Tag
Hash :
f0401f0c
Author :
Thomas de Grivel
Date :
2024-03-04T14:19:12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
/* c3
* Copyright 2022-2024 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "../libc3/tuple.h"
#include "../libc3/str.h"
#include "test.h"
#define TUPLE_TEST_INIT_CLEAN(test) \
do { \
s_tuple tuple_test; \
test_context("tuple_init(" # test ")"); \
TEST_EQ(tuple_init(&tuple_test, (test)), &tuple_test); \
tuple_clean(&tuple_test); \
test_context(NULL); \
} while (0)
#define TUPLE_TEST_INIT_1(test) \
do { \
s_tuple tuple_test; \
test_context("tuple_init_1(" # test ")"); \
TEST_EQ(tuple_init_1(&tuple_test, (test)), &tuple_test); \
tuple_clean(&tuple_test); \
test_context(NULL); \
} while (0)
#define TUPLE_TEST_INSPECT(test, expected) \
do { \
s_tuple tuple_test; \
s_str str_result; \
test_context("tuple_inspect(" # test ") -> " # expected); \
tuple_init_1(&tuple_test, (test)); \
TEST_EQ(tuple_inspect(&tuple_test, &str_result), &str_result); \
tuple_clean(&tuple_test); \
if (g_test_last_ok) { \
TEST_EQ(str_result.size, strlen(expected)); \
if (g_test_last_ok) \
TEST_STRNCMP(str_result.ptr.p, (expected), str_result.size); \
str_clean(&str_result); \
} \
test_context(NULL); \
} while (0)
#define TUPLE_TEST_NEW_1(test) \
do { \
s_tuple *tuple_test; \
test_context("tuple_new_1(" # test ")"); \
TEST_ASSERT((tuple_test = tuple_new_1((test)))); \
tuple_delete(tuple_test); \
test_context(NULL); \
} while (0)
#define TUPLE_TEST_NEW_DELETE(test) \
do { \
s_tuple *tuple_test; \
test_context("tuple_new(" # test ")"); \
TEST_ASSERT((tuple_test = tuple_new((test)))); \
tuple_delete(tuple_test); \
test_context(NULL); \
} while (0)
void tuple_test (void);
TEST_CASE_PROTOTYPE(tuple_init_1);
TEST_CASE_PROTOTYPE(tuple_init_clean);
TEST_CASE_PROTOTYPE(tuple_inspect);
TEST_CASE_PROTOTYPE(tuple_new_1);
TEST_CASE_PROTOTYPE(tuple_new_delete);
void tuple_test (void)
{
TEST_CASE_RUN(tuple_init_clean);
TEST_CASE_RUN(tuple_new_delete);
TEST_CASE_RUN(tuple_init_1);
TEST_CASE_RUN(tuple_new_1);
TEST_CASE_RUN(tuple_inspect);
}
TEST_CASE(tuple_init_clean)
{
TUPLE_TEST_INIT_CLEAN(2);
TUPLE_TEST_INIT_CLEAN(3);
TUPLE_TEST_INIT_CLEAN(4);
TUPLE_TEST_INIT_CLEAN(5);
TUPLE_TEST_INIT_CLEAN(6);
TUPLE_TEST_INIT_CLEAN(7);
TUPLE_TEST_INIT_CLEAN(8);
TUPLE_TEST_INIT_CLEAN(9);
TUPLE_TEST_INIT_CLEAN(10);
TUPLE_TEST_INIT_CLEAN(11);
TUPLE_TEST_INIT_CLEAN(12);
TUPLE_TEST_INIT_CLEAN(13);
TUPLE_TEST_INIT_CLEAN(14);
TUPLE_TEST_INIT_CLEAN(15);
TUPLE_TEST_INIT_CLEAN(16);
TUPLE_TEST_INIT_CLEAN(17);
TUPLE_TEST_INIT_CLEAN(18);
TUPLE_TEST_INIT_CLEAN(19);
TUPLE_TEST_INIT_CLEAN(20);
}
TEST_CASE_END(tuple_init_clean)
TEST_CASE(tuple_init_1)
{
TUPLE_TEST_INIT_1("{:a, :b}");
TUPLE_TEST_INIT_1("{:a, :b, :c}");
TUPLE_TEST_INIT_1("{:a, :b, :c, :d}");
TUPLE_TEST_INIT_1("{{:a, :b}, {:c, :d}}");
TUPLE_TEST_INIT_1("{{:a, :b}, {:c, :d}, {:e, :f}}");
TUPLE_TEST_INIT_1("{{:a, :b}, {:c, :d}, {:e, :f}, {:g, :h}}");
TUPLE_TEST_INIT_1("{{:a, :b}, {:c, :d}, {:e, :f}, {:g, :h}, {:i, :j}}");
}
TEST_CASE_END(tuple_init_1)
TEST_CASE(tuple_inspect)
{
TUPLE_TEST_INSPECT("{:a, :b}", "{:a, :b}");
TUPLE_TEST_INSPECT("{{:a, :b}, {:c, :d}}", "{{:a, :b}, {:c, :d}}");
TUPLE_TEST_INSPECT("{{:a, :b}, {:c, :d}, {:e, :f}}",
"{{:a, :b}, {:c, :d}, {:e, :f}}");
}
TEST_CASE_END(tuple_inspect)
TEST_CASE(tuple_new_1)
{
TUPLE_TEST_NEW_1("{:a, :b}");
TUPLE_TEST_NEW_1("{:a, :b, :c}");
TUPLE_TEST_NEW_1("{:a, :b, :c, :d}");
TUPLE_TEST_NEW_1("{{:a, :b}, {:c, :d}}");
TUPLE_TEST_NEW_1("{{:a, :b}, {:c, :d}, {:e, :f}}");
TUPLE_TEST_NEW_1("{{:a, :b}, {:c, :d}, {:e, :f}, {:g, :h}}");
TUPLE_TEST_NEW_1("{{:a, :b}, {:c, :d}, {:e, :f}, {:g, :h}, {:i, :j}}");
}
TEST_CASE_END(tuple_new_1)
TEST_CASE(tuple_new_delete)
{
TUPLE_TEST_NEW_DELETE(2);
TUPLE_TEST_NEW_DELETE(3);
TUPLE_TEST_NEW_DELETE(4);
TUPLE_TEST_NEW_DELETE(5);
TUPLE_TEST_NEW_DELETE(6);
TUPLE_TEST_NEW_DELETE(7);
TUPLE_TEST_NEW_DELETE(8);
TUPLE_TEST_NEW_DELETE(9);
TUPLE_TEST_NEW_DELETE(10);
TUPLE_TEST_NEW_DELETE(11);
TUPLE_TEST_NEW_DELETE(12);
TUPLE_TEST_NEW_DELETE(13);
TUPLE_TEST_NEW_DELETE(14);
TUPLE_TEST_NEW_DELETE(15);
TUPLE_TEST_NEW_DELETE(16);
TUPLE_TEST_NEW_DELETE(17);
TUPLE_TEST_NEW_DELETE(18);
TUPLE_TEST_NEW_DELETE(19);
TUPLE_TEST_NEW_DELETE(20);
}
TEST_CASE_END(tuple_new_delete)