Changeset 5ebff60 for tests/check_util.c


Ignore:
Timestamp:
2015-02-20T22:50:54Z (9 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/check_util.c

    raf359b4 r5ebff60  
    99#include "url.h"
    1010
    11 START_TEST(test_strip_linefeed)
    12 {
     11START_TEST(test_strip_linefeed){
    1312        int i;
    1413        const char *get[] = { "Test", "Test\r", "Test\rX\r", NULL };
     
    1918                strcpy(copy, get[i]);
    2019                strip_linefeed(copy);
    21                 fail_unless (strcmp(copy, expected[i]) == 0,
    22                                          "(%d) strip_linefeed broken: %s -> %s (expected: %s)",
    23                                         i, get[i], copy, expected[i]);
     20                fail_unless(strcmp(copy, expected[i]) == 0,
     21                            "(%d) strip_linefeed broken: %s -> %s (expected: %s)",
     22                            i, get[i], copy, expected[i]);
    2423        }
    2524}
     
    3635                strcpy(copy, get[i]);
    3736                ret = strip_newlines(copy);
    38                 fail_unless (strcmp(copy, expected[i]) == 0,
    39                                          "(%d) strip_newlines broken: %s -> %s (expected: %s)",
    40                                         i, get[i], copy, expected[i]);
    41                 fail_unless (copy == ret, "Original string not returned");
     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");
    4241        }
    4342}
     
    4544
    4645START_TEST(test_set_url_http)
    47         url_t url;
    48        
    49         fail_if (0 == url_set(&url, "http://host/"));
    50         fail_unless (!strcmp(url.host, "host"));
    51         fail_unless (!strcmp(url.file, "/"));
    52         fail_unless (!strcmp(url.user, ""));
    53         fail_unless (!strcmp(url.pass, ""));
    54         fail_unless (url.proto == PROTO_HTTP);
    55         fail_unless (url.port == 80);
     46url_t url;
     47
     48fail_if(0 == url_set(&url, "http://host/"));
     49fail_unless(!strcmp(url.host, "host"));
     50fail_unless(!strcmp(url.file, "/"));
     51fail_unless(!strcmp(url.user, ""));
     52fail_unless(!strcmp(url.pass, ""));
     53fail_unless(url.proto == PROTO_HTTP);
     54fail_unless(url.port == 80);
    5655END_TEST
    5756
    5857START_TEST(test_set_url_https)
    59         url_t url;
    60        
    61         fail_if (0 == url_set(&url, "https://ahost/AimeeMann"));
    62         fail_unless (!strcmp(url.host, "ahost"));
    63         fail_unless (!strcmp(url.file, "/AimeeMann"));
    64         fail_unless (!strcmp(url.user, ""));
    65         fail_unless (!strcmp(url.pass, ""));
    66         fail_unless (url.proto == PROTO_HTTPS);
    67         fail_unless (url.port == 443);
     58url_t url;
     59
     60fail_if(0 == url_set(&url, "https://ahost/AimeeMann"));
     61fail_unless(!strcmp(url.host, "ahost"));
     62fail_unless(!strcmp(url.file, "/AimeeMann"));
     63fail_unless(!strcmp(url.user, ""));
     64fail_unless(!strcmp(url.pass, ""));
     65fail_unless(url.proto == PROTO_HTTPS);
     66fail_unless(url.port == 443);
    6867END_TEST
    6968
    7069START_TEST(test_set_url_port)
    71         url_t url;
    72        
    73         fail_if (0 == url_set(&url, "https://ahost:200/Lost/In/Space"));
    74         fail_unless (!strcmp(url.host, "ahost"));
    75         fail_unless (!strcmp(url.file, "/Lost/In/Space"));
    76         fail_unless (!strcmp(url.user, ""));
    77         fail_unless (!strcmp(url.pass, ""));
    78         fail_unless (url.proto == PROTO_HTTPS);
    79         fail_unless (url.port == 200);
     70url_t url;
     71
     72fail_if(0 == url_set(&url, "https://ahost:200/Lost/In/Space"));
     73fail_unless(!strcmp(url.host, "ahost"));
     74fail_unless(!strcmp(url.file, "/Lost/In/Space"));
     75fail_unless(!strcmp(url.user, ""));
     76fail_unless(!strcmp(url.pass, ""));
     77fail_unless(url.proto == PROTO_HTTPS);
     78fail_unless(url.port == 200);
    8079END_TEST
    8180
    8281START_TEST(test_set_url_username)
    83         url_t url;
    84        
    85         fail_if (0 == url_set(&url, "socks4://user@ahost/Space"));
    86         fail_unless (!strcmp(url.host, "ahost"));
    87         fail_unless (!strcmp(url.file, "/Space"));
    88         fail_unless (!strcmp(url.user, "user"));
    89         fail_unless (!strcmp(url.pass, ""));
    90         fail_unless (url.proto == PROTO_SOCKS4);
    91         fail_unless (url.port == 1080);
     82url_t url;
     83
     84fail_if(0 == url_set(&url, "socks4://user@ahost/Space"));
     85fail_unless(!strcmp(url.host, "ahost"));
     86fail_unless(!strcmp(url.file, "/Space"));
     87fail_unless(!strcmp(url.user, "user"));
     88fail_unless(!strcmp(url.pass, ""));
     89fail_unless(url.proto == PROTO_SOCKS4);
     90fail_unless(url.port == 1080);
    9291END_TEST
    9392
    9493START_TEST(test_set_url_username_pwd)
    95         url_t url;
    96        
    97         fail_if (0 == url_set(&url, "socks5://user:pass@ahost/"));
    98         fail_unless (!strcmp(url.host, "ahost"));
    99         fail_unless (!strcmp(url.file, "/"));
    100         fail_unless (!strcmp(url.user, "user"));
    101         fail_unless (!strcmp(url.pass, "pass"));
    102         fail_unless (url.proto == PROTO_SOCKS5);
    103         fail_unless (url.port == 1080);
    104 END_TEST
    105 
    106 struct
    107 {
     94url_t url;
     95
     96fail_if(0 == url_set(&url, "socks5://user:pass@ahost/"));
     97fail_unless(!strcmp(url.host, "ahost"));
     98fail_unless(!strcmp(url.file, "/"));
     99fail_unless(!strcmp(url.user, "user"));
     100fail_unless(!strcmp(url.pass, "pass"));
     101fail_unless(url.proto == PROTO_SOCKS5);
     102fail_unless(url.port == 1080);
     103END_TEST
     104
     105struct {
    108106        char *orig;
    109107        int line_len;
     
    146144
    147145START_TEST(test_word_wrap)
    148         int i;
    149        
    150         for( i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i ++ )
    151         {
    152                 char *wrapped = word_wrap( word_wrap_tests[i].orig, word_wrap_tests[i].line_len );
    153                
    154                 fail_unless( strcmp( word_wrap_tests[i].wrapped, wrapped ) == 0,
    155                              "%s (line_len = %d) should wrap to `%s', not to `%s'",
    156                              word_wrap_tests[i].orig, word_wrap_tests[i].line_len,
    157                              word_wrap_tests[i].wrapped, wrapped );
    158                
    159                 g_free( wrapped );
    160         }
     146int i;
     147
     148for (i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i++) {
     149        char *wrapped = word_wrap(word_wrap_tests[i].orig, word_wrap_tests[i].line_len);
     150
     151        fail_unless(strcmp(word_wrap_tests[i].wrapped, wrapped) == 0,
     152                    "%s (line_len = %d) should wrap to `%s', not to `%s'",
     153                    word_wrap_tests[i].orig, word_wrap_tests[i].line_len,
     154                    word_wrap_tests[i].wrapped, wrapped);
     155
     156        g_free(wrapped);
     157}
    161158END_TEST
    162159
    163160START_TEST(test_http_encode)
    164         char s[80];
    165        
    166         strcpy( s, "ee\xc3""\xab""ee!!..." );
    167         http_encode( s );
    168         fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0 );
     161char s[80];
     162
     163strcpy(s, "ee\xc3" "\xab" "ee!!...");
     164http_encode(s);
     165fail_unless(strcmp(s, "ee%C3%ABee%21%21...") == 0);
    169166END_TEST
    170167
     
    172169        int limit;
    173170        char *command;
    174         char *expected[IRC_MAX_ARGS+1];
     171        char *expected[IRC_MAX_ARGS + 1];
    175172} split_tests[] = {
    176173        {
    177174                0, "account add etc \"user name with spaces\" 'pass\\ word'",
    178                 {"account", "add", "etc", "user name with spaces", "pass\\ word", NULL},
     175                { "account", "add", "etc", "user name with spaces", "pass\\ word", NULL },
    179176        },
    180177        {
    181178                0, "channel set group Close\\ friends",
    182                 {"channel", "set", "group", "Close friends", NULL},
     179                { "channel", "set", "group", "Close friends", NULL },
    183180        },
    184181        {
    185182                2, "reply wilmer \"testing in C is a PITA\", you said.",
    186                 {"reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL},
     183                { "reply", "wilmer", "\"testing in C is a PITA\", you said.", NULL },
    187184        },
    188185        {
    189186                4, "one space  two  spaces  limit  limit",
    190                 {"one", "space", "two", "spaces", "limit  limit", NULL},
     187                { "one", "space", "two", "spaces", "limit  limit", NULL },
    191188        },
    192189        {
    193190                0, NULL,
    194                 {NULL}
     191                { NULL }
    195192        },
    196193};
    197194
    198195START_TEST(test_split_command_parts)
    199         int i;
    200         for (i = 0; split_tests[i].command; i++) {
    201                 char *cmd = g_strdup(split_tests[i].command);
    202                 char **split = split_command_parts(cmd, split_tests[i].limit);
    203                 char **expected = split_tests[i].expected;
    204 
    205                 int j;
    206                 for (j = 0; split[j] && expected[j]; j++) {
    207                         fail_unless (strcmp(split[j], expected[j]) == 0,
    208                                 "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)",
    209                                 i, split_tests[i].command, j, split[j], expected[j]);
    210                 }
    211                 g_free(cmd);
    212         }
    213 END_TEST
    214 
    215 Suite *util_suite (void)
     196int i;
     197for (i = 0; split_tests[i].command; i++) {
     198        char *cmd = g_strdup(split_tests[i].command);
     199        char **split = split_command_parts(cmd, split_tests[i].limit);
     200        char **expected = split_tests[i].expected;
     201
     202        int j;
     203        for (j = 0; split[j] && expected[j]; j++) {
     204                fail_unless(strcmp(split[j], expected[j]) == 0,
     205                            "(%d) split_command_parts broken: split(\"%s\")[%d] -> %s (expected: %s)",
     206                            i, split_tests[i].command, j, split[j], expected[j]);
     207        }
     208        g_free(cmd);
     209}
     210END_TEST
     211
     212Suite *util_suite(void)
    216213{
    217214        Suite *s = suite_create("Util");
    218215        TCase *tc_core = tcase_create("Core");
    219         suite_add_tcase (s, tc_core);
    220         tcase_add_test (tc_core, test_strip_linefeed);
    221         tcase_add_test (tc_core, test_strip_newlines);
    222         tcase_add_test (tc_core, test_set_url_http);
    223         tcase_add_test (tc_core, test_set_url_https);
    224         tcase_add_test (tc_core, test_set_url_port);
    225         tcase_add_test (tc_core, test_set_url_username);
    226         tcase_add_test (tc_core, test_set_url_username_pwd);
    227         tcase_add_test (tc_core, test_word_wrap);
    228         tcase_add_test (tc_core, test_http_encode);
    229         tcase_add_test (tc_core, test_split_command_parts);
     216
     217        suite_add_tcase(s, tc_core);
     218        tcase_add_test(tc_core, test_strip_linefeed);
     219        tcase_add_test(tc_core, test_strip_newlines);
     220        tcase_add_test(tc_core, test_set_url_http);
     221        tcase_add_test(tc_core, test_set_url_https);
     222        tcase_add_test(tc_core, test_set_url_port);
     223        tcase_add_test(tc_core, test_set_url_username);
     224        tcase_add_test(tc_core, test_set_url_username_pwd);
     225        tcase_add_test(tc_core, test_word_wrap);
     226        tcase_add_test(tc_core, test_http_encode);
     227        tcase_add_test(tc_core, test_split_command_parts);
    230228        return s;
    231229}
Note: See TracChangeset for help on using the changeset viewer.