1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added more connect tests

This commit is contained in:
James Booth 2015-05-24 20:31:18 +01:00
parent 79ecff1c52
commit e295a474dc
8 changed files with 107 additions and 9 deletions

3
.gitignore vendored
View File

@ -69,4 +69,5 @@ callgrind.out.*
gen_docs.sh
main_fragment.html
toc_fragment.html
stabbertests/testsuite.trs
stabbertests/stabbertestsuite
stabbertests/stabbertestsuite.trs

View File

@ -131,7 +131,7 @@ stabbertest_sources = \
stabbertests/ui/stub_ui.c \
stabbertests/proftest.c stabbertests/proftest.h \
stabbertests/test_connect.c stabbertests/test_connect.h \
stabbertests/testsuite.c
stabbertests/stabbertestsuite.c
main_source = src/main.c
@ -174,12 +174,12 @@ if INCLUDE_GIT_VERSION
BUILT_SOURCES = $(git_include)
endif
TESTS = tests/testsuite stabbertests/testsuite
check_PROGRAMS = tests/testsuite stabbertests/testsuite
TESTS = tests/testsuite stabbertests/stabbertestsuite
check_PROGRAMS = tests/testsuite stabbertests/stabbertestsuite
tests_testsuite_SOURCES = $(test_sources)
tests_testsuite_LDADD = -lcmocka
stabbertests_testsuite_SOURCES = $(stabbertest_sources)
stabbertests_testsuite_LDADD = -lcmocka -lstabber -lpthread
stabbertests_stabbertestsuite_SOURCES = $(stabbertest_sources)
stabbertests_stabbertestsuite_LDADD = -lcmocka -lstabber -lpthread
man_MANS = $(man_sources)

View File

@ -57,6 +57,8 @@ struct curl_data_t
size_t size;
};
static unsigned long unique_id = 0;
static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
// taken from glib 2.30.3
@ -469,7 +471,6 @@ xdg_get_data_home(void)
char *
create_unique_id(char *prefix)
{
static unsigned long unique_id;
char *result = NULL;
GString *result_str = g_string_new("");
@ -485,6 +486,12 @@ create_unique_id(char *prefix)
return result;
}
void
reset_unique_id(void)
{
unique_id = 0;
}
char *
p_sha1_hash(char *str)
{

View File

@ -127,6 +127,7 @@ contact_presence_t contact_presence_from_resource_presence(resource_presence_t r
char * p_sha1_hash(char *str);
char * create_unique_id(char *prefix);
void reset_unique_id(void);
int cmp_win_num(gconstpointer a, gconstpointer b);
int get_next_available_win_num(GList *used);

View File

@ -212,6 +212,7 @@ close_prof_test(void **state)
accounts_close();
cmd_uninit();
log_close();
reset_unique_id();
_cleanup_dirs();

View File

@ -15,9 +15,19 @@
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),
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),

View File

@ -18,7 +18,6 @@ void
connect_jid(void **state)
{
will_return(ui_ask_password, strdup("password"));
expect_cons_show("Connecting as stabber@localhost");
cmd_process_input(strdup("/connect stabber@localhost port 5230"));
@ -28,6 +27,63 @@ connect_jid(void **state)
assert_true(status == JABBER_CONNECTED);
}
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=\"roster\" 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=\"prof_presence_1\">"
"<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"EIpsmHyMRmfAoWbsX7Q2y9zibMM=\" 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=\"bookmark_init_request\" type=\"get\">"
"<query xmlns=\"jabber:iq:private\">"
"<storage xmlns=\"storage:bookmarks\"/>"
"</query>"
"</iq>"
));
}
void
connect_bad_password(void **state)
{
@ -43,6 +99,26 @@ connect_bad_password(void **state)
assert_true(status == JABBER_DISCONNECTED);
}
//void
//connect_loads_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);
//}
void
sends_rooms_iq(void **state)
{

View File

@ -1,5 +1,7 @@
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 sends_rooms_iq(void **state);
void multiple_pings(void **state);