|
| 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::lastIndexOf(char ch)", "[String-lastIndexOf-01]") |
| 18 | +{ |
| 19 | + WHEN ("str is empty") |
| 20 | + { |
| 21 | + arduino::String str; |
| 22 | + REQUIRE(str.lastIndexOf('a') == -1); |
| 23 | + } |
| 24 | + WHEN ("str does not contained searched element") |
| 25 | + { |
| 26 | + arduino::String str("Hello"); |
| 27 | + REQUIRE(str.lastIndexOf('a') == -1); |
| 28 | + } |
| 29 | + WHEN ("str does contain searched element") |
| 30 | + { |
| 31 | + arduino::String str("Hellolol"); |
| 32 | + REQUIRE(str.lastIndexOf('l') == 7); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +TEST_CASE ("Testing String::lastIndexOf(char ch, unsigned int fromIndex)", "[String-lastIndexOf-02]") |
| 37 | +{ |
| 38 | + WHEN ("str is empty") |
| 39 | + { |
| 40 | + arduino::String str; |
| 41 | + REQUIRE(str.lastIndexOf('a', 5) == -1); |
| 42 | + } |
| 43 | + WHEN ("str does not contained searched element") |
| 44 | + { |
| 45 | + arduino::String str("Hallo"); |
| 46 | + REQUIRE(str.lastIndexOf('o', 3) == -1); |
| 47 | + } |
| 48 | + WHEN ("str does contain searched element") |
| 49 | + { |
| 50 | + arduino::String str("Hellolol"); |
| 51 | + REQUIRE(str.lastIndexOf('l', 3) == 3); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +TEST_CASE ("Testing String::lastIndexOf(const String &)", "[String-lastIndexOf-03]") |
| 56 | +{ |
| 57 | + arduino::String const search_str("Arduino"); |
| 58 | + |
| 59 | + WHEN ("str is empty") |
| 60 | + { |
| 61 | + arduino::String str; |
| 62 | + REQUIRE(str.lastIndexOf(search_str) == -1); |
| 63 | + } |
| 64 | + WHEN ("str does not contained searched element") |
| 65 | + { |
| 66 | + arduino::String str("Hallo"); |
| 67 | + REQUIRE(str.lastIndexOf(search_str) == -1); |
| 68 | + } |
| 69 | + WHEN ("str does contain searched element") |
| 70 | + { |
| 71 | + arduino::String str("Hello Arduino, Arduino!"); |
| 72 | + REQUIRE(str.lastIndexOf(search_str) == 15); |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +TEST_CASE ("Testing String::lastIndexOf(const String &, unsigned int fromIndex)", "[String-lastIndexOf-04]") |
| 77 | +{ |
| 78 | + arduino::String const search_str("Arduino"); |
| 79 | + |
| 80 | + WHEN ("str is empty") |
| 81 | + { |
| 82 | + arduino::String str; |
| 83 | + REQUIRE(str.lastIndexOf(search_str, 3) == -1); |
| 84 | + } |
| 85 | + WHEN ("str does not contained searched element") |
| 86 | + { |
| 87 | + arduino::String str("Hallo"); |
| 88 | + REQUIRE(str.lastIndexOf(search_str, 3) == -1); |
| 89 | + } |
| 90 | + WHEN ("str does contain searched element and fromIndex is > start of searched element") |
| 91 | + { |
| 92 | + arduino::String str("Hello Arduino, Arduino!"); |
| 93 | + REQUIRE(str.lastIndexOf(search_str, 17) == 15); |
| 94 | + } |
| 95 | + WHEN ("str does contain searched element and fromIndex is < start of searched element") |
| 96 | + { |
| 97 | + arduino::String str("Hello Arduino, Arduino!"); |
| 98 | + REQUIRE(str.lastIndexOf(search_str, 3) == -1); |
| 99 | + } |
| 100 | +} |
0 commit comments