|
| 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::concat(const String &)", "[String-concat-01]") |
| 18 | +{ |
| 19 | + arduino::String str1("Hello "), str2("Arduino!"); |
| 20 | + REQUIRE(str1.concat(str2) == 1); |
| 21 | + REQUIRE(strcmp(str1.c_str(), "Hello Arduino!") == 0); |
| 22 | +} |
| 23 | + |
| 24 | +TEST_CASE ("Testing String::concat(const char *)", "[String-concat-02]") |
| 25 | +{ |
| 26 | + arduino::String str("Hello "); |
| 27 | + REQUIRE(str.concat("Arduino!") == 1); |
| 28 | + REQUIRE(strcmp(str.c_str(), "Hello Arduino!") == 0); |
| 29 | +} |
| 30 | + |
| 31 | +TEST_CASE ("Testing String::concat(char)", "[String-concat-03]") |
| 32 | +{ |
| 33 | + arduino::String str("Hello "); |
| 34 | + char const c = 'A'; |
| 35 | + REQUIRE(str.concat(c) == 1); |
| 36 | + REQUIRE(strcmp(str.c_str(), "Hello A") == 0); |
| 37 | +} |
| 38 | + |
| 39 | +TEST_CASE ("Testing String::concat(unsigned char)", "[String-concat-04]") |
| 40 | +{ |
| 41 | + arduino::String str("Hello "); |
| 42 | + unsigned char const c = 'A'; |
| 43 | + REQUIRE(str.concat(c) == 1); |
| 44 | + REQUIRE(strcmp(str.c_str(), "Hello 65") == 0); /* ASCII['A'] = 65 */ |
| 45 | +} |
| 46 | + |
| 47 | +TEST_CASE ("Testing String::concat(int)", "[String-concat-05]") |
| 48 | +{ |
| 49 | + arduino::String str("Hello "); |
| 50 | + int const num = -1; |
| 51 | + REQUIRE(str.concat(num) == 1); |
| 52 | + REQUIRE(strcmp(str.c_str(), "Hello -1") == 0); |
| 53 | +} |
| 54 | + |
| 55 | +TEST_CASE ("Testing String::concat(unsigned int)", "[String-concat-06]") |
| 56 | +{ |
| 57 | + arduino::String str("Hello "); |
| 58 | + unsigned int const num = 1; |
| 59 | + REQUIRE(str.concat(num) == 1); |
| 60 | + REQUIRE(strcmp(str.c_str(), "Hello 1") == 0); |
| 61 | +} |
| 62 | + |
| 63 | +TEST_CASE ("Testing String::concat(long)", "[String-concat-07]") |
| 64 | +{ |
| 65 | + arduino::String str("Hello "); |
| 66 | + long const num = -1; |
| 67 | + REQUIRE(str.concat(num) == 1); |
| 68 | + REQUIRE(strcmp(str.c_str(), "Hello -1") == 0); |
| 69 | +} |
| 70 | + |
| 71 | +TEST_CASE ("Testing String::concat(unsigned long)", "[String-concat-08]") |
| 72 | +{ |
| 73 | + arduino::String str("Hello "); |
| 74 | + unsigned long const num = 1; |
| 75 | + REQUIRE(str.concat(num) == 1); |
| 76 | + REQUIRE(strcmp(str.c_str(), "Hello 1") == 0); |
| 77 | +} |
| 78 | + |
| 79 | +TEST_CASE ("Testing String::concat(float)", "[String-concat-09]") |
| 80 | +{ |
| 81 | + arduino::String str("Hello "); |
| 82 | + float const num = 1.234f; |
| 83 | + REQUIRE(str.concat(num) == 1); |
| 84 | + REQUIRE(strcmp(str.c_str(), "Hello 1.23") == 0); |
| 85 | +} |
| 86 | + |
| 87 | +TEST_CASE ("Testing String::concat(double)", "[String-concat-10]") |
| 88 | +{ |
| 89 | + arduino::String str("Hello "); |
| 90 | + double const num = 5.678; |
| 91 | + REQUIRE(str.concat(num) == 1); |
| 92 | + REQUIRE(strcmp(str.c_str(), "Hello 5.68") == 0); |
| 93 | +} |
0 commit comments