From a48b9fcec2385c5d571f1f02ed6e769d6b4ee821 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 13 Jun 2015 19:41:11 +0100 Subject: [PATCH] Tidied functional tests --- tests/functionaltests/functionaltests.c | 3 - tests/functionaltests/proftest.c | 31 +++++-- tests/functionaltests/proftest.h | 6 +- tests/functionaltests/test_chat_session.c | 103 +++++----------------- tests/functionaltests/test_connect.c | 52 ++++------- tests/functionaltests/test_connect.h | 1 - tests/functionaltests/test_message.c | 14 +-- tests/functionaltests/test_ping.c | 16 ++-- tests/functionaltests/test_presence.c | 62 ++++++------- tests/functionaltests/test_rooms.c | 2 +- 10 files changed, 99 insertions(+), 191 deletions(-) diff --git a/tests/functionaltests/functionaltests.c b/tests/functionaltests/functionaltests.c index a1550842..fac7685c 100644 --- a/tests/functionaltests/functionaltests.c +++ b/tests/functionaltests/functionaltests.c @@ -21,9 +21,6 @@ int main(int argc, char* argv[]) { const UnitTest all_tests[] = { - unit_test_setup_teardown(connect_jid, - init_prof_test, - close_prof_test), unit_test_setup_teardown(connect_jid_requests_roster, init_prof_test, close_prof_test), diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index 5d7b6585..c8b38893 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -114,7 +114,7 @@ _create_logs_dir(void) void _cleanup_dirs(void) { - int res = system("rm -rf ./functionaltests/files"); + int res = system("rm -rf ./tests/functionaltests/files"); if (res == -1) { assert_true(FALSE); } @@ -123,7 +123,7 @@ _cleanup_dirs(void) void prof_start(void) { - fd = exp_spawnl("./profanity", NULL); + fd = exp_spawnl("./profanity", "./profanity", "-l", "DEBUG", NULL); FILE *fp = fdopen(fd, "r+"); if (fp == NULL) { @@ -201,13 +201,26 @@ prof_output_regex(char *text) } void -prof_connect(char *jid, char *password) +prof_connect(void) { - GString *connect_cmd = g_string_new("/connect "); - g_string_append(connect_cmd, jid); - g_string_append(connect_cmd, " port 5230"); - prof_input(connect_cmd->str); - g_string_free(connect_cmd, TRUE); + stbbr_for_query("jabber:iq:roster", + "" + "" + "" + "" + "" + "" + ); + stbbr_for_id("prof_presence_1", + "" + "0" + "" + "" + ); - prof_input(password); + prof_input("/connect stabber@localhost port 5230"); + prof_input("password"); + + assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\.")); + stbbr_wait_for("prof_presence_1"); } diff --git a/tests/functionaltests/proftest.h b/tests/functionaltests/proftest.h index f57f6c35..2283ab01 100644 --- a/tests/functionaltests/proftest.h +++ b/tests/functionaltests/proftest.h @@ -1,14 +1,14 @@ #ifndef __H_PROFTEST #define __H_PROFTEST -#define XDG_CONFIG_HOME "./functionaltests/files/xdg_config_home" -#define XDG_DATA_HOME "./functionaltests/files/xdg_data_home" +#define XDG_CONFIG_HOME "./tests/functionaltests/files/xdg_config_home" +#define XDG_DATA_HOME "./tests/functionaltests/files/xdg_data_home" 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_connect(void); void prof_input(char *input); int prof_output_exact(char *text); diff --git a/tests/functionaltests/test_chat_session.c b/tests/functionaltests/test_chat_session.c index 11df4e76..d1229e90 100644 --- a/tests/functionaltests/test_chat_session.c +++ b/tests/functionaltests/test_chat_session.c @@ -14,16 +14,7 @@ void sends_message_to_barejid_when_contact_offline(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); prof_input("/msg buddy1@localhost Hi there"); @@ -37,23 +28,14 @@ sends_message_to_barejid_when_contact_offline(void **state) void sends_message_to_barejid_when_contact_online(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( - "" + "" "10" "" ); - prof_output_exact("buddy1@localhost (mobile) is online"); + assert_true(prof_output_exact("Buddy1 (mobile) is online")); prof_input("/msg buddy1@localhost Hi there"); @@ -67,30 +49,21 @@ sends_message_to_barejid_when_contact_online(void **state) void sends_message_to_fulljid_when_received_from_fulljid(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( "" "10" "" ); - prof_output_exact("buddy1@localhost (mobile) is online"); + assert_true(prof_output_exact("Buddy1 (mobile) is online")); stbbr_send( "" "First message" "" ); - prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + assert_true(prof_output_exact("<< incoming from Buddy1/mobile (2)")); prof_input("/msg buddy1@localhost Hi there"); @@ -104,45 +77,37 @@ sends_message_to_fulljid_when_received_from_fulljid(void **state) void sends_subsequent_messages_to_fulljid(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( "" "10" "" ); - prof_output_exact("buddy1@localhost (mobile) is online"); + assert_true(prof_output_exact("Buddy1 (mobile) is online")); stbbr_send( "" "First message" "" ); - prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + assert_true(prof_output_exact("<< incoming from Buddy1/mobile (2)")); prof_input("/msg buddy1@localhost Outgoing 1"); - prof_input("/msg buddy1@localhost Outgoing 2"); - prof_input("/msg buddy1@localhost Outgoing 3"); - assert_true(stbbr_received( "" "Outgoing 1" "" )); + + prof_input("/msg buddy1@localhost Outgoing 2"); assert_true(stbbr_received( "" "Outgoing 2" "" )); + + prof_input("/msg buddy1@localhost Outgoing 3"); assert_true(stbbr_received( "" "Outgoing 3" @@ -153,33 +118,23 @@ sends_subsequent_messages_to_fulljid(void **state) void resets_to_barejid_after_presence_received(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( "" "10" "" ); - prof_output_exact("buddy1@localhost (mobile) is online"); + assert_true(prof_output_exact("Buddy1 (mobile) is online")); stbbr_send( "" "First message" "" ); - prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + assert_true(prof_output_exact("<< incoming from Buddy1/mobile (2)")); prof_input("/msg buddy1@localhost Outgoing 1"); - assert_true(stbbr_received( "" "Outgoing 1" @@ -192,10 +147,9 @@ resets_to_barejid_after_presence_received(void **state) "dnd" "" ); - prof_output_exact("buddy1@localhost (laptop) is dnd"); + assert_true(prof_output_exact("Buddy1 (laptop) is dnd")); prof_input("/msg buddy1@localhost Outgoing 2"); - assert_true(stbbr_received( "" "Outgoing 2" @@ -206,23 +160,14 @@ resets_to_barejid_after_presence_received(void **state) void new_session_when_message_received_from_different_fulljid(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( "" "10" "" ); - prof_output_exact("buddy1@localhost (mobile) is online"); + assert_true(prof_output_exact("Buddy1 (mobile) is online")); stbbr_send( "" @@ -230,17 +175,16 @@ new_session_when_message_received_from_different_fulljid(void **state) "away" "" ); - prof_output_exact("buddy1@localhost (laptop) is away"); + assert_true(prof_output_exact("Buddy1 (laptop) is away")); stbbr_send( "" "From first resource" "" ); - prof_output_exact("<< incoming from buddy1@localhost/mobile (2)"); + assert_true(prof_output_exact("<< incoming from Buddy1/mobile (2)")); prof_input("/msg buddy1@localhost Outgoing 1"); - assert_true(stbbr_received( "" "Outgoing 1" @@ -252,10 +196,9 @@ new_session_when_message_received_from_different_fulljid(void **state) "From second resource" "" ); - prof_output_regex("buddy1@localhost/laptop:.+From second resource"); + assert_true(prof_output_regex("Buddy1/laptop:.+From second resource")); prof_input("/msg buddy1@localhost Outgoing 2"); - assert_true(stbbr_received( "" "Outgoing 2" diff --git a/tests/functionaltests/test_connect.c b/tests/functionaltests/test_connect.c index 7a42397f..5fcb8a2f 100644 --- a/tests/functionaltests/test_connect.c +++ b/tests/functionaltests/test_connect.c @@ -11,19 +11,10 @@ #include "proftest.h" -void -connect_jid(void **state) -{ - prof_connect("stabber@localhost", "password"); - - assert_true(prof_output_exact("Connecting as stabber@localhost")); - assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\.")); -} - void connect_jid_requests_roster(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); assert_true(stbbr_received( "" @@ -33,16 +24,7 @@ connect_jid_requests_roster(void **state) void connect_jid_sends_presence_after_receiving_roster(void **state) { - stbbr_for_query("jabber:iq:roster", - "" - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); + prof_connect(); assert_true(stbbr_received( "" @@ -54,7 +36,7 @@ connect_jid_sends_presence_after_receiving_roster(void **state) void connect_jid_requests_bookmarks(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); assert_true(stbbr_received( "" @@ -68,7 +50,8 @@ connect_jid_requests_bookmarks(void **state) void connect_bad_password(void **state) { - prof_connect("stabber@localhost", "badpassword"); + prof_input("/connect stabber@localhost port 5230"); + prof_input("badpassword"); assert_true(prof_output_exact("Login failed.")); } @@ -76,34 +59,30 @@ connect_bad_password(void **state) void connect_shows_presence_updates(void **state) { - stbbr_for_query("jabber:iq:roster", - "" - "" - "" - "" - "" - "" - ); + prof_connect(); - stbbr_for_id("prof_presence_1", + stbbr_send( "" "dnd" "busy!" "" + ); + assert_true(prof_output_exact("Buddy1 (mobile) is dnd, \"busy!\"")); + + stbbr_send( "" "chat" "Talk to me!" "" + ); + assert_true(prof_output_exact("Buddy1 (laptop) is chat, \"Talk to me!\"")); + + stbbr_send( "" "away" "Out of office" "" ); - - prof_connect("stabber@localhost", "password"); - - 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( @@ -112,6 +91,5 @@ connect_shows_presence_updates(void **state) "Gone :(" "" ); - assert_true(prof_output_exact("Buddy1 (mobile) is xa, \"Gone :(\"")); } diff --git a/tests/functionaltests/test_connect.h b/tests/functionaltests/test_connect.h index c6ceb404..66010e25 100644 --- a/tests/functionaltests/test_connect.h +++ b/tests/functionaltests/test_connect.h @@ -1,4 +1,3 @@ -void connect_jid(void **state); void connect_jid_requests_roster(void **state); void connect_jid_sends_presence_after_receiving_roster(void **state); void connect_jid_requests_bookmarks(void **state); diff --git a/tests/functionaltests/test_message.c b/tests/functionaltests/test_message.c index 5cdad520..0957b309 100644 --- a/tests/functionaltests/test_message.c +++ b/tests/functionaltests/test_message.c @@ -14,7 +14,7 @@ void message_send(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/msg somejid@someserver.com Hi there"); @@ -30,17 +30,7 @@ message_send(void **state) void message_receive(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( "" diff --git a/tests/functionaltests/test_ping.c b/tests/functionaltests/test_ping.c index e2ca79ca..76fd979c 100644 --- a/tests/functionaltests/test_ping.c +++ b/tests/functionaltests/test_ping.c @@ -14,18 +14,18 @@ void ping_multiple(void **state) { - stbbr_for_id("prof_ping_1", - "" - ); stbbr_for_id("prof_ping_2", "" ); + stbbr_for_id("prof_ping_3", + "" + ); - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/ping"); assert_true(stbbr_received( - "" + "" "" "" )); @@ -33,7 +33,7 @@ ping_multiple(void **state) prof_input("/ping"); assert_true(stbbr_received( - "" + "" "" "" )); @@ -43,9 +43,7 @@ ping_multiple(void **state) void ping_responds(void **state) { - prof_connect("stabber@localhost", "password"); - - assert_true(prof_output_exact("stabber@localhost logged in successfully")); + prof_connect(); stbbr_send( "" diff --git a/tests/functionaltests/test_presence.c b/tests/functionaltests/test_presence.c index b26bdccb..cb2eacd3 100644 --- a/tests/functionaltests/test_presence.c +++ b/tests/functionaltests/test_presence.c @@ -14,12 +14,12 @@ void presence_online(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/online"); assert_true(stbbr_received( - "" + "" "" "" )); @@ -30,12 +30,12 @@ presence_online(void **state) void presence_online_with_message(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/online \"Hi there\""); assert_true(stbbr_received( - "" + "" "Hi there" "" "" @@ -47,12 +47,12 @@ presence_online_with_message(void **state) void presence_away(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/away"); assert_true(stbbr_received( - "" + "" "away" "" "" @@ -64,12 +64,12 @@ presence_away(void **state) void presence_away_with_message(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/away \"I'm not here for a bit\""); assert_true(stbbr_received( - "" + "" "away" "I'm not here for a bit" "" @@ -82,12 +82,12 @@ presence_away_with_message(void **state) void presence_xa(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/xa"); assert_true(stbbr_received( - "" + "" "xa" "" "" @@ -99,12 +99,12 @@ presence_xa(void **state) void presence_xa_with_message(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/xa \"Gone to the shops\""); assert_true(stbbr_received( - "" + "" "xa" "Gone to the shops" "" @@ -117,12 +117,12 @@ presence_xa_with_message(void **state) void presence_dnd(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/dnd"); assert_true(stbbr_received( - "" + "" "dnd" "" "" @@ -134,12 +134,12 @@ presence_dnd(void **state) void presence_dnd_with_message(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/dnd \"Working\""); assert_true(stbbr_received( - "" + "" "dnd" "Working" "" @@ -152,12 +152,12 @@ presence_dnd_with_message(void **state) void presence_chat(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/chat"); assert_true(stbbr_received( - "" + "" "chat" "" "" @@ -169,12 +169,12 @@ presence_chat(void **state) void presence_chat_with_message(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/chat \"Free to talk\""); assert_true(stbbr_received( - "" + "" "chat" "Free to talk" "" @@ -187,12 +187,12 @@ presence_chat_with_message(void **state) void presence_set_priority(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/priority 25"); assert_true(stbbr_received( - "" + "" "25" "" "" @@ -204,11 +204,11 @@ presence_set_priority(void **state) void presence_includes_priority(void **state) { - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/priority 25"); assert_true(stbbr_received( - "" + "" "25" "" "" @@ -217,7 +217,7 @@ presence_includes_priority(void **state) prof_input("/chat \"Free to talk\""); assert_true(stbbr_received( - "" + "" "25" "chat" "Free to talk" @@ -230,17 +230,7 @@ presence_includes_priority(void **state) void presence_received(void **state) { - stbbr_for_id("roster", - "" - "" - "" - "" - "" - "" - ); - - prof_connect("stabber@localhost", "password"); - stbbr_wait_for("prof_presence_1"); + prof_connect(); stbbr_send( "" diff --git a/tests/functionaltests/test_rooms.c b/tests/functionaltests/test_rooms.c index 20ed7342..e4fe0200 100644 --- a/tests/functionaltests/test_rooms.c +++ b/tests/functionaltests/test_rooms.c @@ -23,7 +23,7 @@ rooms_query(void **state) "" ); - prof_connect("stabber@localhost", "password"); + prof_connect(); prof_input("/rooms");