#include #include "prof_cmocka.h" #include #include #include #include #include "proftest.h" void ping_server(void **state) { /* * This test verifies that profanity correctly handles the /ping command * when the server supports ping (urn:xmpp:ping feature). * * We register disco#info response with ping support, then verify * profanity sends ping and receives "Pinged server" confirmation. */ // Register disco#info response that includes 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#info exchange to complete. * TODO: Replace with proper wait mechanism (e.g., wait for capabilities * to be cached). Currently we use sleep to ensure disco#info response * is processed before sending /ping command. */ sleep(3); prof_input("/ping"); prof_timeout(10); assert_true(prof_output_regex("Pinged server")); prof_timeout_reset(); } void ping_server_not_supported(void **state) { stbbr_for_query("http://jabber.org/protocol/disco#info", "" "" "" "" "" ); prof_connect(); prof_input("/ping"); assert_true(prof_output_regex("Server does not support ping requests")); } void ping_responds_to_server_request(void **state) { prof_connect(); stbbr_send( "" "" "" ); assert_true(stbbr_received( "" )); } void ping_jid(void **state) { // Caps/disco info response without relying on a fixed id stbbr_for_query("http://jabber.org/protocol/disco#info", "" "" "" "" "" "" "" "" ); prof_connect(); stbbr_send( "" "10" "I'm here" "" "" ); assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\"")); assert_true(stbbr_received( "" "" "" )); // Respond to ping result regardless of id stbbr_for_query("urn:xmpp:ping", "" ); prof_input("/ping buddy1@localhost/mobile"); assert_true(stbbr_received( "" "" "" )); assert_true(prof_output_regex("Ping response from buddy1@localhost/mobile")); } void ping_jid_not_supported(void **state) { stbbr_for_query("http://jabber.org/protocol/disco#info", "" "" "" "" "" "" "" ); prof_connect(); stbbr_send( "" "10" "I'm here" "" "" ); assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\"")); assert_true(stbbr_received( "" "" "" )); prof_input("/ping buddy1@localhost/mobile"); assert_true(prof_output_exact("buddy1@localhost/mobile does not support ping requests.")); }