forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_find.cpp
78 lines (62 loc) · 1.98 KB
/
test_find.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <StreamMock.h>
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing find(const char *target)", "[Stream-find-01]")
{
StreamMock mock;
WHEN ("'target' is contained in stream")
{
mock << "This is a test string";
REQUIRE(mock.find("test") == true);
REQUIRE(mock.readString() == arduino::String(" string"));
}
WHEN ("'target' is not contained in stream")
{
mock << "This is a string";
REQUIRE(mock.find("test") == false);
REQUIRE(mock.readString() == arduino::String(""));
}
}
TEST_CASE ("Testing find(const char *target, size_t length)", "[Stream-find-02]")
{
StreamMock mock;
WHEN ("'target' is contained in stream")
{
mock << "This is a test string";
/* 'length' should actually be '4' or strlen("test"). I'd rather
* think this API should not be exposed at all.
*/
REQUIRE(mock.find("test", 3) == true);
REQUIRE(mock.readString() == arduino::String("t string"));
}
WHEN ("'target' is not contained in stream")
{
mock << "This is a string";
REQUIRE(mock.find("test", 3) == false);
REQUIRE(mock.readString() == arduino::String(""));
}
}
TEST_CASE ("Testing find(char target)", "[Stream-find-03]")
{
StreamMock mock;
WHEN ("'target' is contained in stream")
{
mock << "This is a test string";
REQUIRE(mock.find('t') == true);
REQUIRE(mock.readString() == arduino::String("est string"));
}
WHEN ("'target' is not contained in stream")
{
mock << "This is a string";
REQUIRE(mock.find('!') == false);
REQUIRE(mock.readString() == arduino::String(""));
}
}