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
RevLine 
[7bcdde3]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)
[6ff651b]11{
12    GIOChannel * ch1, *ch2;
13    irc_t *irc;
14    char *raw;
15    fail_unless(g_io_channel_pair(&ch1, &ch2));
[7bcdde3]16
[6ff651b]17    irc = irc_new(g_io_channel_unix_get_fd(ch1));
[7bcdde3]18
[6ff651b]19    irc_free(irc);
[7bcdde3]20
[6ff651b]21    fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
[7bcdde3]22
[6ff651b]23    fail_if(strcmp(raw, "") != 0);
[5ebff60]24
[6ff651b]25    g_free(raw);
26}
[7bcdde3]27END_TEST
28
29START_TEST(test_login)
[6ff651b]30{
31    GIOChannel * ch1, *ch2;
32    irc_t *irc;
33    char *raw;
34    fail_unless(g_io_channel_pair(&ch1, &ch2));
[5ebff60]35
[6ff651b]36    g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL);
37    g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL);
[7bcdde3]38
[6ff651b]39    irc = irc_new(g_io_channel_unix_get_fd(ch1));
[7bcdde3]40
[6ff651b]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);
[7bcdde3]44
[6ff651b]45    g_main_iteration(FALSE);
46    irc_free(irc);
[7bcdde3]47
[6ff651b]48    fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
[7bcdde3]49
[6ff651b]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);
[7bcdde3]55
[6ff651b]56    g_free(raw);
57}
[7bcdde3]58END_TEST
59
[5ebff60]60Suite *irc_suite(void)
[7bcdde3]61{
62        Suite *s = suite_create("IRC");
63        TCase *tc_core = tcase_create("Core");
[5ebff60]64
65        suite_add_tcase(s, tc_core);
66        tcase_add_test(tc_core, test_connect);
67        tcase_add_test(tc_core, test_login);
[7bcdde3]68        return s;
69}
Note: See TracBrowser for help on using the repository browser.