about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-29 01:01:34 +0100
committerJames Booth <boothj5@gmail.com>2015-05-29 01:01:34 +0100
commita522d0225d7de9124ebbd18188ef9758c60cc8f5 (patch)
treeedbcfa8c196f0b0527a084faee2b4d6024f7560e
parentf17afcf5d421ee987cd2f4fe45cf7d3ad25a6eb9 (diff)
downloadprofani-tty-a522d0225d7de9124ebbd18188ef9758c60cc8f5.tar.gz
Added regex output matcher, presence test
-rw-r--r--Makefile.am1
-rw-r--r--functionaltests/functionaltests.c8
-rw-r--r--functionaltests/proftest.c8
-rw-r--r--functionaltests/proftest.h5
-rw-r--r--functionaltests/test_connect.c14
-rw-r--r--functionaltests/test_ping.c6
-rw-r--r--functionaltests/test_presence.c47
-rw-r--r--functionaltests/test_presence.h2
-rw-r--r--functionaltests/test_rooms.c4
9 files changed, 80 insertions, 15 deletions
diff --git a/Makefile.am b/Makefile.am
index 93d2fec0..a2b46a9c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -99,6 +99,7 @@ functionaltest_sources = \
 	functionaltests/test_connect.c functionaltests/test_connect.h \
 	functionaltests/test_ping.c functionaltests/test_ping.h \
 	functionaltests/test_rooms.c functionaltests/test_rooms.h \
+	functionaltests/test_presence.c functionaltests/test_presence.h \
 	functionaltests/functionaltests.c
 
 main_source = src/main.c
diff --git a/functionaltests/functionaltests.c b/functionaltests/functionaltests.c
index 6c627d38..668445cd 100644
--- a/functionaltests/functionaltests.c
+++ b/functionaltests/functionaltests.c
@@ -13,6 +13,7 @@
 #include "test_connect.h"
 #include "test_ping.h"
 #include "test_rooms.h"
+#include "test_presence.h"
 
 int main(int argc, char* argv[]) {
 
@@ -47,6 +48,13 @@ int main(int argc, char* argv[]) {
         unit_test_setup_teardown(rooms_query,
             init_prof_test,
             close_prof_test),
+
+        unit_test_setup_teardown(presence_away,
+            init_prof_test,
+            close_prof_test),
+        unit_test_setup_teardown(presence_away_with_message,
+            init_prof_test,
+            close_prof_test),
     };
 
     return run_tests(all_tests);
diff --git a/functionaltests/proftest.c b/functionaltests/proftest.c
index a5510d68..94b0c2b3 100644
--- a/functionaltests/proftest.c
+++ b/functionaltests/proftest.c
@@ -178,11 +178,17 @@ prof_input(char *input)
 }
 
 int
-prof_output(char *text)
+prof_output_exact(char *text)
 {
     return (1 == exp_expectl(fd, exp_exact, text, 1, exp_end));
 }
 
+int
+prof_output_regex(char *text)
+{
+    return (1 == exp_expectl(fd, exp_regexp, text, 1, exp_end));
+}
+
 void
 prof_connect(char *jid, char *password)
 {
diff --git a/functionaltests/proftest.h b/functionaltests/proftest.h
index 68574af6..f57f6c35 100644
--- a/functionaltests/proftest.h
+++ b/functionaltests/proftest.h
@@ -7,10 +7,11 @@
 void init_prof_test(void **state);
 void close_prof_test(void **state);
 
-
 void prof_start(void);
 void prof_connect(char *jid, char *password);
 void prof_input(char *input);
-int prof_output(char *text);
+
+int prof_output_exact(char *text);
+int prof_output_regex(char *text);
 
 #endif
diff --git a/functionaltests/test_connect.c b/functionaltests/test_connect.c
index fc2d0f94..957d2798 100644
--- a/functionaltests/test_connect.c
+++ b/functionaltests/test_connect.c
@@ -16,8 +16,8 @@ connect_jid(void **state)
 {
     prof_connect("stabber@localhost", "password");
 
-    assert_true(prof_output("Connecting as stabber@localhost"));
-    assert_true(prof_output("stabber@localhost logged in successfully"));
+    assert_true(prof_output_exact("Connecting as stabber@localhost"));
+    assert_true(prof_output_regex("stabber@localhost logged in successfully, .+online.+ \\(priority 0\\)\\."));
 }
 
 void
@@ -70,7 +70,7 @@ connect_bad_password(void **state)
 {
     prof_connect("stabber@localhost", "badpassword");
 
-    assert_true(prof_output("Login failed."));
+    assert_true(prof_output_exact("Login failed."));
 }
 
 void
@@ -102,9 +102,9 @@ connect_shows_presence_updates(void **state)
 
     prof_connect("stabber@localhost", "password");
 
-    assert_true(prof_output("Buddy1 (mobile) is dnd, \"busy!\""));
-    assert_true(prof_output("Buddy1 (laptop) is chat, \"Talk to me!\""));
-    assert_true(prof_output("Buddy2 (work) is away, \"Out of office\""));
+    assert_true(prof_output_exact("Buddy1 (mobile) is dnd, \"busy!\""));
+    assert_true(prof_output_exact("Buddy1 (laptop) is chat, \"Talk to me!\""));
+    assert_true(prof_output_exact("Buddy2 (work) is away, \"Out of office\""));
 
     stbbr_send(
         "<presence to=\"stabber@localhost\" from=\"buddy1@localhost/mobile\">"
@@ -113,5 +113,5 @@ connect_shows_presence_updates(void **state)
         "</presence>"
     );
 
-    assert_true(prof_output("Buddy1 (mobile) is xa, \"Gone :(\""));
+    assert_true(prof_output_exact("Buddy1 (mobile) is xa, \"Gone :(\""));
 }
diff --git a/functionaltests/test_ping.c b/functionaltests/test_ping.c
index 19a1e413..c1b398d8 100644
--- a/functionaltests/test_ping.c
+++ b/functionaltests/test_ping.c
@@ -29,7 +29,7 @@ ping_multiple(void **state)
             "<ping xmlns=\"urn:xmpp:ping\"/>"
         "</iq>"
     ));
-    assert_true(prof_output("Ping response from server"));
+    assert_true(prof_output_exact("Ping response from server"));
 
     prof_input("/ping");
     assert_true(stbbr_received(
@@ -37,7 +37,7 @@ ping_multiple(void **state)
             "<ping xmlns=\"urn:xmpp:ping\"/>"
         "</iq>"
     ));
-    assert_true(prof_output("Ping response from server"));
+    assert_true(prof_output_exact("Ping response from server"));
 }
 
 void
@@ -45,7 +45,7 @@ ping_responds(void **state)
 {
     prof_connect("stabber@localhost", "password");
 
-    assert_true(prof_output("stabber@localhost logged in successfully"));
+    assert_true(prof_output_exact("stabber@localhost logged in successfully"));
 
     stbbr_send(
         "<iq id=\"pingtest1\" type=\"get\" to=\"stabber@localhost/profanity\" from=\"localhost\">"
diff --git a/functionaltests/test_presence.c b/functionaltests/test_presence.c
new file mode 100644
index 00000000..1334fe91
--- /dev/null
+++ b/functionaltests/test_presence.c
@@ -0,0 +1,47 @@
+#include <glib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <stabber.h>
+#include <expect.h>
+
+#include "proftest.h"
+
+void
+presence_away(void **state)
+{
+    prof_connect("stabber@localhost", "password");
+
+    prof_input("/away");
+
+    assert_true(stbbr_received(
+    "<presence id=\"*\">"
+        "<show>away</show>"
+        "<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
+    "</presence>"
+    ));
+
+    assert_true(prof_output_exact("Status set to away (priority 0)"));
+}
+
+void
+presence_away_with_message(void **state)
+{
+    prof_connect("stabber@localhost", "password");
+
+    prof_input("/away \"I'm not here for a bit\"");
+
+    assert_true(stbbr_received(
+    "<presence id=\"*\">"
+        "<show>away</show>"
+        "<status>I'm not here for a bit</status>"
+        "<c hash=\"sha-1\" xmlns=\"http://jabber.org/protocol/caps\" ver=\"*\" node=\"http://www.profanity.im\"/>"
+    "</presence>"
+    ));
+
+    assert_true(prof_output_exact("Status set to away (priority 0), \"I'm not here for a bit\"."));
+}
diff --git a/functionaltests/test_presence.h b/functionaltests/test_presence.h
new file mode 100644
index 00000000..f199ab41
--- /dev/null
+++ b/functionaltests/test_presence.h
@@ -0,0 +1,2 @@
+void presence_away(void **state);
+void presence_away_with_message(void **state);
diff --git a/functionaltests/test_rooms.c b/functionaltests/test_rooms.c
index c6097a54..313d7a72 100644
--- a/functionaltests/test_rooms.c
+++ b/functionaltests/test_rooms.c
@@ -33,6 +33,6 @@ rooms_query(void **state)
         "</iq>"
     ));
 
-    assert_true(prof_output("chatroom@conference.localhost, (A chat room)"));
-    assert_true(prof_output("hangout@conference.localhost, (Another chat room)"));
+    assert_true(prof_output_exact("chatroom@conference.localhost, (A chat room)"));
+    assert_true(prof_output_exact("hangout@conference.localhost, (Another chat room)"));
 }