|
| 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 readBytes(char *buffer, size_t length)","[Stream-readBytes-01]") |
| 18 | +{ |
| 19 | + StreamMock mock; |
| 20 | + |
| 21 | +WHEN ("the stream is empty") |
| 22 | + { |
| 23 | +char buf[32] = {0}; |
| 24 | + |
| 25 | +REQUIRE(mock.readBytes(buf,sizeof(buf)) ==0); |
| 26 | + } |
| 27 | + |
| 28 | +WHEN ("the stream contains less data then we want to read") |
| 29 | + { |
| 30 | +char buf[32] = {0}; |
| 31 | +charconst str[] ="some stream content"; |
| 32 | + mock << str; |
| 33 | + |
| 34 | +REQUIRE(mock.readBytes(buf,sizeof(buf)) ==strlen(str)); |
| 35 | +REQUIRE(strncmp(buf, str,sizeof(buf)) ==0); |
| 36 | +REQUIRE(mock.readString() ==arduino::String("")); |
| 37 | + } |
| 38 | + |
| 39 | +WHEN ("the stream contains more data then we want to read") |
| 40 | + { |
| 41 | +char buf[5] = {0}; |
| 42 | + mock <<"some stream content"; |
| 43 | +charconst EXPECTED_STR[] ="some"; |
| 44 | + |
| 45 | +REQUIRE(mock.readBytes(buf,sizeof(buf)) ==5); |
| 46 | +REQUIRE(strncmp(buf, EXPECTED_STR,sizeof(buf)) ==0); |
| 47 | +REQUIRE(mock.readString() ==arduino::String("stream content")); |
| 48 | + } |
| 49 | +} |