Skip to content

Commit 1cf220b

Browse files
committed
Add test case for String::compareTo() with empty buffer
1 parent 3af6c3c commit 1cf220b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/src/String/test_compareTo.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,46 @@ TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]")
5555
REQUIRE(str1.compareTo("Hello") == strcmp(str1.c_str(), str2.c_str()));
5656
}
5757
}
58+
59+
TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String-compareTo-03]")
60+
{
61+
WHEN ("First string has a valid buffer")
62+
{
63+
char *buffer = NULL;
64+
65+
arduino::String str1("Hello");
66+
REQUIRE(str1.compareTo(buffer) != 0);
67+
}
68+
69+
WHEN ("First string does NOT have a valid buffer")
70+
{
71+
char *buffer1 = NULL;
72+
char *buffer2 = NULL;
73+
74+
arduino::String str1(buffer1);
75+
REQUIRE(str1.compareTo(buffer2) == 0);
76+
}
77+
}
78+
79+
80+
TEST_CASE ("Testing String::compareTo(const String &) with empty buffer", "[String-compareTo-04]")
81+
{
82+
WHEN ("First string has a valid buffer")
83+
{
84+
char *buffer = NULL;
85+
86+
arduino::String str1("Hello");
87+
arduino::String str2(buffer);
88+
REQUIRE(str1.compareTo(str2) != 0);
89+
}
90+
91+
WHEN ("First string does NOT have a valid buffer")
92+
{
93+
char *buffer1 = NULL;
94+
char *buffer2 = NULL;
95+
96+
arduino::String str1(buffer1);
97+
arduino::String str2(buffer2);
98+
REQUIRE(str1.compareTo(str2) == 0);
99+
}
100+
}

0 commit comments

Comments
 (0)