1+ /*
2+ * Copyright (c) 2020 Arduino. All rights reserved.
3+ */
4+
5+ /* *************************************************************************************
6+ * INCLUDE
7+ **************************************************************************************/
8+
9+ #include < catch.hpp>
10+
11+ #include < String.h>
12+
13+ /* *************************************************************************************
14+ * TEST CODE
15+ **************************************************************************************/
16+
17+ TEST_CASE (" Testing String::equals(const String &) with exit status PASS" , " [String-equals-01]" )
18+ {
19+ arduino::String str1 (" Hello" ), str2 (" Hello" );
20+ REQUIRE (str1.equals (str2) == 1 );
21+ }
22+
23+ TEST_CASE (" Testing String::equals(const String &) with exit status FAIL" , " [String-equals-02]" )
24+ {
25+ arduino::String str1 (" Hello" ), str2 (" World" );
26+ REQUIRE (str1.equals (str2) == 0 );
27+ }
28+
29+ TEST_CASE (" Testing String::equals(const char *) with exit status PASS" , " [String-equals-03]" )
30+ {
31+ arduino::String str1 (" Hello" );
32+ REQUIRE (str1.equals (" Hello" ) == 1 );
33+ }
34+
35+ TEST_CASE (" Testing String::equals(const char *) with exit status FAIL" , " [String-equals-04]" )
36+ {
37+ arduino::String str1 (" Hello" );
38+ REQUIRE (str1.equals (" World" ) == 0 );
39+ }
40+
41+ TEST_CASE (" Testing String::equalsIgnoreCase(const String &) PASS with NON-empty string" , " [String-equalsIgnoreCase-05]" )
42+ {
43+ arduino::String str1 (" Hello" ), str2 (" Hello" );
44+ REQUIRE (str1.equalsIgnoreCase (str2) == 1 );
45+ }
46+
47+ TEST_CASE (" Testing String::equalsIgnoreCase(const String &) FAIL with NON-empty string" , " [String-equalsIgnoreCase-06]" )
48+ {
49+ arduino::String str1 (" Hello" ), str2 (" Hel" );
50+ REQUIRE (str1.equalsIgnoreCase (str2) == 0 );
51+ }
52+
53+ TEST_CASE (" Testing String::equalsIgnoreCase(const String &) FAIL with different strings" , " [String-equalsIgnoreCase-07]" )
54+ {
55+ arduino::String str1 (" Hello" ), str2 (" World" );
56+ REQUIRE (str1.equalsIgnoreCase (str2) == 0 );
57+ }
58+
59+ TEST_CASE (" Testing String::equalsIgnoreCase(const String &) PASS with same string" , " [String-equalsIgnoreCase-08]" )
60+ {
61+ arduino::String str1 (" Hello" );
62+ REQUIRE (str1.equalsIgnoreCase (str1) == 1 );
63+ }
64+
65+ TEST_CASE (" Testing String::startsWith(const String &)" , " [String-startsWith-09]" )
66+ {
67+ WHEN (" str2 is larger than str1" )
68+ {
69+ arduino::String str1 (" Hello" );
70+ arduino::String str2 (" Hello World" );
71+ REQUIRE (str1.startsWith (str2) == 0 );
72+ }
73+ WHEN (" str1 starts with str2" )
74+ {
75+ arduino::String str1 (" Hello World" );
76+ arduino::String str2 (" Hello" );
77+ REQUIRE (str1.startsWith (str2) == 1 );
78+ }
79+ WHEN (" str1 does NOT start with str2" )
80+ {
81+ arduino::String str1 (" Hello World" );
82+ arduino::String str2 (" Helo" );
83+ REQUIRE (str1.startsWith (str2) == 0 );
84+ }
85+ }
86+
87+ TEST_CASE (" Testing String::endsWith(const String &)" , " [String-endsWith-10]" )
88+ {
89+ WHEN (" str2 is larger than str1" )
90+ {
91+ arduino::String str1 (" Hello" );
92+ arduino::String str2 (" Hello World" );
93+ REQUIRE (str1.endsWith (str2) == 0 );
94+ }
95+ WHEN (" str1 ends with str2" )
96+ {
97+ arduino::String str1 (" Hello World" );
98+ arduino::String str2 (" World" );
99+ REQUIRE (str1.endsWith (str2) == 1 );
100+ }
101+ WHEN (" str1 does NOT end with str2" )
102+ {
103+ arduino::String str1 (" Hello World" );
104+ arduino::String str2 (" Helo" );
105+ REQUIRE (str1.endsWith (str2) == 0 );
106+ }
107+ }
0 commit comments