complete properties.c test coverage default tip

Tue, 30 Dec 2025 22:13:44 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 30 Dec 2025 22:13:44 +0100
changeset 1683
e5399c60ae96
parent 1682
9dd7995c51bb

complete properties.c test coverage

src/properties.c file | annotate | diff | comparison | revisions
tests/test_properties.c file | annotate | diff | comparison | revisions
--- a/src/properties.c	Tue Dec 30 21:48:07 2025 +0100
+++ b/src/properties.c	Tue Dec 30 22:13:44 2025 +0100
@@ -128,7 +128,7 @@
 
             if (cxBufferAppend(input.ptr, 1,
                 len_until_nl, &prop->buffer) < len_until_nl) {
-                return CX_PROPERTIES_BUFFER_ALLOC_FAILED;
+                return CX_PROPERTIES_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
             }
 
             // advance the position in the input buffer
@@ -197,7 +197,7 @@
                 cxBufferReset(&prop->buffer);
             }
             if (cxBufferAppend(buf, 1, len, &prop->buffer) < len) {
-                return CX_PROPERTIES_BUFFER_ALLOC_FAILED;
+                return CX_PROPERTIES_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
             }
             // reset the input buffer (make way for a re-fill)
             cxBufferReset(&prop->input);
@@ -256,7 +256,7 @@
                         prop->buffer.size = 0;
                         prop->buffer.pos = 0;
                         if (cxBufferWrite(val.ptr, 1, val.length, &prop->buffer) != val.length) {
-                            return CX_PROPERTIES_BUFFER_ALLOC_FAILED;
+                            return CX_PROPERTIES_BUFFER_ALLOC_FAILED; // LCOV_EXCL_LINE
                         }
                         val.ptr = prop->buffer.space;
                         ptr = prop->buffer.space;
@@ -351,15 +351,19 @@
     while (true) {
         size_t r = fread(fillbuf, 1, cx_properties_load_fill_size, f);
         if (ferror(f)) {
+            // LCOV_EXCL_START
             status = CX_PROPERTIES_FILE_ERROR;
             break;
+            // LCOV_EXCL_STOP
         }
         if (r == 0) {
             break;
         }
         if (cxPropertiesFilln(&parser, fillbuf, r)) {
+            // LCOV_EXCL_START
             status = CX_PROPERTIES_BUFFER_ALLOC_FAILED;
             break;
+            // LCOV_EXCL_STOP
         }
         cxstring key, value;
         while (true) {
@@ -368,15 +372,19 @@
                 break;
             } else {
                 cxmutstr v = cx_strdup_a(allocator, value);
+                // LCOV_EXCL_START
                 if (v.ptr == NULL) {
                     status = CX_PROPERTIES_MAP_ERROR;
                     break;
                 }
+                // LCOV_EXCL_STOP
                 void *mv = use_cstring ? (void*)v.ptr : &v;
                 if (cxMapPut(target, key, mv)) {
+                    // LCOV_EXCL_START
                     cx_strfree(&v);
                     status = CX_PROPERTIES_MAP_ERROR;
                     break;
+                    // LCOV_EXCL_STOP
                 }
                 keys_found++;
             }
--- a/tests/test_properties.c	Tue Dec 30 21:48:07 2025 +0100
+++ b/tests/test_properties.c	Tue Dec 30 22:13:44 2025 +0100
@@ -517,6 +517,30 @@
     cxPropertiesDestroy(&prop);
 }
 
+CX_TEST(test_properties_next_alternative_delimiter) {
+    CxProperties prop;
+    CxPropertiesConfig alt_config = {0};
+    alt_config.delimiter = ':';
+    cxPropertiesInit(&prop, alt_config);
+    
+    cxstring key;
+    cxstring value;
+    CxPropertiesStatus result;
+    
+    CX_TEST_DO {
+        CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, "no_delimiter = value\n"));
+        result = cxPropertiesNext(&prop, &key,  &value);
+        CX_TEST_ASSERT(result == CX_PROPERTIES_INVALID_MISSING_DELIMITER);
+        cxPropertiesReset(&prop);
+        CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, "correct : value\n"));
+        result = cxPropertiesNext(&prop, &key,  &value);
+        CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
+        CX_TEST_ASSERT(!cx_strcmp(key, "correct"));
+        CX_TEST_ASSERT(!cx_strcmp(value, "value"));
+    }
+    cxPropertiesDestroy(&prop);
+}
+
 static FILE *cx_opentmp(char *tpl) {
 #ifdef WITH_MKSTEMP
     strcpy(tpl, "ucxtestXXXXXX");
@@ -865,6 +889,7 @@
     cx_test_register(suite, test_properties_next_starts_with_newlines);
     cx_test_register(suite, test_properties_next_line_continuation);
     cx_test_register(suite, test_properties_next_line_continuation_part);
+    cx_test_register(suite, test_properties_next_alternative_delimiter);
     cx_test_register(suite, test_properties_load);
     cx_test_register(suite, test_properties_load_empty_file);
     cx_test_register(suite, test_properties_load_only_comments);

mercurial