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_(nullptr) {}
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_),
238  builder_(const_cast<detail_func::DummyStream&>(rhs.builder_),
239  move_tag()) {
240  // NOTE: avoid copying...
241  }
242  operator bool() const { return is_success_; }
243  AssertionResult operator!() const { return AssertionResult(!is_success_); }
244  const char* c_str() const { return builder_.c_str(); }
245 
246  template <class T>
247  AssertionResult& operator<<(const T& rhs) {
248  builder_ << rhs;
249  return *this;
250  }
251  AssertionResult& operator<<(AssertionResult& rhs) { // NOLINT
252  is_success_ = rhs.is_success_;
253  builder_.assign(rhs.builder_, move_tag());
254  return *this;
255  }
256 
257  private:
258  bool is_success_;
259  detail_func::DummyStream builder_;
260  AssertionResult& operator=(const AssertionResult&); // cannot assign
261 };
262 
263 class NLIB_VIS_PUBLIC ScopedTrace NLIB_FINAL {
264  public:
265  static void Print();
266  ScopedTrace(AssertionResult& msg, const char* file, int line); // NOLINT
267  ~ScopedTrace();
268 
269  private:
270  NLIB_DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
271 };
272 
273 class NLIB_VIS_PUBLIC FollowMessageTerminator NLIB_FINAL {
274  public:
275  explicit FollowMessageTerminator(bool flag);
276 
277  // NOTE:
278  // This function is a trick to write return statement which has no return value.
279  // ex. return FollowMessageTerminator(true) = ...;
280  // it is to simplify the else clause in the macros
281  void operator=(const AssertionResult& msg) const;
282 
283  private:
284  NLIB_DISALLOW_COPY_AND_ASSIGN(FollowMessageTerminator);
285 };
286 
287 inline bool suppress_warning_(bool b) { return b; }
288 NLIB_VIS_PUBLIC AssertionResult BooleanFailMessage(const char* file, int line, const char* expr,
289  const char* actual, const char* expected);
290 #define NLIB_TESTING_BOOLEAN_IMPL_(expr, expected, actual, iffail) \
291  switch (0) \
292  case 0: \
293  default: \
294  if (::nlib_ns::testing::suppress_warning_(expr)) \
295  ; \
296  else \
297  iffail = \
298  ::nlib_ns::testing::BooleanFailMessage(__FILE__, __LINE__, #expr, #actual, #expected)
299 
300 NLIB_VIS_PUBLIC AssertionResult CompFailMessage(const char* file, int line, const char* expr1,
301  const char* expr2, const char* val1,
302  const char* val2, const char* op);
303 #define NLIB_TESTING_COMP_IMPL_(func_name, op) \
304 template<class T1, class T2> \
305 AssertionResult Comp##func_name(const char* expr1, const char* expr2, const T1& val1, \
306  const T2& val2, const char* file, int line) { \
307  if (val1 op val2) { \
308  return AssertionResult(true); \
309  } else { \
310  detail_func::DummyStream val1str, val2str; \
311  val1str << val1; \
312  val2str << val2; \
313  return CompFailMessage(file, line, expr1, expr2, val1str.c_str(), \
314  val2str.c_str(), #op); \
315  } \
316 } \
317 NLIB_VIS_PUBLIC AssertionResult Comp##func_name(const char* expr1, const char* expr2, \
318  int64_t val1, int64_t val2, \
319  const char* file, int line)
320 
321 NLIB_TESTING_COMP_IMPL_(EQ, ==);
322 NLIB_TESTING_COMP_IMPL_(NE, !=);
323 NLIB_TESTING_COMP_IMPL_(LE, <=);
324 NLIB_TESTING_COMP_IMPL_(LT, <);
325 NLIB_TESTING_COMP_IMPL_(GE, >=);
326 NLIB_TESTING_COMP_IMPL_(GT, >);
327 
328 #undef NLIB_TESTING_COMP_IMPL_
329 
330 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const char* val1,
331  const char* val2, const char* file, int line);
332 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const char* val1,
333  const char* val2, const char* file, int line);
334 
335 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const wchar_t* val1,
336  const wchar_t* val2, const char* file, int line);
337 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const wchar_t* val1,
338  const wchar_t* val2, const char* file, int line);
339 
340 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
341  const char* val1, const char* val2,
342  const char* file, int line);
343 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
344  const char* val1, const char* val2,
345  const char* file, int line);
346 
347 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
348  const wchar_t* val1, const wchar_t* val2,
349  const char* file, int line);
350 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
351  const wchar_t* val1, const wchar_t* val2,
352  const char* file, int line);
353 
354 NLIB_VIS_PUBLIC AssertionResult CompFloatEq(const char* expr1, const char* expr2, float val1,
355  float val2, const char* file, int line);
356 NLIB_VIS_PUBLIC AssertionResult CompDoubleEq(const char* expr1, const char* expr2, double val1,
357  double val2, const char* file, int line);
358 NLIB_VIS_PUBLIC AssertionResult NearDouble(double val1, double val2, double abs_error);
359 
360 // NOTE: PRE05-C. Understand macro replacement
361 // when concatenating tokens or performing stringification
362 #define NLIB_TESTING_CONCAT_TOKEN_(a, b) NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b)
363 #define NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b) a##b
364 
365 #define NLIB_TESTING_FATAL_ return ::nlib_ns::testing::FollowMessageTerminator(true)
366 #define NLIB_TESTING_NONFATAL_ ::nlib_ns::testing::FollowMessageTerminator(false)
367 
368 #define NLIB_TESTING_ASSERT_HELPER_(func, val1, val2) \
369  switch (0) \
370  case 0: \
371  default: \
372  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
373  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
374  ; \
375  else \
376  NLIB_TESTING_FATAL_ = nlib_ar_tmp_
377 
378 #define NLIB_TESTING_EXPECT_HELPER_(func, val1, val2) \
379  switch (0) \
380  case 0: \
381  default: \
382  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
383  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
384  ; \
385  else \
386  NLIB_TESTING_NONFATAL_ = nlib_ar_tmp_
387 
388 #define NLIB_TESTING_CLASS_NAME_(test_case, test_name) test_case##_##test_name##_Test
389 
390 #define NLIB_TEST_(test_case, test_name, parent) \
391 class NLIB_TESTING_CLASS_NAME_(test_case, test_name) \
392  : public parent { \
393 public: \
394  NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
395 private: \
396  virtual void TestBody(); \
397  static ::nlib_ns::testing::TestInfo* info_; \
398  NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
399 }; \
400 ::nlib_ns::testing::TestInfo* NLIB_TESTING_CLASS_NAME_(test_case, test_name)::info_ = \
401  ::nlib_ns::testing::TestInfo::AddTestInfo< \
402  NLIB_TESTING_CLASS_NAME_(test_case, test_name)>( \
403  #test_case, #test_name, -1, parent::SetUpTestCase, parent::TearDownTestCase); \
404 void NLIB_TESTING_CLASS_NAME_(test_case, test_name)::TestBody()
405 
406 NLIB_VIS_PUBLIC AssertionResult& NearFailMessage(AssertionResult* ar, const char* file, int line,
407  const char* expr1, const char* expr2,
408  const char* abs_error_expr, double val1,
409  double val2, double abs_error);
410 
411 NLIB_VIS_PUBLIC AssertionResult
412  FloatLE(const char* expr1, const char* expr2, float val1, float val2);
413 NLIB_VIS_PUBLIC AssertionResult
414  DoubleLE(const char* expr1, const char* expr2, double val1, double val2);
415 NLIB_VIS_PUBLIC AssertionResult AssertionSuccess();
416 NLIB_VIS_PUBLIC AssertionResult AssertionFailure();
417 NLIB_VIS_PUBLIC AssertionResult Message();
418 
419 #define NLIB_TESTING_FLAG(flag_name) NLIB_FLAGS_##flag_name
420 
423 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_break_on_failure);
424 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_also_run_disabled_tests);
428 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_int32(gtest_random_seed);
429 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_print_time);
430 
431 } // namespace testing
432 NLIB_NAMESPACE_END
433 
434 NLIB_NAMESPACE_BEGIN
435 namespace testing {
436 #define TEST(test_case_name, specific_test_name) \
437  NLIB_TEST_(test_case_name, specific_test_name, ::nlib_ns::testing::Test)
438 #define TEST_F(test_fixture_name, specific_test_name) \
439  NLIB_TEST_(test_fixture_name, specific_test_name, test_fixture_name)
440 
441 #define FRIEND_TEST(test_case, test_name) \
442  friend class NLIB_TESTING_CLASS_NAME_(test_case, test_name)
443 
444 #define RUN_ALL_TESTS() ::nlib_ns::testing::TestInfo::Run()
445 
446 #define FAIL() \
447  return ::nlib_ns::testing::FollowMessageTerminator(true) = \
448  ::nlib_ns::testing::AssertionResult(false)
449 #define SUCCEED()
450 
451 #define ASSERT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_FATAL_)
452 #define ASSERT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_FATAL_)
453 #define EXPECT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_NONFATAL_)
454 #define EXPECT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_NONFATAL_)
455 
456 #define ASSERT_EQ(expected, actual) \
457  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
458 #define ASSERT_NE(expected, actual) \
459  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
460 #define ASSERT_LE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
461 #define ASSERT_LT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
462 #define ASSERT_GE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
463 #define ASSERT_GT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
464 
465 #define EXPECT_EQ(expected, actual) \
466  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
467 #define EXPECT_NE(expected, actual) \
468  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
469 #define EXPECT_LE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
470 #define EXPECT_LT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
471 #define EXPECT_GE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
472 #define EXPECT_GT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
473 
474 #define ASSERT_STREQ(expected, actual) \
475  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
476 #define ASSERT_STRNE(expected, actual) \
477  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
478 
479 #define EXPECT_STREQ(expected, actual) \
480  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
481 #define EXPECT_STRNE(expected, actual) \
482  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
483 
484 #define ASSERT_STRCASEEQ(expected, actual) \
485  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
486 #define ASSERT_STRCASENE(expected, actual) \
487  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
488 
489 #define EXPECT_STRCASEEQ(expected, actual) \
490  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
491 #define EXPECT_STRCASENE(expected, actual) \
492  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
493 
494 // NOTE: not implemented, it will be complicated because of locale
495 // ASSERT_STRCASEEQ
496 // ASSERT_STRCASENE
497 
498 #define ASSERT_FLOAT_EQ(expected, actual) \
499  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
500 #define ASSERT_DOUBLE_EQ(expected, actual) \
501  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
502 
503 #define EXPECT_FLOAT_EQ(expected, actual) \
504  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
505 #define EXPECT_DOUBLE_EQ(expected, actual) \
506  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
507 
508 #define ASSERT_NEAR(val1, val2, abs_error) \
509  switch (0) \
510  case 0: \
511  default: \
512  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
513  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
514  ; \
515  else \
516  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::NearFailMessage( \
517  &nlib_ar_tmp_, __FILE__, __LINE__, #val1, #val2, #abs_error, val1, val2, abs_error)
518 
519 #define EXPECT_NEAR(val1, val2, abs_error) \
520  switch (0) \
521  case 0: \
522  default: \
523  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
524  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
525  ; \
526  else /* NOLINT */ \
527  NLIB_TESTING_NONFATAL_ = ::nlib_ns::testing::NearFailMessage( \
528  &nlib_ar_tmp_ , __FILE__, __LINE__, #val1, #val2, #abs_error, val1, val2, abs_error)
529 
530 #define SCOPED_TRACE(msg) \
531  ::nlib_ns::testing::ScopedTrace NLIB_TESTING_CONCAT_TOKEN_(nlib_scopedtrace_, __LINE__)( \
532  ::nlib_ns::testing::AssertionResult(true) << (msg), __FILE__, __LINE__)
533 
534 #define ASSERT_NO_FATAL_FAILURE(statement) \
535  switch (0) \
536  case 0: \
537  default: \
538  for (;;) { \
539  statement; \
540  break; \
541  } \
542  if (!::nlib_ns::testing::UnitTest::GetInstance() \
543  ->current_test_info() \
544  ->result() \
545  ->HasFatalFaiulre()) \
546  ; \
547  else /* NOLINT */ \
548  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::AssertionResult(false) \
549  << "Expected: " #statement \
550  " doesn't generate new fatal failures.\n" \
551  " Actual: it does.\n"
552 
553 #define EXPECT_NO_FATAL_FAILURE(statement) \
554  switch (0) \
555  case 0: \
556  default: \
557  for (;;) { \
558  statement; \
559  break; \
560  } \
561  if (!::nlib_ns::testing::UnitTest::GetInstance() \
562  ->current_test_info() \
563  ->result() \
564  ->HasFatalFaiulre()) \
565  ; \
566  else \
567  NLIB_TESTING_NONFATAL_ = ::nlib_ns::testing::AssertionResult(false) \
568  << "Expected: " #statement \
569  " doesn't generate new fatal failures.\n" \
570  " Actual: it does.\n"
571 
572 #define GTEST_FLAG(name) NLIB_FLAGS_gtest_##name
573 
574 } // namespace testing
575 NLIB_NAMESPACE_END
576 
577 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
578 #undef NLIB_VIS_PUBLIC
579 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
580 #endif
581 
582 #endif // INCLUDE_NN_NLIB_TESTING_NTEST_H_
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:244
テスト失敗時の表示を制御します。
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:179
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:164
シングルトンが定義されています。
空の構造体で、関数の引数をムーブすべきことを示すために利用されます。
Definition: Config.h:265
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:170
#define NLIB_FLAGS_DECLARE_string(opt_name)
別の場所で定義された、NLIB_FLAGS_オプション名、を利用できるようにします。
Definition: Nflags.h:167
このクラスを継承してグローバルに実行される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:165