about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-26 01:07:47 +0100
committerJames Booth <boothj5@gmail.com>2015-05-26 01:07:47 +0100
commit940f6d5f3cbac82f652bbe74e799800c5c2bd0af (patch)
tree29c8177a5e2db49f6180f0d7d2ce6ff5aae5a562
parente4ad20132408b4a84cd4ed8465482a5ede7985e1 (diff)
downloadprofani-tty-940f6d5f3cbac82f652bbe74e799800c5c2bd0af.tar.gz
Added expect test
-rw-r--r--expecttest.c40
-rwxr-xr-xmakeexpecttest.sh1
2 files changed, 41 insertions, 0 deletions
diff --git a/expecttest.c b/expecttest.c
new file mode 100644
index 00000000..2159ed02
--- /dev/null
+++ b/expecttest.c
@@ -0,0 +1,40 @@
+#include <string.h>
+#include <assert.h>
+#include <expect.h>
+#include <stabber.h>
+
+#define CONNECT_CMD "/connect stabber@localhost port 5230\r"
+#define PASSWORD    "password\r"
+#define QUIT_CMD    "/quit\r"
+
+int main(void)
+{
+    stbbr_start(5230);
+
+    int res = 0;
+    int fd = exp_spawnl("./profanity");
+    FILE *fp = fdopen(fd, "r+");
+    setbuf(fp, (char *)0);
+
+    res = exp_expectl(fd, exp_exact, "Profanity. Type /help for help information.", 10, exp_end);
+    assert(res == 10);
+
+    write(fd, CONNECT_CMD, strlen(CONNECT_CMD));
+    res = exp_expectl(fd, exp_exact, "Enter password:", 11, exp_end);
+    assert(res == 11);
+    
+    write(fd, PASSWORD, strlen(PASSWORD));
+    res = exp_expectl(fd, exp_exact, "Connecting with account stabber@localhost", 12, exp_end);
+    assert(res == 12);
+    res = exp_expectl(fd, exp_exact, "stabber@localhost logged in successfully", 13, exp_end);
+    assert(res == 13);
+    
+    write(fd, QUIT_CMD, strlen(QUIT_CMD));
+    sleep(1);
+
+    printf("\n");
+    printf("\n");
+    printf("PID: %d\n", exp_pid);
+
+    stbbr_stop();
+}
diff --git a/makeexpecttest.sh b/makeexpecttest.sh
new file mode 100755
index 00000000..3e690a01
--- /dev/null
+++ b/makeexpecttest.sh
@@ -0,0 +1 @@
+gcc -I/usr/include/tcl8.6 expecttest.c -o expecttest -lexpect -ltcl -lstabber