mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-20 20:16:21 +00:00
Use a behavior-driven naming convention for unit tests. Functions are now named using the pattern: [unit]__[verb]__[scenario] The __ works as a semantic separator. Examples: * jid_create__returns__null_from_null() * cmd_connect__shows__usage_when_no_server_value Benefits: * Easy to find all tests associated with a specific function using the mandatory prefix. * Test output in CI now explicitly describes the unit, the expected outcome, and the scenario being tested. Also disabled keyhandlers tests due to missing code in src/ui.
119 lines
3.7 KiB
C
119 lines
3.7 KiB
C
#include "prof_cmocka.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <glib.h>
|
|
|
|
#include "event/server_events.h"
|
|
#include "xmpp/xmpp.h"
|
|
#include "xmpp/roster_list.h"
|
|
#include "xmpp/chat_session.h"
|
|
#include "config/preferences.h"
|
|
#include "ui/ui.h"
|
|
#include "ui/stub_ui.h"
|
|
#include "xmpp/muc.h"
|
|
#include "plugins/plugins.h"
|
|
#include "ui/window_list.h"
|
|
|
|
void
|
|
sv_ev_contact_online__shows__presence_in_console_when_set_online(void** state)
|
|
{
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, "online");
|
|
plugins_init();
|
|
roster_create();
|
|
roster_process_pending_presence();
|
|
char* barejid = "test1@server";
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
|
Resource* resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
|
|
|
|
expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
|
|
expect_memory(ui_contact_online, resource, resource, sizeof(resource));
|
|
expect_value(ui_contact_online, last_activity, NULL);
|
|
|
|
sv_ev_contact_online(barejid, resource, NULL, NULL);
|
|
|
|
roster_destroy();
|
|
}
|
|
|
|
void
|
|
sv_ev_contact_online__shows__presence_in_console_when_set_all(void** state)
|
|
{
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, "all");
|
|
plugins_init();
|
|
roster_create();
|
|
roster_process_pending_presence();
|
|
char* barejid = "test1@server";
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
|
Resource* resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
|
|
|
|
expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
|
|
expect_memory(ui_contact_online, resource, resource, sizeof(resource));
|
|
expect_value(ui_contact_online, last_activity, NULL);
|
|
|
|
sv_ev_contact_online(barejid, resource, NULL, NULL);
|
|
|
|
roster_destroy();
|
|
}
|
|
|
|
void
|
|
sv_ev_contact_online__shows__dnd_presence_in_console_when_set_all(void** state)
|
|
{
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, "all");
|
|
plugins_init();
|
|
roster_create();
|
|
roster_process_pending_presence();
|
|
char* barejid = "test1@server";
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
|
Resource* resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
|
|
|
|
expect_memory(ui_contact_online, barejid, barejid, sizeof(barejid));
|
|
expect_memory(ui_contact_online, resource, resource, sizeof(resource));
|
|
expect_value(ui_contact_online, last_activity, NULL);
|
|
|
|
sv_ev_contact_online(barejid, resource, NULL, NULL);
|
|
|
|
roster_destroy();
|
|
}
|
|
|
|
void
|
|
sv_ev_contact_offline__updates__removes_chat_session(void** state)
|
|
{
|
|
plugins_init();
|
|
roster_create();
|
|
roster_process_pending_presence();
|
|
chat_sessions_init();
|
|
char* barejid = "friend@server.chat.com";
|
|
char* resource = "home";
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
|
Resource* resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
|
|
roster_update_presence(barejid, resourcep, NULL);
|
|
chat_session_recipient_active(barejid, resource, FALSE);
|
|
ProfConsoleWin* console = g_new0(ProfConsoleWin, 1);
|
|
will_return(win_create_console, &console->window);
|
|
wins_init();
|
|
sv_ev_contact_offline(barejid, resource, NULL);
|
|
ChatSession* session = chat_session_get(barejid);
|
|
|
|
assert_null(session);
|
|
|
|
roster_destroy();
|
|
chat_sessions_clear();
|
|
}
|
|
|
|
void
|
|
sv_ev_lost_connection__updates__clears_chat_sessions(void** state)
|
|
{
|
|
roster_create();
|
|
roster_process_pending_presence();
|
|
chat_sessions_init();
|
|
chat_session_recipient_active("bob@server.org", "laptop", FALSE);
|
|
chat_session_recipient_active("steve@server.org", "mobile", FALSE);
|
|
expect_any_cons_show_error();
|
|
|
|
sv_ev_lost_connection();
|
|
|
|
ChatSession* session1 = chat_session_get("bob@server.org");
|
|
ChatSession* session2 = chat_session_get("steve@server.org");
|
|
assert_null(session1);
|
|
assert_null(session2);
|
|
}
|