Add test for sending a large number of lines using transport.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 10 Apr 2008 02:00:25 +0000 (04:00 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 10 Apr 2008 02:00:25 +0000 (04:00 +0200)
testsuite/test-client.c
testsuite/test-transport.c

index 531b49e5b1255d175a6ac939fc81c8ad4313eb49..03d2891b885e0ddabb977b9cfd5b8a353bef5c8c 100644 (file)
@@ -67,7 +67,9 @@ START_TEST(test_login)
        fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\n"
                                "USER a a a a\r\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
        fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
+       fail_unless(g_io_channel_flush(ch1, NULL) == G_IO_STATUS_NORMAL);
        g_main_iteration(FALSE);
+       fail_if(c->state == NULL);
        fail_if(c->state->me.nick == NULL);
        fail_unless(!strcmp(c->state->me.nick, "bla"));
 END_TEST
index f4c8f199bc5d4b23dcbc892c22a32b72e6fdd28d..419c4671d7fd0471df6dc34b5fe11c68cbf3cc82 100644 (file)
@@ -32,11 +32,38 @@ START_TEST(test_create)
        irc_transport_new_iochannel(ch1);
 END_TEST
 
+START_TEST(test_send)
+       GIOChannel *ch1, *ch2;
+       struct irc_transport *t;
+       int i;
+       g_io_channel_pair(&ch1, &ch2);
+       g_io_channel_set_encoding(ch1, NULL, NULL);
+       g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL);
+       g_io_channel_set_buffered(ch1, FALSE);
+       t = irc_transport_new_iochannel(ch1);
+       /* saturate the buffer */
+       for (i = 0; i < 10000; i++) {
+               char buf[20];
+               snprintf(buf, sizeof(buf), "bar: %d", i);
+               fail_unless(transport_send_args(t, "PRIVMSG", "foo", buf, NULL));
+       }
+       for (i = 0; i < 10000; i++) {
+               char *str;
+               char buf[120];
+               snprintf(buf, sizeof(buf), "PRIVMSG foo :bar: %d\r\n", i);
+               if (!g_queue_is_empty(t->pending_lines))
+                       g_main_iteration(FALSE);
+               g_io_channel_read_line(ch2, &str, NULL, NULL, NULL);
+               fail_if(strcmp(str, buf));
+       }
+END_TEST
+
 Suite *transport_suite()
 {
        Suite *s = suite_create("transport");
        TCase *tc_iochannel = tcase_create("iochannel");
        suite_add_tcase(s, tc_iochannel);
        tcase_add_test(tc_iochannel, test_create);
+       tcase_add_test(tc_iochannel, test_send);
        return s;
 }