Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit08a44c9

Browse files
committed
Adding test code for Stream::find(...)
1 parent7182f67 commit08a44c9

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ set(TEST_SRCS
4747
src/Ringbuffer/test_peek.cpp
4848
src/Ringbuffer/test_read_char.cpp
4949
src/Ringbuffer/test_store_char.cpp
50+
src/Stream/test_find.cpp
5051
src/Stream/test_getTimeout.cpp
5152
src/Stream/test_readString.cpp
5253
src/Stream/test_readStringUntil.cpp

‎test/src/Stream/test_find.cpp‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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 find(const char *target)","[Stream-find-01]")
18+
{
19+
StreamMock mock;
20+
21+
WHEN ("'target' is contained in stream")
22+
{
23+
mock <<"This is a test string";
24+
25+
REQUIRE(mock.find("test") ==true);
26+
REQUIRE(mock.readString() ==arduino::String(" string"));
27+
}
28+
WHEN ("'target' is not contained in stream")
29+
{
30+
mock <<"This is a string";
31+
32+
REQUIRE(mock.find("test") ==false);
33+
REQUIRE(mock.readString() ==arduino::String(""));
34+
}
35+
}
36+
37+
TEST_CASE ("Testing find(const char *target, size_t length)","[Stream-find-02]")
38+
{
39+
StreamMock mock;
40+
41+
WHEN ("'target' is contained in stream")
42+
{
43+
mock <<"This is a test string";
44+
45+
/* 'length' should actually be '4' or strlen("test"). I'd rather
46+
* think this API should not be exposed at all.
47+
*/
48+
REQUIRE(mock.find("test",3) ==true);
49+
REQUIRE(mock.readString() ==arduino::String("t string"));
50+
}
51+
WHEN ("'target' is not contained in stream")
52+
{
53+
mock <<"This is a string";
54+
55+
REQUIRE(mock.find("test",3) ==false);
56+
REQUIRE(mock.readString() ==arduino::String(""));
57+
}
58+
}
59+
60+
TEST_CASE ("Testing find(char target)","[Stream-find-03]")
61+
{
62+
StreamMock mock;
63+
64+
WHEN ("'target' is contained in stream")
65+
{
66+
mock <<"This is a test string";
67+
68+
REQUIRE(mock.find('t') ==true);
69+
REQUIRE(mock.readString() ==arduino::String("est string"));
70+
}
71+
WHEN ("'target' is not contained in stream")
72+
{
73+
mock <<"This is a string";
74+
75+
REQUIRE(mock.find('!') ==false);
76+
REQUIRE(mock.readString() ==arduino::String(""));
77+
}
78+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp