-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathtest_ErrorCodes.cpp
More file actions
57 lines (49 loc) · 2.05 KB
/
test_ErrorCodes.cpp
File metadata and controls
57 lines (49 loc) · 2.05 KB
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
51
52
53
54
55
56
/*
* Copyright (c) 2020 Arduino. All rights reserved.
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <catch.hpp>
#include <api/ErrorCodes.h>
using namespace arduino;
/**************************************************************************************
* TEST CODE
**************************************************************************************/
TEST_CASE ("An ErrorCode can be evaluated as boolean and respect Arduino values", "[ErrorCodes-Evaluation]") {
REQUIRE((bool)ErrorCode(1) == true);
REQUIRE((bool)ErrorCode(0) == false);
}
TEST_CASE ("An error is returned with a value different from 0 and 1", "[ErrorCodes-Evaluation]") {
THEN ("if the error is well defined the boolean evaluation of the error code respects Arduino standard") {
arduino::error_t err = 125;
ErrorCode ec(err);
REQUIRE((bool)ec == false);
REQUIRE(ec.error == err);
}
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and error is evaluated to ArduinoSuccess") {
int err = 1;
ErrorCode ec(err);
REQUIRE((bool)ec == true);
REQUIRE(ec.error == ArduinoSuccess);
}
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and error is evaluated to ArduinoError") {
int err = 0;
ErrorCode ec(err);
REQUIRE((bool)ec == false);
REQUIRE(ec.error == ArduinoError);
}
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and the value is not preserved") {
int err = 125;
ErrorCode ec(err);
REQUIRE((bool)ec == false);
REQUIRE(ec.error == ArduinoError);
}
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and the value is not preserved") {
ErrorCode ec(ArduinoELOOP);
REQUIRE((bool)ec == false);
REQUIRE(ec.error == ArduinoELOOP);
}
}