-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_readBytes.cpp
49 lines (38 loc) · 1.36 KB
/
test_readBytes.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <StreamMock.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing readBytes(char *buffer, size_t length)", "[Stream-readBytes-01]")
{
StreamMock mock;
WHEN ("the stream is empty")
{
char buf[32] = {0};
REQUIRE(mock.readBytes(buf, sizeof(buf)) == 0);
}
WHEN ("the stream contains less data than we want to read")
{
char buf[32] = {0};
char const str[] = "some stream content";
mock << str;
REQUIRE(mock.readBytes(buf, sizeof(buf)) == strlen(str));
REQUIRE(strncmp(buf, str, sizeof(buf)) == 0);
REQUIRE(mock.readString() == arduino::String(""));
}
WHEN ("the stream contains more data than we want to read")
{
char buf[5] = {0};
mock << "some stream content";
char const EXPECTED_STR[] = "some ";
REQUIRE(mock.readBytes(buf, sizeof(buf)) == 5);
REQUIRE(strncmp(buf, EXPECTED_STR, sizeof(buf)) == 0);
REQUIRE(mock.readString() == arduino::String("stream content"));
}
}