SMIL  0.9.1
DTest.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _DTEST_H
31 #define _DTEST_H
32 
33 #include <ctime>
34 #include <iostream>
35 #include <list>
36 #include <sstream>
37 
38 #include "private/DTypes.hpp"
39 #include "DCommon.h"
40 #include "DTime.h"
41 #include "DErrors.h"
42 
43 using namespace std;
44 
45 namespace smil
46 {
47  class TestCase
48  {
49  public:
50  TestCase()
51  : stopIfError(false),
52  outStream(NULL)
53  {
54  }
55  virtual ~TestCase() {}
56  virtual void init() {}
57  virtual void run() = 0;
58  virtual void end() {}
59  const char *name;
60  bool stopIfError;
61  stringstream *outStream;
62  RES_T retVal;
63 #ifdef __clang__
64  SMIL_UNUSED
65 #endif // __clang__
66  int tElapsed;
67  };
68 
69 
70  #define TEST_ASSERT(expr) \
71  { \
72  if (!(expr)) \
73  { \
74  if (outStream) \
75  *outStream << __FILE__ << ":" << __LINE__ << ": error: " << " assert " << #expr << endl; \
76  retVal = RES_ERR; \
77  if (stopIfError) \
78  return; \
79  } \
80  }
81 
82  #define TEST_NO_THROW(expr) \
83  { \
84  bool _throw = false; \
85  try { expr; } \
86  catch(...) { _throw = true; } \
87  if (_throw) \
88  { \
89  if (outStream) \
90  *outStream << __FILE__ << ":" << __LINE__ << ": error: " << " no throw " << #expr << endl; \
91  retVal = RES_ERR; \
92  if (stopIfError) \
93  return; \
94  } \
95  }
96 
97  #define TEST_THROW(expr) \
98  { \
99  bool _throw = false; \
100  try { expr; } \
101  catch(...) { _throw = true; } \
102  if (!_throw) \
103  { \
104  if (outStream) \
105  *outStream << __FILE__ << ":" << __LINE__ << ": error: " << " throw " << #expr << endl; \
106  retVal = RES_ERR; \
107  if (stopIfError) \
108  return; \
109  } \
110  }
111 
112  class TestSuite
113  {
114  public:
115  void add(TestCase *f);
116  int run();
117  private:
118  list<TestCase*> funcList;
119 #ifdef __clang__
120  SMIL_UNUSED
121 #endif // __clang__
122  int tElapsed;
123  };
124 
125 
126  #define ADD_TEST(TS, TC) \
127  TC TC##_inst; \
128  TC##_inst.name = #TC; \
129  TS.add(& TC##_inst);
130 
131 } // namespace smil
132 
133 #endif // _DTEST_H
134 
Definition: DColorConvert.h:38
Definition: DTest.h:112
RES_T add(const Image< T > &imIn1, const Image< T > &imIn2, Image< T > &imOut)
Addition.
Definition: DImageArith.hpp:393
Definition: DTest.h:47