2014-01-20 13:40:48 -05:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
2014-01-20 13:40:48 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2020-07-07 07:53:30 -04:00
|
|
|
#include <glib.h>
|
2014-01-20 13:40:48 -05:00
|
|
|
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "event/server_events.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "xmpp/xmpp.h"
|
|
|
|
#include "xmpp/roster_list.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "xmpp/chat_session.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "config/preferences.h"
|
|
|
|
#include "ui/ui.h"
|
|
|
|
#include "ui/stub_ui.h"
|
2020-07-07 03:43:28 -04:00
|
|
|
#include "xmpp/muc.h"
|
2020-07-07 07:53:30 -04:00
|
|
|
#include "plugins/plugins.h"
|
|
|
|
#include "ui/window_list.h"
|
2014-01-20 13:40:48 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
console_shows_online_presence_when_set_online(void** state)
|
2014-01-20 13:40:48 -05:00
|
|
|
{
|
|
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, "online");
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_init();
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2019-04-16 23:20:11 -04:00
|
|
|
roster_process_pending_presence();
|
2020-07-07 08:18:57 -04:00
|
|
|
char* barejid = "test1@server";
|
2015-05-07 17:05:36 -04:00
|
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
2020-07-07 08:18:57 -04:00
|
|
|
Resource* resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
|
2014-01-20 13:40:48 -05:00
|
|
|
|
2015-05-07 17:05:36 -04:00
|
|
|
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);
|
2014-01-20 19:16:37 -05:00
|
|
|
|
2015-05-07 17:22:28 -04:00
|
|
|
sv_ev_contact_online(barejid, resource, NULL, NULL);
|
2014-01-20 19:16:37 -05:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_shutdown();
|
2014-01-20 13:40:48 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
console_shows_online_presence_when_set_all(void** state)
|
2014-01-20 13:40:48 -05:00
|
|
|
{
|
|
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, "all");
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_init();
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2019-04-16 23:20:11 -04:00
|
|
|
roster_process_pending_presence();
|
2020-07-07 08:18:57 -04:00
|
|
|
char* barejid = "test1@server";
|
2015-05-07 17:05:36 -04:00
|
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
2020-07-07 08:18:57 -04:00
|
|
|
Resource* resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
|
2014-01-20 19:16:37 -05:00
|
|
|
|
2015-05-07 17:05:36 -04:00
|
|
|
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);
|
2014-01-20 19:16:37 -05:00
|
|
|
|
2015-05-07 17:22:28 -04:00
|
|
|
sv_ev_contact_online(barejid, resource, NULL, NULL);
|
2014-01-20 13:40:48 -05:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_shutdown();
|
2014-01-20 13:40:48 -05:00
|
|
|
}
|
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
console_shows_dnd_presence_when_set_all(void** state)
|
2014-01-20 13:40:48 -05:00
|
|
|
{
|
|
|
|
prefs_set_string(PREF_STATUSES_CONSOLE, "all");
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_init();
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2019-04-16 23:20:11 -04:00
|
|
|
roster_process_pending_presence();
|
2020-07-07 08:18:57 -04:00
|
|
|
char* barejid = "test1@server";
|
2015-05-07 17:05:36 -04:00
|
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
2020-07-07 08:18:57 -04:00
|
|
|
Resource* resource = resource_new("resource", RESOURCE_ONLINE, NULL, 10);
|
2014-01-20 13:40:48 -05:00
|
|
|
|
2015-05-07 17:05:36 -04:00
|
|
|
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);
|
2014-01-20 19:16:37 -05:00
|
|
|
|
2015-05-07 17:22:28 -04:00
|
|
|
sv_ev_contact_online(barejid, resource, NULL, NULL);
|
2014-01-20 19:16:37 -05:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_shutdown();
|
2014-01-20 13:40:48 -05:00
|
|
|
}
|
2014-01-28 17:37:50 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
handle_offline_removes_chat_session(void** state)
|
2015-01-06 18:19:56 -05:00
|
|
|
{
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_init();
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2019-04-16 23:20:11 -04:00
|
|
|
roster_process_pending_presence();
|
2015-01-06 18:19:56 -05:00
|
|
|
chat_sessions_init();
|
2020-07-07 08:18:57 -04:00
|
|
|
char* barejid = "friend@server.chat.com";
|
|
|
|
char* resource = "home";
|
2015-01-06 18:19:56 -05:00
|
|
|
roster_add(barejid, "bob", NULL, "both", FALSE);
|
2020-07-07 08:18:57 -04:00
|
|
|
Resource* resourcep = resource_new(resource, RESOURCE_ONLINE, NULL, 10);
|
2015-01-06 18:19:56 -05:00
|
|
|
roster_update_presence(barejid, resourcep, NULL);
|
2015-01-11 18:09:07 -05:00
|
|
|
chat_session_recipient_active(barejid, resource, FALSE);
|
2020-07-07 08:18:57 -04:00
|
|
|
ProfConsoleWin* console = malloc(sizeof(ProfConsoleWin));
|
2016-01-04 19:06:50 -05:00
|
|
|
will_return(win_create_console, &console->window);
|
|
|
|
wins_init();
|
2015-04-28 18:38:56 -04:00
|
|
|
sv_ev_contact_offline(barejid, resource, NULL);
|
2020-07-07 08:18:57 -04:00
|
|
|
ChatSession* session = chat_session_get(barejid);
|
2015-01-06 18:19:56 -05:00
|
|
|
|
2015-01-09 19:25:27 -05:00
|
|
|
assert_null(session);
|
2015-01-06 18:19:56 -05:00
|
|
|
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_destroy();
|
2015-01-06 18:19:56 -05:00
|
|
|
chat_sessions_clear();
|
2016-09-25 18:30:44 -04:00
|
|
|
plugins_shutdown();
|
2015-01-06 18:19:56 -05:00
|
|
|
}
|
2015-01-09 20:17:38 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
void
|
|
|
|
lost_connection_clears_chat_sessions(void** state)
|
2015-01-09 20:17:38 -05:00
|
|
|
{
|
2016-01-04 19:06:50 -05:00
|
|
|
roster_create();
|
2019-04-16 23:20:11 -04:00
|
|
|
roster_process_pending_presence();
|
2015-01-09 20:17:38 -05:00
|
|
|
chat_sessions_init();
|
2015-01-11 18:09:07 -05:00
|
|
|
chat_session_recipient_active("bob@server.org", "laptop", FALSE);
|
|
|
|
chat_session_recipient_active("steve@server.org", "mobile", FALSE);
|
2015-01-09 20:17:38 -05:00
|
|
|
expect_any_cons_show_error();
|
|
|
|
|
2015-04-28 18:38:56 -04:00
|
|
|
sv_ev_lost_connection();
|
2015-01-09 20:17:38 -05:00
|
|
|
|
2020-07-07 08:18:57 -04:00
|
|
|
ChatSession* session1 = chat_session_get("bob@server.org");
|
|
|
|
ChatSession* session2 = chat_session_get("steve@server.org");
|
2015-01-09 20:17:38 -05:00
|
|
|
assert_null(session1);
|
|
|
|
assert_null(session2);
|
|
|
|
}
|