nlib
ParamType.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_TESTING_PARAMTYPE_H_
4 #define INCLUDE_NN_NLIB_TESTING_PARAMTYPE_H_
5 
6 #include "nn/nlib/Config.h"
8 #include "nn/nlib/testing/ParamTypeTypes.h"
9 
10 NLIB_NAMESPACE_BEGIN
11 namespace testing {
12 
13 template <template <class Tmpl> class TEST_CASE, class LIST> // NOLINT
14 class TypedTestLoop {
15  public:
16  static bool AddTestInfo(const char* test_case, const char* test_name, int index) {
17  // NOTE: Executed before main function.
18  // This traverses LIST, and AddTestInfo for each type.
19  typedef typename LIST::Head T;
20  typedef typename LIST::Tail TL;
21  typedef TEST_CASE<T> TestCaseType;
22 
23  ::nlib_ns::testing::TestInfo::AddTestInfo<TestCaseType>(test_case, test_name, index,
24  TestCaseType::SetUpTestCase,
25  TestCaseType::TearDownTestCase);
26  return TypedTestLoop<TEST_CASE, TL>::AddTestInfo(test_case, test_name, index + 1);
27  }
28 };
29 
30 template <template <class Tmpl> class TEST_CASE>
31 class TypedTestLoop<TEST_CASE, Tp0> {
32  public:
33  static bool AddTestInfo(const char* test_case, const char* test_name, int index) {
34  NLIB_UNUSED(test_case);
35  NLIB_UNUSED(test_name);
36  NLIB_UNUSED(index);
37  return true;
38  }
39 };
40 
41 #define NLIB_TESTING_TYPELIST(test_case) ntest_type_params_##test_case##_
42 
43 } // namespace testing
44 NLIB_NAMESPACE_END
45 
46 #define TYPED_TEST_CASE(test_case, types) typedef types::type NLIB_TESTING_TYPELIST(test_case)
47 
48 #define TYPED_TEST(test_case, test_name) \
49 template<class T> \
50 class NLIB_TESTING_CLASS_NAME_(test_case, test_name) \
51  : public test_case<T> { \
52 public: \
53  typedef test_case<T> TestFixture; \
54  typedef T TypeParam; \
55  NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
56 private: \
57  virtual void TestBody(); \
58  NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
59 }; \
60 bool ntest_typed_test_##test_case##test_name##_ = ::nlib_ns::testing::TypedTestLoop< \
61  NLIB_TESTING_CLASS_NAME_(test_case, test_name), \
62  NLIB_TESTING_TYPELIST(test_case)>::AddTestInfo(#test_case, #test_name, 1); \
63 template<class T> \
64 void NLIB_TESTING_CLASS_NAME_(test_case, test_name)<T>::TestBody()
65 
66 #endif // INCLUDE_NN_NLIB_TESTING_PARAMTYPE_H_
開発環境別の設定が書かれるファイルです。
基本的な単体テスト用マクロが定義されています。