nlib
NTest.h
[詳解]
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_TESTING_NTEST_H_
17 #define INCLUDE_NN_NLIB_TESTING_NTEST_H_
18 
19 #include <string.h>
20 #include <new>
21 
22 #include "nn/nlib/Config.h"
25 #include "nn/nlib/Nflags.h"
26 
27 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
28 #undef NLIB_VIS_PUBLIC
29 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
30 #endif
31 
32 // NOTE:
33 // The implementation does not need std::iostream(ostream).
34 NLIB_NAMESPACE_BEGIN
35 namespace testing {
36 
37 NLIB_VIS_PUBLIC void InitNintendoTest(int* argc, char** argv);
38 NLIB_VIS_PUBLIC void InitNintendoTest(int* argc, wchar_t** argv);
39 
41  public:
42  virtual ~Environment() {}
43  virtual void SetUp() {}
44  virtual void TearDown() {}
45 };
46 
48 
49 // The current test result must be accessible globally.
50 struct NLIB_VIS_PUBLIC TestResult {
51  bool HasFatalFaiulre() const { return is_fatal_error; } // gtest
52  bool HasNonfatalFailure() const { return is_non_fatal_error; } // gtest
53 
54  bool is_disabled;
55  bool is_done;
56  bool is_fatal_error;
57  bool is_non_fatal_error;
58 
59  // NOTE:
60  // NO CONSTRUCTOR
61  // The values are set by TestInfo::AddTestInfo() before main function.
62  // If there is a constuctor, the constructor may be invoked
63  // after TestInfo::AddTestInfo() executed.
64 };
65 
66 class Test;
67 class NLIB_VIS_PUBLIC TestFactoryBase {
68  public:
69  virtual ~TestFactoryBase() {}
70  virtual Test* Create() = 0;
71 
72  protected:
73  TestFactoryBase() {}
74 
75  private:
76  NLIB_DISALLOW_COPY_AND_ASSIGN(TestFactoryBase);
77 };
78 
79 template <class TestClass>
80 class TestFactory : public TestFactoryBase {
81  public:
82  TestFactory() {}
83  virtual Test* Create() NLIB_OVERRIDE {
84  NLIB_STATIC_ASSERT(sizeof(TestClass));
85  return new TestClass;
86  }
87 
88  private:
89  NLIB_DISALLOW_COPY_AND_ASSIGN(TestFactory);
90 };
91 
92 class NLIB_VIS_PUBLIC TestInfo NLIB_FINAL {
93  public:
94  TestInfo();
95  ~TestInfo();
96  const char* test_case_name() const { return testcase_name_; } // gtest
97  const char* name() const { return testname_; } // gtest
98  const TestResult* result() const { return &result_; } // gtest
99  static int Run();
100 
101  public:
102  typedef void (*SetUpTestCaseFunc)();
103  typedef void (*TearDownTestCaseFunc)();
104  template <class TestClass>
105  static TestInfo* AddTestInfo(const char* test_case, const char* test_name, int index,
106  SetUpTestCaseFunc setup_func, TearDownTestCaseFunc teardown_func);
107 
108  private:
109  static const int kMaxTestList = 4096;
110  static TestInfo testlist_[kMaxTestList];
111  static int testlist_idx_;
112 
113  private:
114  bool RunTest();
115  bool TestCaseNameLess(const TestInfo& rhs) const {
116  int tmp = strcmp(testcase_name_, rhs.testcase_name_);
117  if (tmp < 0) return true;
118  if (tmp > 0) return false;
119  return index_ < rhs.index_;
120  }
121  bool TestCaseNameEq(const TestInfo& rhs) const {
122  return index_ == rhs.index_ &&
123  strcmp(testcase_name_, rhs.testcase_name_) == 0;
124  }
125  bool IsTypedTest() const { return index_ >= 0; }
126  int GetTypedTestVariant() const { return index_ < 0 ? 0 : index_; }
127  struct TestSortPred {
128  bool operator()(TestInfo* lhs, TestInfo* rhs) {
129  return lhs->TestCaseNameLess(*rhs);
130  }
131  };
132 
133  private:
134  static TestInfo& AddTestInfo_(const char* test_case, const char* test_name, int index,
135  SetUpTestCaseFunc setup_func,
136  TearDownTestCaseFunc teardown_func);
137 
138  private:
139  friend class FollowMessageTerminator;
140  const char* testcase_name_;
141  const char* testname_;
142  int index_; // -1 if not TYPED_TEST_CASE
143  TestFactoryBase* factory_;
144  void (*setup_testcase_)();
145  void (*teardown_testcase_)();
146  TestResult result_;
147  double testfactory_space_[2];
149 };
150 
151 template <class TestClass>
152 TestInfo* TestInfo::AddTestInfo(const char* test_case, const char* test_name, int index,
153  SetUpTestCaseFunc setup_func, TearDownTestCaseFunc teardown_func) {
154  // NOTE:
155  // This function is executed before main function to register the tests.
156  // DYNAMIC MEMORY ALLOCATION CANNOT BE PERFORMED in this function.
157  // Some environments may initialize its heap in main function.
158  TestInfo& info = AddTestInfo_(test_case, test_name, index, setup_func, teardown_func);
159  void* p = &info.testfactory_space_[0];
160  new (p) TestFactory<TestClass>();
161 
162  // NOTE:
163  // We use type 'char*' to avoid
164  // "warning: dereferencing type-punned pointer will break strict-aliasing rules"
165  // on GCC. This is better than using -fno-strict-aliasing.
166  char* tmpptr = reinterpret_cast<char*>(&info.testfactory_space_[0]);
167  info.factory_ = reinterpret_cast<TestFactoryBase*>(tmpptr);
168 
169  return &info;
170 }
171 
172 class NLIB_VIS_PUBLIC UnitTest NLIB_FINAL {
173  // This code does nothing. it is only for source code compatibility with gtest.
174  public:
175  static UnitTest* GetInstance();
176 
177  // const char* original_working_dir() const;
178  // const TestCase* current_test_case() const;
179 
180  const TestInfo* current_test_info() const { return current_; }
181 
182  // int random_seed() const;
183 
184  /*
185  int successful_test_case_count() const;
186  int failed_test_case_count() const;
187  int total_test_case_count() const;
188  int test_case_to_run_count() const;
189  int successful_test_count() const;
190  int failed_test_count() const;
191  int disabled_test_count() const;
192  int total_test_count() const;
193  int test_to_run_count() const;
194  int32_t elapsed_time() const;
195  bool Passed() const;
196  bool Failed() const;
197  */
198 
199  private:
200  TestInfo* current_;
201 
202  private:
203  friend class TestInfo;
204  friend class SimpleSingleton<UnitTest>;
205  friend class FollowMessageTerminator;
206  UnitTest() : current_(NULL) {}
207  virtual ~UnitTest() {}
208 
210 };
211 
212 class NLIB_VIS_PUBLIC Test {
213  public:
214  static void SetUpTestCase() {}
215  static void TearDownTestCase() {}
216 
217  Test();
218  virtual ~Test();
219  void Run();
220  void RecordProperty(const char* key, const char* value);
221  void RecordProperty(const char* key, int value);
222 
223  protected:
224  virtual void SetUp() {}
225  virtual void TearDown() {}
226  virtual void TestBody() = 0;
227 
228  private:
230 };
231 
232 class NLIB_VIS_PUBLIC AssertionResult NLIB_FINAL {
233  public:
234  explicit AssertionResult(bool result) : is_success_(result), builder_() {}
235  ~AssertionResult() {}
236  AssertionResult(const AssertionResult& rhs)
237  : is_success_(rhs.is_success_), builder_() {
238  // NOTE: avoid copying...
239  builder_.swap(const_cast<AssertionResult&>(rhs).builder_);
240  }
241  operator bool() const { return is_success_; }
242  AssertionResult operator!() const { return AssertionResult(!is_success_); }
243  const char* c_str() const { return builder_.c_str(); }
244 
245  template <class T>
246  AssertionResult& operator<<(const T& rhs) {
247  builder_ << rhs;
248  return *this;
249  }
250  AssertionResult& operator<<(AssertionResult& rhs) { // NOLINT
251  is_success_ = rhs.is_success_;
252  builder_.swap(rhs.builder_);
253  return *this;
254  }
255 
256  private:
257  bool is_success_;
258  detail_func::DummyStream builder_;
259  AssertionResult& operator=(const AssertionResult&); // cannot assign
260 };
261 
262 class NLIB_VIS_PUBLIC ScopedTrace NLIB_FINAL {
263  public:
264  static void Print();
265  ScopedTrace(AssertionResult& msg, const char* file, int line); // NOLINT
266  ~ScopedTrace();
267 
268  private:
269  NLIB_DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
270 };
271 
272 class NLIB_VIS_PUBLIC FollowMessageTerminator NLIB_FINAL {
273  public:
274  explicit FollowMessageTerminator(bool flag);
275 
276  // NOTE:
277  // This function is a trick to write return statement which has no return value.
278  // ex. return FollowMessageTerminator(true) = ...;
279  // it is to simplify the else clause in the macros
280  void operator=(const AssertionResult& msg) const;
281 
282  private:
283  NLIB_DISALLOW_COPY_AND_ASSIGN(FollowMessageTerminator);
284 };
285 
286 inline bool suppress_warning_(bool b) { return b; }
287 NLIB_VIS_PUBLIC AssertionResult BooleanFailMessage(const char* file, int line, const char* expr,
288  const char* actual, const char* expected);
289 #define NLIB_TESTING_BOOLEAN_IMPL_(expr, expected, actual, iffail) \
290  switch (0) \
291  case 0: \
292  default: \
293  if (::nlib_ns::testing::suppress_warning_(expr)) \
294  ; \
295  else \
296  iffail = \
297  ::nlib_ns::testing::BooleanFailMessage(__FILE__, __LINE__, #expr, #actual, #expected)
298 
299 NLIB_VIS_PUBLIC AssertionResult CompFailMessage(const char* file, int line, const char* expr1,
300  const char* expr2, const char* val1,
301  const char* val2, const char* op);
302 #define NLIB_TESTING_COMP_IMPL_(func_name, op) \
303 template<class T1, class T2> \
304 AssertionResult Comp##func_name(const char* expr1, const char* expr2, const T1& val1, \
305  const T2& val2, const char* file, int line) { \
306  if (val1 op val2) { \
307  return AssertionResult(true); \
308  } else { \
309  detail_func::DummyStream val1str, val2str; \
310  val1str << val1; \
311  val2str << val2; \
312  return CompFailMessage(file, line, expr1, expr2, val1str.c_str(), \
313  val2str.c_str(), #op); \
314  } \
315 } \
316 NLIB_VIS_PUBLIC AssertionResult Comp##func_name(const char* expr1, const char* expr2, \
317  int64_t val1, int64_t val2, \
318  const char* file, int line)
319 
320 NLIB_TESTING_COMP_IMPL_(EQ, ==);
321 NLIB_TESTING_COMP_IMPL_(NE, !=);
322 NLIB_TESTING_COMP_IMPL_(LE, <=);
323 NLIB_TESTING_COMP_IMPL_(LT, <);
324 NLIB_TESTING_COMP_IMPL_(GE, >=);
325 NLIB_TESTING_COMP_IMPL_(GT, >);
326 
327 #undef NLIB_TESTING_COMP_IMPL_
328 
329 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const char* val1,
330  const char* val2, const char* file, int line);
331 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const char* val1,
332  const char* val2, const char* file, int line);
333 
334 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const wchar_t* val1,
335  const wchar_t* val2, const char* file, int line);
336 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const wchar_t* val1,
337  const wchar_t* val2, const char* file, int line);
338 
339 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
340  const char* val1, const char* val2,
341  const char* file, int line);
342 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
343  const char* val1, const char* val2,
344  const char* file, int line);
345 
346 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
347  const wchar_t* val1, const wchar_t* val2,
348  const char* file, int line);
349 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
350  const wchar_t* val1, const wchar_t* val2,
351  const char* file, int line);
352 
353 NLIB_VIS_PUBLIC AssertionResult CompFloatEq(const char* expr1, const char* expr2, float val1,
354  float val2, const char* file, int line);
355 NLIB_VIS_PUBLIC AssertionResult CompDoubleEq(const char* expr1, const char* expr2, double val1,
356  double val2, const char* file, int line);
357 NLIB_VIS_PUBLIC AssertionResult NearDouble(double val1, double val2, double abs_error);
358 
359 // NOTE: PRE05-C. Understand macro replacement
360 // when concatenating tokens or performing stringification
361 #define NLIB_TESTING_CONCAT_TOKEN_(a, b) NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b)
362 #define NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b) a##b
363 
364 #define NLIB_TESTING_FATAL_ return ::nlib_ns::testing::FollowMessageTerminator(true)
365 #define NLIB_TESTING_NONFATAL_ ::nlib_ns::testing::FollowMessageTerminator(false)
366 
367 #define NLIB_TESTING_ASSERT_HELPER_(func, val1, val2) \
368  switch (0) \
369  case 0: \
370  default: \
371  if (::nlib_ns::testing::AssertionResult ar = \
372  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
373  ; \
374  else \
375  NLIB_TESTING_FATAL_ = ar
376 
377 #define NLIB_TESTING_EXPECT_HELPER_(func, val1, val2) \
378  switch (0) \
379  case 0: \
380  default: \
381  if (::nlib_ns::testing::AssertionResult ar = \
382  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
383  ; \
384  else \
385  NLIB_TESTING_NONFATAL_ = ar
386 
387 #define NLIB_TESTING_CLASS_NAME_(test_case, test_name) test_case##_##test_name##_Test
388 
389 #define NLIB_TEST_(test_case, test_name, parent) \
390 class NLIB_TESTING_CLASS_NAME_(test_case, test_name) \
391  : public parent { \
392 public: \
393  NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
394 private: \
395  virtual void TestBody(); \
396  static ::nlib_ns::testing::TestInfo* info_; \
397  NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
398 }; \
399 ::nlib_ns::testing::TestInfo* NLIB_TESTING_CLASS_NAME_(test_case, test_name)::info_ = \
400  ::nlib_ns::testing::TestInfo::AddTestInfo< \
401  NLIB_TESTING_CLASS_NAME_(test_case, test_name)>( \
402  #test_case, #test_name, -1, parent::SetUpTestCase, parent::TearDownTestCase); \
403 void NLIB_TESTING_CLASS_NAME_(test_case, test_name)::TestBody()
404 
405 NLIB_VIS_PUBLIC AssertionResult& NearFailMessage(AssertionResult* ar, const char* file, int line,
406  const char* expr1, const char* expr2,
407  const char* abs_error_expr, double val1,
408  double val2, double abs_error);
409 
410 NLIB_VIS_PUBLIC AssertionResult
411  FloatLE(const char* expr1, const char* expr2, float val1, float val2);
412 NLIB_VIS_PUBLIC AssertionResult
413  DoubleLE(const char* expr1, const char* expr2, double val1, double val2);
414 NLIB_VIS_PUBLIC AssertionResult AssertionSuccess();
415 NLIB_VIS_PUBLIC AssertionResult AssertionFailure();
416 NLIB_VIS_PUBLIC AssertionResult Message();
417 
418 #define NLIB_TESTING_FLAG(flag_name) NLIB_FLAGS_##flag_name
419 
422 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_break_on_failure);
423 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_also_run_disabled_tests);
427 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_int32(gtest_random_seed);
428 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_print_time);
429 
430 } // namespace testing
431 NLIB_NAMESPACE_END
432 
433 NLIB_NAMESPACE_BEGIN
434 namespace testing {
435 #define TEST(test_case_name, specific_test_name) \
436  NLIB_TEST_(test_case_name, specific_test_name, ::nlib_ns::testing::Test)
437 #define TEST_F(test_fixture_name, specific_test_name) \
438  NLIB_TEST_(test_fixture_name, specific_test_name, test_fixture_name)
439 
440 #define FRIEND_TEST(test_case, test_name) \
441  friend class NLIB_TESTING_CLASS_NAME_(test_case, test_name)
442 
443 #define RUN_ALL_TESTS() ::nlib_ns::testing::TestInfo::Run()
444 
445 #define FAIL() \
446  return ::nlib_ns::testing::FollowMessageTerminator(true) = \
447  ::nlib_ns::testing::AssertionResult(false)
448 #define SUCCEED()
449 
450 #define ASSERT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_FATAL_)
451 #define ASSERT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_FATAL_)
452 #define EXPECT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_NONFATAL_)
453 #define EXPECT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_NONFATAL_)
454 
455 #define ASSERT_EQ(expected, actual) \
456  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
457 #define ASSERT_NE(expected, actual) \
458  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
459 #define ASSERT_LE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
460 #define ASSERT_LT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
461 #define ASSERT_GE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
462 #define ASSERT_GT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
463 
464 #define EXPECT_EQ(expected, actual) \
465  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
466 #define EXPECT_NE(expected, actual) \
467  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
468 #define EXPECT_LE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
469 #define EXPECT_LT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
470 #define EXPECT_GE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
471 #define EXPECT_GT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
472 
473 #define ASSERT_STREQ(expected, actual) \
474  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
475 #define ASSERT_STRNE(expected, actual) \
476  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
477 
478 #define EXPECT_STREQ(expected, actual) \
479  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
480 #define EXPECT_STRNE(expected, actual) \
481  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
482 
483 #define ASSERT_STRCASEEQ(expected, actual) \
484  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
485 #define ASSERT_STRCASENE(expected, actual) \
486  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
487 
488 #define EXPECT_STRCASEEQ(expected, actual) \
489  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
490 #define EXPECT_STRCASENE(expected, actual) \
491  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
492 
493 // NOTE: not implemented, it will be complicated because of locale
494 // ASSERT_STRCASEEQ
495 // ASSERT_STRCASENE
496 
497 #define ASSERT_FLOAT_EQ(expected, actual) \
498  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
499 #define ASSERT_DOUBLE_EQ(expected, actual) \
500  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
501 
502 #define EXPECT_FLOAT_EQ(expected, actual) \
503  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
504 #define EXPECT_DOUBLE_EQ(expected, actual) \
505  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
506 
507 #define ASSERT_NEAR(val1, val2, abs_error) \
508  switch (0) \
509  case 0: \
510  default: \
511  if (::nlib_ns::testing::AssertionResult ar = \
512  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
513  ; \
514  else \
515  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::NearFailMessage( \
516  &ar, __FILE__, __LINE__, #val1, #val2, #abs_error, val1, val2, abs_error)
517 
518 #define EXPECT_NEAR(val1, val2, abs_error) \
519  switch (0) \
520  case 0: \
521  default: \
522  if (::nlib_ns::testing::AssertionResult ar = \
523  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
524  ; \
525  else /* NOLINT */ \
526  NLIB_TESTING_NONFATAL_ = ::nlib_ns::testing::NearFailMessage( \
527  &ar, __FILE__, __LINE__, #val1, #val2, #abs_error, val1, val2, abs_error)
528 
529 #define SCOPED_TRACE(msg) \
530  ::nlib_ns::testing::ScopedTrace NLIB_TESTING_CONCAT_TOKEN_(nlib_scopedtrace_, __LINE__)( \
531  ::nlib_ns::testing::AssertionResult(true) << (msg), __FILE__, __LINE__)
532 
533 #define ASSERT_NO_FATAL_FAILURE(statement) \
534  switch (0) \
535  case 0: \
536  default: \
537  for (;;) { \
538  statement; \
539  break; \
540  } \
541  if (!::nlib_ns::testing::UnitTest::GetInstance() \
542  ->current_test_info() \
543  ->result() \
544  ->HasFatalFaiulre()) \
545  ; \
546  else /* NOLINT */ \
547  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::AssertionResult(false) \
548  << "Expected: " #statement \
549  " doesn't generate new fatal failures.\n" \
550  " Actual: it does.\n"
551 
552 #define EXPECT_NO_FATAL_FAILURE(statement) \
553  switch (0) \
554  case 0: \
555  default: \
556  for (;;) { \
557  statement; \
558  break; \
559  } \
560  if (!::nlib_ns::testing::UnitTest::GetInstance() \
561  ->current_test_info() \
562  ->result() \
563  ->HasFatalFaiulre()) \
564  ; \
565  else \
566  NLIB_TESTING_NONFATAL_ = ::nlib_ns::testing::AssertionResult(false) \
567  << "Expected: " #statement \
568  " doesn't generate new fatal failures.\n" \
569  " Actual: it does.\n"
570 
571 #define GTEST_FLAG(name) NLIB_FLAGS_gtest_##name
572 
573 } // namespace testing
574 NLIB_NAMESPACE_END
575 
576 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
577 #undef NLIB_VIS_PUBLIC
578 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
579 #endif
580 
581 #endif // INCLUDE_NN_NLIB_TESTING_NTEST_H_
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:228
テスト失敗時の表示を制御します。
AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
val1 <= val2を検証します。[ASSERT|EXPECT]_PRED_FORMAT2に組み込んで利用します。
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:163
virtual void SetUp()
全てのテストの前に1回だけ実行される処理を記述します。
Definition: NTest.h:43
コマンドライン文字列を扱うためのクラスが定義されています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
main関数の実行前にstatic変数により暗黙的にインスタンスを構築するタイプのシングルトンです。 ...
#define NLIB_FLAGS_DECLARE_bool(opt_name)
別の場所で定義された、NLIB_FLAGS_オプション名、を利用できるようにします。
Definition: Nflags.h:163
シングルトンが定義されています。
void InitNintendoTest(int *argc, wchar_t **argv)
テストプログラムのコマンドラインオプションを処理します。
Environment * AddGlobalTestEnvironment(Environment *env)
Environment へのポインタを渡して、全てのテストの前と後に実行されるコードを登録します。 ...
開発環境別の設定が書かれるファイルです。
virtual void TearDown()
全てのテストの後に1回だけ実行される処理を記述します。
Definition: NTest.h:44
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
Definition: Config.h:154
#define NLIB_FLAGS_DECLARE_string(opt_name)
別の場所で定義された、NLIB_FLAGS_オプション名、を利用できるようにします。
Definition: Nflags.h:166
このクラスを継承してグローバルに実行されるSetUp()とTearDown()を定義します。
Definition: NTest.h:40
AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
val1 <= val2を検証します。[ASSERT|EXPECT]_PRED_FORMAT2に組み込んで利用します。
#define NLIB_FLAGS_DECLARE_int32(opt_name)
別の場所で定義された、NLIB_FLAGS_オプション名、を利用できるようにします。
Definition: Nflags.h:164