| 143 | } |
| 144 | |
| 145 | void 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 | |
| 180 | void _assert_val_cb |
| 181 | ( |
nothing calls this directly
no test coverage detected