Merge branch 'master' into merge/upstream-full
Some checks failed
CI Code / Check spelling (pull_request) Successful in 17s
CI Code / Check coding style (pull_request) Successful in 31s
CI Code / Linux (debian) (pull_request) Failing after 39s
CI Code / Linux (ubuntu) (pull_request) Failing after 42s
CI Code / Linux (arch) (pull_request) Failing after 4m59s
CI Code / Code Coverage (pull_request) Failing after 4m48s
Some checks failed
CI Code / Check spelling (pull_request) Successful in 17s
CI Code / Check coding style (pull_request) Successful in 31s
CI Code / Linux (debian) (pull_request) Failing after 39s
CI Code / Linux (ubuntu) (pull_request) Failing after 42s
CI Code / Linux (arch) (pull_request) Failing after 4m59s
CI Code / Code Coverage (pull_request) Failing after 4m48s
Resolve conflicts after master gained the flat-file database backend,
AI client, and other cproof-fork features:
- CHANGELOG: keep cproof-fork unreleased section atop full upstream
history (0.17.0 / 0.16.0 / 0.15.1)
- src/command/cmd_ac.c: keep both upstream spellcheck AC and cproof
/history switch|verify|export|import autocompletion
- src/config/preferences.c: merge upstream [spellcheck] group with the
cproof [ai]/[ai/<provider>] groups
- src/database.c: take master (thin dispatcher); upstream SQLite
improvements (v3 migration, auto_gchar) belong in database_sqlite.c
and will land in a follow-up commit
- src/tools/autocomplete.c: take upstream unescape of search_str
- src/ui/statusbar.c: keep guint signatures (per project preference)
and adapt _status_bar_draw_dbbackend to guint as well
- src/xmpp/jid.c: combine the new jid_is_valid/jid_is_valid_user_jid
with the "(null)" legacy-placeholder guard in
jid_create_from_bare_and_resource; use auto_gchar
- tests/functionaltests/proftest.c: keep unsigned-safe pre-check on
output_len before subtracting OUTPUT_BUF_SIZE
- tests/unittests/unittests.c: keep upstream subdirectory include
layout plus cproof-only test_ai_client/database_export/database_stress
- tests/unittests/test_jid.c: drop orphan top-level copy (the
restructured version lives in tests/unittests/xmpp/test_jid.c)
Upstream is included up to 1ac05754b (release 0.18.0 era). Follow-up:
pull 1ac05754b..upstream/master (esp. 42a849d16 db migration fix and
4749645c7 receipt-request restore), and adapt the SQLite improvements
into database_sqlite.c.
This commit is contained in:
@@ -69,7 +69,7 @@ cmd_otr_log__shows__warning_when_chlog_disabled(void** state)
|
||||
prefs_set_boolean(PREF_CHLOG, FALSE);
|
||||
|
||||
expect_cons_show("OTR messages will be logged as plaintext.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/logging chat on' to enable.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/history on' to enable.");
|
||||
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
@@ -115,7 +115,7 @@ cmd_otr_log__shows__redact_warning_when_chlog_disabled(void** state)
|
||||
prefs_set_boolean(PREF_CHLOG, FALSE);
|
||||
|
||||
expect_cons_show("OTR messages will be logged as '[redacted]'.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/logging chat on' to enable.");
|
||||
expect_cons_show("Chat logging is currently disabled, use '/history on' to enable.");
|
||||
|
||||
gboolean result = cmd_otr_log(NULL, CMD_OTR, args);
|
||||
assert_true(result);
|
||||
|
||||
@@ -9,7 +9,15 @@
|
||||
#include <glib.h>
|
||||
#include "prof_cmocka.h"
|
||||
|
||||
#include "config.h"
|
||||
#include "database.h"
|
||||
#include "database_flatfile.h"
|
||||
|
||||
db_backend_t* active_db_backend = NULL;
|
||||
|
||||
// The flatfile parser needs this global for path construction.
|
||||
// In tests we keep it NULL since no real file I/O happens via the backend.
|
||||
char* g_flatfile_account_jid = NULL;
|
||||
|
||||
gboolean
|
||||
log_database_init(ProfAccount* account)
|
||||
@@ -36,3 +44,66 @@ void
|
||||
log_database_close(void)
|
||||
{
|
||||
}
|
||||
gboolean
|
||||
log_database_switch_backend(const char* new_backend)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
GSList*
|
||||
log_database_verify_integrity(const gchar* const contact_barejid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
void
|
||||
integrity_issue_free(integrity_issue_t* issue)
|
||||
{
|
||||
if (issue) {
|
||||
g_free(issue->file);
|
||||
g_free(issue->message);
|
||||
g_free(issue);
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_SQLITE
|
||||
db_backend_t*
|
||||
db_backend_sqlite(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
GSList*
|
||||
db_sqlite_list_contacts(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
GSList*
|
||||
db_sqlite_get_all_chat(const gchar* const contact_barejid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
void
|
||||
db_sqlite_begin_transaction(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
db_sqlite_end_transaction(void)
|
||||
{
|
||||
}
|
||||
void
|
||||
db_sqlite_rollback_transaction(void)
|
||||
{
|
||||
}
|
||||
int
|
||||
log_database_export_to_flatfile(const gchar* const contact_jid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
int
|
||||
log_database_import_from_flatfile(const gchar* const contact_jid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
db_backend_t*
|
||||
db_backend_flatfile(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
1608
tests/unittests/test_ai_client.c
Normal file
1608
tests/unittests/test_ai_client.c
Normal file
File diff suppressed because it is too large
Load Diff
140
tests/unittests/test_ai_client.h
Normal file
140
tests/unittests/test_ai_client.h
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* test_ai_client.h - AI client unit test declarations
|
||||
*/
|
||||
|
||||
int ai_client_setup(void** state);
|
||||
int ai_client_teardown(void** state);
|
||||
|
||||
void test_ai_client_init(void** state);
|
||||
void test_ai_add_provider(void** state);
|
||||
void test_ai_remove_provider(void** state);
|
||||
void test_ai_list_providers(void** state);
|
||||
void test_ai_set_provider_key(void** state);
|
||||
void test_ai_get_provider_key(void** state);
|
||||
void test_ai_session_create(void** state);
|
||||
void test_ai_session_ref_unref(void** state);
|
||||
void test_ai_session_add_message(void** state);
|
||||
void test_ai_session_clear_history(void** state);
|
||||
void test_ai_session_set_model(void** state);
|
||||
void test_ai_json_escape(void** state);
|
||||
void test_ai_json_escape_null(void** state);
|
||||
void test_ai_json_escape_empty(void** state);
|
||||
void test_ai_json_escape_special_chars(void** state);
|
||||
void test_ai_json_escape_percent_signs(void** state);
|
||||
void test_ai_json_escape_backslash_quote(void** state);
|
||||
void test_ai_session_api_key_is_copied(void** state);
|
||||
void test_ai_add_provider_update_existing(void** state);
|
||||
void test_ai_add_provider_null_name_returns_null(void** state);
|
||||
void test_ai_add_provider_null_url_returns_null(void** state);
|
||||
void test_ai_session_create_null_provider_returns_null(void** state);
|
||||
void test_ai_session_create_null_model_returns_null(void** state);
|
||||
void test_ai_session_api_key_null_when_no_key_set(void** state);
|
||||
/* Provider autocomplete tests */
|
||||
void test_ai_providers_find_forward(void** state);
|
||||
void test_ai_providers_find_forward_custom(void** state);
|
||||
void test_ai_providers_find_forward_no_match(void** state);
|
||||
void test_ai_providers_find_forward_partial_match(void** state);
|
||||
void test_ai_providers_find_next(void** state);
|
||||
void test_ai_providers_find_previous(void** state);
|
||||
void test_ai_providers_find_empty_search_str(void** state);
|
||||
void test_ai_providers_find_null_search_str(void** state);
|
||||
void test_ai_providers_find_case_insensitive(void** state);
|
||||
/* Provider default model and settings tests */
|
||||
void test_ai_set_provider_default_model(void** state);
|
||||
void test_ai_get_provider_default_model(void** state);
|
||||
void test_ai_set_provider_setting(void** state);
|
||||
void test_ai_get_provider_setting(void** state);
|
||||
/* Model caching tests */
|
||||
void test_ai_models_are_fresh_initial(void** state);
|
||||
/* Model parsing tests */
|
||||
void test_ai_parse_models_openai_format(void** state);
|
||||
void test_ai_parse_models_perplexity_format(void** state);
|
||||
void test_ai_parse_models_array_format(void** state);
|
||||
void test_ai_parse_models_empty_json(void** state);
|
||||
void test_ai_parse_models_null_handling(void** state);
|
||||
void test_ai_parse_models_escaped_quotes(void** state);
|
||||
void test_ai_parse_models_with_whitespace(void** state);
|
||||
/* AI autocomplete integration tests */
|
||||
void test_ai_start_provider_autocomplete_only_on_exact(void** state);
|
||||
void test_ai_providers_find_cycling(void** state);
|
||||
|
||||
/* Setup that also initializes prefs for round-trip persistence tests. */
|
||||
int ai_client_setup_with_prefs(void** state);
|
||||
int ai_client_teardown_with_prefs(void** state);
|
||||
|
||||
/* Chat response parser tests (ai_parse_response) */
|
||||
void test_ai_parse_response_openai_content(void** state);
|
||||
void test_ai_parse_response_perplexity_text(void** state);
|
||||
void test_ai_parse_response_text_preferred_over_content(void** state);
|
||||
void test_ai_parse_response_escaped_quote(void** state);
|
||||
void test_ai_parse_response_newline_escape(void** state);
|
||||
void test_ai_parse_response_empty_content(void** state);
|
||||
void test_ai_parse_response_missing_field(void** state);
|
||||
void test_ai_parse_response_null_input(void** state);
|
||||
void test_ai_parse_response_empty_input(void** state);
|
||||
void test_ai_parse_response_percent_signs_safe(void** state);
|
||||
void test_ai_parse_response_braces_in_content(void** state);
|
||||
void test_ai_parse_response_multiline_content(void** state);
|
||||
|
||||
/* Error response parser tests (ai_parse_error_message) */
|
||||
void test_ai_parse_error_standard_envelope(void** state);
|
||||
void test_ai_parse_error_with_escapes(void** state);
|
||||
void test_ai_parse_error_no_error_field(void** state);
|
||||
void test_ai_parse_error_no_message_field(void** state);
|
||||
void test_ai_parse_error_null_input(void** state);
|
||||
void test_ai_parse_error_empty_input(void** state);
|
||||
void test_ai_parse_error_tab_escape(void** state);
|
||||
void test_ai_parse_error_backslash_escape(void** state);
|
||||
|
||||
/* Extended JSON escape tests */
|
||||
void test_ai_json_escape_backspace(void** state);
|
||||
void test_ai_json_escape_formfeed(void** state);
|
||||
void test_ai_json_escape_carriage_return(void** state);
|
||||
void test_ai_json_escape_all_specials_combined(void** state);
|
||||
void test_ai_json_escape_passes_utf8_through(void** state);
|
||||
|
||||
/* Autocomplete cycling with many providers */
|
||||
void test_ai_providers_find_cycles_through_many(void** state);
|
||||
void test_ai_providers_find_previous_walks_backwards(void** state);
|
||||
void test_ai_providers_find_wraps_around(void** state);
|
||||
|
||||
/* Session edge cases */
|
||||
void test_ai_session_add_message_null_session_no_crash(void** state);
|
||||
void test_ai_session_add_message_null_role_no_crash(void** state);
|
||||
void test_ai_session_add_message_null_content_no_crash(void** state);
|
||||
void test_ai_session_history_preserves_large_order(void** state);
|
||||
void test_ai_session_clear_empty_history(void** state);
|
||||
void test_ai_session_set_model_null_keeps_old(void** state);
|
||||
void test_ai_session_unref_null_no_crash(void** state);
|
||||
void test_ai_session_ref_null_returns_null(void** state);
|
||||
|
||||
/* Provider edge cases */
|
||||
void test_ai_get_provider_null_returns_null(void** state);
|
||||
void test_ai_remove_provider_null_returns_false(void** state);
|
||||
void test_ai_remove_provider_twice_second_fails(void** state);
|
||||
void test_ai_provider_survives_via_session_after_removal(void** state);
|
||||
|
||||
/* Settings edge cases */
|
||||
void test_ai_settings_multiple_keys_independent(void** state);
|
||||
void test_ai_settings_get_missing_returns_null(void** state);
|
||||
void test_ai_settings_isolated_between_providers(void** state);
|
||||
|
||||
/* Model parsing edge cases */
|
||||
void test_ai_parse_models_data_not_array(void** state);
|
||||
void test_ai_parse_models_empty_data_array(void** state);
|
||||
void test_ai_parse_models_id_outside_data_ignored(void** state);
|
||||
void test_ai_parse_models_multiple_models(void** state);
|
||||
|
||||
/* Prefs round-trip tests */
|
||||
void test_ai_prefs_round_trip_api_key(void** state);
|
||||
void test_ai_prefs_round_trip_remove_key(void** state);
|
||||
void test_ai_prefs_multiple_providers_persist(void** state);
|
||||
|
||||
/* Autocomplete deeper coverage */
|
||||
void test_ai_providers_find_after_remove_skips_removed(void** state);
|
||||
|
||||
/* Reset hook + persistence */
|
||||
void test_ai_providers_reset_ac_restarts_cycle(void** state);
|
||||
void test_ai_add_provider_persisted_across_init(void** state);
|
||||
void test_ai_remove_provider_persisted_across_init(void** state);
|
||||
void test_ai_models_persisted_across_init(void** state);
|
||||
783
tests/unittests/test_database_export.c
Normal file
783
tests/unittests/test_database_export.c
Normal file
@@ -0,0 +1,783 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
//
|
||||
// This file is part of CProof.
|
||||
// See LICENSE for the full GPLv3 text and the special OpenSSL linking exception.
|
||||
|
||||
/*
|
||||
* test_database_export.c
|
||||
*
|
||||
* Unit tests for the flatfile write→parse round-trip, escape/unescape helpers,
|
||||
* jid_to_dir path construction, and parser edge cases — these are the core
|
||||
* functions exercised by database_export.c during export and import.
|
||||
*/
|
||||
|
||||
#include "prof_cmocka.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "database_flatfile.h"
|
||||
|
||||
/* ================================================================
|
||||
* Helper: write a single line to a temporary file, then read and
|
||||
* parse it back. Returns the parsed result; caller must free with
|
||||
* ff_parsed_line_free(). The temp file is removed automatically.
|
||||
* ================================================================ */
|
||||
static ff_parsed_line_t*
|
||||
_roundtrip(const char* timestamp, const char* type, const char* enc,
|
||||
const char* stanza_id, const char* archive_id, const char* replace_id,
|
||||
const char* from_jid, const char* from_resource,
|
||||
const char* to_jid, const char* to_resource, int marked_read,
|
||||
const char* message)
|
||||
{
|
||||
char tmppath[] = "/tmp/proftest_rt_XXXXXX";
|
||||
int fd = mkstemp(tmppath);
|
||||
assert_true(fd >= 0);
|
||||
|
||||
FILE* fp = fdopen(fd, "w");
|
||||
assert_non_null(fp);
|
||||
|
||||
ff_write_line(fp, timestamp, type, enc,
|
||||
stanza_id, archive_id, replace_id,
|
||||
from_jid, from_resource,
|
||||
to_jid, to_resource, marked_read,
|
||||
message);
|
||||
fclose(fp);
|
||||
|
||||
/* Read & parse */
|
||||
fp = fopen(tmppath, "r");
|
||||
assert_non_null(fp);
|
||||
|
||||
gboolean truncated = FALSE;
|
||||
char* buf = ff_readline(fp, &truncated);
|
||||
fclose(fp);
|
||||
unlink(tmppath);
|
||||
|
||||
assert_non_null(buf);
|
||||
assert_false(truncated);
|
||||
|
||||
ff_parsed_line_t* pl = ff_parse_line(buf);
|
||||
free(buf);
|
||||
|
||||
return pl;
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Write → parse round-trip tests
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_roundtrip_simple_chat(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-06-15T12:30:00+00:00", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"alice@example.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"Hello, world!");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->timestamp_str, "2025-06-15T12:30:00+00:00");
|
||||
assert_string_equal(pl->type, "chat");
|
||||
assert_string_equal(pl->enc, "none");
|
||||
assert_string_equal(pl->from_jid, "alice@example.com");
|
||||
assert_null(pl->stanza_id);
|
||||
assert_null(pl->archive_id);
|
||||
assert_null(pl->replace_id);
|
||||
assert_string_equal(pl->message, "Hello, world!");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_with_all_metadata(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-06-15T12:30:00+00:00", "chat", "omemo",
|
||||
"sid-abc-123", "aid-xyz-789", "corrects-old-id",
|
||||
"bob@example.com", "phone",
|
||||
NULL, NULL, -1,
|
||||
"Encrypted message.");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->stanza_id, "sid-abc-123");
|
||||
assert_string_equal(pl->archive_id, "aid-xyz-789");
|
||||
assert_string_equal(pl->replace_id, "corrects-old-id");
|
||||
assert_string_equal(pl->enc, "omemo");
|
||||
assert_string_equal(pl->from_jid, "bob@example.com");
|
||||
assert_string_equal(pl->from_resource, "phone");
|
||||
assert_string_equal(pl->message, "Encrypted message.");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_with_resource(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-01-01T00:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"user@jabber.org", "Profanity.abc123",
|
||||
NULL, NULL, -1,
|
||||
"hi");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->from_jid, "user@jabber.org");
|
||||
assert_string_equal(pl->from_resource, "Profanity.abc123");
|
||||
assert_string_equal(pl->message, "hi");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_newline_in_body(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"alice@x.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"line1\nline2\nline3");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->message, "line1\nline2\nline3");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_pipe_in_stanza_id(void** state)
|
||||
{
|
||||
/* pipes in stanza_id must be escaped in metadata */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
"id|with|pipes", "aid|also|has|pipes", NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"test");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->stanza_id, "id|with|pipes");
|
||||
assert_string_equal(pl->archive_id, "aid|also|has|pipes");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_backslash_in_body(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"path\\to\\file C:\\Users\\test");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->message, "path\\to\\file C:\\Users\\test");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_unicode_body(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"Привет мир 🌍 日本語テスト");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->message, "Привет мир 🌍 日本語テスト");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_empty_body(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->message, "");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_colonspace_in_resource(void** state)
|
||||
{
|
||||
/* ": " in resource must be escaped during write and unescaped on parse */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", "res: with: colons",
|
||||
NULL, NULL, -1,
|
||||
"msg");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->from_jid, "a@b.com");
|
||||
assert_string_equal(pl->from_resource, "res: with: colons");
|
||||
assert_string_equal(pl->message, "msg");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_muc_type(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "muc", "none",
|
||||
NULL, NULL, NULL,
|
||||
"room@conference.x.com", "nick",
|
||||
NULL, NULL, -1,
|
||||
"hello room");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->type, "muc");
|
||||
assert_string_equal(pl->from_jid, "room@conference.x.com");
|
||||
assert_string_equal(pl->from_resource, "nick");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_omemo_enc(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "omemo",
|
||||
"sid-1", NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"secret");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->enc, "omemo");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_replace_id(void** state)
|
||||
{
|
||||
/* LMC (Last Message Correction): corrects: field round-trip */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
"new-id", NULL, "old-id-to-correct",
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"corrected text");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->stanza_id, "new-id");
|
||||
assert_string_equal(pl->replace_id, "old-id-to-correct");
|
||||
assert_string_equal(pl->message, "corrected text");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_to_jid_and_marked_read(void** state)
|
||||
{
|
||||
/* to_jid, to_resource, and marked_read round-trip */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-06-15T12:30:00+00:00", "chat", "none",
|
||||
"sid-1", NULL, NULL,
|
||||
"alice@example.com", "phone",
|
||||
"bob@example.com", "laptop", 1,
|
||||
"Hello Bob!");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->from_jid, "alice@example.com");
|
||||
assert_string_equal(pl->from_resource, "phone");
|
||||
assert_string_equal(pl->to_jid, "bob@example.com");
|
||||
assert_string_equal(pl->to_resource, "laptop");
|
||||
assert_int_equal(pl->marked_read, 1);
|
||||
assert_string_equal(pl->message, "Hello Bob!");
|
||||
ff_parsed_line_free(pl);
|
||||
|
||||
/* marked_read = 0 (unread) */
|
||||
pl = _roundtrip(
|
||||
"2025-06-15T12:31:00+00:00", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"bob@example.com", NULL,
|
||||
"alice@example.com", NULL, 0,
|
||||
"Reply");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->to_jid, "alice@example.com");
|
||||
assert_null(pl->to_resource);
|
||||
assert_int_equal(pl->marked_read, 0);
|
||||
ff_parsed_line_free(pl);
|
||||
|
||||
/* marked_read = -1 (unset) — should NOT appear in output */
|
||||
pl = _roundtrip(
|
||||
"2025-06-15T12:32:00+00:00", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"no read flag");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_null(pl->to_jid);
|
||||
assert_null(pl->to_resource);
|
||||
assert_int_equal(pl->marked_read, -1);
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Escape / unescape symmetry tests
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_escape_unescape_message_identity(void** state)
|
||||
{
|
||||
const char* inputs[] = {
|
||||
"simple text",
|
||||
"has\\backslash",
|
||||
"has\nnewline",
|
||||
"has\rcarriage return",
|
||||
"all\\together\nnow\r!",
|
||||
"already escaped \\n \\r \\\\",
|
||||
"",
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]); i++) {
|
||||
char* escaped = ff_escape_message(inputs[i]);
|
||||
assert_non_null(escaped);
|
||||
/* escaped must not contain raw newlines */
|
||||
assert_null(strchr(escaped, '\n'));
|
||||
assert_null(strchr(escaped, '\r'));
|
||||
|
||||
char* unescaped = ff_unescape_message(escaped);
|
||||
assert_string_equal(unescaped, inputs[i]);
|
||||
|
||||
g_free(escaped);
|
||||
g_free(unescaped);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_escape_unescape_meta_identity(void** state)
|
||||
{
|
||||
const char* inputs[] = {
|
||||
"simple-id",
|
||||
"has|pipe",
|
||||
"has]bracket",
|
||||
"has\\backslash",
|
||||
"has\nnewline",
|
||||
"all|to]ge\\th\ner",
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]); i++) {
|
||||
char* escaped = ff_escape_meta_value(inputs[i]);
|
||||
assert_non_null(escaped);
|
||||
|
||||
char* unescaped = ff_unescape_meta_value(escaped);
|
||||
assert_string_equal(unescaped, inputs[i]);
|
||||
|
||||
g_free(escaped);
|
||||
g_free(unescaped);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_escape_meta_null_returns_null(void** state)
|
||||
{
|
||||
assert_null(ff_escape_meta_value(NULL));
|
||||
assert_null(ff_escape_meta_value(""));
|
||||
assert_null(ff_unescape_meta_value(NULL));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_escape_message_null_returns_empty(void** state)
|
||||
{
|
||||
char* result = ff_escape_message(NULL);
|
||||
assert_non_null(result);
|
||||
assert_string_equal(result, "");
|
||||
g_free(result);
|
||||
|
||||
result = ff_unescape_message(NULL);
|
||||
assert_non_null(result);
|
||||
assert_string_equal(result, "");
|
||||
g_free(result);
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* jid_to_dir tests
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_jid_to_dir_simple(void** state)
|
||||
{
|
||||
char* dir = ff_jid_to_dir("alice");
|
||||
assert_non_null(dir);
|
||||
assert_string_equal(dir, "alice");
|
||||
g_free(dir);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_jid_to_dir_with_at(void** state)
|
||||
{
|
||||
char* dir = ff_jid_to_dir("alice@example.com");
|
||||
assert_non_null(dir);
|
||||
assert_string_equal(dir, "alice_at_example.com");
|
||||
g_free(dir);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_jid_to_dir_path_traversal_rejected(void** state)
|
||||
{
|
||||
/* Slashes and '..' must be sanitized */
|
||||
char* dir = ff_jid_to_dir("../../etc/passwd");
|
||||
assert_non_null(dir);
|
||||
/* No slashes or '..' sequences should remain */
|
||||
assert_null(strchr(dir, '/'));
|
||||
assert_null(strstr(dir, ".."));
|
||||
g_free(dir);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_jid_to_dir_null(void** state)
|
||||
{
|
||||
assert_null(ff_jid_to_dir(NULL));
|
||||
assert_null(ff_jid_to_dir(""));
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Parser edge-case tests
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_parse_line_empty(void** state)
|
||||
{
|
||||
assert_null(ff_parse_line(NULL));
|
||||
assert_null(ff_parse_line(""));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_comment(void** state)
|
||||
{
|
||||
assert_null(ff_parse_line("# this is a comment"));
|
||||
assert_null(ff_parse_line("# cproof chat log — UTF-8, LF line endings"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_legacy_format(void** state)
|
||||
{
|
||||
/* Legacy chatlog.c format: {timestamp} - {sender}: {message} */
|
||||
ff_parsed_line_t* pl = ff_parse_line(
|
||||
"2025-06-15T12:30:00+00:00 - alice@example.com: Hello legacy");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->timestamp_str, "2025-06-15T12:30:00+00:00");
|
||||
assert_string_equal(pl->from_jid, "alice@example.com");
|
||||
assert_string_equal(pl->message, "Hello legacy");
|
||||
assert_string_equal(pl->type, "chat");
|
||||
assert_string_equal(pl->enc, "none");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_no_metadata(void** state)
|
||||
{
|
||||
/* Simple format without [] brackets */
|
||||
ff_parsed_line_t* pl = ff_parse_line(
|
||||
"2025-06-15T12:30:00Z alice@example.com: Simple message");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->from_jid, "alice@example.com");
|
||||
assert_string_equal(pl->message, "Simple message");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_invalid_timestamp(void** state)
|
||||
{
|
||||
/* Invalid timestamp should cause parse failure */
|
||||
ff_parsed_line_t* pl = ff_parse_line(
|
||||
"not-a-timestamp [chat|none] a@b.com: msg");
|
||||
|
||||
assert_null(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_empty_timestamp(void** state)
|
||||
{
|
||||
/* The space before "[" makes the timestamp empty -> g_date_time_new_from_iso8601
|
||||
must reject it. */
|
||||
ff_parsed_line_t* pl = ff_parse_line(
|
||||
" [chat|none] a@b.com: msg");
|
||||
assert_null(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_partial_iso_timestamp(void** state)
|
||||
{
|
||||
/* Year-only or yyyy-mm without time portion is not ISO-8601 enough for
|
||||
g_date_time_new_from_iso8601 — must fail rather than silently succeed. */
|
||||
assert_null(ff_parse_line("2025 [chat|none] a@b.com: msg"));
|
||||
assert_null(ff_parse_line("2025-06-15 [chat|none] a@b.com: msg"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_garbage_timestamp(void** state)
|
||||
{
|
||||
/* Random characters where timestamp should be — parse failure, no segfault. */
|
||||
assert_null(ff_parse_line("@@@@@@ [chat|none] a@b.com: msg"));
|
||||
assert_null(ff_parse_line("12345 [chat|none] a@b.com: msg"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_impossible_calendar_date(void** state)
|
||||
{
|
||||
/* Day 32 / Month 13 — well-formed ISO syntax but impossible date,
|
||||
g_date_time_new_from_iso8601 returns NULL. */
|
||||
assert_null(ff_parse_line(
|
||||
"2025-13-01T12:00:00Z [chat|none] a@b.com: msg"));
|
||||
assert_null(ff_parse_line(
|
||||
"2025-06-32T12:00:00Z [chat|none] a@b.com: msg"));
|
||||
assert_null(ff_parse_line(
|
||||
"2025-06-15T25:00:00Z [chat|none] a@b.com: msg"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_negative_year_timestamp(void** state)
|
||||
{
|
||||
/* Negative year is not parseable by g_date_time_new_from_iso8601. */
|
||||
assert_null(ff_parse_line(
|
||||
"-0001-06-15T12:00:00Z [chat|none] a@b.com: msg"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_far_future_timestamp(void** state)
|
||||
{
|
||||
/* Year 9999 is valid ISO-8601 and should parse — sanity check that we
|
||||
don't artificially reject valid far-future dates. */
|
||||
ff_parsed_line_t* pl = ff_parse_line(
|
||||
"9999-12-31T23:59:59Z [chat|none] a@b.com: hi");
|
||||
assert_non_null(pl);
|
||||
assert_non_null(pl->timestamp);
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Type / enc conversion round-trip
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_type_str_roundtrip(void** state)
|
||||
{
|
||||
assert_int_equal(PROF_MSG_TYPE_CHAT, ff_get_message_type_type(ff_get_message_type_str(PROF_MSG_TYPE_CHAT)));
|
||||
assert_int_equal(PROF_MSG_TYPE_MUC, ff_get_message_type_type(ff_get_message_type_str(PROF_MSG_TYPE_MUC)));
|
||||
assert_int_equal(PROF_MSG_TYPE_MUCPM, ff_get_message_type_type(ff_get_message_type_str(PROF_MSG_TYPE_MUCPM)));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_enc_str_roundtrip(void** state)
|
||||
{
|
||||
assert_int_equal(PROF_MSG_ENC_NONE, ff_get_message_enc_type(ff_get_message_enc_str(PROF_MSG_ENC_NONE)));
|
||||
assert_int_equal(PROF_MSG_ENC_OTR, ff_get_message_enc_type(ff_get_message_enc_str(PROF_MSG_ENC_OTR)));
|
||||
assert_int_equal(PROF_MSG_ENC_PGP, ff_get_message_enc_type(ff_get_message_enc_str(PROF_MSG_ENC_PGP)));
|
||||
assert_int_equal(PROF_MSG_ENC_OX, ff_get_message_enc_type(ff_get_message_enc_str(PROF_MSG_ENC_OX)));
|
||||
assert_int_equal(PROF_MSG_ENC_OMEMO, ff_get_message_enc_type(ff_get_message_enc_str(PROF_MSG_ENC_OMEMO)));
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Additional round-trip tests
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_roundtrip_bracket_in_stanza_id(void** state)
|
||||
{
|
||||
/* ']' in stanza_id must be escaped as \] to avoid breaking metadata parser */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
"id]with]brackets", "aid]also]has]brackets", NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"test brackets");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->stanza_id, "id]with]brackets");
|
||||
assert_string_equal(pl->archive_id, "aid]also]has]brackets");
|
||||
assert_string_equal(pl->message, "test brackets");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_backslash_in_resource(void** state)
|
||||
{
|
||||
/* backslash in from_resource must survive round-trip */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", "res\\with\\backslash",
|
||||
NULL, NULL, -1,
|
||||
"msg");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->from_jid, "a@b.com");
|
||||
assert_string_equal(pl->from_resource, "res\\with\\backslash");
|
||||
assert_string_equal(pl->message, "msg");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_mucpm_type(void** state)
|
||||
{
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "mucpm", "none",
|
||||
NULL, NULL, NULL,
|
||||
"room@conference.x.com", "nick",
|
||||
NULL, NULL, -1,
|
||||
"private message");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->type, "mucpm");
|
||||
assert_string_equal(pl->from_resource, "nick");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_all_enc_types(void** state)
|
||||
{
|
||||
const char* enc_types[] = { "none", "otr", "pgp", "ox", "omemo" };
|
||||
for (size_t i = 0; i < sizeof(enc_types) / sizeof(enc_types[0]); i++) {
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", enc_types[i],
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
NULL, NULL, -1,
|
||||
"msg");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->enc, enc_types[i]);
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_crlf_handling(void** state)
|
||||
{
|
||||
/* Write a line, then read it with \r\n ending — parser should strip \r */
|
||||
char tmppath[] = "/tmp/proftest_crlf_XXXXXX";
|
||||
int fd = mkstemp(tmppath);
|
||||
assert_true(fd >= 0);
|
||||
|
||||
FILE* fp = fdopen(fd, "w");
|
||||
assert_non_null(fp);
|
||||
|
||||
/* Write a raw line with \r\n ending */
|
||||
fprintf(fp, "2025-03-01T10:00:00Z [chat|none] a@b.com: hello\r\n");
|
||||
fclose(fp);
|
||||
|
||||
fp = fopen(tmppath, "r");
|
||||
assert_non_null(fp);
|
||||
|
||||
gboolean truncated = FALSE;
|
||||
char* buf = ff_readline(fp, &truncated);
|
||||
fclose(fp);
|
||||
unlink(tmppath);
|
||||
|
||||
assert_non_null(buf);
|
||||
ff_parsed_line_t* pl = ff_parse_line(buf);
|
||||
free(buf);
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->from_jid, "a@b.com");
|
||||
assert_string_equal(pl->message, "hello");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_to_jid_special_chars(void** state)
|
||||
{
|
||||
/* to: and to_res: with pipe and bracket chars that need escaping */
|
||||
ff_parsed_line_t* pl = _roundtrip(
|
||||
"2025-03-01T10:00:00Z", "chat", "none",
|
||||
NULL, NULL, NULL,
|
||||
"a@b.com", NULL,
|
||||
"to|user@c.com", "res]with|special", -1,
|
||||
"msg with special to");
|
||||
|
||||
assert_non_null(pl);
|
||||
assert_string_equal(pl->to_jid, "to|user@c.com");
|
||||
assert_string_equal(pl->to_resource, "res]with|special");
|
||||
assert_string_equal(pl->message, "msg with special to");
|
||||
ff_parsed_line_free(pl);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_roundtrip_multiple_lines(void** state)
|
||||
{
|
||||
/* Write several lines, read and parse them all sequentially */
|
||||
char tmppath[] = "/tmp/proftest_multi_XXXXXX";
|
||||
int fd = mkstemp(tmppath);
|
||||
assert_true(fd >= 0);
|
||||
|
||||
FILE* fp = fdopen(fd, "w");
|
||||
assert_non_null(fp);
|
||||
|
||||
ff_write_line(fp, "2025-01-01T00:00:01Z", "chat", "none",
|
||||
NULL, NULL, NULL, "a@b.com", NULL,
|
||||
NULL, NULL, -1, "first");
|
||||
ff_write_line(fp, "2025-01-01T00:00:02Z", "chat", "none",
|
||||
NULL, NULL, NULL, "c@d.com", NULL,
|
||||
NULL, NULL, -1, "second");
|
||||
ff_write_line(fp, "2025-01-01T00:00:03Z", "muc", "omemo",
|
||||
"sid-3", NULL, NULL, "room@conf.com", "nick",
|
||||
NULL, NULL, -1, "third");
|
||||
fclose(fp);
|
||||
|
||||
fp = fopen(tmppath, "r");
|
||||
assert_non_null(fp);
|
||||
|
||||
int count = 0;
|
||||
const char* expected_msgs[] = { "first", "second", "third" };
|
||||
const char* expected_from[] = { "a@b.com", "c@d.com", "room@conf.com" };
|
||||
|
||||
while (1) {
|
||||
gboolean truncated = FALSE;
|
||||
char* buf = ff_readline(fp, &truncated);
|
||||
if (!buf)
|
||||
break;
|
||||
ff_parsed_line_t* pl = ff_parse_line(buf);
|
||||
free(buf);
|
||||
if (pl) {
|
||||
assert_true(count < 3);
|
||||
assert_string_equal(pl->message, expected_msgs[count]);
|
||||
assert_string_equal(pl->from_jid, expected_from[count]);
|
||||
ff_parsed_line_free(pl);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
unlink(tmppath);
|
||||
|
||||
assert_int_equal(count, 3);
|
||||
}
|
||||
|
||||
/* ================================================================
|
||||
* Additional parser edge-case tests
|
||||
* ================================================================ */
|
||||
|
||||
void
|
||||
test_ff_parsed_line_free_null_safe(void** state)
|
||||
{
|
||||
/* ff_parsed_line_free(NULL) must not crash */
|
||||
ff_parsed_line_free(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_no_space_rejected(void** state)
|
||||
{
|
||||
/* A line with no spaces at all cannot be parsed */
|
||||
assert_null(ff_parse_line("noseparatoratall"));
|
||||
}
|
||||
|
||||
void
|
||||
test_ff_parse_line_unclosed_bracket(void** state)
|
||||
{
|
||||
/* Unclosed metadata bracket should return NULL */
|
||||
assert_null(ff_parse_line("2025-03-01T10:00:00Z [chat|none a@b.com: msg"));
|
||||
}
|
||||
60
tests/unittests/test_database_export.h
Normal file
60
tests/unittests/test_database_export.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* test_database_export.h — unit tests for flatfile write/parse round-trip,
|
||||
* escape/unescape, and jid_to_dir helpers used by export/import. */
|
||||
|
||||
/* write → parse round-trip */
|
||||
void test_ff_roundtrip_simple_chat(void** state);
|
||||
void test_ff_roundtrip_with_all_metadata(void** state);
|
||||
void test_ff_roundtrip_with_resource(void** state);
|
||||
void test_ff_roundtrip_newline_in_body(void** state);
|
||||
void test_ff_roundtrip_pipe_in_stanza_id(void** state);
|
||||
void test_ff_roundtrip_backslash_in_body(void** state);
|
||||
void test_ff_roundtrip_unicode_body(void** state);
|
||||
void test_ff_roundtrip_empty_body(void** state);
|
||||
void test_ff_roundtrip_colonspace_in_resource(void** state);
|
||||
void test_ff_roundtrip_muc_type(void** state);
|
||||
void test_ff_roundtrip_omemo_enc(void** state);
|
||||
void test_ff_roundtrip_replace_id(void** state);
|
||||
void test_ff_roundtrip_to_jid_and_marked_read(void** state);
|
||||
|
||||
/* escape / unescape symmetry */
|
||||
void test_ff_escape_unescape_message_identity(void** state);
|
||||
void test_ff_escape_unescape_meta_identity(void** state);
|
||||
void test_ff_escape_meta_null_returns_null(void** state);
|
||||
void test_ff_escape_message_null_returns_empty(void** state);
|
||||
|
||||
/* jid_to_dir */
|
||||
void test_ff_jid_to_dir_simple(void** state);
|
||||
void test_ff_jid_to_dir_with_at(void** state);
|
||||
void test_ff_jid_to_dir_path_traversal_rejected(void** state);
|
||||
void test_ff_jid_to_dir_null(void** state);
|
||||
|
||||
/* parser edge cases */
|
||||
void test_ff_parse_line_empty(void** state);
|
||||
void test_ff_parse_line_comment(void** state);
|
||||
void test_ff_parse_line_legacy_format(void** state);
|
||||
void test_ff_parse_line_no_metadata(void** state);
|
||||
void test_ff_parse_line_invalid_timestamp(void** state);
|
||||
void test_ff_parse_line_empty_timestamp(void** state);
|
||||
void test_ff_parse_line_partial_iso_timestamp(void** state);
|
||||
void test_ff_parse_line_garbage_timestamp(void** state);
|
||||
void test_ff_parse_line_impossible_calendar_date(void** state);
|
||||
void test_ff_parse_line_negative_year_timestamp(void** state);
|
||||
void test_ff_parse_line_far_future_timestamp(void** state);
|
||||
|
||||
/* type/enc conversion round-trip */
|
||||
void test_ff_type_str_roundtrip(void** state);
|
||||
void test_ff_enc_str_roundtrip(void** state);
|
||||
|
||||
/* additional round-trip */
|
||||
void test_ff_roundtrip_bracket_in_stanza_id(void** state);
|
||||
void test_ff_roundtrip_backslash_in_resource(void** state);
|
||||
void test_ff_roundtrip_mucpm_type(void** state);
|
||||
void test_ff_roundtrip_all_enc_types(void** state);
|
||||
void test_ff_roundtrip_crlf_handling(void** state);
|
||||
void test_ff_roundtrip_to_jid_special_chars(void** state);
|
||||
void test_ff_roundtrip_multiple_lines(void** state);
|
||||
|
||||
/* additional parser edge cases */
|
||||
void test_ff_parsed_line_free_null_safe(void** state);
|
||||
void test_ff_parse_line_no_space_rejected(void** state);
|
||||
void test_ff_parse_line_unclosed_bracket(void** state);
|
||||
1137
tests/unittests/test_database_stress.c
Normal file
1137
tests/unittests/test_database_stress.c
Normal file
File diff suppressed because it is too large
Load Diff
28
tests/unittests/test_database_stress.h
Normal file
28
tests/unittests/test_database_stress.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* test_database_stress.h — stress tests for database I/O, MUC, large messages,
|
||||
* export/import roundtrip under load, and index/cache correctness. */
|
||||
|
||||
/* High-throughput write + parse */
|
||||
void test_stress_rapid_write_parse_1000(void** state);
|
||||
void test_stress_rapid_write_parse_10000(void** state);
|
||||
|
||||
/* MUC (chat room) messages */
|
||||
void test_stress_muc_many_participants(void** state);
|
||||
void test_stress_muc_rapid_messages(void** state);
|
||||
|
||||
/* Large messages */
|
||||
void test_stress_large_message_1mb(void** state);
|
||||
void test_stress_large_message_body_with_special_chars(void** state);
|
||||
void test_stress_many_large_messages_100(void** state);
|
||||
|
||||
/* Index and ID cache correctness under load */
|
||||
void test_stress_index_build_10000_lines(void** state);
|
||||
void test_stress_index_extend_append(void** state);
|
||||
void test_stress_id_cache_dedup_correctness(void** state);
|
||||
|
||||
/* Export / import roundtrip under load */
|
||||
void test_stress_export_merge_dedup_1000(void** state);
|
||||
void test_stress_mixed_types_and_encodings(void** state);
|
||||
|
||||
/* LMC correction chains under load */
|
||||
void test_stress_lmc_chain_deep(void** state);
|
||||
void test_stress_lmc_many_corrections(void** state);
|
||||
@@ -1,236 +0,0 @@
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xmpp/jid.h"
|
||||
|
||||
void
|
||||
create_jid_from_null_returns_null(void** state)
|
||||
{
|
||||
Jid* result = jid_create(NULL);
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_empty_string_returns_null(void** state)
|
||||
{
|
||||
Jid* result = jid_create("");
|
||||
assert_null(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser@mydomain/laptop", result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_resourcepart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("laptop", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_localpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("myuser", result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_returns_domainpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain/laptop", result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_resourcepart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("laptop", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_domainpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_full_nolocal_returns_null_localpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("mydomain/laptop");
|
||||
assert_null(result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_null_full(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_null(result->fulljid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_null_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_null(result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_bare(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("myuser@mydomain", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_localpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("myuser", result->localpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_jid_from_bare_returns_domainpart(void** state)
|
||||
{
|
||||
Jid* result = jid_create("myuser@mydomain");
|
||||
assert_string_equal("mydomain", result->domainpart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_room_jid_returns_room(void** state)
|
||||
{
|
||||
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
|
||||
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_room_jid_returns_nick(void** state)
|
||||
{
|
||||
Jid* result = jid_create_from_bare_and_resource("room@conference.domain.org", "myname");
|
||||
|
||||
assert_string_equal("myname", result->resourcepart);
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_with_slash_in_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/my/nick");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("my/nick", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/my/nick", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_with_at_in_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/my@nick");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("my@nick", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/my@nick", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_with_at_and_slash_in_resource(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/my@nick/something");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("my@nick/something", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/my@nick/something", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
create_full_with_trailing_slash(void** state)
|
||||
{
|
||||
Jid* result = jid_create("room@conference.domain.org/nick/");
|
||||
|
||||
assert_string_equal("room", result->localpart);
|
||||
assert_string_equal("conference.domain.org", result->domainpart);
|
||||
assert_string_equal("nick/", result->resourcepart);
|
||||
assert_string_equal("room@conference.domain.org", result->barejid);
|
||||
assert_string_equal("room@conference.domain.org/nick/", result->fulljid);
|
||||
|
||||
jid_destroy(result);
|
||||
}
|
||||
|
||||
void
|
||||
returns_fulljid_when_exists(void** state)
|
||||
{
|
||||
Jid* jid = jid_create("localpart@domainpart/resourcepart");
|
||||
|
||||
const char* result = jid_fulljid_or_barejid(jid);
|
||||
|
||||
assert_string_equal("localpart@domainpart/resourcepart", result);
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
void
|
||||
returns_barejid_when_fulljid_not_exists(void** state)
|
||||
{
|
||||
Jid* jid = jid_create("localpart@domainpart");
|
||||
|
||||
const char* result = jid_fulljid_or_barejid(jid);
|
||||
|
||||
assert_string_equal("localpart@domainpart", result);
|
||||
|
||||
jid_destroy(jid);
|
||||
}
|
||||
41
tests/unittests/ui/stub_ai.c
Normal file
41
tests/unittests/ui/stub_ai.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* stub_ai.c - Stubs for AI window functions
|
||||
*/
|
||||
|
||||
#include "ui/window.h"
|
||||
#include "ai/ai_client.h"
|
||||
|
||||
ProfWin*
|
||||
win_create_ai(AISession* session)
|
||||
{
|
||||
/* Return NULL to simulate failure in unit tests */
|
||||
(void)session;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
aiwin_display_response(ProfAiWin* win, const char* response)
|
||||
{
|
||||
/* Stub: do nothing */
|
||||
(void)win;
|
||||
(void)response;
|
||||
}
|
||||
|
||||
void
|
||||
aiwin_display_error(ProfAiWin* win, const char* error_msg)
|
||||
{
|
||||
/* Stub: do nothing */
|
||||
(void)win;
|
||||
(void)error_msg;
|
||||
}
|
||||
|
||||
void
|
||||
win_print_outgoing(ProfWin* window, const char* show_char, const char* const id, const char* const replace_id, const char* const message)
|
||||
{
|
||||
/* Stub: do nothing */
|
||||
(void)window;
|
||||
(void)show_char;
|
||||
(void)id;
|
||||
(void)replace_id;
|
||||
(void)message;
|
||||
}
|
||||
@@ -45,6 +45,9 @@
|
||||
#include "xmpp/test_form.h"
|
||||
#include "plugins/test_callbacks.h"
|
||||
#include "plugins/test_plugins_disco.h"
|
||||
#include "test_ai_client.h"
|
||||
#include "test_database_export.h"
|
||||
#include "test_database_stress.h"
|
||||
|
||||
#define muc_unit_test(f) cmocka_unit_test_setup_teardown(f, muc_before_test, muc_after_test)
|
||||
|
||||
@@ -712,6 +715,202 @@ main(int argc, char* argv[])
|
||||
cmocka_unit_test_setup_teardown(test_allow_unencrypted_message_confirms_on_second_attempt, load_preferences, close_preferences),
|
||||
cmocka_unit_test_setup_teardown(test_cmd_force_encryption_invalid_policy, load_preferences, close_preferences),
|
||||
cmocka_unit_test_setup_teardown(test_allow_unencrypted_message_invalid_mode, load_preferences, close_preferences),
|
||||
|
||||
// AI client tests
|
||||
cmocka_unit_test_setup_teardown(test_ai_client_init, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_add_provider, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_remove_provider, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_list_providers, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_set_provider_key, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_get_provider_key, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_create, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_ref_unref, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_add_message, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_clear_history, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_set_model, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_api_key_is_copied, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_add_provider_update_existing, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_add_provider_null_name_returns_null, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_add_provider_null_url_returns_null, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_create_null_provider_returns_null, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_create_null_model_returns_null, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_api_key_null_when_no_key_set, ai_client_setup, ai_client_teardown),
|
||||
/* Provider autocomplete tests */
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_forward, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_forward_custom, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_forward_no_match, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_forward_partial_match, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_next, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_previous, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_empty_search_str, ai_client_setup, ai_client_teardown),
|
||||
/* SIGSEGV on ai_providers_find(NULL, ...) — see test body and
|
||||
* AI_AUTOCOMPLETE_POSSIBLE_ISSUES.md, issue 1. Re-enable once the
|
||||
* NULL-search path is guarded. */
|
||||
/* cmocka_unit_test_setup_teardown(test_ai_providers_find_null_search_str, ai_client_setup, ai_client_teardown), */
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_case_insensitive, ai_client_setup, ai_client_teardown),
|
||||
/* Provider default model and settings tests */
|
||||
cmocka_unit_test_setup_teardown(test_ai_set_provider_default_model, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_get_provider_default_model, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_set_provider_setting, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_get_provider_setting, ai_client_setup, ai_client_teardown),
|
||||
/* Model caching tests */
|
||||
cmocka_unit_test_setup_teardown(test_ai_models_are_fresh_initial, ai_client_setup, ai_client_teardown),
|
||||
/* Model parsing tests */
|
||||
cmocka_unit_test(test_ai_parse_models_openai_format),
|
||||
cmocka_unit_test(test_ai_parse_models_perplexity_format),
|
||||
cmocka_unit_test(test_ai_parse_models_array_format),
|
||||
cmocka_unit_test(test_ai_parse_models_empty_json),
|
||||
cmocka_unit_test(test_ai_parse_models_null_handling),
|
||||
cmocka_unit_test(test_ai_parse_models_escaped_quotes),
|
||||
cmocka_unit_test(test_ai_parse_models_with_whitespace),
|
||||
/* AI autocomplete integration tests */
|
||||
cmocka_unit_test_setup_teardown(test_ai_start_provider_autocomplete_only_on_exact, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_cycling, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test(test_ai_json_escape),
|
||||
cmocka_unit_test(test_ai_json_escape_null),
|
||||
cmocka_unit_test(test_ai_json_escape_empty),
|
||||
cmocka_unit_test(test_ai_json_escape_special_chars),
|
||||
cmocka_unit_test(test_ai_json_escape_percent_signs),
|
||||
cmocka_unit_test(test_ai_json_escape_backslash_quote),
|
||||
/* Chat response parser */
|
||||
cmocka_unit_test(test_ai_parse_response_openai_content),
|
||||
cmocka_unit_test(test_ai_parse_response_perplexity_text),
|
||||
cmocka_unit_test(test_ai_parse_response_text_preferred_over_content),
|
||||
cmocka_unit_test(test_ai_parse_response_escaped_quote),
|
||||
cmocka_unit_test(test_ai_parse_response_newline_escape),
|
||||
cmocka_unit_test(test_ai_parse_response_empty_content),
|
||||
cmocka_unit_test(test_ai_parse_response_missing_field),
|
||||
cmocka_unit_test(test_ai_parse_response_null_input),
|
||||
cmocka_unit_test(test_ai_parse_response_empty_input),
|
||||
cmocka_unit_test(test_ai_parse_response_percent_signs_safe),
|
||||
cmocka_unit_test(test_ai_parse_response_braces_in_content),
|
||||
cmocka_unit_test(test_ai_parse_response_multiline_content),
|
||||
/* Error response parser */
|
||||
cmocka_unit_test(test_ai_parse_error_standard_envelope),
|
||||
cmocka_unit_test(test_ai_parse_error_with_escapes),
|
||||
cmocka_unit_test(test_ai_parse_error_no_error_field),
|
||||
cmocka_unit_test(test_ai_parse_error_no_message_field),
|
||||
cmocka_unit_test(test_ai_parse_error_null_input),
|
||||
cmocka_unit_test(test_ai_parse_error_empty_input),
|
||||
cmocka_unit_test(test_ai_parse_error_tab_escape),
|
||||
cmocka_unit_test(test_ai_parse_error_backslash_escape),
|
||||
/* Extended JSON escape coverage */
|
||||
cmocka_unit_test(test_ai_json_escape_backspace),
|
||||
cmocka_unit_test(test_ai_json_escape_formfeed),
|
||||
cmocka_unit_test(test_ai_json_escape_carriage_return),
|
||||
cmocka_unit_test(test_ai_json_escape_all_specials_combined),
|
||||
cmocka_unit_test(test_ai_json_escape_passes_utf8_through),
|
||||
/* Autocomplete cycling */
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_cycles_through_many, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_previous_walks_backwards, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_wraps_around, ai_client_setup, ai_client_teardown),
|
||||
/* Session edge cases */
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_add_message_null_session_no_crash, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_add_message_null_role_no_crash, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_add_message_null_content_no_crash, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_history_preserves_large_order, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_clear_empty_history, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_set_model_null_keeps_old, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_unref_null_no_crash, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_session_ref_null_returns_null, ai_client_setup, ai_client_teardown),
|
||||
/* Provider edge cases */
|
||||
cmocka_unit_test_setup_teardown(test_ai_get_provider_null_returns_null, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_remove_provider_null_returns_false, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_remove_provider_twice_second_fails, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_provider_survives_via_session_after_removal, ai_client_setup, ai_client_teardown),
|
||||
/* Settings */
|
||||
cmocka_unit_test_setup_teardown(test_ai_settings_multiple_keys_independent, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_settings_get_missing_returns_null, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_settings_isolated_between_providers, ai_client_setup, ai_client_teardown),
|
||||
/* Model parsing edge cases */
|
||||
cmocka_unit_test_setup_teardown(test_ai_parse_models_data_not_array, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_parse_models_empty_data_array, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_parse_models_id_outside_data_ignored, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_parse_models_multiple_models, ai_client_setup, ai_client_teardown),
|
||||
/* Prefs round-trip (uses prefs+ai setup) */
|
||||
cmocka_unit_test_setup_teardown(test_ai_prefs_round_trip_api_key, ai_client_setup_with_prefs, ai_client_teardown_with_prefs),
|
||||
cmocka_unit_test_setup_teardown(test_ai_prefs_round_trip_remove_key, ai_client_setup_with_prefs, ai_client_teardown_with_prefs),
|
||||
cmocka_unit_test_setup_teardown(test_ai_prefs_multiple_providers_persist, ai_client_setup_with_prefs, ai_client_teardown_with_prefs),
|
||||
/* Autocomplete deeper coverage */
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_find_after_remove_skips_removed, ai_client_setup, ai_client_teardown),
|
||||
/* Reset hook + persistence */
|
||||
cmocka_unit_test_setup_teardown(test_ai_providers_reset_ac_restarts_cycle, ai_client_setup, ai_client_teardown),
|
||||
cmocka_unit_test_setup_teardown(test_ai_add_provider_persisted_across_init, ai_client_setup_with_prefs, ai_client_teardown_with_prefs),
|
||||
cmocka_unit_test_setup_teardown(test_ai_remove_provider_persisted_across_init, ai_client_setup_with_prefs, ai_client_teardown_with_prefs),
|
||||
cmocka_unit_test_setup_teardown(test_ai_models_persisted_across_init, ai_client_setup_with_prefs, ai_client_teardown_with_prefs),
|
||||
// Flatfile export/import round-trip
|
||||
cmocka_unit_test(test_ff_roundtrip_simple_chat),
|
||||
cmocka_unit_test(test_ff_roundtrip_with_all_metadata),
|
||||
cmocka_unit_test(test_ff_roundtrip_with_resource),
|
||||
cmocka_unit_test(test_ff_roundtrip_newline_in_body),
|
||||
cmocka_unit_test(test_ff_roundtrip_pipe_in_stanza_id),
|
||||
cmocka_unit_test(test_ff_roundtrip_backslash_in_body),
|
||||
cmocka_unit_test(test_ff_roundtrip_unicode_body),
|
||||
cmocka_unit_test(test_ff_roundtrip_empty_body),
|
||||
cmocka_unit_test(test_ff_roundtrip_colonspace_in_resource),
|
||||
cmocka_unit_test(test_ff_roundtrip_muc_type),
|
||||
cmocka_unit_test(test_ff_roundtrip_omemo_enc),
|
||||
cmocka_unit_test(test_ff_roundtrip_replace_id),
|
||||
cmocka_unit_test(test_ff_roundtrip_to_jid_and_marked_read),
|
||||
|
||||
// Escape / unescape
|
||||
cmocka_unit_test(test_ff_escape_unescape_message_identity),
|
||||
cmocka_unit_test(test_ff_escape_unescape_meta_identity),
|
||||
cmocka_unit_test(test_ff_escape_meta_null_returns_null),
|
||||
cmocka_unit_test(test_ff_escape_message_null_returns_empty),
|
||||
|
||||
// jid_to_dir
|
||||
cmocka_unit_test(test_ff_jid_to_dir_simple),
|
||||
cmocka_unit_test(test_ff_jid_to_dir_with_at),
|
||||
cmocka_unit_test(test_ff_jid_to_dir_path_traversal_rejected),
|
||||
cmocka_unit_test(test_ff_jid_to_dir_null),
|
||||
|
||||
// Parser edge cases
|
||||
cmocka_unit_test(test_ff_parse_line_empty),
|
||||
cmocka_unit_test(test_ff_parse_line_comment),
|
||||
cmocka_unit_test(test_ff_parse_line_legacy_format),
|
||||
cmocka_unit_test(test_ff_parse_line_no_metadata),
|
||||
cmocka_unit_test(test_ff_parse_line_invalid_timestamp),
|
||||
cmocka_unit_test(test_ff_parse_line_empty_timestamp),
|
||||
cmocka_unit_test(test_ff_parse_line_partial_iso_timestamp),
|
||||
cmocka_unit_test(test_ff_parse_line_garbage_timestamp),
|
||||
cmocka_unit_test(test_ff_parse_line_impossible_calendar_date),
|
||||
cmocka_unit_test(test_ff_parse_line_negative_year_timestamp),
|
||||
cmocka_unit_test(test_ff_parse_line_far_future_timestamp),
|
||||
|
||||
// Type/enc round-trip
|
||||
cmocka_unit_test(test_ff_type_str_roundtrip),
|
||||
cmocka_unit_test(test_ff_enc_str_roundtrip),
|
||||
|
||||
// Additional round-trip
|
||||
cmocka_unit_test(test_ff_roundtrip_bracket_in_stanza_id),
|
||||
cmocka_unit_test(test_ff_roundtrip_backslash_in_resource),
|
||||
cmocka_unit_test(test_ff_roundtrip_mucpm_type),
|
||||
cmocka_unit_test(test_ff_roundtrip_all_enc_types),
|
||||
cmocka_unit_test(test_ff_roundtrip_crlf_handling),
|
||||
cmocka_unit_test(test_ff_roundtrip_to_jid_special_chars),
|
||||
cmocka_unit_test(test_ff_roundtrip_multiple_lines),
|
||||
|
||||
// Additional parser edge cases
|
||||
cmocka_unit_test(test_ff_parsed_line_free_null_safe),
|
||||
cmocka_unit_test(test_ff_parse_line_no_space_rejected),
|
||||
cmocka_unit_test(test_ff_parse_line_unclosed_bracket),
|
||||
|
||||
// Stress tests
|
||||
cmocka_unit_test(test_stress_rapid_write_parse_1000),
|
||||
cmocka_unit_test(test_stress_rapid_write_parse_10000),
|
||||
cmocka_unit_test(test_stress_muc_many_participants),
|
||||
cmocka_unit_test(test_stress_muc_rapid_messages),
|
||||
cmocka_unit_test(test_stress_large_message_1mb),
|
||||
cmocka_unit_test(test_stress_large_message_body_with_special_chars),
|
||||
cmocka_unit_test(test_stress_many_large_messages_100),
|
||||
cmocka_unit_test(test_stress_index_build_10000_lines),
|
||||
cmocka_unit_test(test_stress_index_extend_append),
|
||||
cmocka_unit_test(test_stress_id_cache_dedup_correctness),
|
||||
cmocka_unit_test(test_stress_export_merge_dedup_1000),
|
||||
cmocka_unit_test(test_stress_mixed_types_and_encodings),
|
||||
cmocka_unit_test(test_stress_lmc_chain_deep),
|
||||
cmocka_unit_test(test_stress_lmc_many_corrections),
|
||||
};
|
||||
return cmocka_run_group_tests(all_tests, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -112,6 +112,12 @@ connection_create_uuid(void)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char*
|
||||
connection_create_stanza_id(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
connection_free_uuid(char* uuid)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user