mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 03:25:45 +01:00
apply new formatting rules
This commit is contained in:
34
test/dat.h
34
test/dat.h
@@ -8,14 +8,14 @@
|
||||
#include "test.h"
|
||||
|
||||
testdat tests[] = {
|
||||
{"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} },
|
||||
{"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} },
|
||||
{"", test_bswap16, (u16[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"", test_bswap16_impl, (u16[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32_impl, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64_impl, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"", test_float3_norm, &(float3){2.0F, 0.67F, 5.0F} },
|
||||
{"", test_float3_norm, &(float3){0.2F, 0.4F, 0.1F} },
|
||||
{"", test_bswap16, (u16[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"", test_bswap16_impl, (u16[]){0x11EE, 0xEE11} },
|
||||
{"", test_bswap32_impl, (u32[]){0x1142ADEE, 0xEEAD4211} },
|
||||
{"", test_bswap64_impl, (u64[]){0x114266897799ADEE, 0xEEAD997789664211} },
|
||||
{"k=v", test_procbuf, &(struct test_procbuf){"key=val", "key", "val", 0} },
|
||||
{"sometxt", test_procbuf, &(struct test_procbuf){"sometxt", "sometxt", "", CONF_ESYNTAX} },
|
||||
{"comment", test_procbuf, &(struct test_procbuf){"# comment", "", "", CONF_ENODAT} },
|
||||
@@ -26,17 +26,17 @@ testdat tests[] = {
|
||||
{"k=v (CRLF)", test_procbuf, &(struct test_procbuf){"k=v\r\na", "k", "v", 0} },
|
||||
{"get", test_matchopt, &(struct test_matchopt){"key3", 2} },
|
||||
{"invalid", test_matchopt, &(struct test_matchopt){"nono", -1} },
|
||||
{"", test_colour32_endianess, NULL }, // NOTE: formatter is fucking with alignment making it use tabs @.@
|
||||
{"", test_colour32_endianess, NULL }, // NOTE: formatter is fucking with alignment making it use tabs @.@
|
||||
{"i32", test_procval_int, &(struct test_procval_int){"42", 42, CONF_I32} },
|
||||
{"i32_neg", test_procval_int, &(struct test_procval_int){"-42", (u32)-42, CONF_I32} },
|
||||
{"i32_neg", test_procval_int, &(struct test_procval_int){"-42", (u32)-42, CONF_I32} },
|
||||
{"u32_max", test_procval_int, &(struct test_procval_int){"4294967295", UINT32_MAX, CONF_U64} },
|
||||
{"u64", test_procval_int, &(struct test_procval_int){"3141592653589793238", 3141592653589793238, CONF_U64}},
|
||||
{"u8_overflow", test_procval_int, &(struct test_procval_int){"256", 255, CONF_U8} },
|
||||
{"", test_procval_f32, NULL },
|
||||
{"", test_procval_str, NULL },
|
||||
{"", test_procval_str_predef, NULL },
|
||||
{"", test_procval_fstr, NULL },
|
||||
{"", test_procval_fstr_trunc, NULL },
|
||||
{"", test_procval_eparse, NULL },
|
||||
{"", test_getpat, NULL },
|
||||
{"", test_procval_f32, NULL },
|
||||
{"", test_procval_str, NULL },
|
||||
{"", test_procval_str_predef, NULL },
|
||||
{"", test_procval_fstr, NULL },
|
||||
{"", test_procval_fstr_trunc, NULL },
|
||||
{"", test_procval_eparse, NULL },
|
||||
{"", test_getpat, NULL },
|
||||
};
|
||||
|
||||
@@ -11,15 +11,15 @@
|
||||
// Environment saver structure for conf_getpat tests
|
||||
#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
|
||||
struct test_getpat_envdat {
|
||||
char* xdg_config_home;
|
||||
char* home;
|
||||
char* appdata;
|
||||
char* userprofile;
|
||||
char *xdg_config_home;
|
||||
char *home;
|
||||
char *appdata;
|
||||
char *userprofile;
|
||||
};
|
||||
|
||||
/* save the current environment variables */
|
||||
static void env_save(struct test_getpat_envdat* s) {
|
||||
char const* tmp;
|
||||
static void env_save(struct test_getpat_envdat *s) {
|
||||
char const *tmp;
|
||||
|
||||
tmp = getenv("XDG_CONFIG_HOME");
|
||||
s->xdg_config_home = tmp ? strdup(tmp) : NULL;
|
||||
@@ -35,7 +35,7 @@ static void env_save(struct test_getpat_envdat* s) {
|
||||
}
|
||||
|
||||
/* restores the environment variables to what they were before */
|
||||
static void env_restore(struct test_getpat_envdat* s) {
|
||||
static void env_restore(struct test_getpat_envdat *s) {
|
||||
#ifdef _WIN32
|
||||
if (s->xdg_config_home) _putenv_s("XDG_CONFIG_HOME", s->xdg_config_home);
|
||||
else _putenv("XDG_CONFIG_HOME=");
|
||||
@@ -64,13 +64,13 @@ static void env_restore(struct test_getpat_envdat* s) {
|
||||
|
||||
/* check procbuf's functionality */
|
||||
struct test_procbuf {
|
||||
char const* in; // data in
|
||||
char const* xkey; // expected key
|
||||
char const* xval; // expected value
|
||||
char const *in; // data in
|
||||
char const *xkey; // expected key
|
||||
char const *xval; // expected value
|
||||
int xret; // expected return type
|
||||
};
|
||||
int test_procbuf(void* arg) {
|
||||
struct test_procbuf* dat = arg;
|
||||
int test_procbuf(void *arg) {
|
||||
struct test_procbuf *dat = arg;
|
||||
size_t len = strlen(dat->in) + 1;
|
||||
char k[len], v[len];
|
||||
*k = '\0', *v = '\0';
|
||||
@@ -81,58 +81,58 @@ int test_procbuf(void* arg) {
|
||||
|
||||
/* check matchopt functionality */
|
||||
struct test_matchopt {
|
||||
char const* key; // key to search for (key1, key2, key3)
|
||||
char const *key; // key to search for (key1, key2, key3)
|
||||
int xidx; // expect index (<0 is NULL, may not be more than 2)
|
||||
};
|
||||
int test_matchopt(void* arg) {
|
||||
struct test_matchopt* dat = arg;
|
||||
int test_matchopt(void *arg) {
|
||||
struct test_matchopt *dat = arg;
|
||||
struct conf_entry opts[] = {
|
||||
{"key1", NULL, 0},
|
||||
{"key2", NULL, 0},
|
||||
{"key3", NULL, 0},
|
||||
};
|
||||
struct conf_entry* xopt = dat->xidx < 0 ? NULL : opts + dat->xidx;
|
||||
struct conf_entry *xopt = dat->xidx < 0 ? NULL : opts + dat->xidx;
|
||||
return assert_true(conf_matchopt(opts, 3, dat->key) == xopt);
|
||||
}
|
||||
|
||||
struct test_procval_int {
|
||||
char const* val;
|
||||
char const *val;
|
||||
u64 xres;
|
||||
u8 type;
|
||||
};
|
||||
int test_procval_int(void* arg) {
|
||||
struct test_procval_int* dat = arg;
|
||||
int test_procval_int(void *arg) {
|
||||
struct test_procval_int *dat = arg;
|
||||
u64 out = 0;
|
||||
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, dat->type}, dat->val)) ||
|
||||
assert_true(out == dat->xres);
|
||||
}
|
||||
|
||||
int test_procval_f32(void* arg) {
|
||||
int test_procval_f32(void *arg) {
|
||||
(void)arg;
|
||||
f32 out;
|
||||
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, CONF_F32}, "3.14159265")) ||
|
||||
assert_true(fabsf(out - 3.14159265F) < 1e-6F);
|
||||
}
|
||||
|
||||
int test_procval_str(void* arg) {
|
||||
int test_procval_str(void *arg) {
|
||||
(void)arg;
|
||||
char* out = NULL;
|
||||
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void*)&out, CONF_STR}, "here comes the sowon")) ||
|
||||
char *out = NULL;
|
||||
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "here comes the sowon")) ||
|
||||
assert_false(strcmp("here comes the sowon", out));
|
||||
free(out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_procval_str_predef(void* arg) {
|
||||
int test_procval_str_predef(void *arg) {
|
||||
(void)arg;
|
||||
char* out = strdup("owo");
|
||||
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void*)&out, CONF_STR}, "i leak if I don't free")) ||
|
||||
char *out = strdup("owo");
|
||||
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void *)&out, CONF_STR}, "i leak if I don't free")) ||
|
||||
assert_true(!strcmp("i leak if I don't free", out));
|
||||
free(out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int test_procval_fstr(void* arg) {
|
||||
int test_procval_fstr(void *arg) {
|
||||
(void)arg;
|
||||
char buf[16];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
@@ -140,7 +140,7 @@ int test_procval_fstr(void* arg) {
|
||||
assert_true(!strcmp(str.out, "hewwoo wowld"));
|
||||
}
|
||||
|
||||
int test_procval_fstr_trunc(void* arg) {
|
||||
int test_procval_fstr_trunc(void *arg) {
|
||||
(void)arg;
|
||||
char buf[8];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
@@ -148,19 +148,19 @@ int test_procval_fstr_trunc(void* arg) {
|
||||
assert_true(!strcmp(str.out, "hewwooo"));
|
||||
}
|
||||
|
||||
int test_procval_eparse(void* arg) {
|
||||
int test_procval_eparse(void *arg) {
|
||||
(void)arg;
|
||||
i32 out;
|
||||
return assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE);
|
||||
}
|
||||
|
||||
/* ensure paths are being set correctly */
|
||||
int test_getpat(void* arg) {
|
||||
int test_getpat(void *arg) {
|
||||
(void)arg;
|
||||
struct test_getpat_envdat envs;
|
||||
env_save(&envs);
|
||||
int ret = 0;
|
||||
char* path = NULL;
|
||||
char *path = NULL;
|
||||
|
||||
#ifdef __linux__
|
||||
setenv("XDG_CONFIG_HOME", "/test/config", 1);
|
||||
@@ -196,7 +196,7 @@ int test_getpat(void* arg) {
|
||||
|
||||
_putenv("USERPROFILE=");
|
||||
#endif
|
||||
void* ptr;
|
||||
void *ptr;
|
||||
ret |= assert_true(!(ptr = conf_getpat("anything")));
|
||||
free(ptr);
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "../src/util/vec/float3.h"
|
||||
#include "test.h"
|
||||
|
||||
int test_float3_norm(void* d) {
|
||||
float* arg = d;
|
||||
int test_float3_norm(void *d) {
|
||||
float *arg = d;
|
||||
float3 v = {arg[0], arg[1], arg[2]};
|
||||
float3 r = float3_norm(v);
|
||||
float n = r.x * r.x + r.y * r.y + r.z * r.z;
|
||||
@@ -18,38 +18,38 @@ int test_float3_norm(void* d) {
|
||||
return assert_true(fabsf(n - 1.0F) < 1e-6F);
|
||||
}
|
||||
|
||||
int test_colour32_endianess(void* d) {
|
||||
int test_colour32_endianess(void *d) {
|
||||
(void)d;
|
||||
colour32 c = {0xFF000000}; // setting just the red channel
|
||||
return assert_true(c.ch.r == 0xFF);
|
||||
}
|
||||
|
||||
int test_bswap16(void* d) {
|
||||
u16* arg = d;
|
||||
int test_bswap16(void *d) {
|
||||
u16 *arg = d;
|
||||
return assert_true(bswap16(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap32(void* d) {
|
||||
u32* arg = d;
|
||||
int test_bswap32(void *d) {
|
||||
u32 *arg = d;
|
||||
return assert_true(bswap32(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap64(void* d) {
|
||||
u64* arg = d;
|
||||
int test_bswap64(void *d) {
|
||||
u64 *arg = d;
|
||||
return assert_true(bswap64(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap16_impl(void* d) {
|
||||
u16* arg = d;
|
||||
int test_bswap16_impl(void *d) {
|
||||
u16 *arg = d;
|
||||
return assert_true(bswap16_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap32_impl(void* d) {
|
||||
u32* arg = d;
|
||||
int test_bswap32_impl(void *d) {
|
||||
u32 *arg = d;
|
||||
return assert_true(bswap32_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
int test_bswap64_impl(void* d) {
|
||||
u64* arg = d;
|
||||
int test_bswap64_impl(void *d) {
|
||||
u64 *arg = d;
|
||||
return assert_true(bswap64_impl(arg[0]) == arg[1]);
|
||||
}
|
||||
|
||||
12
test/test.h
12
test/test.h
@@ -3,12 +3,12 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
|
||||
char const* test_ctest;
|
||||
char const *test_ctest;
|
||||
size_t test_runs = 0;
|
||||
|
||||
// evaluates the test
|
||||
// returns 1 upon error
|
||||
static inline int assert_helper(int cond, char const* restrict fname, unsigned ln, char const* restrict fnname, char const* restrict expr) {
|
||||
static inline int assert_helper(int cond, char const *restrict fname, unsigned ln, char const *restrict fnname, char const *restrict expr) {
|
||||
test_runs++;
|
||||
if (cond)
|
||||
printf("[\033[32;1m OK \033[0m] %s %s -> %s:%u (%s)\n", test_ctest, fnname, fname, ln, expr);
|
||||
@@ -22,14 +22,14 @@ static inline int assert_helper(int cond, char const* restrict fname, unsigned l
|
||||
|
||||
// contains the data for executing a single test
|
||||
struct testdat {
|
||||
char const* name; // test name
|
||||
int (*test)(void*); // test, returns 0 upon success, non-zero upon failure
|
||||
void* args; // arguments to the test
|
||||
char const *name; // test name
|
||||
int (*test)(void *); // test, returns 0 upon success, non-zero upon failure
|
||||
void *args; // arguments to the test
|
||||
};
|
||||
typedef struct testdat testdat;
|
||||
|
||||
// executes the tests, returns the amount of failed tests; >0: failure
|
||||
static inline size_t exec_tests(testdat* dat, size_t ntests) {
|
||||
static inline size_t exec_tests(testdat *dat, size_t ntests) {
|
||||
size_t i;
|
||||
size_t err = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user