added some string tests

Mon, 21 Jul 2014 13:18:32 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 21 Jul 2014 13:18:32 +0200
changeset 184
5c0990c95f74
parent 183
6a694f8f0084
child 185
a48428642b4e

added some string tests

test/string_tests.c file | annotate | diff | comparison | revisions
     1.1 --- a/test/string_tests.c	Mon Jul 21 13:04:57 2014 +0200
     1.2 +++ b/test/string_tests.c	Mon Jul 21 13:18:32 2014 +0200
     1.3 @@ -45,11 +45,15 @@
     1.4      sstr_t s2 = ST(".:.:.");
     1.5      sstr_t s3 = ST("X");
     1.6      
     1.7 -    size_t len = sstrnlen(3, s1, s2, s3);
     1.8 +    size_t len1 = sstrnlen(1, s1);
     1.9 +    size_t len2 = sstrnlen(2, s1, s2);
    1.10 +    size_t len3 = sstrnlen(3, s1, s2, s3);
    1.11      
    1.12      UCX_TEST_BEGIN
    1.13      
    1.14 -    UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size");
    1.15 +    UCX_TEST_ASSERT(len1 == 4, "sstrnlen returned wrong size");
    1.16 +    UCX_TEST_ASSERT(len2 == 9, "sstrnlen returned wrong size");
    1.17 +    UCX_TEST_ASSERT(len3 == 10, "sstrnlen returned wrong size");
    1.18  
    1.19      UCX_TEST_END
    1.20  }
    1.21 @@ -59,6 +63,9 @@
    1.22      sstr_t str = ST("I will find you - and I will kill you");
    1.23      UCX_TEST_BEGIN
    1.24      
    1.25 +    sstr_t notfound = sstrchr(str, 'x');
    1.26 +    UCX_TEST_ASSERT(notfound.length == 0, "string length not 0");
    1.27 +    
    1.28      sstr_t result = sstrchr(str, 'w');
    1.29      UCX_TEST_ASSERT(result.length == 35, "sstrchr returned wrong length");
    1.30      UCX_TEST_ASSERT(strcmp("will find you - and I will kill you", result.ptr)
    1.31 @@ -76,6 +83,8 @@
    1.32      sstr_t str = ST("compare this");
    1.33      
    1.34      UCX_TEST_BEGIN
    1.35 +    UCX_TEST_ASSERT(sstrcmp(str, S("")) == 1, "empty cmp failed");
    1.36 +    UCX_TEST_ASSERT(sstrcmp(S(""), S("")) == 0, "empty cmp false negative");
    1.37      UCX_TEST_ASSERT(sstrcmp(str, S("compare this")) == 0, "false negative");
    1.38      UCX_TEST_ASSERT(sstrcmp(str, S("Compare This")) != 0, "false positive");
    1.39      UCX_TEST_ASSERT(sstrcmp(str, S("compare tool")) < 0, "memcmp < 0 failed");
    1.40 @@ -90,6 +99,8 @@
    1.41      sstr_t str = ST("compare this");
    1.42      
    1.43      UCX_TEST_BEGIN
    1.44 +    UCX_TEST_ASSERT(sstrcasecmp(str, S("")) == 1, "empty cmp failed");
    1.45 +    UCX_TEST_ASSERT(sstrcasecmp(S(""), S("")) == 0, "empty cmp false negative");
    1.46      UCX_TEST_ASSERT(sstrcasecmp(str, S("compare this")) == 0, "false negative");
    1.47      UCX_TEST_ASSERT(sstrcasecmp(str, S("Compare This")) == 0,
    1.48          "not ignoring case");

mercurial