Skip to content

Commit

Permalink
gh-674: Fix properties/convert ei tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Mar 21, 2024
1 parent 0ad0e94 commit 5cfdf19
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions libs/utils/error_injector/celix_array_list/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ target_link_options(array_list_ei INTERFACE
LINKER:--wrap,celix_arrayList_create
LINKER:--wrap,celix_arrayList_createWithOptions
LINKER:--wrap,celix_arrayList_createStringArray
LINKER:--wrap,celix_arrayList_createLongArray
LINKER:--wrap,celix_arrayList_copy
LINKER:--wrap,celix_arrayList_add
LINKER:--wrap,celix_arrayList_addString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ CELIX_EI_DECLARE(celix_arrayList_createWithOptions, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_createStringArray, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_createLongArray, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_copy, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_add, celix_status_t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ void *__wrap_celix_arrayList_createStringArray() {
return __real_celix_arrayList_createStringArray();
}

void *__real_celix_arrayList_createLongArray();
CELIX_EI_DEFINE(celix_arrayList_createLongArray, celix_array_list_t*)
void *__wrap_celix_arrayList_createLongArray() {
CELIX_EI_IMPL(celix_arrayList_createLongArray);
return __real_celix_arrayList_createLongArray();
}

celix_status_t __real_celix_arrayList_add(celix_array_list_t* list, void* value);
CELIX_EI_DEFINE(celix_arrayList_add, celix_status_t)
celix_status_t __wrap_celix_arrayList_add(celix_array_list_t* list, void* value) {
Expand Down
5 changes: 3 additions & 2 deletions libs/utils/gtest/src/ConvertUtilsErrorInjectionTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ConvertUtilsWithErrorInjectionTestSuite : public ::testing::Test {
celix_ei_expect_celix_version_copy(nullptr, 0, nullptr);
celix_ei_expect_celix_version_createVersionFromString(nullptr, 0, CELIX_SUCCESS);
celix_ei_expect_celix_arrayList_createWithOptions(nullptr, 0, nullptr);
celix_ei_expect_celix_arrayList_createLongArray(nullptr, 0, nullptr);
celix_ei_expect_celix_arrayList_addLong(nullptr, 0, CELIX_SUCCESS);
celix_ei_expect_open_memstream(nullptr, 0, nullptr);
celix_ei_expect_fputs(nullptr, 0, 0);
Expand Down Expand Up @@ -67,7 +68,7 @@ TEST_F(ConvertUtilsWithErrorInjectionTestSuite, ConvertToVersionTest) {

TEST_F(ConvertUtilsWithErrorInjectionTestSuite, ConvertToLongArrayTest) {
//Given an error injection for celix_arrayList_create
celix_ei_expect_celix_arrayList_createWithOptions((void*)celix_utils_convertStringToLongArrayList, 1, nullptr);
celix_ei_expect_celix_arrayList_createLongArray((void*)celix_utils_convertStringToLongArrayList, 0, nullptr);
//When calling celix_utils_convertStringToLongArrayList
celix_array_list_t* result;
celix_status_t status = celix_utils_convertStringToLongArrayList("1,2,3", nullptr, &result);
Expand Down Expand Up @@ -100,7 +101,7 @@ TEST_F(ConvertUtilsWithErrorInjectionTestSuite, ConvertToLongArrayTest) {
}

TEST_F(ConvertUtilsWithErrorInjectionTestSuite, LongArrayToStringTest) {
celix_autoptr(celix_array_list_t) list = celix_arrayList_create();
celix_autoptr(celix_array_list_t) list = celix_arrayList_createLongArray();
celix_arrayList_addLong(list, 1L);
celix_arrayList_addLong(list, 2L);

Expand Down
15 changes: 8 additions & 7 deletions libs/utils/gtest/src/PropertiesErrorInjectionTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class PropertiesErrorInjectionTestSuite : public ::testing::Test {
celix_err_resetErrors();
celix_ei_expect_malloc(nullptr, 0, nullptr);
celix_ei_expect_celix_stringHashMap_createWithOptions(nullptr, 0, nullptr);
celix_ei_expect_celix_arrayList_copy(nullptr, 0, nullptr);
celix_ei_expect_celix_utils_strdup(nullptr, 0, nullptr);
celix_ei_expect_fopen(nullptr, 0, nullptr);
celix_ei_expect_fputc(nullptr, 0, 0);
Expand Down Expand Up @@ -286,8 +287,8 @@ TEST_F(PropertiesErrorInjectionTestSuite, GetAsArrayWithArrayListCopyFailedTest)
const char* str1 = "string1";
const char* str2 = "string2";
celix_autoptr(celix_array_list_t) stringList = celix_arrayList_createStringArray();
celix_arrayList_add(stringList, (void*)str1);
celix_arrayList_add(stringList, (void*)str2);
celix_arrayList_addString(stringList, str1);
celix_arrayList_addString(stringList, str2);
celix_autoptr(celix_array_list_t) longList = celix_arrayList_createLongArray();
celix_arrayList_addLong(longList, 1);
celix_arrayList_addLong(longList, 2);
Expand All @@ -299,8 +300,8 @@ TEST_F(PropertiesErrorInjectionTestSuite, GetAsArrayWithArrayListCopyFailedTest)
celix_arrayList_addBool(boolList, false);
celix_autoptr(celix_version_t) v = celix_version_create(1, 2, 3, "qualifier");
celix_autoptr(celix_array_list_t) versionList = celix_arrayList_createVersionArray();
celix_arrayList_add(versionList, v);
celix_arrayList_add(versionList, v);
celix_arrayList_addVersion(versionList, v);
celix_arrayList_addVersion(versionList, v);

celix_autoptr(celix_properties_t) props = celix_properties_create();
celix_properties_setArrayList(props, "stringArray", stringList);
Expand All @@ -310,7 +311,7 @@ TEST_F(PropertiesErrorInjectionTestSuite, GetAsArrayWithArrayListCopyFailedTest)
celix_properties_setArrayList(props, "versionArray", versionList);

// When a celix_arrayList_createWithOptions error injection is set for celix_properties_getAsStringArrayList
celix_ei_expect_celix_arrayList_createWithOptions((void*)celix_properties_getAsStringArrayList, 1, nullptr);
celix_ei_expect_celix_arrayList_copy((void*)celix_properties_getAsStringArrayList, 0, nullptr);

// Then the celix_properties_getAsStringArrayList call fails
celix_array_list_t* strings = nullptr;
Expand Down Expand Up @@ -346,7 +347,7 @@ TEST_F(PropertiesErrorInjectionTestSuite, GetAsArrayWithArrayListCopyFailedTest)
ASSERT_EQ(nullptr, bools);

//When a celix_arrayList_createWithOptions error injection is set for celix_properties_getAsVersionArrayList
celix_ei_expect_celix_arrayList_createWithOptions((void*)celix_properties_getAsVersionArrayList, 1, nullptr);
celix_ei_expect_celix_arrayList_copy((void*)celix_properties_getAsVersionArrayList, 0, nullptr);

// Then the celix_properties_getAsVersionArrayList call fails
celix_array_list_t* versions = nullptr;
Expand All @@ -360,7 +361,7 @@ TEST_F(PropertiesErrorInjectionTestSuite, SetArrayWithArrayListCopyFailedTest) {
celix_autoptr(celix_properties_t) props = celix_properties_create();

//And a (empty) array list
celix_autoptr(celix_array_list_t) list = celix_arrayList_create();
celix_autoptr(celix_array_list_t) list = celix_arrayList_createLongArray();

// When a celix_arrayList_copy error injection is set for celix_properties_setArrayList
celix_ei_expect_celix_arrayList_copy((void*)celix_properties_setArrayList, 0, nullptr);
Expand Down

0 comments on commit 5cfdf19

Please sign in to comment.