apply new formatting rules

This commit is contained in:
2025-07-03 10:48:15 +02:00
parent da8e8c1450
commit 2d059cf1db
9 changed files with 113 additions and 115 deletions

View File

@@ -17,7 +17,7 @@
#define WIN_DEFAULT_HEIGHT 480 #define WIN_DEFAULT_HEIGHT 480
// callback for GLFW errors // callback for GLFW errors
static void error_callback(int err, char const* const msg) { static void error_callback(int err, char const *const msg) {
fprintf(stderr, "\033[91mE: glfw returned (%i); \"%s\"\033[0m\n", err, msg); fprintf(stderr, "\033[91mE: glfw returned (%i); \"%s\"\033[0m\n", err, msg);
} }
@@ -35,7 +35,7 @@ static inline void quit(void) {
glfwTerminate(); glfwTerminate();
} }
int main(int argc, char** argv) { int main(int argc, char **argv) {
(void)argc, (void)argv; (void)argc, (void)argv;
printf("debug: [DBG], info: [INF], warning: [WAR], error: [ERR], fatal: [FAT]\n"); printf("debug: [DBG], info: [INF], warning: [WAR], error: [ERR], fatal: [FAT]\n");
if (init()) fatal("failed to initialize!"); if (init()) fatal("failed to initialize!");

View File

@@ -13,7 +13,7 @@
/* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together /* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together
returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */ returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */
static inline int faccess(char const* restrict fname, int perms); static inline int faccess(char const *restrict fname, int perms);
// define the constants if they haven't been // define the constants if they haven't been
#ifndef F_OK #ifndef F_OK
@@ -33,14 +33,14 @@ static inline int faccess(char const* restrict fname, int perms);
#define PATH_SEP '/' // contains the path separator as a character. Yes it is extremely annoying that this has to exist. #define PATH_SEP '/' // contains the path separator as a character. Yes it is extremely annoying that this has to exist.
#define PATH_SEP_STR "/" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist. #define PATH_SEP_STR "/" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist.
int faccess(char const* restrict fname, int perms) { int faccess(char const *restrict fname, int perms) {
return access(fname, perms); return access(fname, perms);
} }
#elif defined(_WIN32) #elif defined(_WIN32)
#define PATH_SEP '\\' // contains the path separator as a character. Yes it is extremely annoying that this has to exist. #define PATH_SEP '\\' // contains the path separator as a character. Yes it is extremely annoying that this has to exist.
#define PATH_SEP_STR "\\" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist. #define PATH_SEP_STR "\\" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist.
int faccess(char const* restrict fname, int perms) { int faccess(char const *restrict fname, int perms) {
return _access(fname, perms); return _access(fname, perms);
} }
#else #else

View File

@@ -14,11 +14,11 @@
#include "atrb.h" #include "atrb.h"
#include "types.h" #include "types.h"
int conf_procbuf(char const* restrict buf, char* restrict kout, char* restrict vout, size_t len) { int conf_procbuf(char const *restrict buf, char *restrict kout, char *restrict vout, size_t len) {
bool feq = false; // whether we've found the equal sign bool feq = false; // whether we've found the equal sign
// data traversal // data traversal
char* pos = kout; // will point to the next point in the buffer, where we'll write data char *pos = kout; // will point to the next point in the buffer, where we'll write data
// acquire data // acquire data
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i++) {
@@ -50,12 +50,10 @@ int conf_procbuf(char const* restrict buf, char* restrict kout, char* restrict v
// no data if we didn't move from the key position // no data if we didn't move from the key position
// syntax error if we couldn't find the equal sign // syntax error if we couldn't find the equal sign
return (pos == kout) return (pos == kout) ? CONF_ENODAT : (!feq ? CONF_ESYNTAX : 0);
? CONF_ENODAT
: (!feq ? CONF_ESYNTAX : 0);
} }
struct conf_entry const* conf_matchopt(struct conf_entry const* opts, size_t optc, char const* restrict key) { struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, char const *restrict key) {
// find a match for the current key // find a match for the current key
size_t i = 0; size_t i = 0;
for (; i < optc; i++) { for (; i < optc; i++) {
@@ -65,10 +63,10 @@ struct conf_entry const* conf_matchopt(struct conf_entry const* opts, size_t opt
return NULL; return NULL;
} }
int conf_procval(struct conf_entry const* opt, char const* restrict val) { int conf_procval(struct conf_entry const *opt, char const *restrict val) {
// parse the data // parse the data
errno = 0; errno = 0;
char* end; char *end;
u8 dat[sizeof(u64)]; u8 dat[sizeof(u64)];
switch (opt->type) { switch (opt->type) {
@@ -77,30 +75,30 @@ int conf_procval(struct conf_entry const* opt, char const* restrict val) {
case CONF_I16: case CONF_I16:
case CONF_I32: case CONF_I32:
case CONF_I64: case CONF_I64:
*(i64*)dat = strtoll(val, &end, 10); // for signed integer types *(i64 *)dat = strtoll(val, &end, 10); // for signed integer types
break; break;
// unsigned integer data parsing // unsigned integer data parsing
case CONF_U8: case CONF_U8:
case CONF_U16: case CONF_U16:
case CONF_U32: case CONF_U32:
case CONF_U64: case CONF_U64:
*(u64*)dat = strtoull(val, &end, 10); // for unsigned integer types *(u64 *)dat = strtoull(val, &end, 10); // for unsigned integer types
break; break;
// floating-point data parsing // floating-point data parsing
case CONF_F32: *(f32*)dat = strtof(val, &end); break; case CONF_F32: *(f32 *)dat = strtof(val, &end); break;
case CONF_F64: *(f64*)dat = strtod(val, &end); break; case CONF_F64: *(f64 *)dat = strtod(val, &end); break;
// string data parsing // string data parsing
case CONF_STR: case CONF_STR:
if (*(char**)opt->out) { if (*(char **)opt->out) {
free(*(char**)opt->out); // if the same key is given multiple times, free the memory so we don't leak. free(*(char **)opt->out); // if the same key is given multiple times, free the memory so we don't leak.
warn("encountered a dynamic string multiple times, this is sub-optimal."); warn("encountered a dynamic string multiple times, this is sub-optimal.");
} }
*(char**)opt->out = strdup(val); *(char **)opt->out = strdup(val);
return 0; return 0;
case CONF_FSTR: { case CONF_FSTR: {
struct conf_fstr* s = opt->out; struct conf_fstr *s = opt->out;
strncpy(s->out, val, s->len); strncpy(s->out, val, s->len);
s->out[s->len - 1] = '\0'; // ensure the string is null-terminated s->out[s->len - 1] = '\0'; // ensure the string is null-terminated
return 0; return 0;
@@ -114,22 +112,22 @@ int conf_procval(struct conf_entry const* opt, char const* restrict val) {
} }
switch (opt->type) { switch (opt->type) {
case CONF_U8: *(u8*)opt->out = *(u64*)dat >= UINT8_MAX ? UINT8_MAX : *(u64*)dat; return 0; case CONF_U8: *(u8 *)opt->out = *(u64 *)dat >= UINT8_MAX ? UINT8_MAX : *(u64 *)dat; return 0;
case CONF_U16: *(u16*)opt->out = *(u64*)dat >= UINT16_MAX ? UINT16_MAX : *(u64*)dat; return 0; case CONF_U16: *(u16 *)opt->out = *(u64 *)dat >= UINT16_MAX ? UINT16_MAX : *(u64 *)dat; return 0;
case CONF_U32: *(u32*)opt->out = *(u64*)dat >= UINT32_MAX ? UINT32_MAX : *(u64*)dat; return 0; case CONF_U32: *(u32 *)opt->out = *(u64 *)dat >= UINT32_MAX ? UINT32_MAX : *(u64 *)dat; return 0;
case CONF_U64: *(u64*)opt->out = *(u64*)dat >= UINT64_MAX ? UINT64_MAX : *(u64*)dat; return 0; case CONF_U64: *(u64 *)opt->out = *(u64 *)dat >= UINT64_MAX ? UINT64_MAX : *(u64 *)dat; return 0;
case CONF_I8: *(i8*)opt->out = *(i64*)dat >= INT8_MAX ? INT8_MAX : (*(i64*)dat <= INT8_MIN ? INT8_MIN : *(i64*)dat); return 0; case CONF_I8: *(i8 *)opt->out = *(i64 *)dat >= INT8_MAX ? INT8_MAX : (*(i64 *)dat <= INT8_MIN ? INT8_MIN : *(i64 *)dat); return 0;
case CONF_I16: *(i16*)opt->out = *(i64*)dat >= INT16_MAX ? INT16_MAX : (*(i64*)dat <= INT16_MIN ? INT16_MIN : *(i64*)dat); return 0; case CONF_I16: *(i16 *)opt->out = *(i64 *)dat >= INT16_MAX ? INT16_MAX : (*(i64 *)dat <= INT16_MIN ? INT16_MIN : *(i64 *)dat); return 0;
case CONF_I32: *(i32*)opt->out = *(i64*)dat >= INT32_MAX ? INT32_MAX : (*(i64*)dat <= INT32_MIN ? INT32_MIN : *(i64*)dat); return 0; case CONF_I32: *(i32 *)opt->out = *(i64 *)dat >= INT32_MAX ? INT32_MAX : (*(i64 *)dat <= INT32_MIN ? INT32_MIN : *(i64 *)dat); return 0;
case CONF_I64: *(i64*)opt->out = *(i64*)dat >= INT64_MAX ? INT64_MAX : (*(i64*)dat <= INT64_MIN ? INT64_MIN : *(i64*)dat); return 0; case CONF_I64: *(i64 *)opt->out = *(i64 *)dat >= INT64_MAX ? INT64_MAX : (*(i64 *)dat <= INT64_MIN ? INT64_MIN : *(i64 *)dat); return 0;
case CONF_F32: *(f32*)opt->out = *(f32*)dat; return 0; case CONF_F32: *(f32 *)opt->out = *(f32 *)dat; return 0;
case CONF_F64: *(f64*)opt->out = *(f64*)dat; return 0; case CONF_F64: *(f64 *)opt->out = *(f64 *)dat; return 0;
default: fatal("invalid switch state, all cases should be handled already"); // abort; this shouldn't be possible, so I blame the programmer default: fatal("invalid switch state, all cases should be handled already"); // abort; this shouldn't be possible, so I blame the programmer
} }
} }
/* utility function for conf_getpat to concatenate 3 strings, where we already know the size */ /* utility function for conf_getpat to concatenate 3 strings, where we already know the size */
atrb_nonnull(1, 3) static char* conf_getpat_concat(char const* restrict s1, char const* restrict s2, char const* restrict s3, size_t s1len, size_t s2len, size_t s3len) { atrb_nonnull(1, 3) static char *conf_getpat_concat(char const *restrict s1, char const *restrict s2, char const *restrict s3, size_t s1len, size_t s2len, size_t s3len) {
assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if they intend to assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if they intend to
char *buf, *ptr; char *buf, *ptr;
@@ -148,8 +146,8 @@ atrb_nonnull(1, 3) static char* conf_getpat_concat(char const* restrict s1, char
} }
/* appends str to the config directory string we acquire from environment variables. */ /* appends str to the config directory string we acquire from environment variables. */
char* conf_getpat(char const* restrict str) { char *conf_getpat(char const *restrict str) {
char* buf = NULL; char *buf = NULL;
size_t len; size_t len;
size_t str_len = strlen(str); size_t str_len = strlen(str);
#if defined(__linux__) #if defined(__linux__)

View File

@@ -36,13 +36,13 @@ enum conf_primitive {
/* for outputting a fixed string as this config field */ /* for outputting a fixed string as this config field */
struct conf_fstr { struct conf_fstr {
size_t len; // length in BYTES of the output data size_t len; // length in BYTES of the output data
char* out; // where we will output the data char *out; // where we will output the data
}; };
/* defines the structure of a config file entry */ /* defines the structure of a config file entry */
struct conf_entry { struct conf_entry {
char const* key; // the key of this entry char const *key; // the key of this entry
void* out; // the pointer to which the data is written value is read if the given option is incorrect or missing void *out; // the pointer to which the data is written value is read if the given option is incorrect or missing
uint8_t type; // the primitive type which we are querying for uint8_t type; // the primitive type which we are querying for
}; };
@@ -51,15 +51,15 @@ struct conf_entry {
* `kout` and `vout` will contain a null-terminated string if the function returned successfully. * `kout` and `vout` will contain a null-terminated string if the function returned successfully.
* returns `0` on success, `<0` when no data was found. `>0` when data was invalid but something went wrong. * returns `0` on success, `<0` when no data was found. `>0` when data was invalid but something went wrong.
* see `CONF_E*` or `enum conf_err` */ * see `CONF_E*` or `enum conf_err` */
int conf_procbuf(char const* restrict buf, char* restrict kout, char* restrict vout, size_t len); int conf_procbuf(char const *restrict buf, char *restrict kout, char *restrict vout, size_t len);
/* matches the key with one of the options and returns the pointer. Returns NULL if none could be found. */ /* matches the key with one of the options and returns the pointer. Returns NULL if none could be found. */
struct conf_entry const* conf_matchopt(struct conf_entry const* opts, size_t optc, char const* restrict key); struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, char const *restrict key);
/* processes the value belonging to the key and outputs the result to opts. /* processes the value belonging to the key and outputs the result to opts.
* - `val` points to a null-terminated string which contains the key and value. * - `val` points to a null-terminated string which contains the key and value.
* returns `0` upon success, non-zero upon failure. For information about specific error codes, see `enum conf_err` */ * returns `0` upon success, non-zero upon failure. For information about specific error codes, see `enum conf_err` */
int conf_procval(struct conf_entry const* opts, char const* restrict val); int conf_procval(struct conf_entry const *opts, char const *restrict val);
/* acquires the config file path, appending str to the end (you need to handle path separators yourself) /* acquires the config file path, appending str to the end (you need to handle path separators yourself)
* expecting str to be null-terminated * expecting str to be null-terminated
@@ -67,4 +67,4 @@ int conf_procval(struct conf_entry const* opts, char const* restrict val);
* - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned. * - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned.
* - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned. * - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned.
* !! A malloc'd null-terminated string is returned !! */ * !! A malloc'd null-terminated string is returned !! */
atrb_malloc atrb_nonnull(1) char* conf_getpat(char const*); atrb_malloc atrb_nonnull(1) char *conf_getpat(char const *);

View File

@@ -11,15 +11,15 @@
// Environment saver structure for conf_getpat tests // Environment saver structure for conf_getpat tests
#if defined(__linux__) || defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__) #if defined(__linux__) || defined(__APPLE__) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
struct test_getpat_envdat { struct test_getpat_envdat {
char* xdg_config_home; char *xdg_config_home;
char* home; char *home;
char* appdata; char *appdata;
char* userprofile; char *userprofile;
}; };
/* save the current environment variables */ /* save the current environment variables */
static void env_save(struct test_getpat_envdat* s) { static void env_save(struct test_getpat_envdat *s) {
char const* tmp; char const *tmp;
tmp = getenv("XDG_CONFIG_HOME"); tmp = getenv("XDG_CONFIG_HOME");
s->xdg_config_home = tmp ? strdup(tmp) : NULL; 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 */ /* 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 #ifdef _WIN32
if (s->xdg_config_home) _putenv_s("XDG_CONFIG_HOME", s->xdg_config_home); if (s->xdg_config_home) _putenv_s("XDG_CONFIG_HOME", s->xdg_config_home);
else _putenv("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 */ /* check procbuf's functionality */
struct test_procbuf { struct test_procbuf {
char const* in; // data in char const *in; // data in
char const* xkey; // expected key char const *xkey; // expected key
char const* xval; // expected value char const *xval; // expected value
int xret; // expected return type int xret; // expected return type
}; };
int test_procbuf(void* arg) { int test_procbuf(void *arg) {
struct test_procbuf* dat = arg; struct test_procbuf *dat = arg;
size_t len = strlen(dat->in) + 1; size_t len = strlen(dat->in) + 1;
char k[len], v[len]; char k[len], v[len];
*k = '\0', *v = '\0'; *k = '\0', *v = '\0';
@@ -81,58 +81,58 @@ int test_procbuf(void* arg) {
/* check matchopt functionality */ /* check matchopt functionality */
struct test_matchopt { 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 xidx; // expect index (<0 is NULL, may not be more than 2)
}; };
int test_matchopt(void* arg) { int test_matchopt(void *arg) {
struct test_matchopt* dat = arg; struct test_matchopt *dat = arg;
struct conf_entry opts[] = { struct conf_entry opts[] = {
{"key1", NULL, 0}, {"key1", NULL, 0},
{"key2", NULL, 0}, {"key2", NULL, 0},
{"key3", 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); return assert_true(conf_matchopt(opts, 3, dat->key) == xopt);
} }
struct test_procval_int { struct test_procval_int {
char const* val; char const *val;
u64 xres; u64 xres;
u8 type; u8 type;
}; };
int test_procval_int(void* arg) { int test_procval_int(void *arg) {
struct test_procval_int* dat = arg; struct test_procval_int *dat = arg;
u64 out = 0; u64 out = 0;
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, dat->type}, dat->val)) || return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, dat->type}, dat->val)) ||
assert_true(out == dat->xres); assert_true(out == dat->xres);
} }
int test_procval_f32(void* arg) { int test_procval_f32(void *arg) {
(void)arg; (void)arg;
f32 out; f32 out;
return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, CONF_F32}, "3.14159265")) || return assert_true(!conf_procval(&(struct conf_entry){NULL, &out, CONF_F32}, "3.14159265")) ||
assert_true(fabsf(out - 3.14159265F) < 1e-6F); assert_true(fabsf(out - 3.14159265F) < 1e-6F);
} }
int test_procval_str(void* arg) { int test_procval_str(void *arg) {
(void)arg; (void)arg;
char* out = NULL; char *out = NULL;
int ret = assert_true(!conf_procval(&(struct conf_entry){NULL, (void*)&out, CONF_STR}, "here comes the sowon")) || 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)); assert_false(strcmp("here comes the sowon", out));
free(out); free(out);
return ret; return ret;
} }
int test_procval_str_predef(void* arg) { int test_procval_str_predef(void *arg) {
(void)arg; (void)arg;
char* out = strdup("owo"); 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")) || 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)); assert_true(!strcmp("i leak if I don't free", out));
free(out); free(out);
return ret; return ret;
} }
int test_procval_fstr(void* arg) { int test_procval_fstr(void *arg) {
(void)arg; (void)arg;
char buf[16]; char buf[16];
struct conf_fstr str = {sizeof(buf), buf}; struct conf_fstr str = {sizeof(buf), buf};
@@ -140,7 +140,7 @@ int test_procval_fstr(void* arg) {
assert_true(!strcmp(str.out, "hewwoo wowld")); assert_true(!strcmp(str.out, "hewwoo wowld"));
} }
int test_procval_fstr_trunc(void* arg) { int test_procval_fstr_trunc(void *arg) {
(void)arg; (void)arg;
char buf[8]; char buf[8];
struct conf_fstr str = {sizeof(buf), buf}; struct conf_fstr str = {sizeof(buf), buf};
@@ -148,19 +148,19 @@ int test_procval_fstr_trunc(void* arg) {
assert_true(!strcmp(str.out, "hewwooo")); assert_true(!strcmp(str.out, "hewwooo"));
} }
int test_procval_eparse(void* arg) { int test_procval_eparse(void *arg) {
(void)arg; (void)arg;
i32 out; i32 out;
return assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE); return assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE);
} }
/* ensure paths are being set correctly */ /* ensure paths are being set correctly */
int test_getpat(void* arg) { int test_getpat(void *arg) {
(void)arg; (void)arg;
struct test_getpat_envdat envs; struct test_getpat_envdat envs;
env_save(&envs); env_save(&envs);
int ret = 0; int ret = 0;
char* path = NULL; char *path = NULL;
#ifdef __linux__ #ifdef __linux__
setenv("XDG_CONFIG_HOME", "/test/config", 1); setenv("XDG_CONFIG_HOME", "/test/config", 1);
@@ -196,7 +196,7 @@ int test_getpat(void* arg) {
_putenv("USERPROFILE="); _putenv("USERPROFILE=");
#endif #endif
void* ptr; void *ptr;
ret |= assert_true(!(ptr = conf_getpat("anything"))); ret |= assert_true(!(ptr = conf_getpat("anything")));
free(ptr); free(ptr);

View File

@@ -8,8 +8,8 @@
#include "../src/util/vec/float3.h" #include "../src/util/vec/float3.h"
#include "test.h" #include "test.h"
int test_float3_norm(void* d) { int test_float3_norm(void *d) {
float* arg = d; float *arg = d;
float3 v = {arg[0], arg[1], arg[2]}; float3 v = {arg[0], arg[1], arg[2]};
float3 r = float3_norm(v); float3 r = float3_norm(v);
float n = r.x * r.x + r.y * r.y + r.z * r.z; 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); return assert_true(fabsf(n - 1.0F) < 1e-6F);
} }
int test_colour32_endianess(void* d) { int test_colour32_endianess(void *d) {
(void)d; (void)d;
colour32 c = {0xFF000000}; // setting just the red channel colour32 c = {0xFF000000}; // setting just the red channel
return assert_true(c.ch.r == 0xFF); return assert_true(c.ch.r == 0xFF);
} }
int test_bswap16(void* d) { int test_bswap16(void *d) {
u16* arg = d; u16 *arg = d;
return assert_true(bswap16(arg[0]) == arg[1]); return assert_true(bswap16(arg[0]) == arg[1]);
} }
int test_bswap32(void* d) { int test_bswap32(void *d) {
u32* arg = d; u32 *arg = d;
return assert_true(bswap32(arg[0]) == arg[1]); return assert_true(bswap32(arg[0]) == arg[1]);
} }
int test_bswap64(void* d) { int test_bswap64(void *d) {
u64* arg = d; u64 *arg = d;
return assert_true(bswap64(arg[0]) == arg[1]); return assert_true(bswap64(arg[0]) == arg[1]);
} }
int test_bswap16_impl(void* d) { int test_bswap16_impl(void *d) {
u16* arg = d; u16 *arg = d;
return assert_true(bswap16_impl(arg[0]) == arg[1]); return assert_true(bswap16_impl(arg[0]) == arg[1]);
} }
int test_bswap32_impl(void* d) { int test_bswap32_impl(void *d) {
u32* arg = d; u32 *arg = d;
return assert_true(bswap32_impl(arg[0]) == arg[1]); return assert_true(bswap32_impl(arg[0]) == arg[1]);
} }
int test_bswap64_impl(void* d) { int test_bswap64_impl(void *d) {
u64* arg = d; u64 *arg = d;
return assert_true(bswap64_impl(arg[0]) == arg[1]); return assert_true(bswap64_impl(arg[0]) == arg[1]);
} }

View File

@@ -3,12 +3,12 @@
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
char const* test_ctest; char const *test_ctest;
size_t test_runs = 0; size_t test_runs = 0;
// evaluates the test // evaluates the test
// returns 1 upon error // 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++; test_runs++;
if (cond) if (cond)
printf("[\033[32;1m OK \033[0m] %s %s -> %s:%u (%s)\n", test_ctest, fnname, fname, ln, expr); 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 // contains the data for executing a single test
struct testdat { struct testdat {
char const* name; // test name char const *name; // test name
int (*test)(void*); // test, returns 0 upon success, non-zero upon failure int (*test)(void *); // test, returns 0 upon success, non-zero upon failure
void* args; // arguments to the test void *args; // arguments to the test
}; };
typedef struct testdat testdat; typedef struct testdat testdat;
// executes the tests, returns the amount of failed tests; >0: failure // 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 i;
size_t err = 0; size_t err = 0;