nlib
NTest.h
Go to the documentation of this file.
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 #include <string>
9 
10 #include "nn/nlib/Config.h"
12 #include "nn/nlib/UniquePtr.h"
14 #include "nn/nlib/Nflags.h"
15 
16 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
17 #undef NLIB_VIS_PUBLIC
18 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
19 #endif
20 
21 // NOTE:
22 // The implementation does not need std::iostream(ostream).
23 // std::string is needed.
24 NLIB_NAMESPACE_BEGIN
25 namespace testing {
26 
27 NLIB_VIS_PUBLIC void InitNintendoTest(int* argc, char** argv);
28 NLIB_VIS_PUBLIC void InitNintendoTest(int* argc, wchar_t** argv);
29 
31  public:
32  virtual ~Environment() {}
33  virtual void SetUp() {}
34  virtual void TearDown() {}
35 };
36 
37 NLIB_VIS_PUBLIC Environment* AddGlobalTestEnvironment(Environment* env);
38 
39 // The current test result must be accessible globally.
40 struct NLIB_VIS_PUBLIC TestResult {
41  bool HasFatalFaiulre() const { return is_fatal_error; } // gtest
42  bool HasNonfatalFailure() const { return is_non_fatal_error; } // gtest
43 
44  bool is_disabled;
45  bool is_done;
46  bool is_fatal_error;
47  bool is_non_fatal_error;
48 
49  // NOTE:
50  // NO CONSTRUCTOR
51  // The values are set by TestInfo::AddTestInfo() before main function.
52  // If there is a constuctor, the constructor may be invoked
53  // after TestInfo::AddTestInfo() executed.
54 };
55 
56 class Test;
57 class NLIB_VIS_PUBLIC TestFactoryBase {
58  public:
59  virtual ~TestFactoryBase() {}
60  virtual Test* Create() = 0;
61 
62  protected:
63  TestFactoryBase() {}
64 
65  private:
66  NLIB_DISALLOW_COPY_AND_ASSIGN(TestFactoryBase);
67 };
68 
69 template <class TestClass>
70 class TestFactory : public TestFactoryBase {
71  public:
72  TestFactory() {}
73  virtual Test* Create() NLIB_OVERRIDE {
74  NLIB_STATIC_ASSERT(sizeof(TestClass));
75  return new TestClass;
76  }
77 
78  private:
79  NLIB_DISALLOW_COPY_AND_ASSIGN(TestFactory);
80 };
81 
82 class NLIB_VIS_PUBLIC TestInfo NLIB_FINAL {
83  public:
84  TestInfo();
85  ~TestInfo();
86  const char* test_case_name() const { return m_TestCaseName; } // gtest
87  const char* name() const { return m_TestName; } // gtest
88  const TestResult* result() const { return &m_Result; } // gtest
89  static int Run();
90 
91  public:
92  typedef void (*SetUpTestCaseFunc)();
93  typedef void (*TearDownTestCaseFunc)();
94  template <class TestClass>
95  static TestInfo* AddTestInfo(const char* test_case, const char* test_name, int index,
96  SetUpTestCaseFunc setup_func, TearDownTestCaseFunc teardown_func);
97 
98  private:
99  static const int kMaxTestList = 4096;
100  static TestInfo m_TestList[kMaxTestList];
101  static int m_TestListIdx;
102 
103  private:
104  bool RunTest();
105  bool TestCaseNameLess(const TestInfo& rhs) const {
106  int tmp = strcmp(m_TestCaseName, rhs.m_TestCaseName);
107  if (tmp < 0) return true;
108  if (tmp > 0) return false;
109  return m_Index < rhs.m_Index;
110  }
111  bool TestCaseNameEq(const TestInfo& rhs) const {
112  return m_Index == rhs.m_Index &&
113  strcmp(m_TestCaseName, rhs.m_TestCaseName) == 0;
114  }
115  bool IsTypedTest() const { return m_Index >= 0; }
116  int GetTypedTestVariant() const { return m_Index < 0 ? 0 : m_Index; }
117  struct TestSortPred {
118  bool operator()(TestInfo* lhs, TestInfo* rhs) {
119  return lhs->TestCaseNameLess(*rhs);
120  }
121  };
122 
123  private:
124  static TestInfo& AddTestInfo_(const char* test_case, const char* test_name, int index,
125  SetUpTestCaseFunc setup_func,
126  TearDownTestCaseFunc teardown_func);
127 
128  private:
129  friend class FollowMessageTerminator;
130  const char* m_TestCaseName;
131  const char* m_TestName;
132  int m_Index; // -1 if not TYPED_TEST_CASE
133  TestFactoryBase* m_Factory;
134  void (*m_SetUpTestCase)();
135  void (*m_TearDownTestCase)();
136  TestResult m_Result;
137  double m_TestFactorySpace[2];
139 };
140 
141 template <class TestClass>
142 TestInfo* TestInfo::AddTestInfo(const char* test_case, const char* test_name, int index,
143  SetUpTestCaseFunc setup_func, TearDownTestCaseFunc teardown_func) {
144  // NOTE:
145  // This function is executed before main function to register the tests.
146  // DYNAMIC MEMORY ALLOCATION CANNOT BE PERFORMED in this function.
147  // Some environments may initialize its heap in main function.
148  TestInfo& info = AddTestInfo_(test_case, test_name, index, setup_func, teardown_func);
149  void* p = &info.m_TestFactorySpace[0];
150  new (p) TestFactory<TestClass>();
151 
152  // NOTE:
153  // We use type 'char*' to avoid
154  // "warning: dereferencing type-punned pointer will break strict-aliasing rules"
155  // on GCC. This is better than using -fno-strict-aliasing.
156  char* tmpptr = reinterpret_cast<char*>(&info.m_TestFactorySpace[0]);
157  info.m_Factory = reinterpret_cast<TestFactoryBase*>(tmpptr);
158 
159  return &info;
160 }
161 
162 class NLIB_VIS_PUBLIC UnitTest NLIB_FINAL {
163  // This code does nothing. it is only for source code compatibility with gtest.
164  public:
165  static UnitTest* GetInstance();
166 
167  // const char* original_working_dir() const;
168  // const TestCase* current_test_case() const;
169 
170  const TestInfo* current_test_info() const { return m_Current; }
171 
172  // int random_seed() const;
173 
174  /*
175  int successful_test_case_count() const;
176  int failed_test_case_count() const;
177  int total_test_case_count() const;
178  int test_case_to_run_count() const;
179  int successful_test_count() const;
180  int failed_test_count() const;
181  int disabled_test_count() const;
182  int total_test_count() const;
183  int test_to_run_count() const;
184  int32_t elapsed_time() const;
185  bool Passed() const;
186  bool Failed() const;
187  */
188 
189  private:
190  TestInfo* m_Current;
191 
192  private:
193  friend class TestInfo;
194  friend class SimpleSingleton<UnitTest>;
195  friend class FollowMessageTerminator;
196  UnitTest() : m_Current(NULL) {}
197  virtual ~UnitTest() {}
198 
200 };
201 
202 class NLIB_VIS_PUBLIC Test {
203  public:
204  static void SetUpTestCase() {}
205  static void TearDownTestCase() {}
206 
207  Test();
208  virtual ~Test();
209  void Run();
210  void RecordProperty(const char* key, const char* value);
211  void RecordProperty(const char* key, int value);
212 
213  protected:
214  virtual void SetUp() {}
215  virtual void TearDown() {}
216  virtual void TestBody() = 0;
217 
218  private:
220 };
221 
222 class StringBuilder NLIB_FINAL {
223  public:
224  NLIB_VIS_PUBLIC StringBuilder();
225  NLIB_VIS_PUBLIC StringBuilder& append(const std::string& str);
226  NLIB_VIS_PUBLIC const std::string& str() const;
227 
228  private:
229  mutable std::string m_Main;
230  mutable std::string m_Scratch;
231  static const std::string::size_type kScratchSize = 1024;
232  NLIB_DISALLOW_COPY_AND_ASSIGN(StringBuilder);
233 };
234 
235 class AssertionResult NLIB_FINAL {
236  public:
237  NLIB_VIS_PUBLIC explicit AssertionResult(bool result);
238  NLIB_VIS_PUBLIC ~AssertionResult();
239  NLIB_VIS_PUBLIC AssertionResult(const AssertionResult& rhs);
240 
241  operator bool() const { return m_Success; }
242  AssertionResult operator!() const { return AssertionResult(!m_Success); }
243  NLIB_VIS_PUBLIC const std::string& str() const;
244 
245  template <class T>
246  AssertionResult& operator<<(const T& rhs) {
247  if (!m_Builder) m_Builder.reset(new StringBuilder);
248  m_Builder->append(PrintToString(rhs));
249  return *this;
250  }
251  NLIB_VIS_PUBLIC AssertionResult& operator<<(AssertionResult& rhs); // NOLINT
252  private:
253  bool m_Success;
254  mutable ::nlib_ns::UniquePtr<StringBuilder> m_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); // NOLINT
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 inline bool suppress_warning_(bool b) { return b; }
283 NLIB_VIS_PUBLIC AssertionResult BooleanFailMessage(const char* file, int line, const char* expr,
284  const char* actual, const char* expected);
285 #define NLIB_TESTING_BOOLEAN_IMPL_(expr, expected, actual, iffail) \
286  switch (0) \
287  case 0: \
288  default: \
289  if (::nlib_ns::testing::suppress_warning_(expr)) \
290  ; \
291  else \
292  iffail = \
293  ::nlib_ns::testing::BooleanFailMessage(__FILE__, __LINE__, #expr, #actual, #expected)
294 
295 NLIB_VIS_PUBLIC AssertionResult CompFailMessage(const char* file, int line, const char* expr1,
296  const char* expr2, const std::string& val1,
297  const std::string& val2, const char* op);
298 #define NLIB_TESTING_COMP_IMPL_(func_name, op) \
299 template<class T1, class T2> \
300 AssertionResult Comp##func_name(const char* expr1, const char* expr2, const T1& val1, \
301  const T2& val2, const char* file, int line) { \
302  if (val1 op val2) { \
303  return AssertionResult(true); \
304  } else { \
305  return CompFailMessage(file, line, expr1, expr2, PrintToString(val1), \
306  PrintToString(val2), #op); \
307  } \
308 } \
309 NLIB_VIS_PUBLIC AssertionResult Comp##func_name(const char* expr1, const char* expr2, \
310  int64_t val1, int64_t val2, \
311  const char* file, int line)
312 
313 NLIB_TESTING_COMP_IMPL_(EQ, ==);
314 NLIB_TESTING_COMP_IMPL_(NE, !=);
315 NLIB_TESTING_COMP_IMPL_(LE, <=);
316 NLIB_TESTING_COMP_IMPL_(LT, <);
317 NLIB_TESTING_COMP_IMPL_(GE, >=);
318 NLIB_TESTING_COMP_IMPL_(GT, >);
319 
320 #undef NLIB_TESTING_COMP_IMPL_
321 
322 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const char* val1,
323  const char* val2, const char* file, int line);
324 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const char* val1,
325  const char* val2, const char* file, int line);
326 
327 NLIB_VIS_PUBLIC AssertionResult CompStrEq(const char* expr1, const char* expr2, const wchar_t* val1,
328  const wchar_t* val2, const char* file, int line);
329 NLIB_VIS_PUBLIC AssertionResult CompStrNe(const char* expr1, const char* expr2, const wchar_t* val1,
330  const wchar_t* val2, const char* file, int line);
331 
332 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
333  const char* val1, const char* val2,
334  const char* file, int line);
335 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
336  const char* val1, const char* val2,
337  const char* file, int line);
338 
339 NLIB_VIS_PUBLIC AssertionResult CompStrCaseEq(const char* expr1, const char* expr2,
340  const wchar_t* val1, const wchar_t* val2,
341  const char* file, int line);
342 NLIB_VIS_PUBLIC AssertionResult CompStrCaseNe(const char* expr1, const char* expr2,
343  const wchar_t* val1, const wchar_t* val2,
344  const char* file, int line);
345 
346 NLIB_VIS_PUBLIC AssertionResult CompFloatEq(const char* expr1, const char* expr2, float val1,
347  float val2, const char* file, int line);
348 NLIB_VIS_PUBLIC AssertionResult CompDoubleEq(const char* expr1, const char* expr2, double val1,
349  double val2, const char* file, int line);
350 NLIB_VIS_PUBLIC AssertionResult NearDouble(double val1, double val2, double abs_error);
351 
352 // NOTE: PRE05-C. Understand macro replacement
353 // when concatenating tokens or performing stringification
354 #define NLIB_TESTING_CONCAT_TOKEN_(a, b) NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b)
355 #define NLIB_TESTING_CONCAT_TOKEN_IMPL_(a, b) a##b
356 
357 #define NLIB_TESTING_FATAL_ return ::nlib_ns::testing::FollowMessageTerminator(true)
358 #define NLIB_TESTING_NONFATAL_ ::nlib_ns::testing::FollowMessageTerminator(false)
359 
360 #define NLIB_TESTING_ASSERT_HELPER_(func, val1, val2) \
361  switch (0) \
362  case 0: \
363  default: \
364  if (::nlib_ns::testing::AssertionResult ar = \
365  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
366  ; \
367  else \
368  NLIB_TESTING_FATAL_ = ar
369 
370 #define NLIB_TESTING_EXPECT_HELPER_(func, val1, val2) \
371  switch (0) \
372  case 0: \
373  default: \
374  if (::nlib_ns::testing::AssertionResult ar = \
375  func(#val1, #val2, val1, val2, __FILE__, __LINE__)) \
376  ; \
377  else \
378  NLIB_TESTING_NONFATAL_ = ar
379 
380 #define NLIB_TESTING_CLASS_NAME_(test_case, test_name) test_case##_##test_name##_Test
381 
382 #define NLIB_TEST_(test_case, test_name, parent) \
383 class NLIB_TESTING_CLASS_NAME_(test_case, test_name) \
384  : public parent { \
385 public: \
386  NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
387 private: \
388  virtual void TestBody(); \
389  static ::nlib_ns::testing::TestInfo* m_Info; \
390  NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
391 }; \
392 ::nlib_ns::testing::TestInfo* NLIB_TESTING_CLASS_NAME_(test_case, test_name)::m_Info = \
393  ::nlib_ns::testing::TestInfo::AddTestInfo< \
394  NLIB_TESTING_CLASS_NAME_(test_case, test_name)>( \
395  #test_case, #test_name, -1, parent::SetUpTestCase, parent::TearDownTestCase); \
396 void NLIB_TESTING_CLASS_NAME_(test_case, test_name)::TestBody()
397 
398 NLIB_VIS_PUBLIC AssertionResult& NearFailMessage(AssertionResult* ar, const char* file, int line,
399  const char* expr1, const char* expr2,
400  const char* abs_error_expr, double val1,
401  double val2, double abs_error);
402 
403 NLIB_VIS_PUBLIC AssertionResult
404  FloatLE(const char* expr1, const char* expr2, float val1, float val2);
405 NLIB_VIS_PUBLIC AssertionResult
406  DoubleLE(const char* expr1, const char* expr2, double val1, double val2);
407 NLIB_VIS_PUBLIC AssertionResult AssertionSuccess();
408 NLIB_VIS_PUBLIC AssertionResult AssertionFailure();
409 NLIB_VIS_PUBLIC AssertionResult Message();
410 
411 #define NLIB_TESTING_FLAG(flag_name) NLIB_FLAGS_##flag_name
412 
415 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_break_on_failure);
416 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_also_run_disabled_tests);
420 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_int32(gtest_random_seed);
421 NLIB_VIS_PUBLIC NLIB_FLAGS_DECLARE_bool(gtest_print_time);
422 
423 } // namespace testing
424 NLIB_NAMESPACE_END
425 
426 NLIB_NAMESPACE_BEGIN
427 namespace testing {
428 #define TEST(test_case_name, specific_test_name) \
429  NLIB_TEST_(test_case_name, specific_test_name, ::nlib_ns::testing::Test)
430 #define TEST_F(test_fixture_name, specific_test_name) \
431  NLIB_TEST_(test_fixture_name, specific_test_name, test_fixture_name)
432 
433 #define FRIEND_TEST(test_case, test_name) \
434  friend class NLIB_TESTING_CLASS_NAME_(test_case, test_name)
435 
436 #define RUN_ALL_TESTS() ::nlib_ns::testing::TestInfo::Run()
437 
438 #define FAIL() \
439  return ::nlib_ns::testing::FollowMessageTerminator(true) = \
440  ::nlib_ns::testing::AssertionResult(false)
441 #define SUCCEED()
442 
443 #define ASSERT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_FATAL_)
444 #define ASSERT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_FATAL_)
445 #define EXPECT_TRUE(expr) NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_NONFATAL_)
446 #define EXPECT_FALSE(expr) NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_NONFATAL_)
447 
448 #define ASSERT_EQ(expected, actual) \
449  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
450 #define ASSERT_NE(expected, actual) \
451  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
452 #define ASSERT_LE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
453 #define ASSERT_LT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
454 #define ASSERT_GE(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
455 #define ASSERT_GT(val1, val2) NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
456 
457 #define EXPECT_EQ(expected, actual) \
458  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
459 #define EXPECT_NE(expected, actual) \
460  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
461 #define EXPECT_LE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
462 #define EXPECT_LT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
463 #define EXPECT_GE(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
464 #define EXPECT_GT(val1, val2) NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
465 
466 #define ASSERT_STREQ(expected, actual) \
467  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
468 #define ASSERT_STRNE(expected, actual) \
469  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
470 
471 #define EXPECT_STREQ(expected, actual) \
472  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
473 #define EXPECT_STRNE(expected, actual) \
474  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
475 
476 #define ASSERT_STRCASEEQ(expected, actual) \
477  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
478 #define ASSERT_STRCASENE(expected, actual) \
479  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
480 
481 #define EXPECT_STRCASEEQ(expected, actual) \
482  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
483 #define EXPECT_STRCASENE(expected, actual) \
484  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
485 
486 // NOTE: not implemented, it will be complicated because of locale
487 // ASSERT_STRCASEEQ
488 // ASSERT_STRCASENE
489 
490 #define ASSERT_FLOAT_EQ(expected, actual) \
491  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
492 #define ASSERT_DOUBLE_EQ(expected, actual) \
493  NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
494 
495 #define EXPECT_FLOAT_EQ(expected, actual) \
496  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
497 #define EXPECT_DOUBLE_EQ(expected, actual) \
498  NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
499 
500 #define ASSERT_NEAR(val1, val2, abs_error) \
501  switch (0) \
502  case 0: \
503  default: \
504  if (::nlib_ns::testing::AssertionResult ar = \
505  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
506  ; \
507  else \
508  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::NearFailMessage( \
509  &ar, __FILE__, __LINE__, #val1, #val2, #abs_error, val1, val2, abs_error)
510 
511 #define EXPECT_NEAR(val1, val2, abs_error) \
512  switch (0) \
513  case 0: \
514  default: \
515  if (::nlib_ns::testing::AssertionResult ar = \
516  ::nlib_ns::testing::NearDouble(val1, val2, abs_error)) \
517  ; \
518  else /* NOLINT */ \
519  NLIB_TESTING_NONFATAL_ = ::nlib_ns::testing::NearFailMessage( \
520  &ar, __FILE__, __LINE__, #val1, #val2, #abs_error, val1, val2, abs_error)
521 
522 #define SCOPED_TRACE(msg) \
523  ::nlib_ns::testing::ScopedTrace NLIB_TESTING_CONCAT_TOKEN_(nlib_scopedtrace_, __LINE__)( \
524  ::nlib_ns::testing::AssertionResult(true) << (msg), __FILE__, __LINE__)
525 
526 #define ASSERT_NO_FATAL_FAILURE(statement) \
527  switch (0) \
528  case 0: \
529  default: \
530  for (;;) { \
531  statement; \
532  break; \
533  } \
534  if (!::nlib_ns::testing::UnitTest::GetInstance() \
535  ->current_test_info() \
536  ->result() \
537  ->HasFatalFaiulre()) \
538  ; \
539  else /* NOLINT */ \
540  NLIB_TESTING_FATAL_ = ::nlib_ns::testing::AssertionResult(false) \
541  << "Expected: " #statement \
542  " doesn't generate new fatal failures.\n" \
543  " Actual: it does.\n"
544 
545 #define EXPECT_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_NONFATAL_ = ::nlib_ns::testing::AssertionResult(false) \
560  << "Expected: " #statement \
561  " doesn't generate new fatal failures.\n" \
562  " Actual: it does.\n"
563 
564 #define GTEST_FLAG(name) NLIB_FLAGS_gtest_##name
565 
566 } // namespace testing
567 NLIB_NAMESPACE_END
568 
569 #if defined(_MSC_VER) && defined(nx_testing_EXPORTS)
570 #undef NLIB_VIS_PUBLIC
571 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
572 #endif
573 
574 #endif // INCLUDE_NN_NLIB_TESTING_NTEST_H_
Controls display when tests fails.
AssertionResult FloatLE(const char *expr1, const char *expr2, float val1, float val2)
Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:126
virtual void SetUp()
Writes the process to execute only once before all tests.
Definition: NTest.h:33
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Defines that class that is corresponding to std::unique_ptr.
Defines the class for handling command line strings.
#define NLIB_FLAGS_DECLARE_bool(opt_name)
Enables the use of an NLIB_FLAGS_option name that was defined in a different place.
Definition: Nflags.h:122
Defines a singleton.
void InitNintendoTest(int *argc, wchar_t **argv)
Processes command-line options for the test program.
Environment * AddGlobalTestEnvironment(Environment *env)
Passes the pointer to Environment and registers the code to run before and after all tests...
A file that contains the configuration information for each development environment.
virtual void TearDown()
Writes the process to execute only once after all tests.
Definition: NTest.h:34
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
#define NLIB_STATIC_ASSERT(exp)
Defines a static assertion. Uses static_assert if it is available for use.
Definition: Config.h:117
#define NLIB_FLAGS_DECLARE_string(opt_name)
Enables the use of an NLIB_FLAGS_option name that was defined in a different place.
Definition: Nflags.h:125
Defines the SetUp and TearDown functions that inherit this class and are run globally.
Definition: NTest.h:30
AssertionResult DoubleLE(const char *expr1, const char *expr2, double val1, double val2)
Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2.
#define NLIB_FLAGS_DECLARE_int32(opt_name)
Enables the use of an NLIB_FLAGS_option name that was defined in a different place.
Definition: Nflags.h:123