mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added chat session tests
This commit is contained in:
parent
8d759741e8
commit
f7843def2f
1
.gitignore
vendored
1
.gitignore
vendored
@ -62,3 +62,4 @@ profanity.mk
|
||||
profanity.project
|
||||
profanity.workspace
|
||||
m4/
|
||||
test.sh
|
||||
|
@ -88,6 +88,7 @@ tests_sources = \
|
||||
tests/test_roster_list.c tests/test_roster_list.h \
|
||||
tests/test_server_events.c tests/test_server_events.h \
|
||||
tests/test_autocomplete.c tests/test_autocomplete.h \
|
||||
tests/test_chat_session.c tests/test_chat_session.h \
|
||||
tests/testsuite.c
|
||||
|
||||
main_source = src/main.c
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "common.h"
|
||||
#include "helpers.h"
|
||||
#include "config/preferences.h"
|
||||
#include "chat_session.h"
|
||||
|
||||
void create_config_dir(void **state)
|
||||
{
|
||||
@ -72,6 +73,16 @@ void close_preferences(void **state)
|
||||
rmdir("./tests/files");
|
||||
}
|
||||
|
||||
void init_chat_sessions(void **state)
|
||||
{
|
||||
chat_sessions_init();
|
||||
}
|
||||
|
||||
void close_chat_sessions(void **state)
|
||||
{
|
||||
chat_sessions_clear();
|
||||
}
|
||||
|
||||
static GCompareFunc cmp_func;
|
||||
|
||||
void
|
||||
|
@ -3,5 +3,8 @@
|
||||
void load_preferences(void **state);
|
||||
void close_preferences(void **state);
|
||||
|
||||
void init_chat_sessions(void **state);
|
||||
void close_chat_sessions(void **state);
|
||||
|
||||
void glist_set_cmp(GCompareFunc func);
|
||||
int glist_contents_equal(const void *actual, const void *expected);
|
125
tests/test_chat_session.c
Normal file
125
tests/test_chat_session.c
Normal file
@ -0,0 +1,125 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "chat_session.h"
|
||||
|
||||
void returns_false_when_chat_session_does_not_exist(void **state)
|
||||
{
|
||||
gboolean result = chat_session_exists("somejid@server.org");
|
||||
assert_false(result);
|
||||
}
|
||||
|
||||
void creates_chat_session_on_message_send(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
gboolean exists = chat_session_exists(barejid);
|
||||
|
||||
assert_true(exists);
|
||||
}
|
||||
|
||||
void creates_chat_session_on_activity(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_activity(barejid);
|
||||
gboolean exists = chat_session_exists(barejid);
|
||||
|
||||
assert_true(exists);
|
||||
}
|
||||
|
||||
void returns_null_resource_for_new_session(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
char *resource = chat_session_get_resource(barejid);
|
||||
|
||||
assert_null(resource);
|
||||
}
|
||||
|
||||
void returns_true_send_states_for_new_session(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
gboolean send_states = chat_session_send_states(barejid);
|
||||
|
||||
assert_true(send_states);
|
||||
}
|
||||
|
||||
void sets_resource_on_incoming_message(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
char *expected_resource = "laptop";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
chat_session_on_incoming_message(barejid, expected_resource, FALSE);
|
||||
char *actual_resource = chat_session_get_resource(barejid);
|
||||
|
||||
assert_string_equal(expected_resource, actual_resource);
|
||||
}
|
||||
|
||||
void sets_send_states_on_incoming_message(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
chat_session_on_incoming_message(barejid, "resource", TRUE);
|
||||
gboolean send_states = chat_session_send_states(barejid);
|
||||
|
||||
assert_true(send_states);
|
||||
}
|
||||
|
||||
void replaces_chat_session_when_new_resource(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
char *first_resource = "laptop";
|
||||
char *second_resource = "mobile";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
chat_session_on_incoming_message(barejid, first_resource, TRUE);
|
||||
chat_session_on_incoming_message(barejid, second_resource, TRUE);
|
||||
char *actual_resource = chat_session_get_resource(barejid);
|
||||
|
||||
assert_string_equal(second_resource, actual_resource);
|
||||
}
|
||||
|
||||
void removes_chat_session_on_window_close(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
chat_session_on_window_close(barejid);
|
||||
gboolean exists = chat_session_exists(barejid);
|
||||
|
||||
assert_false(exists);
|
||||
}
|
||||
|
||||
void removes_chat_session_on_cancel_for_barejid(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
chat_session_on_cancel(barejid);
|
||||
gboolean exists = chat_session_exists(barejid);
|
||||
|
||||
assert_false(exists);
|
||||
}
|
||||
|
||||
void removes_chat_session_on_cancel_for_fulljid(void **state)
|
||||
{
|
||||
char *barejid = "myjid@server.org";
|
||||
char *fulljid = "myjid@server.org/desktop";
|
||||
|
||||
chat_session_on_message_send(barejid);
|
||||
chat_session_on_cancel(fulljid);
|
||||
gboolean exists = chat_session_exists(barejid);
|
||||
|
||||
assert_false(exists);
|
||||
}
|
11
tests/test_chat_session.h
Normal file
11
tests/test_chat_session.h
Normal file
@ -0,0 +1,11 @@
|
||||
void returns_false_when_chat_session_does_not_exist(void **state);
|
||||
void creates_chat_session_on_message_send(void **state);
|
||||
void creates_chat_session_on_activity(void **state);
|
||||
void returns_null_resource_for_new_session(void **state);
|
||||
void returns_true_send_states_for_new_session(void **state);
|
||||
void sets_resource_on_incoming_message(void **state);
|
||||
void sets_send_states_on_incoming_message(void **state);
|
||||
void replaces_chat_session_when_new_resource(void **state);
|
||||
void removes_chat_session_on_window_close(void **state);
|
||||
void removes_chat_session_on_cancel_for_barejid(void **state);
|
||||
void removes_chat_session_on_cancel_for_fulljid(void **state);
|
@ -8,9 +8,11 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "chat_session.h"
|
||||
|
||||
#include "helpers.h"
|
||||
#include "test_autocomplete.h"
|
||||
#include "test_chat_session.h"
|
||||
#include "test_common.h"
|
||||
#include "test_contact.h"
|
||||
#include "test_cmd_connect.h"
|
||||
@ -204,6 +206,40 @@ int main(int argc, char* argv[]) {
|
||||
unit_test(find_five_times_finds_fifth),
|
||||
unit_test(find_twice_returns_first_when_two_match_and_reset),
|
||||
|
||||
unit_test_setup_teardown(returns_false_when_chat_session_does_not_exist,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(creates_chat_session_on_message_send,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(creates_chat_session_on_activity,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(returns_null_resource_for_new_session,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(returns_true_send_states_for_new_session,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(sets_resource_on_incoming_message,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(sets_send_states_on_incoming_message,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(replaces_chat_session_when_new_resource,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(removes_chat_session_on_window_close,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(removes_chat_session_on_cancel_for_barejid,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
unit_test_setup_teardown(removes_chat_session_on_cancel_for_fulljid,
|
||||
init_chat_sessions,
|
||||
close_chat_sessions),
|
||||
|
||||
unit_test_setup_teardown(cmd_connect_shows_message_when_disconnecting,
|
||||
load_preferences,
|
||||
close_preferences),
|
||||
|
Loading…
Reference in New Issue
Block a user