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 
47 NLIB_VIS_PUBLIC Environment* AddGlobalTestEnvironment(Environment* env);
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() NLIB_NOEXCEPT;
95  ~TestInfo() NLIB_NOEXCEPT;
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_ && strcmp(testcase_name_, rhs.testcase_name_) == 0;
123  }
124  bool IsTypedTest() const { return index_ >= 0; }
125  int GetTypedTestVariant() const { return index_ < 0 ? 0 : index_; }
126  struct TestSortPred {
127  bool operator()(TestInfo* lhs, TestInfo* rhs) { return lhs->TestCaseNameLess(*rhs); }
128  };
129 
130  private:
131  static TestInfo& AddTestInfo_(const char* test_case, const char* test_name, int index,
132  SetUpTestCaseFunc setup_func, TearDownTestCaseFunc teardown_func);
133 
134  private:
135  friend class FollowMessageTerminator;
136  const char* testcase_name_;
137  const char* testname_;
138  TestFactoryBase* factory_;
139  void (*setup_testcase_)();
140  void (*teardown_testcase_)();
141  int index_; // -1 if not TYPED_TEST_CASE
142  TestResult result_;
143  double testfactory_space_[2];
145 };
146 
147 template<class TestClass>
148 TestInfo* TestInfo::AddTestInfo(const char* test_case, const char* test_name, int index,
149  SetUpTestCaseFunc setup_func, TearDownTestCaseFunc teardown_func) {
150  // NOTE:
151  // This function is executed before main function to register the tests.
152  // DYNAMIC MEMORY ALLOCATION CANNOT BE PERFORMED in this function.
153  // Some environments may initialize its heap in main function.
154  TestInfo& info = AddTestInfo_(test_case, test_name, index, setup_func, teardown_func);
155  void* p = &info.testfactory_space_[0];
156  new (p) TestFactory<TestClass>();
157 
158  // NOTE:
159  // We use type 'char*' to avoid
160  // "warning: dereferencing type-punned pointer will break strict-aliasing rules"
161  // on GCC. This is better than using -fno-strict-aliasing.
162  char* tmpptr = reinterpret_cast<char*>(&info.testfactory_space_[0]);
163  info.factory_ = reinterpret_cast<TestFactoryBase*>(tmpptr);
164 
165  return &info;
166 }
167 
168 class NLIB_VIS_PUBLIC UnitTest NLIB_FINAL {
169  // This code does nothing. it is only for source code compatibility with gtest.
170  public:
171  static UnitTest* GetInstance();
172 
173  // const char* original_working_dir() const;
174  // const TestCase* current_test_case() const;
175 
176  const TestInfo* current_test_info() const { return current_; }
177 
178  // int random_seed() const;
179 
180  /*
181  int successful_test_case_count() const;
182  int failed_test_case_count() const;
183  int total_test_case_count() const;
184  int test_case_to_run_count() const;
185  int successful_test_count() const;
186  int failed_test_count() const;
187  int disabled_test_count() const;
188  int total_test_count() const;
189  int test_to_run_count() const;
190  int32_t elapsed_time() const;
191  bool Passed() const;
192  bool Failed() const;
193  */
194 
195  private:
196  TestInfo* current_;
197 
198  private:
199  friend class TestInfo;
200  friend class SimpleSingleton<UnitTest>;
201  friend class FollowMessageTerminator;
202  UnitTest() NLIB_NOEXCEPT : current_(nullptr) {}
203  virtual ~UnitTest() {}
204 
206 };
207 
208 class NLIB_VIS_PUBLIC Test {
209  public:
210  static void SetUpTestCase() {}
211  static void TearDownTestCase() {}
212 
213  Test();
214  virtual ~Test();
215  void Run();
216  void RecordProperty(const char* key, const char* value);
217  void RecordProperty(const char* key, int value);
218 
219  protected:
220  virtual void SetUp() {}
221  virtual void TearDown() {}
222  virtual void TestBody() = 0;
223 
224  private:
226 };
227 
228 class NLIB_VIS_PUBLIC AssertionResult NLIB_FINAL {
229  public:
230  explicit AssertionResult(bool result) : is_success_(result), builder_() {}
231  ~AssertionResult() {}
232  AssertionResult(const AssertionResult& rhs) :
233  is_success_(rhs.is_success_),
234  builder_(const_cast<detail_func::DummyStream&>(rhs.builder_), move_tag()) {
235  // NOTE: avoid copying...
236  }
237  operator bool() const { return is_success_; }
238  AssertionResult operator!() const { return AssertionResult(!is_success_); }
239  const char* c_str() const { return builder_.c_str(); }
240 
241  template<class T>
242  AssertionResult& operator<<(const T& rhs) {
243  builder_ << rhs;
244  return *this;
245  }
246  AssertionResult& operator<<(AssertionResult& rhs) {
247  is_success_ = rhs.is_success_;
248  builder_.assign(rhs.builder_, move_tag());
249  return *this;
250  }
251 
252  private:
253  bool is_success_;
254  detail_func::DummyStream builder_;
255  AssertionResult& operator=(const AssertionResult&); // cannot assign
256 };
257 
258 class NLIB_VIS_PUBLIC ScopedTrace NLIB_FINAL {
259  public:
260  static void Print();
261  ScopedTrace(AssertionResult& msg, const char* file, int line);
262  ~ScopedTrace();
263 
264  private:
265  NLIB_DISALLOW_COPY_AND_ASSIGN(ScopedTrace);
266 };
267 
268 class NLIB_VIS_PUBLIC FollowMessageTerminator NLIB_FINAL {
269  public:
270  explicit FollowMessageTerminator(bool flag);
271 
272  // NOTE:
273  // This function is a trick to write return statement which has no return value.
274  // ex. return FollowMessageTerminator(true) = ...;
275  // it is to simplify the else clause in the macros
276  void operator=(const AssertionResult& msg) const;
277 
278  private:
279  NLIB_DISALLOW_COPY_AND_ASSIGN(FollowMessageTerminator);
280 };
281 
282 NLIB_VIS_PUBLIC AssertionResult BooleanFailMessage(const char* file, int line, const char* expr,
283  const char* actual, const char* msg,
284  const char* expected);
285 #define NLIB_TESTING_BOOLEAN_IMPL_(expr, expected, actual, iffail) \
286  switch (0) \
287  case 0: \
288  default: \
289  if (const ::nlib_ns::testing::AssertionResult ar = \
290  ::nlib_ns::testing::AssertionResult(expr)) \
291  ; \
292  else \
293  iffail = ::nlib_ns::testing::BooleanFailMessage(__FILE__, __LINE__, #expr, #actual, \
294  ar.c_str(), #expected)
295 
296 NLIB_VIS_PUBLIC AssertionResult CompFailMessage(const char* file, int line, const char* expr1,
297  const char* expr2, const char* val1,
298  const char* val2, const char* op);
299 #define NLIB_TESTING_COMP_IMPL_(func_name, op) \
300  template<class T1, class T2> \
301  AssertionResult Comp##func_name(const char* expr1, const char* expr2, const T1& val1, \
302  const T2& val2, const char* file, int line) { \
303  if (val1 op val2) { \
304  return AssertionResult(true); \
305  } else { \
306  detail_func::DummyStream val1str, val2str; \
307  val1str << val1; \
308  val2str << val2; \
309  return CompFailMessage(file, line, expr1, expr2, val1str.c_str(), val2str.c_str(), \
310  #op); \
311  } \
312  } \
313  NLIB_VIS_PUBLIC AssertionResult Comp##func_name(const char* expr1, const char* expr2, \
314  int64_t val1, int64_t val2, const char* file, \
315  int line)
316 
317 NLIB_TESTING_COMP_IMPL_(EQ, ==);
318 NLIB_TESTING_COMP_IMPL_(NE, !=);
319 NLIB_TESTING_COMP_IMPL_(LE, <=);
320 NLIB_TESTING_COMP_IMPL_(LT, <);
321 NLIB_TESTING_COMP_IMPL_(GE, >=);
322 NLIB_TESTING_COMP_IMPL_(GT, >);
323 
324 #undef NLIB_TESTING_COMP_IMPL_
325 
326 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const char* val1,
327  const char* val2, const char* file, int line);
328 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const char* val1,
329  const char* val2, const char* file, int line);
330 
331 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const wchar_t* val1,
332  const wchar_t* val2, const char* file, int line);
333 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const wchar_t* val1,
334  const wchar_t* val2, const char* file, int line);
335 
336 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2,
337  const nlib_utf16_t* val1, const nlib_utf16_t* val2,
338  const char* file, int line);
339 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2,
340  const nlib_utf16_t* val1, const nlib_utf16_t* val2,
341  const char* file, int line);
342 
343 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2,
344  const nlib_utf32_t* val1, const nlib_utf32_t* val2,
345  const char* file, int line);
346 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2,
347  const nlib_utf32_t* val1, const nlib_utf32_t* val2,
348  const char* file, int line);
349 
350 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
351  const char* val1, const char* val2, const char* file,
352  int line);
353 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
354  const char* val1, const char* val2, const char* file,
355  int line);
356 
357 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
358  const wchar_t* val1, const wchar_t* val2,
359  const char* file, int line);
360 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
361  const wchar_t* val1, const wchar_t* val2,
362  const char* file, int line);
363 
364 NLIB_VIS_PUBLIC AssertionResult CompFloatEq(const char* expr1, const char* expr2, float val1,
365  float val2, const char* file, int line);
366 NLIB_VIS_PUBLIC AssertionResult CompDoubleEq(const char* expr1, const char* expr2, double val1,
367  double val2, const char* file, int line);
368 NLIB_VIS_PUBLIC AssertionResult NearDouble(double val1, double val2, double abs_error);
369 
370 // NOTE: PRE05-C. Understand macro replacement
371 // when concatenating tokens or performing stringification
372 #define NLIB_TESTING_CONCAT_TOKEN_(a, b) NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b)
373 #define NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b) a##b
374 
375 #define NLIB_TESTING_FATAL_ return ::nlib_ns::testing::FollowMessageTerminator(true)
376 #define NLIB_TESTING_NONFATAL_ ::nlib_ns::testing::FollowMessageTerminator(false)
377 
378 #define NLIB_TESTING_ASSERT_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_FATAL_ = nlib_ar_tmp_
387 
388 #define NLIB_TESTING_EXPECT_HELPER_(func, val1, val2) \
389  switch (0) \
390  case 0: \
391  default: \
392  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
393  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
394  ; \
395  else \
396  NLIB_TESTING_NONFATAL_ = nlib_ar_tmp_
397 
398 #define NLIB_TESTING_CLASS_NAME_(test_case, test_name) test_case##_##test_name##_Test
399 
400 #define NLIB_TEST_(test_case, test_name, parent) \
401  class NLIB_TESTING_CLASS_NAME_(test_case, test_name) : public parent { \
402  public: \
403  NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
404  \
405  private: \
406  virtual void TestBody(); \
407  static ::nlib_ns::testing::TestInfo* info_; \
408  NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
409  }; \
410  ::nlib_ns::testing::TestInfo* NLIB_TESTING_CLASS_NAME_(test_case, test_name)::info_ = \
411  ::nlib_ns::testing::TestInfo::AddTestInfo<NLIB_TESTING_CLASS_NAME_(test_case, test_name)>( \
412  #test_case, #test_name, -1, parent::SetUpTestCase, parent::TearDownTestCase); \
413  void NLIB_TESTING_CLASS_NAME_(test_case, test_name)::TestBody()
414 
415 NLIB_VIS_PUBLIC AssertionResult&
416 NearFailMessage(AssertionResult* ar, const char* file, int line, const char* expr1,
417  const char* expr2, const char* abs_error_expr, double val1, double val2,
418  double abs_error);
419 
420 NLIB_VIS_PUBLIC AssertionResult FloatLE(const char* expr1, const char* expr2, float val1,
421  float val2);
422 NLIB_VIS_PUBLIC AssertionResult DoubleLE(const char* expr1, const char* expr2, double val1,
423  double val2);
424 NLIB_VIS_PUBLIC AssertionResult AssertionSuccess();
425 NLIB_VIS_PUBLIC AssertionResult AssertionFailure();
426 NLIB_VIS_PUBLIC AssertionResult Message();
427 
428 #define NLIB_TESTING_FLAG(flag_name) NLIB_FLAGS_##flag_name
429 
432 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_break_on_failure);
433 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_also_run_disabled_tests);
437 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_int32(gtest_random_seed);
438 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_print_time);
439 
440 } // namespace testing
441 NLIB_NAMESPACE_END
442 
443 NLIB_NAMESPACE_BEGIN
444 namespace testing {
445 #define TEST(test_case_name, specific_test_name) \
446  NLIB_TEST_(test_case_name, specific_test_name, ::nlib_ns::testing::Test)
447 #define TEST_F(test_fixture_name, specific_test_name) \
448  NLIB_TEST_(test_fixture_name, specific_test_name, test_fixture_name)
449 
450 #define FRIEND_TEST(test_case, test_name) \
451  friend class NLIB_TESTING_CLASS_NAME_(test_case, test_name)
452 
453 #define RUN_ALL_TESTS() ::nlib_ns::testing::TestInfo::Run()
454 
455 #define FAIL() \
456  return ::nlib_ns::testing::FollowMessageTerminator(true) = \
457  ::nlib_ns::testing::AssertionResult(false)
458 #define SUCCEED()
459 
460 #define ASSERT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_FATAL_)
461 #define ASSERT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_FATAL_)
462 #define EXPECT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_NONFATAL_)
463 #define EXPECT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_NONFATAL_)
464 
465 #define ASSERT_EQ(expected, actual) \
466  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
467 #define ASSERT_NE(expected, actual) \
468  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
469 #define ASSERT_LE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
470 #define ASSERT_LT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
471 #define ASSERT_GE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
472 #define ASSERT_GT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
473 
474 #define EXPECT_EQ(expected, actual) \
475  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
476 #define EXPECT_NE(expected, actual) \
477  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
478 #define EXPECT_LE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
479 #define EXPECT_LT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
480 #define EXPECT_GE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
481 #define EXPECT_GT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
482 
483 #define ASSERT_STREQ(expected, actual) \
484  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
485 #define ASSERT_STRNE(expected, actual) \
486  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
487 
488 #define EXPECT_STREQ(expected, actual) \
489  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
490 #define EXPECT_STRNE(expected, actual) \
491  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
492 
493 #define ASSERT_STRCASEEQ(expected, actual) \
494  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
495 #define ASSERT_STRCASENE(expected, actual) \
496  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
497 
498 #define EXPECT_STRCASEEQ(expected, actual) \
499  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
500 #define EXPECT_STRCASENE(expected, actual) \
501  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
502 
503 // NOTE: not implemented, it will be complicated because of locale
504 // ASSERT_STRCASEEQ
505 // ASSERT_STRCASENE
506 
507 #define ASSERT_FLOAT_EQ(expected, actual) \
508  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
509 #define ASSERT_DOUBLE_EQ(expected, actual) \
510  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
511 
512 #define EXPECT_FLOAT_EQ(expected, actual) \
513  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
514 #define EXPECT_DOUBLE_EQ(expected, actual) \
515  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
516 
517 #define ASSERT_NEAR(val1, val2, abs_error) \
518  switch (0) \
519  case 0: \
520  default: \
521  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
522  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
523  ; \
524  else \
525  NLIB_TESTING_FATAL_ = \
526  ::nlib_ns::testing::NearFailMessage(&nlib_ar_tmp_, __FILE__, __LINE__, #val1, \
527  #val2, #abs_error, val1, val2, abs_error)
528 
529 #define EXPECT_NEAR(val1, val2, abs_error) \
530  switch (0) \
531  case 0: \
532  default: \
533  if (::nlib_ns::testing::AssertionResult nlib_ar_tmp_ = \
534  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
535  ; \
536  else \
537  NLIB_TESTING_NONFATAL_ = \
538  ::nlib_ns::testing::NearFailMessage(&nlib_ar_tmp_, __FILE__, __LINE__, #val1, \
539  #val2, #abs_error, val1, val2, abs_error)
540 
541 #define SCOPED_TRACE(msg) \
542  ::nlib_ns::testing::ScopedTrace NLIB_TESTING_CONCAT_TOKEN_(nlib_scopedtrace_, __LINE__)( \
543  ::nlib_ns::testing::AssertionResult(true) << (msg), __FILE__, __LINE__)
544 
545 #define ASSERT_NO_FATAL_FAILURE(statement) \
546  switch (0) \
547  case 0: \
548  default: \
549  for (;;) { \
550  statement; \
551  break; \
552  } \
553  if (!::nlib_ns::testing::UnitTest::GetInstance() \
554  ->current_test_info() \
555  ->result() \
556  ->HasFatalFaiulre()) \
557  ; \
558  else \
559  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::AssertionResult(false) \
560  << "Expected: " #statement \
561  " doesn't generate new fatal failures.\n" \
562  " Actual: it does.\n"
563 
564 #define EXPECT_NO_FATAL_FAILURE(statement) \
565  switch (0) \
566  case 0: \
567  default: \
568  for (;;) { \
569  statement; \
570  break; \
571  } \
572  if (!::nlib_ns::testing::UnitTest::GetInstance() \
573  ->current_test_info() \
574  ->result() \
575  ->HasFatalFaiulre()) \
576  ; \
577  else \
578  NLIB_TESTING_NONFATAL_ = ::nlib_ns::testing::AssertionResult(false) \
579  << "Expected: " #statement \
580  " doesn't generate new fatal failures.\n" \
581  " Actual: it does.\n"
582 
583 #define GTEST_FLAG(name) NLIB_FLAGS_gtest_##name
584 
585 } // namespace testing
586 NLIB_NAMESPACE_END
587 
588 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
589 #undef NLIB_VIS_PUBLIC
590 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
591 #endif
592 
593 #endif // INCLUDE_NN_NLIB_TESTING_NTEST_H_
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:249
テスト失敗時の表示を制御します。
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:183
virtual void SetUp()
全てのテストの前に1回だけ実行される処理を記述します。
Definition: NTest.h:43
コマンドライン文字列を扱うためのクラスが定義されています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
#define NLIB_FLAGS_DECLARE_bool(opt_name)
別の場所で定義された、NLIB_FLAGS_オプション名、を利用できるようにします。
Definition: Nflags.h:184
uint32_t nlib_utf32_t
char32_tが利用できる場合はchar32_tに、そうでない場合はuint32_tにtypedefされます。 ...
Definition: Platform.h:289
シングルトンが定義されています。
uint16_t nlib_utf16_t
char16_tが利用できる場合はchar16_tに、そうでない場合はuint16_tにtypedefされます。 ...
Definition: Platform.h:288
void InitNintendoTest(int *argc, wchar_t **argv)
テストプログラムのコマンドラインオプションを処理します。
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
Environment * AddGlobalTestEnvironment(Environment *env)
Environment へのポインタを渡して、全てのテストの前と後に実行されるコードを登録します。 ...
開発環境別の設定が書かれるファイルです。
virtual void TearDown()
全てのテストの後に1回だけ実行される処理を記述します。
Definition: NTest.h:44
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:250
#define NLIB_STATIC_ASSERT(exp)
静的アサートが定義されます。利用可能であればstatic_assertを利用します。
Definition: Config.h:174
#define NLIB_FLAGS_DECLARE_string(opt_name)
別の場所で定義された、NLIB_FLAGS_オプション名、を利用できるようにします。
Definition: Nflags.h:187
このクラスを継承してグローバルに実行される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:185