expand integer config tests

This commit is contained in:
2025-06-16 12:30:05 +02:00
parent 38aa65942f
commit 48f4b28f90
2 changed files with 40 additions and 39 deletions

View File

@@ -7,32 +7,35 @@
#include "test.h" #include "test.h"
testdat tests[] = { testdat tests[] = {
{"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} }, {"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} },
{"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} }, {"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} },
{"", test_bswap16, (uint16_t[]){0x11EE, 0xEE11} }, {"", test_bswap16, (uint16_t[]){0x11EE, 0xEE11} },
{"", test_bswap32, (uint32_t[]){0x1142ADEE, 0xEEAD4211} }, {"", test_bswap32, (uint32_t[]){0x1142ADEE, 0xEEAD4211} },
{"", test_bswap64, (uint64_t[]){0x114266897799ADEE, 0xEEAD997789664211} }, {"", test_bswap64, (uint64_t[]){0x114266897799ADEE, 0xEEAD997789664211} },
{"", test_bswap16_impl, (uint16_t[]){0x11EE, 0xEE11} }, {"", test_bswap16_impl, (uint16_t[]){0x11EE, 0xEE11} },
{"", test_bswap32_impl, (uint32_t[]){0x1142ADEE, 0xEEAD4211} }, {"", test_bswap32_impl, (uint32_t[]){0x1142ADEE, 0xEEAD4211} },
{"", test_bswap64_impl, (uint64_t[]){0x114266897799ADEE, 0xEEAD997789664211} }, {"", test_bswap64_impl, (uint64_t[]){0x114266897799ADEE, 0xEEAD997789664211} },
{"k=v", test_procbuf, &(struct test_procbuf){"key=val", "key", "val", 0} }, {"k=v", test_procbuf, &(struct test_procbuf){"key=val", "key", "val", 0} },
{"sometxt", test_procbuf, &(struct test_procbuf){"sometxt", "sometxt", "", CONF_ESYNTAX}}, {"sometxt", test_procbuf, &(struct test_procbuf){"sometxt", "sometxt", "", CONF_ESYNTAX} },
{"comment", test_procbuf, &(struct test_procbuf){"# comment", "", "", CONF_ENODAT} }, {"comment", test_procbuf, &(struct test_procbuf){"# comment", "", "", CONF_ENODAT} },
{"empty", test_procbuf, &(struct test_procbuf){"", "", "", CONF_ENODAT} }, {"empty", test_procbuf, &(struct test_procbuf){"", "", "", CONF_ENODAT} },
{"LF", test_procbuf, &(struct test_procbuf){"\n", "", "", CONF_ENODAT} }, {"LF", test_procbuf, &(struct test_procbuf){"\n", "", "", CONF_ENODAT} },
{"CRLF", test_procbuf, &(struct test_procbuf){"\r\n", "", "", CONF_ENODAT} }, {"CRLF", test_procbuf, &(struct test_procbuf){"\r\n", "", "", CONF_ENODAT} },
{"k=v (LF)", test_procbuf, &(struct test_procbuf){"k=v\na", "k", "v", 0} }, {"k=v (LF)", test_procbuf, &(struct test_procbuf){"k=v\na", "k", "v", 0} },
{"k=v (CRLF)", test_procbuf, &(struct test_procbuf){"k=v\r\na", "k", "v", 0} }, {"k=v (CRLF)", test_procbuf, &(struct test_procbuf){"k=v\r\na", "k", "v", 0} },
{"get", test_matchopt, &(struct test_matchopt){"key3", 2} }, {"get", test_matchopt, &(struct test_matchopt){"key3", 2} },
{"invalid", test_matchopt, &(struct test_matchopt){"nono", -1} }, {"invalid", test_matchopt, &(struct test_matchopt){"nono", -1} },
{"", test_colour32_endianess, NULL }, {"", test_colour32_endianess, NULL }, // NOTE: formatter is fucking with alignment making it use tabs @.@
{"", test_procval_i32, NULL }, {"i32", test_procval_int, &(struct test_procval_int){"42", 42, CONF_I32} },
{"", test_procval_u64, NULL }, {"i32_neg", test_procval_int, &(struct test_procval_int){"-42", (uint32_t)-42, CONF_I32} },
{"", test_procval_f32, NULL }, {"u32_max", test_procval_int, &(struct test_procval_int){"4294967295", UINT32_MAX, CONF_U64} },
{"", test_procval_str, NULL }, {"u64", test_procval_int, &(struct test_procval_int){"3141592653589793238", 3141592653589793238, CONF_U64}},
{"", test_procval_str_predef, NULL }, {"u8_overflow", test_procval_int, &(struct test_procval_int){"256", 255, CONF_U8} },
{"", test_procval_fstr, NULL }, {"", test_procval_f32, NULL },
{"", test_procval_fstr_trunc, NULL }, {"", test_procval_str, NULL },
{"", test_procval_eparse, NULL }, {"", test_procval_str_predef, NULL },
{"", test_getpat, NULL }, {"", test_procval_fstr, NULL },
{"", test_procval_fstr_trunc, NULL },
{"", test_procval_eparse, NULL },
{"", test_getpat, NULL },
}; };

View File

@@ -94,18 +94,16 @@ int test_matchopt(void* arg) {
return assert_true(conf_matchopt(opts, 3, dat->key) == xopt); return assert_true(conf_matchopt(opts, 3, dat->key) == xopt);
} }
int test_procval_i32(void* arg) { struct test_procval_int {
(void)arg; char const* val;
int32_t out; uint64_t xres;
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "42")) || uint8_t type;
assert_true(out == 42); };
} int test_procval_int(void* arg) {
struct test_procval_int* dat = arg;
int test_procval_u64(void* arg) {
(void)arg;
uint64_t out; uint64_t out;
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, CONF_U64}, "3141592653589793238")) || return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, dat->type}, dat->val)) ||
assert_true(out == 3141592653589793238); assert_true(out == dat->xres);
} }
int test_procval_f32(void* arg) { int test_procval_f32(void* arg) {