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

Function test_CircularBuffer_Circularity

tests/unit/test_circular_buffer.c:79–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void test_CircularBuffer_Circularity(void) {
80 int n;
81 int cap = 16;
82 CircularBuffer buff = CircularBuffer_New(sizeof(int), cap);
83
84 //--------------------------------------------------------------------------
85 // fill buffer
86 //--------------------------------------------------------------------------
87 for(int i = 0; i < cap; i++) {
88 // make sure item was added
89 TEST_ASSERT(CircularBuffer_Add(buff, &i) == 1);
90 }
91 TEST_ASSERT(CircularBuffer_Full(buff) == true);
92
93 // try to overflow buffer
94 TEST_ASSERT(CircularBuffer_Add(buff, &n) == 0);
95
96 // removing an item should make space in the buffer
97 TEST_ASSERT(CircularBuffer_Read(buff, &n) != NULL);
98 TEST_ASSERT(CircularBuffer_Add(buff, &n) == 1);
99
100 //--------------------------------------------------------------------------
101 // clear buffer
102 //--------------------------------------------------------------------------
103
104 while(CircularBuffer_Empty(buff) == false) {
105 CircularBuffer_Read(buff, &n);
106 }
107
108 // add/remove elements cycling through the buffer multiple times
109 for(int i = 0; i < cap * 4; i++) {
110 TEST_ASSERT(CircularBuffer_Add(buff, &i) == 1);
111 TEST_ASSERT(CircularBuffer_Read(buff, &n) != NULL);
112 TEST_ASSERT(n == i);
113 }
114 TEST_ASSERT(CircularBuffer_Empty(buff) == true);
115
116 // clean up
117 CircularBuffer_Free(buff);
118}
119
120void test_CircularBuffer_free(void) {
121 //--------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected