refactor code with new formatting rules

Functions now break before their brace, mirroring the Linux kernel.
The reason for this is that breaking the parameter list otherwise makes
code unreadable.
This commit is contained in:
2025-10-09 18:43:09 +02:00
parent eb45650178
commit 00719b1933
14 changed files with 137 additions and 73 deletions

View File

@@ -6,7 +6,8 @@
#include "test.h"
#include "test_conf.h"
int main(void) {
int main(void)
{
assert_true(-3 >> 5 == -1); // checking for arithmetic shift, rather than logical shift
assert_true(sizeof(u8) == 1);
assert_true(sizeof(u16) == 2);

View File

@@ -7,7 +7,8 @@
uint test_okay = 0;
uint test_fail = 0;
int test_process(int res, const char *restrict file, uint ln, const char *restrict function, const char *restrict expression) {
int test_process(int res, const char *restrict file, uint ln, const char *restrict function, const char *restrict expression)
{
const char *status = res ?
"[\033[32;1m OK \033[0m]" :
"[\033[31;1m FAIL \033[0m]";

View File

@@ -9,7 +9,8 @@
#include "../src/util/conf.h"
#include "test.h"
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return) {
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return)
{
usize len = strlen(buf) + 1;
char k[len], v[len];
*k = '\0', *v = '\0';
@@ -18,20 +19,23 @@ void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key
assert_true(!strcmp(v, expect_val)));
}
void test_conf_matchopt(struct conf_entry *opts, usize optc, const char *restrict key, int expect_index) {
void test_conf_matchopt(struct conf_entry *opts, usize optc, const char *restrict key, int expect_index)
{
usize idx = opts - conf_matchopt(opts, optc, key);
idx = (ssize)idx < 0 ? -idx : idx;
int i = idx < optc ? (int)idx : -1;
assert_true(i == expect_index);
}
void test_conf_procval_int(const char *val, u64 expect_value, int type) {
void test_conf_procval_int(const char *val, u64 expect_value, int type)
{
u8 out[sizeof(u64)] = {0};
assert_true(!conf_procval(&(struct conf_entry){NULL, out, type}, val));
assert_true(memcmp(out, &expect_value, sizeof(u64)) == 0);
}
void test_conf_procval_f32(const char *val, f32 expect_value) {
void test_conf_procval_f32(const char *val, f32 expect_value)
{
u8 out[4];
f32 result;
conf_procval(&(struct conf_entry){NULL, out, CONF_F32}, val);
@@ -39,40 +43,46 @@ void test_conf_procval_f32(const char *val, f32 expect_value) {
assert_true(fabsf(expect_value - result) < 1e-9f);
}
void test_procval_str(void) {
void test_procval_str(void)
{
char *out = NULL;
(void)(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);
}
void test_procval_str_predef(void) {
void test_procval_str_predef(void)
{
char *out = strdup("owo");
(void)(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);
}
void test_procval_fstr(void) {
void test_procval_fstr(void)
{
char buf[16];
struct conf_fstr str = {sizeof(buf), buf};
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwoo wowld")) &&
assert_true(!strcmp(str.out, "hewwoo wowld")));
}
void test_procval_fstr_trunc(void) {
void test_procval_fstr_trunc(void)
{
char buf[8];
struct conf_fstr str = {sizeof(buf), buf};
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwooo wowld")) &&
assert_true(!strcmp(str.out, "hewwooo")));
}
void test_procval_eparse(void) {
void test_procval_eparse(void)
{
i32 out;
assert_true(conf_procval(&(struct conf_entry){NULL, &out, CONF_I32}, "owo") == CONF_EPARSE);
}
void test_conf_getpat(void) {
void test_conf_getpat(void)
{
char *path;
#if defined(__linux__)
/* test without setting environment variables. */