Compare commits
1 Commits
test/autop
...
test/db-fu
| Author | SHA1 | Date | |
|---|---|---|---|
|
b289d1a753
|
@@ -185,9 +185,8 @@ functionaltest_sources = \
|
||||
tests/functionaltests/test_software.c tests/functionaltests/test_software.h \
|
||||
tests/functionaltests/test_muc.c tests/functionaltests/test_muc.h \
|
||||
tests/functionaltests/test_disconnect.c tests/functionaltests/test_disconnect.h \
|
||||
tests/functionaltests/test_history.c tests/functionaltests/test_history.h \
|
||||
tests/functionaltests/test_lastactivity.c tests/functionaltests/test_lastactivity.h \
|
||||
tests/functionaltests/test_autoping.c tests/functionaltests/test_autoping.h \
|
||||
tests/functionaltests/test_disco.c tests/functionaltests/test_disco.h \
|
||||
tests/functionaltests/functionaltests.c
|
||||
|
||||
main_source = src/main.c
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
* functional tests run less frequently than unit tests.
|
||||
*
|
||||
* Tests are organized into groups for better maintainability and parallel execution:
|
||||
* Group 1: Connect, Ping, Autoping (fast), Rooms, Software, Last Activity
|
||||
* Group 2: Message, Receipts, Roster, Chat Session
|
||||
* Group 3: Presence, Disconnect, Autoping (slow)
|
||||
* Group 4: MUC, Carbons
|
||||
* Group 1: Connect, Ping, Rooms, Software, Last Activity (19 tests)
|
||||
* Group 2: Message, Receipts, Roster, DB History (22 tests)
|
||||
* Group 3: Chat Session, Presence, Disconnect (22 tests)
|
||||
* Group 4: MUC, Carbons (21 tests)
|
||||
*
|
||||
* Parallel execution:
|
||||
* ./functionaltests - run all tests sequentially
|
||||
@@ -53,8 +53,7 @@
|
||||
#include "test_muc.h"
|
||||
#include "test_disconnect.h"
|
||||
#include "test_lastactivity.h"
|
||||
#include "test_autoping.h"
|
||||
#include "test_disco.h"
|
||||
#include "test_history.h"
|
||||
|
||||
/* Macro to wrap each test with setup/teardown functions */
|
||||
#define PROF_FUNC_TEST(test) cmocka_unit_test_setup_teardown(test, init_prof_test, close_prof_test)
|
||||
@@ -79,8 +78,9 @@ main(int argc, char* argv[])
|
||||
fprintf(stderr, "[PROF_TEST] Starting functional tests, group=%d\n", group);
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 1: Connect, Ping, Rooms, Software
|
||||
* GROUP 1: Connect, Ping, Rooms, Software, Last Activity
|
||||
* Basic XMPP session establishment and server queries
|
||||
* (19 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group1_tests[] = {
|
||||
/* Connection tests - verify login, roster, bookmarks */
|
||||
@@ -111,21 +111,12 @@ main(int argc, char* argv[])
|
||||
/* Last Activity - XEP-0012 */
|
||||
PROF_FUNC_TEST(responds_to_last_activity_request),
|
||||
PROF_FUNC_TEST(last_activity_request_to_contact),
|
||||
|
||||
/* Autoping command tests - fast, no waiting */
|
||||
PROF_FUNC_TEST(autoping_set_interval),
|
||||
PROF_FUNC_TEST(autoping_set_zero_disables),
|
||||
PROF_FUNC_TEST(autoping_timeout_set),
|
||||
PROF_FUNC_TEST(autoping_timeout_zero_disables),
|
||||
|
||||
/* Autoping slow tests - require sleep for timer triggers (~2s each) */
|
||||
PROF_FUNC_TEST(autoping_sends_ping_after_interval),
|
||||
PROF_FUNC_TEST(autoping_server_not_supporting_ping),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 2: Message, Receipts, Roster, Chat Session
|
||||
* GROUP 2: Message, Receipts, Roster, DB History
|
||||
* Core messaging and contact management
|
||||
* (23 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group2_tests[] = {
|
||||
/* Basic message send/receive */
|
||||
@@ -145,6 +136,29 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(sends_remove_item_nick),
|
||||
PROF_FUNC_TEST(sends_nick_change),
|
||||
|
||||
/* Database persistence - message write+read round-trip */
|
||||
PROF_FUNC_TEST(message_db_history_on_reopen),
|
||||
PROF_FUNC_TEST(message_db_history_multiple),
|
||||
PROF_FUNC_TEST(message_db_history_contact_isolation),
|
||||
PROF_FUNC_TEST(message_db_history_special_chars),
|
||||
PROF_FUNC_TEST(message_db_history_outgoing),
|
||||
PROF_FUNC_TEST(message_db_history_dialog),
|
||||
PROF_FUNC_TEST(message_db_history_empty),
|
||||
PROF_FUNC_TEST(message_db_history_long_message),
|
||||
PROF_FUNC_TEST(message_db_history_newline),
|
||||
PROF_FUNC_TEST(message_db_history_service_chars),
|
||||
#ifdef HAVE_HISTORY_VERIFY
|
||||
PROF_FUNC_TEST(message_db_history_verify),
|
||||
#endif
|
||||
PROF_FUNC_TEST(message_db_history_lmc),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 3: Chat Session, Presence, Disconnect
|
||||
* Session routing, status management, clean teardown
|
||||
* (22 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group3_tests[] = {
|
||||
/* Chat session management - bare/full JID routing */
|
||||
PROF_FUNC_TEST(sends_message_to_barejid_when_contact_offline),
|
||||
PROF_FUNC_TEST(sends_message_to_barejid_when_contact_online),
|
||||
@@ -152,13 +166,8 @@ main(int argc, char* argv[])
|
||||
PROF_FUNC_TEST(sends_subsequent_messages_to_fulljid),
|
||||
PROF_FUNC_TEST(resets_to_barejid_after_presence_received),
|
||||
PROF_FUNC_TEST(new_session_when_message_received_from_different_fulljid),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 3: Presence, Disconnect, Disco
|
||||
* Online/away/xa/dnd/chat status management
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group3_tests[] = {
|
||||
/* Presence - online/away/xa/dnd/chat status management */
|
||||
PROF_FUNC_TEST(presence_online),
|
||||
PROF_FUNC_TEST(presence_online_with_message),
|
||||
PROF_FUNC_TEST(presence_away),
|
||||
@@ -177,27 +186,12 @@ main(int argc, char* argv[])
|
||||
|
||||
/* Disconnect - clean session termination */
|
||||
PROF_FUNC_TEST(disconnect_ends_session),
|
||||
|
||||
/* Service Discovery - XEP-0030 */
|
||||
PROF_FUNC_TEST(disco_info_shows_identity),
|
||||
PROF_FUNC_TEST(disco_info_shows_features),
|
||||
PROF_FUNC_TEST(disco_info_to_server),
|
||||
PROF_FUNC_TEST(disco_info_to_jid),
|
||||
PROF_FUNC_TEST(disco_info_not_found),
|
||||
PROF_FUNC_TEST(disco_items_shows_items),
|
||||
PROF_FUNC_TEST(disco_items_empty_result),
|
||||
PROF_FUNC_TEST(disco_requires_connection),
|
||||
PROF_FUNC_TEST(disco_items_to_jid),
|
||||
PROF_FUNC_TEST(disco_info_empty_result),
|
||||
PROF_FUNC_TEST(disco_info_multiple_identities),
|
||||
PROF_FUNC_TEST(disco_info_without_name),
|
||||
PROF_FUNC_TEST(disco_items_without_name),
|
||||
PROF_FUNC_TEST(disco_info_service_unavailable),
|
||||
};
|
||||
|
||||
/* ============================================================
|
||||
* GROUP 4: MUC, Carbons
|
||||
* Multi-user chat and message synchronization
|
||||
* (21 tests)
|
||||
* ============================================================ */
|
||||
const struct CMUnitTest group4_tests[] = {
|
||||
/* MUC room join with various options - XEP-0045 */
|
||||
@@ -240,9 +234,9 @@ main(int argc, char* argv[])
|
||||
const struct CMUnitTest* tests;
|
||||
size_t count;
|
||||
} groups[] = {
|
||||
{ "Group 1: Connect/Ping/Rooms/Software/Autoping", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: Message/Receipts/Roster/Session", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Presence/Disconnect/Disco", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 1: Connect/Ping/Rooms/Software/LastActivity", group1_tests, ARRAY_SIZE(group1_tests) },
|
||||
{ "Group 2: Message/Receipts/Roster/DBHistory", group2_tests, ARRAY_SIZE(group2_tests) },
|
||||
{ "Group 3: Session/Presence/Disconnect", group3_tests, ARRAY_SIZE(group3_tests) },
|
||||
{ "Group 4: MUC/Carbons", group4_tests, ARRAY_SIZE(group4_tests) },
|
||||
};
|
||||
const int num_groups = ARRAY_SIZE(groups);
|
||||
|
||||
@@ -362,6 +362,7 @@ close_prof_test(void **state)
|
||||
fd = 0;
|
||||
child_pid = 0;
|
||||
}
|
||||
_cleanup_dirs();
|
||||
|
||||
if (config_orig) {
|
||||
setenv("XDG_CONFIG_HOME", config_orig, 1);
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
#include <glib.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
void
|
||||
autoping_set_interval(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping set 60");
|
||||
assert_true(prof_output_exact("Autoping interval set to 60 seconds."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_set_zero_disables(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping set 0");
|
||||
assert_true(prof_output_exact("Autoping disabled."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_timeout_set(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping timeout 30");
|
||||
assert_true(prof_output_exact("Autoping timeout set to 30 seconds."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_timeout_zero_disables(void** state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/autoping timeout 0");
|
||||
assert_true(prof_output_exact("Autoping timeout disabled."));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_sends_ping_after_interval(void** state)
|
||||
{
|
||||
/*
|
||||
* This test verifies that autoping sends a ping IQ after the configured
|
||||
* interval. We set a short interval (1 second) and verify the ping is sent.
|
||||
*/
|
||||
|
||||
// Register disco#info response with ping support
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Stabber'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
// Register ping response
|
||||
stbbr_for_query("urn:xmpp:ping",
|
||||
"<iq from='localhost' to='stabber@localhost/profanity' type='result'/>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
// Set short autoping interval
|
||||
prof_input("/autoping set 1");
|
||||
assert_true(prof_output_exact("Autoping interval set to 1 seconds."));
|
||||
|
||||
// Wait for autoping to trigger (interval + some buffer)
|
||||
sleep(2);
|
||||
|
||||
// Verify ping was sent (no 'to' attribute means server ping)
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' type='get'>"
|
||||
"<ping xmlns='urn:xmpp:ping'/>"
|
||||
"</iq>"
|
||||
));
|
||||
}
|
||||
|
||||
void
|
||||
autoping_server_not_supporting_ping(void** state)
|
||||
{
|
||||
/*
|
||||
* When server doesn't support ping, autoping should show error.
|
||||
*/
|
||||
|
||||
// Register disco#info response WITHOUT ping support
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Stabber'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
// Set short autoping interval
|
||||
prof_input("/autoping set 1");
|
||||
assert_true(prof_output_exact("Autoping interval set to 1 seconds."));
|
||||
|
||||
// Wait for autoping to trigger
|
||||
sleep(2);
|
||||
|
||||
// Should show error about ping not being supported
|
||||
assert_true(prof_output_regex("Server ping not supported"));
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
void autoping_set_interval(void** state);
|
||||
void autoping_set_zero_disables(void** state);
|
||||
void autoping_timeout_set(void** state);
|
||||
void autoping_timeout_zero_disables(void** state);
|
||||
void autoping_sends_ping_after_interval(void** state);
|
||||
void autoping_server_not_supporting_ping(void** state);
|
||||
@@ -1,420 +0,0 @@
|
||||
/*
|
||||
* test_disco.c
|
||||
*
|
||||
* Functional tests for /disco command (XEP-0030 Service Discovery).
|
||||
* Tests cover:
|
||||
* - /disco info [jid] - query entity capabilities and features
|
||||
* - /disco items [jid] - query entity items/services
|
||||
*
|
||||
* XEP-0030: https://xmpp.org/extensions/xep-0030.html
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
void
|
||||
disco_info_shows_identity(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info displays identity information correctly.
|
||||
* Identity includes: name, type, category
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='Prosody'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery info for localhost"));
|
||||
assert_true(prof_output_exact("Identities"));
|
||||
assert_true(prof_output_regex("Prosody.*im.*server"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_shows_features(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info displays feature list.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='TestServer'/>"
|
||||
"<feature var='urn:xmpp:ping'/>"
|
||||
"<feature var='http://jabber.org/protocol/disco#info'/>"
|
||||
"<feature var='http://jabber.org/protocol/disco#items'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Features:"));
|
||||
assert_true(prof_output_exact("urn:xmpp:ping"));
|
||||
assert_true(prof_output_exact("http://jabber.org/protocol/disco#info"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_to_server(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info without arguments queries the server (domainpart).
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im' name='LocalServer'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
/* Verify request was sent to server (localhost) */
|
||||
prof_timeout(10);
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_to_jid(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info <jid> queries the specified JID.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='conference.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='conference' type='text' name='MUC Service'/>"
|
||||
"<feature var='http://jabber.org/protocol/muc'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info conference.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Verify request was sent to specified JID */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='conference.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
||||
assert_true(prof_output_exact("Service discovery info for conference.localhost"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_not_found(void **state)
|
||||
{
|
||||
/*
|
||||
* Test error handling when disco info returns item-not-found.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='error' from='unknown.localhost'>"
|
||||
"<error type='cancel'>"
|
||||
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
|
||||
"</error>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
|
||||
prof_input("/disco info unknown.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_regex("Service discovery failed.*item-not-found"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_shows_items(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items displays items list with JID and name.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'>"
|
||||
"<item jid='conference.localhost' name='Chat Rooms'/>"
|
||||
"<item jid='pubsub.localhost' name='Publish-Subscribe'/>"
|
||||
"<item jid='proxy.localhost' name='SOCKS5 Bytestreams'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery items for localhost:"));
|
||||
assert_true(prof_output_regex("conference.localhost.*Chat Rooms"));
|
||||
assert_true(prof_output_regex("pubsub.localhost.*Publish-Subscribe"));
|
||||
assert_true(prof_output_regex("proxy.localhost.*SOCKS5 Bytestreams"));
|
||||
|
||||
/* Verify IQ was sent with correct id */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='discoitemsreq' to='localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||||
"</iq>"
|
||||
));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_empty_result(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items handles empty result gracefully.
|
||||
* Per XEP-0030: "if an entity has no associated items, it MUST return
|
||||
* an empty <query/> element (rather than an error)"
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("No service discovery items for localhost"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_requires_connection(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info and /disco items require an active connection.
|
||||
* First test without any connection, then after connect/disconnect.
|
||||
*/
|
||||
|
||||
/* Without connection */
|
||||
prof_input("/disconnect");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
prof_input("/disco info");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
prof_input("/disco items");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
/* After connect and disconnect */
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disconnect");
|
||||
assert_true(prof_output_exact("stabber@localhost logged out successfully."));
|
||||
|
||||
prof_input("/disco info");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
|
||||
prof_input("/disco items");
|
||||
assert_true(prof_output_exact("You are not currently connected."));
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_to_jid(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items <jid> queries the specified JID.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='conference.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'>"
|
||||
"<item jid='room1@conference.localhost' name='General Chat'/>"
|
||||
"<item jid='room2@conference.localhost' name='Support'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items conference.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Verify request was sent to specified JID */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='discoitemsreq' to='conference.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'/>"
|
||||
"</iq>"
|
||||
));
|
||||
|
||||
assert_true(prof_output_exact("Service discovery items for conference.localhost:"));
|
||||
assert_true(prof_output_regex("room1@conference.localhost.*General Chat"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_empty_result(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info handles empty result (no identities/features).
|
||||
* This can happen with minimal server configurations.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='minimal.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info minimal.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
/* Verify request was sent */
|
||||
assert_true(stbbr_received(
|
||||
"<iq id='*' to='minimal.localhost' type='get'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'/>"
|
||||
"</iq>"
|
||||
));
|
||||
/* Empty result should not crash and should not show "Service discovery info" */
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_multiple_identities(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info displays multiple identities correctly.
|
||||
* Entities can have multiple identities (e.g., server + gateway).
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='gateway.localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='gateway' type='irc' name='IRC Gateway'/>"
|
||||
"<identity category='directory' type='chatroom' name='Room Directory'/>"
|
||||
"<identity category='automation' type='command-node' name='Ad-Hoc Commands'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info gateway.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery info for gateway.localhost"));
|
||||
assert_true(prof_output_exact("Identities"));
|
||||
assert_true(prof_output_regex("IRC Gateway.*irc.*gateway"));
|
||||
assert_true(prof_output_regex("Room Directory.*chatroom.*directory"));
|
||||
assert_true(prof_output_regex("Ad-Hoc Commands.*command-node.*automation"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_without_name(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco info handles identity without name attribute.
|
||||
* Per XEP-0030: name is OPTIONAL, only category and type are REQUIRED.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#info'>"
|
||||
"<identity category='server' type='im'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery info for localhost"));
|
||||
assert_true(prof_output_exact("Identities"));
|
||||
/* Should show type and category even without name */
|
||||
assert_true(prof_output_regex("im.*server"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_items_without_name(void **state)
|
||||
{
|
||||
/*
|
||||
* Test that /disco items handles items without name attribute.
|
||||
* Per XEP-0030: name is OPTIONAL for items, only jid is REQUIRED.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#items",
|
||||
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
|
||||
"<query xmlns='http://jabber.org/protocol/disco#items'>"
|
||||
"<item jid='conference.localhost'/>"
|
||||
"<item jid='pubsub.localhost' name='PubSub Service'/>"
|
||||
"<item jid='upload.localhost'/>"
|
||||
"</query>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco items");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_exact("Service discovery items for localhost:"));
|
||||
/* Items without name should still display their JID */
|
||||
assert_true(prof_output_exact("conference.localhost"));
|
||||
assert_true(prof_output_regex("pubsub.localhost.*PubSub Service"));
|
||||
assert_true(prof_output_exact("upload.localhost"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
void
|
||||
disco_info_service_unavailable(void **state)
|
||||
{
|
||||
/*
|
||||
* Test error handling when disco info returns service-unavailable.
|
||||
*/
|
||||
stbbr_for_query("http://jabber.org/protocol/disco#info",
|
||||
"<iq to='stabber@localhost/profanity' type='error' from='offline.localhost'>"
|
||||
"<error type='cancel'>"
|
||||
"<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
|
||||
"</error>"
|
||||
"</iq>"
|
||||
);
|
||||
|
||||
prof_connect();
|
||||
|
||||
prof_input("/disco info offline.localhost");
|
||||
|
||||
prof_timeout(10);
|
||||
assert_true(prof_output_regex("Service discovery failed.*service-unavailable"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
/* test_disco.h
|
||||
*
|
||||
* Functional tests for /disco command (XEP-0030 Service Discovery)
|
||||
*/
|
||||
|
||||
void disco_info_shows_identity(void **state);
|
||||
void disco_info_shows_features(void **state);
|
||||
void disco_info_to_server(void **state);
|
||||
void disco_info_to_jid(void **state);
|
||||
void disco_info_not_found(void **state);
|
||||
void disco_items_shows_items(void **state);
|
||||
void disco_items_empty_result(void **state);
|
||||
void disco_requires_connection(void **state);
|
||||
void disco_items_to_jid(void **state);
|
||||
void disco_info_empty_result(void **state);
|
||||
void disco_info_multiple_identities(void **state);
|
||||
void disco_info_without_name(void **state);
|
||||
void disco_items_without_name(void **state);
|
||||
void disco_info_service_unavailable(void **state);
|
||||
475
tests/functionaltests/test_history.c
Normal file
475
tests/functionaltests/test_history.c
Normal file
@@ -0,0 +1,475 @@
|
||||
/*
|
||||
* test_history.c
|
||||
*
|
||||
* Functional test for database message persistence.
|
||||
* Verifies that a received chat message is written to the database
|
||||
* and loaded back as history when the chat window is reopened.
|
||||
*
|
||||
* These tests only exercise the public log_database API through normal
|
||||
* profanity UI operations, so they work with any storage backend.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "prof_cmocka.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <stabber.h>
|
||||
|
||||
#include "proftest.h"
|
||||
|
||||
/*
|
||||
* Test: message written to DB is loaded as history on chat window reopen.
|
||||
*
|
||||
* Flow:
|
||||
* 1. Connect and enable /history on (enables PREF_CHLOG + PREF_HISTORY)
|
||||
* 2. Receive a chat message while on the console window — the message
|
||||
* body is NOT rendered to the terminal (only a console notification
|
||||
* "<< chat message: ... (win N)" appears), but the message IS
|
||||
* written to the database via chat_log_msg_in()
|
||||
* 3. Close the auto-created chat window (destroying its in-memory buffer)
|
||||
* 4. Reopen the chat window with /msg — chatwin_new() calls
|
||||
* _chatwin_history() which reads from log_database_get_previous_chat()
|
||||
* 5. Assert the message body appears in the terminal output, proving
|
||||
* it was persisted to and read back from the database
|
||||
*/
|
||||
void
|
||||
message_db_history_on_reopen(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
/* Enable chat logging and history display */
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Receive a message while on the console window.
|
||||
* The body text is NOT printed to the visible terminal — only the
|
||||
* console notification appears. The message is logged to the DB. */
|
||||
stbbr_send(
|
||||
"<message id='hist-db-test-1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>persistence-roundtrip-check-42</body>"
|
||||
"</message>");
|
||||
|
||||
/* Wait for the console notification (proves message was received).
|
||||
* buddy1@localhost is in the roster as "Buddy1", and PREF_RESOURCE_MESSAGE
|
||||
* is on by default, so the display name is "Buddy1/phone". */
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Close the chat window that was auto-created for the incoming message.
|
||||
* This destroys its in-memory buffer so the text is gone from UI. */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Reopen the chat window — chatwin_new() will load history from DB.
|
||||
* The message body should now appear on screen for the first time. */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* The history-loaded message must contain the body we sent earlier.
|
||||
* Since the body was never rendered to the terminal before (it was
|
||||
* only in the hidden window's ncurses buffer which was destroyed),
|
||||
* finding it now proves the database write+read round-trip works. */
|
||||
assert_true(prof_output_exact("persistence-roundtrip-check-42"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: multiple messages from the same contact are all preserved.
|
||||
*
|
||||
* Uses different resources so each console notification is unique and
|
||||
* we can reliably synchronise on each delivery before proceeding.
|
||||
*/
|
||||
void
|
||||
message_db_history_multiple(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Three messages from different resources → distinct notifications */
|
||||
stbbr_send(
|
||||
"<message id='multi1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>db-multi-first-aaa</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='multi2' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/laptop' type='chat'>"
|
||||
"<body>db-multi-second-bbb</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/laptop (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='multi3' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/tablet' type='chat'>"
|
||||
"<body>db-multi-third-ccc</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/tablet (win 2)"));
|
||||
|
||||
/* Close and reopen */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* All three must be present in history */
|
||||
assert_true(prof_output_exact("db-multi-first-aaa"));
|
||||
assert_true(prof_output_exact("db-multi-second-bbb"));
|
||||
assert_true(prof_output_exact("db-multi-third-ccc"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: messages are stored per-contact — buddy1's history does not
|
||||
* leak into buddy2's window.
|
||||
*
|
||||
* 1. Receive from buddy1 and buddy2 while on console (bodies hidden)
|
||||
* 2. Close all chat windows
|
||||
* 3. Open buddy1 → verify buddy1's body present, buddy2's body absent
|
||||
*/
|
||||
void
|
||||
message_db_history_contact_isolation(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Receive from buddy1 */
|
||||
stbbr_send(
|
||||
"<message id='iso1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>isolation-buddy1-only-xyzzy</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Receive from buddy2 */
|
||||
stbbr_send(
|
||||
"<message id='iso2' to='stabber@localhost' "
|
||||
"from='buddy2@localhost/phone' type='chat'>"
|
||||
"<body>isolation-buddy2-only-plugh</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy2/phone (win 3)"));
|
||||
|
||||
/* Close all chat windows at once */
|
||||
prof_input("/close all");
|
||||
assert_true(prof_output_exact("Closed 2 windows."));
|
||||
|
||||
/* Open buddy1 — history should contain ONLY buddy1's message */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("isolation-buddy1-only-xyzzy"));
|
||||
|
||||
/* buddy2's body was never printed to the terminal (received on
|
||||
* console), so finding it now would mean cross-contact leakage */
|
||||
prof_timeout(3);
|
||||
assert_false(prof_output_exact("isolation-buddy2-only-plugh"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: special characters survive the DB write+read round-trip.
|
||||
*
|
||||
* The XMPP body uses XML entities (& < > ") which the
|
||||
* XML parser decodes before storage. The DB must preserve the decoded
|
||||
* characters and return them unchanged.
|
||||
*/
|
||||
void
|
||||
message_db_history_special_chars(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='spec1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>chars: & <tag> "quoted"</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* The decoded text must appear exactly as-is */
|
||||
assert_true(prof_output_exact("chars: & <tag> \"quoted\""));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: outgoing message (sent via /msg) persists in DB.
|
||||
*
|
||||
* NOTE: The outgoing body IS rendered to the terminal when sent. Since
|
||||
* prof_output_exact searches the cumulative buffer, the assertion alone
|
||||
* does not conclusively prove DB persistence. However, combined with
|
||||
* the incoming tests, this verifies the end-to-end outgoing write path
|
||||
* and catches crashes in the outgoing DB code.
|
||||
*/
|
||||
void
|
||||
message_db_history_outgoing(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Send outgoing — opens and focuses chat window */
|
||||
prof_input("/msg buddy1@localhost db-outgoing-sent-42");
|
||||
assert_true(prof_output_regex("me: .+db-outgoing-sent-42"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Reopen — history should load the outgoing message */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("db-outgoing-sent-42"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: a dialog (outgoing + incoming) is fully preserved in history.
|
||||
*
|
||||
* Sends an outgoing message, then closes the window. A reply arrives
|
||||
* while on the console (body never rendered). After reopen, both sides
|
||||
* of the conversation appear — proving the incoming read from DB works
|
||||
* and the outgoing write path completed without error.
|
||||
*/
|
||||
void
|
||||
message_db_history_dialog(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Phase 1: send outgoing (renders to terminal) */
|
||||
prof_input("/msg buddy1@localhost dialog-out-msg-42");
|
||||
assert_true(prof_output_regex("me: .+dialog-out-msg-42"));
|
||||
|
||||
/* Return to console */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Phase 2: receive reply on console (body NOT in terminal buffer) */
|
||||
stbbr_send(
|
||||
"<message id='dlg-in' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>dialog-in-reply-77</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Close the auto-created window */
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
/* Phase 3: reopen — history should have both directions */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
|
||||
/* Incoming body conclusively proves DB round-trip */
|
||||
assert_true(prof_output_exact("dialog-in-reply-77"));
|
||||
/* Outgoing body is consistent with DB persistence */
|
||||
assert_true(prof_output_exact("dialog-out-msg-42"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: opening a chat window for a contact with no prior messages
|
||||
* does not crash and the window is usable.
|
||||
*/
|
||||
void
|
||||
message_db_history_empty(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* buddy2 has never exchanged messages — history is empty */
|
||||
prof_input("/msg buddy2@localhost");
|
||||
assert_true(prof_output_exact("buddy2@localhost"));
|
||||
|
||||
/* Verify the window is functional by sending a message */
|
||||
prof_input("empty-history-smoke-test");
|
||||
assert_true(prof_output_regex("me: .+empty-history-smoke-test"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: a long message (1000+ characters) is not truncated by the DB.
|
||||
*/
|
||||
void
|
||||
message_db_history_long_message(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Build a 1020-character body: 1000 x 'A' + unique suffix */
|
||||
char body[1100];
|
||||
memset(body, 'A', 1000);
|
||||
strcpy(body + 1000, "-long-db-end-MARKER");
|
||||
|
||||
char xml[1500];
|
||||
snprintf(xml, sizeof(xml),
|
||||
"<message id='long1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>%s</body>"
|
||||
"</message>", body);
|
||||
stbbr_send(xml);
|
||||
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("-long-db-end-MARKER"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: message body containing embedded newlines (LF) is stored and
|
||||
* loaded correctly.
|
||||
*
|
||||
* Uses XML character reference for literal newline in body.
|
||||
*/
|
||||
void
|
||||
message_db_history_newline(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='nl1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>nl-first-line-7k nl-second-line-9m nl-third-line-2p</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
/* Each fragment must survive the round-trip */
|
||||
assert_true(prof_output_exact("nl-first-line-7k"));
|
||||
assert_true(prof_output_exact("nl-second-line-9m"));
|
||||
assert_true(prof_output_exact("nl-third-line-2p"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test: characters that could break storage format (backslash, pipe,
|
||||
* percent, braces, brackets, equals) survive DB round-trip.
|
||||
*/
|
||||
void
|
||||
message_db_history_service_chars(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='svc1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>svc: a\\b c|d e%f {g} [h] i=j</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
prof_input("/close 2");
|
||||
assert_true(prof_output_exact("Closed window 2"));
|
||||
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("svc: a\\b c|d e%f {g} [h] i=j"));
|
||||
}
|
||||
|
||||
#ifdef HAVE_HISTORY_VERIFY
|
||||
/*
|
||||
* Test: /history verify reports no issues after normal message writes.
|
||||
*/
|
||||
void
|
||||
message_db_history_verify(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Write a few messages to create non-trivial DB state */
|
||||
stbbr_send(
|
||||
"<message id='ver1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>verify-msg-one</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
stbbr_send(
|
||||
"<message id='ver2' to='stabber@localhost' "
|
||||
"from='buddy2@localhost/phone' type='chat'>"
|
||||
"<body>verify-msg-two</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy2/phone (win 3)"));
|
||||
|
||||
/* Run verify — should find no issues */
|
||||
prof_input("/history verify");
|
||||
assert_true(prof_output_exact("Verification complete: no issues found."));
|
||||
}
|
||||
#endif /* HAVE_HISTORY_VERIFY */
|
||||
|
||||
/*
|
||||
* Test: LMC (Last Message Correction, XEP-0308) — incoming correction
|
||||
* replaces the original in DB history.
|
||||
*
|
||||
* Both messages arrive while focused on the console so their bodies
|
||||
* are never rendered to the terminal. After reopen, only the corrected
|
||||
* text should appear — the original should be absent.
|
||||
*/
|
||||
void
|
||||
message_db_history_lmc(void **state)
|
||||
{
|
||||
prof_connect();
|
||||
|
||||
prof_input("/history on");
|
||||
assert_true(prof_output_regex("Chat history enabled\\."));
|
||||
|
||||
/* Original message (body never displayed — received on console) */
|
||||
stbbr_send(
|
||||
"<message id='lmc-orig-1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>lmc-before-correction-aaa</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy1/phone (win 2)"));
|
||||
|
||||
/* Correction replacing the original (XEP-0308).
|
||||
* Use buddy2 message as sync barrier to ensure correction is processed. */
|
||||
stbbr_send(
|
||||
"<message id='lmc-corr-1' to='stabber@localhost' "
|
||||
"from='buddy1@localhost/phone' type='chat'>"
|
||||
"<body>lmc-after-correction-zzz</body>"
|
||||
"<replace id='lmc-orig-1' xmlns='urn:xmpp:message-correct:0'/>"
|
||||
"</message>");
|
||||
|
||||
/* Sync barrier: send from buddy2, wait for its notification */
|
||||
stbbr_send(
|
||||
"<message id='lmc-sync' to='stabber@localhost' "
|
||||
"from='buddy2@localhost/phone' type='chat'>"
|
||||
"<body>lmc-sync-barrier</body>"
|
||||
"</message>");
|
||||
assert_true(prof_output_exact("<< chat message: Buddy2/phone (win 3)"));
|
||||
|
||||
/* Close buddy1 and buddy2 windows */
|
||||
prof_input("/close all");
|
||||
assert_true(prof_output_exact("Closed 2 windows."));
|
||||
|
||||
/* Reopen buddy1 — should have corrected text only */
|
||||
prof_input("/msg buddy1@localhost");
|
||||
assert_true(prof_output_exact("lmc-after-correction-zzz"));
|
||||
|
||||
/* Original body was never in the terminal buffer (received on console).
|
||||
* Its absence in history proves the correction was applied in the DB. */
|
||||
prof_timeout(3);
|
||||
assert_false(prof_output_exact("lmc-before-correction-aaa"));
|
||||
prof_timeout_reset();
|
||||
}
|
||||
14
tests/functionaltests/test_history.h
Normal file
14
tests/functionaltests/test_history.h
Normal file
@@ -0,0 +1,14 @@
|
||||
void message_db_history_on_reopen(void **state);
|
||||
void message_db_history_multiple(void **state);
|
||||
void message_db_history_contact_isolation(void **state);
|
||||
void message_db_history_special_chars(void **state);
|
||||
void message_db_history_outgoing(void **state);
|
||||
void message_db_history_dialog(void **state);
|
||||
void message_db_history_empty(void **state);
|
||||
void message_db_history_long_message(void **state);
|
||||
void message_db_history_newline(void **state);
|
||||
void message_db_history_service_chars(void **state);
|
||||
#ifdef HAVE_HISTORY_VERIFY
|
||||
void message_db_history_verify(void **state);
|
||||
#endif
|
||||
void message_db_history_lmc(void **state);
|
||||
Reference in New Issue
Block a user