1 /*
2 ** SPDX-License-Identifier: BSD-3-Clause
3 ** Copyright Contributors to the OpenEXR Project.
4 */
5
6 #ifndef OPENEXR_CORE_TEST_VALUE_H
7 #define OPENEXR_CORE_TEST_VALUE_H
8
9 #include <cstdlib>
10 #include <iostream>
11
12 static void
core_test_fail(const char * expr,const char * file,unsigned line,const char * func)13 core_test_fail (
14 const char* expr, const char* file, unsigned line, const char* func)
15 {
16 std::cerr << "Core Test failed: " << expr << "\n file:" << file
17 << "\n line:" << line << "\n function:" << func
18 << std::endl;
19 abort ();
20 }
21
22 #ifdef _MSC_VER
23 # define EXRCORE_TEST_FAIL(expr) \
24 core_test_fail (#expr, __FILE__, __LINE__, __FUNCSIG__)
25 #else
26 # define EXRCORE_TEST_FAIL(expr) \
27 core_test_fail (#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__)
28 #endif
29
30 #define EXRCORE_TEST(expr) \
31 (static_cast<bool> (expr)) ? void (0) : EXRCORE_TEST_FAIL (expr)
32
33 #define EXRCORE_TEST_LOCATION(expr, x, y) \
34 { \
35 if (!static_cast<bool> (expr)) \
36 { \
37 std::cerr << "At " << x << ", " << y << ":\n"; \
38 EXRCORE_TEST_FAIL (expr); \
39 } \
40 }
41
42 #define EXRCORE_TEST_RVAL(expr) \
43 { \
44 exr_result_t _test_rv = expr; \
45 if (_test_rv != EXR_ERR_SUCCESS) \
46 { \
47 std::cerr << "Return Error: (" << (int) _test_rv << ") " \
48 << exr_get_default_error_message (_test_rv) \
49 << std::endl; \
50 EXRCORE_TEST_FAIL (expr); \
51 } \
52 }
53
54 #define EXRCORE_TEST_RVAL_FAIL(code, expr) \
55 { \
56 exr_result_t _test_rv = expr; \
57 if (_test_rv != code) \
58 { \
59 std::cerr << "Return Error: (" << (int) _test_rv << ") " \
60 << exr_get_default_error_message (_test_rv) \
61 << "\n expected: (" << (int) (code) << ") " \
62 << exr_get_default_error_message (code) << std::endl; \
63 EXRCORE_TEST_FAIL (expr); \
64 } \
65 }
66
67 #define EXRCORE_TEST_RVAL_FAIL_MALLOC(code, expr) \
68 { \
69 exr_result_t _test_rv; \
70 set_malloc_fail_on (1); \
71 _test_rv = expr; \
72 set_malloc_fail_off (); \
73 if (_test_rv != code) \
74 { \
75 std::cerr << "Return Error: (" << (int) _test_rv << ") " \
76 << exr_get_default_error_message (_test_rv) \
77 << "\n expected: (" << (int) (code) << ") " \
78 << exr_get_default_error_message (code) << std::endl; \
79 EXRCORE_TEST_FAIL (expr); \
80 } \
81 }
82
83 #define EXRCORE_TEST_RVAL_FAIL_MALLOC_AFTER(count, code, expr) \
84 { \
85 exr_result_t _test_rv; \
86 set_malloc_fail_on (1 + count); \
87 _test_rv = expr; \
88 set_malloc_fail_off (); \
89 if (_test_rv != code) \
90 { \
91 std::cerr << "Return Error: (" << (int) _test_rv << ") " \
92 << exr_get_default_error_message (_test_rv) \
93 << "\n expected: (" << (int) (code) << ") " \
94 << exr_get_default_error_message (code) << std::endl; \
95 EXRCORE_TEST_FAIL (expr); \
96 } \
97 }
98
99 #endif // OPENEXR_CORE_TEST_VALUE_H
100