Skip to content

Commit 5baa2db

Browse files
committed
Adding test code for testing all the String::Ctors(...)
1 parent 19fdf41 commit 5baa2db

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

test/CMakeLists.txt

+1
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_String.cpp
4546
src/WCharacter/test_isControl.cpp
4647
src/WCharacter/test_isDigit.cpp
4748
src/WCharacter/test_isHexadecimalDigit.cpp

test/src/String/test_String.cpp

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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(const char *) constructor()", "[String-Ctor-01]")
18+
{
19+
char const CSTR[] = "Hello Arduino String Class";
20+
arduino::String str(CSTR);
21+
REQUIRE(strcmp(CSTR, str.c_str()) == 0);
22+
}
23+
24+
TEST_CASE ("Testing String(const String &) constructor()", "[String-Ctor-02]")
25+
{
26+
arduino::String str1("Hello Arduino String class"),
27+
str2(str1);
28+
REQUIRE(strcmp(str1.c_str(), str2.c_str()) == 0);
29+
}
30+
31+
TEST_CASE ("Testing String(char) constructor()", "[String-Ctor-03]")
32+
{
33+
char const ch = 'A';
34+
arduino::String str(ch);
35+
REQUIRE(strcmp(str.c_str(), "A") == 0);
36+
}
37+
38+
TEST_CASE ("Testing String(int, unsigned char base = 10) constructor()", "[String-Ctor-04]")
39+
{
40+
int const val = -1;
41+
arduino::String str(val);
42+
REQUIRE(strcmp(str.c_str(), "-1") == 0);
43+
}
44+
45+
TEST_CASE ("Testing String(unsigned int, unsigned char base = 10) constructor()", "[String-Ctor-05]")
46+
{
47+
unsigned int const val = 1;
48+
arduino::String str(val);
49+
REQUIRE(strcmp(str.c_str(), "1") == 0);
50+
}
51+
52+
TEST_CASE ("Testing String(long, unsigned char base = 10) constructor()", "[String-Ctor-06]")
53+
{
54+
long const val = -1;
55+
arduino::String str(val);
56+
REQUIRE(strcmp(str.c_str(), "-1") == 0);
57+
}
58+
59+
TEST_CASE ("Testing String(unsigned long, unsigned char base = 10) constructor()", "[String-Ctor-06]")
60+
{
61+
unsigned long const val = 1;
62+
arduino::String str(val);
63+
REQUIRE(strcmp(str.c_str(), "1") == 0);
64+
}
65+
66+
TEST_CASE ("Testing String(float, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-07]")
67+
{
68+
float const val = 1.234f;
69+
arduino::String str(val);
70+
REQUIRE(strcmp(str.c_str(), "1.23") == 0);
71+
}
72+
73+
TEST_CASE ("Testing String(double, unsigned char decimalPlaces = 2) constructor()", "[String-Ctor-08]")
74+
{
75+
double const val = 5.678;
76+
arduino::String str(val);
77+
REQUIRE(strcmp(str.c_str(), "5.68") == 0);
78+
}

0 commit comments

Comments
 (0)