source: tests/check_util.c @ 9225e08

Last change on this file since 9225e08 was 2c7df62, checked in by Jelmer Vernooij <jelmer@…>, at 2006-12-06T12:15:09Z

Fix testsuite.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#include <stdlib.h>
2#include <glib.h>
3#include <gmodule.h>
4#include <check.h>
5#include <string.h>
6#include "irc.h"
7#include "set.h"
8#include "misc.h"
9
10START_TEST(test_strip_linefeed)
11{
12        int i;
13        const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL };
14        const char *expected[] = { "Test", "Test", "TestX", NULL };
15
16        for (i = 0; get[i]; i++) {
17                char copy[20];
18                strcpy(copy, get[i]);
19                strip_linefeed(copy);
20                fail_unless (strcmp(copy, expected[i]) == 0, 
21                                         "(%d) strip_linefeed broken: %s -> %s (expected: %s)", 
22                                         i, get[i], copy, expected[i]);
23        }
24}
25END_TEST
26
27START_TEST(test_strip_newlines)
28{
29        int i;
30        const char *get[] = { "Test", "Test\r\n", "Test\nX\n", NULL };
31        const char *expected[] = { "Test", "Test  ", "Test X ", NULL };
32
33        for (i = 0; get[i]; i++) {
34                char copy[20], *ret;
35                strcpy(copy, get[i]);
36                ret = strip_newlines(copy);
37                fail_unless (strcmp(copy, expected[i]) == 0, 
38                                         "(%d) strip_newlines broken: %s -> %s (expected: %s)", 
39                                         i, get[i], copy, expected[i]);
40                fail_unless (copy == ret, "Original string not returned"); 
41        }
42}
43END_TEST
44
45Suite *util_suite (void)
46{
47        Suite *s = suite_create("Util");
48        TCase *tc_core = tcase_create("Core");
49        suite_add_tcase (s, tc_core);
50        tcase_add_test (tc_core, test_strip_linefeed);
51        tcase_add_test (tc_core, test_strip_newlines);
52        return s;
53}
Note: See TracBrowser for help on using the repository browser.