1 #include "gtest/gtest.h" 3 #include "../ring_buffer.h" 6 #define BUFFER_SIZE 1024 8 TEST(RingBuffer, U8_1for1_Test)
12 std::deque<uint8_t> myDeque;
17 for (uint8_t i = 0; i < 255; i++)
23 ref = myDeque.front();
30 TEST(RingBuffer, U32_1for1_Test)
34 std::deque<uint32_t> myDeque;
39 for (uint32_t i = 0; i < 1000000; i++)
45 ref = myDeque.front();
51 EXPECT_TRUE((
bool)(
ringBufEmpty(&rb)) ==
true && myDeque.empty() ==
true);
55 TEST(RingBuffer, WriteReadWriteReadTest)
59 std::deque<uint8_t> myDeque;
66 for (uint8_t i = 0; i < 201; i++)
73 for (uint8_t i = 0; i < 50; i++)
76 ref = myDeque.front();
82 for (uint8_t i = 0; i < 104; i++)
89 for (uint8_t i = 0; i < 254; i++)
92 ref = myDeque.front();
98 EXPECT_TRUE(
ringBufUsed(&rb) == 1 && myDeque.size() == 1);
102 ref = myDeque.front();
106 EXPECT_TRUE((
bool)(
ringBufEmpty(&rb))==
true && myDeque.empty()==
true);
110 TEST(RingBuffer, U32TestWriteThenReadTest)
114 std::deque<uint32_t> myDeque;
116 ringBufInit(&rb, (uint8_t*)buffer,
sizeof(buffer), 1);
122 myDeque.push_back(i);
125 for (uint32_t i = 0; i < BUFFER_SIZE-1; i++)
128 ref = myDeque.front();
139 static uint8_t comm_buffer[2048];
147 std::deque<uint8_t> myDeque;
152 for (
int i = 0;; i++)
158 ins1.
theta[0] = i * 2.0f;
159 ins1.
theta[1] = i * 3.0f;
160 ins1.
theta[2] = i * 4.0f;
161 ins1.
uvw[0] = i * 5.0
f;
162 ins1.
uvw[1] = i * 6.0
f;
163 ins1.
uvw[2] = i * 7.0
f;
164 ins1.
lla[0] = 40.330565516;
165 ins1.
lla[1] = -111.725787806;
166 ins1.
lla[2] = 1408.565264;
167 ins1.
ned[0] = i * 1.234f;
168 ins1.
ned[1] = i * 2.345f;
169 ins1.
ned[2] = i * 3.456f;
182 for (
int j = 0; j < n; j++)
184 myDeque.push_back(comm.
buf.
start[j]);
196 EXPECT_TRUE((
bool)(
ringBufEmpty(&rb)) ==
true && myDeque.empty() ==
true);
201 EXPECT_EQ(val, myDeque.front());
208 TEST(RingBuffer, WriteOverflowTest)
210 #define BUFFERX_SIZE 1000 211 #define OVERLAP_SIZE 450 221 for (uint32_t i = 0; i <
sizeof(buffer)+
OVERLAP_SIZE; i++)
243 TEST(RingBuffer, FloatArrayWithOverflow)
245 #define BUFFERA_SIZE 4 246 #define OVRLAPA_SIZE 3 250 ringBufInit(&rb, (uint8_t*)buffer,
sizeof(buffer),
sizeof(
float));
253 EXPECT_TRUE(
ringBufFree(&rb) ==
sizeof(buffer) -
sizeof(
float));
262 EXPECT_TRUE(
ringBufUsed(&rb) ==
sizeof(buffer) -
sizeof(
float));
int ringBufUsed(const ring_buf_t *rbuf)
This function returns the number of bytes currently in ring buffer.
f_t f[DEBUG_F_ARRAY_SIZE]
TEST(RingBuffer, U8_1for1_Test)
void ringBufInit(ring_buf_t *rbuf, unsigned char *buf, int bufSize, int wordByteSize)
Initialize ring buffer pointers.
int ringBufRead(ring_buf_t *rbuf, unsigned char *buf, int len)
This function reads data from the ring buffer.
int ringBufWrite(ring_buf_t *rb, unsigned char *buf, int numBytes)
This function writes data to the ring buffer.
void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
int ringBufEmpty(const ring_buf_t *rbuf)
This function returns 1 if the buffer is empty, 0 if not empty.
int is_comm_data(is_comm_instance_t *instance, uint32_t dataId, uint32_t offset, uint32_t size, void *data)
int ringBufFree(const ring_buf_t *rbuf)
This function returns the number of bytes free in UART Rx buffer. Important: Buffer size is one less ...