| 
 | 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 | +using namespace arduino;  | 
 | 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 | +    ErrorCode ec(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 | +    ErrorCode ec(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 | +    ErrorCode ec(ArduinoELOOP);  | 
 | 41 | +    REQUIRE((bool)ec == false);  | 
 | 42 | +    REQUIRE(ec.error == ArduinoELOOP);  | 
 | 43 | +  }  | 
 | 44 | +}  | 
 | 45 | + | 
0 commit comments