Changeset 6ff651b for tests/check_util.c


Ignore:
Timestamp:
2019-11-19T12:51:39Z (4 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.