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