Skip to content

Commit 3af6c3c

Browse files
committed
Adding test code for Stream::readBytesUntil()
1 parent 2c1feec commit 3af6c3c

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ set(TEST_SRCS
5353
src/Stream/test_parseFloat.cpp
5454
src/Stream/test_parseInt.cpp
5555
src/Stream/test_readBytes.cpp
56+
src/Stream/test_readBytesUntil.cpp
5657
src/Stream/test_readString.cpp
5758
src/Stream/test_readStringUntil.cpp
5859
src/Stream/test_setTimeout.cpp
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <StreamMock.h>
12+
13+
/**************************************************************************************
14+
* TEST CODE
15+
**************************************************************************************/
16+
17+
TEST_CASE ("Testing readBytesUntil(char terminator, char *buffer, size_t length)", "[Stream-readBytesUntil-01]")
18+
{
19+
StreamMock mock;
20+
21+
WHEN ("the stream is empty")
22+
{
23+
char buf[32] = {0};
24+
25+
REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == 0);
26+
}
27+
28+
WHEN ("the stream contains the termination character")
29+
{
30+
char buf[32] = {0};
31+
char const str[] = "some stream content";
32+
char const EXPECTED_STR[] = "some";
33+
mock << str;
34+
35+
REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == strlen("some"));
36+
REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0);
37+
REQUIRE(mock.readString() == arduino::String("stream content"));
38+
}
39+
40+
WHEN ("the stream does not contain the termination character")
41+
{
42+
char buf[32] = {0};
43+
char const STR[] = "some stream content";
44+
mock << STR;
45+
46+
REQUIRE(mock.readBytesUntil('!', buf, sizeof(buf)) == strlen(STR));
47+
REQUIRE(strncmp(buf, STR, sizeof(buf)) == 0);
48+
REQUIRE(mock.readString() == arduino::String(""));
49+
}
50+
}

0 commit comments

Comments
 (0)