Simplified expect tests

This commit is contained in:
James Booth
2015-05-27 01:06:17 +01:00
parent 7507e4ecfa
commit db9376d82b
5 changed files with 104 additions and 110 deletions

View File

@@ -20,6 +20,8 @@
char *config_orig; char *config_orig;
char *data_orig; char *data_orig;
int fd = 0;
gboolean gboolean
_create_dir(char *name) _create_dir(char *name)
{ {
@@ -141,6 +143,8 @@ init_prof_test(void **state)
_create_data_dir(); _create_data_dir();
_create_chatlogs_dir(); _create_chatlogs_dir();
_create_logs_dir(); _create_logs_dir();
prof_start();
} }
void void
@@ -153,3 +157,31 @@ close_prof_test(void **state)
stbbr_stop(); 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));
}

View File

@@ -7,4 +7,8 @@
void init_prof_test(void **state); void init_prof_test(void **state);
void close_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 #endif

View File

@@ -19,18 +19,18 @@ int main(int argc, char* argv[]) {
unit_test_setup_teardown(connect_jid, unit_test_setup_teardown(connect_jid,
init_prof_test, init_prof_test,
close_prof_test), close_prof_test),
// unit_test_setup_teardown(connect_jid_requests_roster, unit_test_setup_teardown(connect_jid_requests_roster,
// init_prof_test, init_prof_test,
// close_prof_test), close_prof_test),
// unit_test_setup_teardown(connect_jid_sends_presence_after_receiving_roster, unit_test_setup_teardown(connect_jid_sends_presence_after_receiving_roster,
// init_prof_test, init_prof_test,
// close_prof_test), close_prof_test),
// unit_test_setup_teardown(connect_jid_requests_bookmarks, unit_test_setup_teardown(connect_jid_requests_bookmarks,
// init_prof_test, init_prof_test,
// close_prof_test), close_prof_test),
// unit_test_setup_teardown(connect_bad_password, unit_test_setup_teardown(connect_bad_password,
// init_prof_test, init_prof_test,
// close_prof_test), close_prof_test),
// unit_test_setup_teardown(show_presence_updates, // unit_test_setup_teardown(show_presence_updates,
// init_prof_test, // init_prof_test,
// close_prof_test), // close_prof_test),

View File

@@ -11,11 +11,31 @@
#include "proftest.h" #include "proftest.h"
#define CONNECT_CMD "/connect stabber@localhost port 5230\r"
#define PASSWORD "password\r"
void void
connect_jid(void **state) 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", stbbr_for("roster",
"<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">" "<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">"
@@ -26,27 +46,11 @@ connect_jid(void **state)
"</iq>" "</iq>"
); );
int res = 0; prof_input("/connect stabber@localhost port 5230");
int fd = exp_spawnl("./profanity", NULL); prof_input("password");
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);
sleep(1); sleep(1);
assert_true(stbbr_verify( assert_true(stbbr_verify(
"<presence id=\"*\">" "<presence id=\"*\">"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>" "<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 void
//connect_jid_requests_roster(void **state) connect_jid_requests_bookmarks(void **state)
//{ {
// will_return(ui_ask_password, strdup("password")); prof_input("/connect stabber@localhost port 5230");
// expect_any_cons_show(); prof_input("password");
//
// cmd_process_input(strdup("/connect stabber@localhost port 5230")); sleep(1);
// prof_process_xmpp(20);
// assert_true(stbbr_verify(
// assert_true(stbbr_verify( "<iq id=\"*\" type=\"get\">"
// "<iq id=\"*\" type=\"get\"><query xmlns=\"jabber:iq:roster\"/></iq>" "<query xmlns=\"jabber:iq:private\">"
// )); "<storage xmlns=\"storage:bookmarks\"/>"
//} "</query>"
// "</iq>"
//void ));
//connect_jid_sends_presence_after_receiving_roster(void **state) }
//{
// will_return(ui_ask_password, strdup("password")); void
// expect_any_cons_show(); connect_bad_password(void **state)
// {
// stbbr_for("roster", prof_input("/connect stabber@localhost port 5230");
// "<iq id=\"roster\" type=\"result\" to=\"stabber@localhost/profanity\">" prof_input("badpassword");
// "<query xmlns=\"jabber:iq:roster\" ver=\"362\">"
// "<item jid=\"buddy1@localhost\" subscription=\"both\" name=\"Buddy1\"/>" assert_true(prof_output("Login failed."));
// "<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 //void
//show_presence_updates(void **state) //show_presence_updates(void **state)
//{ //{

View File

@@ -1,8 +1,8 @@
void connect_jid(void **state); void connect_jid(void **state);
//void connect_jid_requests_roster(void **state); void connect_jid_requests_roster(void **state);
//void connect_jid_sends_presence_after_receiving_roster(void **state); void connect_jid_sends_presence_after_receiving_roster(void **state);
//void connect_jid_requests_bookmarks(void **state); void connect_jid_requests_bookmarks(void **state);
//void connect_bad_password(void **state); void connect_bad_password(void **state);
//void show_presence_updates(void **state); //void show_presence_updates(void **state);
//void sends_rooms_iq(void **state); //void sends_rooms_iq(void **state);
//void multiple_pings(void **state); //void multiple_pings(void **state);