about summary refs log tree commit diff stats
path: root/stabbertests
diff options
context:
space:
mode:
Diffstat (limited to 'stabbertests')
-rw-r--r--stabbertests/proftest.c18
-rw-r--r--stabbertests/test_connect.c25
-rw-r--r--stabbertests/test_connect.h3
-rw-r--r--stabbertests/testsuite.c5
4 files changed, 43 insertions, 8 deletions
diff --git a/stabbertests/proftest.c b/stabbertests/proftest.c
index 6c44a6ee..e8409907 100644
--- a/stabbertests/proftest.c
+++ b/stabbertests/proftest.c
@@ -10,6 +10,8 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <stabber.h>
+
 #include "config.h"
 
 #include "config/preferences.h"
@@ -29,6 +31,9 @@
 #define XDG_CONFIG_HOME "./stabbertests/files/xdg_config_home"
 #define XDG_DATA_HOME   "./stabbertests/files/xdg_data_home"
 
+char *config_orig;
+char *data_orig;
+
 void
 prof_process_xmpp(void)
 {
@@ -141,6 +146,14 @@ _cleanup_dirs(void)
 void
 init_prof_test(void **state)
 {
+    if (stbbr_start(5230) != 0) {
+        assert_true(FALSE);
+        return;
+    }
+
+    config_orig = getenv("XDG_CONFIG_HOME");
+    data_orig = getenv("XDG_DATA_HOME");
+
     setenv("XDG_CONFIG_HOME", XDG_CONFIG_HOME, 1);
     setenv("XDG_DATA_HOME", XDG_DATA_HOME, 1);
 
@@ -196,4 +209,9 @@ close_prof_test(void **state)
     log_close();
 
     _cleanup_dirs();
+
+    setenv("XDG_CONFIG_HOME", config_orig, 1);
+    setenv("XDG_DATA_HOME", data_orig, 1);
+
+    stbbr_stop();
 }
diff --git a/stabbertests/test_connect.c b/stabbertests/test_connect.c
index 5f4027bf..bc145da8 100644
--- a/stabbertests/test_connect.c
+++ b/stabbertests/test_connect.c
@@ -14,16 +14,11 @@
 #include "command/command.h"
 
 void
-connect_with_jid(void **state)
+connect_jid(void **state)
 {
     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));
 
@@ -35,3 +30,21 @@ connect_with_jid(void **state)
     jabber_conn_status_t status = jabber_get_connection_status();
     assert_true(status == JABBER_CONNECTED);
 }
+
+void
+connect_bad_password(void **state)
+{
+    char *connect = "/connect stabber@localhost port 5230";
+
+    stbbr_auth_passwd("password");
+    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));
+    prof_process_xmpp();
+
+    jabber_conn_status_t status = jabber_get_connection_status();
+    assert_true(status == JABBER_DISCONNECTED);
+}
diff --git a/stabbertests/test_connect.h b/stabbertests/test_connect.h
index 9716c6a9..999d9d08 100644
--- a/stabbertests/test_connect.h
+++ b/stabbertests/test_connect.h
@@ -1 +1,2 @@
-void connect_with_jid(void **state);
+void connect_jid(void **state);
+void connect_bad_password(void **state);
diff --git a/stabbertests/testsuite.c b/stabbertests/testsuite.c
index 467884ff..bde4eacf 100644
--- a/stabbertests/testsuite.c
+++ b/stabbertests/testsuite.c
@@ -15,7 +15,10 @@
 int main(int argc, char* argv[]) {
 
     const UnitTest all_tests[] = {
-        unit_test_setup_teardown(connect_with_jid,
+        unit_test_setup_teardown(connect_jid,
+            init_prof_test,
+            close_prof_test),
+        unit_test_setup_teardown(connect_bad_password,
             init_prof_test,
             close_prof_test),
     };