All checks were successful
CI Code / Check spelling (pull_request) Successful in 19s
CI Code / Check coding style (pull_request) Successful in 34s
CI Code / Linux (ubuntu) (pull_request) Successful in 30m9s
CI Code / Linux (arch) (pull_request) Successful in 33m47s
CI Code / Linux (debian) (pull_request) Successful in 33m9s
217 lines
8.4 KiB
C
217 lines
8.4 KiB
C
/*
|
|
* functionaltests.c
|
|
*
|
|
* Functional tests for CProof XMPP client.
|
|
* Uses cmocka framework with stabber mock XMPP server.
|
|
*
|
|
* Each test is wrapped with PROF_FUNC_TEST macro which sets up
|
|
* init_prof_test (starts stabber server and profanity client)
|
|
* and close_prof_test (cleanup) as setup/teardown functions.
|
|
*
|
|
* NOTE: We restart client and server for each test to ensure complete
|
|
* isolation. This prevents state leakage between tests (roster entries,
|
|
* MUC rooms, presence subscriptions, etc.). While slower, it eliminates
|
|
* flaky tests caused by leftover state. The overhead is acceptable since
|
|
* 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 (17 tests)
|
|
* Group 2: Message, Receipts, Roster, Chat Session (17 tests)
|
|
* Group 3: Presence (16 tests)
|
|
* Group 4: MUC, Carbons (19 tests)
|
|
*
|
|
* Parallel execution:
|
|
* ./functionaltests - run all tests sequentially
|
|
* ./functionaltests 1 - run group 1 only
|
|
* ./functionaltests 2 - run group 2 only
|
|
* ./functionaltests 3 - run group 3 only
|
|
* ./functionaltests 4 - run group 4 only
|
|
*
|
|
* For parallel execution, run multiple groups simultaneously:
|
|
* ./functionaltests 1 & ./functionaltests 2 & ./functionaltests 3 & ./functionaltests 4 & wait
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include "prof_cmocka.h"
|
|
#include <sys/stat.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "proftest.h"
|
|
#include "test_connect.h"
|
|
#include "test_ping.h"
|
|
#include "test_rooms.h"
|
|
#include "test_presence.h"
|
|
#include "test_message.h"
|
|
#include "test_carbons.h"
|
|
#include "test_chat_session.h"
|
|
#include "test_receipts.h"
|
|
#include "test_roster.h"
|
|
#include "test_software.h"
|
|
#include "test_muc.h"
|
|
#include "test_disconnect.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)
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
int group = 0; /* 0 = all groups */
|
|
if (argc > 1) {
|
|
group = atoi(argv[1]);
|
|
if (group < 1 || group > 4) {
|
|
fprintf(stderr, "Usage: %s [group]\n", argv[0]);
|
|
fprintf(stderr, " group: 1-4 to run specific group, or omit for all\n");
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
/* GROUP 1: Connect, Ping, Rooms, Software (17 tests)
|
|
* Basic XMPP session establishment and server queries */
|
|
|
|
/* Connection tests - verify login, roster, bookmarks */
|
|
const struct CMUnitTest group1_tests[] = {
|
|
PROF_FUNC_TEST(connect_jid_requests_roster),
|
|
PROF_FUNC_TEST(connect_jid_sends_presence_after_receiving_roster),
|
|
PROF_FUNC_TEST(connect_jid_requests_bookmarks),
|
|
PROF_FUNC_TEST(connect_bad_password),
|
|
PROF_FUNC_TEST(connect_shows_presence_updates),
|
|
|
|
/* Ping tests - XEP-0199 XMPP Ping */
|
|
PROF_FUNC_TEST(ping_server),
|
|
PROF_FUNC_TEST(ping_server_not_supported),
|
|
PROF_FUNC_TEST(ping_responds_to_server_request),
|
|
PROF_FUNC_TEST(ping_jid),
|
|
PROF_FUNC_TEST(ping_jid_not_supported),
|
|
|
|
/* Room discovery - XEP-0045 */
|
|
PROF_FUNC_TEST(rooms_query),
|
|
|
|
/* Software Version - XEP-0092 */
|
|
PROF_FUNC_TEST(send_software_version_request),
|
|
PROF_FUNC_TEST(display_software_version_result),
|
|
PROF_FUNC_TEST(shows_message_when_software_version_error),
|
|
PROF_FUNC_TEST(display_software_version_result_when_from_domainpart),
|
|
PROF_FUNC_TEST(show_message_in_chat_window_when_no_resource),
|
|
PROF_FUNC_TEST(display_software_version_result_in_chat),
|
|
};
|
|
|
|
/* GROUP 2: Message, Receipts, Roster, Chat Session (17 tests)
|
|
* Core messaging and contact management */
|
|
const struct CMUnitTest group2_tests[] = {
|
|
|
|
/* Basic message send/receive */
|
|
PROF_FUNC_TEST(message_send),
|
|
PROF_FUNC_TEST(message_receive_console),
|
|
PROF_FUNC_TEST(message_receive_chatwin),
|
|
|
|
/* Message receipts - XEP-0184 */
|
|
PROF_FUNC_TEST(does_not_send_receipt_request_to_barejid),
|
|
PROF_FUNC_TEST(send_receipt_request),
|
|
PROF_FUNC_TEST(send_receipt_on_request),
|
|
|
|
/* Roster management - add/remove/rename contacts */
|
|
PROF_FUNC_TEST(sends_new_item),
|
|
PROF_FUNC_TEST(sends_new_item_nick),
|
|
PROF_FUNC_TEST(sends_remove_item),
|
|
PROF_FUNC_TEST(sends_remove_item_nick),
|
|
PROF_FUNC_TEST(sends_nick_change),
|
|
|
|
/* 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),
|
|
PROF_FUNC_TEST(sends_message_to_fulljid_when_received_from_fulljid),
|
|
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 (16 tests)
|
|
* Online/away/xa/dnd/chat status management */
|
|
const struct CMUnitTest group3_tests[] = {
|
|
PROF_FUNC_TEST(presence_online),
|
|
PROF_FUNC_TEST(presence_online_with_message),
|
|
PROF_FUNC_TEST(presence_away),
|
|
PROF_FUNC_TEST(presence_away_with_message),
|
|
PROF_FUNC_TEST(presence_xa),
|
|
PROF_FUNC_TEST(presence_xa_with_message),
|
|
PROF_FUNC_TEST(presence_dnd),
|
|
PROF_FUNC_TEST(presence_dnd_with_message),
|
|
PROF_FUNC_TEST(presence_chat),
|
|
PROF_FUNC_TEST(presence_chat_with_message),
|
|
PROF_FUNC_TEST(presence_set_priority),
|
|
PROF_FUNC_TEST(presence_includes_priority),
|
|
PROF_FUNC_TEST(presence_keeps_status),
|
|
PROF_FUNC_TEST(presence_received),
|
|
PROF_FUNC_TEST(presence_missing_resource_defaults),
|
|
|
|
/* Disconnect - clean session termination */
|
|
PROF_FUNC_TEST(disconnect_ends_session),
|
|
};
|
|
|
|
/* GROUP 4: MUC, Carbons (19 tests)
|
|
* Multi-user chat and message synchronization */
|
|
const struct CMUnitTest group4_tests[] = {
|
|
|
|
/* MUC room join with various options - XEP-0045 */
|
|
PROF_FUNC_TEST(sends_room_join),
|
|
PROF_FUNC_TEST(sends_room_join_with_nick),
|
|
PROF_FUNC_TEST(sends_room_join_with_password),
|
|
PROF_FUNC_TEST(sends_room_join_with_nick_and_password),
|
|
|
|
/* MUC room information display */
|
|
PROF_FUNC_TEST(shows_role_and_affiliation_on_join),
|
|
PROF_FUNC_TEST(shows_subject_on_join),
|
|
PROF_FUNC_TEST(shows_occupant_join),
|
|
|
|
/* MUC messaging */
|
|
PROF_FUNC_TEST(shows_message),
|
|
PROF_FUNC_TEST(shows_me_message_from_occupant),
|
|
PROF_FUNC_TEST(shows_me_message_from_self),
|
|
|
|
/* MUC console notification settings */
|
|
PROF_FUNC_TEST(shows_all_messages_in_console_when_window_not_focussed),
|
|
PROF_FUNC_TEST(shows_first_message_in_console_when_window_not_focussed),
|
|
PROF_FUNC_TEST(shows_no_message_in_console_when_window_not_focussed),
|
|
|
|
/* Message Carbons - XEP-0280 (message sync across devices) */
|
|
PROF_FUNC_TEST(send_enable_carbons),
|
|
PROF_FUNC_TEST(connect_with_carbons_enabled),
|
|
PROF_FUNC_TEST(send_disable_carbons),
|
|
PROF_FUNC_TEST(receive_carbon),
|
|
PROF_FUNC_TEST(receive_self_carbon),
|
|
PROF_FUNC_TEST(receive_private_carbon),
|
|
};
|
|
|
|
int result = 0;
|
|
|
|
switch (group) {
|
|
case 1:
|
|
result = cmocka_run_group_tests_name("Group 1: Connect/Ping/Rooms/Software", group1_tests, NULL, NULL);
|
|
break;
|
|
case 2:
|
|
result = cmocka_run_group_tests_name("Group 2: Message/Receipts/Roster/Session", group2_tests, NULL, NULL);
|
|
break;
|
|
case 3:
|
|
result = cmocka_run_group_tests_name("Group 3: Presence", group3_tests, NULL, NULL);
|
|
break;
|
|
case 4:
|
|
result = cmocka_run_group_tests_name("Group 4: MUC/Carbons", group4_tests, NULL, NULL);
|
|
break;
|
|
default:
|
|
/* Run all groups sequentially */
|
|
result |= cmocka_run_group_tests_name("Group 1: Connect/Ping/Rooms/Software", group1_tests, NULL, NULL);
|
|
result |= cmocka_run_group_tests_name("Group 2: Message/Receipts/Roster/Session", group2_tests, NULL, NULL);
|
|
result |= cmocka_run_group_tests_name("Group 3: Presence", group3_tests, NULL, NULL);
|
|
result |= cmocka_run_group_tests_name("Group 4: MUC/Carbons", group4_tests, NULL, NULL);
|
|
break;
|
|
}
|
|
|
|
return result;
|
|
}
|