Files
cproof/tests/functionaltests/test_export_import.c
jabber.developer2 081de77593
All checks were successful
CI Code / Check coding style (pull_request) Successful in 35s
CI Code / Check spelling (pull_request) Successful in 44s
CI Code / Code Coverage (pull_request) Successful in 6m14s
CI Code / Linux (ubuntu) (pull_request) Successful in 7m37s
CI Code / Linux (arch) (pull_request) Successful in 7m41s
CI Code / Linux (debian) (pull_request) Successful in 10m22s
Add functional and unit tests for DB export/import
- 2 functional tests: export_sqlite_to_flatfile, import_flatfile_to_sqlite
  with XEP-0203 delay timestamps for deterministic verification
- 27 unit tests for database_export covering edge cases
- Merge test/db-functional-tests: 12 DB persistence tests (test_history)
- Group 2 rebalanced: 25 tests (23 base + 2 SQLite-only export/import)
- #ifdef HAVE_SQLITE guards for export/import tests
- prof_stop() helper in proftest.c
- Makefile.am: source ordering cleanup, new test files added
2026-03-04 18:45:17 +03:00

115 lines
4.1 KiB
C

#include <glib.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stabber.h>
#include "proftest.h"
/*
* Test: SQLite -> flat-file export preserves messages.
*
* Uses <delay> stamped messages to verify round-trip through export.
* Timestamp preservation is verified by unit tests (test_database_export.c);
* the history-load path returns NULL GDateTime for timestamps, so
* functional tests verify content survival only.
*
* Flow:
* 1. Connect (SQLite backend)
* 2. Receive message from buddy1 with delay stamp
* 3. Send outgoing message
* 4. /close, /history export, /history switch flatfile
* 5. Re-open chat -- history loaded from flat-file
* 6. Verify message content survives cross-backend migration
*/
void
export_sqlite_to_flatfile(void** state)
{
/* Phase 1: create message history in SQLite */
prof_connect();
/* Send outgoing message (timestamp = now) */
prof_input("/msg buddy1@localhost Hello from SQLite export test");
assert_true(prof_output_regex("me: .+Hello from SQLite export test"));
/* Receive incoming message with a fixed delay timestamp (10:30 UTC) */
stbbr_send(
"<message id='exp1' to='stabber@localhost' from='buddy1@localhost/res' type='chat'>"
"<body>SQLite reply at 1030</body>"
"<delay xmlns='urn:xmpp:delay' stamp='2025-06-15T10:30:00Z'/>"
"</message>");
assert_true(prof_output_regex("Buddy1/res: .+SQLite reply at 1030"));
/* Close chat window, return to console */
prof_input("/close");
/* Export SQLite history to flat-file format */
prof_input("/history export buddy1@localhost");
assert_true(prof_output_regex("Export complete: [0-9]+ message\\(s\\) exported\\."));
/* Phase 2: switch to flat-file backend and verify content survived */
prof_input("/history switch flatfile");
assert_true(prof_output_regex("Database backend switched to 'flatfile'\\."));
/* Open chat window -- history loads from flat-file backend */
prof_input("/msg buddy1@localhost");
/* Verify messages survived cross-backend migration */
assert_true(prof_output_regex("SQLite reply at 1030"));
assert_true(prof_output_regex("Hello from SQLite export test"));
}
/*
* Test: flat-file -> SQLite import preserves messages.
*
* Flow:
* 1. Connect, switch to flat-file backend
* 2. Receive message with delay stamp -- stored in flat-file
* 3. Send outgoing message
* 4. /close, switch to SQLite, /history import
* 5. Open chat -- history loaded from SQLite
* 6. Verify message content survives cross-backend migration
*/
void
import_flatfile_to_sqlite(void** state)
{
/* Phase 1: connect and switch to flat-file backend */
prof_connect();
prof_input("/history switch flatfile");
assert_true(prof_output_regex("Database backend switched to 'flatfile'\\."));
/* Send outgoing message */
prof_input("/msg buddy1@localhost Hello from flatfile import test");
assert_true(prof_output_regex("me: .+Hello from flatfile import test"));
/* Receive incoming message with a fixed delay timestamp (14:45 UTC) */
stbbr_send(
"<message id='imp1' to='stabber@localhost' from='buddy1@localhost/res' type='chat'>"
"<body>Flatfile reply at 1445</body>"
"<delay xmlns='urn:xmpp:delay' stamp='2025-06-15T14:45:00Z'/>"
"</message>");
assert_true(prof_output_regex("Buddy1/res: .+Flatfile reply at 1445"));
/* Close chat window */
prof_input("/close");
/* Phase 2: switch back to SQLite and import */
prof_input("/history switch sqlite");
assert_true(prof_output_regex("Database backend switched to 'sqlite'\\."));
/* Import flat-file history into SQLite */
prof_input("/history import buddy1@localhost");
assert_true(prof_output_regex("Import complete: [0-9]+ message\\(s\\) imported\\."));
/* Open chat window -- history loads from SQLite with imported data */
prof_input("/msg buddy1@localhost");
/* Verify messages survived cross-backend migration */
assert_true(prof_output_regex("Flatfile reply at 1445"));
assert_true(prof_output_regex("Hello from flatfile import test"));
}