17 #ifndef LIBOPEN_CESTER_H
18 #define LIBOPEN_CESTER_H
36 #ifdef __STDC_VERSION__
37 #define __CESTER_STDC_VERSION__ __STDC_VERSION__
40 #if __cplusplus > 199711L
41 #define __CESTER_STDC_VERSION__ __cplusplus
45 #ifndef __CESTER_STDC_VERSION__
46 #define __CESTER_INLINE__
47 #define __CESTER_LONG_LONG__ long
48 #define __CESTER_LONG_LONG_FORMAT__ "%ld"
50 #define __CESTER_FUNCTION__ __FUNCTION__
52 #define __CESTER_FUNCTION__ "<unknown>"
54 #define CESTER_NULL 0L
57 #define __CESTER_INLINE__ inline
58 #define __CESTER_LONG_LONG__ long long
59 #define __CESTER_LONG_LONG_FORMAT__ "%lld"
60 #define __CESTER_FUNCTION__ __func__
61 #define CESTER_NULL NULL
65 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
66 #define __CESTER_CAST_CHAR_ARRAY__ (unsigned)
68 #define __CESTER_CAST_CHAR_ARRAY__ (char*)
71 #define __CESTER_CAST_CHAR_ARRAY__
74 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
78 #include <sys/types.h>
85 #include <sys/types.h>
87 #ifndef CESTER_NO_SIGNAL
95 #pragma message("__BASE_FILE__ not defined. Define the __BASE_FILE__ directive in Properties -> C/C++ -> Preprocessor -> Preprocessor Definition as __BASE_FILE__=\"%(Filename)%(Extension)\" or register your test cases manually.")
97 #pragma message("__BASE_FILE__ not defined. Define __BASE_FILE__ during compilation. -D__BASE_FILE__=\"/the/path/to/yout/testfile.c\" or register your test cases manually.")
102 #define cester_meta_free(x) free(x); x = CESTER_NULL
104 #if defined __has_include
105 #if !__has_include (__BASE_FILE__)
106 #pragma message("__BASE_FILE__ is not in include directory. Add the option '-I.' for your compiler so it can find the file.")
111 #ifndef CESTER_EXCLUDE_WINDOWS_H
119 #define mkdir(x,y) _mkdir(x)
121 #define stat __stat64
131 #define _WIN32_WINNT 0x502
132 #define EXOTICTYPES_WINDLLEXPORT 1
135 #define EXOTICTYPES_WINDLLEXPORT 0
138 #if EXOTICTYPES_WINDLLEXPORT
139 #define EXOTIC_API __declspec(dllexport)
141 #define EXOTIC_API extern
147 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
149 #define CESTER_RESET_TERMINAL 15
150 #define CESTER_BOLD 15
151 #define CESTER_FOREGROUND_BLACK 8
152 #define CESTER_FOREGROUND_RED 4
153 #define CESTER_FOREGROUND_GREEN 2
154 #define CESTER_FOREGROUND_YELLOW 6
155 #define CESTER_FOREGROUND_BLUE 3
156 #define CESTER_FOREGROUND_MAGENTA 5
157 #define CESTER_FOREGROUND_CYAN 11
158 #define CESTER_FOREGROUND_WHITE 15
159 #define CESTER_FOREGROUND_GRAY 8
160 #define CESTER_BACKGROUND_BLACK 0
161 #define CESTER_BACKGROUND_RED 64
162 #define CESTER_BACKGROUND_GREEN 39
163 #define CESTER_BACKGROUND_YELLOW 96
164 #define CESTER_BACKGROUND_BLUE 48
165 #define CESTER_BACKGROUND_MAGENTA 87
166 #define CESTER_BACKGROUND_CYAN 176
167 #define CESTER_BACKGROUND_GRAY 0
168 #define CESTER_BACKGROUND_WHITE 10
169 #define CESTER_RESET_TERMINAL_ATTR() SetConsoleTextAttribute(cester_hConsole, cester_default_color);
173 #define CESTER_RESET_TERMINAL "\x1B[0m"
174 #define CESTER_BOLD "\x1B[1m"
175 #define CESTER_FOREGROUND_BLACK "\x1B[30m"
176 #define CESTER_FOREGROUND_RED "\x1B[31m"
177 #define CESTER_FOREGROUND_GREEN "\x1B[32m"
178 #define CESTER_FOREGROUND_YELLOW "\x1B[33m"
179 #define CESTER_FOREGROUND_BLUE "\x1B[34m"
180 #define CESTER_FOREGROUND_MAGENTA "\x1B[35m"
181 #define CESTER_FOREGROUND_CYAN "\x1B[36m"
182 #define CESTER_FOREGROUND_WHITE "\x1B[37m"
183 #define CESTER_FOREGROUND_GRAY "\x1B[90m"
184 #define CESTER_BACKGROUND_BLACK "\x1B[40m"
185 #define CESTER_BACKGROUND_RED "\x1B[41m"
186 #define CESTER_BACKGROUND_GREEN "\x1B[42m"
187 #define CESTER_BACKGROUND_YELLOW "\x1B[43m"
188 #define CESTER_BACKGROUND_BLUE "\x1B[44m"
189 #define CESTER_BACKGROUND_MAGENTA "\x1B[45m"
190 #define CESTER_BACKGROUND_CYAN "\x1B[46m"
191 #define CESTER_BACKGROUND_GRAY "\x1B[100m"
192 #define CESTER_BACKGROUND_WHITE "\x1B[47m"
193 #define CESTER_RESET_TERMINAL_ATTR() ;
200 #define CESTER_VERSION "0.4"
205 #define CESTER_VERSION_NUM 0.4
210 #define CESTER_LICENSE "MIT License"
215 #define CESTER_AUTHOR "Adewale Azeez and other contributors"
220 #define CESTER_HASH_SIGN #
225 #define CESTER_CONCAT(x, y) x y
252 #ifndef CESTER_NO_MEM_TEST
272 #ifndef CESTER_NO_STREAM_CAPTURE
328 #ifndef CESTER_NO_TIME
340 #ifndef CESTER_NO_MEM_TEST
357 #define CESTER_ARRAY_INITIAL_CAPACITY 30
364 #define CESTER_ARRAY_MAX_CAPACITY ((size_t) - 5)
373 #define CESTER_ARRAY_FOREACH(w,x,y,z) for (x = 0; x < w->size; ++x) {\
374 void* y = w->buffer[x];\
406 #ifndef CESTER_NO_TIME
413 #ifndef CESTER_NO_STREAM_CAPTURE
418 #ifndef CESTER_NO_STREAM_CAPTURE
426 #ifndef CESTER_NO_MEM_TEST
438 static __CESTER_INLINE__ void cester_str_value_after_first(
char *,
char,
char**);
464 #ifndef CESTER_NO_TIME
470 (
char*)__BASE_FILE__,
475 #ifndef CESTER_NO_STREAM_CAPTURE
477 (
char*)
"./build/libcester/captured_streams/",
480 #ifndef CESTER_NO_STREAM_CAPTURE
488 #ifndef CESTER_NO_MEM_TEST
494 #define cester_sprintf(x,y,z,a,b,c) sprintf_s(x, y, z, a, b, c);
495 #define cester_sprintf1(x,y,z,a) cester_sprintf(x,y,z,a,"","")
496 #define cester_sprintf2(x,y,z,a,b) cester_sprintf(x,y,z,a,b,"")
497 #define cester_sprintf3(x,y,z,a,b,c) cester_sprintf(x,y,z,a,b,c)
499 #define cester_sprintf(x,y,z,a,b) sprintf(x, z, a, b);
500 #define cester_sprintf1(x,y,z,a) sprintf(x, z, a)
501 #define cester_sprintf2(x,y,z,a,b) sprintf(x, z, a, b)
502 #define cester_sprintf3(x,y,z,a,b,c) sprintf(x, z, a, b, c)
519 #define CESTER_CHANGE_STREAM(x) { cester_ptr_to_str(&(superTestInstance.output_stream_str), x); superTestInstance.output_stream_address = *x; } (superTestInstance.output_stream = x)
527 #define CESTER_NOCOLOR() (superTestInstance.no_color = 1)
535 #define CESTER_PRINT_ERROR_ONLY(x) (superTestInstance.print_error_only = x)
544 #define CESTER_MINIMAL() (superTestInstance.verbose_level = 0)
556 #define CESTER_VERBOSE() (superTestInstance.verbose_level = 10); (superTestInstance.print_error_only = 0)
564 #define CESTER_DEBUG_LEVEL(x) (superTestInstance.verbose_level = x)
569 #define CESTER_VERBOSE_LEVEL(x) (superTestInstance.verbose_level = x)
576 #define CESTER_PRINT_VERSION() (superTestInstance.print_version = 1)
583 #define CESTER_SINGLE_OUPUT_ONLY() (superTestInstance.single_output_only = 1)
593 #define CESTER_NO_ISOLATION() (superTestInstance.isolate_tests = 0)
600 #define CESTER_NO_MEMTEST() (superTestInstance.mem_test_active = 0)
612 #define CESTER_DO_MEMTEST() (superTestInstance.mem_test_active = 1)
619 #define CESTER_NO_STREAMCAPTURE() (superTestInstance.stream_capture_active = 0)
631 #define CESTER_DO_STREAMCAPTURE() (superTestInstance.stream_capture_active = 1)
636 #define CESTER_OUTPUT_TEXT() superTestInstance.output_format = (char*) "text"
641 #define CESTER_OUTPUT_JUNITXML() superTestInstance.output_format = (char*) "junitxml"
646 #define CESTER_OUTPUT_TAP() superTestInstance.output_format = (char*) "tap"
651 #define CESTER_OUTPUT_TAPV13() superTestInstance.output_format = (char*) "tapV13"
659 #define CESTER_FORMAT_TESTNAME() superTestInstance.format_test_name = 1;
665 #define CESTER_DONT_FORMAT_TESTNAME() superTestInstance.format_test_name = 0;
672 #define CESTER_TOTAL_TESTS_COUNT (superTestInstance.total_tests_count)
677 #define CESTER_TOTAL_TESTS_RAN (superTestInstance.total_tests_ran)
682 #define CESTER_TOTAL_FAILED_TESTS_COUNT (superTestInstance.total_failed_tests_count)
694 #define CESTER_TOTAL_TEST_ERRORS_COUNT (superTestInstance.total_test_errors_count)
703 #define CESTER_TOTAL_TESTS_SKIPPED (superTestInstance.skipped_test_count)
708 #define CESTER_TOTAL_PASSED_TESTS_COUNT (superTestInstance.total_passed_tests_count)
717 #define CESTER_TOTAL_TODO_TESTS (superTestInstance.todo_tests_count)
726 #define CESTER_RUN_ALL_TESTS(x,y) cester_run_all_test(x,y)
732 #define CESTER_REPORT_SUCCESS_REGARDLESS() (superTestInstance.report_failure_regardless = 0); (superTestInstance.report_success_regardless = 1)
738 #define CESTER_REPORT_FAILURE_REGARDLESS() (superTestInstance.report_success_regardless = 0); (superTestInstance.report_failure_regardless = 1)
740 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
742 HANDLE cester_hConsole;
747 static void cester_copy_str(
char **src_out,
char **dest_out,
int size)
750 while (index < size) {
751 (*dest_out)[index] = (*src_out)[index];
754 (*dest_out)[index] =
'\0';
757 static __CESTER_INLINE__ char *cester_extract_name(
char const*
const file_path) {
758 unsigned i = 0, j = 0;
759 char *file_name_only_actual;
760 char *file_name_only = (
char*)
malloc (
sizeof (
char) * 200);
761 while (file_path[i] !=
'\0') {
762 if (file_path[i] ==
'\\' || file_path[i] ==
'/') {
765 file_name_only[j] = file_path[i];
770 file_name_only_actual = (
char*)
malloc(j+1);
771 cester_copy_str(&file_name_only, &file_name_only_actual, j);
773 return file_name_only_actual;
776 static __CESTER_INLINE__ char *cester_extract_name_only(
char const*
const file_path) {
778 char *file_name = cester_extract_name(file_path);
779 while (file_name[i] !=
'\0') {
780 if (file_name[i] ==
'.') {
798 cester_concat_str(out, tmp);
804 cester_concat_str(out, tmp);
810 cester_concat_str(out, tmp);
814 (*out) = (
char*)
malloc(
sizeof(
char) * 30 );
818 static __CESTER_INLINE__ unsigned cester_str_after_prefix(
const char* arg,
char* prefix,
unsigned prefix_size,
char** out) {
819 unsigned i = 0, index = 0;
820 char *value = (
char*)
malloc(
sizeof (
char) * 1000);
823 if (arg[i] ==
'\0') {
824 if (i < prefix_size) {
831 if (i < prefix_size && arg[i] != prefix[i]) {
835 if (i >= prefix_size) {
836 value[i-prefix_size] = arg[i];
841 *out = (
char*)
malloc(i+1);
842 cester_copy_str(&value, out, i);
847 static __CESTER_INLINE__ char* cester_str_replace(
char* str,
char old_char,
char new_char) {
848 char* tmp = (
char*)
malloc(strlen(str) + 1);
851 if (*str == old_char) {
852 tmp[index] = new_char;
858 }
while (*str !=
'\0');
870 if (arg[i] ==
'\0' && arg1[i] ==
'\0') {
873 if (arg[i] != arg1[i]) {
881 static __CESTER_INLINE__ unsigned cester_string_contains(
char* arg,
char* arg1) {
882 unsigned i = 0, index = 0;
887 if (arg[i] ==
'\0' || arg1[index] ==
'\0') {
890 if (arg[i] == arg1[index]) {
893 while (arg[i] == arg1[index]) {
894 if (arg[i] ==
'\0') {
900 if (arg1[index] ==
'\0') {
911 #ifndef CESTER_NO_PRINT_INFO
915 if (arg[size] ==
'\0') {
924 static __CESTER_INLINE__ unsigned cester_string_starts_with(
char* arg,
char* arg1) {
927 if (arg[i] ==
'\0' && arg1[i] ==
'\0') {
930 if (arg[i] != arg1[i]) {
931 if (arg1[i] ==
'\0') {
942 static __CESTER_INLINE__ void unpack_selected_extra_args(
char *arg,
char ***out,
unsigned *out_size) {
944 unsigned size = 0, current_index = 0;
945 char* prefix = (
char*)
"test=";
946 char **arr = (
char**)
malloc(30 *
sizeof(
char*));
948 arr[size] = (
char*)
malloc(
sizeof(
char) * 1000);
950 if (arg[i] ==
'\0') {
954 if (i < 5 && arg[i] != prefix[i]) {
958 arr[size][current_index] =
'\0';
961 arr[size] = (
char*)
malloc(
sizeof(
char) * 1000);
965 arr[size][current_index] = arg[i];
971 if (current_index > 0) {
972 arr[size-1][current_index] =
'\0';
975 if (current_index == 0) {
982 (*out) = (
char**)
malloc(size *
sizeof(
char*));
983 while (current_index < size) {
984 (*out)[current_index] = arr[current_index];
992 static __CESTER_INLINE__ void cester_str_value_after_first(
char *arg,
char from,
char** out) {
993 unsigned i = 0, index = 0;
994 unsigned found_char = 0;
995 char *value = (
char*)
malloc(
sizeof(
char) * 200);
997 if (arg[i] ==
'\0') {
1000 if (arg[i] == from) {
1004 if (found_char == 1) {
1005 value[index] = arg[i];
1011 (*out) = (
char*)
malloc(index+1);
1012 cester_copy_str(&value, out, index);
1016 static __CESTER_INLINE__ void cester_concat_str(
char **out,
const char * extra) {
1018 size_t extra_length;
1019 size_t original_length;
1027 extra_length = strlen(extra);
1031 original_length = strlen(*out);
1034 original_length = 0;
1037 new_length = original_length + extra_length;
1038 concatted = (
char *)
malloc(
sizeof(
char) * new_length + 1);
1040 if (original_length > 0) {
1041 strncpy(concatted, *out, original_length);
1042 concatted[original_length] = 0;
1048 if (extra_length > 0) {
1049 strncpy(concatted + original_length, extra, extra_length);
1050 concatted[original_length + extra_length] = 0;
1053 if (*out && *out[0] != 0) {
1061 cester_ptr_to_str(&extra, ptr);
1062 cester_concat_str(out, extra);
1066 static __CESTER_INLINE__ unsigned cester_is_validate_output_option(
char *format_option) {
1067 return (cester_string_equals(format_option, (
char*)
"junitxml") ||
1068 cester_string_equals(format_option, (
char*)
"tap") ||
1069 cester_string_equals(format_option, (
char*)
"tapV13") ||
1070 cester_string_equals(format_option, (
char*)
"text"));
1074 #define CESTER_SELECTCOLOR(x) (superTestInstance.no_color == 1 ? cester_default_color : x)
1076 #define CESTER_SELECTCOLOR(x) (superTestInstance.no_color == 1 ? "" : x)
1078 #define CESTER_GET_RESULT_AGGR (superTestInstance.total_failed_tests_count == 0 ? "SUCCESS" : "FAILURE")
1079 #define CESTER_GET_RESULT_AGGR_COLOR (superTestInstance.total_failed_tests_count == 0 ? (CESTER_FOREGROUND_GREEN) : (CESTER_FOREGROUND_RED))
1081 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
1082 #define CESTER_DELEGATE_FPRINT(y) fprintf(superTestInstance.output_stream, "%s", y)
1083 #define CESTER_DELEGATE_FPRINT_STR(x,y) SetConsoleTextAttribute(cester_hConsole, CESTER_SELECTCOLOR(x)); fprintf(superTestInstance.output_stream, "%s", y)
1084 #define CESTER_DELEGATE_FPRINT_PTR(x,y) SetConsoleTextAttribute(cester_hConsole, CESTER_SELECTCOLOR(x)); fprintf(superTestInstance.output_stream, "%p", y)
1085 #define CESTER_DELEGATE_FPRINT_INT(x,y) SetConsoleTextAttribute(cester_hConsole, CESTER_SELECTCOLOR(x)); fprintf(superTestInstance.output_stream, "%d", y)
1086 #define CESTER_DELEGATE_FPRINT_UINT(x,y) SetConsoleTextAttribute(cester_hConsole, CESTER_SELECTCOLOR(x)); fprintf(superTestInstance.output_stream, "%u", y)
1087 #ifndef CESTER_NO_TIME
1088 #define CESTER_DELEGATE_FPRINT_DOUBLE(x,y) SetConsoleTextAttribute(cester_hConsole, CESTER_SELECTCOLOR(x)); fprintf(superTestInstance.output_stream, "%f", y)
1089 #define CESTER_DELEGATE_FPRINT_DOUBLE_2(x,y) SetConsoleTextAttribute(cester_hConsole, CESTER_SELECTCOLOR(x)); fprintf(superTestInstance.output_stream, "%.2f", y)
1092 #define CESTER_DELEGATE_FPRINT(y) fprintf(superTestInstance.output_stream, "%s", y)
1093 #define CESTER_DELEGATE_FPRINT_STR(x,y) fprintf(superTestInstance.output_stream, "%s%s%s", CESTER_SELECTCOLOR(x), y, CESTER_SELECTCOLOR(CESTER_RESET_TERMINAL))
1094 #define CESTER_DELEGATE_FPRINT_PTR(x,y) fprintf(superTestInstance.output_stream, "%s%p%s", CESTER_SELECTCOLOR(x), y, CESTER_SELECTCOLOR(CESTER_RESET_TERMINAL))
1095 #define CESTER_DELEGATE_FPRINT_INT(x,y) fprintf(superTestInstance.output_stream, "%s%d%s", CESTER_SELECTCOLOR(x), y, CESTER_SELECTCOLOR(CESTER_RESET_TERMINAL))
1096 #define CESTER_DELEGATE_FPRINT_UINT(x,y) fprintf(superTestInstance.output_stream, "%s%u%s", CESTER_SELECTCOLOR(x), y, CESTER_SELECTCOLOR(CESTER_RESET_TERMINAL))
1097 #ifndef CESTER_NO_TIME
1098 #define CESTER_DELEGATE_FPRINT_DOUBLE(x,y) fprintf(superTestInstance.output_stream, "%s%f%s", CESTER_SELECTCOLOR(x), y, CESTER_SELECTCOLOR(CESTER_RESET_TERMINAL))
1099 #define CESTER_DELEGATE_FPRINT_DOUBLE_2(x,y) fprintf(superTestInstance.output_stream, "%s%.2f%s", CESTER_SELECTCOLOR(x), y, CESTER_SELECTCOLOR(CESTER_RESET_TERMINAL))
1123 #ifndef CESTER_NO_MEM_TEST
1126 #ifndef CESTER_NO_STREAM_CAPTURE
1129 #ifdef __CESTER_STDC_VERSION__
1136 #ifndef CESTER_NO_PRINT_INFO
1170 static void cester_print_test_case_message(
char const*
const type,
char const*
const message,
char const*
const file_path,
unsigned const line_num) {
1196 static __CESTER_INLINE__ void cester_print_assertion(
char const*
const expression,
char const*
const file_path,
unsigned const line_num) {
1215 static __CESTER_INLINE__ void cester_print_expect_actual(
unsigned expecting,
char const*
const expect,
char const*
const received,
char const*
const file_path,
unsigned const line_num) {
1225 if (expecting == 0) {
1260 #ifndef CESTER_NO_TIME
1268 #ifndef CESTER_NO_TIME
1313 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
1321 #ifndef CESTER_NO_TIME
1335 #ifdef __CESTER_STDC_VERSION__
1345 #ifdef __CESTER_STDC_VERSION__
1353 #ifndef CESTER_NO_TIME
1397 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
1439 #ifndef CESTER_NO_MEM_TEST
1464 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
1528 #ifndef CESTER_NO_MEM_TEST
1541 #ifndef CESTER_NO_TIME
1566 #ifndef CESTER_NO_TIME
1619 #ifndef CESTER_NO_MEM_TEST
1648 #ifndef CESTER_NO_MEM_TEST
1649 static __CESTER_INLINE__ unsigned check_memory_allocated_for_functions(
char *funcname1,
char *funcname2,
char *prefix,
char **write_string) {
1651 unsigned leaked_memory_count = 0;
1655 if ((funcname1 != CESTER_NULL && cester_string_equals((char*)((AllocatedMemory*)alloc_mem)->function_name, funcname1)) ||
1656 (funcname2 != CESTER_NULL && cester_string_equals((char*)((AllocatedMemory*)alloc_mem)->function_name, funcname2))) {
1658 leaked_memory_count += 1;
1659 if (superTestInstance.current_test_case != CESTER_NULL) {
1660 cester_concat_str(write_string, prefix);
1661 cester_concat_str(write_string,
"MemoryLeakError ");
1662 cester_concat_str(write_string, cleaned_name);
1663 cester_concat_str(write_string,
":");
1664 cester_concat_int(write_string, ((AllocatedMemory*)alloc_mem)->line_num);
1665 cester_concat_str(write_string,
": ");
1666 cester_concat_str(write_string,
"in '");
1667 cester_concat_str(write_string, (char*)((AllocatedMemory*)alloc_mem)->function_name);
1668 if (superTestInstance.verbose_level >= 2) {
1669 cester_concat_str(write_string,
"' => Memory allocated in line '");
1670 cester_concat_int(write_string, ((AllocatedMemory*)alloc_mem)->line_num);
1671 cester_concat_str(write_string,
"' not freed. Leaking '");
1672 cester_concat_sizet(write_string, ((AllocatedMemory *)alloc_mem)->allocated_bytes);
1673 cester_concat_str(write_string,
"' Bytes ");
1675 cester_concat_str(write_string,
"\n");
1683 return leaked_memory_count;
1691 static void cester_cleanup_super_instance(
void);
1694 unsigned index_sub, ret_val;
1695 unsigned i, index4, index5, index6, index7;
1696 char *prefix = (
char *)
"";
1699 #ifndef CESTER_NO_TIME
1715 if (((TestCase*)test_case)->test_type == CESTER_AFTER_ALL_TEST && superTestInstance.single_output_only == 0) {
1716 superTestInstance.current_cester_function_type = CESTER_AFTER_ALL_TEST;
1717 ((cester_test)((TestCase*)test_case)->test_function)(test_instance);
1722 prefix = (
char *)
"# ";
1725 #ifndef CESTER_NO_MEM_TEST
1761 #ifndef CESTER_NO_TIME
1772 write_testcase_junitxml(&cester_test_cases[i], file_name);
1777 if (((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST && ((TestCase*)test_case)->execution_status != CESTER_RESULT_UNKNOWN) {
1778 write_testcase_junitxml(((TestCase*)test_case), file_name);
1797 write_testcase_tap(&cester_test_cases[i], file_name, index_sub);
1803 if (((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST || ((TestCase*)test_case)->test_type == CESTER_NORMAL_TODO_TEST ||
1804 ((TestCase*)test_case)->test_type == CESTER_NORMAL_SKIP_TEST) {
1806 if (superTestInstance.selected_test_cases_size > 0 && ((TestCase*)test_case)->execution_status == CESTER_RESULT_UNKNOWN) {
1809 write_testcase_tap(((TestCase*)test_case), file_name, index_sub);
1834 #ifndef CESTER_NO_TIME
1859 write_testcase_tap_v13(&cester_test_cases[i], file_name, index_sub);
1865 if (((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST || ((TestCase*)test_case)->test_type == CESTER_NORMAL_TODO_TEST ||
1866 ((TestCase*)test_case)->test_type == CESTER_NORMAL_SKIP_TEST) {
1868 if (superTestInstance.selected_test_cases_size > 0 && ((TestCase*)test_case)->execution_status == CESTER_RESULT_UNKNOWN) {
1871 write_testcase_tap_v13(((TestCase*)test_case), file_name, index_sub);
1896 #ifndef CESTER_NO_TIME
1910 print_test_case_result(&cester_test_cases[i]);
1916 print_test_case_result(&cester_test_cases[i]);
1921 TestCase* test_case = (TestCase*) test_case_delegate;
1922 if (superTestInstance.selected_test_cases_size > 0 && test_case->execution_status != CESTER_RESULT_UNKNOWN) {
1923 print_test_case_result(test_case);
1929 print_test_case_result(test_case);
1937 print_test_case_outputs(&cester_test_cases[i]);
1942 TestCase* test_case1 = (TestCase*) test_case_delegate1;
1943 if (test_case1->test_type == CESTER_NORMAL_TEST && test_case1->execution_status != CESTER_RESULT_UNKNOWN) {
1944 print_test_case_outputs(test_case1);
1949 #ifndef CESTER_NO_TIME
1950 print_test_result(time_spent);
1952 print_test_result();
1958 cester_cleanup_super_instance();
1982 #define cester_assert_nothing()
1988 #define cester_swallow(param)
1999 #define cester_assert_cmp_msg(w,x,y,z) cester_evaluate_expression(w x y, z, __FILE__, __LINE__)
2009 #define cester_assert_cmp(x,y,z) cester_assert_cmp_msg(x, y, z, "(" #x " " #y " " #z ")")
2017 #define cester_assert_true(x) cester_assert_cmp_msg(x, ==, 1, "(" #x ")")
2027 #define cester_assert_true_msg(x,y) cester_assert_cmp_msg(x, ==, 1, y)
2035 #define cester_assert_false(x) cester_assert_cmp_msg(x, ==, 0, "(" #x ")")
2045 #define cester_assert_false_msg(x,y) cester_assert_cmp_msg(x, ==, 0, y)
2053 #define cester_assert_null(x) cester_assert_cmp_msg(x, ==, CESTER_NULL, "(" #x ")")
2061 #define cester_assert_not_null(x) cester_assert_cmp_msg(x, !=, CESTER_NULL, "!(" #x ")")
2070 #define cester_assert_equal(x,y) cester_evaluate_expect_actual(x==y, 1, #x, #y, __FILE__, __LINE__)
2079 #define cester_assert_not_equal(x,y) cester_evaluate_expect_actual(x!=y, 0, #x, #y, __FILE__, __LINE__)
2089 #define cester_assert_str_equal(x,y) cester_evaluate_expect_actual_str(x, y, #x, #y, 1, __FILE__, __LINE__)
2094 #define cester_assert_str_eq cester_assert_str_equal
2104 #define cester_assert_str_not_equal(x,y) cester_evaluate_expect_actual_str(x, y, #x, #y, 0, __FILE__, __LINE__)
2109 #define cester_assert_str_ne cester_assert_str_not_equal
2119 #define cester_assert_ptr_equal(x,y) cester_evaluate_expect_actual_ptr(x, y, #x, #y, 1, __FILE__, __LINE__)
2124 #define cester_assert_ptr_eq cester_assert_ptr_equal
2134 #define cester_assert_ptr_not_equal(x,y) cester_evaluate_expect_actual_ptr(x, y, #x, #y, 0, __FILE__, __LINE__)
2139 #define cester_assert_ptr_ne cester_assert_ptr_not_equal
2142 #define __internal_cester_assert_cmp(w,x,y,z) (w x y, z, w, y, #x, __FILE__, __LINE__)
2143 #define __internal_cester_assert_eq(x,y,z) (CESTER_COMPARATOR_EQUAL, "expected " #z ",%s received " #z, y, x, "", __FILE__, __LINE__)
2144 #define __internal_cester_assert_ne(x,y,z) (CESTER_COMPARATOR_NOT_EQUAL, "not expecting " #z ",%s found " #z, x, y, "", __FILE__, __LINE__)
2145 #define __internal_cester_assert_gt(x,y,z) (CESTER_COMPARATOR_GREATER_THAN, "expected value to be greater than " #z ",%s received " #z, x, y, "", __FILE__, __LINE__)
2146 #define __internal_cester_assert_ge(x,y,z) (CESTER_COMPARATOR_GREATER_THAN_OR_EQUAL, "expected value to be greater than or equal to " #z ",%s received " #z, x, y, "", __FILE__, __LINE__)
2147 #define __internal_cester_assert_lt(x,y,z) (CESTER_COMPARATOR_LESSER_THAN, "expected value to be lesser than " #z ",%s received " #z, x, y, "", __FILE__, __LINE__)
2148 #define __internal_cester_assert_le(x,y,z) (CESTER_COMPARATOR_LESSER_THAN_OR_EQUAL, "expected value to be lesser than or equal to " #z ",%s received " #z, x, y, "", __FILE__, __LINE__)
2160 #define cester_assert_cmp_char(w,x,y,z) CESTER_CONCAT(cester_compare_char_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2170 #define cester_assert_char_eq(x,y) CESTER_CONCAT(cester_compare_char, __internal_cester_assert_eq(x,y,%c))
2180 #define cester_assert_char_ne(x,y) CESTER_CONCAT(cester_compare_char, __internal_cester_assert_ne(x,y,%c))
2190 #define cester_assert_char_gt(x,y) CESTER_CONCAT(cester_compare_char, __internal_cester_assert_gt(x,y,%c))
2200 #define cester_assert_char_ge(x,y) CESTER_CONCAT(cester_compare_char, __internal_cester_assert_ge(x,y,%c))
2210 #define cester_assert_char_lt(x,y) CESTER_CONCAT(cester_compare_char, __internal_cester_assert_lt(x,y,%c))
2220 #define cester_assert_char_le(x,y) CESTER_CONCAT(cester_compare_char, __internal_cester_assert_le(x,y,%c))
2232 #define cester_assert_cmp_uchar(w,x,y,z) CESTER_CONCAT(cester_compare_uchar_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2242 #define cester_assert_uchar_eq(x,y) CESTER_CONCAT(cester_compare_uchar, __internal_cester_assert_eq(x,y,%c))
2252 #define cester_assert_uchar_ne(x,y) CESTER_CONCAT(cester_compare_uchar, __internal_cester_assert_ne(x,y,%c))
2262 #define cester_assert_uchar_gt(x,y) CESTER_CONCAT(cester_compare_uchar, __internal_cester_assert_gt(x,y,%c))
2272 #define cester_assert_uchar_ge(x,y) CESTER_CONCAT(cester_compare_uchar, __internal_cester_assert_ge(x,y,%c))
2282 #define cester_assert_uchar_lt(x,y) CESTER_CONCAT(cester_compare_uchar, __internal_cester_assert_lt(x,y,%c))
2292 #define cester_assert_uchar_le(x,y) CESTER_CONCAT(cester_compare_uchar, __internal_cester_assert_le(x,y,%c))
2304 #define cester_assert_cmp_short(w,x,y,z) CESTER_CONCAT(cester_compare_short_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2314 #define cester_assert_short_eq(x,y) CESTER_CONCAT(cester_compare_short, __internal_cester_assert_eq(x,y,%hi))
2324 #define cester_assert_short_ne(x,y) CESTER_CONCAT(cester_compare_short, __internal_cester_assert_ne(x,y,%hi))
2334 #define cester_assert_short_gt(x,y) CESTER_CONCAT(cester_compare_short, __internal_cester_assert_gt(x,y,%hi))
2344 #define cester_assert_short_ge(x,y) CESTER_CONCAT(cester_compare_short, __internal_cester_assert_ge(x,y,%hi))
2354 #define cester_assert_short_lt(x,y) CESTER_CONCAT(cester_compare_short, __internal_cester_assert_lt(x,y,%hi))
2364 #define cester_assert_short_le(x,y) CESTER_CONCAT(cester_compare_short, __internal_cester_assert_le(x,y,%hi))
2376 #define cester_assert_cmp_ushort(w,x,y,z) CESTER_CONCAT(cester_compare_ushort_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2386 #define cester_assert_ushort_eq(x,y) CESTER_CONCAT(cester_compare_ushort, __internal_cester_assert_eq(x,y,%hu))
2396 #define cester_assert_ushort_ne(x,y) CESTER_CONCAT(cester_compare_ushort, __internal_cester_assert_ne(x,y,%hu))
2406 #define cester_assert_ushort_gt(x,y) CESTER_CONCAT(cester_compare_ushort, __internal_cester_assert_gt(x,y,%hu))
2416 #define cester_assert_ushort_ge(x,y) CESTER_CONCAT(cester_compare_ushort, __internal_cester_assert_ge(x,y,%hu))
2426 #define cester_assert_ushort_lt(x,y) CESTER_CONCAT(cester_compare_ushort, __internal_cester_assert_lt(x,y,%hu))
2436 #define cester_assert_ushort_le(x,y) CESTER_CONCAT(cester_compare_ushort, __internal_cester_assert_le(x,y,%hu))
2448 #define cester_assert_cmp_int(w,x,y,z) CESTER_CONCAT(cester_compare_int_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2458 #define cester_assert_int_eq(x,y) CESTER_CONCAT(cester_compare_int, __internal_cester_assert_eq(x,y,%d))
2468 #define cester_assert_int_ne(x,y) CESTER_CONCAT(cester_compare_int, __internal_cester_assert_ne(x,y,%d))
2478 #define cester_assert_int_gt(x,y) CESTER_CONCAT(cester_compare_int, __internal_cester_assert_gt(x,y,%d))
2488 #define cester_assert_int_ge(x,y) CESTER_CONCAT(cester_compare_int, __internal_cester_assert_ge(x,y,%d))
2498 #define cester_assert_int_lt(x,y) CESTER_CONCAT(cester_compare_int, __internal_cester_assert_lt(x,y,%d))
2508 #define cester_assert_int_le(x,y) CESTER_CONCAT(cester_compare_int, __internal_cester_assert_le(x,y,%d))
2520 #define cester_assert_cmp_uint(w,x,y,z) CESTER_CONCAT(cester_compare_uint_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2530 #define cester_assert_uint_eq(x,y) CESTER_CONCAT(cester_compare_uint, __internal_cester_assert_eq(x,y,%u))
2540 #define cester_assert_uint_ne(x,y) CESTER_CONCAT(cester_compare_uint, __internal_cester_assert_ne(x,y,%u))
2550 #define cester_assert_uint_gt(x,y) CESTER_CONCAT(cester_compare_uint, __internal_cester_assert_gt(x,y,%u))
2560 #define cester_assert_uint_ge(x,y) CESTER_CONCAT(cester_compare_uint, __internal_cester_assert_ge(x,y,%u))
2570 #define cester_assert_uint_lt(x,y) CESTER_CONCAT(cester_compare_uint, __internal_cester_assert_lt(x,y,%u))
2580 #define cester_assert_uint_le(x,y) CESTER_CONCAT(cester_compare_uint, __internal_cester_assert_le(x,y,%u))
2592 #define cester_assert_cmp_long(w,x,y,z) CESTER_CONCAT(cester_compare_long_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2602 #define cester_assert_long_eq(x,y) CESTER_CONCAT(cester_compare_long, __internal_cester_assert_eq(x,y,%li))
2612 #define cester_assert_long_ne(x,y) CESTER_CONCAT(cester_compare_long, __internal_cester_assert_ne(x,y,%li))
2622 #define cester_assert_long_gt(x,y) CESTER_CONCAT(cester_compare_long, __internal_cester_assert_gt(x,y,%li))
2632 #define cester_assert_long_ge(x,y) CESTER_CONCAT(cester_compare_long, __internal_cester_assert_ge(x,y,%li))
2642 #define cester_assert_long_lt(x,y) CESTER_CONCAT(cester_compare_long, __internal_cester_assert_lt(x,y,%li))
2652 #define cester_assert_long_le(x,y) CESTER_CONCAT(cester_compare_long, __internal_cester_assert_le(x,y,%li))
2664 #define cester_assert_cmp_ulong(w,x,y,z) CESTER_CONCAT(cester_compare_ulong_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2674 #define cester_assert_ulong_eq(x,y) CESTER_CONCAT(cester_compare_ulong, __internal_cester_assert_eq(x,y,%lu))
2684 #define cester_assert_ulong_ne(x,y) CESTER_CONCAT(cester_compare_ulong, __internal_cester_assert_ne(x,y,%lu))
2694 #define cester_assert_ulong_gt(x,y) CESTER_CONCAT(cester_compare_ulong, __internal_cester_assert_gt(x,y,%lu))
2704 #define cester_assert_ulong_ge(x,y) CESTER_CONCAT(cester_compare_ulong, __internal_cester_assert_ge(x,y,%lu))
2714 #define cester_assert_ulong_lt(x,y) CESTER_CONCAT(cester_compare_ulong, __internal_cester_assert_lt(x,y,%lu))
2724 #define cester_assert_ulong_le(x,y) CESTER_CONCAT(cester_compare_ulong, __internal_cester_assert_le(x,y,%lu))
2736 #define cester_assert_cmp_llong(w,x,y,z) CESTER_CONCAT(cester_compare_llong_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2746 #ifndef __CESTER_STDC_VERSION__
2747 #define cester_assert_llong_eq(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_eq(x,y,%li))
2749 #define cester_assert_llong_eq(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_eq(x,y,%lli))
2760 #ifndef __CESTER_STDC_VERSION__
2761 #define cester_assert_llong_ne(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_ne(x,y,%li))
2763 #define cester_assert_llong_ne(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_ne(x,y,%lli))
2774 #ifndef __CESTER_STDC_VERSION__
2775 #define cester_assert_llong_gt(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_gt(x,y,%li))
2777 #define cester_assert_llong_gt(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_gt(x,y,%lli))
2788 #ifndef __CESTER_STDC_VERSION__
2789 #define cester_assert_llong_ge(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_ge(x,y,%li))
2791 #define cester_assert_llong_ge(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_ge(x,y,%lli))
2802 #ifndef __CESTER_STDC_VERSION__
2803 #define cester_assert_llong_lt(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_lt(x,y,%li))
2805 #define cester_assert_llong_lt(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_lt(x,y,%lli))
2816 #ifndef __CESTER_STDC_VERSION__
2817 #define cester_assert_llong_le(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_ge(x,y,%li))
2819 #define cester_assert_llong_le(x,y) CESTER_CONCAT(cester_compare_llong, __internal_cester_assert_ge(x,y,%lli))
2832 #define cester_assert_cmp_ullong(w,x,y,z) CESTER_CONCAT(cester_compare_ullong_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2842 #define cester_assert_ullong_eq(x,y) CESTER_CONCAT(cester_compare_ullong, __internal_cester_assert_eq(x,y,%llu))
2852 #define cester_assert_ullong_ne(x,y) CESTER_CONCAT(cester_compare_ullong, __internal_cester_assert_ne(x,y,%llu))
2862 #define cester_assert_ullong_gt(x,y) CESTER_CONCAT(cester_compare_ullong, __internal_cester_assert_gt(x,y,%llu))
2872 #define cester_assert_ullong_ge(x,y) CESTER_CONCAT(cester_compare_ullong, __internal_cester_assert_ge(x,y,%llu))
2882 #define cester_assert_ullong_lt(x,y) CESTER_CONCAT(cester_compare_ullong, __internal_cester_assert_lt(x,y,%llu))
2892 #define cester_assert_ullong_le(x,y) CESTER_CONCAT(cester_compare_ullong, __internal_cester_assert_le(x,y,%llu))
2904 #define cester_assert_cmp_float(w,x,y,z) CESTER_CONCAT(cester_compare_float_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2914 #define cester_assert_float_eq(x,y) CESTER_CONCAT(cester_compare_float, __internal_cester_assert_eq(x,y,%f))
2924 #define cester_assert_float_ne(x,y) CESTER_CONCAT(cester_compare_float, __internal_cester_assert_ne(x,y,%f))
2934 #define cester_assert_float_gt(x,y) CESTER_CONCAT(cester_compare_float, __internal_cester_assert_gt(x,y,%f))
2944 #define cester_assert_float_ge(x,y) CESTER_CONCAT(cester_compare_float, __internal_cester_assert_ge(x,y,%f))
2954 #define cester_assert_float_lt(x,y) CESTER_CONCAT(cester_compare_float, __internal_cester_assert_lt(x,y,%f))
2964 #define cester_assert_float_le(x,y) CESTER_CONCAT(cester_compare_float, __internal_cester_assert_le(x,y,%f))
2976 #define cester_assert_cmp_double(w,x,y,z) CESTER_CONCAT(cester_compare_double_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
2986 #define cester_assert_double_eq(x,y) CESTER_CONCAT(cester_compare_double, __internal_cester_assert_eq(x,y,%lf))
2996 #define cester_assert_double_ne(x,y) CESTER_CONCAT(cester_compare_double, __internal_cester_assert_ne(x,y,%lf))
3006 #define cester_assert_double_gt(x,y) CESTER_CONCAT(cester_compare_double, __internal_cester_assert_gt(x,y,%lf))
3016 #define cester_assert_double_ge(x,y) CESTER_CONCAT(cester_compare_double, __internal_cester_assert_ge(x,y,%lf))
3026 #define cester_assert_double_lt(x,y) CESTER_CONCAT(cester_compare_double, __internal_cester_assert_lt(x,y,%lf))
3036 #define cester_assert_double_le(x,y) CESTER_CONCAT(cester_compare_double, __internal_cester_assert_le(x,y,%lf))
3048 #define cester_assert_cmp_ldouble(w,x,y,z) CESTER_CONCAT(cester_compare_ldouble_pre_evaluated, __internal_cester_assert_cmp(w,x,y,z))
3058 #define cester_assert_ldouble_eq(x,y) CESTER_CONCAT(cester_compare_ldouble, __internal_cester_assert_eq(x,y,%e))
3068 #define cester_assert_ldouble_ne(x,y) CESTER_CONCAT(cester_compare_ldouble, __internal_cester_assert_ne(x,y,%e))
3078 #define cester_assert_ldouble_gt(x,y) CESTER_CONCAT(cester_compare_ldouble, __internal_cester_assert_gt(x,y,%e))
3088 #define cester_assert_ldouble_ge(x,y) CESTER_CONCAT(cester_compare_ldouble, __internal_cester_assert_ge(x,y,%e))
3098 #define cester_assert_ldouble_lt(x,y) CESTER_CONCAT(cester_compare_ldouble, __internal_cester_assert_lt(x,y,%e))
3108 #define cester_assert_ldouble_le(x,y) CESTER_CONCAT(cester_compare_ldouble, __internal_cester_assert_le(x,y,%e))
3110 static __CESTER_INLINE__ void cester_evaluate_expression(
unsigned eval_result,
char const*
const expression,
char const*
const file_path,
unsigned const line_num) {
3117 if (eval_result == 0) {
3125 cester_print_assertion(expression, file_path, line_num);
3130 static __CESTER_INLINE__ void cester_evaluate_expect_actual(
unsigned eval_result,
unsigned expecting,
char const*
const expected,
char const*
const actual,
3131 char const*
const file_path,
unsigned const line_num) {
3140 if (eval_result == 0) {
3147 cester_print_expect_actual(expecting, expected, actual, file_path, line_num);
3152 static __CESTER_INLINE__ void cester_evaluate_expect_actual_str(
char const*
const expected_in,
char const*
const actual_in,
char const*
const expected_expr,
3153 char const*
const actual_expr,
unsigned expecting,
char const*
const file_path,
unsigned const line_num) {
3155 unsigned eval_result;
3160 expected = (
char*)
"";
3161 actual = (
char*)
"";
3162 eval_result = cester_string_equals((
char*)expected_in, (
char*)actual_in);
3164 cester_concat_str(&expected, expected_expr);
3165 cester_concat_str(&actual, actual_expr);
3167 cester_concat_char(&expected,
'=');
3168 cester_concat_char(&actual,
'=');
3170 cester_concat_str(&expected, expected_in);
3171 cester_concat_str(&actual, actual_in);
3173 if (eval_result != expecting) {
3192 cester_print_expect_actual(expecting, expected, actual, file_path, line_num);
3199 static __CESTER_INLINE__ void cester_evaluate_expect_actual_ptr(
void* ptr1,
void* ptr2,
char const*
const expected_expr,
char const*
const actual_expr,
3200 unsigned expecting,
char const*
const file_path,
unsigned const line_num) {
3202 unsigned eval_result;
3206 eval_result = ptr1 == ptr2;
3208 expected = (
char*)
"";
3209 actual = (
char*)
"";
3210 cester_concat_str(&expected, expected_expr);
3211 cester_concat_str(&actual, actual_expr);
3213 cester_concat_char(&expected,
'=');
3214 cester_concat_char(&actual,
'=');
3216 cester_concat_ptr(&expected, ptr1);
3217 cester_concat_ptr(&actual, ptr2);
3219 cester_ptr_to_str(&expected, ptr1);
3220 cester_ptr_to_str(&actual, ptr2);
3222 if (eval_result != expecting) {
3241 cester_print_expect_actual(expecting, expected, actual, file_path, line_num);
3252 #define CESTER_INTERNAL_EVALUATE(comparator_type, x, y, result) {\
3253 if (comparator_type == CESTER_COMPARATOR_EQUAL) {\
3255 } else if (comparator_type == CESTER_COMPARATOR_NOT_EQUAL) {\
3257 } else if (comparator_type == CESTER_COMPARATOR_GREATER_THAN) {\
3259 } else if (comparator_type == CESTER_COMPARATOR_GREATER_THAN_OR_EQUAL) {\
3261 } else if (comparator_type == CESTER_COMPARATOR_LESSER_THAN) {\
3263 } else if (comparator_type == CESTER_COMPARATOR_LESSER_THAN_OR_EQUAL) {\
3270 static __CESTER_INLINE__ void cester_compare_char_pre_evaluated(
int eval_result,
char const*
const expr,
char first,
char second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3271 char expression[2048] =
"";
3273 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3276 static __CESTER_INLINE__ void cester_compare_char(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
char first,
char second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3277 int eval_result = 0;
3279 cester_compare_char_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3282 static __CESTER_INLINE__ void cester_compare_uchar_pre_evaluated(
int eval_result,
char const*
const expr,
unsigned char first,
unsigned char second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3283 char expression[2048] =
"";
3285 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3288 static __CESTER_INLINE__ void cester_compare_uchar(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
unsigned char first,
unsigned char second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3289 int eval_result = 0;
3291 cester_compare_uchar_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3294 static __CESTER_INLINE__ void cester_compare_int_pre_evaluated(
int eval_result,
char const*
const expr,
int first,
int second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3295 char expression[2048] =
"";
3297 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3300 static __CESTER_INLINE__ void cester_compare_int(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
int first,
int second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3301 int eval_result = 0;
3303 cester_compare_int_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3306 static __CESTER_INLINE__ void cester_compare_uint_pre_evaluated(
int eval_result,
char const*
const expr,
unsigned int first,
unsigned int second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3307 char expression[2048] =
"";
3309 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3312 static __CESTER_INLINE__ void cester_compare_uint(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
unsigned int first,
unsigned int second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3313 int eval_result = 0;
3315 cester_compare_uint_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3318 static __CESTER_INLINE__ void cester_compare_short_pre_evaluated(
int eval_result,
char const*
const expr,
short first,
short second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3319 char expression[2048] =
"";
3321 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3324 static __CESTER_INLINE__ void cester_compare_short(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
short first,
short second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3325 int eval_result = 0;
3327 cester_compare_short_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3330 static __CESTER_INLINE__ void cester_compare_ushort_pre_evaluated(
int eval_result,
char const*
const expr,
unsigned short first,
unsigned short second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3331 char expression[2048] =
"";
3333 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3336 static __CESTER_INLINE__ void cester_compare_ushort(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
unsigned short first,
unsigned short second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3337 int eval_result = 0;
3339 cester_compare_ushort_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3342 static __CESTER_INLINE__ void cester_compare_long_pre_evaluated(
int eval_result,
char const*
const expr,
long first,
long second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3343 char expression[2048] =
"";
3345 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3348 static __CESTER_INLINE__ void cester_compare_long(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
long first,
long second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3349 int eval_result = 0;
3351 cester_compare_long_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3354 static __CESTER_INLINE__ void cester_compare_ulong_pre_evaluated(
int eval_result,
char const*
const expr,
unsigned long first,
unsigned long second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3355 char expression[2048] =
"";
3357 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3360 static __CESTER_INLINE__ void cester_compare_ulong(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
unsigned long first,
unsigned long second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3361 int eval_result = 0;
3363 cester_compare_ulong_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3367 char expression[2048] =
"";
3369 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3373 int eval_result = 0;
3375 cester_compare_llong_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3379 char expression[2048] =
"";
3381 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3385 int eval_result = 0;
3387 cester_compare_ullong_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3390 static __CESTER_INLINE__ void cester_compare_float_pre_evaluated(
int eval_result,
char const*
const expr,
float first,
float second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3391 char expression[2048] =
"";
3393 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3396 static __CESTER_INLINE__ void cester_compare_float(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
float first,
float second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3397 int eval_result = 0;
3399 cester_compare_float_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3402 static __CESTER_INLINE__ void cester_compare_double_pre_evaluated(
int eval_result,
char const*
const expr,
double first,
double second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3403 char expression[2048] =
"";
3405 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3408 static __CESTER_INLINE__ void cester_compare_double(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
double first,
double second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3409 int eval_result = 0;
3411 cester_compare_double_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3414 static __CESTER_INLINE__ void cester_compare_ldouble_pre_evaluated(
int eval_result,
char const*
const expr,
long double first,
long double second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3415 char expression[2048] =
"";
3417 cester_evaluate_expression(eval_result, (
char*)expression, file_path, line_num);
3420 static __CESTER_INLINE__ void cester_compare_ldouble(
enum cester_assertion_caparator comparator_type,
char const*
const expr,
long double first,
long double second,
char const*
const op,
char const*
const file_path,
unsigned const line_num) {
3421 int eval_result = 0;
3423 cester_compare_ldouble_pre_evaluated(eval_result, expr, first, second, op, file_path, line_num);
3426 #ifndef __CESTER_STDC_VERSION__
3431 #define CESTER_TEST(x,y,z) static void cester_test_##x(TestInstance* y);
3441 #define CESTER_TODO_TEST(x,y,z) static void cester_test_##x(TestInstance* y);
3449 #define CESTER_SKIP_TEST(x,y,z) static void cester_test_##x(TestInstance* y);
3456 #define CESTER_BEFORE_ALL(x,y) void cester_before_all_test(TestInstance* x);
3462 #define CESTER_BEFORE_EACH(w,x,y,z) void cester_before_each_test(TestInstance* w, char * const x, unsigned y);
3469 #define CESTER_AFTER_ALL(x,y) void cester_after_all_test(TestInstance* x);
3475 #define CESTER_AFTER_EACH(w,x,y,z) void cester_after_each_test(TestInstance* w, char * const x, unsigned y);
3481 #define CESTER_OPTIONS(x) void cester_options_before_main(void);
3491 #define CESTER_BODY(x)
3503 #define CESTER_COMMENT(x) void cester_test_file_comment_function(void);
3505 #ifndef CESTER_NO_MOCK
3519 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,z) __attribute__((weak)) y x; y __real_##x;
3524 #define CESTER_MOCK_FUNCTION(x,y,z) __attribute__((weak)) y x; extern y __real_##x;
3526 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,z)
3527 #define CESTER_MOCK_FUNCTION(x,y,z)
3532 #define CESTER_TEST(x,y,...) static void cester_test_##x(TestInstance* y);
3533 #define CESTER_TODO_TEST(x,y,...) static void cester_test_##x(TestInstance* y);
3534 #define CESTER_SKIP_TEST(x,y,...) static void cester_test_##x(TestInstance* y);
3535 #define CESTER_BEFORE_ALL(x,...) void cester_before_all_test(TestInstance* x);
3536 #define CESTER_BEFORE_EACH(w,x,y,...) void cester_before_each_test(TestInstance* w, char * const x, unsigned y);
3537 #define CESTER_AFTER_ALL(x,...) void cester_after_all_test(TestInstance* x);
3538 #define CESTER_AFTER_EACH(w,x,y,...) void cester_after_each_test(TestInstance* w, char * const x, unsigned y);
3539 #define CESTER_OPTIONS(...) void cester_options_before_main(void);
3540 #define CESTER_BODY(...)
3541 #define CESTER_COMMENT(...) void cester_test_file_comment_function(void);
3542 #ifndef CESTER_NO_MOCK
3543 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,...) __attribute__((weak)) y x; y __real_##x;
3544 #define CESTER_MOCK_FUNCTION(x,y,...) __attribute__((weak)) y x; extern y __real_##x;
3546 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,...)
3547 #define CESTER_MOCK_FUNCTION(x,y,...)
3551 #ifdef __BASE_FILE__
3555 #include __BASE_FILE__
3564 #undef CESTER_TODO_TEST
3565 #undef CESTER_SKIP_TEST
3566 #undef CESTER_BEFORE_ALL
3567 #undef CESTER_BEFORE_EACH
3568 #undef CESTER_AFTER_ALL
3569 #undef CESTER_AFTER_EACH
3570 #undef CESTER_OPTIONS
3572 #undef CESTER_COMMENT
3573 #undef CESTER_MOCK_SIMPLE_FUNCTION
3574 #undef CESTER_MOCK_FUNCTION
3576 #ifdef __CESTER_STDC_VERSION__
3577 #ifndef CESTER_NO_TIME
3578 #define CESTER_TEST(x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TEST },
3579 #define CESTER_TODO_TEST(x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TODO_TEST },
3580 #define CESTER_SKIP_TEST(x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_SKIP_TEST },
3581 #define CESTER_BEFORE_ALL(x,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_before_all_test", (cester_before_all_test), CESTER_NULL, CESTER_NULL, CESTER_BEFORE_ALL_TEST },
3582 #define CESTER_BEFORE_EACH(w,x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) (char*) "", (char*) "cester_before_each_test", CESTER_NULL, (cester_before_each_test), CESTER_NULL, CESTER_BEFORE_EACH_TEST },
3583 #define CESTER_AFTER_ALL(x,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_after_all_test", (cester_after_all_test), CESTER_NULL, CESTER_NULL, CESTER_AFTER_ALL_TEST },
3584 #define CESTER_AFTER_EACH(w,x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_after_each_test", CESTER_NULL, (cester_after_each_test), CESTER_NULL, CESTER_AFTER_EACH_TEST },
3585 #define CESTER_OPTIONS(...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_options_before_main", CESTER_NULL, CESTER_NULL, (cester_options_before_main), CESTER_OPTIONS_FUNCTION },
3586 #define CESTER_COMMENT(...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_test_file_comment_function", CESTER_NULL, CESTER_NULL, (cester_test_file_comment_function), CESTER_TEST_FILE_COMMENT },
3588 #define CESTER_TEST(x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TEST },
3589 #define CESTER_TODO_TEST(x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TODO_TEST },
3590 #define CESTER_SKIP_TEST(x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_SKIP_TEST },
3591 #define CESTER_BEFORE_ALL(x,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_before_all_test", (cester_before_all_test), CESTER_NULL, CESTER_NULL, CESTER_BEFORE_ALL_TEST },
3592 #define CESTER_BEFORE_EACH(w,x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) (char*) "", (char*) "cester_before_each_test", CESTER_NULL, (cester_before_each_test), CESTER_NULL, CESTER_BEFORE_EACH_TEST },
3593 #define CESTER_AFTER_ALL(x,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_after_all_test", (cester_after_all_test), CESTER_NULL, CESTER_NULL, CESTER_AFTER_ALL_TEST },
3594 #define CESTER_AFTER_EACH(w,x,y,...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_after_each_test", CESTER_NULL, (cester_after_each_test), CESTER_NULL, CESTER_AFTER_EACH_TEST },
3595 #define CESTER_OPTIONS(...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_options_before_main", CESTER_NULL, CESTER_NULL, (cester_options_before_main), CESTER_OPTIONS_FUNCTION },
3596 #define CESTER_COMMENT(...) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_test_file_comment_function", CESTER_NULL, CESTER_NULL, (cester_test_file_comment_function), CESTER_TEST_FILE_COMMENT },
3598 #define CESTER_BODY(...)
3599 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,...)
3600 #define CESTER_MOCK_FUNCTION(x,y,...)
3602 #ifndef CESTER_NO_TIME
3603 #define CESTER_TEST(x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TEST },
3604 #define CESTER_TODO_TEST(x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TODO_TEST },
3605 #define CESTER_SKIP_TEST(x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_SKIP_TEST },
3606 #define CESTER_BEFORE_ALL(x,y) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_before_all_test", (cester_before_all_test), CESTER_NULL, CESTER_NULL, CESTER_BEFORE_ALL_TEST },
3607 #define CESTER_BEFORE_EACH(w,x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) (char*) "", (char*) "cester_before_each_test", CESTER_NULL, (cester_before_each_test), CESTER_NULL, CESTER_BEFORE_EACH_TEST },
3608 #define CESTER_AFTER_ALL(x,y) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_after_all_test", (cester_after_all_test), CESTER_NULL, CESTER_NULL, CESTER_AFTER_ALL_TEST },
3609 #define CESTER_AFTER_EACH(w,x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_after_each_test", CESTER_NULL, (cester_after_each_test), CESTER_NULL, CESTER_AFTER_EACH_TEST },
3610 #define CESTER_OPTIONS(x) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_options_before_main", CESTER_NULL, CESTER_NULL, (cester_options_before_main), CESTER_OPTIONS_FUNCTION },
3611 #define CESTER_COMMENT(x) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, 0.000, 0.000, (char*) "", (char*) "cester_test_file_comment_function", CESTER_NULL, CESTER_NULL, (cester_test_file_comment_function), CESTER_TEST_FILE_COMMENT },
3613 #define CESTER_TEST(x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TEST },
3614 #define CESTER_TODO_TEST(x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_TODO_TEST },
3615 #define CESTER_SKIP_TEST(x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) #x, (cester_test_##x), CESTER_NULL, CESTER_NULL, CESTER_NORMAL_SKIP_TEST },
3616 #define CESTER_BEFORE_ALL(x,y) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_before_all_test", (cester_before_all_test), CESTER_NULL, CESTER_NULL, CESTER_BEFORE_ALL_TEST },
3617 #define CESTER_BEFORE_EACH(w,x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) (char*) "", (char*) "cester_before_each_test", CESTER_NULL, (cester_before_each_test), CESTER_NULL, CESTER_BEFORE_EACH_TEST },
3618 #define CESTER_AFTER_ALL(x,y) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_after_all_test", (cester_after_all_test), CESTER_NULL, CESTER_NULL, CESTER_AFTER_ALL_TEST },
3619 #define CESTER_AFTER_EACH(w,x,y,z) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_after_each_test", CESTER_NULL, (cester_after_each_test), CESTER_NULL, CESTER_AFTER_EACH_TEST },
3620 #define CESTER_OPTIONS(x) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_options_before_main", CESTER_NULL, CESTER_NULL, (cester_options_before_main), CESTER_OPTIONS_FUNCTION },
3621 #define CESTER_COMMENT(x) { CESTER_RESULT_UNKNOWN, __LINE__, CESTER_RESULT_SUCCESS, (char*) "", (char*) "cester_test_file_comment_function", CESTER_NULL, CESTER_NULL, (cester_test_file_comment_function), CESTER_TEST_FILE_COMMENT },
3623 #define CESTER_BODY(x)
3624 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,z)
3625 #define CESTER_MOCK_FUNCTION(x,y,z)
3631 static TestCase cester_test_cases[] = {
3632 #ifdef __BASE_FILE__
3633 #include __BASE_FILE__
3635 #ifndef CESTER_NO_TIME
3636 {
CESTER_RESULT_UNKNOWN, 0,
CESTER_RESULT_SUCCESS, 0.000, 0.000,
CESTER_NULL,
CESTER_NULL,
CESTER_NULL,
CESTER_NULL,
CESTER_NULL,
CESTER_TESTS_TERMINATOR }
3646 #undef CESTER_TODO_TEST
3647 #undef CESTER_SKIP_TEST
3648 #undef CESTER_BEFORE_ALL
3649 #undef CESTER_BEFORE_EACH
3650 #undef CESTER_AFTER_ALL
3651 #undef CESTER_AFTER_EACH
3652 #undef CESTER_OPTIONS
3654 #undef CESTER_COMMENT
3655 #undef CESTER_MOCK_SIMPLE_FUNCTION
3656 #undef CESTER_MOCK_FUNCTION
3658 #ifdef __CESTER_STDC_VERSION__
3659 #define CESTER_TEST(x,y,...) static void cester_test_##x(TestInstance* y) { __VA_ARGS__ }
3660 #define CESTER_TODO_TEST(x,y,...) static void cester_test_##x(TestInstance* y) { }
3661 #define CESTER_SKIP_TEST(x,y,...) static void cester_test_##x(TestInstance* y) { __VA_ARGS__ }
3662 #define CESTER_BEFORE_ALL(x,...) void cester_before_all_test(TestInstance* x) { __VA_ARGS__ CESTER_NO_ISOLATION(); }
3663 #define CESTER_BEFORE_EACH(w,x,y,...) void cester_before_each_test(TestInstance* w, char * const x, unsigned y) { __VA_ARGS__ CESTER_NO_ISOLATION(); }
3664 #define CESTER_AFTER_ALL(x,...) void cester_after_all_test(TestInstance* x) { __VA_ARGS__ CESTER_NO_ISOLATION(); }
3665 #define CESTER_AFTER_EACH(w,x,y,...) void cester_after_each_test(TestInstance* w, char * const x, unsigned y) { __VA_ARGS__ CESTER_NO_ISOLATION(); }
3666 #define CESTER_OPTIONS(...) void cester_options_before_main(void) { __VA_ARGS__ }
3667 #define CESTER_BODY(...) __VA_ARGS__
3668 #define CESTER_COMMENT(...) void cester_test_file_comment_function(void) { if (cester_string_equals(superTestInstance.output_format, (char*) "text") == 1) { CESTER_DELEGATE_FPRINT_STR((cester_default_color), "\n"); CESTER_DELEGATE_FPRINT_STR((cester_default_color), #__VA_ARGS__); CESTER_DELEGATE_FPRINT_STR((cester_default_color), "\n"); } }
3669 #ifndef CESTER_NO_MOCK
3670 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,...) y __wrap_##x { return __VA_ARGS__; }
3671 #define CESTER_MOCK_FUNCTION(x,y,...) y __wrap_##x { __VA_ARGS__ }
3673 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,...)
3674 #define CESTER_MOCK_FUNCTION(x,y,...)
3679 #define CESTER_TEST(x,y,z) static void cester_test_##x(TestInstance* y) { z }
3680 #define CESTER_TODO_TEST(x,y,z) static void cester_test_##x(TestInstance* y) { }
3681 #define CESTER_SKIP_TEST(x,y,z) static void cester_test_##x(TestInstance* y) { z }
3682 #define CESTER_BEFORE_ALL(x,y) void cester_before_all_test(TestInstance* x) { y CESTER_NO_ISOLATION(); }
3683 #define CESTER_BEFORE_EACH(w,x,y,z) void cester_before_each_test(TestInstance* w, char * const x, unsigned y) { z CESTER_NO_ISOLATION(); }
3684 #define CESTER_AFTER_ALL(x,y) void cester_after_all_test(TestInstance* x) { y CESTER_NO_ISOLATION(); }
3685 #define CESTER_AFTER_EACH(w,x,y,z) void cester_after_each_test(TestInstance* w, char * const x, unsigned y) { z CESTER_NO_ISOLATION(); }
3686 #define CESTER_OPTIONS(x) void cester_options_before_main(void) { x }
3687 #define CESTER_BODY(x) x
3688 #define CESTER_COMMENT(x) void cester_test_file_comment_function(void) { if (cester_string_equals(superTestInstance.output_format, (char*) "text") == 1) { CESTER_DELEGATE_FPRINT_STR((cester_default_color), "\n"); CESTER_DELEGATE_FPRINT_STR((cester_default_color), #x); CESTER_DELEGATE_FPRINT_STR((cester_default_color), "\n"); } }
3689 #ifndef CESTER_NO_MOCK
3690 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,z) y __wrap_##x { return z; }
3691 #define CESTER_MOCK_FUNCTION(x,y,z) y __wrap_##x { z }
3693 #define CESTER_MOCK_SIMPLE_FUNCTION(x,y,z)
3694 #define CESTER_MOCK_FUNCTION(x,y,z)
3705 #define CESTER_REGISTER_TEST(x) cester_register_test((char*)#x, (cester_test_##x), CESTER_NULL, CESTER_NULL, __LINE__, CESTER_NORMAL_TEST)
3714 #define CESTER_REGISTER_SKIP_TEST(x) cester_register_test((char*)#x, (cester_test_##x), CESTER_NULL, CESTER_NULL, __LINE__, CESTER_NORMAL_SKIP_TEST)
3720 #define CESTER_REGISTER_TODO_TEST(x) cester_register_test((char*)#x, (cester_test_##x), CESTER_NULL, CESTER_NULL, __LINE__, CESTER_NORMAL_TODO_TEST)
3726 #define CESTER_REGISTER_BEFORE_ALL() cester_register_test("cester_before_all_test", (cester_before_all_test), CESTER_NULL, CESTER_NULL, __LINE__, CESTER_BEFORE_ALL_TEST)
3732 #define CESTER_REGISTER_BEFORE_EACH() cester_register_test("cester_before_each_test", CESTER_NULL, (cester_before_each_test), CESTER_NULL, __LINE__, CESTER_BEFORE_EACH_TEST)
3738 #define CESTER_REGISTER_AFTER_ALL() cester_register_test("cester_after_all_test", (cester_after_all_test), CESTER_NULL, CESTER_NULL, __LINE__, CESTER_AFTER_ALL_TEST)
3744 #define CESTER_REGISTER_AFTER_EACH() cester_register_test("cester_after_each_test", CESTER_NULL, (cester_after_each_test), CESTER_NULL, __LINE__, CESTER_AFTER_EACH_TEST)
3750 #define CESTER_REGISTER_OPTIONS() cester_register_test("cester_options_before_main", CESTER_NULL, CESTER_NULL, (cester_options_before_main), __LINE__, CESTER_OPTIONS_FUNCTION)
3756 #define CESTER_REGISTER_COMMENT() cester_register_test("cester_test_file_comment_function", CESTER_NULL, CESTER_NULL, (cester_test_file_comment_function), __LINE__, CESTER_OPTIONS_FUNCTION)
3764 #define CESTER_TEST_SHOULD(x,y) cester_expected_test_result(#x, y);
3773 #define CESTER_TEST_SHOULD_SEGFAULT(x) CESTER_TEST_SHOULD(x, CESTER_RESULT_SEGFAULT);
3782 #define CESTER_TEST_SHOULD_FAIL(x) CESTER_TEST_SHOULD(x, CESTER_RESULT_FAILURE);
3790 #define CESTER_TEST_SHOULD_BE_TERMINATED(x) CESTER_TEST_SHOULD(x, CESTER_RESULT_TERMINATED);
3802 #define CESTER_TEST_SHOULD_NOT_RELEASE_STREAM(x) CESTER_TEST_SHOULD(x, CESTER_RESULT_UNRELEASED_STREAM);
3804 #ifndef CESTER_NO_MEM_TEST
3811 #define CESTER_TEST_SHOULD_LEAK_MEMORY(x) CESTER_TEST_SHOULD(x, CESTER_RESULT_MEMORY_LEAK);
3813 #define CESTER_TEST_SHOULD_LEAK_MEMORY(x)
3816 #if !defined(__unix__) && !defined(__unix) && !(defined(__APPLE__) && defined(__MACH__)) && !defined(_WIN32)
3817 #pragma message("Stream capture not supported on this platform, open an issue on the github repo with the platform details")
3820 #ifndef CESTER_NO_STREAM_CAPTURE
3828 static void cester_set_captured_streams_tmp_folder(
char *path1,
char *fallback_path) {
3829 struct stat st = {0};
3835 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
3850 #define CESTER_CHANGE_STREAM_CAPTURE_TM_FOLDER(x) cester_set_captured_streams_tmp_folder(x, CESTER_NULL)
3866 static void cester_capture_stream(FILE *stream,
char const*
const file_path,
unsigned const line_num) {
3868 char *replaced_stream_file_path = (
char *)
"";
3870 struct stat st = {0};
3884 #if defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
3886 cester_print_test_case_message(
"StreamCaptureWarning",
"", file_path, line_num);
3893 cester_print_test_case_message(
"StreamCaptureWarning",
"", file_path, line_num);
3900 cester_concat_str(&replaced_stream_file_path,
"/");
3901 cester_concat_ptr(&replaced_stream_file_path, stream);
3902 cester_concat_str(&replaced_stream_file_path,
".txt");
3903 replaced_stream = fopen(replaced_stream_file_path,
"w+");
3905 cester_print_test_case_message(
"StreamCaptureWarning",
"", file_path, line_num);
3909 goto cester_capture_stream_cleanup;
3922 cester_print_test_case_message(
"StreamCaptureWarning",
"", file_path, line_num);
3926 goto cester_capture_stream_cleanup;
3932 cester_capture_stream_cleanup:
3934 fclose(replaced_stream);
3935 if (remove(replaced_stream_file_path)) {
3936 cester_print_test_case_message(
"StreamCaptureCleanupWarning",
"", file_path, line_num);
3962 static void cester_release_captured_stream(FILE *stream,
CapturedStream *
captured_stream,
char const*
const file_path,
unsigned const line_num) {
3968 cester_print_test_case_message(
"StreamCaptureCleanupWarning",
"", file_path, line_num);
3992 static void cester_reset_stream(FILE *stream,
char const*
const file_path,
unsigned const line_num) {
3994 char *stream_ptr_str;
3998 goto cester_reset_stream_cleanup;
4000 cester_ptr_to_str(&stream_ptr_str, stream);
4003 CapturedStream *captured_stream;
4004 if (captured_stream_ != CESTER_NULL) {
4005 captured_stream = (CapturedStream *) captured_stream_;
4006 if (cester_string_equals(captured_stream->original_stream_ptr_str, stream_ptr_str) == 1) {
4007 if (stream != CESTER_NULL) {
4008 fclose(captured_stream->replaced_stream_handle);
4009 captured_stream->replaced_stream_handle = fopen(captured_stream->replaced_stream_file_path,
"w+");
4010 *stream = *(captured_stream->replaced_stream_handle);
4011 captured_stream->line_num = line_num;
4013 cester_meta_free(stream_ptr_str);
4019 cester_reset_stream_cleanup:
4020 cester_print_test_case_message(
"StreamCaptureWarning",
"", file_path, line_num);
4037 static char *cester_stream_content(FILE *stream,
char const*
const file_path,
unsigned const line_num) {
4040 char *stream_ptr_str;
4045 cester_ptr_to_str(&stream_ptr_str, stream);
4048 CapturedStream *captured_stream;
4049 if (captured_stream_ != CESTER_NULL) {
4050 captured_stream = (CapturedStream *) captured_stream_;
4051 if (cester_string_equals(captured_stream->original_stream_ptr_str, stream_ptr_str) == 1) {
4052 if (stream != CESTER_NULL) {
4054 fseek(captured_stream->replaced_stream_handle, 0, SEEK_END);
4055 length = ftell(captured_stream->replaced_stream_handle);
4056 fseek(captured_stream->replaced_stream_handle, 0, SEEK_SET);
4057 if (captured_stream->stream_buffer != CESTER_NULL) {
4058 cester_meta_free(captured_stream->stream_buffer);
4060 captured_stream->stream_buffer = (char *) malloc(length+1);
4061 if (captured_stream->stream_buffer) {
4062 length = fread(captured_stream->stream_buffer, 1, length, captured_stream->replaced_stream_handle);
4063 captured_stream->stream_buffer[length] =
'\0';
4065 cester_meta_free(stream_ptr_str);
4066 return captured_stream->stream_buffer;
4068 cester_meta_free(stream_ptr_str);
4089 static void cester_release_stream(FILE *stream,
char const*
const file_path,
unsigned const line_num) {
4091 char *stream_ptr_str;
4095 goto cester_release_stream_cleanup;
4097 cester_ptr_to_str(&stream_ptr_str, stream);
4100 CapturedStream *captured_stream;
4101 if (captured_stream_ != CESTER_NULL) {
4102 captured_stream = (CapturedStream *) captured_stream_;
4103 if (cester_string_equals(captured_stream->original_stream_ptr_str, stream_ptr_str) == 1) {
4104 if (cester_array_remove_at(superTestInstance.captured_streams, index) == CESTER_NULL) {
4105 cester_print_test_case_message(
"StreamCaptureCleanupWarning",
"", file_path, line_num);
4106 cester_concat_str(&superTestInstance.current_test_case->execution_output,
"Failed to remove captured stream with pointer address '");
4107 cester_concat_str(&superTestInstance.current_test_case->execution_output, stream_ptr_str);
4108 cester_concat_str(&superTestInstance.current_test_case->execution_output,
"' from captured stream array, expect non breaking issues.\n");
4110 cester_meta_free(stream_ptr_str);
4111 cester_release_captured_stream(stream, captured_stream, file_path, line_num);
4112 captured_stream = CESTER_NULL;
4118 cester_release_stream_cleanup:
4119 cester_print_test_case_message(
"StreamCaptureWarning",
"", file_path, line_num);
4137 unsigned unreleased_stream_count = 0;
4140 goto release_forgotten_captured_streams_cleanup;
4143 CapturedStream *captured_stream = (CapturedStream *) captured_stream_;
4144 if (captured_stream == CESTER_NULL) {
4148 fflush(superTestInstance.output_stream);
4149 *(superTestInstance.output_stream) = superTestInstance.output_stream_address;
4152 unreleased_stream_count++;
4153 cester_print_test_case_message(
"StreamCaptureError",
"", superTestInstance.test_file_path, captured_stream->line_num);
4154 cester_concat_str(&test_case->execution_output,
"You forgot to realease the stream '");
4155 cester_concat_str(&test_case->execution_output, captured_stream->original_stream_ptr_str);
4156 cester_concat_str(&test_case->execution_output,
"' captured in line ");
4157 cester_concat_int(&test_case->execution_output, captured_stream->line_num);
4158 cester_concat_str(&test_case->execution_output,
"\n");
4161 cester_print_test_case_message(
"StreamCaptureCleanupWarning",
"", superTestInstance.test_file_path, captured_stream->line_num);
4162 cester_concat_str(&superTestInstance.current_test_case->execution_output,
"Failed to remove captured stream with pointer address '");
4163 cester_concat_str(&superTestInstance.current_test_case->execution_output, captured_stream->original_stream_ptr_str);
4164 cester_concat_str(&superTestInstance.current_test_case->execution_output,
"' from captured stream array, expect non breaking issues.\n");
4171 release_forgotten_captured_streams_cleanup:
4172 return unreleased_stream_count;
4178 #define CESTER_CAPTURE_STREAM(x) cester_capture_stream(x, __FILE__, __LINE__)
4183 #define CESTER_STREAM_CONTENT(x) cester_stream_content(x, __FILE__, __LINE__)
4188 #define CESTER_RESET_STREAM(x) cester_reset_stream(x, __FILE__, __LINE__)
4193 #define CESTER_RELEASE_STREAM(x) cester_release_stream(x, __FILE__, __LINE__)
4199 #define CESTER_CAPTURE_STDIN() CESTER_CAPTURE_STREAM(stdin)
4204 #define CESTER_STDIN_CONTENT() CESTER_STREAM_CONTENT(stdin)
4209 #define CESTER_RESET_STDIN() CESTER_RESET_STREAM(stdin)
4215 #define CESTER_RELEASE_STDIN() CESTER_RELEASE_STREAM(stdin)
4221 #define CESTER_CAPTURE_STDOUT() CESTER_CAPTURE_STREAM(stdout)
4226 #define CESTER_STDOUT_CONTENT() CESTER_STREAM_CONTENT(stdout)
4231 #define CESTER_RESET_STDOUT() CESTER_RESET_STREAM(stdout)
4237 #define CESTER_RELEASE_STDOUT() CESTER_RELEASE_STREAM(stdout)
4242 #define CESTER_CAPTURE_STDERR() CESTER_CAPTURE_STREAM(stderr)
4247 #define CESTER_STDERR_CONTENT() CESTER_STREAM_CONTENT(stderr)
4252 #define CESTER_RESET_STDERR() CESTER_RESET_STREAM(stderr)
4257 #define CESTER_RELEASE_STDERR() CESTER_RELEASE_STREAM(stderr)
4265 #define cester_assert_stream_content_equal(x,y) cester_assert_str_equal(CESTER_STREAM_CONTENT(x), y)
4273 #define cester_assert_stream_content_contain(x, y) cester_assert_true(cester_string_contains(CESTER_STREAM_CONTENT(x), y))
4281 #define cester_assert_stream_content_not_equal(x,y) cester_assert_str_not_equal(CESTER_STREAM_CONTENT(x), y)
4289 #define cester_assert_stream_content_not_contain(x, y) cester_assert_false(cester_string_contains(CESTER_STREAM_CONTENT(x), y))
4294 #define cester_assert_stdin_stream_content_equal(y) cester_assert_str_equal(CESTER_STDIN_CONTENT(), y)
4299 #define cester_assert_stdin_stream_content_contain(y) cester_assert_true(cester_string_contains(CESTER_STDIN_CONTENT(), y))
4304 #define cester_assert_stdin_stream_content_not_equal(y) cester_assert_str_not_equal(CESTER_STDIN_CONTENT(), y)
4309 #define cester_assert_stdin_stream_content_not_contain(y) cester_assert_false(cester_string_contains(CESTER_STDIN_CONTENT(), y))
4314 #define cester_assert_stdout_stream_content_equal(y) cester_assert_str_equal(CESTER_STDOUT_CONTENT(), y)
4319 #define cester_assert_printf_equal cester_assert_stdout_stream_content_equal
4324 #define cester_assert_stdout_stream_content_contain(y) cester_assert_true(cester_string_contains(CESTER_STDOUT_CONTENT(), y))
4329 #define cester_assert_printf_contain cester_assert_stdout_stream_content_contain
4334 #define cester_assert_stdout_stream_content_not_equal(y) cester_assert_str_not_equal(CESTER_STDOUT_CONTENT(), y)
4339 #define cester_assert_printf_not_equal cester_assert_stdout_stream_content_not_equal
4344 #define cester_assert_stdout_stream_content_not_contain(y) cester_assert_false(cester_string_contains(CESTER_STDOUT_CONTENT(), y))
4349 #define cester_assert_printf_not_contain cester_assert_stdout_stream_content_not_contain
4354 #define cester_assert_stderr_stream_content_equal(y) cester_assert_str_equal(CESTER_STDERR_CONTENT(), y)
4359 #define cester_assert_stderr_stream_content_contain(y) cester_assert_true(cester_string_contains(CESTER_STDERR_CONTENT(), y))
4364 #define cester_assert_stderr_stream_content_not_equal(y) cester_assert_str_not_equal(CESTER_STDERR_CONTENT(), y)
4369 #define cester_assert_stderr_stream_content_not_contain(y) cester_assert_false(cester_string_contains(CESTER_STDERR_CONTENT(), y))
4376 #define CESTER_CAPTURE_STREAM(x)
4377 #define CESTER_STREAM_CONTENT(x)
4378 #define CESTER_RESET_STREAM(x)
4379 #define CESTER_RELEASE_STREAM(x)
4380 #define CESTER_CAPTURE_STDIN() CESTER_CAPTURE_STREAM(stdin)
4381 #define CESTER_STDIN_CONTENT() CESTER_STREAM_CONTENT(stdin)
4382 #define CESTER_RESET_STDIN() CESTER_RESET_STREAM(stdin)
4383 #define CESTER_RELEASE_STDIN() CESTER_RELEASE_STREAM(stdin)
4384 #define CESTER_CAPTURE_STDOUT() CESTER_CAPTURE_STREAM(stdout)
4385 #define CESTER_STDOUT_CONTENT() CESTER_STREAM_CONTENT(stdout)
4386 #define CESTER_RESET_STDOUT() CESTER_RESET_STREAM(stdout)
4387 #define CESTER_RELEASE_STDOUT() CESTER_RELEASE_STREAM(stdout)
4388 #define CESTER_CAPTURE_STDERR() CESTER_CAPTURE_STREAM(stderr)
4389 #define CESTER_STDERR_CONTENT() CESTER_STREAM_CONTENT(stderr)
4390 #define CESTER_RESET_STDERR() CESTER_RESET_STREAM(stderr)
4391 #define CESTER_RELEASE_STDERR() CESTER_RELEASE_STREAM(stderr)
4392 #define cester_assert_stream_content_equal(x,y)
4393 #define cester_assert_stream_content_contain(x, y)
4394 #define cester_assert_stream_content_not_equal(x,y)
4395 #define cester_assert_stream_content_not_contain(x, y)
4396 #define cester_assert_stdin_stream_content_equal(y)
4397 #define cester_assert_stdin_stream_content_contain(y)
4398 #define cester_assert_stdin_stream_content_not_equal(y)
4399 #define cester_assert_stdin_stream_content_not_contain(y)
4400 #define cester_assert_stdout_stream_content_equal(y)
4401 #define cester_assert_printf_equal cester_assert_stdout_stream_content_equal
4402 #define cester_assert_stdout_stream_content_contain(y)
4403 #define cester_assert_printf_contain cester_assert_stdout_stream_content_contain
4404 #define cester_assert_stdout_stream_content_not_equal(y)
4405 #define cester_assert_printf_not_equal cester_assert_stdout_stream_content_not_equal
4406 #define cester_assert_stdout_stream_content_not_contain(y)
4407 #define cester_assert_printf_not_contain cester_assert_stdout_stream_content_not_contain
4408 #define cester_assert_stderr_stream_content_equal(y)
4409 #define cester_assert_stderr_stream_content_contain(y)
4410 #define cester_assert_stderr_stream_content_not_equal(y)
4411 #define cester_assert_stderr_stream_content_not_contain(y)
4424 #ifndef CESTER_NO_STREAM_CAPTURE
4445 #ifndef CESTER_NO_TIME
4458 #ifndef CESTER_NO_STREAM_CAPTURE
4479 cester_string_equals(cester_test_cases[i].name, (
char*)test_name) == 1) {
4488 if ((((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST ||
4489 ((TestCase*)test_case)->test_type == CESTER_NORMAL_TODO_TEST ||
4490 ((TestCase*)test_case)->test_type == CESTER_NORMAL_SKIP_TEST) &&
4491 cester_string_equals(((TestCase*)test_case)->name, (char*)test_name) == 1) {
4493 ((TestCase*)test_case)->expected_result = expected_result;
4502 #ifndef CESTER_NO_TIME
4530 cester_concat_str(&a_test_case->
execution_output,
"Prematurely terminated as expected");
4533 cester_concat_str(&a_test_case->
execution_output,
"Timed out as expected");
4536 cester_concat_str(&a_test_case->
execution_output,
"Have unreleased stream as expected (ARE YOU SERIOUS? BAD IDEA!!!!)");
4538 #ifndef CESTER_NO_MEM_TEST
4540 cester_concat_str(&a_test_case->
execution_output,
"Leaked memory as expected");
4564 cester_concat_str(&a_test_case->
execution_output,
"Expected to Fail but passed");
4567 cester_concat_str(&a_test_case->
execution_output,
"Expected to Segfault but passed");
4570 cester_concat_str(&a_test_case->
execution_output,
"Expected to be Prematurely terminated but exit gracefully");
4573 cester_concat_str(&a_test_case->
execution_output,
"Expected to Time out but ends in time");
4576 cester_concat_str(&a_test_case->
execution_output,
"Expected to have unreleased stream but all streams were released");
4578 #ifndef CESTER_NO_MEM_TEST
4580 cester_concat_str(&a_test_case->
execution_output,
"Expected to Leak memory but no memory was leaked");
4608 unsigned last_status;
4611 #ifndef CESTER_NO_SIGNAL
4612 if (setjmp(
buf) == 1) {
4613 goto check_isolation;
4616 #ifndef CESTER_NO_TIME
4619 #ifndef __CESTER_STDC_VERSION__
4620 #pragma message("Isolated tests not supported in C version less than C99 and C++ version less than C++11. cester will rely on signal for crash reporting")
4624 #ifdef __CESTER_STDC_VERSION__
4625 #if defined(_WIN32) && !defined(CESTER_EXCLUDE_WINDOWS_H)
4626 HANDLE stdout_pipe_read;
4627 HANDLE stdout_pipe_write;
4628 SECURITY_ATTRIBUTES sa;
4629 sa.nLength =
sizeof(SECURITY_ATTRIBUTES);
4630 sa.bInheritHandle = TRUE;
4633 CreatePipe(&stdout_pipe_read, &stdout_pipe_write, &sa, 0);
4635 PROCESS_INFORMATION pi;
4638 .cb =
sizeof(STARTUPINFO),
4639 .dwFlags = STARTF_USESTDHANDLES,
4640 .hStdOutput = stdout_pipe_write
4645 .cb =
sizeof(STARTUPINFO),
4646 .dwFlags = STARTF_USESTDHANDLES,
4647 .hStdOutput = stdout_pipe_write
4649 PROCESS_INFORMATION pi = {0};
4655 snprintf(command, 1500,
"%s --cester-test=%s --cester-singleoutput --cester-noisolation --cester-verbose-level=%d %s %s %s %s %s %s",
4678 CloseHandle(stdout_pipe_write);
4686 ReadFile(stdout_pipe_read, buffer, maxlen, &len,
CESTER_NULL);
4691 WaitForSingleObject(pi.hProcess, INFINITE);
4694 GetExitCodeProcess(pi.hProcess, &status);
4696 if ((status & 0x80000000)) {
4701 last_status = status;
4705 CloseHandle(pi.hProcess);
4706 CloseHandle(pi.hThread);
4707 #elif defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__))
4710 char *selected_test_unix;
4711 char *verbose_level_str;
4720 last_status = cester_run_test_no_isolation(
test_instance, a_test_case, index);
4722 }
else if (pid == 0) {
4723 selected_test_unix = (
char*)
"";
4724 verbose_level_str = (
char *)
"";
4725 cester_concat_str(&selected_test_unix,
"--cester-test=");
4726 cester_concat_str(&selected_test_unix, a_test_case->
name);
4727 cester_concat_str(&verbose_level_str,
"--cester-verbose-level=");
4731 dup2(pipefd[1], STDOUT_FILENO);
4735 "--cester-singleoutput",
4736 "--cester-noisolation",
4756 while ((len = read(pipefd[0], buffer, 700)) != 0) {
4760 waitpid(pid, &status, 0);
4762 last_status = WEXITSTATUS(status);
4767 #pragma message("Isolated tests not supported in this environment. The tests will be run on the main process")
4768 last_status = cester_run_test_no_isolation(
test_instance, a_test_case, index);
4769 #define CESTER_NO_SUBPROCESS 1
4773 last_status = cester_run_test_no_isolation(
test_instance, a_test_case, index);
4775 resolve_test_result:
4776 cester_report_single_test_result(last_status, a_test_case);
4781 #ifdef __CESTER_STDC_VERSION__
4782 #ifndef CESTER_NO_SUBPROCESS
4784 goto end_sub_process;
4788 goto resolve_test_result;
4792 unsigned i, index1, index2, ret_val;
4793 char *prefix = (
char *)
"";
4804 if (((TestCase*)test_case)->test_type == CESTER_BEFORE_EACH_TEST) {
4805 superTestInstance.current_cester_function_type = CESTER_BEFORE_EACH_TEST;
4806 ((cester_before_after_each)((TestCase*)test_case)->test_ba_function)(test_instance, a_test_case->name, index);
4813 prefix = (
char *)
"# ";
4816 prefix = (
char *)
" - ";
4820 #ifndef CESTER_NO_STREAM_CAPTURE
4821 if (release_forgotten_captured_streams(a_test_case) > 0) {
4825 #ifndef CESTER_NO_MEM_TEST
4840 if (((TestCase*)test_case)->test_type == CESTER_AFTER_EACH_TEST) {
4841 superTestInstance.current_cester_function_type = CESTER_AFTER_EACH_TEST;
4842 ((cester_before_after_each)((TestCase*)test_case)->test_ba_function)(test_instance, a_test_case->name, index);
4847 prefix = (
char *)
"# ";
4850 #ifndef CESTER_NO_MEM_TEST
4864 #ifndef CESTER_NO_SIGNAL
4873 unsigned i, j, index2, index3, test_index;
4874 unsigned found_test;
4875 char* selected_test_case_name;
4895 if (((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST && ((TestCase*)test_case)->execution_status == CESTER_RESULT_UNKNOWN) {
4896 cester_run_test(superTestInstance.test_instance, ((TestCase*)test_case), ++test_index);
4915 cester_string_equals(cester_test_cases[i].name, selected_test_case_name) == 1 &&
4933 if (found_test == 0) {
4935 if ((((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST || ((TestCase*)test_case)->test_type == CESTER_NORMAL_TODO_TEST ||
4936 ((TestCase*)test_case)->test_type == CESTER_NORMAL_SKIP_TEST) &&
4937 cester_string_equals(((TestCase*)test_case)->name, selected_test_case_name) == 1 &&
4938 ((TestCase*)test_case)->execution_status == CESTER_RESULT_UNKNOWN) {
4941 if (((TestCase*)test_case)->test_type == CESTER_NORMAL_TEST) {
4942 ++superTestInstance.selected_test_cases_found;
4943 cester_run_test(superTestInstance.test_instance, ((TestCase*)test_case), ++test_index);
4945 ((TestCase*)test_case)->execution_status = CESTER_RESULT_SUCCESS;
4946 if (((TestCase*)test_case)->test_type == CESTER_NORMAL_SKIP_TEST) {
4947 ++superTestInstance.skipped_test_count;
4949 ++superTestInstance.todo_tests_count;
4954 if (found_test == 0) {
4967 static void cester_cleanup_super_instance(
void)
4971 #ifndef CESTER_NO_MEM_TEST
4974 if (alloc_mem != CESTER_NULL) {
4975 cester_meta_free(alloc_mem);
4987 if (strlen(((TestCase *)test_case)->execution_output) > 0) {
4988 cester_meta_free(((TestCase *)test_case)->execution_output);
5006 #ifndef CESTER_NO_STREAM_CAPTURE
5016 #ifndef CESTER_NO_PRINT_INFO
5021 #define CESTER_TEST_FUNTION_TYPE_TO_STRING(test_type) (test_type == CESTER_NORMAL_TEST ? "CESTER_NORMAL_TEST" :\
5022 (test_type == CESTER_NORMAL_TODO_TEST ? "CESTER_NORMAL_TODO_TEST" :\
5023 (test_type == CESTER_NORMAL_SKIP_TEST ? "CESTER_NORMAL_SKIP_TEST" :\
5024 (test_type == CESTER_BEFORE_ALL_TEST ? "CESTER_BEFORE_ALL_TEST" :\
5025 (test_type == CESTER_BEFORE_EACH_TEST ? "CESTER_BEFORE_EACH_TEST" :\
5026 (test_type == CESTER_AFTER_ALL_TEST ? "CESTER_AFTER_ALL_TEST" :\
5027 (test_type == CESTER_AFTER_EACH_TEST ? "CESTER_AFTER_EACH_TEST" :\
5028 (test_type == CESTER_OPTIONS_FUNCTION ? "CESTER_OPTIONS_FUNCTION" :\
5029 (test_type == CESTER_TEST_FILE_COMMENT ? "CESTER_TEST_FILE_COMMENT" : "CESTER_TESTS_TERMINATOR")))))))))
5034 #define CESTER_PRINT_TEST_FUNCTION(tab, text_prefix, test_case) if (cester_string_equals(superTestInstance.output_format, (char*) "junitxml")) {\
5035 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_BLUE), "" tab "<function");\
5036 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_RED), " name=");\
5037 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), "\"");\
5038 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), test_case.name);\
5039 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), "\"");\
5040 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_RED), " line_number=");\
5041 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), "\"");\
5042 CESTER_DELEGATE_FPRINT_INT((CESTER_FOREGROUND_MAGENTA), test_case.line_num);\
5043 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), "\"");\
5044 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_RED), " type=");\
5045 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), "\"");\
5046 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), CESTER_TEST_FUNTION_TYPE_TO_STRING(test_case.test_type));\
5047 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_MAGENTA), "\"");\
5048 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_BLUE), "/>\n");\
5050 CESTER_DELEGATE_FPRINT(text_prefix); CESTER_DELEGATE_FPRINT(test_case.name);\
5051 if (!cester_string_equals(info_section, "all")) CESTER_DELEGATE_FPRINT("\n");\
5059 static __CESTER_INLINE__ unsigned int cester_print_tests_information(
char *info_section) {
5081 if (cester_string_equals(info_section,
"all")) {
5181 if (cester_test_cases[index].test_type ==
CESTER_OPTIONS_FUNCTION && cester_string_contains(info_section,
"options")) {
5184 }
else if (cester_test_cases[index].test_type ==
CESTER_TEST_FILE_COMMENT && cester_string_contains(info_section,
"comments")) {
5187 }
else if (cester_test_cases[index].test_type ==
CESTER_BEFORE_ALL_TEST && (cester_string_contains(info_section,
"before_all") ||
5188 cester_string_contains(info_section,
"before*"))) {
5191 }
else if (cester_test_cases[index].test_type ==
CESTER_BEFORE_EACH_TEST && (cester_string_contains(info_section,
"before_each") ||
5192 cester_string_contains(info_section,
"before*"))) {
5195 }
else if (cester_test_cases[index].test_type ==
CESTER_AFTER_ALL_TEST && (cester_string_contains(info_section,
"after_all") ||
5196 cester_string_contains(info_section,
"after*"))) {
5199 }
else if (cester_test_cases[index].test_type ==
CESTER_AFTER_EACH_TEST && (cester_string_contains(info_section,
"after_each") ||
5200 cester_string_contains(info_section,
"after*"))) {
5203 }
else if (cester_test_cases[index].test_type ==
CESTER_NORMAL_TEST && (((cester_string_starts_with(info_section,
"test") &&
5204 cester_str_size(info_section) == 4) || cester_string_contains(info_section,
"test,") || cester_string_contains(info_section,
"test ")) ||
5205 cester_string_contains(info_section,
"test*"))) {
5208 }
else if (cester_test_cases[index].test_type ==
CESTER_NORMAL_SKIP_TEST && (cester_string_contains(info_section,
"test_skip") ||
5209 cester_string_contains(info_section,
"test*"))) {
5212 }
else if (cester_test_cases[index].test_type ==
CESTER_NORMAL_TODO_TEST && (cester_string_contains(info_section,
"test_todo") ||
5213 cester_string_contains(info_section,
"test*"))) {
5225 if (cester_string_equals(info_section,
"all")) {
5235 static __CESTER_INLINE__ unsigned cester_run_all_test(
unsigned argc,
char **argv) {
5238 #ifndef CESTER_NO_PRINT_INFO
5241 unsigned i, j, index, index1;
5244 #ifndef CESTER_EXCLUDE_WINDOWS_H
5245 CONSOLE_SCREEN_BUFFER_INFO info;
5246 if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info)) {
5249 cester_hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
5251 #ifndef CESTER_NO_STREAM_CAPTURE
5252 cester_set_captured_streams_tmp_folder(getenv(
"TEMP"), (
char *)
"C:/libcester_tmp/");
5255 #ifndef CESTER_NO_STREAM_CAPTURE
5256 cester_set_captured_streams_tmp_folder(getenv(
"TMPDIR"), (
char *)
"/tmp/libcester_tmp/");
5260 #ifndef CESTER_NO_SIGNAL
5266 #ifndef CESTER_NO_PRINT_INFO
5271 #ifndef CESTER_NO_STREAM_CAPTURE
5276 #ifndef CESTER_NO_MEM_TEST
5292 for (;j < argc; ++j) {
5294 if (cester_str_after_prefix(arg, (
char*)
"--cester-", 9, &cester_option) == 1) {
5295 if (cester_string_equals(cester_option, (
char*)
"minimal") == 1) {
5298 }
else if (cester_string_equals(cester_option, (
char*)
"verbose") == 1) {
5302 }
else if (cester_string_equals(cester_option, (
char*)
"nocolor") == 1) {
5305 }
else if (cester_string_equals(cester_option, (
char*)
"printversion") == 1) {
5308 }
else if (cester_string_equals(cester_option, (
char*)
"singleoutput") == 1) {
5311 }
else if (cester_string_equals(cester_option, (
char*)
"noisolation") == 1) {
5314 }
else if (cester_string_equals(cester_option, (
char*)
"dontformatname") == 1) {
5316 #ifndef CESTER_NO_MEM_TEST
5317 }
else if (cester_string_equals(cester_option, (
char*)
"nomemtest") == 1) {
5320 #ifndef CESTER_NO_STREAM_CAPTURE
5321 }
else if (cester_string_equals(cester_option, (
char*)
"nostreamcapture") == 1) {
5324 }
else if (cester_string_equals(cester_option, (
char*)
"version") == 1) {
5326 cester_print_version();
5328 cester_cleanup_super_instance();
5330 return EXIT_SUCCESS;
5332 }
else if (cester_string_equals(cester_option, (
char*)
"help") == 1) {
5334 cester_print_version();
5335 cester_print_help();
5338 cester_cleanup_super_instance();
5339 return EXIT_SUCCESS;
5341 #ifndef CESTER_NO_PRINT_INFO
5342 }
else if (cester_string_starts_with(cester_option, (
char*)
"info=") == 1) {
5343 cester_str_value_after_first(cester_option,
'=', &info_section);
5346 }
else if (cester_string_starts_with(cester_option, (
char*)
"test=") == 1) {
5349 }
else if (cester_string_starts_with(cester_option, (
char*)
"verbose-level=") == 1) {
5350 cester_str_value_after_first(cester_option,
'=', &extra);
5357 }
else if (cester_string_starts_with(cester_option, (
char*)
"output=") == 1) {
5358 cester_str_value_after_first(cester_option,
'=', &extra);
5359 if (cester_is_validate_output_option(extra) == 0) {
5363 if (cester_string_starts_with(extra, (
char*)
"tap")) {
5369 return EXIT_FAILURE;
5384 return EXIT_FAILURE;
5391 if (strlen(argv[j]) != 0) {
5401 #ifndef CESTER_NO_PRINT_INFO
5403 return cester_print_tests_information(info_section);
5408 cester_print_version();
5422 ((
cester_void)cester_test_cases[i].test_void_function)();
5435 if ((((TestCase*)test_case)->test_type == CESTER_OPTIONS_FUNCTION || ((TestCase*)test_case)->test_type == CESTER_TEST_FILE_COMMENT) &&
5436 superTestInstance.single_output_only == 0) {
5437 superTestInstance.current_cester_function_type = CESTER_OPTIONS_FUNCTION;
5438 ((cester_void)((TestCase*)test_case)->test_void_function)();
5458 if (((TestCase*)test_case)->test_type == CESTER_BEFORE_ALL_TEST && superTestInstance.single_output_only == 0) {
5459 superTestInstance.current_cester_function_type = CESTER_BEFORE_ALL_TEST;
5460 ((cester_test)((TestCase*)test_case)->test_function)(superTestInstance.test_instance);
5464 #ifndef CESTER_NO_TIME
5467 cester_run_all_test_iterator(0);
5472 #ifndef CESTER_NO_MAIN
5478 #ifndef CESTER_NO_SIGNAL
5498 #ifndef CESTER_NO_MEM_TEST
5512 cester_run_all_test_iterator(0);
5534 array_local->
size = 0;
5541 array_local->
buffer = buffer;
5561 memcpy(new_buffer, array->
buffer, array->
size *
sizeof(
void*));
5563 array->
buffer = new_buffer;
5572 if (index >= array->
size) {
5575 item = array->
buffer[index];
5576 if (index != array->
size - 1) {
5577 size_t block_size = (array->
size - 1 - index) *
sizeof(
void*);
5578 memmove(&(array->
buffer[index]),
5579 &(array->
buffer[index + 1]),
5593 #ifndef CESTER_NO_MEM_TEST
5595 static __CESTER_INLINE__ void* cester_allocator(
size_t nitems,
size_t size,
unsigned type,
const char *file,
unsigned line,
const char *func) {
5597 const char* actual_function_name;
5598 #ifndef __CESTER_STDC_VERSION__
5602 actual_function_name = func;
5605 actual_function_name = func;
5608 actual_function_name =
"CESTER_BEFORE_ALL";
5611 actual_function_name =
"CESTER_OPTIONS";
5614 actual_function_name =
"CESTER_BEFORE_EACH";
5622 #ifndef CESTER_NO_STREAM_CAPTURE
5634 p =
calloc(nitems, size);
5645 if (cester_str_after_prefix(actual_function_name, (
char*)
"cester_test_", 12, (
char **) &(allocated_mem->
function_name)) == 0) {
5646 allocated_mem->
function_name = (
char *) actual_function_name;
5650 cester_ptr_to_str(&allocated_mem->
address, p);
5659 static __CESTER_INLINE__ void cester_free(
void *pointer,
const char *file,
unsigned line,
const char *func) {
5684 cester_ptr_to_str(&address, pointer);
5686 if (cester_string_equals(((AllocatedMemory*)alloc_mem)->address, address) == 1) {
5687 if (!cester_array_remove_at(superTestInstance.mem_alloc_manager, index)) {
5688 CESTER_DELEGATE_FPRINT_STR((CESTER_FOREGROUND_YELLOW),
"Memory allocation array corrupted. Further Memory test disabled.\n");
5689 superTestInstance.mem_test_active = 0;
5691 if (((AllocatedMemory*)alloc_mem)->function_name_allocated == 1) {
5692 cester_meta_free(((AllocatedMemory*)alloc_mem)->function_name);
5694 cester_meta_free(((AllocatedMemory*)alloc_mem)->address);
5695 cester_meta_free(alloc_mem);
5707 #define malloc(x) cester_allocator( 0, x, 0, __FILE__, __LINE__, __CESTER_FUNCTION__)
5708 #define calloc(x,y) cester_allocator( x, y, 1, __FILE__, __LINE__, __CESTER_FUNCTION__)
5709 #define free(x) cester_free( x, __FILE__, __LINE__, __CESTER_FUNCTION__)