#include #include "prof_cmocka.h" #include #include #include #include #include #include "proftest.h" /* * Test: SQLite -> flat-file export preserves messages. * * Uses 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( "" "SQLite reply at 1030" "" ""); 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( "" "Flatfile reply at 1445" "" ""); 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")); }