source: tests/check_irc.c @ 6ff651b

Last change on this file since 6ff651b was 6ff651b, checked in by Dima <dgoldin+github@…>, at 2019-11-19T12:51:39Z

Fixing tests for libcheck 0.13.0

Since libcheck 0.13 it's mandatory to wrap the unit-test code
in a block. This updates the tests to comply with this.

This fix is backwards compatible with libcheck 0.12.

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