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

Function test_dataBlockAddItem

tests/unit/test_datablock.c:46–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44}
45
46void test_dataBlockAddItem() {
47 DataBlock *dataBlock = DataBlock_New(DATABLOCK_BLOCK_CAP, 1024, sizeof(int), NULL);
48 size_t itemCount = 512;
49 DataBlock_Accommodate(dataBlock, itemCount);
50 TEST_ASSERT(dataBlock->itemCap >= itemCount);
51
52 // Set items.
53 for(int i = 0 ; i < itemCount; i++) {
54 int *value = (int *)DataBlock_AllocateItem(dataBlock, NULL);
55 *value = i;
56 }
57
58 // Read items.
59 for(int i = 0 ; i < itemCount; i++) {
60 int *value = (int *)DataBlock_GetItem(dataBlock, i);
61 TEST_ASSERT(*value == i);
62 }
63
64 // Add enough item to cause datablock to re-allocate.
65 size_t prevItemCount = dataBlock->itemCount;
66 itemCount *= 64;
67 DataBlock_Accommodate(dataBlock, itemCount);
68 TEST_ASSERT(dataBlock->itemCap >= prevItemCount + itemCount);
69
70 // Set items.
71 for(int i = 0 ; i < itemCount; i++) {
72 int *value = (int *)DataBlock_AllocateItem(dataBlock, NULL);
73 *value = prevItemCount + i;
74 }
75
76 // Read items.
77 for(int i = 0 ; i < dataBlock->itemCount; i++) {
78 int *value = (int *)DataBlock_GetItem(dataBlock, i);
79 TEST_ASSERT(*value == i);
80 }
81
82 DataBlock_Free(dataBlock);
83}
84
85void test_dataBlockScan() {
86 DataBlock *dataBlock = DataBlock_New(DATABLOCK_BLOCK_CAP, 1024, sizeof(int), NULL);

Callers

nothing calls this directly

Calls 5

DataBlock_NewFunction · 0.85
DataBlock_AccommodateFunction · 0.85
DataBlock_AllocateItemFunction · 0.85
DataBlock_GetItemFunction · 0.85
DataBlock_FreeFunction · 0.85

Tested by

no test coverage detected