diff -r cc204fc56c9c -r a9a1d07a6840 tests/test_properties.c --- a/tests/test_properties.c Sat Nov 02 13:48:53 2024 +0100 +++ b/tests/test_properties.c Sat Nov 02 19:27:45 2024 +0100 @@ -96,7 +96,7 @@ cxstring value; CX_TEST_DO { for (int i = 0; i < 10; i++) { - cxPropertiesInput(&prop, tests[i], strlen(tests[i])); + cxPropertiesFill(&prop, tests[i]); CX_TEST_ASSERT(prop.text == tests[i]); CX_TEST_ASSERT(prop.text_size == strlen(tests[i])); CX_TEST_ASSERT(prop.text_pos == 0); @@ -115,29 +115,42 @@ cxPropertiesDestroy(&prop); } -CX_TEST(test_properties_next_multi) { +CX_TEST_SUBROUTINE(test_properties_next_multi_check, CxProperties *prop) { const char *keys[] = { - "a", - "b", - "c", - "uap", - "name", - "key1", - "key2", - "key3" + "a", + "b", + "c", + "uap", + "name", + "key1", + "key2", + "key3" }; const char *values[] = { - "a value", - "b value", - "core", - "core", - "ucx", - "value1", - "value2", - "value3" + "a value", + "b value", + "core", + "core", + "ucx", + "value1", + "value2", + "value3" }; + CxPropertiesStatus result; + cxstring key; + cxstring value; + for (int i = 0; i < 8; i++) { + result = cxPropertiesNext(prop, &key, &value); + CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); + CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i]))); + CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i]))); + } + result = cxPropertiesNext(prop, &key, &value); + CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); +} +CX_TEST(test_properties_next_multi) { const char *str = "#\n" "# properties\n" "# contains key/value pairs\n" @@ -157,22 +170,25 @@ CxProperties prop; cxPropertiesInitDefault(&prop); - CxPropertiesStatus result; - cxstring key; - cxstring value; CX_TEST_DO { + CxPropertiesStatus result; + cxstring key; + cxstring value; result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NULL_INPUT); - cxPropertiesInput(&prop, str, strlen(str)); - for (int i = 0; i < 8; i++) { - result = cxPropertiesNext(&prop, &key, &value); - CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); - CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i]))); - CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i]))); - } - result = cxPropertiesNext(&prop, &key, &value); - CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); + + // check for C string + cxPropertiesFill(&prop, str); + CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop); + + // check for cxstring + cxPropertiesFill(&prop, cx_str(str)); + CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop); + + // check for mutstr + cxPropertiesFill(&prop, cx_mutstr((char*)str)); + CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop); } cxPropertiesDestroy(&prop); } @@ -187,35 +203,35 @@ CX_TEST_DO { str = ""; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); str = " \n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); str = "name"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = " "; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); // call fill twice in a row str = "= "; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); str = "value"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = "\n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name"))); @@ -223,17 +239,17 @@ // second round str = "#comment\n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); str = "#comment\nname2 = "; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = "value2\na = b\n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name2"))); @@ -245,17 +261,17 @@ CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("b"))); str = "# comment\n#\n#\ntests = "; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = "test1 "; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = "test2 test3 test4\n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("tests"))); @@ -263,17 +279,17 @@ // test if cxPropertiesNext finds a name/value after a comment str = "# just a comment"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = " in 3"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = " parts\nx = 1\n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("x"))); @@ -305,41 +321,41 @@ memset(long_value+1024, 'y', 1024); CX_TEST_DO { - cxPropertiesFill(&prop, long_key, 10); + cxPropertiesFilln(&prop, long_key, 10); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); - cxPropertiesFill(&prop, long_key + 10, 202); + cxPropertiesFilln(&prop, long_key + 10, 202); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); - cxPropertiesFill(&prop, long_key + 212, 200); + cxPropertiesFilln(&prop, long_key + 212, 200); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); - cxPropertiesFill(&prop, long_key + 412, 100); + cxPropertiesFilln(&prop, long_key + 412, 100); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); const char *str = " = "; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); - cxPropertiesFill(&prop, long_value, 512); + cxPropertiesFilln(&prop, long_value, 512); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); - cxPropertiesFill(&prop, long_value + 512, 1024); + cxPropertiesFilln(&prop, long_value + 512, 1024); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); - cxPropertiesFill(&prop, long_value + 1536, 512); + cxPropertiesFilln(&prop, long_value + 1536, 512); result = cxPropertiesNext(&prop, &key, &value); CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); str = "\n#comment\nkey = value\n"; - cxPropertiesFill(&prop, str, strlen(str)); + cxPropertiesFill(&prop, str); result = cxPropertiesNext(&prop, &key, &value); cxstring k = cx_strn(long_key, key_len); cxstring v = cx_strn(long_value, value_len);