1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00
profanity/tests/unittests/test_chat_session.c

52 lines
1.3 KiB
C
Raw Normal View History

2015-01-06 16:22:09 -05:00
#include <stdarg.h>
#include <string.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <stdlib.h>
2016-07-24 09:23:55 -04:00
#include "xmpp/chat_session.h"
2015-01-06 16:22:09 -05:00
void returns_false_when_chat_session_does_not_exist(void **state)
{
2015-01-09 19:25:27 -05:00
ChatSession *session = chat_session_get("somejid@server.org");
assert_null(session);
2015-01-06 16:22:09 -05:00
}
2015-01-09 19:25:27 -05:00
void creates_chat_session_on_recipient_activity(void **state)
2015-01-06 16:22:09 -05:00
{
char *barejid = "myjid@server.org";
2015-01-09 19:25:27 -05:00
char *resource = "tablet";
2015-01-06 16:22:09 -05:00
2015-01-11 18:09:07 -05:00
chat_session_recipient_active(barejid, resource, FALSE);
2015-01-09 19:25:27 -05:00
ChatSession *session = chat_session_get(barejid);
2015-01-06 16:22:09 -05:00
2015-01-09 19:25:27 -05:00
assert_non_null(session);
assert_string_equal(session->resource, resource);
2015-01-06 16:22:09 -05:00
}
2015-01-09 19:25:27 -05:00
void replaces_chat_session_on_recipient_activity_with_different_resource(void **state)
2015-01-06 16:22:09 -05:00
{
char *barejid = "myjid@server.org";
2015-01-09 19:25:27 -05:00
char *resource1 = "tablet";
char *resource2 = "mobile";
2015-01-06 16:22:09 -05:00
2015-01-11 18:09:07 -05:00
chat_session_recipient_active(barejid, resource1, FALSE);
chat_session_recipient_active(barejid, resource2, FALSE);
2015-01-09 19:25:27 -05:00
ChatSession *session = chat_session_get(barejid);
2015-01-06 16:22:09 -05:00
2015-01-09 19:25:27 -05:00
assert_string_equal(session->resource, resource2);
2015-01-06 16:22:09 -05:00
}
2015-01-09 19:25:27 -05:00
void removes_chat_session(void **state)
2015-01-06 16:22:09 -05:00
{
char *barejid = "myjid@server.org";
2015-01-09 19:25:27 -05:00
char *resource1 = "laptop";
2015-01-06 16:22:09 -05:00
2015-01-11 18:09:07 -05:00
chat_session_recipient_active(barejid, resource1, FALSE);
2015-01-09 19:25:27 -05:00
chat_session_remove(barejid);
ChatSession *session = chat_session_get(barejid);
2015-01-06 16:22:09 -05:00
2015-01-09 19:25:27 -05:00
assert_null(session);
2016-07-24 09:23:55 -04:00
}