Run clang-format on test/unit/conf_parse.c

This commit is contained in:
Slobodan Predolac 2026-03-31 20:33:49 -07:00
parent 5904a42187
commit 3ac9f96158

View file

@ -27,8 +27,8 @@ TEST_END
TEST_BEGIN(test_conf_handle_unsigned_in_range) { TEST_BEGIN(test_conf_handle_unsigned_in_range) {
uintmax_t result = 0; uintmax_t result = 0;
bool err = conf_handle_unsigned("100", sizeof("100") - 1, bool err = conf_handle_unsigned(
1, 2048, true, true, true, &result); "100", sizeof("100") - 1, 1, 2048, true, true, true, &result);
expect_false(err, "Should succeed for in-range value"); expect_false(err, "Should succeed for in-range value");
expect_u64_eq((uint64_t)result, 100, "result should be 100"); expect_u64_eq((uint64_t)result, 100, "result should be 100");
} }
@ -36,44 +36,43 @@ TEST_END
TEST_BEGIN(test_conf_handle_unsigned_clip_max) { TEST_BEGIN(test_conf_handle_unsigned_clip_max) {
uintmax_t result = 0; uintmax_t result = 0;
bool err = conf_handle_unsigned("9999", sizeof("9999") - 1, bool err = conf_handle_unsigned(
1, 2048, true, true, true, &result); "9999", sizeof("9999") - 1, 1, 2048, true, true, true, &result);
expect_false(err, "Should succeed with clipping"); expect_false(err, "Should succeed with clipping");
expect_u64_eq((uint64_t)result, 2048, expect_u64_eq(
"result should be clipped to max 2048"); (uint64_t)result, 2048, "result should be clipped to max 2048");
} }
TEST_END TEST_END
TEST_BEGIN(test_conf_handle_unsigned_clip_min) { TEST_BEGIN(test_conf_handle_unsigned_clip_min) {
uintmax_t result = 0; uintmax_t result = 0;
bool err = conf_handle_unsigned("0", sizeof("0") - 1, bool err = conf_handle_unsigned(
1, 2048, true, true, true, &result); "0", sizeof("0") - 1, 1, 2048, true, true, true, &result);
expect_false(err, "Should succeed with clipping"); expect_false(err, "Should succeed with clipping");
expect_u64_eq((uint64_t)result, 1, expect_u64_eq((uint64_t)result, 1, "result should be clipped to min 1");
"result should be clipped to min 1");
} }
TEST_END TEST_END
TEST_BEGIN(test_conf_handle_unsigned_no_clip_reject) { TEST_BEGIN(test_conf_handle_unsigned_no_clip_reject) {
uintmax_t result = 0; uintmax_t result = 0;
bool err = conf_handle_unsigned("9999", sizeof("9999") - 1, bool err = conf_handle_unsigned(
1, 2048, true, true, false, &result); "9999", sizeof("9999") - 1, 1, 2048, true, true, false, &result);
expect_true(err, "Should fail for out-of-range value without clip"); expect_true(err, "Should fail for out-of-range value without clip");
} }
TEST_END TEST_END
TEST_BEGIN(test_conf_handle_unsigned_invalid) { TEST_BEGIN(test_conf_handle_unsigned_invalid) {
uintmax_t result = 0; uintmax_t result = 0;
bool err = conf_handle_unsigned("abc", sizeof("abc") - 1, bool err = conf_handle_unsigned(
1, 2048, true, true, true, &result); "abc", sizeof("abc") - 1, 1, 2048, true, true, true, &result);
expect_true(err, "Should fail for non-numeric input"); expect_true(err, "Should fail for non-numeric input");
} }
TEST_END TEST_END
TEST_BEGIN(test_conf_handle_signed_valid) { TEST_BEGIN(test_conf_handle_signed_valid) {
intmax_t result = 0; intmax_t result = 0;
bool err = conf_handle_signed("5000", sizeof("5000") - 1, bool err = conf_handle_signed("5000", sizeof("5000") - 1, -1,
-1, INTMAX_MAX, true, false, false, &result); INTMAX_MAX, true, false, false, &result);
expect_false(err, "Should succeed for valid value"); expect_false(err, "Should succeed for valid value");
expect_d64_eq((int64_t)result, 5000, "result should be 5000"); expect_d64_eq((int64_t)result, 5000, "result should be 5000");
} }
@ -81,8 +80,8 @@ TEST_END
TEST_BEGIN(test_conf_handle_signed_negative) { TEST_BEGIN(test_conf_handle_signed_negative) {
intmax_t result = 0; intmax_t result = 0;
bool err = conf_handle_signed("-1", sizeof("-1") - 1, bool err = conf_handle_signed("-1", sizeof("-1") - 1, -1, INTMAX_MAX,
-1, INTMAX_MAX, true, false, false, &result); true, false, false, &result);
expect_false(err, "Should succeed for -1"); expect_false(err, "Should succeed for -1");
expect_d64_eq((int64_t)result, -1, "result should be -1"); expect_d64_eq((int64_t)result, -1, "result should be -1");
} }
@ -90,8 +89,8 @@ TEST_END
TEST_BEGIN(test_conf_handle_signed_out_of_range) { TEST_BEGIN(test_conf_handle_signed_out_of_range) {
intmax_t result = 0; intmax_t result = 0;
bool err = conf_handle_signed("5000", sizeof("5000") - 1, bool err = conf_handle_signed(
-1, 4999, true, true, false, &result); "5000", sizeof("5000") - 1, -1, 4999, true, true, false, &result);
expect_true(err, "Should fail for out-of-range value"); expect_true(err, "Should fail for out-of-range value");
} }
TEST_END TEST_END
@ -101,13 +100,14 @@ TEST_BEGIN(test_conf_handle_char_p) {
bool err; bool err;
/* Normal copy. */ /* Normal copy. */
err = conf_handle_char_p("hello", sizeof("hello") - 1, buf, sizeof(buf)); err = conf_handle_char_p(
"hello", sizeof("hello") - 1, buf, sizeof(buf));
expect_false(err, "Should succeed"); expect_false(err, "Should succeed");
expect_str_eq(buf, "hello", "Should copy string"); expect_str_eq(buf, "hello", "Should copy string");
/* Truncation. */ /* Truncation. */
err = conf_handle_char_p("longstring", sizeof("longstring") - 1, err = conf_handle_char_p(
buf, sizeof(buf)); "longstring", sizeof("longstring") - 1, buf, sizeof(buf));
expect_false(err, "Should succeed even when truncating"); expect_false(err, "Should succeed even when truncating");
expect_str_eq(buf, "longstr", "Should truncate to dest_sz - 1"); expect_str_eq(buf, "longstr", "Should truncate to dest_sz - 1");
} }
@ -115,16 +115,12 @@ TEST_END
int int
main(void) { main(void) {
return test(test_conf_handle_bool_true, return test(test_conf_handle_bool_true, test_conf_handle_bool_false,
test_conf_handle_bool_false, test_conf_handle_bool_invalid, test_conf_handle_unsigned_in_range,
test_conf_handle_bool_invalid,
test_conf_handle_unsigned_in_range,
test_conf_handle_unsigned_clip_max, test_conf_handle_unsigned_clip_max,
test_conf_handle_unsigned_clip_min, test_conf_handle_unsigned_clip_min,
test_conf_handle_unsigned_no_clip_reject, test_conf_handle_unsigned_no_clip_reject,
test_conf_handle_unsigned_invalid, test_conf_handle_unsigned_invalid, test_conf_handle_signed_valid,
test_conf_handle_signed_valid,
test_conf_handle_signed_negative, test_conf_handle_signed_negative,
test_conf_handle_signed_out_of_range, test_conf_handle_signed_out_of_range, test_conf_handle_char_p);
test_conf_handle_char_p);
} }