PengZheng commented on code in PR #810:
URL: https://github.com/apache/celix/pull/810#discussion_r2633439011


##########
libs/utils/gtest/src/ArrayListErrorInjectionTestSuite.cc:
##########
@@ -160,3 +160,18 @@ TEST_F(ArrayListErrorInjectionTestSuite, 
CopyArrayListFailureTest) {
     // And a celix_err is expected
     EXPECT_EQ(3, celix_err_getErrorCount());
 }
+
+
+TEST_F(ArrayListErrorInjectionTestSuite, InitialCapacityOptionUsed) {
+    celix_array_list_create_options_t opts{};
+    opts.elementType = CELIX_ARRAY_LIST_ELEMENT_TYPE_STRING;
+    opts.initialCapacity = 1; // smaller than number of elements we will add
+    celix_autoptr(celix_array_list_t) list = 
celix_arrayList_createWithOptions(&opts);
+
+    // First add fits in initial capacity
+    EXPECT_EQ(CELIX_SUCCESS, celix_arrayList_addString(list, "v1"));
+
+    // Fail the next realloc to verify that a second add triggers a 
reallocation
+    celix_ei_expect_realloc((void*)celix_arrayList_addString, 2, nullptr, 1);

Review Comment:
   It would be better to move this line before `EXPECT_EQ(CELIX_SUCCESS, 
celix_arrayList_addString(list, "v1"));` to make it clear the first operation 
does not trigger memory allocation.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to