diff --git a/Makefile.am b/Makefile.am index 60ff0f33..f21b6eea 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,6 +186,7 @@ functionaltest_sources = \ tests/functionaltests/test_muc.c tests/functionaltests/test_muc.h \ tests/functionaltests/test_disconnect.c tests/functionaltests/test_disconnect.h \ tests/functionaltests/test_lastactivity.c tests/functionaltests/test_lastactivity.h \ + tests/functionaltests/test_autoping.c tests/functionaltests/test_autoping.h \ tests/functionaltests/functionaltests.c main_source = src/main.c diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index 46d1a7d2..331543ad 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -15,9 +15,9 @@ * functional tests run less frequently than unit tests. * * Tests are organized into groups for better maintainability and parallel execution: - * Group 1: Connect, Ping, Rooms, Software + * Group 1: Connect, Ping, Autoping (fast), Rooms, Software, Last Activity * Group 2: Message, Receipts, Roster, Chat Session - * Group 3: Presence, Disconnect + * Group 3: Presence, Disconnect, Autoping (slow) * Group 4: MUC, Carbons * * Parallel execution: @@ -53,6 +53,7 @@ #include "test_muc.h" #include "test_disconnect.h" #include "test_lastactivity.h" +#include "test_autoping.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) @@ -95,6 +96,12 @@ main(int argc, char* argv[]) PROF_FUNC_TEST(ping_jid), PROF_FUNC_TEST(ping_jid_not_supported), + /* 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), + /* Room discovery - XEP-0045 */ PROF_FUNC_TEST(rooms_query), @@ -165,6 +172,10 @@ main(int argc, char* argv[]) /* Disconnect - clean session termination */ PROF_FUNC_TEST(disconnect_ends_session), + + /* Autoping slow tests - require sleep for timer triggers */ + PROF_FUNC_TEST(autoping_sends_ping_after_interval), + PROF_FUNC_TEST(autoping_server_not_supporting_ping), }; /* ============================================================ diff --git a/tests/functionaltests/test_autoping.c b/tests/functionaltests/test_autoping.c new file mode 100644 index 00000000..55c99df3 --- /dev/null +++ b/tests/functionaltests/test_autoping.c @@ -0,0 +1,120 @@ +#include +#include "prof_cmocka.h" +#include +#include +#include + +#include + +#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 (2 seconds) and verify the ping is sent. + */ + + // Register disco#info response with ping support + stbbr_for_query("http://jabber.org/protocol/disco#info", + "" + "" + "" + "" + "" + "" + ); + + // Register ping response + stbbr_for_query("urn:xmpp:ping", + "" + ); + + prof_connect(); + + // Wait for disco exchange + sleep(2); + + // Set short autoping interval + prof_input("/autoping set 2"); + assert_true(prof_output_exact("Autoping interval set to 2 seconds.")); + + // Wait for autoping to trigger (interval + some buffer) + sleep(4); + + // Verify ping was sent (no 'to' attribute means server ping) + assert_true(stbbr_received( + "" + "" + "" + )); +} + +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", + "" + "" + "" + "" + "" + ); + + prof_connect(); + + // Wait for disco exchange + sleep(2); + + // Set short autoping interval + prof_input("/autoping set 2"); + assert_true(prof_output_exact("Autoping interval set to 2 seconds.")); + + // Wait for autoping to trigger + sleep(4); + + // Should show error about ping not being supported + assert_true(prof_output_regex("Server ping not supported")); +} diff --git a/tests/functionaltests/test_autoping.h b/tests/functionaltests/test_autoping.h new file mode 100644 index 00000000..9456a50d --- /dev/null +++ b/tests/functionaltests/test_autoping.h @@ -0,0 +1,6 @@ +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);