tests: Apply coding style to unit tests

This commit is contained in:
Michael Vetter
2026-02-28 13:46:23 +01:00
parent 174848499d
commit 80e36bd1e2
35 changed files with 735 additions and 827 deletions

View File

@@ -9,7 +9,7 @@
#include "proftest.h"
void
presence_online(void **state)
presence_online(void** state)
{
prof_connect();
@@ -17,15 +17,14 @@ presence_online(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_3'>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to online (priority 0)"));
}
void
presence_online_with_message(void **state)
presence_online_with_message(void** state)
{
prof_connect();
@@ -33,16 +32,15 @@ presence_online_with_message(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<status>Hi there</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<status>Hi there</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to online (priority 0), \"Hi there\"."));
}
void
presence_away(void **state)
presence_away(void** state)
{
prof_connect();
@@ -50,16 +48,15 @@ presence_away(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>away</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>away</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to away (priority 0)"));
}
void
presence_away_with_message(void **state)
presence_away_with_message(void** state)
{
prof_connect();
@@ -67,17 +64,16 @@ presence_away_with_message(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>away</show>"
"<status>I'm not here for a bit</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>away</show>"
"<status>I'm not here for a bit</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to away (priority 0), \"I'm not here for a bit\"."));
}
void
presence_xa(void **state)
presence_xa(void** state)
{
prof_connect();
@@ -85,16 +81,15 @@ presence_xa(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>xa</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>xa</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to xa (priority 0)"));
}
void
presence_xa_with_message(void **state)
presence_xa_with_message(void** state)
{
prof_connect();
@@ -102,17 +97,16 @@ presence_xa_with_message(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>xa</show>"
"<status>Gone to the shops</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>xa</show>"
"<status>Gone to the shops</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to xa (priority 0), \"Gone to the shops\"."));
}
void
presence_dnd(void **state)
presence_dnd(void** state)
{
prof_connect();
@@ -120,16 +114,15 @@ presence_dnd(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>dnd</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>dnd</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to dnd (priority 0)"));
}
void
presence_dnd_with_message(void **state)
presence_dnd_with_message(void** state)
{
prof_connect();
@@ -137,17 +130,16 @@ presence_dnd_with_message(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>dnd</show>"
"<status>Working</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>dnd</show>"
"<status>Working</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to dnd (priority 0), \"Working\"."));
}
void
presence_chat(void **state)
presence_chat(void** state)
{
prof_connect();
@@ -155,16 +147,15 @@ presence_chat(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>chat</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>chat</show>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to chat (priority 0)"));
}
void
presence_chat_with_message(void **state)
presence_chat_with_message(void** state)
{
prof_connect();
@@ -172,17 +163,16 @@ presence_chat_with_message(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\"."));
}
void
presence_set_priority(void **state)
presence_set_priority(void** state)
{
prof_connect();
@@ -190,94 +180,87 @@ presence_set_priority(void **state)
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Priority set to 25."));
}
void
presence_includes_priority(void **state)
presence_includes_priority(void** state)
{
prof_connect();
prof_input("/priority 25");
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Priority set to 25."));
prof_input("/chat \"Free to talk\"");
assert_true(stbbr_received(
"<presence id='prof_presence_5'>"
"<priority>25</priority>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<priority>25</priority>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to chat (priority 25), \"Free to talk\"."));
}
void
presence_keeps_status(void **state)
presence_keeps_status(void** state)
{
prof_connect();
prof_input("/chat \"Free to talk\"");
assert_true(stbbr_received(
"<presence id='prof_presence_4'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>chat</show>"
"<status>Free to talk</status>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Status set to chat (priority 0), \"Free to talk\"."));
prof_input("/priority 25");
assert_true(stbbr_received(
"<presence id='prof_presence_5'>"
"<show>chat</show>"
"<status>Free to talk</status>"
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"
));
"<show>chat</show>"
"<status>Free to talk</status>"
"<priority>25</priority>"
"<c hash='sha-1' xmlns='http://jabber.org/protocol/caps' ver='*' node='http://profanity-im.github.io'/>"
"</presence>"));
assert_true(prof_output_exact("Priority set to 25."));
}
void
presence_received(void **state)
presence_received(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost/mobile'>"
"<priority>10</priority>"
"<status>I'm here</status>"
"</presence>"
);
"<priority>10</priority>"
"<status>I'm here</status>"
"</presence>");
assert_true(prof_output_exact("Buddy1 (mobile) is online, \"I'm here\""));
}
// Typical use case for gateways that don't support resources
void
presence_missing_resource_defaults(void **state)
presence_missing_resource_defaults(void** state)
{
prof_connect();
stbbr_send(
"<presence to='stabber@localhost' from='buddy1@localhost'>"
"<priority>15</priority>"
"<status>My status</status>"
"</presence>"
);
"<priority>15</priority>"
"<status>My status</status>"
"</presence>");
assert_true(prof_output_exact("Buddy1 is online, \"My status\""));