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

Commit74c2f26

Browse files
Added unit tests for Error codes
1 parent6b8a920 commit74c2f26

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 error is evaluated to ArduinoSuccess") {
34+
int err =1;
35+
ErrorCodeec(err);
36+
REQUIRE((bool)ec ==true);
37+
REQUIRE(ec.error == ArduinoSuccess);
38+
}
39+
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and error is evaluated to ArduinoError") {
40+
int err =0;
41+
ErrorCodeec(err);
42+
REQUIRE((bool)ec ==false);
43+
REQUIRE(ec.error == ArduinoError);
44+
}
45+
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and the value is not preserved") {
46+
int err =125;
47+
ErrorCodeec(err);
48+
REQUIRE((bool)ec ==false);
49+
REQUIRE(ec.error == ArduinoError);
50+
}
51+
THEN ("if an int is provided the boolean evaluation of the error code respects Arduino standard and the value is not preserved") {
52+
ErrorCodeec(ArduinoELOOP);
53+
REQUIRE((bool)ec ==false);
54+
REQUIRE(ec.error == ArduinoELOOP);
55+
}
56+
}
57+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp