MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_objectPoolRemoveItem

Function test_objectPoolRemoveItem

tests/unit/test_object_pool.c:75–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void test_objectPoolRemoveItem() {
76 ObjectPool *object_pool = ObjectPool_New(1024, sizeof(uint), NULL);
77 uint item_count = 32;
78
79 uint *item_pointers[item_count];
80 // Set items.
81 for(uint i = 0; i < item_count; i++) {
82 uint *item = (uint *)ObjectPool_NewItem(object_pool);
83 *item = i;
84 item_pointers[i] = item;
85 }
86
87 // Validate that no items have been modified.
88 for(uint i = 0; i < item_count; i++) {
89 TEST_ASSERT(*item_pointers[i] == i);
90 }
91
92 // Delete an entry from the pool and perform validations..
93 uint delete_idx = 10;
94 ObjectPool_DeleteItem(object_pool, item_pointers[delete_idx]);
95 TEST_ASSERT(object_pool->itemCount == item_count - 1);
96 TEST_ASSERT(array_len(object_pool->deletedIdx) == 1);
97 // Index 10 should be added to ObjectPool deletedIdx array.
98 TEST_ASSERT(object_pool->deletedIdx[0] == 10);
99
100 // Add a new item and verify that the deleted entry is reused.
101 uint *new_item = (uint *)ObjectPool_NewItem(object_pool);
102 TEST_ASSERT(object_pool->itemCount == item_count);
103 TEST_ASSERT(array_len(object_pool->deletedIdx) == 0);
104 // Verify that the new entry is zeroed.
105 TEST_ASSERT(*new_item == 0);
106
107 // cleanup
108 ObjectPool_Free(object_pool);
109}
110
111TEST_LIST = {
112 {"objectPoolNew", test_objectPoolNew},

Callers

nothing calls this directly

Calls 5

ObjectPool_NewFunction · 0.85
ObjectPool_NewItemFunction · 0.85
ObjectPool_DeleteItemFunction · 0.85
array_lenFunction · 0.85
ObjectPool_FreeFunction · 0.85

Tested by

no test coverage detected