Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit0c77d1d

Browse files
Added unit tests for Error codes
1 parent6b8a920 commit0c77d1d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(TEST_SRCS
4949
src/Common/test_map.cpp
5050
src/Common/test_max.cpp
5151
src/Common/test_min.cpp
52+
src/ErrorCodes/test_ErrorCodes.cpp
5253
src/IPAddress/test_toString.cpp
5354
src/IPAddress/test_fromString.cpp
5455
src/IPAddress/test_fromString6.cpp
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: LGPL-2.1-or-later
5+
*/
6+
7+
/**************************************************************************************
8+
* INCLUDE
9+
**************************************************************************************/
10+
11+
#include<catch2/catch_test_macros.hpp>
12+
13+
#include<api/ErrorCodes.h>
14+
15+
usingnamespacearduino;
16+
17+
/**************************************************************************************
18+
* TEST CODE
19+
**************************************************************************************/
20+
21+
TEST_CASE ("An ErrorCode can be evaluated as boolean and respect Arduino values","[ErrorCodes-Evaluation]") {
22+
REQUIRE((bool)ErrorCode(1) ==true);
23+
REQUIRE((bool)ErrorCode(0) ==false);
24+
}
25+
26+
TEST_CASE ("An error is returned with a value different from 0 and 1","[ErrorCodes-Evaluation]") {
27+
THEN ("if the error is well defined the boolean evaluation of the error code respects Arduino standard") {
28+
arduino::error_t err =125;
29+
ErrorCodeec(err);
30+
REQUIRE((bool)ec ==false);
31+
REQUIRE(ec.error == err);
32+
}
33+
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and the value is not preserved") {
34+
int err =125;
35+
ErrorCodeec(err);
36+
REQUIRE((bool)ec ==false);
37+
REQUIRE(ec.error == ArduinoError);
38+
}
39+
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and the value is not preserved") {
40+
ErrorCodeec(ArduinoELOOP);
41+
REQUIRE((bool)ec ==false);
42+
REQUIRE(ec.error == ArduinoELOOP);
43+
}
44+
}
45+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp