forked from arduino/ArduinoCore-API
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_characterAccessFunc.cpp
69 lines (57 loc) · 1.69 KB
/
test_characterAccessFunc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <String.h>
#include "StringPrinter.h"
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("Testing String::charAt(unsigned int)", "[String-charAt-01]")
{
arduino::String str1("Hello");
REQUIRE(str1.charAt(2) == 'l');
}
TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt-02]")
{
arduino::String str1("Hello");
str1.setCharAt(1, 'a');
REQUIRE(str1 == "Hallo");
}
TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]")
{
WHEN("No bufsize") {
arduino::String str("Hello");
unsigned char buf[2];
str.getBytes(buf, 0, 0);
}
WHEN("Index >= len") {
arduino::String str("Hello");
unsigned char buf[2];
str.getBytes(buf, 5, 6);
}
WHEN("Valid operation") {
arduino::String str("Hello");
unsigned char buf[3];
str.getBytes(buf, 5, 3);
REQUIRE(buf[0] == 'l');
REQUIRE(buf[1] == 'o');
REQUIRE(buf[2] == '\0');
}
}
TEST_CASE ("Testing & String::operator[]", "[String-&operator[]-03]")
{
arduino::String str("Hello");
str[0] = 'M';
REQUIRE(str == "Mello");
}
TEST_CASE ("Testing & String::operator[] with invalid buffer", "[String-&operator[]-04]")
{
char *buffer = NULL;
arduino::String str(buffer);
str[0] = 'M';
REQUIRE(str[0] == 0);
}