Skip to content

Commit b7edc11

Browse files
committed
Adding test code for 'Ringbuffer::read_char'
1 parent 7219305 commit b7edc11

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(TEST_SRCS
3131
src/Ringbuffer/test_availableForStore.cpp
3232
src/Ringbuffer/test_clear.cpp
3333
src/Ringbuffer/test_isFull.cpp
34+
src/Ringbuffer/test_read_char.cpp
3435
src/Ringbuffer/test_store_char.cpp
3536
src/WCharacter/test_isControl.cpp
3637
src/WCharacter/test_isDigit.cpp
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <RingBuffer.h>
12+
13+
/**************************************************************************************
14+
* TEST CODE
15+
**************************************************************************************/
16+
17+
TEST_CASE ("Data is removed from the ring buffer via 'read_char'", "[Ringbuffer-read_char-01]")
18+
{
19+
arduino::RingBufferN<2> ringbuffer;
20+
21+
WHEN("The ringbuffer is empty")
22+
THEN("'read_char' should return -1")
23+
REQUIRE(ringbuffer.read_char() == -1);
24+
25+
WHEN("The ringbuffer contains data")
26+
{
27+
ringbuffer.store_char('A');
28+
ringbuffer.store_char('B');
29+
THEN("'read_char' should return first inserted element first (FIFO)")
30+
{
31+
REQUIRE(ringbuffer.read_char() == 'A');
32+
REQUIRE(ringbuffer.read_char() == 'B');
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)