revert: restore pre-upstream-merge baseline (tree of 3b673150b)

Roll the tree back to the pre-merge tip 3b673150b, undoing the upstream sync merge 72f4f186d (303 files) and the 13 post-merge commits layered on top of it.

Purpose: restore the last pre-sync baseline so the reported OMEMO/OTR encryption regressions can be reproduced against a known-good state and the upstream sync ruled in or out as the cause. Nothing is dropped from history; the merge and every post-merge commit remain reachable and can be cherry-picked back selectively.

Baseline:     3b673150b chore(chatlog): disable background message file logging (stage 1)

Undoes merge: 72f4f186d merge: sync upstream profanity-im/profanity
This commit is contained in:
2026-06-29 12:17:01 +03:00
parent ca92d29179
commit f9e184eda7
311 changed files with 9908 additions and 11285 deletions

View File

@@ -1,21 +1,10 @@
/*
* test_common.c
*
* Copyright (C) 2015 - 2017 James Booth <boothj5@gmail.com>
* Copyright (C) 2015 - 2026 Michael Vetter <jubalh@iodoru.org>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "xmpp/resource.h"
#include "common.h"
#include "prof_cmocka.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include "tests/unittests/ui/stub_ui.h" // Include for mocking cons_show
void
str_replace__returns__one_substr(void** state)
replace_one_substr(void** state)
{
char* string = "it is a string";
char* sub = "is";
@@ -29,7 +18,7 @@ str_replace__returns__one_substr(void** state)
}
void
str_replace__returns__one_substr_beginning(void** state)
replace_one_substr_beginning(void** state)
{
char* string = "it is a string";
char* sub = "it";
@@ -43,7 +32,7 @@ str_replace__returns__one_substr_beginning(void** state)
}
void
str_replace__returns__one_substr_end(void** state)
replace_one_substr_end(void** state)
{
char* string = "it is a string";
char* sub = "string";
@@ -57,7 +46,7 @@ str_replace__returns__one_substr_end(void** state)
}
void
str_replace__returns__two_substr(void** state)
replace_two_substr(void** state)
{
char* string = "it is a is string";
char* sub = "is";
@@ -71,7 +60,7 @@ str_replace__returns__two_substr(void** state)
}
void
str_replace__returns__char(void** state)
replace_char(void** state)
{
char* string = "some & a thing & something else";
char* sub = "&";
@@ -85,7 +74,7 @@ str_replace__returns__char(void** state)
}
void
str_replace__returns__original_when_none(void** state)
replace_when_none(void** state)
{
char* string = "its another string";
char* sub = "haha";
@@ -99,7 +88,7 @@ str_replace__returns__original_when_none(void** state)
}
void
str_replace__returns__replaced_when_match(void** state)
replace_when_match(void** state)
{
char* string = "hello";
char* sub = "hello";
@@ -113,7 +102,7 @@ str_replace__returns__replaced_when_match(void** state)
}
void
str_replace__returns__empty_when_string_empty(void** state)
replace_when_string_empty(void** state)
{
char* string = "";
char* sub = "hello";
@@ -127,7 +116,7 @@ str_replace__returns__empty_when_string_empty(void** state)
}
void
str_replace__returns__null_when_string_null(void** state)
replace_when_string_null(void** state)
{
char* string = NULL;
char* sub = "hello";
@@ -139,7 +128,7 @@ str_replace__returns__null_when_string_null(void** state)
}
void
str_replace__returns__original_when_sub_empty(void** state)
replace_when_sub_empty(void** state)
{
char* string = "hello";
char* sub = "";
@@ -153,7 +142,7 @@ str_replace__returns__original_when_sub_empty(void** state)
}
void
str_replace__returns__original_when_sub_null(void** state)
replace_when_sub_null(void** state)
{
char* string = "hello";
char* sub = NULL;
@@ -167,7 +156,7 @@ str_replace__returns__original_when_sub_null(void** state)
}
void
str_replace__returns__empty_when_new_empty(void** state)
replace_when_new_empty(void** state)
{
char* string = "hello";
char* sub = "hello";
@@ -181,7 +170,7 @@ str_replace__returns__empty_when_new_empty(void** state)
}
void
str_replace__returns__original_when_new_null(void** state)
replace_when_new_null(void** state)
{
char* string = "hello";
char* sub = "hello";
@@ -195,55 +184,55 @@ str_replace__returns__original_when_new_null(void** state)
}
void
valid_resource_presence_string__is__true_for_online(void** state)
test_online_is_valid_resource_presence_string(void** state)
{
assert_true(valid_resource_presence_string("online"));
}
void
valid_resource_presence_string__is__true_for_chat(void** state)
test_chat_is_valid_resource_presence_string(void** state)
{
assert_true(valid_resource_presence_string("chat"));
}
void
valid_resource_presence_string__is__true_for_away(void** state)
test_away_is_valid_resource_presence_string(void** state)
{
assert_true(valid_resource_presence_string("away"));
}
void
valid_resource_presence_string__is__true_for_xa(void** state)
test_xa_is_valid_resource_presence_string(void** state)
{
assert_true(valid_resource_presence_string("xa"));
}
void
valid_resource_presence_string__is__true_for_dnd(void** state)
test_dnd_is_valid_resource_presence_string(void** state)
{
assert_true(valid_resource_presence_string("dnd"));
}
void
valid_resource_presence_string__is__false_for_available(void** state)
test_available_is_not_valid_resource_presence_string(void** state)
{
assert_false(valid_resource_presence_string("available"));
}
void
valid_resource_presence_string__is__false_for_unavailable(void** state)
test_unavailable_is_not_valid_resource_presence_string(void** state)
{
assert_false(valid_resource_presence_string("unavailable"));
}
void
valid_resource_presence_string__is__false_for_blah(void** state)
test_blah_is_not_valid_resource_presence_string(void** state)
{
assert_false(valid_resource_presence_string("blah"));
}
void
utf8_display_len__returns__0_for_null(void** state)
utf8_display_len_null_str(void** state)
{
int result = utf8_display_len(NULL);
@@ -251,7 +240,7 @@ utf8_display_len__returns__0_for_null(void** state)
}
void
utf8_display_len__returns__1_for_non_wide(void** state)
utf8_display_len_1_non_wide(void** state)
{
int result = utf8_display_len("1");
@@ -259,7 +248,7 @@ utf8_display_len__returns__1_for_non_wide(void** state)
}
void
utf8_display_len__returns__2_for_wide(void** state)
utf8_display_len_1_wide(void** state)
{
int result = utf8_display_len("");
@@ -267,7 +256,7 @@ utf8_display_len__returns__2_for_wide(void** state)
}
void
utf8_display_len__returns__correct_for_non_wide(void** state)
utf8_display_len_non_wide(void** state)
{
int result = utf8_display_len("123456789abcdef");
@@ -275,7 +264,7 @@ utf8_display_len__returns__correct_for_non_wide(void** state)
}
void
utf8_display_len__returns__correct_for_wide(void** state)
utf8_display_len_wide(void** state)
{
int result = utf8_display_len("12三四56");
@@ -283,7 +272,7 @@ utf8_display_len__returns__correct_for_wide(void** state)
}
void
utf8_display_len__returns__correct_for_all_wide(void** state)
utf8_display_len_all_wide(void** state)
{
int result = utf8_display_len("ひらがな");
@@ -291,7 +280,7 @@ utf8_display_len__returns__correct_for_all_wide(void** state)
}
void
strip_arg_quotes__returns__original_when_no_quotes(void** state)
strip_quotes_does_nothing_when_no_quoted(void** state)
{
char* input = "/cmd test string";
@@ -303,7 +292,7 @@ strip_arg_quotes__returns__original_when_no_quotes(void** state)
}
void
strip_arg_quotes__returns__stripped_first(void** state)
strip_quotes_strips_first(void** state)
{
char* input = "/cmd \"test string";
@@ -315,7 +304,7 @@ strip_arg_quotes__returns__stripped_first(void** state)
}
void
strip_arg_quotes__returns__stripped_last(void** state)
strip_quotes_strips_last(void** state)
{
char* input = "/cmd test string\"";
@@ -327,7 +316,7 @@ strip_arg_quotes__returns__stripped_last(void** state)
}
void
strip_arg_quotes__returns__stripped_both(void** state)
strip_quotes_strips_both(void** state)
{
char* input = "/cmd \"test string\"";
@@ -338,317 +327,6 @@ strip_arg_quotes__returns__stripped_both(void** state)
free(result);
}
void
strip_arg_quotes__unescapes(void** state)
{
char* input = "\"Thor \\\"The Thunderer\\\" Odinson\"";
char* result = strip_arg_quotes(input);
assert_string_equal("Thor \"The Thunderer\" Odinson", result);
free(result);
}
void
valid_tls_policy_option__is__correct_for_various_inputs(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
get_expanded_path__returns__expanded(void** state)
{
gchar* expanded_path;
// `file://` prefix
expanded_path = get_expanded_path("file:///tmp/test.txt");
assert_string_equal("/tmp/test.txt", expanded_path);
g_free(expanded_path);
// `~/"` prefix
setenv("HOME", "/home/test", 1);
expanded_path = get_expanded_path("~/folder/file.txt");
assert_string_equal("/home/test/folder/file.txt", expanded_path);
g_free(expanded_path);
unsetenv("HOME");
// regular path
expanded_path = get_expanded_path("/home/test/file.pdf");
assert_string_equal("/home/test/file.pdf", expanded_path);
g_free(expanded_path);
// empty path
expanded_path = get_expanded_path("");
assert_string_equal("", expanded_path);
g_free(expanded_path);
}
void
strtoi_range__returns__true_for_valid_input(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
result = strtoi_range("10", &value, 0, 20, &err_msg);
assert_true(result);
assert_int_equal(10, value);
assert_null(err_msg);
result = strtoi_range("0", &value, 0, 20, &err_msg);
assert_true(result);
assert_int_equal(0, value);
assert_null(err_msg);
result = strtoi_range("20", &value, 0, 20, &err_msg);
assert_true(result);
assert_int_equal(20, value);
assert_null(err_msg);
result = strtoi_range("-5", &value, -10, 0, &err_msg);
assert_true(result);
assert_int_equal(-5, value);
assert_null(err_msg);
}
void
strtoi_range__returns__false_for_out_of_range(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// too low, negative
result = strtoi_range("-11", &value, -10, 0, &err_msg);
assert_false(result);
assert_string_equal("Value -11 out of range. Must be in -10..0.", err_msg);
g_free(err_msg);
err_msg = NULL;
// too low
result = strtoi_range("-1", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Value -1 out of range. Must be in 0..10.", err_msg);
g_free(err_msg);
err_msg = NULL;
// too high
result = strtoi_range("11", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Value 11 out of range. Must be in 0..10.", err_msg);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns__false_for_invalid_input(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// not a number
result = strtoi_range("profanity", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"profanity\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
// not a number, start with digits
result = strtoi_range("23kk", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"23kk\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns__false_for_null_empty_input(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// NULL input string
result = strtoi_range(NULL, &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("'str' input pointer can not be NULL", err_msg);
g_free(err_msg);
err_msg = NULL;
// Empty input string
result = strtoi_range("", &value, 0, 10, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns__correct_values_when_err_msg_null(void** state)
{
int value;
gboolean result;
// valid conversion, err_msg is NULL
result = strtoi_range("5", &value, 0, 10, NULL);
assert_true(result);
assert_int_equal(5, value);
// invalid conversion, err_msg is NULL
result = strtoi_range("profanity", &value, 0, 10, NULL);
assert_false(result);
}
void
strtoi_range__returns__false_for_integer_overflow_underflow(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
char buf[64];
// INT_MAX + 1 overflows
snprintf(buf, sizeof(buf), "%lld", (long long)INT_MAX + 1);
result = strtoi_range(buf, &value, INT_MIN, INT_MAX, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
// INT_MIN - 1 underflows
snprintf(buf, sizeof(buf), "%lld", (long long)INT_MIN - 1);
result = strtoi_range(buf, &value, INT_MIN, INT_MAX, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
// Extreme overflow, larger than `long`
result = strtoi_range("9999999999999999999999999999999999", &value, INT_MIN, INT_MAX, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
}
void
strtoi_range__returns_consistent_with_strtol_parsing(void** state)
{
int value;
gchar* err_msg = NULL;
gboolean result;
// Hexadecimal: "0x10" -> 16
result = strtoi_range("0x10", &value, 0, 100, &err_msg);
assert_true(result);
assert_int_equal(16, value);
g_free(err_msg);
err_msg = NULL;
// Octal: "010" -> 8
result = strtoi_range("010", &value, 0, 100, &err_msg);
assert_true(result);
assert_int_equal(8, value);
g_free(err_msg);
err_msg = NULL;
// Floating point "0.8" should fail: '.' is not a valid integer char
result = strtoi_range("0.8", &value, -10, 10, &err_msg);
assert_false(result);
g_free(err_msg);
err_msg = NULL;
}
void
string_to_verbosity__returns__correct_values(void** state)
{
int verbosity;
gchar* err_msg = NULL;
gboolean result;
// Valid input string (0)
result = string_to_verbosity("0", &verbosity, &err_msg);
assert_true(result);
assert_int_equal(0, verbosity);
assert_null(err_msg);
g_free(err_msg);
err_msg = NULL; // Clear for next test
// Valid input string (1)
result = string_to_verbosity("1", &verbosity, &err_msg);
assert_true(result);
assert_int_equal(1, verbosity);
assert_null(err_msg);
g_free(err_msg);
err_msg = NULL;
// Valid input string (3)
result = string_to_verbosity("3", &verbosity, &err_msg);
assert_true(result);
assert_int_equal(3, verbosity);
assert_null(err_msg);
g_free(err_msg);
err_msg = NULL;
// Invalid input string (not a number)
result = string_to_verbosity("profanity", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"profanity\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
// Valid input string, out of range (too low)
result = string_to_verbosity("-1", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Value -1 out of range. Must be in 0..3.", err_msg);
g_free(err_msg);
err_msg = NULL;
// Valid input string, out of range (too high)
result = string_to_verbosity("4", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Value 4 out of range. Must be in 0..3.", err_msg);
g_free(err_msg);
err_msg = NULL;
// NULL input string
result = string_to_verbosity(NULL, &verbosity, &err_msg);
assert_false(result);
assert_string_equal("'str' input pointer can not be NULL", err_msg);
g_free(err_msg);
err_msg = NULL;
// Empty input string
result = string_to_verbosity("", &verbosity, &err_msg);
assert_false(result);
assert_string_equal("Could not convert \"\" to a number.", err_msg);
g_free(err_msg);
err_msg = NULL;
// err_msg is NULL
result = string_to_verbosity("abc", &verbosity, NULL);
assert_false(result);
}
typedef struct
{
char* template;
@@ -658,7 +336,7 @@ typedef struct
} format_call_external_argv_t;
void
format_call_external_argv__tests__table_driven(void** state)
format_call_external_argv_td(void** state)
{
enum table { num_tests = 4 };
@@ -715,7 +393,7 @@ typedef struct
} unique_filename_from_url_t;
void
unique_filename_from_url__tests__table_driven(void** state)
unique_filename_from_url_td(void** state)
{
enum table { num_tests = 15 };
@@ -822,8 +500,8 @@ unique_filename_from_url__tests__table_driven(void** state)
assert_string_equal(got_filename, exp_filename);
g_free(got_filename);
g_free(exp_filename);
free(got_filename);
free(exp_filename);
}
}
@@ -853,7 +531,7 @@ _lists_equal(GSList* a, GSList* b)
}
void
prof_occurrences__tests__large_message(void** state)
prof_occurrences_of_large_message_tests(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
@@ -875,7 +553,7 @@ prof_occurrences__tests__large_message(void** state)
}
void
prof_occurrences__tests__partial(void** state)
prof_partial_occurrences_tests(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
@@ -967,132 +645,7 @@ prof_occurrences__tests__partial(void** state)
}
void
get_mentions__tests__various(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
// Basic match, case sensitive
expected = g_slist_append(expected, GINT_TO_POINTER(6));
actual = get_mentions(FALSE, TRUE, "hello boothj5", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Case insensitive match
expected = g_slist_append(expected, GINT_TO_POINTER(6));
actual = get_mentions(FALSE, FALSE, "hello BOOTHJ5", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Whole word match
expected = g_slist_append(expected, GINT_TO_POINTER(0));
actual = get_mentions(TRUE, TRUE, "boothj5 hello", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Whole word no match (partial)
actual = get_mentions(TRUE, TRUE, "boothj5hello", "boothj5");
assert_true(_lists_equal(actual, expected)); // expected is NULL
g_slist_free(actual);
actual = NULL;
// Multiple matches
expected = g_slist_append(expected, GINT_TO_POINTER(0));
expected = g_slist_append(expected, GINT_TO_POINTER(14));
actual = get_mentions(FALSE, TRUE, "boothj5 hello boothj5", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Nick with punctuation (whole word)
expected = g_slist_append(expected, GINT_TO_POINTER(0));
actual = get_mentions(TRUE, TRUE, "boothj5: hi", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Nick surrounded by punctuation
expected = g_slist_append(expected, GINT_TO_POINTER(1));
actual = get_mentions(TRUE, TRUE, "(boothj5)", "boothj5");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
// Empty message
actual = get_mentions(FALSE, TRUE, "", "boothj5");
assert_true(_lists_equal(actual, expected)); // expected is NULL
g_slist_free(actual);
actual = NULL;
// Empty nick
actual = get_mentions(FALSE, TRUE, "hello", "");
assert_true(_lists_equal(actual, expected)); // expected is NULL
g_slist_free(actual);
actual = NULL;
// UTF-8 characters
expected = g_slist_append(expected, GINT_TO_POINTER(0));
actual = get_mentions(TRUE, TRUE, "我能 hello", "我能");
assert_true(_lists_equal(actual, expected));
g_slist_free(actual);
actual = NULL;
g_slist_free(expected);
expected = NULL;
}
void
release_is_new__tests__various(void** state)
{
// Higher major version
assert_true(release_is_new("0.16.0", "1.0.0"));
// Higher minor version
assert_true(release_is_new("0.16.0", "0.17.0"));
// Higher patch version
assert_true(release_is_new("0.16.0", "0.16.1"));
// Same version
assert_false(release_is_new("0.16.0", "0.16.0"));
// Lower major version
assert_false(release_is_new("0.16.0", "0.15.9"));
// Lower minor version
assert_false(release_is_new("0.16.0", "0.15.0"));
// Lower patch version
assert_false(release_is_new("0.16.1", "0.16.0"));
// Higher version but with different current versions
assert_true(release_is_new("1.2.3", "1.2.4"));
assert_true(release_is_new("1.2.3", "1.3.0"));
assert_true(release_is_new("1.2.3", "2.0.0"));
// Malformed version strings
assert_false(release_is_new("0.16.0", "0.16")); // Missing patch in found
assert_false(release_is_new("0.16", "0.16.0")); // Missing patch in curr
assert_false(release_is_new("0.16.0", "0.16.0.1")); // Extra part
assert_false(release_is_new("0.16.0", "abc.def.ghi"));
assert_false(release_is_new("0.16.0", ""));
assert_false(release_is_new(NULL, "1.0.0"));
assert_false(release_is_new("1.0.0", NULL));
}
void
prof_occurrences__tests__whole(void** state)
prof_whole_occurrences_tests(void** state)
{
GSList* actual = NULL;
GSList* expected = NULL;
@@ -1293,94 +846,3 @@ prof_occurrences__tests__whole(void** state)
g_slist_free(expected);
expected = NULL;
}
void
string_matches_one_of__tests__edge_cases(void** state)
{
// is is NULL, is_can_be_null is TRUE -> should return TRUE
assert_true(string_matches_one_of(NULL, NULL, TRUE, "option1", "option2", NULL));
// is is NULL, is_can_be_null is FALSE -> should return FALSE
assert_false(string_matches_one_of(NULL, NULL, FALSE, "option1", "option2", NULL));
// is matches one of the options
assert_true(string_matches_one_of("Test", "option1", FALSE, "option1", "option2", NULL));
assert_true(string_matches_one_of("Test", "option2", FALSE, "option1", "option2", NULL));
// is does not match any of the options
expect_any_cons_show(); // For "Invalid Test: 'option3'"
expect_any_cons_show(); // For "Test must be one of: 'option1', or 'option2'."
assert_false(string_matches_one_of("Test", "option3", FALSE, "option1", "option2", NULL));
// what is NULL (no error message printed)
assert_false(string_matches_one_of(NULL, "option3", FALSE, "option1", "option2", NULL));
// Empty options list (first is NULL)
expect_any_cons_show(); // For "Invalid Test: 'option1'"
expect_any_cons_show(); // For "Test must be one of: ." (empty options list error message)
assert_false(string_matches_one_of("Test", "option1", FALSE, NULL, NULL));
assert_false(string_matches_one_of(NULL, NULL, FALSE, NULL, NULL));
assert_true(string_matches_one_of(NULL, NULL, TRUE, NULL, NULL));
// Single option, matches
assert_true(string_matches_one_of("Test", "single", FALSE, "single", NULL));
// Single option, no match
expect_any_cons_show(); // For "Invalid Test: 'nomatch'"
expect_any_cons_show(); // For "Test must be one of: 'single'."
assert_false(string_matches_one_of("Test", "nomatch", FALSE, "single", NULL));
// Multiple options, first matches
assert_true(string_matches_one_of("Test", "first", FALSE, "first", "second", "third", NULL));
// Multiple options, middle matches
assert_true(string_matches_one_of("Test", "second", FALSE, "first", "second", "third", NULL));
// Multiple options, last matches
assert_true(string_matches_one_of("Test", "third", FALSE, "first", "second", "third", NULL));
// Multiple options, no match
expect_any_cons_show(); // For "Invalid Test: 'none'"
expect_any_cons_show(); // For "Test must be one of: 'first', 'second', or 'third'."
assert_false(string_matches_one_of("Test", "none", FALSE, "first", "second", "third", NULL));
// is is an empty string, options are not
expect_any_cons_show(); // For "Invalid Test: ''"
expect_any_cons_show(); // For "Test must be one of: 'option1', or 'option2'."
assert_false(string_matches_one_of("Test", "", FALSE, "option1", "option2", NULL));
// is is an empty string, one of the options is an empty string
assert_true(string_matches_one_of("Test", "", FALSE, "option1", "", "option2", NULL));
}
void
str_xml_sanitize__strips_illegal_characters(void** state)
{
// Test NULL input
assert_null(str_xml_sanitize(NULL));
// Test empty string
gchar* res1 = str_xml_sanitize("");
assert_string_equal("", res1);
g_free(res1);
// Test string with no illegal characters
gchar* res2 = str_xml_sanitize("Hello World! \t\n\r");
assert_string_equal("Hello World! \t\n\r", res2);
g_free(res2);
// Test string with illegal characters (0x16 is ^V, 0x01 is ^A)
gchar* res3 = str_xml_sanitize("Hello\x16World\x01!");
assert_string_equal("HelloWorld!", res3);
g_free(res3);
// Test string with mixed legal and illegal control characters
gchar* res4 = str_xml_sanitize("\x09Legal\x0BIllegal\x0ALegal\x1FIllegal\x0DLegal");
assert_string_equal("\tLegalIllegal\nLegalIllegal\rLegal", res4);
g_free(res4);
// Test UTF-8 characters
gchar* res5 = str_xml_sanitize("UTF-8: üñîçøðé \x16 and more");
assert_string_equal("UTF-8: üñîçøðé and more", res5);
g_free(res5);
}