Skip to content

Do not rely on the actual value returned from strcmp in tests, only the sign. #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions test/src/String/test_compareTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ TEST_CASE ("Testing String::compareTo(const String &)", "[String-compareTo-01]")
WHEN ("str2 is empty")
{
arduino::String str1("Hello"), str2;
REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str()));
REQUIRE(str1.compareTo(str2) > 0);
}

WHEN ("str1 is empty")
{
arduino::String str1, str2("Hello");
REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str()));
REQUIRE(str1.compareTo(str2) < 0);
}
}

Expand All @@ -47,14 +47,14 @@ TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]")

WHEN ("Passed string is empty")
{
arduino::String str1("Hello"), str2("");
REQUIRE(str1.compareTo("") == strcmp(str1.c_str(), str2.c_str()));
arduino::String str("Hello");
REQUIRE(str.compareTo("") > 0);
}

WHEN ("Passed string is compared with empty string")
{
arduino::String str1, str2("Hello");
REQUIRE(str1.compareTo("Hello") == strcmp(str1.c_str(), str2.c_str()));
arduino::String str;
REQUIRE(str.compareTo("") == 0);
}
}

Expand All @@ -64,17 +64,17 @@ TEST_CASE ("Testing String::compareTo(const char *) with empty buffer", "[String
{
char *buffer = NULL;

arduino::String str1("Hello");
REQUIRE(str1.compareTo(buffer) != 0);
arduino::String str("Hello");
REQUIRE(str.compareTo(buffer) != 0);
}

WHEN ("First string does NOT have a valid buffer")
{
char *buffer1 = NULL;
char *buffer2 = NULL;

arduino::String str1(buffer1);
REQUIRE(str1.compareTo(buffer2) == 0);
arduino::String str(buffer1);
REQUIRE(str.compareTo(buffer2) == 0);
}
}

Expand Down