src/test.c
changeset 49 96e0f703a58c
parent 47 7d4094eb3117
child 50 46c3983638d3
--- a/src/test.c	Thu Mar 12 23:54:03 2009 +0200
+++ b/src/test.c	Fri Mar 13 00:01:12 2009 +0200
@@ -241,7 +241,7 @@
 }
 
 struct _test_irc_conn_ctx {
-    bool on_registered, on_TEST;
+    bool on_registered, on_TEST, on_error, on_quit;
 };
 
 static void _conn_on_registered (struct irc_conn *conn, void *arg)
@@ -255,6 +255,29 @@
     log_debug("registered");
 }
 
+static void _conn_on_error (struct irc_conn *conn, struct error_info *err, void *arg)
+{
+    struct _test_irc_conn_ctx *ctx = arg;
+    
+    (void) conn;
+    (void) err;
+
+    if (ctx) ctx->on_error = true;
+
+    log_debug("on_error");
+}
+
+static void _conn_on_quit (struct irc_conn *conn, void *arg)
+{
+    struct _test_irc_conn_ctx *ctx = arg;
+
+    (void) conn;
+
+    if (ctx) ctx->on_quit = true;
+
+    log_debug("on_quit");
+}
+
 static void _conn_on_TEST (const struct irc_line *line, void *arg)
 {
     struct _test_irc_conn_ctx *ctx = arg;
@@ -271,6 +294,8 @@
 
 static struct irc_conn_callbacks _conn_callbacks = {
     .on_registered      = &_conn_on_registered,
+    .on_error           = &_conn_on_error,
+    .on_quit            = &_conn_on_quit,
 };
 
 static struct irc_cmd_handler _conn_handlers[] = {
@@ -308,7 +333,7 @@
 {
     struct sock_test *sock;
     struct irc_conn *conn;
-    struct _test_irc_conn_ctx ctx = { false, false };
+    struct _test_irc_conn_ctx ctx = { false, false, false, false };
 
     // create the test socket
     assert((sock = sock_test_create()));
@@ -329,6 +354,18 @@
     sock_test_add_recv_str(sock, "PING foo\r\n");
     assert_sock_data(sock, "PONG foo\r\n");
 
+    // quit nicely
+    log_info("test QUIT");
+    assert_success(irc_conn_QUIT(conn, "bye now"));
+    assert_sock_data(sock, "QUIT :bye now\r\n");
+    assert(conn->quitting);
+
+    sock_test_add_recv_str(sock, "ERROR :Closing Link: Quit\r\n");
+    sock_test_set_recv_eof(sock);
+    assert(conn->quit && !conn->quitting && !conn->registered);
+    assert(ctx.on_quit);
+    assert(!ctx.on_error);
+
     // destroy it
     irc_conn_destroy(conn);
 }