-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_readBytesUntil.cpp
50 lines (39 loc) · 1.45 KB
/
test_readBytesUntil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <StreamMock.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing readBytesUntil(char terminator, char *buffer, size_t length)", "[Stream-readBytesUntil-01]")
{
StreamMock mock;
WHEN ("the stream is empty")
{
char buf[32] = {0};
REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == 0);
}
WHEN ("the stream contains the termination character")
{
char buf[32] = {0};
char const str[] = "some stream content";
char const EXPECTED_STR[] = "some";
mock << str;
REQUIRE(mock.readBytesUntil(' ', buf, sizeof(buf)) == strlen("some"));
REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0);
REQUIRE(mock.readString() == arduino::String("stream content"));
}
WHEN ("the stream does not contain the termination character")
{
char buf[32] = {0};
char const STR[] = "some stream content";
mock << STR;
REQUIRE(mock.readBytesUntil('!', buf, sizeof(buf)) == strlen(STR));
REQUIRE(strncmp(buf, STR, sizeof(buf)) == 0);
REQUIRE(mock.readString() == arduino::String(""));
}
}