added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build

Mon, 26 Oct 2015 14:09:45 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 26 Oct 2015 14:09:45 +0100
changeset 213
fa8b745be7b5
parent 212
c766c423dee6
child 214
2bc19726c340

added important test case to sstrsplit and fixed bug with consecutively occurring delimiters + fixed build system not linking test binary with newest library build

Makefile file | annotate | diff | comparison | revisions
test/Makefile file | annotate | diff | comparison | revisions
test/string_tests.c file | annotate | diff | comparison | revisions
ucx/string.c file | annotate | diff | comparison | revisions
--- a/Makefile	Thu Oct 22 11:35:40 2015 +0200
+++ b/Makefile	Mon Oct 26 14:09:45 2015 +0100
@@ -49,16 +49,16 @@
 ucx-debug: FORCE
 	cd ucx; $(MAKE) CONF=$(CONF) debug
 	
-test: FORCE ucx
+test: ucx
 	cd test; $(MAKE) CONF=$(CONF)
 
-test-debug: FORCE ucx-debug
+test-debug: ucx-debug
 	cd test; $(MAKE) CONF=$(CONF) debug
 
-run: FORCE test
+run: test
 	./build/release/test/ucxtest$(APP_EXT)
 	
-run-debug: FORCE test-debug
+run-debug: test-debug
 	./build/debug/test/ucxtest$(APP_EXT)
 	
 debug: ucx-debug test-debug
--- a/test/Makefile	Thu Oct 22 11:35:40 2015 +0200
+++ b/test/Makefile	Mon Oct 26 14:09:45 2015 +0100
@@ -47,7 +47,7 @@
 all: ../build/release/test ../build/release/test/ucxtest$(APP_EXT)
 debug: ../build/debug/test ../build/debug/test/ucxtest$(APP_EXT)
 
-../build/release/test/ucxtest$(APP_EXT): $(OBJ)
+../build/release/test/ucxtest$(APP_EXT): FORCE $(OBJ)
 	$(LD) $(LDFLAGS) -o ../build/release/test/ucxtest$(APP_EXT) \
 		$(OBJ) ../build/release/libucx$(LIB_EXT)
 
@@ -57,7 +57,7 @@
 ../build/release/test:
 	$(MKDIR) $(MKDIRFLAGS) ../build/release/test
 
-../build/debug/test/ucxtest$(APP_EXT): $(OBJ_D)
+../build/debug/test/ucxtest$(APP_EXT): FORCE $(OBJ_D)
 	$(LD) $(LDFLAGS) -o ../build/debug/test/ucxtest$(APP_EXT) \
 		$(OBJ_D) ../build/debug/libucx$(LIB_EXT)
 
@@ -66,3 +66,7 @@
 
 ../build/debug/test:
 	$(MKDIR) $(MKDIRFLAGS) ../build/debug/test
+
+# force rebuild of test binary (library might have been changed)
+FORCE:
+	
--- a/test/string_tests.c	Thu Oct 22 11:35:40 2015 +0200
+++ b/test/string_tests.c	Mon Oct 26 14:09:45 2015 +0100
@@ -293,6 +293,19 @@
         free(list[i].ptr);
     }
     free(list);
+    
+    /* double encounter delimiter (ded) */
+    n = 0;
+    list = sstrsplit(test, S("is,"), &n);
+    UCX_TEST_ASSERT(n == 3, "ded, list length must be 3");
+    UCX_TEST_ASSERT(strcmp(list[0].ptr, "th") == 0, "ded, item 0 mismatch");
+    UCX_TEST_ASSERT(list[1].length == 0, "ded, item 1 not empty!");
+    UCX_TEST_ASSERT(strcmp(list[2].ptr, "a,csv,string") == 0,
+        "ded, item 2 mismatch");
+    for(int i=0;i<n;i++) {
+        free(list[i].ptr);
+    }
+    free(list);
 
     UCX_TEST_END
 }
--- a/ucx/string.c	Thu Oct 22 11:35:40 2015 +0200
+++ b/ucx/string.c	Mon Oct 26 14:09:45 2015 +0100
@@ -216,7 +216,7 @@
                 for (size_t j = 0 ; j < d.length ; j++) {
                     sv.ptr[i+j] = 0;
                 }
-                i += d.length;
+                i += d.length - 1; // -1, because the loop will do a i++
             }
         }
         if ((*n) == nmax) break;

mercurial