tests: Add test for valid_tls_policy_option()

See last commit with comment regarding cons_show().

In this test here we can see that if we pass NULL cons_show() isn't
called. Making it a bit different that other invalid test cases.
This commit is contained in:
Michael Vetter
2026-02-24 20:12:53 +01:00
parent b7d53adba6
commit 0c15cd1d93
3 changed files with 26 additions and 1 deletions

View File

@@ -328,6 +328,30 @@ strip_quotes_strips_both(void** state)
free(result);
}
void test_valid_tls_policy_option(void** state) {
// Valid inputs
assert_true(valid_tls_policy_option("force"));
assert_true(valid_tls_policy_option("allow"));
assert_true(valid_tls_policy_option("trust"));
assert_true(valid_tls_policy_option("disable"));
assert_true(valid_tls_policy_option("legacy"));
assert_true(valid_tls_policy_option("direct"));
// Invalid inputs
// Not an option
expect_any_cons_show(); // For "Invalid TLS policy: 'profanity'"
expect_any_cons_show(); // For "TLS policy must be one of: 'force', 'allow', 'trust', 'disable', 'legacy', or 'direct'."
assert_false(valid_tls_policy_option("profanity"));
// Empty
expect_any_cons_show(); // For "Invalid TLS policy: ''"
expect_any_cons_show(); // For "TLS policy must be one of: 'force', 'allow', 'trust', 'disable', 'legacy', or 'direct'."
assert_false(valid_tls_policy_option(""));
// NULL
assert_true(valid_tls_policy_option(NULL));
}
void test_get_expanded_path(void** state) {
gchar* expanded_path;

View File

@@ -42,3 +42,4 @@ void test_strtoi_range_invalid_input(void** state);
void test_strtoi_range_null_empty_input(void** state);
void test_strtoi_range_null_err_msg(void** state);
void test_string_matches_one_of_edge_cases(void** state);
void test_valid_tls_policy_option(void** state);

View File

@@ -102,7 +102,7 @@ main(int argc, char* argv[])
cmocka_unit_test(test_strtoi_range_null_empty_input),
cmocka_unit_test(test_strtoi_range_null_err_msg),
cmocka_unit_test(test_string_matches_one_of_edge_cases),
cmocka_unit_test(test_valid_tls_policy_option),
cmocka_unit_test(clear_empty),
cmocka_unit_test(reset_after_create),
cmocka_unit_test(find_after_create),