|
| 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::compareTo(const String &)", "[String-compareTo-01]") |
| 18 | +{ |
| 19 | + WHEN ("Strings are equal") |
| 20 | + { |
| 21 | + arduino::String str1("Hello"), str2("Hello"); |
| 22 | + REQUIRE(str1.compareTo(str2) == 0); |
| 23 | + } |
| 24 | + |
| 25 | + WHEN ("str2 is empty") |
| 26 | + { |
| 27 | + arduino::String str1("Hello"), str2; |
| 28 | + REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str())); |
| 29 | + } |
| 30 | + |
| 31 | + WHEN ("str1 is empty") |
| 32 | + { |
| 33 | + arduino::String str1, str2("Hello"); |
| 34 | + REQUIRE(str1.compareTo(str2) == strcmp(str1.c_str(), str2.c_str())); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +TEST_CASE ("Testing String::compareTo(const char *)", "[String-compareTo-02]") |
| 39 | +{ |
| 40 | + WHEN ("Strings are equal") |
| 41 | + { |
| 42 | + arduino::String str("Hello"); |
| 43 | + REQUIRE(str.compareTo("Hello") == 0); |
| 44 | + } |
| 45 | + |
| 46 | + WHEN ("Passed string is empty") |
| 47 | + { |
| 48 | + arduino::String str1("Hello"), str2(""); |
| 49 | + REQUIRE(str1.compareTo("") == strcmp(str1.c_str(), str2.c_str())); |
| 50 | + } |
| 51 | + |
| 52 | + WHEN ("Passed string is compared with empty string") |
| 53 | + { |
| 54 | + arduino::String str1, str2("Hello"); |
| 55 | + REQUIRE(str1.compareTo("Hello") == strcmp(str1.c_str(), str2.c_str())); |
| 56 | + } |
| 57 | +} |
0 commit comments