aboutsummaryrefslogtreecommitdiffstats
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c80
1 files changed, 56 insertions, 24 deletions
diff --git a/test.c b/test.c
index da565c4..87dbcbf 100644
--- a/test.c
+++ b/test.c
@@ -58,49 +58,81 @@ check(size_t count, char **strings, ...)
}
+static void
+cnst_check(size_t count, const char **strings, ...)
+{
+ size_t i, len;
+ const char *expect;
+ va_list args;
+ va_start(args, strings);
+ for (i = 0; (expect = va_arg(args, const char *)); i++) {
+ len = strlen(expect);
+ assert(strings[i]);
+ assert(!strncmp(strings[i], expect, len));
+ assert(!strings[i][len] || strings[i][len] == '=');
+ }
+ va_end(args);
+ assert(!strings[i]);
+ assert(count == i);
+}
+
+
#define CHECK(CALL, ...)\
do {\
+ const char *cstrings[8];\
char *strings[8];\
char *allocations[8];\
size_t i;\
char *p;\
- assert((strings[0] = allocations[0] = strdup("a=")));\
- assert((strings[1] = allocations[1] = strdup("aa=1")));\
- assert((strings[2] = allocations[2] = strdup("b=12")));\
- assert((strings[3] = allocations[3] = strdup("bb=34")));\
- assert((strings[4] = allocations[4] = strdup("BB")));\
- assert((strings[5] = allocations[5] = strdup("x=5")));\
- assert((strings[6] = allocations[6] = strdup("xx")));\
- strings[7] = allocations[7] = NULL;\
+ assert((cstrings[0] = strings[0] = allocations[0] = strdup("a=")));\
+ assert((cstrings[1] = strings[1] = allocations[1] = strdup("aa=1")));\
+ assert((cstrings[2] = strings[2] = allocations[2] = strdup("b=12")));\
+ assert((cstrings[3] = strings[3] = allocations[3] = strdup("bb=34")));\
+ assert((cstrings[4] = strings[4] = allocations[4] = strdup("BB")));\
+ assert((cstrings[5] = strings[5] = allocations[5] = strdup("x=5")));\
+ assert((cstrings[6] = strings[6] = allocations[6] = strdup("xx")));\
+ cstrings[7] = strings[7] = allocations[7] = NULL;\
if (!variable_version) {\
for (i = 0; strings[i]; i++) {\
for (p = strings[i]; *p && *p != '='; p++);\
*p = '\0';\
}\
}\
- check(CALL, strings, __VA_ARGS__);\
+ if (dealloc_version)\
+ check(CALL, strings, __VA_ARGS__);\
+ else if (dealloc_version)\
+ cnst_check(CALL, cstrings, __VA_ARGS__);\
dealloc(dealloc_version ? strings : allocations);\
} while (0)
+#define TEST_FILTER(FUN, STRS)\
+ do {\
+ CHECK((*function->FUN)(STRS, LIBENV_END), NULL); /* each contain all of nothing, so remove all */\
+ if (!variable_version) {\
+ CHECK((*function->FUN)(STRS, 3, LIBENV_END), "a", "aa", "b", "bb", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 2, LIBENV_END), "a", "b", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 1, 2, 3, LIBENV_END), "a", "aa", "b", "bb", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 1, 2, LIBENV_END), "a", "b", "bb", "x", "xx", NULL);\
+ } else {\
+ CHECK((*function->FUN)(STRS, 3, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 2, LIBENV_END), "a", "b", "BB", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 1, 2, 3, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 1, 2, LIBENV_END), "a", "b", "bb", "BB", "x", "xx", NULL);\
+ }\
+ CHECK((*function->FUN)(STRS, 10, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 64, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);\
+ CHECK((*function->FUN)(STRS, 100000, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);\
+ } while (0)
+
+
static void
test_filter(int dealloc_version, int variable_version, const union list_process_function *function)
{
- CHECK((*function->dyn)(strings, LIBENV_END), NULL); /* each contain all of nothing, so remove all */
- if (!variable_version) {
- CHECK((*function->dyn)(strings, 3, LIBENV_END), "a", "aa", "b", "bb", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 2, LIBENV_END), "a", "b", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 1, 2, 3, LIBENV_END), "a", "aa", "b", "bb", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 1, 2, LIBENV_END), "a", "b", "bb", "x", "xx", NULL);
- } else {
- CHECK((*function->dyn)(strings, 3, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 2, LIBENV_END), "a", "b", "BB", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 1, 2, 3, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 1, 2, LIBENV_END), "a", "b", "bb", "BB", "x", "xx", NULL);
- }
- CHECK((*function->dyn)(strings, 10, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 64, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);
- CHECK((*function->dyn)(strings, 100000, LIBENV_END), "a", "aa", "b", "bb", "BB", "x", "xx", NULL);
+ if (dealloc_version)
+ TEST_FILTER(dyn, strings);
+ else
+ TEST_FILTER(cnst, cstrings);
}