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

Function test_dataBlockScan

tests/unit/test_datablock.c:85–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void test_dataBlockScan() {
86 DataBlock *dataBlock = DataBlock_New(DATABLOCK_BLOCK_CAP, 1024, sizeof(int), NULL);
87 size_t itemCount = 2048;
88 DataBlock_Accommodate(dataBlock, itemCount);
89
90 // Set items.
91 for(int i = 0 ; i < itemCount; i++) {
92 int *item = (int *)DataBlock_AllocateItem(dataBlock, NULL);
93 *item = i;
94 }
95
96 // Scan through items.
97 int count = 0; // items iterated so far
98 int *item = NULL; // current iterated item
99 uint64_t idx = 0; // iterated item index
100
101 DataBlockIterator *it = DataBlock_Scan(dataBlock);
102 while((item = (int *)DataBlockIterator_Next(it, &idx))) {
103 TEST_ASSERT(count == idx);
104 TEST_ASSERT(*item == count);
105 count++;
106 }
107 TEST_ASSERT(count == itemCount);
108
109 item = (int *)DataBlockIterator_Next(it, NULL);
110 TEST_ASSERT(item == NULL);
111
112 DataBlockIterator_Reset(it);
113
114 // Re-scan through items.
115 count = 0;
116 item = NULL;
117 while((item = (int *)DataBlockIterator_Next(it, &idx))) {
118 TEST_ASSERT(count == idx);
119 TEST_ASSERT(*item == count);
120 count++;
121 }
122 TEST_ASSERT(count == itemCount);
123
124 item = (int *)DataBlockIterator_Next(it, NULL);
125 TEST_ASSERT(item == NULL);
126
127 DataBlock_Free(dataBlock);
128 DataBlockIterator_Free(it);
129}
130
131void test_dataBlockRemoveItem() {
132 DataBlock *dataBlock = DataBlock_New(DATABLOCK_BLOCK_CAP, 1024, sizeof(int), NULL);

Callers

nothing calls this directly

Calls 8

DataBlock_NewFunction · 0.85
DataBlock_AccommodateFunction · 0.85
DataBlock_AllocateItemFunction · 0.85
DataBlock_ScanFunction · 0.85
DataBlockIterator_NextFunction · 0.85
DataBlockIterator_ResetFunction · 0.85
DataBlock_FreeFunction · 0.85
DataBlockIterator_FreeFunction · 0.85

Tested by

no test coverage detected