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

Commit5a417ea

Browse files
Added unit tests for Return Values
1 parent047d9a3 commit5a417ea

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ set(TEST_SRCS
4141
src/Common/test_max.cpp
4242
src/Common/test_min.cpp
4343
src/ErrorCodes/test_ErrorCodes.cpp
44+
src/ErrorCodes/test_ReturnValues.cpp
4445
src/IPAddress/test_toString.cpp
4546
src/IPAddress/test_fromString.cpp
4647
src/IPAddress/test_fromString6.cpp
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
inttest_int(int i) {
22+
return i;
23+
}
24+
25+
ReturnValuetest(int i) {
26+
return i;
27+
}
28+
29+
TEST_CASE ("A ReturnValue can be evaluated as boolean","[ReturnValues-Evaluation]") {
30+
// Default constructor takes an integer implicitly, if negative it means error
31+
REQUIRE((bool)ReturnValue(1) ==true);
32+
REQUIRE((bool)ReturnValue(-12) ==false);
33+
}
34+
35+
TEST_CASE ("A ReturnValue can be substituted to int in a function return value","[ReturnValues-Evaluation]") {
36+
REQUIRE((bool)test(1) ==true);
37+
REQUIRE((bool)test(-123) ==false);
38+
REQUIRE(test_int(1) == (int)test(1));
39+
REQUIRE(test_int(-123) == (int)test(-123));
40+
}
41+
42+
TEST_CASE ("A ReturnValue can be instantiated with explicit error code and value","[ReturnValues-Evaluation]") {
43+
THEN("It can take a negative value as value and still be successful") {
44+
auto rv =ReturnValue(-1231, ArduinoSuccess);
45+
46+
REQUIRE((bool)rv ==true);
47+
}
48+
THEN("It can take both a value and an error code") {
49+
auto rv =ReturnValue(-1231, ArduinoError);
50+
51+
REQUIRE((bool)rv ==false);
52+
REQUIRE(rv.value == -1231);
53+
REQUIRE(rv.error == ArduinoError);
54+
}
55+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp