Files
cproof/tests/functionaltests/test_ping.c
jabber.developer2 8e8d715734
Some checks failed
CI Code / Check spelling (pull_request) Successful in 21s
CI Code / Check coding style (pull_request) Successful in 37s
CI Code / Linux (arch) (pull_request) Failing after 22m22s
CI Code / Linux (debian) (pull_request) Successful in 1h8m49s
CI Code / Linux (ubuntu) (pull_request) Failing after 25m28s
refactor(tests): improve functional test documentation and cleanup
- Add detailed documentation about test isolation in functionaltests.c
- Improve comments in proftest.c: buffer size explanation, stabber sync TODO
- Add reference to stabber issue #1 for stbbr_wait_stopped() API
- Document prof_output_regex() usage rationale in test_muc.c
- Enhance ping_server test comments for clarity
- Update CONTRIBUTING.md: fix function names (prof_output_regex, prof_timeout)
- Remove redundant commented-out test configurations from ci-build.sh
- Remove obsolete stabber recv suppressions from prof.supp (issue fixed)
- Add clear explanation for disabled assertion in test_chat_session.c
- Add comment explaining /connect max args in cmd_defs.c
2026-01-05 18:29:41 +03:00

175 lines
5.8 KiB
C

#include <glib.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stabber.h>
#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",
"<iq to='stabber@localhost/profanity' type='result' from='localhost'>"
"<query xmlns='http://jabber.org/protocol/disco#info'>"
"<identity category='server' type='im' name='Prosody'/>"
"<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();
/*
* 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",
"<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();
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(
"<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
"<ping xmlns=\"urn:xmpp:ping\"/>"
"</iq>"
);
assert_true(stbbr_received(
"<iq id='pingtest1' type='result' from='stabber@localhost/profanity' to='localhost'></iq>"
));
}
void ping_jid(void **state)
{
// Caps/disco info response without relying on a fixed id
stbbr_for_query("http://jabber.org/protocol/disco#info",
"<iq to='stabber@localhost/profanity' type='result' from='buddy1@localhost/mobile'>"
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='>"
"<identity category='client' type='console' name='Profanity0.6.0'/>"
"<feature var='urn:xmpp:ping'/>"
"<feature var='http://jabber.org/protocol/disco#info'/>"
"<feature var='http://jabber.org/protocol/caps'/>"
"</query>"
"</iq>"
);
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"<status>I'm here</status>"
"<c "
"hash='sha-1' "
"xmlns='http://jabber.org/protocol/caps' "
"node='http://profanity-im.github.io' "
"ver='LpT2xs3nun7jC2sq4gg3WRDQFZ4='"
"/>"
"</presence>"
);
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
assert_true(stbbr_received(
"<iq id='*' to='buddy1@localhost/mobile' type='get'>"
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='/>"
"</iq>"
));
// Respond to ping result regardless of id
stbbr_for_query("urn:xmpp:ping",
"<iq from='buddy1@localhost/mobile' to='stabber@localhost' type='result'/>"
);
prof_input("/ping buddy1@localhost/mobile");
assert_true(stbbr_received(
"<iq id='*' type='get' to='buddy1@localhost/mobile'>"
"<ping xmlns='urn:xmpp:ping'/>"
"</iq>"
));
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",
"<iq to='stabber@localhost/profanity' type='result' from='buddy1@localhost/mobile'>"
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='>"
"<identity category='client' type='console' name='Profanity0.6.0'/>"
"<feature var='http://jabber.org/protocol/disco#info'/>"
"<feature var='http://jabber.org/protocol/caps'/>"
"</query>"
"</iq>"
);
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"<status>I'm here</status>"
"<c "
"hash='sha-1' "
"xmlns='http://jabber.org/protocol/caps' "
"node='http://profanity-im.github.io' "
"ver='LpT2xs3nun7jC2sq4gg3WRDQFZ4='"
"/>"
"</presence>"
);
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
assert_true(stbbr_received(
"<iq id='*' to='buddy1@localhost/mobile' type='get'>"
"<query xmlns='http://jabber.org/protocol/disco#info' node='http://profanity-im.github.io#LpT2xs3nun7jC2sq4gg3WRDQFZ4='/>"
"</iq>"
));
prof_input("/ping buddy1@localhost/mobile");
assert_true(prof_output_exact("buddy1@localhost/mobile does not support ping requests."));
}