|
| 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::charAt(unsigned int)", "[String-charAt-01]") |
| 18 | +{ |
| 19 | + arduino::String str1("Hello"); |
| 20 | + REQUIRE(str1.charAt(2) == 'l'); |
| 21 | +} |
| 22 | + |
| 23 | +TEST_CASE ("Testing String::setCharAt(unsigned int, char )", "[String-setCharAt-02]") |
| 24 | +{ |
| 25 | + arduino::String str1("Hello"); |
| 26 | + str1.setCharAt(1, 'a'); |
| 27 | + REQUIRE(str1.compareTo("Hallo") == 0); |
| 28 | +} |
| 29 | + |
| 30 | +TEST_CASE ("Testing String::getBytes(unsigned char, unsigned int, unsigned int)", "[String-getBytes-02]") |
| 31 | +{ |
| 32 | + WHEN("No bufsize") { |
| 33 | + arduino::String str("Hello"); |
| 34 | + unsigned char buf[2]; |
| 35 | + str.getBytes(buf, 0, 0); |
| 36 | + } |
| 37 | + |
| 38 | + WHEN("Index >= len") { |
| 39 | + arduino::String str("Hello"); |
| 40 | + unsigned char buf[2]; |
| 41 | + str.getBytes(buf, 5, 6); |
| 42 | + } |
| 43 | + |
| 44 | + WHEN("Valid operation") { |
| 45 | + arduino::String str("Hello"); |
| 46 | + unsigned char buf[2]; |
| 47 | + str.getBytes(buf, 5, 3); |
| 48 | + REQUIRE(buf[0] == 'l'); |
| 49 | + REQUIRE(buf[1] == 'o'); |
| 50 | + } |
| 51 | +} |
0 commit comments