OpenImageIO
 All Classes Files Friends Macros Pages
unittest.h
1  /*
2  Copyright 2010 Larry Gritz and the other authors and contributors.
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
7  met:
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 the software's owners nor the names of its
14  contributors may be used to endorse or promote products derived from
15  this software without specific prior written permission.
16  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28  (This is the Modified BSD License)
29 */
30 
31 #ifndef OPENIMAGEIO_UNITTEST_H
32 #define OPENIMAGEIO_UNITTEST_H
33 
34 #include <iostream>
35 
36 
37 static int unit_test_failures = 0;
38 
43 #define OIIO_CHECK_ASSERT(x) \
44  ((x) ? ((void)0) \
45  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
46  << "FAILED: " << #x << "\n"), \
47  (void)++unit_test_failures))
48 
49 #define OIIO_CHECK_EQUAL(x,y) \
50  (((x) == (y)) ? ((void)0) \
51  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
52  << "FAILED: " << #x << " == " << #y << "\n" \
53  << "\tvalues were '" << (x) << "' and '" << (y) << "'\n"), \
54  (void)++unit_test_failures))
55 
56 #define OIIO_CHECK_EQUAL_THRESH(x,y,eps) \
57  ((std::abs((x)-(y)) <= eps) ? ((void)0) \
58  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
59  << "FAILED: " << #x << " == " << #y << "\n" \
60  << "\tvalues were '" << (x) << "' and '" << (y) << "'" \
61  << ", diff was " << std::abs((x)-(y)) << "\n"), \
62  (void)++unit_test_failures))
63 
64 #define OIIO_CHECK_NE(x,y) \
65  (((x) != (y)) ? ((void)0) \
66  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
67  << "FAILED: " << #x << " != " << #y << "\n" \
68  << "\tvalues were '" << (x) << "' and '" << (y) << "'\n"), \
69  (void)++unit_test_failures))
70 
71 #define OIIO_CHECK_LT(x,y) \
72  (((x) < (y)) ? ((void)0) \
73  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
74  << "FAILED: " << #x << " < " << #y << "\n" \
75  << "\tvalues were '" << (x) << "' and '" << (y) << "'\n"), \
76  (void)++unit_test_failures))
77 
78 #define OIIO_CHECK_GT(x,y) \
79  (((x) > (y)) ? ((void)0) \
80  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
81  << "FAILED: " << #x << " > " << #y << "\n" \
82  << "\tvalues were '" << (x) << "' and '" << (y) << "'\n"), \
83  (void)++unit_test_failures))
84 
85 #define OIIO_CHECK_LE(x,y) \
86  (((x) <= (y)) ? ((void)0) \
87  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
88  << "FAILED: " << #x << " <= " << #y << "\n" \
89  << "\tvalues were '" << (x) << "' and '" << (y) << "'\n"), \
90  (void)++unit_test_failures))
91 
92 #define OIIO_CHECK_GE(x,y) \
93  (((x) >= (y)) ? ((void)0) \
94  : ((std::cout << __FILE__ << ":" << __LINE__ << ":\n" \
95  << "FAILED: " << #x << " >= " << #y << "\n" \
96  << "\tvalues were '" << (x) << "' and '" << (y) << "'\n"), \
97  (void)++unit_test_failures))
98 
99 
100 
101 #endif /* OPENIMAGEIO_UNITTEST_H */
102