source: tests/check_irc.c @ 1fb3406

Last change on this file since 1fb3406 was b15cbc4, checked in by Petr Vaněk <arkamar@…>, at 2020-03-17T11:29:47Z

Make the irc test work with libevent

  • Property mode set to 100644
File size: 1.6 KB
Line 
1#include <stdlib.h>
2#include <glib.h>
3#include <gmodule.h>
4#include <check.h>
5#include <string.h>
6#include <stdio.h>
7#include "irc.h"
8#include "events.h"
9#include "testsuite.h"
10
11START_TEST(test_connect)
12{
13    GIOChannel * ch1, *ch2;
14    irc_t *irc;
15    char *raw;
16    fail_unless(g_io_channel_pair(&ch1, &ch2));
17
18    irc = irc_new(g_io_channel_unix_get_fd(ch1));
19
20    irc_free(irc);
21
22    fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
23
24    fail_if(strcmp(raw, "") != 0);
25
26    g_free(raw);
27}
28END_TEST
29
30START_TEST(test_login)
31{
32    GIOChannel * ch1, *ch2;
33    irc_t *irc;
34    char *raw;
35    fail_unless(g_io_channel_pair(&ch1, &ch2));
36
37    g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL);
38    g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL);
39
40    irc = irc_new(g_io_channel_unix_get_fd(ch1));
41
42    fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n"
43                "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
44    fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
45
46    b_main_iteration();
47    irc_free(irc);
48
49    fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
50
51    fail_unless(strstr(raw, "001") != NULL);
52    fail_unless(strstr(raw, "002") != NULL);
53    fail_unless(strstr(raw, "003") != NULL);
54    fail_unless(strstr(raw, "004") != NULL);
55    fail_unless(strstr(raw, "005") != NULL);
56
57    g_free(raw);
58}
59END_TEST
60
61Suite *irc_suite(void)
62{
63        Suite *s = suite_create("IRC");
64        TCase *tc_core = tcase_create("Core");
65
66        suite_add_tcase(s, tc_core);
67        tcase_add_test(tc_core, test_connect);
68        tcase_add_test(tc_core, test_login);
69        return s;
70}
Note: See TracBrowser for help on using the repository browser.