Back to home page

Enduro/X

 
 

    


0001 #ifndef ASSERTIONS_HEADER
0002 #define ASSERTIONS_HEADER
0003 
0004 #include "internal/assertions_internal.h"
0005 
0006 #include <cgreen/constraint.h>
0007 #ifdef __cplusplus
0008 #include <cgreen/cpp_assertions.h>
0009 #endif
0010 #include <cgreen/reporter.h>
0011 #include <stdint.h>
0012 
0013 #ifndef __cplusplus
0014 #include <stdbool.h>
0015 #endif
0016 
0017 #ifdef __cplusplus
0018 #include <cgreen/cpp_assertions.h>
0019 
0020 namespace cgreen {
0021     extern "C" {
0022 #endif
0023 
0024 /*
0025   Modern style asserts using constraints:
0026 
0027    assert_that(actual, <constraint>(expected));
0028    assert_that(<expression>);
0029 
0030 */
0031 #define assert_that(...) assert_that_NARG(__VA_ARGS__)(__VA_ARGS__)
0032 #define assert_that_double(actual, constraint) assert_that_double_(__FILE__, __LINE__, #actual, (double)actual, constraint)
0033 
0034 #define pass_test() assert_true(true)
0035 #define fail_test(...) assert_true_with_message(false, __VA_ARGS__)
0036 
0037 
0038 /* Utility: */
0039 void significant_figures_for_assert_double_are(int figures);
0040 
0041 
0042 /* Legacy style asserts:*/
0043 #define assert_true(result) \
0044         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, result, "[" #result "] should be true\n", NULL)
0045 #define assert_false(result) \
0046         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, ! result, "[" #result "] should be false\n", NULL)
0047 #define assert_equal(tried, expected) \
0048         assert_equal_(__FILE__, __LINE__, #tried, (intptr_t)tried, (intptr_t)expected)
0049 #define assert_not_equal(tried, expected) \
0050         assert_not_equal_(__FILE__, __LINE__, #tried, (intptr_t)tried, (intptr_t)expected)
0051 #define assert_double_equal(tried, expected) \
0052         assert_double_equal_(__FILE__, __LINE__, #tried, tried, expected)
0053 #define assert_double_not_equal(tried, expected) \
0054         assert_double_not_equal_(__FILE__, __LINE__, #tried, tried, expected)
0055 #define assert_string_equal(tried, expected) \
0056         assert_string_equal_(__FILE__, __LINE__, #tried, tried, expected)
0057 #define assert_string_not_equal(tried, expected) \
0058         assert_string_not_equal_(__FILE__, __LINE__, #tried, tried, expected)
0059 
0060 #define assert_true_with_message(result, ...) \
0061         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, result, __VA_ARGS__)
0062 #define assert_false_with_message(result, ...) \
0063         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, ! result, __VA_ARGS__)
0064 #define assert_equal_with_message(tried, expected, ...) \
0065         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, (tried == expected), __VA_ARGS__)
0066 #define assert_not_equal_with_message(tried, expected, ...) \
0067         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, (tried != expected), __VA_ARGS__)
0068 #define assert_double_equal_with_message(tried, expected, ...) \
0069         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, doubles_are_equal(tried, expected), __VA_ARGS__)
0070 #define assert_double_not_equal_with_message(tried, expected, ...) \
0071         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, doubles_are_equal(tried, expected), __VA_ARGS__)
0072 #define assert_string_equal_with_message(tried, expected, ...) \
0073         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, strings_are_equal(tried, expected), __VA_ARGS__)
0074 #define assert_string_not_equal_with_message(tried, expected, ...) \
0075         (*get_test_reporter()->assert_true)(get_test_reporter(), __FILE__, __LINE__, !strings_are_equal(tried, expected), __VA_ARGS__)
0076 
0077 #ifdef __cplusplus
0078     }
0079 }
0080 #endif
0081 
0082 #endif