|
| 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::Stringstr1("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::Stringstr("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::Stringstr("Hello"); |
| 34 | +charconst 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::Stringstr("Hello"); |
| 42 | +unsignedcharconst 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::Stringstr("Hello"); |
| 50 | +intconst 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::Stringstr("Hello"); |
| 58 | +unsignedintconst 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::Stringstr("Hello"); |
| 66 | +longconst 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::Stringstr("Hello"); |
| 74 | +unsignedlongconst 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::Stringstr("Hello"); |
| 82 | +floatconst 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::Stringstr("Hello"); |
| 90 | +doubleconst num =5.678; |
| 91 | +REQUIRE(str.concat(num) ==1); |
| 92 | +REQUIRE(strcmp(str.c_str(),"Hello 5.68") ==0); |
| 93 | +} |