Skip to content

Commit 1009657

Browse files
committed
Add testcases for toAscii
1 parent 1171abb commit 1009657

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ set(TEST_SRCS
9090
src/WCharacter/test_isSpace.cpp
9191
src/WCharacter/test_isUpperCase.cpp
9292
src/WCharacter/test_isWhitespace.cpp
93+
src/WCharacter/test_toAscii.cpp
9394
)
9495

9596
set(TEST_DUT_SRCS

test/src/WCharacter/test_toAscii.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#undef _GNU_SOURCE
10+
11+
#include <catch.hpp>
12+
13+
#include <vector>
14+
15+
#include <WCharacter.h>
16+
17+
/**************************************************************************************
18+
* CONSTANTS
19+
**************************************************************************************/
20+
21+
std::vector<char> const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'};
22+
23+
/**************************************************************************************
24+
* TEST CODE
25+
**************************************************************************************/
26+
27+
TEST_CASE ("toAscii(...) is called with a valid ascii character", "[toAscii-01]")
28+
{
29+
std::for_each(std::begin(VALID_ASCII_VECT),
30+
std::end (VALID_ASCII_VECT),
31+
[](char const c)
32+
{
33+
REQUIRE(arduino::toAscii(c) == c);
34+
});
35+
}
36+
37+
TEST_CASE ("toAscii(...) is called with a invalid ascii character", "[toAscii-02]")
38+
{
39+
REQUIRE(arduino::toAscii(0xf7) == 0x77);
40+
}
41+
42+
TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toAscii-03]")
43+
{
44+
REQUIRE(arduino::toAscii((unsigned char)0xf7) == 0x77);
45+
}
46+
47+
TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]")
48+
{
49+
REQUIRE(arduino::toAscii(0x3030) == 0x30);
50+
}

0 commit comments

Comments
 (0)