Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1009657

Browse filesBrowse files
committed
Add testcases for toAscii
1 parent 1171abb commit 1009657
Copy full SHA for 1009657

File tree

2 files changed

+51
-0
lines changed
Filter options

2 files changed

+51
-0
lines changed

‎test/CMakeLists.txt

Copy file name to clipboardExpand all lines: test/CMakeLists.txt
+1Lines changed: 1 addition & 0 deletions
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

Copy file name to clipboard
+50Lines changed: 50 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.