1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef CES_CAPI_XTS_COMMON_TEST_H 17 #define CES_CAPI_XTS_COMMON_TEST_H 18 19 #include <cstring> 20 #include <napi/native_api.h> 21 #include <hilog/log.h> 22 23 namespace CesCapiTest { 24 #define PARAM_NEGATIVE_1 (-1) 25 #define PARAM_0 0 26 #define PARAM_1 1 27 #define PARAM_4 4 28 #define PARAM_6 6 29 #define SUCCESS 0 30 #define INVALID_PARAM 401 31 32 #define NAPI_END \ 33 do { \ 34 napi_value result = nullptr; \ 35 napi_create_int32(env, SUCCESS, &result); \ 36 return result; \ 37 } while (0) \ 38 39 #define ASSERT_OBJEQ(result, expect) \ 40 do { \ 41 if ((result) != (expect)) { \ 42 napi_value errorResult = nullptr; \ 43 return errorResult; \ 44 } \ 45 } while (0) 46 47 #define ASSERT_OBJNE(result, expect) \ 48 do { \ 49 if ((result) == (expect)) { \ 50 napi_value errorResult = nullptr; \ 51 return errorResult; \ 52 } \ 53 } while (0) 54 55 #define ASSERT_EQ(result, expect) \ 56 do { \ 57 if ((result) != (expect)) { \ 58 napi_value errorResult = nullptr; \ 59 napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult); \ 60 return errorResult; \ 61 } \ 62 } while (0) 63 64 #define ASSERT_NE(result, expect) \ 65 do { \ 66 if ((result) == (expect)) { \ 67 napi_value errorResult = nullptr; \ 68 napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult); \ 69 return errorResult; \ 70 } \ 71 } while (0) 72 73 #define ASSERT_STREQ(result, expect) \ 74 do { \ 75 auto *res1 = (result); \ 76 decltype(res1) res2 = (expect); \ 77 if (::strcmp(res1, res2) != 0) { \ 78 napi_value errorResult = nullptr; \ 79 napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult); \ 80 return errorResult; \ 81 } \ 82 } while (0) 83 84 #define ASSERT_STRNE(result, expect) \ 85 do { \ 86 auto *res1 = (result); \ 87 decltype(res1) res2 = (expect); \ 88 if (::strcmp(res1, res2) == 0) { \ 89 napi_value errorResult = nullptr; \ 90 napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult); \ 91 return errorResult; \ 92 } \ 93 } while (0) 94 95 const char* const COMMON_EVENT_TEST = "event_test"; 96 const unsigned int LOG_PRINT_DOMAIN = 0xFF00; 97 98 } // namespace CesCapiTest 99 #endif // CES_CAPI_XTS_COMMON_TEST_H