|
| 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 | + |