|
| 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 findUntil(const char *target, const char *terminator)","[Stream-findUntil-01]") |
| 18 | +{ |
| 19 | + StreamMock mock; |
| 20 | + |
| 21 | +WHEN ("'target' is contained in stream") |
| 22 | + { |
| 23 | +WHEN ("'terminator' appears before 'target'") |
| 24 | + { |
| 25 | + mock <<"This is a : test string"; |
| 26 | +REQUIRE(mock.findUntil("test",":") ==false); |
| 27 | +REQUIRE(mock.readString() ==arduino::String("test string")); |
| 28 | + } |
| 29 | +WHEN ("'terminator' appears after 'target'") |
| 30 | + { |
| 31 | + mock <<"This is a test : string"; |
| 32 | +REQUIRE(mock.findUntil("test",":") ==true); |
| 33 | +REQUIRE(mock.readString() ==arduino::String(" : string")); |
| 34 | + } |
| 35 | +WHEN ("'terminator' is not included in the string at all") |
| 36 | + { |
| 37 | + mock <<"This is a test string"; |
| 38 | +REQUIRE(mock.findUntil("test",":") ==true); |
| 39 | +REQUIRE(mock.readString() ==arduino::String(" string")); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | +WHEN ("'target' is not contained in stream") |
| 44 | + { |
| 45 | + mock <<"This is a test string"; |
| 46 | +REQUIRE(mock.findUntil("abc","def") ==false); |
| 47 | +REQUIRE(mock.readString() ==arduino::String("")); |
| 48 | + } |
| 49 | +} |