8000 Adding test code for String::concat(...) · arduino/ArduinoCore-API@cbec108 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbec108

Browse files
committed
Adding test code for String::concat(...)
1 parent eb0861f commit cbec108

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(TEST_SRCS
4242
src/Ringbuffer/test_peek.cpp
4343
src/Ringbuffer/test_read_char.cpp
4444
src/Ringbuffer/test_store_char.cpp
45+
src/String/test_concat.cpp
4546
src/String/test_length.cpp
4647
src/String/test_String.cpp
4748
src/WCharacter/test_isControl.cpp

test/src/String/test_concat.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)
0