IODA Bundle
TestCase.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file TestCase.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, Feb 2009
14 
15 #ifndef TestCase_H
16 #define TestCase_H
17 
18 #include "Tool.h"
19 #include "ToolFactory.h"
20 
21 namespace odc {
22 namespace tool {
23 namespace test {
24 
25 class TestCase : public Tool {
26 public:
27 
28  static void help(std::ostream &o) { o << "No help available for this command yet"; }
29  static void usage(const std::string& name, std::ostream &o) { o << name << ": Not implemented yet"; }
30  virtual void run();
31 
32  virtual void setUp();
33  virtual void test();
34  virtual void tearDown();
35 
36  virtual ~TestCase();
37 
38 protected:
39  TestCase(int argc, char **argv);
40 };
41 
42 typedef std::vector<TestCase*> TestCases;
43 
44 #define TESTCASE(F) \
45 struct Test_##F : public TestCase { Test_##F(int argc, char **argv) : TestCase(argc, argv) {} void test() { F(); } }; \
46 ToolFactory<Test_##F> test_##F(std::string("Test_") + #F);
47 
48 #define TEST_FIXTURE(F, T) \
49 struct Test_##F##_##T : public F, public odc::tool::test::TestCase \
50 { \
51  Test_##F##_##T(int argc, char **argv) : F(), odc::tool::test::TestCase(argc, argv) {} \
52  void test(); \
53 }; \
54 odc::tool::ToolFactory<Test_##F##_##T> test_##F##_##T(std::string("Test_") + #F + std::string("_") + #T); \
55 void Test_##F##_##T::test()
56 
57 #define TEST(T) \
58 struct Test_##T : public odc::tool::test::TestCase \
59 { \
60  Test_##T(int argc, char **argv) : odc::tool::test::TestCase(argc, argv) {} \
61  void test(); \
62 }; \
63 odc::tool::ToolFactory<Test_##T> test_##T(std::string("Test_") + #T); \
64 void Test_##T::test()
65 
66 #define SIMPLE_TEST(name) \
67 struct Test_##name : public odc::tool::test::TestCase \
68 { \
69  Test_##name(int argc, char **argv) : odc::tool::test::TestCase(argc, argv) {} \
70  void setUp() { ::setUp(); } \
71  void tearDown() { ::tearDown(); } \
72  void test() { ::test(); } \
73 }; \
74 odc::tool::ToolFactory<Test_##name> test_##name(std::string("Test_") + #name);
75 
76 #define CHECK(expected) ASSERT(expected)
77 #define CHECK_EQUAL(expected, actual) ASSERT((expected) == (actual))
78 
79 template <typename Expected, typename Actual>
80 bool CheckArrayEqual(const Expected& expected, const Actual& actual, const int count)
81 {
82  bool equal = true;
83  for (int i = 0; i < count; ++i)
84  equal &= (expected[i] == actual[i]);
85  return equal;
86 }
87 
88 #define CHECK_ARRAY_EQUAL(expected, actual, count) \
89 ASSERT(odc::tool::test::CheckArrayEqual(expected, actual, count))
90 
91 } // namespace test
92 } // namespace tool
93 } // namespace odc
94 
95 #endif
96 
static void count(void *counter, const double *data, size_t n)
Definition: UnitTests.cc:531
std::string name()
Definition: Tool.h:34
virtual void test()
Definition: TestCase.cc:42
virtual void setUp()
Definition: TestCase.cc:41
virtual void tearDown()
Definition: TestCase.cc:43
virtual void run()
Definition: TestCase.cc:32
TestCase(int argc, char **argv)
Definition: TestCase.cc:28
static void help(std::ostream &o)
Definition: TestCase.h:28
static void usage(const std::string &name, std::ostream &o)
Definition: TestCase.h:29
bool CheckArrayEqual(const Expected &expected, const Actual &actual, const int count)
Definition: TestCase.h:80
std::vector< TestCase * > TestCases
Definition: TestCase.h:42
Definition: ColumnInfo.h:23