test/string_tests.c

changeset 100
e0ec80179a5d
parent 98
0a752853f792
child 103
08018864fb91
--- a/test/string_tests.c	Wed Feb 27 14:52:52 2013 +0100
+++ b/test/string_tests.c	Wed Feb 27 16:59:02 2013 +0100
@@ -21,22 +21,15 @@
     sstr_t s2 = S(".:.:.");
     sstr_t s3 = S("X");
     
+    size_t len = sstrnlen(3, s1, s2, s3);
     sstr_t cat;
-    
-    size_t len = sstrnlen(3, s1, s2, s3);
+    cat.ptr = (char*) malloc(16);
+    cat.length = 16;
+    cat = sstrncat(3, cat, s1, s2, s3);
     
     UCX_TEST_BEGIN
     
-    UCX_TEST_ASSERT(len == s1.length + s2.length + s3.length,
-            "sstrnlen returned wrong size");
-    
-    len = s1.length + s2.length + s3.length;
-    
-    cat.ptr = (char*) malloc(len + 1);
-    cat.ptr[len] = 0;
-    cat.length = len;
-    
-    sstrncat(3, cat, s1, s2, s3);
+    UCX_TEST_ASSERT(len == 10, "sstrnlen returned wrong size");
     
     UCX_TEST_ASSERT(cat.ptr[0] == '1', "sstrncat, wrong content");
     UCX_TEST_ASSERT(cat.ptr[1] == '2', "sstrncat, wrong content");
@@ -45,6 +38,7 @@
     UCX_TEST_ASSERT(cat.ptr[4] == '.', "sstrncat, wrong content");
     UCX_TEST_ASSERT(cat.ptr[8] == '.', "sstrncat, wrong content");
     UCX_TEST_ASSERT(cat.ptr[9] == 'X', "sstrncat, wrong content");
+    UCX_TEST_ASSERT(cat.length == 10, "sstrncat, wrong length");
     
     UCX_TEST_END
     
@@ -176,8 +170,8 @@
 }
 
 UCX_TEST_IMPLEMENT(test_sstrtrim) {
-    sstr_t test = sstrtrim(sstr("  ein test   "));
-    sstr_t empty = sstrtrim(sstr(""));
+    sstr_t test = sstrtrim(sstr((char*)"  ein test   "));
+    sstr_t empty = sstrtrim(sstr((char*)""));
     UCX_TEST_BEGIN
     UCX_TEST_ASSERT(strncmp(test.ptr, "ein test", test.length) == 0, "failed");
     UCX_TEST_ASSERT(empty.length == 0, "empty string failed");

mercurial