Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcbec108

Browse files
committed
Adding test code for String::concat(...)
1 parenteb0861f commitcbec108

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::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+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp