about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-24 20:31:18 +0100
committerJames Booth <boothj5@gmail.com>2015-05-24 20:31:18 +0100
commite295a474dcbf1633d3b7e4e8403bbcf3e84adc90 (patch)
tree095df24f6497b749877b5ed953f8be61df896bc7
parent79ecff1c52dccf93db451635c596dedf49bf8609 (diff)
downloadprofani-tty-e295a474dcbf1633d3b7e4e8403bbcf3e84adc90.tar.gz
Added more connect tests
-rw-r--r--.gitignore3
-rw-r--r--Makefile.am10
-rw-r--r--src/common.c9
-rw-r--r--src/common.h1
-rw-r--r--stabbertests/proftest.c1
-rw-r--r--stabbertests/stabbertestsuite.c (renamed from stabbertests/testsuite.c)10
-rw-r--r--stabbertests/test_connect.c78
-rw-r--r--stabbertests/test_connect.h4
8 files changed, 107 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 6be27ed5..c3d9a977 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,4 +69,5 @@ callgrind.out.*
 gen_docs.sh
 main_fragment.html
 toc_fragment.html
-stabbertests/testsuite.trs
+stabbertests/stabbertestsuite
+stabbertests/stabbertestsuite.trs
diff --git a/Makefile.am b/Makefile.am
index d3aed4e9..cae3a268 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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)
 
diff --git a/src/common.c b/src/common.c
index 772e24d3..4fa45608 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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)
 {
diff --git a/src/common.h b/src/common.h
index 9521a701..c1aa532d 100644
--- a/src/common.h
+++ b/src/common.h
@@ -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);
diff --git a/stabbertests/proftest.c b/stabbertests/proftest.c
index d20e9f3a..e3f7f6a6 100644
--- a/stabbertests/proftest.c
+++ b/stabbertests/proftest.c
@@ -212,6 +212,7 @@ close_prof_test(void **state)
     accounts_close();
     cmd_uninit();
     log_close();
+    reset_unique_id();
 
     _cleanup_dirs();
 
diff --git a/stabbertests/testsuite.c b/stabbertests/stabbertestsuite.c
index 6905aeec..03b751ae 100644
--- a/stabbertests/testsuite.c
+++ b/stabbertests/stabbertestsuite.c
@@ -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),
diff --git a/stabbertests/test_connect.c b/stabbertests/test_connect.c
index bfc8c69a..1176a71f 100644
--- a/stabbertests/test_connect.c
+++ b/stabbertests/test_connect.c
@@ -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"));
@@ -29,6 +28,63 @@ 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=\"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)
 {
     will_return(ui_ask_password, strdup("badpassword"));
@@ -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)
 {
diff --git a/stabbertests/test_connect.h b/stabbertests/test_connect.h
index 0bf018cd..df66da05 100644
--- a/stabbertests/test_connect.h
+++ b/stabbertests/test_connect.h
@@ -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);
-