|
| 1 | +//@ args = '--rename test:flavorful/to-test=test' |
| 2 | + |
| 3 | +#include <assert.h> |
| 4 | +#include <runner.h> |
| 5 | +#include <stdlib.h> |
| 6 | +#include <string.h> |
| 7 | + |
| 8 | +int main() { |
| 9 | + { |
| 10 | + test_list_in_record1_t a; |
| 11 | + runner_string_set(&a.a, "list_in_record1"); |
| 12 | + test_f_list_in_record1(&a); |
| 13 | + |
| 14 | + test_list_in_record2_t b; |
| 15 | + test_f_list_in_record2(&b); |
| 16 | + assert(memcmp(b.a.ptr, "list_in_record2", b.a.len) == 0); |
| 17 | + test_list_in_record2_free(&b); |
| 18 | + } |
| 19 | + |
| 20 | + { |
| 21 | + test_list_in_record3_t a, b; |
| 22 | + runner_string_set(&a.a, "list_in_record3 input"); |
| 23 | + test_f_list_in_record3(&a, &b); |
| 24 | + assert(memcmp(b.a.ptr, "list_in_record3 output", b.a.len) == 0); |
| 25 | + test_list_in_record3_free(&b); |
| 26 | + } |
| 27 | + |
| 28 | + { |
| 29 | + test_list_in_record4_t a, b; |
| 30 | + runner_string_set(&a.a, "input4"); |
| 31 | + test_f_list_in_record4(&a, &b); |
| 32 | + assert(memcmp(b.a.ptr, "result4", b.a.len) == 0); |
| 33 | + test_list_in_record4_free(&b); |
| 34 | + } |
| 35 | + |
| 36 | + { |
| 37 | + test_list_in_variant1_v1_t a; |
| 38 | + test_list_in_variant1_v2_t b; |
| 39 | + a.is_some = true; |
| 40 | + runner_string_set(&a.val, "foo"); |
| 41 | + b.is_err = true; |
| 42 | + runner_string_set(&b.val.err, "bar"); |
| 43 | + test_f_list_in_variant1(&a.val, &b); |
| 44 | + } |
| 45 | + |
| 46 | + { |
| 47 | + runner_string_t a; |
| 48 | + assert(test_f_list_in_variant2(&a)); |
| 49 | + assert(memcmp(a.ptr, "list_in_variant2", a.len) == 0); |
| 50 | + runner_string_free(&a); |
| 51 | + } |
| 52 | + |
| 53 | + { |
| 54 | + test_list_in_variant3_t a; |
| 55 | + a.is_some = true; |
| 56 | + runner_string_set(&a.val, "input3"); |
| 57 | + runner_string_t b; |
| 58 | + assert(test_f_list_in_variant3(&a.val, &b)); |
| 59 | + assert(memcmp(b.ptr, "output3", b.len) == 0); |
| 60 | + runner_string_free(&b); |
| 61 | + } |
| 62 | + |
| 63 | + { |
| 64 | + test_my_errno_t errno; |
| 65 | + assert(!test_errno_result(&errno)); |
| 66 | + assert(errno == TEST_MY_ERRNO_B); |
| 67 | + } |
| 68 | + |
| 69 | + { |
| 70 | + test_my_errno_t errno; |
| 71 | + assert(test_errno_result(&errno)); |
| 72 | + } |
| 73 | + |
| 74 | + { |
| 75 | + runner_string_t a; |
| 76 | + runner_string_set(&a, "typedef1"); |
| 77 | + runner_string_t b_str; |
| 78 | + runner_string_set(&b_str, "typedef2"); |
| 79 | + test_list_typedef3_t b; |
| 80 | + b.ptr = &b_str; |
| 81 | + b.len = 1; |
| 82 | + runner_tuple2_list_typedef2_list_typedef3_t ret; |
| 83 | + test_list_typedefs(&a, &b, &ret); |
| 84 | + |
| 85 | + assert(memcmp(ret.f0.ptr, "typedef3", ret.f0.len) == 0); |
| 86 | + assert(ret.f1.len == 1); |
| 87 | + assert(memcmp(ret.f1.ptr[0].ptr, "typedef4", ret.f1.ptr[0].len) == 0); |
| 88 | + |
| 89 | + test_list_typedef2_free(&ret.f0); |
| 90 | + test_list_typedef3_free(&ret.f1); |
| 91 | + } |
| 92 | + |
| 93 | + { |
| 94 | + runner_list_bool_t a; |
| 95 | + bool a_val[] = {true, false}; |
| 96 | + a.ptr = a_val; |
| 97 | + a.len = 2; |
| 98 | + |
| 99 | + test_list_result_void_void_t b; |
| 100 | + test_result_void_void_t b_val[2]; |
| 101 | + b_val[0].is_err = false; |
| 102 | + b_val[1].is_err = true; |
| 103 | + b.ptr = b_val; |
| 104 | + b.len = 2; |
| 105 | + |
| 106 | + test_list_my_errno_t c; |
| 107 | + test_my_errno_t c_val[2]; |
| 108 | + c_val[0] = TEST_MY_ERRNO_SUCCESS; |
| 109 | + c_val[1] = TEST_MY_ERRNO_A; |
| 110 | + c.ptr = c_val; |
| 111 | + c.len = 2; |
| 112 | + |
| 113 | + test_tuple3_list_bool_list_result_void_void_list_my_errno_t ret; |
| 114 | + test_list_of_variants(&a, &b, &c, &ret); |
| 115 | + |
| 116 | + assert(ret.f0.len == 2); |
| 117 | + assert(ret.f0.ptr[0] == false); |
| 118 | + assert(ret.f0.ptr[1] == true); |
| 119 | + |
| 120 | + assert(ret.f1.len == 2); |
| 121 | + assert(ret.f1.ptr[0].is_err == true); |
| 122 | + assert(ret.f1.ptr[1].is_err == false); |
| 123 | + |
| 124 | + assert(ret.f2.len == 2); |
| 125 | + assert(ret.f2.ptr[0] == TEST_MY_ERRNO_A); |
| 126 | + assert(ret.f2.ptr[1] == TEST_MY_ERRNO_B); |
| 127 | + |
| 128 | + runner_list_bool_free(&ret.f0); |
| 129 | + test_list_result_void_void_free(&ret.f1); |
| 130 | + test_list_my_errno_free(&ret.f2); |
| 131 | + } |
| 132 | +} |
0 commit comments