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

Function test_CircularBuffer_Reserve

tests/unit/test_circular_buffer.c:145–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143}
144
145void test_CircularBuffer_Reserve(void) {
146
147 // -------------------------------------------------------------------------
148 // fill a buffer of size 16 with 32 integers
149 // -------------------------------------------------------------------------
150
151 uint cap = 16;
152 CircularBuffer buff = CircularBuffer_New(sizeof(int), cap);
153 for(int i = 0; i < 2 * cap; i++) {
154 int *item = CircularBuffer_Reserve(buff);
155 *item = i;
156 }
157
158 // make sure item count did not exceeded buffer cap
159 TEST_ASSERT(CircularBuffer_ItemCount(buff) == CircularBuffer_Cap(buff));
160
161 // -------------------------------------------------------------------------
162 // assert override correctness
163 // -------------------------------------------------------------------------
164
165 for(uint i = 0; i < 16; i++) {
166 int item;
167 void *res = CircularBuffer_Read(buff, &item);
168 TEST_ASSERT(res != NULL);
169 TEST_ASSERT(item == (i + 16));
170 TEST_ASSERT(CircularBuffer_ItemCount(buff) == 16-i-1);
171 }
172
173 // -------------------------------------------------------------------------
174 // free the buffer
175 // -------------------------------------------------------------------------
176
177 CircularBuffer_Free(buff);
178}
179
180void _assert_val_cb
181(

Callers

nothing calls this directly

Calls 6

CircularBuffer_NewFunction · 0.85
CircularBuffer_ReserveFunction · 0.85
CircularBuffer_ItemCountFunction · 0.85
CircularBuffer_CapFunction · 0.85
CircularBuffer_ReadFunction · 0.85
CircularBuffer_FreeFunction · 0.85

Tested by

no test coverage detected