diff options
author | James Booth <boothj5@gmail.com> | 2015-05-27 01:06:17 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-05-27 01:06:17 +0100 |
commit | db9376d82bcb71caae627b05f79849369798aa2f (patch) | |
tree | 65cacd56523151d6ea81813fba0bb9e186b19501 | |
parent | 7507e4ecfad65e1df0ac60d56599aeea6027e345 (diff) | |
download | profani-tty-db9376d82bcb71caae627b05f79849369798aa2f.tar.gz |
Simplified expect tests
-rw-r--r-- | stabbertests/proftest.c | 32 | ||||
-rw-r--r-- | stabbertests/proftest.h | 4 | ||||
-rw-r--r-- | stabbertests/stabbertestsuite.c | 24 | ||||
-rw-r--r-- | stabbertests/test_connect.c | 146 | ||||
-rw-r--r-- | 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,12 +11,32 @@ #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( + "<iq id=\"*\" type=\"get\"><query xmlns=\"jabber:iq:roster\"/></iq>" + )); +} + +void +connect_jid_sends_presence_after_receiving_roster(void **state) +{ stbbr_for("roster", "<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">" "<query xmlns=\"jabber:iq:roster\" ver=\"362\">" @@ -26,27 +46,11 @@ connect_jid(void **state) "</iq>" ); - 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( "<presence id=\"*\">" "<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>" @@ -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( -// "<iq id=\"*\" type=\"get\"><query xmlns=\"jabber:iq:roster\"/></iq>" -// )); -//} -// -//void -//connect_jid_sends_presence_after_receiving_roster(void **state) -//{ -// will_return(ui_ask_password, strdup("password")); -// expect_any_cons_show(); -// -// stbbr_for("roster", -// "<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">" -// "<query xmlns=\"jabber:iq:roster\" ver=\"362\">" -// "<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>" -// "<item jid=\"buddy2@localhost\" subscription=\"both\" name=\"Buddy2\"/>" -// "</query>" -// "</iq>" -// ); -// -// cmd_process_input(strdup("/connect stabber@localhost port 5230")); -// prof_process_xmpp(20); -// -// assert_true(stbbr_verify( -// "<presence id=\"*\">" -// "<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>" -// "</presence>" -// )); -//} -// -//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( -// "<iq id=\"*\" type=\"get\">" -// "<query xmlns=\"jabber:iq:private\">" -// "<storage xmlns=\"storage:bookmarks\"/>" -// "</query>" -// "</iq>" -// )); -//} -// -//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( + "<iq id=\"*\" type=\"get\">" + "<query xmlns=\"jabber:iq:private\">" + "<storage xmlns=\"storage:bookmarks\"/>" + "</query>" + "</iq>" + )); +} + +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); |