From 63b3299b069a276994508859e4a8b6500f47df2e Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Jan 2014 23:32:52 +0000 Subject: [PATCH 1/5] Added muc tests --- Makefile.am | 1 + tests/test_muc.c | 18 ++++++++++++++++++ tests/test_muc.h | 1 + tests/testsuite.c | 6 ++++++ 4 files changed, 26 insertions(+) create mode 100644 tests/test_muc.c create mode 100644 tests/test_muc.h diff --git a/Makefile.am b/Makefile.am index 5d5e3fba..802340e0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -85,6 +85,7 @@ test_sources = \ tests/test_roster_list.c \ tests/test_preferences.c \ tests/test_server_events.c \ + tests/test_muc.c \ tests/testsuite.c main_source = src/main.c diff --git a/tests/test_muc.c b/tests/test_muc.c new file mode 100644 index 00000000..42a27931 --- /dev/null +++ b/tests/test_muc.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include + +#include "muc.h" + +void test_muc_add_invite(void **state) +{ + char *room = "room@conf.server"; + muc_init(); + muc_add_invite(room); + + gboolean invite_exists = muc_invites_include(room); + + assert_true(invite_exists); +} diff --git a/tests/test_muc.h b/tests/test_muc.h new file mode 100644 index 00000000..8efff108 --- /dev/null +++ b/tests/test_muc.h @@ -0,0 +1 @@ +void test_muc_add_invite(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 2f940af1..5120bcf2 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -23,6 +23,7 @@ #include "test_preferences.h" #include "test_server_events.h" #include "test_cmd_alias.h" +#include "test_muc.h" #define PROF_RUN_TESTS(name) fprintf(stderr, "\n-> Running %s\n", #name); \ fflush(stderr); \ @@ -427,6 +428,10 @@ int main(int argc, char* argv[]) { close_preferences), }; + const UnitTest muc_tests[] = { + unit_test(test_muc_add_invite), + }; + int bak, bak2, new; fflush(stdout); fflush(stderr); @@ -456,6 +461,7 @@ int main(int argc, char* argv[]) { PROF_RUN_TESTS(preferences_tests); PROF_RUN_TESTS(cmd_alias_tests); PROF_RUN_TESTS(server_events_tests); + PROF_RUN_TESTS(muc_tests); fflush(stdout); dup2(bak, 1); From a472ce653f1801726f18ca579f8dcffd64ef4d20 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Jan 2014 23:36:24 +0000 Subject: [PATCH 2/5] Added muc remove invite test --- tests/test_muc.c | 14 +++++++++++++- tests/test_muc.h | 1 + tests/testsuite.c | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_muc.c b/tests/test_muc.c index 42a27931..3a8da50a 100644 --- a/tests/test_muc.c +++ b/tests/test_muc.c @@ -11,8 +11,20 @@ void test_muc_add_invite(void **state) char *room = "room@conf.server"; muc_init(); muc_add_invite(room); - + gboolean invite_exists = muc_invites_include(room); assert_true(invite_exists); } + +void test_muc_remove_invite(void **state) +{ + char *room = "room@conf.server"; + muc_init(); + muc_add_invite(room); + muc_remove_invite(room); + + gboolean invite_exists = muc_invites_include(room); + + assert_false(invite_exists); +} diff --git a/tests/test_muc.h b/tests/test_muc.h index 8efff108..8f0a879b 100644 --- a/tests/test_muc.h +++ b/tests/test_muc.h @@ -1 +1,2 @@ void test_muc_add_invite(void **state); +void test_muc_remove_invite(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 5120bcf2..e823acd3 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -430,6 +430,7 @@ int main(int argc, char* argv[]) { const UnitTest muc_tests[] = { unit_test(test_muc_add_invite), + unit_test(test_muc_remove_invite), }; int bak, bak2, new; From 991ffdecebf4c9f4023c9e4f36141098ba23dd58 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Jan 2014 23:37:36 +0000 Subject: [PATCH 3/5] Close muc after test --- tests/test_muc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_muc.c b/tests/test_muc.c index 3a8da50a..2af13516 100644 --- a/tests/test_muc.c +++ b/tests/test_muc.c @@ -15,6 +15,8 @@ void test_muc_add_invite(void **state) gboolean invite_exists = muc_invites_include(room); assert_true(invite_exists); + + muc_close(); } void test_muc_remove_invite(void **state) @@ -27,4 +29,6 @@ void test_muc_remove_invite(void **state) gboolean invite_exists = muc_invites_include(room); assert_false(invite_exists); + + muc_close(); } From 16aecaf01768094ea0c7cfcd0b0ea5c34e5bb037 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Jan 2014 23:41:18 +0000 Subject: [PATCH 4/5] Added setup and teardown for muc tests --- tests/test_muc.c | 16 ++++++++++------ tests/test_muc.h | 3 +++ tests/testsuite.c | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_muc.c b/tests/test_muc.c index 2af13516..94acd21c 100644 --- a/tests/test_muc.c +++ b/tests/test_muc.c @@ -6,29 +6,33 @@ #include "muc.h" +void muc_before_test(void **state) +{ + muc_init(); +} + +void muc_after_test(void **state) +{ + muc_close(); +} + void test_muc_add_invite(void **state) { char *room = "room@conf.server"; - muc_init(); muc_add_invite(room); gboolean invite_exists = muc_invites_include(room); assert_true(invite_exists); - - muc_close(); } void test_muc_remove_invite(void **state) { char *room = "room@conf.server"; - muc_init(); muc_add_invite(room); muc_remove_invite(room); gboolean invite_exists = muc_invites_include(room); assert_false(invite_exists); - - muc_close(); } diff --git a/tests/test_muc.h b/tests/test_muc.h index 8f0a879b..4a3b5315 100644 --- a/tests/test_muc.h +++ b/tests/test_muc.h @@ -1,2 +1,5 @@ +void muc_before_test(void **state); +void muc_after_test(void **state); + void test_muc_add_invite(void **state); void test_muc_remove_invite(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index e823acd3..b8769efe 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -429,8 +429,8 @@ int main(int argc, char* argv[]) { }; const UnitTest muc_tests[] = { - unit_test(test_muc_add_invite), - unit_test(test_muc_remove_invite), + unit_test_setup_teardown(test_muc_add_invite, muc_before_test, muc_after_test), + unit_test_setup_teardown(test_muc_remove_invite, muc_before_test, muc_after_test), }; int bak, bak2, new; From 31321077de1dd723bf7713b2906a5786dc5fe29e Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 30 Jan 2014 23:49:58 +0000 Subject: [PATCH 5/5] Added muc invite count tests --- tests/test_muc.c | 20 ++++++++++++++++++++ tests/test_muc.h | 2 ++ tests/testsuite.c | 2 ++ 3 files changed, 24 insertions(+) diff --git a/tests/test_muc.c b/tests/test_muc.c index 94acd21c..37570666 100644 --- a/tests/test_muc.c +++ b/tests/test_muc.c @@ -36,3 +36,23 @@ void test_muc_remove_invite(void **state) assert_false(invite_exists); } + +void test_muc_invite_count_0(void **state) +{ + int invite_count = muc_invite_count(); + + assert_true(invite_count == 0); +} + +void test_muc_invite_count_5(void **state) +{ + muc_add_invite("room1@conf.server"); + muc_add_invite("room2@conf.server"); + muc_add_invite("room3@conf.server"); + muc_add_invite("room4@conf.server"); + muc_add_invite("room5@conf.server"); + + int invite_count = muc_invite_count(); + + assert_true(invite_count == 5); +} diff --git a/tests/test_muc.h b/tests/test_muc.h index 4a3b5315..75b63403 100644 --- a/tests/test_muc.h +++ b/tests/test_muc.h @@ -3,3 +3,5 @@ void muc_after_test(void **state); void test_muc_add_invite(void **state); void test_muc_remove_invite(void **state); +void test_muc_invite_count_0(void **state); +void test_muc_invite_count_5(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index b8769efe..4e016aef 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -431,6 +431,8 @@ int main(int argc, char* argv[]) { const UnitTest muc_tests[] = { unit_test_setup_teardown(test_muc_add_invite, muc_before_test, muc_after_test), unit_test_setup_teardown(test_muc_remove_invite, muc_before_test, muc_after_test), + unit_test_setup_teardown(test_muc_invite_count_0, muc_before_test, muc_after_test), + unit_test_setup_teardown(test_muc_invite_count_5, muc_before_test, muc_after_test), }; int bak, bak2, new;