• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_DEMO_COMMON_TEST_H
17 #define CES_CAPI_DEMO_COMMON_TEST_H
18 
19 #include <cstring>
20 #include <napi/native_api.h>
21 #include <hilog/log.h>
22 #include "BasicServicesKit/oh_commonevent.h"
23 #include "BasicServicesKit/oh_commonevent_support.h"
24 
25 #define PARAM_NEGATIVE_1 (-1)
26 #define PARAM_0 0
27 #define PARAM_1 1
28 #define PARAM_4 4
29 #define PARAM_6 6
30 #define SUCCESS 0
31 #define INVALID_PARAM 401
32 
33 #define NAPI_END                                                                                                     \
34     do {                                                                                                             \
35         napi_value result = nullptr;                                                                                 \
36         napi_create_int32(env, SUCCESS, &result);                                                                    \
37         return result;                                                                                               \
38     } while (0)                                                                                                      \
39 
40 #define ASSERT_OBJEQ(result, expect)                                                                                 \
41     do {                                                                                                             \
42         if ((result) != (expect)) {                                                                                  \
43             napi_value errorResult = nullptr;                                                                        \
44             return errorResult;                                                                                      \
45         }                                                                                                            \
46     } while (0)
47 
48 #define ASSERT_OBJNE(result, expect)                                                                                 \
49     do {                                                                                                             \
50         if ((result) == (expect)) {                                                                                  \
51             napi_value errorResult = nullptr;                                                                        \
52             return errorResult;                                                                                      \
53         }                                                                                                            \
54     } while (0)
55 
56 #define ASSERT_EQ(result, expect)                                                                                    \
57     do {                                                                                                             \
58         if ((result) != (expect)) {                                                                                  \
59             napi_value errorResult = nullptr;                                                                        \
60             napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult);                                                  \
61             return errorResult;                                                                                      \
62         }                                                                                                            \
63     } while (0)
64 
65 #define ASSERT_NE(result, expect)                                                                                    \
66     do {                                                                                                             \
67         if ((result) == (expect)) {                                                                                  \
68             napi_value errorResult = nullptr;                                                                        \
69             napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult);                                                  \
70             return errorResult;                                                                                      \
71         }                                                                                                            \
72     } while (0)
73 
74 #define ASSERT_STREQ(result, expect)                                                                                   \
75     do {                                                                                                               \
76         auto *res1 = (result);                                                                                         \
77         decltype(res1) res2 = (expect);                                                                                \
78         if (::strcmp(res1, res2) != 0) {                                                                               \
79             napi_value errorResult = nullptr;                                                                          \
80             napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult);                                                    \
81             return errorResult;                                                                                        \
82         }                                                                                                              \
83     } while (0)
84 
85 #define ASSERT_STRNE(result, expect)                                                                                   \
86     do {                                                                                                               \
87         auto *res1 = (result);                                                                                         \
88         decltype(res1) res2 = (expect);                                                                                \
89         if (::strcmp(res1, res2) == 0) {                                                                               \
90             napi_value errorResult = nullptr;                                                                          \
91             napi_create_int32(env, PARAM_NEGATIVE_1, &errorResult);                                                    \
92             return errorResult;                                                                                        \
93         }                                                                                                              \
94     } while (0)
95 
96 static const char* COMMON_EVENT_TEST = "event_test";
97 static const char* KEY_INT = "int";
98 static const char* KEY_INT_ARRAY = "int_array";
99 static const char* KEY_LONG = "long";
100 static const char* KEY_LONG_ARRAY = "long_array";
101 static const char* KEY_DOUBLE = "double";
102 static const char* KEY_DOUBLE_ARRAY = "double_array";
103 static const char* KEY_BOOL = "bool";
104 static const char* KEY_BOOL_ARRAY = "bool_array";
105 static const char* KEY_CHAR = "char";
106 static const char* KEY_CHAR_ARRAY = "char_array";
107 const unsigned int LOG_PRINT_DOMAIN = 0xFF00;
108 
109 static CommonEvent_Subscriber* subscriber = nullptr;
110 static CommonEvent_SubscribeInfo* subscribeInfo = nullptr;
111 static CommonEvent_PublishInfo* publishInfo = nullptr;
112 static char* dataStr = nullptr;
113 static char* g_publishInfoBN = nullptr;
114 static char* g_publishInfoData = nullptr;
115 static int32_t g_publishInfoCode = PARAM_0;
116 static int32_t g_parametersInt = PARAM_0;
117 static CommonEvent_Parameters* parameters = nullptr;
118 
119 #endif // CES_CAPI_DEMO_COMMON_TEST_H