test/string_tests.c

changeset 49
1771360b740d
parent 47
22fb97e9f58a
child 69
fb59270b1de3
--- a/test/string_tests.c	Fri Oct 05 11:52:53 2012 +0200
+++ b/test/string_tests.c	Fri Oct 05 11:55:36 2012 +0200
@@ -4,6 +4,53 @@
 
 #include "string_tests.h"
 
+UCX_TEST_IMPLEMENT(test_sstr) {
+    sstr_t s1 = sstr("1234");
+    sstr_t s2 = sstrn("ab", 2);
+    
+    UCX_TEST_BEGIN
+    
+    UCX_TEST_ASSERT(s1.length == 4, "s1 length must be 4");
+    UCX_TEST_ASSERT(s2.length == 2, "s2 length must be 2");
+    
+    UCX_TEST_END
+}
+
+UCX_TEST_IMPLEMENT(test_sstr_len_cat) {
+    sstr_t s1 = sstr("1234");
+    sstr_t s2 = sstr(".:.:.");
+    sstr_t s3 = sstr("X");
+    
+    sstr_t cat;
+    
+    size_t len = sstrnlen(3, 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 = malloc(len + 1);
+    cat.ptr[len] = 0;
+    cat.length = len;
+    
+    sstrncat(3, cat, s1, s2, s3);
+    
+    UCX_TEST_ASSERT(cat.ptr[0] == '1', "sstrncat, wrong content");
+    UCX_TEST_ASSERT(cat.ptr[1] == '2', "sstrncat, wrong content");
+    UCX_TEST_ASSERT(cat.ptr[2] == '3', "sstrncat, wrong content");
+    UCX_TEST_ASSERT(cat.ptr[3] == '4', "sstrncat, wrong content");
+    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_END
+    
+    free(cat.ptr);
+}
+
 UCX_TEST_IMPLEMENT(test_sstrsplit) {
 
     const char *original = "this,is,a,csv,string";

mercurial