Skip to content

Commit

Permalink
gh-674: Refactor array list to not allow NULL entries.
Browse files Browse the repository at this point in the history
Also remove support for int, uint, ulong, float and
size as array list element. This is now more aligned
with hash map.
  • Loading branch information
pnoltes committed Feb 17, 2024
1 parent 86e3b7a commit 05047d5
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 698 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ limitations under the License.
- linked_list.h is removed and no longer supported. Use celix_array_list.h instead.
- ip_utils.h is removed and no longer supported.
- array_list.h is removed and no longer supported. Use celix_array_list.h instead.
- the celix_arrayList_add function no longer accepts a NULL value.

## New Features

Expand Down
7 changes: 3 additions & 4 deletions libs/utils/error_injector/celix_array_list/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ target_link_libraries(array_list_ei PUBLIC Celix::error_injector Celix::utils)
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_add
LINKER:--wrap,celix_arrayList_addInt
LINKER:--wrap,celix_arrayList_addLong
LINKER:--wrap,celix_arrayList_addUInt
LINKER:--wrap,celix_arrayList_addULong
LINKER:--wrap,celix_arrayList_addFloat
LINKER:--wrap,celix_arrayList_addDouble
LINKER:--wrap,celix_arrayList_addBool
LINKER:--wrap,celix_arrayList_addSize
LINKER:--wrap,celix_arrayList_addString
LINKER:--wrap,celix_arrayList_assignString
)
add_library(Celix::array_list_ei ALIAS array_list_ei)
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ CELIX_EI_DECLARE(celix_arrayList_create, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_createWithOptions, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_add, celix_status_t);
CELIX_EI_DECLARE(celix_arrayList_createStringArray, celix_array_list_t*);

CELIX_EI_DECLARE(celix_arrayList_addInt, celix_status_t);
CELIX_EI_DECLARE(celix_arrayList_add, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addLong, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addUInt, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addULong, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addFloat, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addDouble, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addBool, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_addSize, celix_status_t);
CELIX_EI_DECLARE(celix_arrayList_addString, celix_status_t);

CELIX_EI_DECLARE(celix_arrayList_assignString, celix_status_t);


#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "celix_array_list_ei.h"
#include "celix_stdlib_cleanup.h"

extern "C" {

Expand All @@ -35,48 +36,27 @@ void *__wrap_celix_arrayList_createWithOptions(const celix_array_list_create_opt
return __real_celix_arrayList_createWithOptions(opts);
}

void *__real_celix_arrayList_createStringArray();
CELIX_EI_DEFINE(celix_arrayList_createStringArray, celix_array_list_t*)
void *__wrap_celix_arrayList_createStringArray() {
CELIX_EI_IMPL(celix_arrayList_createStringArray);
return __real_celix_arrayList_createStringArray();
}

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) {
CELIX_EI_IMPL(celix_arrayList_add);
return __real_celix_arrayList_add(list, value);
}

celix_status_t __real_celix_arrayList_addInt(celix_array_list_t* list, int value);
CELIX_EI_DEFINE(celix_arrayList_addInt, celix_status_t)
celix_status_t __wrap_celix_arrayList_addInt(celix_array_list_t* list, int value) {
CELIX_EI_IMPL(celix_arrayList_addInt);
return __real_celix_arrayList_addInt(list, value);
}

celix_status_t __real_celix_arrayList_addLong(celix_array_list_t* list, long value);
CELIX_EI_DEFINE(celix_arrayList_addLong, celix_status_t)
celix_status_t __wrap_celix_arrayList_addLong(celix_array_list_t* list, long value) {
CELIX_EI_IMPL(celix_arrayList_addLong);
return __real_celix_arrayList_addLong(list, value);
}

celix_status_t __real_celix_arrayList_addUInt(celix_array_list_t* list, unsigned int value);
CELIX_EI_DEFINE(celix_arrayList_addUInt, celix_status_t)
celix_status_t __wrap_celix_arrayList_addUInt(celix_array_list_t* list, unsigned int value) {
CELIX_EI_IMPL(celix_arrayList_addUInt);
return __real_celix_arrayList_addUInt(list, value);
}

celix_status_t __real_celix_arrayList_addULong(celix_array_list_t* list, unsigned long value);
CELIX_EI_DEFINE(celix_arrayList_addULong, celix_status_t)
celix_status_t __wrap_celix_arrayList_addULong(celix_array_list_t* list, unsigned long value) {
CELIX_EI_IMPL(celix_arrayList_addULong);
return __real_celix_arrayList_addULong(list, value);
}

celix_status_t __real_celix_arrayList_addFloat(celix_array_list_t* list, float value);
CELIX_EI_DEFINE(celix_arrayList_addFloat, celix_status_t)
celix_status_t __wrap_celix_arrayList_addFloat(celix_array_list_t* list, float value) {
CELIX_EI_IMPL(celix_arrayList_addFloat);
return __real_celix_arrayList_addFloat(list, value);
}

celix_status_t __real_celix_arrayList_addDouble(celix_array_list_t* list, double value);
CELIX_EI_DEFINE(celix_arrayList_addDouble, celix_status_t)
celix_status_t __wrap_celix_arrayList_addDouble(celix_array_list_t* list, double value) {
Expand All @@ -91,11 +71,20 @@ celix_status_t __wrap_celix_arrayList_addBool(celix_array_list_t* list, bool val
return __real_celix_arrayList_addBool(list, value);
}

celix_status_t __real_celix_arrayList_addSize(celix_array_list_t* list, size_t value);
CELIX_EI_DEFINE(celix_arrayList_addSize, celix_status_t)
celix_status_t __wrap_celix_arrayList_addSize(celix_array_list_t* list, size_t value) {
CELIX_EI_IMPL(celix_arrayList_addSize);
return __real_celix_arrayList_addSize(list, value);
celix_status_t __real_celix_arrayList_addString(celix_array_list_t* list, const char* value);
CELIX_EI_DEFINE(celix_arrayList_addString, celix_status_t)
celix_status_t __wrap_celix_arrayList_addString(celix_array_list_t* list, const char* value) {
CELIX_EI_IMPL(celix_arrayList_addString);
return __real_celix_arrayList_addString(list, value);
}

celix_status_t __real_celix_arrayList_assignString(celix_array_list_t* list, char* value);
CELIX_EI_DEFINE(celix_arrayList_assignString, celix_status_t)
celix_status_t __wrap_celix_arrayList_assignString(celix_array_list_t* list, char* value) {
celix_autofree char* tmp = value; //ensure that the value is freed when an error is injected
CELIX_EI_IMPL(celix_arrayList_assignString);
celix_steal_ptr(tmp);
return __real_celix_arrayList_assignString(list, value);
}

}
24 changes: 19 additions & 5 deletions libs/utils/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,36 @@ setup_target_for_coverage(test_utils SCAN_DIR ..)

if (EI_TESTS)
#Note testing celix err separated, otherwise celix err tss can already be initialized by another util function
add_executable(test_celix_err_with_ei
add_executable(test_utils_celix_err_with_ei
src/ErrErrorInjectionTestSuite.cc
)
target_link_libraries(test_celix_err_with_ei PRIVATE
target_link_libraries(test_utils_celix_err_with_ei PRIVATE
utils_cut
Celix::malloc_ei
Celix::threads_ei
GTest::gtest GTest::gtest_main
)
add_test(NAME test_celix_err_with_ei COMMAND test_celix_err_with_ei)
setup_target_for_coverage(test_celix_err_with_ei SCAN_DIR ..)
add_test(NAME test_utils_celix_err_with_ei COMMAND test_utils_celix_err_with_ei)
setup_target_for_coverage(test_utils_celix_err_with_ei SCAN_DIR ..)


#Note testing array list seperated, otherwise array list calls are already wrapped
add_executable(test_utils_array_list_with_ei
src/ArrayListErrorInjectionTestSuite.cc
)
target_link_libraries(test_utils_array_list_with_ei PRIVATE
utils_cut
Celix::malloc_ei
Celix::utils_ei
Celix::version_ei
GTest::gtest GTest::gtest_main
)
add_test(NAME test_utils_array_list_with_ei COMMAND test_utils_array_list_with_ei)
setup_target_for_coverage(test_utils_array_list_with_ei SCAN_DIR ..)

add_executable(test_utils_with_ei
src/FileUtilsErrorInjectionTestSuite.cc
src/ConvertUtilsErrorInjectionTestSuite.cc
src/ArrayListErrorInjectionTestSuite.cc
src/PropertiesErrorInjectionTestSuite.cc
src/VersionErrorInjectionTestSuite.cc
src/HashMapErrorInjectionTestSuite.cc
Expand Down
11 changes: 6 additions & 5 deletions libs/utils/gtest/src/ArrayListErrorInjectionTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ TEST_F(ArrayListErrorInjectionTestSuite, CreateTest) {
EXPECT_EQ(1, celix_err_getErrorCount());

//Given an error is injected for malloc (used for the element data)
celix_ei_expect_malloc(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
celix_ei_expect_calloc(CELIX_EI_UNKNOWN_CALLER, 0, nullptr);
//Then creating an array list should fail
EXPECT_EQ(nullptr, celix_arrayList_create());
//And an error is logged to the celix_err
Expand All @@ -55,20 +55,21 @@ TEST_F(ArrayListErrorInjectionTestSuite, CreateTest) {


TEST_F(ArrayListErrorInjectionTestSuite, AddFunctionsTest) {
//Given an array list with a capacity of 10 (whitebox knowledge)
auto* list = celix_arrayList_create();
// Given an array list with a capacity of 10 (whitebox knowledge) and with an entry than needs to be freed when
// removed.
auto* list = celix_arrayList_createStringArray();

//When adding 10 elements, no error is expected
for (int i = 0; i < 10; ++i) {
EXPECT_EQ(CELIX_SUCCESS, celix_arrayList_addInt(list, i));
EXPECT_EQ(CELIX_SUCCESS, celix_arrayList_addString(list, "test"));
}
EXPECT_EQ(10, celix_arrayList_size(list));

//And realloc is primed to fail
celix_ei_expect_realloc(CELIX_EI_UNKNOWN_CALLER, 1, nullptr);

//Then adding an element should fail
EXPECT_EQ(CELIX_ENOMEM, celix_arrayList_addInt(list, 10));
EXPECT_EQ(CELIX_ENOMEM, celix_arrayList_addString(list, "fail"));
EXPECT_EQ(10, celix_arrayList_size(list));
//And an error is logged to the celix_err
EXPECT_EQ(1, celix_err_getErrorCount());
Expand Down
Loading

0 comments on commit 05047d5

Please sign in to comment.