Silence unused-variable warning (#2872)
[ExpressLRS.git] / src / test / test_fifo / test_fifo.cpp
blob4af93803d7ec5d2fca645301675a6bdafbd9c873
1 #include <cstdint>
2 #include <FIFO.h>
3 #include <unity.h>
4 #include <set>
6 using namespace std;
8 const uint32_t fifoSize = 256;
9 FIFO<fifoSize> f;
11 void init()
13 f.flush();
14 for(int i=0;i<fifoSize/2;i++) {
15 f.push(i);
16 TEST_ASSERT_EQUAL(i, f.pop());
18 for(int i=0;i<fifoSize-1;i++) {
19 f.push(i);
23 void test_fifo_pop_wrap(void)
25 init();
26 for(int i=0;i<fifoSize-1;i++) {
27 TEST_ASSERT_EQUAL(i, f.pop());
31 void test_fifo_popBytes_wrap(void)
33 init();
34 uint8_t buf[fifoSize] = {0};
35 f.popBytes(buf, fifoSize-1);
36 for(int i=0;i<fifoSize-1;i++) {
37 TEST_ASSERT_EQUAL(i, buf[i]);
41 void test_fifo_ensure()
43 f.flush();
44 // Push 25 9-byte packets with a 1 byte length header
45 for (int i = 0; i < 25; i++)
47 f.push(9); // 9 bytes;
48 for(int x = 0 ; x<9 ; x++)
49 f.push(i);
51 TEST_ASSERT_EQUAL(250, f.size());
53 // Ensure we can push a 99 byte packet with a prefix (i.e. 100 bytes)
54 f.ensure(100);
55 TEST_ASSERT_EQUAL(150, f.size()); // make sure that we've popped the right amount to fit our jumbo packet
56 TEST_ASSERT_EQUAL(9, f.pop()); // check that we have a header len
57 for (int x = 0; x < 9; x++)
58 TEST_ASSERT_EQUAL(10, f.pop()); // and that all the bytes in the head packet are what we expect
61 // Unity setup/teardown
62 void setUp() {}
63 void tearDown() {}
65 int main(int argc, char **argv)
67 UNITY_BEGIN();
68 RUN_TEST(test_fifo_pop_wrap);
69 RUN_TEST(test_fifo_popBytes_wrap);
70 RUN_TEST(test_fifo_ensure);
71 UNITY_END();
73 return 0;