From a522d0225d7de9124ebbd18188ef9758c60cc8f5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 29 May 2015 01:01:34 +0100 Subject: Added regex output matcher, presence test --- Makefile.am | 1 + functionaltests/functionaltests.c | 8 +++++++ functionaltests/proftest.c | 8 ++++++- functionaltests/proftest.h | 5 +++-- functionaltests/test_connect.c | 14 ++++++------ functionaltests/test_ping.c | 6 ++--- functionaltests/test_presence.c | 47 +++++++++++++++++++++++++++++++++++++++ functionaltests/test_presence.h | 2 ++ functionaltests/test_rooms.c | 4 ++-- 9 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 functionaltests/test_presence.c create mode 100644 functionaltests/test_presence.h diff --git a/Makefile.am b/Makefile.am index 93d2fec0..a2b46a9c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -99,6 +99,7 @@ functionaltest_sources = \ functionaltests/test_connect.c functionaltests/test_connect.h \ functionaltests/test_ping.c functionaltests/test_ping.h \ functionaltests/test_rooms.c functionaltests/test_rooms.h \ + functionaltests/test_presence.c functionaltests/test_presence.h \ functionaltests/functionaltests.c main_source = src/main.c diff --git a/functionaltests/functionaltests.c b/functionaltests/functionaltests.c index 6c627d38..668445cd 100644 --- a/functionaltests/functionaltests.c +++ b/functionaltests/functionaltests.c @@ -13,6 +13,7 @@ #include "test_connect.h" #include "test_ping.h" #include "test_rooms.h" +#include "test_presence.h" int main(int argc, char* argv[]) { @@ -47,6 +48,13 @@ int main(int argc, char* argv[]) { unit_test_setup_teardown(rooms_query, init_prof_test, close_prof_test), + + unit_test_setup_teardown(presence_away, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(presence_away_with_message, + init_prof_test, + close_prof_test), }; return run_tests(all_tests); diff --git a/functionaltests/proftest.c b/functionaltests/proftest.c index a5510d68..94b0c2b3 100644 --- a/functionaltests/proftest.c +++ b/functionaltests/proftest.c @@ -178,11 +178,17 @@ prof_input(char *input) } int -prof_output(char *text) +prof_output_exact(char *text) { return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end)); } +int +prof_output_regex(char *text) +{ + return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end)); +} + void prof_connect(char *jid, char *password) { diff --git a/functionaltests/proftest.h b/functionaltests/proftest.h index 68574af6..f57f6c35 100644 --- a/functionaltests/proftest.h +++ b/functionaltests/proftest.h @@ -7,10 +7,11 @@ void init_prof_test(void **state); void close_prof_test(void **state); - void prof_start(void); void prof_connect(char *jid, char *password); void prof_input(char *input); -int prof_output(char *text); + +int prof_output_exact(char *text); +int prof_output_regex(char *text); #endif diff --git a/functionaltests/test_connect.c b/functionaltests/test_connect.c index fc2d0f94..957d2798 100644 --- a/functionaltests/test_connect.c +++ b/functionaltests/test_connect.c @@ -16,8 +16,8 @@ connect_jid(void **state) { prof_connect("stabber@localhost", "password"); - assert_true(prof_output("Connecting as stabber@localhost")); - assert_true(prof_output("stabber@localhost logged in successfully")); + assert_true(prof_output_exact("Connecting as stabber@localhost")); + assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\.")); } void @@ -70,7 +70,7 @@ connect_bad_password(void **state) { prof_connect("stabber@localhost", "badpassword"); - assert_true(prof_output("Login failed.")); + assert_true(prof_output_exact("Login failed.")); } void @@ -102,9 +102,9 @@ connect_shows_presence_updates(void **state) prof_connect("stabber@localhost", "password"); - assert_true(prof_output("Buddy1 (mobile) is dnd, \"busy!\"")); - assert_true(prof_output("Buddy1 (laptop) is chat, \"Talk to me!\"")); - assert_true(prof_output("Buddy2 (work) is away, \"Out of office\"")); + assert_true(prof_output_exact("Buddy1 (mobile) is dnd, \"busy!\"")); + assert_true(prof_output_exact("Buddy1 (laptop) is chat, \"Talk to me!\"")); + assert_true(prof_output_exact("Buddy2 (work) is away, \"Out of office\"")); stbbr_send( "" @@ -113,5 +113,5 @@ connect_shows_presence_updates(void **state) "" ); - assert_true(prof_output("Buddy1 (mobile) is xa, \"Gone :(\"")); + assert_true(prof_output_exact("Buddy1 (mobile) is xa, \"Gone :(\"")); } diff --git a/functionaltests/test_ping.c b/functionaltests/test_ping.c index 19a1e413..c1b398d8 100644 --- a/functionaltests/test_ping.c +++ b/functionaltests/test_ping.c @@ -29,7 +29,7 @@ ping_multiple(void **state) "" "" )); - assert_true(prof_output("Ping response from server")); + assert_true(prof_output_exact("Ping response from server")); prof_input("/ping"); assert_true(stbbr_received( @@ -37,7 +37,7 @@ ping_multiple(void **state) "" "" )); - assert_true(prof_output("Ping response from server")); + assert_true(prof_output_exact("Ping response from server")); } void @@ -45,7 +45,7 @@ ping_responds(void **state) { prof_connect("stabber@localhost", "password"); - assert_true(prof_output("stabber@localhost logged in successfully")); + assert_true(prof_output_exact("stabber@localhost logged in successfully")); stbbr_send( "" diff --git a/functionaltests/test_presence.c b/functionaltests/test_presence.c new file mode 100644 index 00000000..1334fe91 --- /dev/null +++ b/functionaltests/test_presence.c @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "proftest.h" + +void +presence_away(void **state) +{ + prof_connect("stabber@localhost", "password"); + + prof_input("/away"); + + assert_true(stbbr_received( + "" + "away" + "" + "" + )); + + assert_true(prof_output_exact("Status set to away (priority 0)")); +} + +void +presence_away_with_message(void **state) +{ + prof_connect("stabber@localhost", "password"); + + prof_input("/away \"I'm not here for a bit\""); + + assert_true(stbbr_received( + "" + "away" + "I'm not here for a bit" + "" + "" + )); + + assert_true(prof_output_exact("Status set to away (priority 0), \"I'm not here for a bit\".")); +} diff --git a/functionaltests/test_presence.h b/functionaltests/test_presence.h new file mode 100644 index 00000000..f199ab41 --- /dev/null +++ b/functionaltests/test_presence.h @@ -0,0 +1,2 @@ +void presence_away(void **state); +void presence_away_with_message(void **state); diff --git a/functionaltests/test_rooms.c b/functionaltests/test_rooms.c index c6097a54..313d7a72 100644 --- a/functionaltests/test_rooms.c +++ b/functionaltests/test_rooms.c @@ -33,6 +33,6 @@ rooms_query(void **state) "" )); - assert_true(prof_output("chatroom@conference.localhost, (A chat room)")); - assert_true(prof_output("hangout@conference.localhost, (Another chat room)")); + assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)")); + assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)")); } -- cgit 1.4.1-2-gfad0