test_util.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2012 Equinor ASA, Norway.
3
4 The file 'test_util.h' is part of ERT - Ensemble based Reservoir Tool.
5
6 ERT is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 ERT is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
16 for more details.
17*/
18
19
20#ifndef ERT_TEST_UTIL_H
21#define ERT_TEST_UTIL_H
22
23#include <stdlib.h>
24#include <stdbool.h>
25#include <setjmp.h>
26#include <ert/util/ert_api_config.hpp>
27
28#if defined(__APPLE__)
29#include <wchar.h>
30#include <time.h>
31#endif
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37
38 void test_error_exit( const char * fmt , ...);
39 void * test_argpack_is_stringlist( void * arg );
40 void * thread_pool_test_func1( void * arg );
41
42#define test_exit( fmt, ...) test_exit__( __FILE__ , __LINE__ , fmt , __VA_ARGS__);
43 void test_exit__(const char * file , int line , const char * fmt , ...);
44
45#define test_assert_string_equal( s1 , s2 ) test_assert_string_equal__(s1 , s2 , __FILE__ , __LINE__)
46 void test_assert_string_equal__( const char * s1 , const char * s2 , const char * file , int line);
47#define test_assert_string_not_equal( s1 , s2 ) test_assert_string_not_equal__(s1 , s2 , __FILE__ , __LINE__)
48 void test_assert_string_not_equal__( const char * s1 , const char * s2 , const char * file , int line);
49
50 bool test_check_string_equal( const char *s1 , const char * s2);
51
52#define test_assert_int_equal( i1 , i2 ) test_assert_int_equal__( (i1) , (i2) , __FILE__ , __LINE__ )
53 void test_assert_int_equal__( int i1 , int i2 , const char * file , int line );
54
55#define test_assert_int_not_equal( i1 , i2 ) test_assert_int_not_equal__( (i1) , (i2) , __FILE__ , __LINE__ )
56 void test_assert_int_not_equal__( int i1 , int i2 , const char * file , int line );
57
58#define test_assert_long_equal( i1 , i2 ) test_assert_long_equal__( (i1) , (i2) , __FILE__ , __LINE__ )
59 void test_assert_long_equal__( long i1 , long i2 , const char * file , long line );
60
61#define test_assert_long_not_equal( i1 , i2 ) test_assert_long_not_equal__( (i1) , (i2) , __FILE__ , __LINE__ )
62 void test_assert_long_not_equal__( long i1 , long i2 , const char * file , long line );
63
64#define test_assert_uint_equal( i1 , i2 ) test_assert_uint_equal__( (i1) , (i2) , __FILE__ , __LINE__ )
65 void test_assert_uint_equal__( unsigned int i1 , unsigned int i2 , const char * file , int line );
66
67#define test_assert_uint_not_equal( i1 , i2 ) test_assert_uint_not_equal__( (i1) , (i2) , __FILE__ , __LINE__ )
68 void test_assert_uint_not_equal__( unsigned int i1 , unsigned int i2 , const char * file , int line );
69
70#define test_assert_size_t_equal( s1 , s2 ) test_assert_size_t_equal__( (s1) , (s2) , __FILE__ , __LINE__ )
71 void test_assert_size_t_equal__( size_t s1 , size_t s2 , const char * file , int line );
72
73#define test_assert_size_t_not_equal( s1 , s2 ) test_assert_size_t_not_equal__( (s1) , (s2) , __FILE__ , __LINE__ )
74 void test_assert_size_t_not_equal__( size_t s1 , size_t s2 , const char * file , int line );
75
76
77#define test_assert_double_equal( d1 , d2 ) test_assert_double_equal__( (d1) , (d2) , __FILE__ , __LINE__ )
78 void test_assert_double_equal__( double d1 , double d2 , const char * file , int line );
79 bool test_check_double_equal( double d1 , double d2);
80
81#define test_assert_float_equal( d1 , d2 ) test_assert_float_equal__( (d1) , (d2) , __FILE__ , __LINE__ )
82 void test_assert_float_equal__( float d1 , float d2 , const char * file , int line );
83 bool test_check_float_equal( float d1 , float d2);
84
85#define test_assert_double_not_equal( d1 , d2 ) test_assert_double_not_equal__( (d1) , (d2) , __FILE__ , __LINE__ )
86 void test_assert_double_not_equal__( double d1 , double d2 , const char * file , int line );
87
88#define test_assert_bool_equal( b1 , b2 ) test_assert_bool_equal__( (b1) , (b2) , __FILE__ , __LINE__ )
89 void test_assert_bool_equal__( bool b1 , bool b2 , const char * file , int line);
90
91#define test_assert_bool_not_equal( b1 , b2 ) test_assert_bool_not_equal__( (b1) , (b2) , __FILE__ , __LINE__ )
92 void test_assert_bool_not_equal__( bool b1 , bool b2 , const char * file , int line);
93
94#define test_assert_true( value ) test_assert_true__( (value) , __FILE__ , __LINE__)
95 void test_assert_true__( bool value, const char * file , int line);
96
97#define test_assert_false( value ) test_assert_false__( (value) , __FILE__ , __LINE__)
98 void test_assert_false__( bool value, const char * file , int line);
99
100#define test_assert_time_t_equal( t1 , t2) test_assert_time_t_equal__((t1) , (t2) , __FILE__ , __LINE__)
101 void test_assert_time_t_equal__( time_t t1 , time_t t2 , const char * file , int line);
102
103#define test_assert_time_t_not_equal( t1 , t2) test_assert_time_t_not_equal__((t1) , (t2) , __FILE__ , __LINE__)
104 void test_assert_time_t_not_equal__( time_t t1 , time_t t2 , const char * file , int line);
105
106#define test_assert_ptr_equal( p1 , p2 ) test_assert_ptr_equal__( (p1) , (p2) , __FILE__ , __LINE__)
107 void test_assert_ptr_equal__( const void * p1 , const void * p2 , const char * file , int line);
108
109#define test_assert_ptr_not_equal(p1 , p2) test_assert_ptr_not_equal__( (p1) , (p2) , __FILE__ , __LINE__)
110 void test_assert_ptr_not_equal__( const void * p1 , const void * p2 , const char * file , int line);
111
112#define test_assert_NULL( p ) test_assert_NULL__( (p) , __FILE__ , __LINE__)
113 void test_assert_NULL__( const void * p , const char * file , int line);
114
115#define test_assert_not_NULL( p ) test_assert_not_NULL__( (p) , __FILE__ , __LINE__)
116 void test_assert_not_NULL__( const void * p , const char * file , int line);
117
118#define test_assert_mem_equal( p1 , p2 , byte_size ) test_assert_mem_equal__( (p1) , (p2) , (byte_size), __FILE__ , __LINE__)
119 void test_assert_mem_equal__( const void * p1 , const void * p2 , size_t byte_size , const char * file , int line);
120
121#define test_assert_mem_not_equal( p1 , p2 , byte_size ) test_assert_mem_not_equal__( (p1) , (p2) , (byte_size), __FILE__ , __LINE__)
122 void test_assert_mem_not_equal__( const void * p1 , const void * p2 , size_t byte_size , const char * file , int line);
123
124#define test_assert_file_content( input_file , expected) test_assert_file_content__( input_file , expected , __FILE__ , __LINE__)
125 void test_assert_file_content__( const char * input_file , const char * expected, const char * src_file , int line);
126
128
131 void test_assert_util_abort(const char * function_name , void call_func (void *) , void * arg);
132
133
134#ifdef __cplusplus
135}
136#endif
137
138#ifdef __cplusplus
139
140#define test_assert_throw(expr , exception_type ) \
141 { \
142 bool throw_ok = false; \
143 try { \
144 expr; \
145 } \
146 catch (std::exception &e) { \
147 if (dynamic_cast<exception_type *>(&e)) \
148 throw_ok = true; \
149 } \
150 if (!throw_ok) \
151 test_error_exit("Correct exception not thrown at %s:%d\n",__FILE__ , __LINE__); \
152 }
153
154#define test_assert_std_string_equal(s0, s1) \
155 { \
156 if (s0.compare(s1) != 0) \
157 test_error_exit("Strings not equal at%s:%d (%s != %s)\n", \
158 __FILE__ , __LINE__, s0.c_str(), s1.c_str()); \
159 }
160
161
162#endif
163
164
165#endif
int cJSON_bool fmt
Definition: cJSON.h:158
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955
void test_assert_string_not_equal__(const char *s1, const char *s2, const char *file, int line)
void * test_argpack_is_stringlist(void *arg)
void test_assert_uint_not_equal__(unsigned int i1, unsigned int i2, const char *file, int line)
void test_assert_time_t_not_equal__(time_t t1, time_t t2, const char *file, int line)
void test_assert_string_equal__(const char *s1, const char *s2, const char *file, int line)
void test_assert_false__(bool value, const char *file, int line)
void test_assert_true__(bool value, const char *file, int line)
void test_assert_float_equal__(float d1, float d2, const char *file, int line)
void test_error_exit(const char *fmt,...)
void test_exit__(const char *file, int line, const char *fmt,...)
void test_assert_long_equal__(long i1, long i2, const char *file, long line)
void test_assert_long_not_equal__(long i1, long i2, const char *file, long line)
void test_assert_ptr_equal__(const void *p1, const void *p2, const char *file, int line)
void test_assert_ptr_not_equal__(const void *p1, const void *p2, const char *file, int line)
void test_assert_file_content__(const char *input_file, const char *expected, const char *src_file, int line)
void test_install_SIGNALS(void)
void test_assert_time_t_equal__(time_t t1, time_t t2, const char *file, int line)
void test_util_addr2line()
void test_assert_mem_not_equal__(const void *p1, const void *p2, size_t byte_size, const char *file, int line)
void test_assert_double_not_equal__(double d1, double d2, const char *file, int line)
void test_assert_mem_equal__(const void *p1, const void *p2, size_t byte_size, const char *file, int line)
bool test_check_float_equal(float d1, float d2)
void test_assert_NULL__(const void *p, const char *file, int line)
void test_assert_size_t_equal__(size_t s1, size_t s2, const char *file, int line)
bool test_check_string_equal(const char *s1, const char *s2)
jmp_buf * util_abort_test_jump_buffer()
void * thread_pool_test_func1(void *arg)
void test_assert_size_t_not_equal__(size_t s1, size_t s2, const char *file, int line)
void test_assert_double_equal__(double d1, double d2, const char *file, int line)
void test_assert_not_NULL__(const void *p, const char *file, int line)
void test_assert_bool_equal__(bool b1, bool b2, const char *file, int line)
void test_assert_bool_not_equal__(bool b1, bool b2, const char *file, int line)
bool test_check_double_equal(double d1, double d2)
void test_assert_uint_equal__(unsigned int i1, unsigned int i2, const char *file, int line)
void test_assert_int_equal__(int i1, int i2, const char *file, int line)
void test_assert_util_abort(const char *function_name, void call_func(void *), void *arg)
void test_assert_int_not_equal__(int i1, int i2, const char *file, int line)