mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 23:35:46 +01:00
apply new formatting rules
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
#define warn(s, ...) fprintf(stderr, "\033[93m" __FILE__ ":" MACRO_STR2(__LINE__) ": [WAR]: " s "\033[0m\n", ##__VA_ARGS__)
|
||||
#define error(s, ...) fprintf(stderr, "\033[91m" __FILE__ ":" MACRO_STR2(__LINE__) ": [ERR]: " s "\033[0m\n", ##__VA_ARGS__)
|
||||
|
||||
#define fatal(s, ...) \
|
||||
do { \
|
||||
#define fatal(s, ...) \
|
||||
do { \
|
||||
printf("\033[101m" __FILE__ ":" MACRO_STR2(__LINE__) ": [FAT]: " s "\033[0m\n", ##__VA_ARGS__); \
|
||||
exit(1); \
|
||||
exit(1); \
|
||||
} while (0)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define WIN_DEFAULT_HEIGHT 480
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ static inline void quit(void) {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char **argv) {
|
||||
(void)argc, (void)argv;
|
||||
printf("debug: [DBG], info: [INF], warning: [WAR], error: [ERR], fatal: [FAT]\n");
|
||||
if (init()) fatal("failed to initialize!");
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
/* 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 */
|
||||
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
|
||||
#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_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);
|
||||
}
|
||||
#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_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);
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
#include "atrb.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
|
||||
|
||||
// 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
|
||||
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
|
||||
// syntax error if we couldn't find the equal sign
|
||||
return (pos == kout)
|
||||
? CONF_ENODAT
|
||||
: (!feq ? CONF_ESYNTAX : 0);
|
||||
return (pos == kout) ? 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
|
||||
size_t i = 0;
|
||||
for (; i < optc; i++) {
|
||||
@@ -65,10 +63,10 @@ struct conf_entry const* conf_matchopt(struct conf_entry const* opts, size_t opt
|
||||
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
|
||||
errno = 0;
|
||||
char* end;
|
||||
char *end;
|
||||
u8 dat[sizeof(u64)];
|
||||
|
||||
switch (opt->type) {
|
||||
@@ -77,30 +75,30 @@ int conf_procval(struct conf_entry const* opt, char const* restrict val) {
|
||||
case CONF_I16:
|
||||
case CONF_I32:
|
||||
case CONF_I64:
|
||||
*(i64*)dat = strtoll(val, &end, 10); // for signed integer types
|
||||
*(i64 *)dat = strtoll(val, &end, 10); // for signed integer types
|
||||
break;
|
||||
// unsigned integer data parsing
|
||||
case CONF_U8:
|
||||
case CONF_U16:
|
||||
case CONF_U32:
|
||||
case CONF_U64:
|
||||
*(u64*)dat = strtoull(val, &end, 10); // for unsigned integer types
|
||||
*(u64 *)dat = strtoull(val, &end, 10); // for unsigned integer types
|
||||
break;
|
||||
|
||||
// floating-point data parsing
|
||||
case CONF_F32: *(f32*)dat = strtof(val, &end); break;
|
||||
case CONF_F64: *(f64*)dat = strtod(val, &end); break;
|
||||
case CONF_F32: *(f32 *)dat = strtof(val, &end); break;
|
||||
case CONF_F64: *(f64 *)dat = strtod(val, &end); break;
|
||||
|
||||
// string data parsing
|
||||
case CONF_STR:
|
||||
if (*(char**)opt->out) {
|
||||
free(*(char**)opt->out); // if the same key is given multiple times, free the memory so we don't leak.
|
||||
if (*(char **)opt->out) {
|
||||
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.");
|
||||
}
|
||||
*(char**)opt->out = strdup(val);
|
||||
*(char **)opt->out = strdup(val);
|
||||
return 0;
|
||||
case CONF_FSTR: {
|
||||
struct conf_fstr* s = opt->out;
|
||||
struct conf_fstr *s = opt->out;
|
||||
strncpy(s->out, val, s->len);
|
||||
s->out[s->len - 1] = '\0'; // ensure the string is null-terminated
|
||||
return 0;
|
||||
@@ -114,22 +112,22 @@ int conf_procval(struct conf_entry const* opt, char const* restrict val) {
|
||||
}
|
||||
|
||||
switch (opt->type) {
|
||||
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_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_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_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_F32: *(f32*)opt->out = *(f32*)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
|
||||
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_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_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_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_F32: *(f32 *)opt->out = *(f32 *)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
|
||||
}
|
||||
}
|
||||
|
||||
/* 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
|
||||
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. */
|
||||
char* conf_getpat(char const* restrict str) {
|
||||
char* buf = NULL;
|
||||
char *conf_getpat(char const *restrict str) {
|
||||
char *buf = NULL;
|
||||
size_t len;
|
||||
size_t str_len = strlen(str);
|
||||
#if defined(__linux__)
|
||||
|
||||
@@ -36,13 +36,13 @@ enum conf_primitive {
|
||||
/* for outputting a fixed string as this config field */
|
||||
struct conf_fstr {
|
||||
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 */
|
||||
struct conf_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
|
||||
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
|
||||
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.
|
||||
* 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` */
|
||||
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. */
|
||||
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.
|
||||
* - `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` */
|
||||
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)
|
||||
* 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.
|
||||
* - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL 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 *);
|
||||
|
||||
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