celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject celix git commit: Adds celix array list remove functions for the supported types and the unit test for those functions
Date Thu, 19 Jul 2018 20:59:59 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 66f89bb7c -> bd247745c


Adds celix array list remove functions for the supported types and the unit test for those
functions


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/bd247745
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/bd247745
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/bd247745

Branch: refs/heads/develop
Commit: bd247745cc8dec1d71573a1e8d408ec0a348d83e
Parents: 66f89bb
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Thu Jul 19 22:59:30 2018 +0200
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Thu Jul 19 22:59:30 2018 +0200

----------------------------------------------------------------------
 libs/utils/include/celix_array_list.h       | 12 +++++-
 libs/utils/private/test/array_list_test.cpp | 31 ++++++++++++++++
 libs/utils/src/array_list.c                 | 47 +++++++++++++++++++++++-
 3 files changed, 87 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/bd247745/libs/utils/include/celix_array_list.h
----------------------------------------------------------------------
diff --git a/libs/utils/include/celix_array_list.h b/libs/utils/include/celix_array_list.h
index 681929e..26c32ef 100644
--- a/libs/utils/include/celix_array_list.h
+++ b/libs/utils/include/celix_array_list.h
@@ -66,7 +66,7 @@ void celix_arrayList_addBool(celix_array_list_t *list, bool val);
 void celix_arrayList_addSize(celix_array_list_t *list, size_t val);
 
 int celix_arrayList_indexOf(celix_array_list_t *list, celix_array_list_entry_t entry);
-void celix_arrayList_remove(celix_array_list_t *list, int index);
+void celix_arrayList_removeAt(celix_array_list_t *list, int index);
 
 /**
  * Remove entry from array list. To use this first memset the entry to null to ensure it
completely initialized or
@@ -74,6 +74,16 @@ void celix_arrayList_remove(celix_array_list_t *list, int index);
  */
 void celix_arrayList_removeEntry(celix_array_list_t *list, celix_array_list_entry_t entry);
 
+void celix_arrayList_remove(celix_array_list_t *list, void *ptr);
+void celix_arrayList_removeInt(celix_array_list_t *list, int val);
+void celix_arrayList_removeLong(celix_array_list_t *list, long val);
+void celix_arrayList_removeUInt(celix_array_list_t *list, unsigned int val);
+void celix_arrayList_removeULong(celix_array_list_t *list, unsigned long val);
+void celix_arrayList_removeFloat(celix_array_list_t *list, float val);
+void celix_arrayList_removeDouble(celix_array_list_t *list, double val);
+void celix_arrayList_removeBool(celix_array_list_t *list, bool val);
+void celix_arrayList_removeSize(celix_array_list_t *list, size_t val);
+
 #ifdef __cplusplus
 }
 #endif

http://git-wip-us.apache.org/repos/asf/celix/blob/bd247745/libs/utils/private/test/array_list_test.cpp
----------------------------------------------------------------------
diff --git a/libs/utils/private/test/array_list_test.cpp b/libs/utils/private/test/array_list_test.cpp
index 8a2a04e..df8c135 100644
--- a/libs/utils/private/test/array_list_test.cpp
+++ b/libs/utils/private/test/array_list_test.cpp
@@ -33,6 +33,7 @@
 
 extern "C"
 {
+#include "celix_array_list.h"
 #include "array_list.h"
 #include "array_list_private.h"
 }
@@ -577,3 +578,33 @@ TEST(array_list_iterator, remove){
 	free(value3);
 	arrayListIterator_destroy(it_list);
 }
+
+
+template<typename I>
+void testCelixArrayForType(void(*add)(celix_array_list_t *, I val), void(*rem)(celix_array_list_t
*list, I val), I val1, I val2, I val3) {
+    celix_array_list_t *array = celix_arrayList_create();
+    add(array, val1);
+    add(array, val2);
+    add(array, val3);
+
+    CHECK_EQUAL(3, celix_arrayList_size(array));
+
+    rem(array, val2);
+    CHECK_EQUAL(2, celix_arrayList_size(array));
+    rem(array, val3);
+    CHECK_EQUAL(1, celix_arrayList_size(array));
+
+    celix_arrayList_destroy(array);
+}
+
+TEST(array_list_iterator, addAndRemovesTypes) {
+    testCelixArrayForType(celix_arrayList_add, celix_arrayList_remove, (void*)0x41, (void*)0x42,
(void*)0x43);
+    testCelixArrayForType(celix_arrayList_addInt, celix_arrayList_removeInt, 41, -42, 43);
+    testCelixArrayForType(celix_arrayList_addLong, celix_arrayList_removeLong, 41L, -42L,
43L);
+    testCelixArrayForType(celix_arrayList_addUInt, celix_arrayList_removeUInt, 41U, 42U,
43U);
+    testCelixArrayForType(celix_arrayList_addULong, celix_arrayList_removeULong, 41UL, 42UL,
43UL);
+    testCelixArrayForType(celix_arrayList_addFloat, celix_arrayList_removeFloat, 41.2f, 42.2f,
43.2f);
+    testCelixArrayForType(celix_arrayList_addDouble, celix_arrayList_removeDouble, 41.2,
42.2, 43.2);
+    //testCelixArrayForType(celix_arrayList_addBool, celix_arrayList_removeBool, true, false,
true);
+    testCelixArrayForType(celix_arrayList_addSize, celix_arrayList_removeSize, (size_t)41,
(size_t)42, (size_t)43);
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/bd247745/libs/utils/src/array_list.c
----------------------------------------------------------------------
diff --git a/libs/utils/src/array_list.c b/libs/utils/src/array_list.c
index e66a3c8..4ad277c 100644
--- a/libs/utils/src/array_list.c
+++ b/libs/utils/src/array_list.c
@@ -442,7 +442,7 @@ int celix_arrayList_indexOf(celix_array_list_t *list, celix_array_list_entry_t
e
 	}
 	return index;
 }
-void celix_arrayList_remove(celix_array_list_t *list, int index) {
+void celix_arrayList_removeAt(celix_array_list_t *list, int index) {
 	if (index >= 0 && index < list->size) {
 		list->modCount++;
 		size_t numMoved = list->size - index - 1;
@@ -453,8 +453,51 @@ void celix_arrayList_remove(celix_array_list_t *list, int index) {
 
 void celix_arrayList_removeEntry(celix_array_list_t *list, celix_array_list_entry_t entry)
{
 	int index = celix_arrayList_indexOf(list, entry);
-	celix_arrayList_remove(list, index);
+	celix_arrayList_removeAt(list, index);
 }
 
 
+void celix_arrayList_remove(celix_array_list_t *list, void *ptr) {
+	celix_array_list_entry_t entry = {.voidPtrVal = ptr};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeInt(celix_array_list_t *list, int val) {
+	celix_array_list_entry_t entry = {.intVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeLong(celix_array_list_t *list, long val) {
+	celix_array_list_entry_t entry = {.longVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeUInt(celix_array_list_t *list, unsigned int val) {
+	celix_array_list_entry_t entry = {.uintVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeULong(celix_array_list_t *list, unsigned long val) {
+	celix_array_list_entry_t entry = {.ulongVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeFloat(celix_array_list_t *list, float val) {
+	celix_array_list_entry_t entry = {.floatVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeDouble(celix_array_list_t *list, double val) {
+	celix_array_list_entry_t entry = {.doubleVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
+
+void celix_arrayList_removeBool(celix_array_list_t *list, bool val) {
+	celix_array_list_entry_t entry = {.boolVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}
 
+void celix_arrayList_removeSize(celix_array_list_t *list, size_t val) {
+	celix_array_list_entry_t entry = {.sizeVal = val};
+	celix_arrayList_removeEntry(list, entry);
+}


Mime
View raw message