about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-17 22:05:43 +0100
committerJames Booth <boothj5@gmail.com>2015-05-17 22:05:43 +0100
commit2c5b44421e1b3a163ce33249f9d0b1567d411b16 (patch)
tree5ba771ddcc003ef7d86e9585c87dd4b11af44f5a
parent97c5072f56b992d3bf2e4c3550a8010f9638b80a (diff)
downloadprofani-tty-2c5b44421e1b3a163ce33249f9d0b1567d411b16.tar.gz
Added initial stabber test
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac3
-rw-r--r--src/config/preferences.c4
-rw-r--r--src/config/theme.c5
-rw-r--r--src/profanity.c2
-rw-r--r--src/xmpp/connection.c9
-rw-r--r--src/xmpp/xmpp.h2
-rw-r--r--stabbertests/proftest.c11
-rw-r--r--stabbertests/proftest.h1
-rw-r--r--stabbertests/test_connect.c31
-rw-r--r--stabbertests/test_connect.h2
-rw-r--r--stabbertests/testsuite.c2
-rw-r--r--tests/xmpp/stub_xmpp.c2
13 files changed, 60 insertions, 16 deletions
diff --git a/Makefile.am b/Makefile.am
index e3ffc654..d3aed4e9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -179,7 +179,7 @@ check_PROGRAMS = tests/testsuite stabbertests/testsuite
 tests_testsuite_SOURCES = $(test_sources)
 tests_testsuite_LDADD = -lcmocka
 stabbertests_testsuite_SOURCES = $(stabbertest_sources)
-stabbertests_testsuite_LDADD = -lcmocka -lstabber
+stabbertests_testsuite_LDADD = -lcmocka -lstabber -lpthread
 
 man_MANS = $(man_sources)
 
diff --git a/configure.ac b/configure.ac
index 1e2c6173..e4558c02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -235,6 +235,9 @@ AM_CONDITIONAL([THEMES_INSTALL], "$THEMES_INSTALL")
 PKG_CHECK_MODULES([cmocka], [cmocka], [],
     [AC_MSG_NOTICE([cmocka is not found, will not be able to run tests])])
 
+AC_CHECK_LIB([stabber], [stbbr_start], [],
+    [AC_MSG_ERROR([stabber not found, will not be able to run tests])])
+
 ### Check for ncursesw/ncurses.h first, Arch linux uses ncurses.h for ncursesw
 AC_CHECK_HEADERS([ncursesw/ncurses.h], [], [])
 AC_CHECK_HEADERS([ncurses.h], [], [])
diff --git a/src/config/preferences.c b/src/config/preferences.c
index 59a6a7ca..36a04a8f 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -82,7 +82,7 @@ prefs_load(void)
 {
     GError *err;
 
-    log_info("Loading preferences");
+//    log_info("Loading preferences");
     prefs_loc = _get_preferences_file();
 
     if (g_file_test(prefs_loc, G_FILE_TEST_EXISTS)) {
@@ -739,4 +739,4 @@ _get_default_string(preference_t pref)
         default:
             return NULL;
     }
-}
\ No newline at end of file
+}
diff --git a/src/config/theme.c b/src/config/theme.c
index f73dee19..aeee4463 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -207,12 +207,15 @@ theme_close(void)
 {
     if (theme) {
         g_key_file_free(theme);
+        theme = NULL;
     }
     if (theme_loc) {
         g_string_free(theme_loc, TRUE);
+        theme_loc = NULL;
     }
     if (bold_items) {
         g_hash_table_destroy(bold_items);
+        bold_items = NULL;
     }
 }
 
@@ -613,4 +616,4 @@ theme_attrs(theme_item_t attrs)
         return result;
 
     }
-}
\ No newline at end of file
+}
diff --git a/src/profanity.c b/src/profanity.c
index 55a73430..0908c658 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -100,7 +100,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
         otr_poll();
 #endif
         notify_remind();
-        jabber_process_events();
+        jabber_process_events(10);
         ui_update();
     }
 }
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 70d49b7c..8fa83144 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -194,7 +194,7 @@ jabber_disconnect(void)
         xmpp_disconnect(jabber_conn.conn);
 
         while (jabber_get_connection_status() == JABBER_DISCONNECTING) {
-            jabber_process_events();
+            jabber_process_events(10);
         }
         _connection_free_saved_account();
         _connection_free_saved_details();
@@ -222,10 +222,11 @@ jabber_shutdown(void)
     _connection_free_session_data();
     xmpp_shutdown();
     free(jabber_conn.log);
+    jabber_conn.log = NULL;
 }
 
 void
-jabber_process_events(void)
+jabber_process_events(int millis)
 {
     int reconnect_sec;
 
@@ -234,7 +235,7 @@ jabber_process_events(void)
         case JABBER_CONNECTED:
         case JABBER_CONNECTING:
         case JABBER_DISCONNECTING:
-            xmpp_run_once(jabber_conn.ctx, 10);
+            xmpp_run_once(jabber_conn.ctx, millis);
             break;
         case JABBER_DISCONNECTED:
             reconnect_sec = prefs_get_reconnect();
@@ -577,4 +578,4 @@ _xmpp_get_file_logger()
     file_log->userdata = &level;
 
     return file_log;
-}
\ No newline at end of file
+}
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 398c9f46..6b985b08 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -136,7 +136,7 @@ jabber_conn_status_t jabber_connect_with_details(const char * const jid,
 jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account);
 void jabber_disconnect(void);
 void jabber_shutdown(void);
-void jabber_process_events(void);
+void jabber_process_events(int millis);
 const char * jabber_get_fulljid(void);
 const char * jabber_get_domain(void);
 jabber_conn_status_t jabber_get_connection_status(void);
diff --git a/stabbertests/proftest.c b/stabbertests/proftest.c
index d15b9cbf..d5fdeb0a 100644
--- a/stabbertests/proftest.c
+++ b/stabbertests/proftest.c
@@ -25,10 +25,19 @@
 #include "otr/otr.h"
 #endif
 
-
 #define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home"
 #define XDG_DATA_HOME   "./stabbertests/files/xdg_data_home"
 
+void
+prof_process_xmpp(void)
+{
+    int i = 0;
+    while (i < 20) {
+        jabber_process_events(10);
+        i++;
+    }
+}
+
 gboolean
 _create_dir(char *name)
 {
diff --git a/stabbertests/proftest.h b/stabbertests/proftest.h
index d35daae4..e0b6dded 100644
--- a/stabbertests/proftest.h
+++ b/stabbertests/proftest.h
@@ -1,2 +1,3 @@
 void init_prof_test(void **state);
 void close_prof_test(void **state);
+void prof_process_xmpp(void);
diff --git a/stabbertests/test_connect.c b/stabbertests/test_connect.c
index 1ddc9849..7a5c464a 100644
--- a/stabbertests/test_connect.c
+++ b/stabbertests/test_connect.c
@@ -4,9 +4,36 @@
 #include <setjmp.h>
 #include <cmocka.h>
 #include <stdlib.h>
+#include <string.h>
+
+#include <stabber.h>
+
+#include "proftest.h"
+#include "xmpp/xmpp.h"
+#include "ui/stub_ui.h"
+#include "command/command.h"
 
 void
-connect_with_no_jid(void **state)
+connect_with_jid(void **state)
 {
-    assert_true(1);
+    char *connect = "/connect stabber@localhost port 5230";
+    char *password = "password";
+
+    if (stbbr_start(5230) != 0) {
+        assert_true(FALSE);
+        return;
+    }
+
+    stbbr_auth_passwd(password);
+    will_return(ui_ask_password, strdup(password));
+
+    expect_cons_show("Connecting as stabber@localhost");
+
+    cmd_process_input(strdup(connect));
+    prof_process_xmpp();
+
+    jabber_conn_status_t status = jabber_get_connection_status();
+    assert_true(status == JABBER_CONNECTED);
+
+    stbbr_stop();
 }
diff --git a/stabbertests/test_connect.h b/stabbertests/test_connect.h
index 887cec73..9716c6a9 100644
--- a/stabbertests/test_connect.h
+++ b/stabbertests/test_connect.h
@@ -1 +1 @@
-void connect_with_no_jid(void **state);
+void connect_with_jid(void **state);
diff --git a/stabbertests/testsuite.c b/stabbertests/testsuite.c
index e4a220d7..467884ff 100644
--- a/stabbertests/testsuite.c
+++ b/stabbertests/testsuite.c
@@ -15,7 +15,7 @@
 int main(int argc, char* argv[]) {
 
     const UnitTest all_tests[] = {
-        unit_test_setup_teardown(connect_with_no_jid,
+        unit_test_setup_teardown(connect_with_jid,
             init_prof_test,
             close_prof_test),
     };
diff --git a/tests/xmpp/stub_xmpp.c b/tests/xmpp/stub_xmpp.c
index cc9580bf..d3be1af6 100644
--- a/tests/xmpp/stub_xmpp.c
+++ b/tests/xmpp/stub_xmpp.c
@@ -26,7 +26,7 @@ jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const accou
 
 void jabber_disconnect(void) {}
 void jabber_shutdown(void) {}
-void jabber_process_events(void) {}
+void jabber_process_events(int millis) {}
 const char * jabber_get_fulljid(void)
 {
     return (char *)mock();