Changeset 6ff651b for tests


Ignore:
Timestamp:
2019-11-19T12:51:39Z (5 years ago)
Author:
Dima <dgoldin+github@…>
Branches:
master
Children:
b504415
Parents:
bcd8f52
Message:

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.

Location:
tests
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • tests/check_arc.c

    rbcd8f52 r6ff651b  
    1818};
    1919
    20 static void check_codec(int l)
     20START_TEST(check_codec)
    2121{
    2222        int i;
     
    3838        }
    3939}
     40END_TEST
    4041
    4142struct {
     
    7374};
    7475
    75 static void check_decod(int l)
     76START_TEST(check_decod)
    7677{
    7778        int i;
     
    9394        }
    9495}
     96END_TEST
    9597
    9698Suite *arc_suite(void)
  • tests/check_help.c

    rbcd8f52 r6ff651b  
    88
    99START_TEST(test_help_initfree)
    10 help_t * h, *r;
    11 r = help_init(&h, "/dev/null");
    12 fail_if(r == NULL);
    13 fail_if(r != h);
     10{
     11    help_t * h, *r;
     12    r = help_init(&h, "/dev/null");
     13    fail_if(r == NULL);
     14    fail_if(r != h);
    1415
    15 help_free(&h);
    16 fail_if(h != NULL);
     16    help_free(&h);
     17    fail_if(h != NULL);
     18}
    1719END_TEST
    1820
    1921START_TEST(test_help_nonexistent)
    20 help_t * h, *r;
    21 r = help_init(&h, "/dev/null");
    22 fail_unless(help_get(&h, "nonexistent") == NULL);
    23 fail_if(r == NULL);
     22{
     23    help_t * h, *r;
     24    r = help_init(&h, "/dev/null");
     25    fail_unless(help_get(&h, "nonexistent") == NULL);
     26    fail_if(r == NULL);
     27}
    2428END_TEST
    2529
  • tests/check_irc.c

    rbcd8f52 r6ff651b  
    99
    1010START_TEST(test_connect)
    11 GIOChannel * ch1, *ch2;
    12 irc_t *irc;
    13 char *raw;
    14 fail_unless(g_io_channel_pair(&ch1, &ch2));
     11{
     12    GIOChannel * ch1, *ch2;
     13    irc_t *irc;
     14    char *raw;
     15    fail_unless(g_io_channel_pair(&ch1, &ch2));
    1516
    16 irc = irc_new(g_io_channel_unix_get_fd(ch1));
     17    irc = irc_new(g_io_channel_unix_get_fd(ch1));
    1718
    18 irc_free(irc);
     19    irc_free(irc);
    1920
    20 fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
     21    fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
    2122
    22 fail_if(strcmp(raw, "") != 0);
     23    fail_if(strcmp(raw, "") != 0);
    2324
    24 g_free(raw);
     25    g_free(raw);
     26}
    2527END_TEST
    2628
    2729START_TEST(test_login)
    28 GIOChannel * ch1, *ch2;
    29 irc_t *irc;
    30 char *raw;
    31 fail_unless(g_io_channel_pair(&ch1, &ch2));
     30{
     31    GIOChannel * ch1, *ch2;
     32    irc_t *irc;
     33    char *raw;
     34    fail_unless(g_io_channel_pair(&ch1, &ch2));
    3235
    33 g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL);
    34 g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL);
     36    g_io_channel_set_flags(ch1, G_IO_FLAG_NONBLOCK, NULL);
     37    g_io_channel_set_flags(ch2, G_IO_FLAG_NONBLOCK, NULL);
    3538
    36 irc = irc_new(g_io_channel_unix_get_fd(ch1));
     39    irc = irc_new(g_io_channel_unix_get_fd(ch1));
    3740
    38 fail_unless(g_io_channel_write_chars(ch2, "NICK bla\r\r\n"
    39                                      "USER a a a a\n", -1, NULL, NULL) == G_IO_STATUS_NORMAL);
    40 fail_unless(g_io_channel_flush(ch2, NULL) == G_IO_STATUS_NORMAL);
     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);
    4144
    42 g_main_iteration(FALSE);
    43 irc_free(irc);
     45    g_main_iteration(FALSE);
     46    irc_free(irc);
    4447
    45 fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
     48    fail_unless(g_io_channel_read_to_end(ch2, &raw, NULL, NULL) == G_IO_STATUS_NORMAL);
    4649
    47 fail_unless(strstr(raw, "001") != NULL);
    48 fail_unless(strstr(raw, "002") != NULL);
    49 fail_unless(strstr(raw, "003") != NULL);
    50 fail_unless(strstr(raw, "004") != NULL);
    51 fail_unless(strstr(raw, "005") != NULL);
     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);
    5255
    53 g_free(raw);
     56    g_free(raw);
     57}
    5458END_TEST
    5559
  • tests/check_jabber_sasl.c

    rbcd8f52 r6ff651b  
    7878};
    7979
    80 static void check_get_part(int l)
     80START_TEST(check_get_part)
    8181{
    8282        int i;
     
    104104        }
    105105}
     106END_TEST
    106107
    107108Suite *jabber_sasl_suite(void)
  • tests/check_jabber_util.c

    rbcd8f52 r6ff651b  
    99static struct im_connection *ic;
    1010
    11 static void check_buddy_add(int l)
     11START_TEST(check_buddy_add)
    1212{
    1313        struct jabber_buddy *budw1, *budw2, *budw3, *budn, *bud;
     
    9494        fail_unless(jabber_buddy_remove(ic, "bugtest@google.com/C"));
    9595}
     96END_TEST
    9697
    97 static void check_compareJID(int l)
     98START_TEST(check_compareJID)
    9899{
    99100        fail_unless(jabber_compare_jid("bugtest@google.com/B", "bugtest@google.com/A"));
     
    106107        fail_if(jabber_compare_jid("", NULL));
    107108}
     109END_TEST
    108110
    109 static void check_hipchat_slug(int l)
     111START_TEST(check_hipchat_slug)
    110112{
    111113        int i;
     
    125127        }
    126128}
     129END_TEST
    127130
    128131Suite *jabber_util_suite(void)
  • tests/check_md5.c

    rbcd8f52 r6ff651b  
    3030};
    3131
    32 static void check_sums(int l)
     32START_TEST(check_sums)
    3333{
    3434        int i;
     
    4646        }
    4747}
     48END_TEST
    4849
    4950Suite *md5_suite(void)
  • tests/check_set.c

    rbcd8f52 r6ff651b  
    88
    99START_TEST(test_set_add)
    10 void *data = "data";
    11 set_t *s = NULL, *t;
    12 t = set_add(&s, "name", "default", NULL, data);
    13 fail_unless(s == t);
    14 fail_unless(t->data == data);
    15 fail_unless(strcmp(t->def, "default") == 0);
     10{
     11    void *data = "data";
     12    set_t *s = NULL, *t;
     13    t = set_add(&s, "name", "default", NULL, data);
     14    fail_unless(s == t);
     15    fail_unless(t->data == data);
     16    fail_unless(strcmp(t->def, "default") == 0);
     17}
    1618END_TEST
    1719
    1820START_TEST(test_set_add_existing)
    19 void *data = "data";
    20 set_t *s = NULL, *t;
    21 t = set_add(&s, "name", "default", NULL, data);
    22 t = set_add(&s, "name", "newdefault", NULL, data);
    23 fail_unless(s == t);
    24 fail_unless(strcmp(t->def, "newdefault") == 0);
     21{
     22    void *data = "data";
     23    set_t *s = NULL, *t;
     24    t = set_add(&s, "name", "default", NULL, data);
     25    t = set_add(&s, "name", "newdefault", NULL, data);
     26    fail_unless(s == t);
     27    fail_unless(strcmp(t->def, "newdefault") == 0);
     28}
    2529END_TEST
    2630
    2731START_TEST(test_set_find_unknown)
    28 set_t * s = NULL;
    29 fail_unless(set_find(&s, "foo") == NULL);
     32{
     33    set_t * s = NULL;
     34    fail_unless(set_find(&s, "foo") == NULL);
     35}
    3036END_TEST
    3137
    3238START_TEST(test_set_find)
    33 void *data = "data";
    34 set_t *s = NULL, *t;
    35 t = set_add(&s, "name", "default", NULL, data);
    36 fail_unless(s == t);
    37 fail_unless(set_find(&s, "name") == t);
     39{
     40    void *data = "data";
     41    set_t *s = NULL, *t;
     42    t = set_add(&s, "name", "default", NULL, data);
     43    fail_unless(s == t);
     44    fail_unless(set_find(&s, "name") == t);
     45}
    3846END_TEST
    3947
    4048START_TEST(test_set_get_str_default)
    41 void *data = "data";
    42 set_t *s = NULL, *t;
    43 t = set_add(&s, "name", "default", NULL, data);
    44 fail_unless(s == t);
    45 fail_unless(strcmp(set_getstr(&s, "name"), "default") == 0);
     49{
     50    void *data = "data";
     51    set_t *s = NULL, *t;
     52    t = set_add(&s, "name", "default", NULL, data);
     53    fail_unless(s == t);
     54    fail_unless(strcmp(set_getstr(&s, "name"), "default") == 0);
     55}
    4656END_TEST
    4757
    4858START_TEST(test_set_get_bool_default)
    49 void *data = "data";
    50 set_t *s = NULL, *t;
    51 t = set_add(&s, "name", "true", NULL, data);
    52 fail_unless(s == t);
    53 fail_unless(set_getbool(&s, "name"));
     59{
     60    void *data = "data";
     61    set_t *s = NULL, *t;
     62    t = set_add(&s, "name", "true", NULL, data);
     63    fail_unless(s == t);
     64    fail_unless(set_getbool(&s, "name"));
     65}
    5466END_TEST
    5567
    5668START_TEST(test_set_get_bool_integer)
    57 void *data = "data";
    58 set_t *s = NULL, *t;
    59 t = set_add(&s, "name", "3", NULL, data);
    60 fail_unless(s == t);
    61 fail_unless(set_getbool(&s, "name") == 3);
     69{
     70    void *data = "data";
     71    set_t *s = NULL, *t;
     72    t = set_add(&s, "name", "3", NULL, data);
     73    fail_unless(s == t);
     74    fail_unless(set_getbool(&s, "name") == 3);
     75}
    6276END_TEST
    6377
    6478START_TEST(test_set_get_bool_unknown)
    65 set_t * s = NULL;
    66 fail_unless(set_getbool(&s, "name") == 0);
     79{
     80    set_t * s = NULL;
     81    fail_unless(set_getbool(&s, "name") == 0);
     82}
    6783END_TEST
    6884
    6985START_TEST(test_set_get_str_value)
    70 void *data = "data";
    71 set_t *s = NULL;
    72 set_add(&s, "name", "default", NULL, data);
    73 set_setstr(&s, "name", "foo");
    74 fail_unless(strcmp(set_getstr(&s, "name"), "foo") == 0);
     86{
     87    void *data = "data";
     88    set_t *s = NULL;
     89    set_add(&s, "name", "default", NULL, data);
     90    set_setstr(&s, "name", "foo");
     91    fail_unless(strcmp(set_getstr(&s, "name"), "foo") == 0);
     92}
    7593END_TEST
    7694
    7795START_TEST(test_set_get_str_unknown)
    78 set_t * s = NULL;
    79 fail_unless(set_getstr(&s, "name") == NULL);
     96{
     97    set_t * s = NULL;
     98    fail_unless(set_getstr(&s, "name") == NULL);
     99}
    80100END_TEST
    81101
    82102START_TEST(test_setint)
    83 void *data = "data";
    84 set_t *s = NULL;
    85 set_add(&s, "name", "10", NULL, data);
    86 set_setint(&s, "name", 3);
    87 fail_unless(set_getint(&s, "name") == 3);
     103{
     104    void *data = "data";
     105    set_t *s = NULL;
     106    set_add(&s, "name", "10", NULL, data);
     107    set_setint(&s, "name", 3);
     108    fail_unless(set_getint(&s, "name") == 3);
     109}
    88110END_TEST
    89111
    90112START_TEST(test_setstr)
    91 void *data = "data";
    92 set_t *s = NULL;
    93 set_add(&s, "name", "foo", NULL, data);
    94 set_setstr(&s, "name", "bloe");
    95 fail_unless(strcmp(set_getstr(&s, "name"), "bloe") == 0);
     113{
     114    void *data = "data";
     115    set_t *s = NULL;
     116    set_add(&s, "name", "foo", NULL, data);
     117    set_setstr(&s, "name", "bloe");
     118    fail_unless(strcmp(set_getstr(&s, "name"), "bloe") == 0);
     119}
    96120END_TEST
    97121
    98122START_TEST(test_set_get_int_unknown)
    99 set_t * s = NULL;
    100 fail_unless(set_getint(&s, "foo") == 0);
     123{
     124    set_t * s = NULL;
     125    fail_unless(set_getint(&s, "foo") == 0);
     126}
    101127END_TEST
    102128
  • tests/check_util.c

    rbcd8f52 r6ff651b  
    99#include "url.h"
    1010
    11 START_TEST(test_strip_linefeed){
     11START_TEST(test_strip_linefeed)
     12{
    1213        int i;
    1314        const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL };
     
    4445
    4546START_TEST(test_set_url_http)
    46 url_t url;
    47 
    48 fail_if(0 == url_set(&url, "http://host/"));
    49 fail_unless(!strcmp(url.host, "host"));
    50 fail_unless(!strcmp(url.file, "/"));
    51 fail_unless(!strcmp(url.user, ""));
    52 fail_unless(!strcmp(url.pass, ""));
    53 fail_unless(url.proto == PROTO_HTTP);
    54 fail_unless(url.port == 80);
     47{
     48    url_t url;
     49
     50    fail_if(0 == url_set(&url, "http://host/"));
     51    fail_unless(!strcmp(url.host, "host"));
     52    fail_unless(!strcmp(url.file, "/"));
     53    fail_unless(!strcmp(url.user, ""));
     54    fail_unless(!strcmp(url.pass, ""));
     55    fail_unless(url.proto == PROTO_HTTP);
     56    fail_unless(url.port == 80);
     57}
    5558END_TEST
    5659
    5760START_TEST(test_set_url_https)
    58 url_t url;
    59 
    60 fail_if(0 == url_set(&url, "https://ahost/AimeeMann"));
    61 fail_unless(!strcmp(url.host, "ahost"));
    62 fail_unless(!strcmp(url.file, "/AimeeMann"));
    63 fail_unless(!strcmp(url.user, ""));
    64 fail_unless(!strcmp(url.pass, ""));
    65 fail_unless(url.proto == PROTO_HTTPS);
    66 fail_unless(url.port == 443);
     61{
     62    url_t url;
     63
     64    fail_if(0 == url_set(&url, "https://ahost/AimeeMann"));
     65    fail_unless(!strcmp(url.host, "ahost"));
     66    fail_unless(!strcmp(url.file, "/AimeeMann"));
     67    fail_unless(!strcmp(url.user, ""));
     68    fail_unless(!strcmp(url.pass, ""));
     69    fail_unless(url.proto == PROTO_HTTPS);
     70    fail_unless(url.port == 443);
     71}
    6772END_TEST
    6873
    6974START_TEST(test_set_url_port)
    70 url_t url;
    71 
    72 fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space"));
    73 fail_unless(!strcmp(url.host, "ahost"));
    74 fail_unless(!strcmp(url.file, "/Lost/In/Space"));
    75 fail_unless(!strcmp(url.user, ""));
    76 fail_unless(!strcmp(url.pass, ""));
    77 fail_unless(url.proto == PROTO_HTTPS);
    78 fail_unless(url.port == 200);
     75{
     76    url_t url;
     77
     78    fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space"));
     79    fail_unless(!strcmp(url.host, "ahost"));
     80    fail_unless(!strcmp(url.file, "/Lost/In/Space"));
     81    fail_unless(!strcmp(url.user, ""));
     82    fail_unless(!strcmp(url.pass, ""));
     83    fail_unless(url.proto == PROTO_HTTPS);
     84    fail_unless(url.port == 200);
     85}
    7986END_TEST
    8087
    8188START_TEST(test_set_url_username)
    82 url_t url;
    83 
    84 fail_if(0 == url_set(&url, "socks4://user@ahost/Space"));
    85 fail_unless(!strcmp(url.host, "ahost"));
    86 fail_unless(!strcmp(url.file, "/Space"));
    87 fail_unless(!strcmp(url.user, "user"));
    88 fail_unless(!strcmp(url.pass, ""));
    89 fail_unless(url.proto == PROTO_SOCKS4);
    90 fail_unless(url.port == 1080);
     89{
     90    url_t url;
     91
     92    fail_if(0 == url_set(&url, "socks4://user@ahost/Space"));
     93    fail_unless(!strcmp(url.host, "ahost"));
     94    fail_unless(!strcmp(url.file, "/Space"));
     95    fail_unless(!strcmp(url.user, "user"));
     96    fail_unless(!strcmp(url.pass, ""));
     97    fail_unless(url.proto == PROTO_SOCKS4);
     98    fail_unless(url.port == 1080);
     99}
    91100END_TEST
    92101
    93102START_TEST(test_set_url_username_pwd)
    94 url_t url;
    95 
    96 fail_if(0 == url_set(&url, "socks5://user:pass@ahost/"));
    97 fail_unless(!strcmp(url.host, "ahost"));
    98 fail_unless(!strcmp(url.file, "/"));
    99 fail_unless(!strcmp(url.user, "user"));
    100 fail_unless(!strcmp(url.pass, "pass"));
    101 fail_unless(url.proto == PROTO_SOCKS5);
    102 fail_unless(url.port == 1080);
     103{
     104    url_t url;
     105
     106    fail_if(0 == url_set(&url, "socks5://user:pass@ahost/"));
     107    fail_unless(!strcmp(url.host, "ahost"));
     108    fail_unless(!strcmp(url.file, "/"));
     109    fail_unless(!strcmp(url.user, "user"));
     110    fail_unless(!strcmp(url.pass, "pass"));
     111    fail_unless(url.proto == PROTO_SOCKS5);
     112    fail_unless(url.port == 1080);
     113}
    103114END_TEST
    104115
     
    149160
    150161START_TEST(test_word_wrap)
    151 int i;
    152 
    153 for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) {
    154         char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len);
    155 
    156         fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0,
    157                     "%s (line_len = %d) should wrap to `%s', not to `%s'",
    158                     word_wrap_tests[i].orig, word_wrap_tests[i].line_len,
    159                     word_wrap_tests[i].wrapped, wrapped);
    160 
    161         g_free(wrapped);
     162{
     163    int i;
     164
     165    for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) {
     166        char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len);
     167
     168        fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0,
     169                "%s (line_len = %d) should wrap to `%s', not to `%s'",
     170                word_wrap_tests[i].orig, word_wrap_tests[i].line_len,
     171                word_wrap_tests[i].wrapped, wrapped);
     172
     173        g_free(wrapped);
     174    }
    162175}
    163176END_TEST
    164177
    165178START_TEST(test_http_encode)
    166 char s[80];
    167 
    168 strcpy(s, "ee\xc3" "\xab" "ee!!...");
    169 http_encode(s);
    170 fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0);
     179{
     180    char s[80];
     181
     182    strcpy(s, "ee\xc3" "\xab" "ee!!...");
     183    http_encode(s);
     184    fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0);
     185}
    171186END_TEST
    172187
     
    199214
    200215START_TEST(test_split_command_parts)
    201 int i;
    202 for (i = 0; split_tests[i].command; i++) {
    203         char *cmd = g_strdup(split_tests[i].command);
    204         char **split = split_command_parts(cmd, split_tests[i].limit);
    205         char **expected = split_tests[i].expected;
    206 
    207         int j;
    208         for (j = 0; split[j] && expected[j]; j++) {
    209                 fail_unless(strcmp(split[j], expected[j]) == 0,
    210                             "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)",
    211                             i, split_tests[i].command, j, split[j], expected[j]);
    212         }
    213         g_free(cmd);
     216{
     217    int i;
     218    for (i = 0; split_tests[i].command; i++) {
     219        char *cmd = g_strdup(split_tests[i].command);
     220        char **split = split_command_parts(cmd, split_tests[i].limit);
     221        char **expected = split_tests[i].expected;
     222
     223        int j;
     224        for (j = 0; split[j] && expected[j]; j++) {
     225            fail_unless(strcmp(split[j], expected[j]) == 0,
     226                    "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)",
     227                    i, split_tests[i].command, j, split[j], expected[j]);
     228        }
     229        g_free(cmd);
     230    }
    214231}
    215232END_TEST
Note: See TracChangeset for help on using the changeset viewer.