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

Function test_CircularBufferPopulation

tests/unit/test_circular_buffer.c:34–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32}
33
34void test_CircularBufferPopulation(void) {
35 int n;
36 int cap = 16;
37 CircularBuffer buff = CircularBuffer_New(sizeof(int), cap);
38
39 // remove item from an empty buffer should report failure
40 TEST_ASSERT(CircularBuffer_Read(buff, &n) == NULL);
41
42 //--------------------------------------------------------------------------
43 // fill buffer
44 //--------------------------------------------------------------------------
45 for(int i = 0; i < cap; i++) {
46 // make sure item was added
47 TEST_ASSERT(CircularBuffer_Add(buff, &i) == 1);
48 // validate buffer's item count
49 TEST_ASSERT(CircularBuffer_ItemCount(buff) == i+1);
50 }
51 TEST_ASSERT(CircularBuffer_Full(buff) == true);
52
53 // forcefully try to overflow buffer
54 for(int i = 0; i < 10; i++) {
55 TEST_ASSERT(CircularBuffer_Add(buff, &n) == 0);
56 }
57
58 //--------------------------------------------------------------------------
59 // empty buffer
60 //--------------------------------------------------------------------------
61 for(int i = 0; i < cap; i++) {
62 // get item from buffer
63 TEST_ASSERT(CircularBuffer_Read(buff, &n) != NULL);
64
65 // validate item's value
66 TEST_ASSERT(n == i);
67 }
68 TEST_ASSERT(CircularBuffer_Empty(buff) == true);
69
70 // forcefully try to read an item from an empty buffer
71 for(int i = 0; i < 10; i++) {
72 TEST_ASSERT(CircularBuffer_Read(buff, &n) == NULL);
73 }
74
75 // clean up
76 CircularBuffer_Free(buff);
77}
78
79void test_CircularBuffer_Circularity(void) {
80 int n;

Callers

nothing calls this directly

Calls 7

CircularBuffer_NewFunction · 0.85
CircularBuffer_ReadFunction · 0.85
CircularBuffer_AddFunction · 0.85
CircularBuffer_ItemCountFunction · 0.85
CircularBuffer_FullFunction · 0.85
CircularBuffer_EmptyFunction · 0.85
CircularBuffer_FreeFunction · 0.85

Tested by

no test coverage detected