diff --git a/libs/utils/gtest/src/ConvertUtilsErrorInjectionTestSuite.cc b/libs/utils/gtest/src/ConvertUtilsErrorInjectionTestSuite.cc index 63d6a8ff3..259362e97 100644 --- a/libs/utils/gtest/src/ConvertUtilsErrorInjectionTestSuite.cc +++ b/libs/utils/gtest/src/ConvertUtilsErrorInjectionTestSuite.cc @@ -114,7 +114,7 @@ TEST_F(ConvertUtilsWithErrorInjectionTestSuite, LongArrayToStringTest) { //Given an error injection for fputs celix_ei_expect_fputs((void*)celix_utils_arrayListToString, 1, -1); - //When calling celix_utils_longArrayListToString + //When calling celix_utils_arrayListToString result = celix_utils_arrayListToString(list); //Then the result is null EXPECT_EQ(nullptr, result); @@ -137,6 +137,20 @@ TEST_F(ConvertUtilsWithErrorInjectionTestSuite, StringToStringArrayTest) { // Then the result is null and the status is ENOMEM EXPECT_EQ(status, CELIX_ENOMEM); + // Given an error injection for fputc + celix_ei_expect_fputc((void*)celix_utils_convertStringToStringArrayList, 1, EOF, 2); + // When calling celix_utils_convertStringToStringArrayList + status = celix_utils_convertStringToStringArrayList("a,b,c", nullptr, &result); + // Then the result is null and the status is ENOMEM + EXPECT_EQ(status, CELIX_ENOMEM); + + // Given an error injection for fputc + celix_ei_expect_fputc((void*)celix_utils_convertStringToStringArrayList, 1, EOF, 6); + // When calling celix_utils_convertStringToStringArrayList + status = celix_utils_convertStringToStringArrayList("a,b,c", nullptr, &result); + // Then the result is null and the status is ENOMEM + EXPECT_EQ(status, CELIX_ENOMEM); + // Given an error injection for fputc (on writing an escaped char) celix_ei_expect_fputc((void*)celix_utils_convertStringToStringArrayList, 1, EOF); // When calling celix_utils_convertStringToStringArrayList @@ -144,3 +158,22 @@ TEST_F(ConvertUtilsWithErrorInjectionTestSuite, StringToStringArrayTest) { // Then the result is null and the status is ENOMEM EXPECT_EQ(status, CELIX_ENOMEM); } + +TEST_F(ConvertUtilsWithErrorInjectionTestSuite, StringArrayToStringTest) { + celix_autoptr(celix_array_list_t) list = celix_arrayList_createStringArray(); + celix_arrayList_addString(list, ",hello"); + celix_arrayList_addString(list, "world"); + + //Given an error injection for fputc + celix_ei_expect_fputc((void*)celix_utils_arrayListToString, 2, -1); + //When calling celix_utils_arrayListToString + char* result = celix_utils_arrayListToString(list); + //Then the result is null + EXPECT_EQ(nullptr, result); + + celix_ei_expect_fputc((void*)celix_utils_arrayListToString, 2, -1, 2); + //When calling celix_utils_arrayListToString + result = celix_utils_arrayListToString(list); + //Then the result is null + EXPECT_EQ(nullptr, result); +} diff --git a/libs/utils/gtest/src/ConvertUtilsTestSuite.cc b/libs/utils/gtest/src/ConvertUtilsTestSuite.cc index d0b402ba2..d3e8658cb 100644 --- a/libs/utils/gtest/src/ConvertUtilsTestSuite.cc +++ b/libs/utils/gtest/src/ConvertUtilsTestSuite.cc @@ -322,6 +322,10 @@ TEST_F(ConvertUtilsTestSuite, ConvertToLongArrayTest) { EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); EXPECT_TRUE(result == nullptr); + convertState = celix_utils_convertStringToLongArrayList(nullptr, nullptr, &result); + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); + EXPECT_TRUE(result == nullptr); + celix_autoptr(celix_array_list_t) defaultList = celix_arrayList_create(); celix_arrayList_addLong(defaultList, 42L); convertState = celix_utils_convertStringToLongArrayList("1,2,3,invalid", defaultList, &result); @@ -384,6 +388,10 @@ TEST_F(ConvertUtilsTestSuite, ConvertToDoubleArrayList) { EXPECT_DOUBLE_EQ(5.0, celix_arrayList_getDouble(result, 4)); celix_arrayList_destroy(result); + convertState = celix_utils_convertStringToDoubleArrayList("0.1,invalid,3.1,4,5", nullptr, &result); + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); + EXPECT_TRUE(result == nullptr); + // NOTE celix_utils_convertStringToDoubleArrayList uses the same generic function as is used in // celix_utils_convertStringToLongArrayList and because celix_utils_convertStringToLongArrayList is already // tested, we only test a few cases here. @@ -417,6 +425,10 @@ TEST_F(ConvertUtilsTestSuite, ConvertToBoolArrayList) { EXPECT_TRUE(celix_arrayList_getBool(result, 2)); celix_arrayList_destroy(result); + convertState = celix_utils_convertStringToBoolArrayList("true,invalid,true", nullptr, &result); + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); + EXPECT_TRUE(result == nullptr); + // NOTE celix_utils_convertStringToBoolArrayList uses the same generic function as is used in // celix_utils_convertStringToLongArrayList and because celix_utils_convertStringToLongArrayList is already // tested, we only test a few cases here. @@ -515,6 +527,10 @@ TEST_F(ConvertUtilsTestSuite, ConvertToVersionArrayList) { checkVersion(celix_arrayList_getVersion(result, 2), 3, 4, 5, "qualifier"); celix_arrayList_destroy(result); + convertState = celix_utils_convertStringToVersionArrayList("1.2.3,invalid,3.4.5.qualifier", nullptr, &result); + EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, convertState); + EXPECT_TRUE(result == nullptr); + // NOTE celix_utils_convertStringToVersionArrayList uses the same generic function as is used in // celix_utils_convertStringToLongArrayList and because celix_utils_convertStringToLongArrayList is already // tested, we only test a few cases here.