-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy pathtest_toAscii.cpp
50 lines (38 loc) · 1.49 KB
/
test_toAscii.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
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#undef _GNU_SOURCE
#include <catch.hpp>
#include <vector>
#include <WCharacter.h>
/**************************************************************************************
* CONSTANTS
**************************************************************************************/
std::vector<char> const VALID_ASCII_VECT = {' ', 'a', 'b', 'q', '\n', '\r'};
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("toAscii(...) is called with a valid ascii character", "[toAscii-01]")
{
std::for_each(std::begin(VALID_ASCII_VECT),
std::end (VALID_ASCII_VECT),
[](char const c)
{
REQUIRE(arduino::toAscii(c) == c);
});
}
TEST_CASE ("toAscii(...) is called with a invalid ascii character", "[toAscii-02]")
{
REQUIRE(arduino::toAscii(0xf7) == 0x77);
}
TEST_CASE ("toAscii(...) is called with a invalid casted ascii character", "[toAscii-03]")
{
REQUIRE(arduino::toAscii((unsigned char)0xf7) == 0x77);
}
TEST_CASE ("toAscii(...) is called with a character larger than 1 byte", "[toAscii-04]")
{
REQUIRE(arduino::toAscii(0x3030) == 0x30);
}