From 06b18be8514eab863f3a65262a36fcbd8a0f2f62 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 25 May 2015 02:18:31 +0100 Subject: [PATCH] Added custom resource checker --- Makefile.am | 1 + stabbertests/checkers/checkers.c | 26 ++++++++++++++++ stabbertests/checkers/checkers.h | 6 ++++ stabbertests/proftest.h | 5 +++ stabbertests/stabbertestsuite.c | 3 ++ stabbertests/test_connect.c | 53 +++++++++++++++++++++++++++++++- stabbertests/test_connect.h | 1 + 7 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 stabbertests/checkers/checkers.c create mode 100644 stabbertests/checkers/checkers.h diff --git a/Makefile.am b/Makefile.am index cae3a268..8fdb5c54 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,6 +130,7 @@ stabbertest_sources = \ src/config/theme.c src/config/theme.h \ stabbertests/ui/stub_ui.c \ stabbertests/proftest.c stabbertests/proftest.h \ + stabbertests/checkers/checkers.c stabbertests/checkers/checkers.h \ stabbertests/test_connect.c stabbertests/test_connect.h \ stabbertests/stabbertestsuite.c diff --git a/stabbertests/checkers/checkers.c b/stabbertests/checkers/checkers.c new file mode 100644 index 00000000..6709dc97 --- /dev/null +++ b/stabbertests/checkers/checkers.c @@ -0,0 +1,26 @@ +#include "resource.h" + +int +resource_equal_check(void *param, void *value) +{ + Resource *param_res = (Resource *)param; + Resource *value_res = (Resource *)value; + + if (g_strcmp0(param_res->name, value_res->name) != 0) { + return 0; + } + + if (param_res->presence != value_res->presence) { + return 0; + } + + if (param_res->priority != value_res->priority) { + return 0; + } + + if (g_strcmp0(param_res->status, value_res->status) != 0) { + return 0; + } + + return 1; +} diff --git a/stabbertests/checkers/checkers.h b/stabbertests/checkers/checkers.h new file mode 100644 index 00000000..64654c77 --- /dev/null +++ b/stabbertests/checkers/checkers.h @@ -0,0 +1,6 @@ +#ifndef __H_CHECKERS +#define __H_CHECKERS + +int resource_equal_check(void *param, void *value); + +#endif \ No newline at end of file diff --git a/stabbertests/proftest.h b/stabbertests/proftest.h index 2feb0346..7d95db93 100644 --- a/stabbertests/proftest.h +++ b/stabbertests/proftest.h @@ -1,3 +1,8 @@ +#ifndef __H_PROFTEST +#define __H_PROFTEST + void init_prof_test(void **state); void close_prof_test(void **state); void prof_process_xmpp(int loops); + +#endif \ No newline at end of file diff --git a/stabbertests/stabbertestsuite.c b/stabbertests/stabbertestsuite.c index 335ddce5..a54b94dc 100644 --- a/stabbertests/stabbertestsuite.c +++ b/stabbertests/stabbertestsuite.c @@ -31,6 +31,9 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(connect_bad_password, init_prof_test, close_prof_test), + unit_test_setup_teardown(show_presence_updates, + init_prof_test, + close_prof_test), unit_test_setup_teardown(sends_rooms_iq, init_prof_test, close_prof_test), diff --git a/stabbertests/test_connect.c b/stabbertests/test_connect.c index 1c833c82..759dc4e5 100644 --- a/stabbertests/test_connect.c +++ b/stabbertests/test_connect.c @@ -9,6 +9,7 @@ #include #include "proftest.h" +#include "checkers/checkers.h" #include "xmpp/xmpp.h" #include "ui/stub_ui.h" #include "ui/window.h" @@ -99,6 +100,57 @@ connect_bad_password(void **state) assert_true(status == JABBER_DISCONNECTED); } +void +show_presence_updates(void **state) +{ + will_return(ui_ask_password, strdup("password")); + expect_any_cons_show(); + + stbbr_for("roster", + "" + "" + "" + "" + "" + "" + ); + + cmd_process_input(strdup("/connect stabber@localhost port 5230")); + prof_process_xmpp(20); + + stbbr_send( + "" + "dnd" + "busy!" + "" + "" + "chat" + "Talk to me!" + "" + "" + "away" + "Out of office" + "" + ); + + Resource *resource1 = resource_new("mobile", RESOURCE_DND, "busy!", 0); + expect_string(ui_contact_online, barejid, "buddy1@localhost"); + expect_check(ui_contact_online, resource, (CheckParameterValue)resource_equal_check, resource1); + expect_value(ui_contact_online, last_activity, NULL); + + Resource *resource2 = resource_new("laptop", RESOURCE_CHAT, "Talk to me!", 0); + expect_string(ui_contact_online, barejid, "buddy1@localhost"); + expect_check(ui_contact_online, resource, (CheckParameterValue)resource_equal_check, resource2); + expect_value(ui_contact_online, last_activity, NULL); + + Resource *resource3 = resource_new("work", RESOURCE_AWAY, "Out of office", 0); + expect_string(ui_contact_online, barejid, "buddy2@localhost"); + expect_check(ui_contact_online, resource, (CheckParameterValue)resource_equal_check, resource3); + expect_value(ui_contact_online, last_activity, NULL); + + prof_process_xmpp(20); +} + void sends_rooms_iq(void **state) { @@ -182,7 +234,6 @@ responds_to_ping(void **state) "" "" ); - prof_process_xmpp(20); assert_true(stbbr_verify( diff --git a/stabbertests/test_connect.h b/stabbertests/test_connect.h index 8e80b113..971652b0 100644 --- a/stabbertests/test_connect.h +++ b/stabbertests/test_connect.h @@ -3,6 +3,7 @@ void connect_jid_requests_roster(void **state); void connect_jid_sends_presence_after_receiving_roster(void **state); void connect_jid_requests_bookmarks(void **state); void connect_bad_password(void **state); +void show_presence_updates(void **state); void sends_rooms_iq(void **state); void multiple_pings(void **state); void responds_to_ping(void **state);