From db9376d82bcb71caae627b05f79849369798aa2f Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 27 May 2015 01:06:17 +0100 Subject: Simplified expect tests --- stabbertests/proftest.c | 32 +++++++++ stabbertests/proftest.h | 4 ++ stabbertests/stabbertestsuite.c | 24 +++---- stabbertests/test_connect.c | 146 ++++++++++++++-------------------------- stabbertests/test_connect.h | 8 +-- 5 files changed, 104 insertions(+), 110 deletions(-) diff --git a/stabbertests/proftest.c b/stabbertests/proftest.c index 65cee269..3b3014ad 100644 --- a/stabbertests/proftest.c +++ b/stabbertests/proftest.c @@ -20,6 +20,8 @@ char *config_orig; char *data_orig; +int fd = 0; + gboolean _create_dir(char *name) { @@ -141,6 +143,8 @@ init_prof_test(void **state) _create_data_dir(); _create_chatlogs_dir(); _create_logs_dir(); + + prof_start(); } void @@ -153,3 +157,31 @@ close_prof_test(void **state) stbbr_stop(); } + +void +prof_start(void) +{ + fd = exp_spawnl("./profanity", NULL); + FILE *fp = fdopen(fd, "r+"); + + if (fp == NULL) { + assert_true(FALSE); + } + + setbuf(fp, (char *)0); +} + +void +prof_input(char *input) +{ + GString *inp_str = g_string_new(input); + g_string_append(inp_str, "\r"); + write(fd, inp_str->str, inp_str->len); + g_string_free(inp_str, TRUE); +} + +int +prof_output(char *text) +{ + return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end)); +} diff --git a/stabbertests/proftest.h b/stabbertests/proftest.h index 358b355c..73e3680e 100644 --- a/stabbertests/proftest.h +++ b/stabbertests/proftest.h @@ -7,4 +7,8 @@ void init_prof_test(void **state); void close_prof_test(void **state); +void prof_start(void); +void prof_input(char *input); +int prof_output(char *text); + #endif diff --git a/stabbertests/stabbertestsuite.c b/stabbertests/stabbertestsuite.c index 86d5b192..55affa2a 100644 --- a/stabbertests/stabbertestsuite.c +++ b/stabbertests/stabbertestsuite.c @@ -19,18 +19,18 @@ int main(int argc, char* argv[]) { 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), -// unit_test_setup_teardown(connect_jid_sends_presence_after_receiving_roster, -// init_prof_test, -// close_prof_test), -// unit_test_setup_teardown(connect_jid_requests_bookmarks, -// init_prof_test, -// close_prof_test), -// unit_test_setup_teardown(connect_bad_password, -// init_prof_test, -// close_prof_test), + unit_test_setup_teardown(connect_jid_requests_roster, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(connect_jid_sends_presence_after_receiving_roster, + init_prof_test, + close_prof_test), + unit_test_setup_teardown(connect_jid_requests_bookmarks, + init_prof_test, + close_prof_test), + 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), diff --git a/stabbertests/test_connect.c b/stabbertests/test_connect.c index c24e20eb..b8f1a1a6 100644 --- a/stabbertests/test_connect.c +++ b/stabbertests/test_connect.c @@ -11,11 +11,31 @@ #include "proftest.h" -#define CONNECT_CMD "/connect stabber@localhost port 5230\r" -#define PASSWORD "password\r" - void connect_jid(void **state) +{ + prof_input("/connect stabber@localhost port 5230"); + prof_input("password"); + + assert_true(prof_output("Connecting as stabber@localhost")); + assert_true(prof_output("stabber@localhost logged in successfully")); +} + +void +connect_jid_requests_roster(void **state) +{ + prof_input("/connect stabber@localhost port 5230"); + prof_input("password"); + + sleep(1); + + assert_true(stbbr_verify( + "" + )); +} + +void +connect_jid_sends_presence_after_receiving_roster(void **state) { stbbr_for("roster", "" @@ -26,27 +46,11 @@ connect_jid(void **state) "" ); - int res = 0; - int fd = exp_spawnl("./profanity", NULL); - FILE *fp = fdopen(fd, "r+"); - - if (fp == NULL) { - assert_true(FALSE); - } - - setbuf(fp, (char *)0); - - write(fd, CONNECT_CMD, strlen(CONNECT_CMD)); - res = exp_expectl(fd, exp_exact, "Enter password:", 11, exp_end); - assert_true(res == 11); - - write(fd, PASSWORD, strlen(PASSWORD)); - res = exp_expectl(fd, exp_exact, "Connecting as stabber@localhost", 12, exp_end); - assert_true(res == 12); - res = exp_expectl(fd, exp_exact, "stabber@localhost logged in successfully", 13, exp_end); - assert_true(res == 13); + prof_input("/connect stabber@localhost port 5230"); + prof_input("password"); sleep(1); + assert_true(stbbr_verify( "" "" @@ -54,78 +58,32 @@ connect_jid(void **state) )); } -//void -//connect_jid_requests_roster(void **state) -//{ -// will_return(ui_ask_password, strdup("password")); -// expect_any_cons_show(); -// -// cmd_process_input(strdup("/connect stabber@localhost port 5230")); -// prof_process_xmpp(20); -// -// assert_true(stbbr_verify( -// "" -// )); -//} -// -//void -//connect_jid_sends_presence_after_receiving_roster(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); -// -// assert_true(stbbr_verify( -// "" -// "" -// "" -// )); -//} -// -//void -//connect_jid_requests_bookmarks(void **state) -//{ -// will_return(ui_ask_password, strdup("password")); -// expect_any_cons_show(); -// -// cmd_process_input(strdup("/connect stabber@localhost port 5230")); -// prof_process_xmpp(20); -// -// assert_true(stbbr_verify( -// "" -// "" -// "" -// "" -// "" -// )); -//} -// -//void -//connect_bad_password(void **state) -//{ -// will_return(ui_ask_password, strdup("badpassword")); -// -// expect_cons_show("Connecting as stabber@localhost"); -// expect_cons_show_error("Login failed."); -// -// cmd_process_input(strdup("/connect stabber@localhost port 5230")); -// prof_process_xmpp(20); -// -// jabber_conn_status_t status = jabber_get_connection_status(); -// assert_true(status == JABBER_DISCONNECTED); -//} -// +void +connect_jid_requests_bookmarks(void **state) +{ + prof_input("/connect stabber@localhost port 5230"); + prof_input("password"); + + sleep(1); + + assert_true(stbbr_verify( + "" + "" + "" + "" + "" + )); +} + +void +connect_bad_password(void **state) +{ + prof_input("/connect stabber@localhost port 5230"); + prof_input("badpassword"); + + assert_true(prof_output("Login failed.")); +} + //void //show_presence_updates(void **state) //{ diff --git a/stabbertests/test_connect.h b/stabbertests/test_connect.h index d2d4dbee..a8795399 100644 --- a/stabbertests/test_connect.h +++ b/stabbertests/test_connect.h @@ -1,8 +1,8 @@ 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); -//void connect_bad_password(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); +void connect_bad_password(void **state); //void show_presence_updates(void **state); //void sends_rooms_iq(void **state); //void multiple_pings(void **state); -- cgit 1.4.1-2-gfad0