1 /*
2 * Copyright (C) 2021 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 #include <numeric>
16 #include <iostream>
17 #include <gtest/gtest.h>
18 #include <vector>
19 #include <map>
20 #include <sstream>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <time.h>
24 #include <ctime>
25 #include "hiappevent.h"
26 #include "hiappevent_config.h"
27 #include "hilog/log.h"
28 #include "file_utils.h"
29 #include <securec.h>
30 #include "hiappevent_base.h"
31
32 #define BUFF_SIZE 100
33 using namespace std;
34 using namespace testing;
35 using namespace testing::ext;
36 using namespace OHOS::HiviewDFX;
37
38 namespace{
39 const char* TEST_DOMAIN_NAME = "test_domain";
40 const char* TEST_EVENT_NAME = "test_event";
41 string g_reDiRectTimeout = "5";
42 string logPath = "/data/test/hiappevent/";
43 string delelogPath = "/data/test/hiappevent/*";
44 }
45
46 class HiAppEventCPPTest : public testing::Test{
47 public:
48 void TearDown();
49 private:
50 };
TearDown()51 void HiAppEventCPPTest::TearDown()
52 {
53 std::cout << "TearDown" << std::endl;
54 std::vector<std::string> cmdret;
55 string cmd = "rm -f " + delelogPath;
56 ExecCmdWithRet(cmd, cmdret);
57 }
58
59 /**
60 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
61 * is of the boolean type and the bool value is false.
62 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0100
63 * @author f00601390
64 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
65 */
66 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0100, Function|MediumTest|Level3){
67 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0100 start" << endl;
68 bool result = false;
69 bool boolean = false;
70 string getlogFile;
71 string path;
72 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
73 ParamList list = OH_HiAppEvent_CreateParamList();
74 OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean);
75 EventType eventType = EventType::FAULT;
76 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
77 sleep(1); //等待1s
78 std::vector<std::string> file;
79 file = getfileinpath(logPath);
80 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
81 path = logPath + getlogFile;
82 string fileinfo = "";
83 fileinfo = ReadFile(path);
84 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"bool_key\":false"};
85 if (fileinfo != "") {
86 result = CheckInfo(para, fileinfo);
87 } else {
88 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0100 file error" << std::endl;
89 }
90 OH_HiAppEvent_DestroyParamList(list);
91 ASSERT_TRUE(result);
92 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0100 end" << endl;
93 }
94
95 /**
96 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
97 * is of the boolean type and the bool value is true.
98 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0200
99 * @author f00601390
100 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
101 */
102 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0200, Function|MediumTest|Level3){
103 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0200 start" << endl;
104 bool result = false;
105 bool boolean = true;
106 string getlogFile;
107 string path;
108 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
109 ParamList list = OH_HiAppEvent_CreateParamList();
110 OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean);
111 EventType eventType = EventType::FAULT;
112 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
113 sleep(1); //等待1s
114 std::vector<std::string> file;
115 file = getfileinpath(logPath);
116 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
117 path = logPath + getlogFile;
118 string fileinfo = "";
119 fileinfo = ReadFile(path);
120 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"bool_key\":true"};
121 if (fileinfo != "") {
122 result = CheckInfo(para, fileinfo);
123 } else {
124 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0200 file error" << std::endl;
125 }
126 OH_HiAppEvent_DestroyParamList(list);
127 ASSERT_TRUE(result);
128 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0200 end" << endl;
129 }
130
131 /**
132 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the Boolean List Type.
133 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0300
134 * @author f00601390
135 * @tc.desc The keyvalue is reported as a boolean list.
136 */
137 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0300, Function|MediumTest|Level3){
138 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0300 start" << endl;
139 bool result = false;
140 bool booleans[] = {true, true};
141 string getlogFile;
142 string path;
143 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
144 ParamList list = OH_HiAppEvent_CreateParamList();
145 OH_HiAppEvent_AddBoolArrayParam(list, "bool_arr_key", booleans, sizeof(booleans) / sizeof(booleans[0]));
146 EventType eventType = EventType::FAULT;
147 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
148 sleep(1); //等待1s
149 std::vector<std::string> file;
150 file = getfileinpath(logPath);
151 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
152 path = logPath + getlogFile;
153 string fileinfo = "";
154 fileinfo = ReadFile(path);
155 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"bool_arr_key\":[true,true]"};
156 if (fileinfo != "") {
157 result = CheckInfo(para, fileinfo);
158 } else {
159 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0300 file error" << std::endl;
160 }
161 OH_HiAppEvent_DestroyParamList(list);
162 ASSERT_TRUE(result);
163 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0300 end" << endl;
164 }
165
166 /**
167 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the Boolean List Type.
168 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0400
169 * @author f00601390
170 * @tc.desc The keyvalue is reported as a boolean list.
171 */
172 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0400, Function|MediumTest|Level3){
173 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0400 start" << endl;
174 bool result = false;
175 char str[] = "hello";
176 string getlogFile;
177 string path;
178 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
179 ParamList list = OH_HiAppEvent_CreateParamList();
180 OH_HiAppEvent_AddStringParam(list, "str_key", str);
181 EventType eventType = EventType::BEHAVIOR;
182 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
183 sleep(1); //等待1s
184 std::vector<std::string> file;
185 file = getfileinpath(logPath);
186 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
187 path = logPath + getlogFile;
188 string fileinfo = "";
189 fileinfo = ReadFile(path);
190 std::vector<std::string> para = {"test_event", "\"type_\":4", "\"str_key\":\"hello\""};
191 if (fileinfo != "") {
192 result = CheckInfo(para, fileinfo);
193 } else {
194 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0400 file error" << std::endl;
195 }
196 OH_HiAppEvent_DestroyParamList(list);
197 ASSERT_TRUE(result);
198 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0400 end" << endl;
199 }
200
201 /**
202 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the Boolean List Type.
203 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0500
204 * @author f00601390
205 * @tc.desc The keyvalue is reported as a boolean list.
206 */
207 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0500, Function|MediumTest|Level3){
208 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0500 start" << endl;
209 bool result = false;
210 char str1[] = "hello";
211 char str2[] = "world";
212 char* strs[] = {str1, str2};
213 string getlogFile;
214 string path;
215 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
216 ParamList list = OH_HiAppEvent_CreateParamList();
217 OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0]));
218 EventType eventType = EventType::BEHAVIOR;
219 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
220 sleep(1); //等待1s
221 std::vector<std::string> file;
222 file = getfileinpath(logPath);
223 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
224 path = logPath + getlogFile;
225 string fileinfo = "";
226 fileinfo = ReadFile(path);
227 std::vector<std::string> para = {"test_event", "\"type_\":4", "\"str_arr_key\":[\"hello\",\"world\"]"};
228 if (fileinfo != "") {
229 result = CheckInfo(para, fileinfo);
230 } else {
231 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0500 file error" << std::endl;
232 }
233 OH_HiAppEvent_DestroyParamList(list);
234 ASSERT_TRUE(result);
235 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0500 end" << endl;
236 }
237
238 /**
239 * @tc.name Testing the Native Write Interface of the HiAppEvent, Reporting the Keyvalue of the Double Type.
240 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0800
241 * @author f00601390
242 * @tc.desc The keyvalue type is double.
243 */
244 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0800, Function|MediumTest|Level3){
245 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0800 start" << endl;
246 bool result = false;
247 double num = 30949.374;
248 string getlogFile;
249 string path;
250 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
251 ParamList list = OH_HiAppEvent_CreateParamList();
252 OH_HiAppEvent_AddDoubleParam(list, "double_key", num);
253 EventType eventType = EventType::FAULT;
254 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
255 sleep(1); //等待1s
256 std::vector<std::string> file;
257 file = getfileinpath(logPath);
258 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
259 path = logPath + getlogFile;
260 string fileinfo = "";
261 fileinfo = ReadFile(path);
262 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"double_key\":30949.374"};
263 if (fileinfo != "") {
264 result = CheckInfo(para, fileinfo);
265 } else {
266 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0800 file error" << std::endl;
267 }
268 OH_HiAppEvent_DestroyParamList(list);
269 ASSERT_TRUE(result);
270 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0800 end" << endl;
271 }
272
273 /**
274 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of a Double List.
275 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_0900
276 * @author f00601390
277 * @tc.desc The keyvalue is reported as a double list.
278 */
279 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_0900, Function|MediumTest|Level3){
280 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0900 start" << endl;
281 bool result = false;
282 double nums[] = {123.22, 30949.374, 131312.46464};
283 string getlogFile;
284 string path;
285 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
286 ParamList list = OH_HiAppEvent_CreateParamList();
287 OH_HiAppEvent_AddDoubleArrayParam(list, "double_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
288 EventType eventType = EventType::STATISTIC;
289 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
290 sleep(1); //等待1s
291 std::vector<std::string> file;
292 file = getfileinpath(logPath);
293 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
294 path = logPath + getlogFile;
295 string fileinfo = "";
296 fileinfo = ReadFile(path);
297 std::vector<std::string> para = {"test_event", "\"type_\":2", "\"double_arr_key\":[123.22,30949.374,131312.46464]"};
298 if (fileinfo != "") {
299 result = CheckInfo(para, fileinfo);
300 } else {
301 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_0900 file error" << std::endl;
302 }
303 OH_HiAppEvent_DestroyParamList(list);
304 ASSERT_TRUE(result);
305 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_0900 end" << endl;
306 }
307
308 /**
309 * @tc.name HiAppEvent Native Write Interface Test, Reporting the KeyValue of the Floating Type.
310 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1000
311 * @author f00601390
312 * @tc.desc The keyvalue type is float.
313 */
314 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1000, Function|MediumTest|Level3){
315 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1000 start" << endl;
316 bool result = false;
317 float num = 234.5f;
318 string getlogFile;
319 string path;
320 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
321 ParamList list = OH_HiAppEvent_CreateParamList();
322 OH_HiAppEvent_AddFloatParam(list, "float_key", num);
323 EventType eventType = EventType::STATISTIC;
324 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
325 sleep(1); //等待1s
326 std::vector<std::string> file;
327 file = getfileinpath(logPath);
328 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
329 path = logPath + getlogFile;
330 string fileinfo = "";
331 fileinfo = ReadFile(path);
332 std::vector<std::string> para = {"test_event", "\"type_\":2", "\"float_key\":234.5"};
333 if (fileinfo != "") {
334 result = CheckInfo(para, fileinfo);
335 } else {
336 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1000 file error" << std::endl;
337 }
338 OH_HiAppEvent_DestroyParamList(list);
339 ASSERT_TRUE(result);
340 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1000 end" << endl;
341 }
342
343 /**
344 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of a Floating List.
345 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1100
346 * @author f00601390
347 * @tc.desc The keyvalue is reported as a float list.
348 */
349 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1100, Function|MediumTest|Level3){
350 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1100 start" << endl;
351 bool result = false;
352 float nums[] = {123.22f, 234.5f, 131312.46464f};
353 string getlogFile;
354 string path;
355 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
356 ParamList list = OH_HiAppEvent_CreateParamList();
357 OH_HiAppEvent_AddFloatArrayParam(list, "float_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
358 EventType eventType = EventType::STATISTIC;
359 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
360 sleep(1); //等待1s
361 std::vector<std::string> file;
362 file = getfileinpath(logPath);
363 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
364 path = logPath + getlogFile;
365 string fileinfo = "";
366 fileinfo = ReadFile(path);
367 std::vector<std::string> para = {"test_event", "\"type_\":2", "\"float_arr_key\":[123.22", "234.5", "131312.46"};
368 if (fileinfo != "") {
369 result = CheckInfo(para, fileinfo);
370 } else {
371 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1100 file error" << std::endl;
372 }
373 OH_HiAppEvent_DestroyParamList(list);
374 ASSERT_TRUE(result);
375 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1100 end" << endl;
376 }
377
378 /**
379 * @tc.name HiAppEvent Native Write Interface Test, Reported When the Keyvalue Is of the Int Type.
380 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1200
381 * @author f00601390
382 * @tc.desc The keyvalue is of the int type.
383 */
384 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1200, Function|MediumTest|Level3){
385 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1200 start" << endl;
386 bool result = false;
387 int num = 1;
388 string getlogFile;
389 string path;
390 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
391 ParamList list = OH_HiAppEvent_CreateParamList();
392 OH_HiAppEvent_AddInt8Param(list, "int8_key", num);
393 EventType eventType = EventType::SECURITY;
394 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
395 sleep(1); //等待1s
396 std::vector<std::string> file;
397 file = getfileinpath(logPath);
398 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
399 path = logPath + getlogFile;
400 string fileinfo = "";
401 fileinfo = ReadFile(path);
402 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int8_key\":1"};
403 if (fileinfo != "") {
404 result = CheckInfo(para, fileinfo);
405 } else {
406 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1200 file error" << std::endl;
407 }
408 OH_HiAppEvent_DestroyParamList(list);
409 ASSERT_TRUE(result);
410 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1200 end" << endl;
411 }
412
413 /**
414 * @tc.name HiAppEvent Native Write Interface Test, Reporting of the int List Type of Keyvalue.
415 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1300
416 * @author f00601390
417 * @tc.desc The keyvalue is reported as an int list.
418 */
419 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1300, Function|MediumTest|Level3){
420 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1300 start" << endl;
421 bool result = false;
422 int8_t nums[] = {1, 10, 100};
423 string getlogFile;
424 string path;
425 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
426 ParamList list = OH_HiAppEvent_CreateParamList();
427 OH_HiAppEvent_AddInt8ArrayParam(list, "int8_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
428 EventType eventType = EventType::SECURITY;
429 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
430 sleep(1); //等待1s
431 std::vector<std::string> file;
432 file = getfileinpath(logPath);
433 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
434 path = logPath + getlogFile;
435 string fileinfo = "";
436 fileinfo = ReadFile(path);
437 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int8_arr_key\":[1,10,100]"};
438 if (fileinfo != "") {
439 result = CheckInfo(para, fileinfo);
440 } else {
441 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1300 file error" << std::endl;
442 }
443 OH_HiAppEvent_DestroyParamList(list);
444 ASSERT_TRUE(result);
445 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1300 end" << endl;
446 }
447
448 /**
449 * @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type.
450 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1400
451 * @author f00601390
452 * @tc.desc The keyvalue type is long.
453 */
454 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1400, Function|MediumTest|Level3){
455 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1400 start" << endl;
456 bool result = false;
457 int16_t num = 1;
458 string getlogFile;
459 string path;
460 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
461 ParamList list = OH_HiAppEvent_CreateParamList();
462 OH_HiAppEvent_AddInt16Param(list, "int16_key", num);
463 EventType eventType = EventType::SECURITY;
464 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
465 sleep(1); //等待1s
466 std::vector<std::string> file;
467 file = getfileinpath(logPath);
468 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
469 path = logPath + getlogFile;
470 string fileinfo = "";
471 fileinfo = ReadFile(path);
472 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int16_key\":1"};
473 if (fileinfo != "") {
474 result = CheckInfo(para, fileinfo);
475 } else {
476 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1400 file error" << std::endl;
477 }
478 OH_HiAppEvent_DestroyParamList(list);
479 ASSERT_TRUE(result);
480 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1400 end" << endl;
481 }
482
483 /**
484 * @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type.
485 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1500
486 * @author f00601390
487 * @tc.desc The keyvalue type is long.
488 */
489 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1500, Function|MediumTest|Level3){
490 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1500 start" << endl;
491 bool result = false;
492 int16_t nums[] = {1, 1000, 5000};
493 string getlogFile;
494 string path;
495 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
496 ParamList list = OH_HiAppEvent_CreateParamList();
497 OH_HiAppEvent_AddInt16ArrayParam(list, "int16_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
498 EventType eventType = EventType::SECURITY;
499 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
500 sleep(1); //等待1s
501 std::vector<std::string> file;
502 file = getfileinpath(logPath);
503 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
504 path = logPath + getlogFile;
505 string fileinfo = "";
506 fileinfo = ReadFile(path);
507 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int16_arr_key\":[1,1000,5000]"};
508 if (fileinfo != "") {
509 result = CheckInfo(para, fileinfo);
510 } else {
511 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1500 file error" << std::endl;
512 }
513 OH_HiAppEvent_DestroyParamList(list);
514 ASSERT_TRUE(result);
515 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1500 end" << endl;
516 }
517
518 /**
519 * @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type.
520 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1600
521 * @author f00601390
522 * @tc.desc The keyvalue type is long.
523 */
524 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1600, Function|MediumTest|Level3){
525 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1600 start" << endl;
526 bool result = false;
527 int32_t num = 1;
528 string getlogFile;
529 string path;
530 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
531 ParamList list = OH_HiAppEvent_CreateParamList();
532 OH_HiAppEvent_AddInt32Param(list, "int32_key", num);
533 EventType eventType = EventType::SECURITY;
534 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
535 sleep(1); //等待1s
536 std::vector<std::string> file;
537 file = getfileinpath(logPath);
538 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
539 path = logPath + getlogFile;
540 string fileinfo = "";
541 fileinfo = ReadFile(path);
542 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int32_key\":1"};
543 if (fileinfo != "") {
544 result = CheckInfo(para, fileinfo);
545 } else {
546 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1600 file error" << std::endl;
547 }
548 OH_HiAppEvent_DestroyParamList(list);
549 ASSERT_TRUE(result);
550 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1600 end" << endl;
551 }
552
553 /**
554 * @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type.
555 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1700
556 * @author f00601390
557 * @tc.desc The keyvalue type is long.
558 */
559 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1700, Function|MediumTest|Level3){
560 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1700 start" << endl;
561 bool result = false;
562 int32_t nums[] = {1, 100000, 500000};
563 string getlogFile;
564 string path;
565 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
566 ParamList list = OH_HiAppEvent_CreateParamList();
567 OH_HiAppEvent_AddInt32ArrayParam(list, "int32_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
568 EventType eventType = EventType::SECURITY;
569 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
570 sleep(1); //等待1s
571 std::vector<std::string> file;
572 file = getfileinpath(logPath);
573 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
574 path = logPath + getlogFile;
575 string fileinfo = "";
576 fileinfo = ReadFile(path);
577 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int32_arr_key\":[1,100000,500000]"};
578 if (fileinfo != "") {
579 result = CheckInfo(para, fileinfo);
580 } else {
581 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1700 file error" << std::endl;
582 }
583 OH_HiAppEvent_DestroyParamList(list);
584 ASSERT_TRUE(result);
585 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1700 end" << endl;
586 }
587
588 /**
589 * @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type.
590 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1800
591 * @author f00601390
592 * @tc.desc The keyvalue type is long.
593 */
594 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1800, Function|MediumTest|Level3){
595 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1800 start" << endl;
596 bool result = false;
597 int64_t num = 1;
598 string getlogFile;
599 string path;
600 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
601 ParamList list = OH_HiAppEvent_CreateParamList();
602 OH_HiAppEvent_AddInt64Param(list, "int64_key", num);
603 EventType eventType = EventType::SECURITY;
604 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
605 sleep(1); //等待1s
606 std::vector<std::string> file;
607 file = getfileinpath(logPath);
608 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
609 path = logPath + getlogFile;
610 string fileinfo = "";
611 fileinfo = ReadFile(path);
612 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int64_key\":1"};
613 if (fileinfo != "") {
614 result = CheckInfo(para, fileinfo);
615 } else {
616 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1800 file error" << std::endl;
617 }
618 OH_HiAppEvent_DestroyParamList(list);
619 ASSERT_TRUE(result);
620 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1800 end" << endl;
621 }
622
623 /**
624 * @tc.name HiAppEvent Native Write Interface Test Reported When the Keyvalue Is of the Long Type.
625 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_1900
626 * @author f00601390
627 * @tc.desc The keyvalue type is long.
628 */
629 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_1900, Function|MediumTest|Level3){
630 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1900 start" << endl;
631 bool result = false;
632 int64_t nums[] = {1, 10000000, 50000000};
633 string getlogFile;
634 string path;
635 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
636 ParamList list = OH_HiAppEvent_CreateParamList();
637 OH_HiAppEvent_AddInt64ArrayParam(list, "int64_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
638 EventType eventType = EventType::SECURITY;
639 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
640 sleep(1); //等待1s
641 std::vector<std::string> file;
642 file = getfileinpath(logPath);
643 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
644 path = logPath + getlogFile;
645 string fileinfo = "";
646 fileinfo = ReadFile(path);
647 std::vector<std::string> para = {"test_event", "\"type_\":3", "\"int64_arr_key\":[1,10000000,50000000]"};
648 if (fileinfo != "") {
649 result = CheckInfo(para, fileinfo);
650 } else {
651 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_1900 file error" << std::endl;
652 }
653 OH_HiAppEvent_DestroyParamList(list);
654 ASSERT_TRUE(result);
655 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_1900 end" << endl;
656 }
657
658 /**
659 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the string List Type.
660 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2100
661 * @author f00601390
662 * @tc.desc The keyvalue is reported as a string list, 100 list parameters .
663 */
664 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2100, Function|MediumTest|Level3){
665 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2100 start" << endl;
666 bool result = false;
667 char* strs[100];
668 int num = 32;
669 for(int i=0;i<100;i++){
670 strs[i] = new char[32];
671 sprintf_s(strs[i], num,"hello_world_%d",i);
672 std::cout << sizeof(strs[i]) << std::endl;
673 std::cout << strs[i] << std::endl;
674 }
675 string getlogFile;
676 string path;
677 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
678 ParamList list = OH_HiAppEvent_CreateParamList();
679 OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0]));
680 EventType eventType = EventType::BEHAVIOR;
681 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
682 sleep(1); //等待1s
683 std::vector<std::string> file;
684 file = getfileinpath(logPath);
685 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
686 path = logPath + getlogFile;
687 string fileinfo = "";
688 fileinfo = ReadFile(path);
689 std::vector<std::string> para = {"test_event", "\"type_\":4"};
690 if (fileinfo != "") {
691 result = CheckInfo(para, fileinfo);
692 } else {
693 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2100 file error" << std::endl;
694 }
695 OH_HiAppEvent_DestroyParamList(list);
696 ASSERT_TRUE(result);
697 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2100 end" << endl;
698 }
699
700 /**
701 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Keyvalue of the string Type.
702 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2200
703 * @author f00601390
704 * @tc.desc The keyvalue is reported as a string, 8 * 1024 lenth.
705 */
706 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2200, Function|MediumTest|Level4){
707 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2200 start" << endl;
708 bool result = false;
709 string strs = "";
710 for(int i=0;i<1024;i++){
711 strs.append("abcdefgh");
712 }
713 string getlogFile;
714 string path;
715 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
716 ParamList list = OH_HiAppEvent_CreateParamList();
717 OH_HiAppEvent_AddStringParam(list, "str_key", strs.c_str());
718 EventType eventType = EventType::BEHAVIOR;
719 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
720 sleep(1); //等待1s
721 std::vector<std::string> file;
722 file = getfileinpath(logPath);
723 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
724 path = logPath + getlogFile;
725 string fileinfo = "";
726 fileinfo = ReadFile(path);
727 std::vector<std::string> para = {"test_event", "\"type_\":4"};
728 if (fileinfo != "") {
729 result = CheckInfo(para, fileinfo);
730 } else {
731 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2200 file error" << std::endl;
732 }
733 OH_HiAppEvent_DestroyParamList(list);
734 ASSERT_TRUE(result);
735 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2200 end" << endl;
736 }
737
738 /**
739 * @tc.name HiAppEvent Native Write Interface Test, Reporting the event name is null.
740 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2300
741 * @author f00601390
742 * @tc.desc Reported event name is null.
743 */
744 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2300, Function|MediumTest|Level4){
745 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2300 start" << endl;
746 char str[] = "hello";
747 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
748 ParamList list = OH_HiAppEvent_CreateParamList();
749 OH_HiAppEvent_AddStringParam(list, "str_key", str);
750 EventType eventType = EventType::FAULT;
751 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, NULL, eventType, list);
752 sleep(1); //等待1s
753 OH_HiAppEvent_DestroyParamList(list);
754 ASSERT_TRUE(ret == -1);
755 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2300 end" << endl;
756 }
757
758 /**
759 * @tc.name HiAppEvent Native Write Interface Test, Reporting the event name is empty.
760 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2400
761 * @author f00601390
762 * @tc.desc Reported event name is empty.
763 */
764 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2400, Function|MediumTest|Level3){
765 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2400 start" << endl;
766 char str[] = "hello";
767 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
768 ParamList list = OH_HiAppEvent_CreateParamList();
769 OH_HiAppEvent_AddStringParam(list, "str_key", str);
770 EventType eventType = EventType::FAULT;
771 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "", eventType, list);
772 sleep(1); //等待1s
773 OH_HiAppEvent_DestroyParamList(list);
774 ASSERT_TRUE(ret == -1);
775 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2400 end" << endl;
776 }
777
778 /**
779 * @tc.name HiAppEvent Native Write Interface Test, Reporting the event name starts with number.
780 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2500
781 * @author f00601390
782 * @tc.desc Reported event name starts with number.
783 */
784 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2500, Function|MediumTest|Level3){
785 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2500 start" << endl;
786 char str[] = "hello";
787 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
788 ParamList list = OH_HiAppEvent_CreateParamList();
789 OH_HiAppEvent_AddStringParam(list, "str_key", str);
790 EventType eventType = EventType::FAULT;
791 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, "9527_test_event", eventType, list);
792 sleep(1); //等待1s
793 OH_HiAppEvent_DestroyParamList(list);
794 ASSERT_TRUE(ret == -1);
795 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2500 end" << endl;
796 }
797
798 /**
799 * @tc.name HiAppEvent Native Write Interface Test, 33 parameters are reported.
800 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2700
801 * @author f00601390
802 * @tc.desc key and values 33 parameters are reported.
803 */
804 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2700, Function|MediumTest|Level4){
805 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2700 start" << endl;
806 bool result = false;
807 string getlogFile;
808 string path;
809 int maxLen = 32;
810 string keys[maxLen + 1];
811 string values[maxLen + 1];
812 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
813 ParamList list = OH_HiAppEvent_CreateParamList();
814 for (int i = 0; i <= maxLen; i++){
815 keys[i] = "key" + std::to_string(i);
816 values[i] = "value" + std::to_string(i);
817 OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str());
818 }
819 EventType eventType = EventType::FAULT;
820 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
821 sleep(1); //等待1s
822 std::vector<std::string> file;
823 file = getfileinpath(logPath);
824 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
825 path = logPath + getlogFile;
826 string fileinfo = "";
827 fileinfo = ReadFile(path);
828 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"", "\"key15\":\"value15\""};
829 if (fileinfo != "") {
830 result = CheckInfo(para, fileinfo);
831 } else {
832 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2700 file error" << std::endl;
833 }
834 OH_HiAppEvent_DestroyParamList(list);
835 ASSERT_TRUE(ret == 5);
836 ASSERT_TRUE(result);
837 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2700 end" << endl;
838 }
839
840 /**
841 * @tc.name HiAppEvent Native Write Interface Test, key and value is empty.
842 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2800
843 * @author f00601390
844 * @tc.desc key and value is empty.
845 */
846 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2800, Function|MediumTest|Level3){
847 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2800 start" << endl;
848 bool result = false;
849 string getlogFile;
850 string path;
851 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
852 ParamList list = OH_HiAppEvent_CreateParamList();
853 OH_HiAppEvent_AddStringParam(list, "", "");
854 EventType eventType = EventType::FAULT;
855 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
856 sleep(1); //等待1s
857 std::vector<std::string> file;
858 file = getfileinpath(logPath);
859 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
860 path = logPath + getlogFile;
861 string fileinfo = "";
862 fileinfo = ReadFile(path);
863 std::vector<std::string> para = {"test_event", "\"type_\":1"};
864 if (fileinfo != "") {
865 result = CheckInfo(para, fileinfo);
866 } else {
867 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2800 file error" << std::endl;
868 }
869 OH_HiAppEvent_DestroyParamList(list);
870 ASSERT_TRUE(result);
871 ASSERT_TRUE(ret == 1);
872 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2800 end" << endl;
873 }
874
875 /**
876 * @tc.name HiAppEvent Native Write Interface Test, key is not string type.
877 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_2900
878 * @author f00601390
879 * @tc.desc key is not string type.
880 */
881 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_2900, Function|MediumTest|Level4){
882 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2900 start" << endl;
883 bool result = false;
884 string getlogFile;
885 string path;
886 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
887 ParamList list = OH_HiAppEvent_CreateParamList();
888 OH_HiAppEvent_AddStringParam(list, "", "hello");
889 EventType eventType = EventType::FAULT;
890 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
891 sleep(1); //等待1s
892 std::vector<std::string> file;
893 file = getfileinpath(logPath);
894 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
895 path = logPath + getlogFile;
896 string fileinfo = "";
897 fileinfo = ReadFile(path);
898 std::vector<std::string> para = {"test_event", "\"type_\":1"};
899 if (fileinfo != "") {
900 result = CheckInfo(para, fileinfo);
901 } else {
902 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_2900 file error" << std::endl;
903 }
904 OH_HiAppEvent_DestroyParamList(list);
905 ASSERT_TRUE(result);
906 ASSERT_TRUE(ret == 1);
907 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_2900 end" << endl;
908 }
909
910 /**
911 * @tc.name HiAppEvent Native Write Interface Test, key start with number.
912 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3000
913 * @author f00601390
914 * @tc.desc key start with number.
915 */
916 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3000, Function|MediumTest|Level4){
917 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3000 start" << endl;
918 bool result = false;
919 string getlogFile;
920 string path;
921 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
922 ParamList list = OH_HiAppEvent_CreateParamList();
923 OH_HiAppEvent_AddStringParam(list, "9527_hello", "world");
924 EventType eventType = EventType::FAULT;
925 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
926 sleep(1); //等待1s
927 std::vector<std::string> file;
928 file = getfileinpath(logPath);
929 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
930 path = logPath + getlogFile;
931 string fileinfo = "";
932 fileinfo = ReadFile(path);
933 std::vector<std::string> para = {"test_event", "\"type_\":1"};
934 if (fileinfo != "") {
935 result = CheckInfo(para, fileinfo);
936 } else {
937 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3000 file error" << std::endl;
938 }
939 OH_HiAppEvent_DestroyParamList(list);
940 ASSERT_TRUE(result);
941 ASSERT_TRUE(ret == 1);
942 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3000 end" << endl;
943 }
944
945 /**
946 * @tc.name HiAppEvent Native Write Interface Test, Reporting the Key value of the string Type.
947 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3100
948 * @author f00601390
949 * @tc.desc The keyvalue is reported as a string, 8 * 1024 + 1 length.
950 */
951 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3100, Function|MediumTest|Level4){
952 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3100 start" << endl;
953 bool result = false;
954 string strs = "";
955 for(int i=0;i<1024;i++){
956 strs.append("abcdefgh");
957 }
958 strs.append("a");
959 string getlogFile;
960 string path;
961 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
962 ParamList list = OH_HiAppEvent_CreateParamList();
963 OH_HiAppEvent_AddStringParam(list, "str_key", strs.c_str());
964 EventType eventType = EventType::FAULT;
965 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
966 sleep(1); //等待1s
967 std::vector<std::string> file;
968 file = getfileinpath(logPath);
969 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
970 path = logPath + getlogFile;
971 string fileinfo = "";
972 fileinfo = ReadFile(path);
973 std::vector<std::string> para = {"test_event", "\"type_\":1"};
974 if (fileinfo != "") {
975 result = CheckInfo(para, fileinfo);
976 } else {
977 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3100 file error" << std::endl;
978 }
979 OH_HiAppEvent_DestroyParamList(list);
980 ASSERT_TRUE(result);
981 ASSERT_TRUE(ret == 4);
982 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3100 end" << endl;
983 }
984
985 /**
986 * @tc.name HiAppEvent Native Write Interface Test, key and value is NULL.
987 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3200
988 * @author f00601390
989 * @tc.desc key and value is NULL.
990 */
991 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3200, Function|MediumTest|Level3){
992 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3200 start" << endl;
993 bool result = false;
994 string getlogFile;
995 string path;
996 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
997 ParamList list = OH_HiAppEvent_CreateParamList();
998 OH_HiAppEvent_AddStringParam(list, NULL, NULL);
999 EventType eventType = EventType::FAULT;
1000 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
1001 sleep(1); //等待1s
1002 std::vector<std::string> file;
1003 file = getfileinpath(logPath);
1004 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
1005 path = logPath + getlogFile;
1006 string fileinfo = "";
1007 fileinfo = ReadFile(path);
1008 std::vector<std::string> para = {"test_event", "\"type_\":1"};
1009 if (fileinfo != "") {
1010 result = CheckInfo(para, fileinfo);
1011 } else {
1012 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3200 file error" << std::endl;
1013 }
1014 OH_HiAppEvent_DestroyParamList(list);
1015 ASSERT_TRUE(ret == 0);
1016 ASSERT_TRUE(result);
1017 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3200 end" << endl;
1018 }
1019
1020 /**
1021 * @tc.name HiAppEvent Native Write Interface Test, List Type Reporting,101 List Parameters.
1022 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3300
1023 * @author f00601390
1024 * @tc.desc 101 List Parameters.
1025 */
1026 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3300, Function|MediumTest|Level4){
1027 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3300 start" << endl;
1028 bool result = false;
1029 char* strs[101];
1030 int num = 32;
1031 for(int i=0;i<101;i++){
1032 strs[i] = new char[32];
1033 sprintf_s(strs[i], num,"hello_world_%d",i);
1034 std::cout << sizeof(strs[i]) << std::endl;
1035 std::cout << strs[i] << std::endl;
1036 }
1037 string getlogFile;
1038 string path;
1039 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
1040 ParamList list = OH_HiAppEvent_CreateParamList();
1041 OH_HiAppEvent_AddStringArrayParam(list, "str_arr_key", strs, sizeof(strs) / sizeof(strs[0]));
1042 EventType eventType = EventType::BEHAVIOR;
1043 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
1044 sleep(1); //等待1s
1045 std::vector<std::string> file;
1046 file = getfileinpath(logPath);
1047 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
1048 path = logPath + getlogFile;
1049 string fileinfo = "";
1050 fileinfo = ReadFile(path);
1051 std::vector<std::string> para = {"test_event", "\"type_\":4", "\"str_arr_key\":[\"hello_world_0\",\"hello_world_1\",\"hello_world_2\"", "hello_world_99"};
1052 if (fileinfo != "") {
1053 result = CheckInfo(para, fileinfo);
1054 } else {
1055 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3300 file error" << std::endl;
1056 }
1057 OH_HiAppEvent_DestroyParamList(list);
1058 ASSERT_TRUE(ret == 6);
1059 ASSERT_TRUE(result);
1060 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3300 end" << endl;
1061 }
1062
1063 /**
1064 * @tc.name HiAppEvent Native Write Interface Test, 32 parameters are reported.
1065 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3400
1066 * @author f00601390
1067 * @tc.desc key and values 32 parameters are reported.
1068 */
1069 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3400, Function|MediumTest|Level4){
1070 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3400 start" << endl;
1071 bool result = false;
1072 string getlogFile;
1073 string path;
1074 int maxLen = 32;
1075 string keys[maxLen+1];
1076 string values[maxLen+1];
1077 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
1078 ParamList list = OH_HiAppEvent_CreateParamList();
1079 for (int i = 0; i <= maxLen; i++){
1080 keys[i] = "key" + std::to_string(i);
1081 values[i] = "value" + std::to_string(i);
1082 OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str());
1083 }
1084 EventType eventType = EventType::FAULT;
1085 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
1086 sleep(1); //等待1s
1087 std::vector<std::string> file;
1088 file = getfileinpath(logPath);
1089 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
1090 path = logPath + getlogFile;
1091 string fileinfo = "";
1092 fileinfo = ReadFile(path);
1093 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"","\"key15\":\"value15\"","\"key0\":\"value0\""};
1094 if (fileinfo != "") {
1095 result = CheckInfo(para, fileinfo);
1096 } else {
1097 std::cout << "DFX_DFT_HiviewKit_HiAppEvent_Native_3400 file error" << std::endl;
1098 }
1099 OH_HiAppEvent_DestroyParamList(list);
1100 ASSERT_TRUE(ret == 5);
1101 ASSERT_TRUE(result);
1102 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3400 end" << endl;
1103 }
1104
1105 /**
1106 * @tc.name HiAppEvent Native Write Interface Test, 32 parameters are reported.
1107 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3500
1108 * @author f00601390
1109 * @tc.desc key and values 32 parameters are reported.
1110 */
1111 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3500, Function|MediumTest|Level4){
1112 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3500 start" << endl;
1113 string getlogFile;
1114 string path;
1115 OH_HiAppEvent_Configure("max_storage", "10M");
1116 int maxLen = 32;
1117 string keys[maxLen+1];
1118 string values[maxLen+1];
1119 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
1120 std::vector<std::string> cmdret;
1121 time_t nowtime;
1122 struct tm* p;
1123 time(&nowtime);
1124 p = localtime(&nowtime);
1125 char s[25];
1126 sprintf_s(s, sizeof(s),"app_event_%d%02d%02d.log", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
1127 std::cout << s << std::endl;
1128 string fname = s;
1129 string cmd = "dd if=/dev/zero of=/data/test/hiappevent/" + fname + " bs=11M count=1";
1130 ExecCmdWithRet(cmd, cmdret);
1131 ParamList list = OH_HiAppEvent_CreateParamList();
1132 for (int i = 0; i <= maxLen; i++){
1133 keys[i] = "key" + std::to_string(i);
1134 values[i] = "value" + std::to_string(i);
1135 OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str());
1136 }
1137 EventType eventType = EventType::FAULT;
1138 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
1139 sleep(1); //等待1s
1140 std::vector<std::string> file;
1141 file = getfileinpath(logPath);
1142 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
1143 path = logPath + getlogFile;
1144 bool result = false;
1145 string fileinfo = ReadFile(path);
1146 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"","\"key15\":\"value15\"","\"key0\":\"value0\""};
1147 if (fileinfo != "") {
1148 result = CheckInfo(para, fileinfo);
1149 }
1150 OH_HiAppEvent_DestroyParamList(list);
1151 ASSERT_TRUE(result);
1152 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3500 end" << endl;
1153 }
1154
1155 /**
1156 * @tc.name HiAppEvent Native Write Interface Test, 32 parameters are reported.
1157 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3500
1158 * @author f00601390
1159 * @tc.desc key and values 32 parameters are reported.
1160 */
1161 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3600, Function|MediumTest|Level4){
1162 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3600 start" << endl;
1163 string getlogFile;
1164 string path;
1165 OH_HiAppEvent_Configure("max_storage", "1M");
1166 int maxLen = 32;
1167 string keys[maxLen+1];
1168 string values[maxLen+1];
1169 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
1170 std::vector<std::string> cmdret;
1171 time_t nowtime;
1172 struct tm* p;
1173 time(&nowtime);
1174 p = localtime(&nowtime);
1175 char s[25];
1176 sprintf_s(s, sizeof(s),"app_event_%d%02d%02d.log", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);
1177 string fname = s;
1178 string cmd = "dd if=/dev/zero of=/data/test/hiappevent/" + fname + " bs=1.5M count=1";
1179 ExecCmdWithRet(cmd, cmdret);
1180 ParamList list = OH_HiAppEvent_CreateParamList();
1181 for (int i = 0; i <= maxLen; i++){
1182 keys[i] = "key" + std::to_string(i);
1183 values[i] = "value" + std::to_string(i);
1184 OH_HiAppEvent_AddStringParam(list, keys[i].c_str(), values[i].c_str());
1185 }
1186 EventType eventType = EventType::FAULT;
1187 OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
1188 sleep(1); //等待1s
1189 std::vector<std::string> file;
1190 file = getfileinpath(logPath);
1191 getlogFile = accumulate(file.begin(), file.end(), getlogFile);
1192 path = logPath + getlogFile;
1193 bool result = false;
1194 string fileinfo = ReadFile(path);
1195 std::vector<std::string> para = {"test_event", "\"type_\":1", "\"key31\":\"value31\"","\"key15\":\"value15\"","\"key0\":\"value0\""};
1196 if (fileinfo != "") {
1197 result = CheckInfo(para, fileinfo);
1198 }
1199 OH_HiAppEvent_DestroyParamList(list);
1200 ASSERT_TRUE(result);
1201 OH_HiAppEvent_Configure("max_storage", "10M");
1202 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3600 end" << endl;
1203 }
1204
1205 /**
1206 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
1207 * is of the boolean type and the bool value is true.
1208 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3700
1209 * @author f00601390
1210 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1211 */
1212 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3700, Function|MediumTest|Level3){
1213 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3700 start" << endl;
1214 OH_HiAppEvent_Configure("disable", "true");
1215 bool boolean = true;
1216 OHOS::HiviewDFX::HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
1217 ParamList list = OH_HiAppEvent_CreateParamList();
1218 OH_HiAppEvent_AddBoolParam(list, "bool_key", boolean);
1219 EventType eventType = EventType::FAULT;
1220 int ret = OH_HiAppEvent_Write(TEST_DOMAIN_NAME, TEST_EVENT_NAME, eventType, list);
1221 sleep(1); //等待1s
1222 std::vector<std::string> file;
1223 file = getfileinpath(logPath);
1224 OH_HiAppEvent_DestroyParamList(list);
1225 ASSERT_TRUE(file.size() == 0);
1226 ASSERT_TRUE(ret == -99);
1227 OH_HiAppEvent_Configure("disable", "false");
1228 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3700 end" << endl;
1229 }
1230
1231 /**
1232 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
1233 * is of the boolean type and the bool value is true.
1234 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3800
1235 * @author z30053398
1236 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1237 */
1238 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3800, Function | MediumTest | Level3) {
1239 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3800 start" << endl;
1240 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(nullptr, "testName", "testValue"), ErrorCode::ERROR_EVENT_CONFIG_IS_NULL);
1241
1242 int maxStrLen = 1024;
1243 std::string longStr(maxStrLen, 'a');
1244 std::string longInvalidStr(maxStrLen + 1, 'a');
1245 HiAppEvent_Config* configDemo = OH_HiAppEvent_CreateConfig();
1246
1247 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "", "testValue"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1248 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, longStr.c_str(), "testValue"),
1249 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1250 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, nullptr, "testValue"), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1251 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, longInvalidStr.c_str(), "testValue"),
1252 ErrorCode::ERROR_INVALID_PARAM_VALUE);
1253
1254 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "testName", ""), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1255 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "testName", longStr.c_str()),
1256 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1257 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "testName", nullptr), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1258 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "testName", longInvalidStr.c_str()),
1259 ErrorCode::ERROR_INVALID_PARAM_VALUE);
1260
1261 OH_HiAppEvent_DestroyConfig(configDemo);
1262
1263 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3800 end" << endl;
1264 }
1265
1266 /**
1267 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
1268 * is of the boolean type and the bool value is true.
1269 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_3900
1270 * @author z30053398
1271 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1272 */
1273 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_3900, Function | MediumTest | Level3) {
1274 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3900 start" << endl;
1275 HiAppEvent_Config* configDemo = OH_HiAppEvent_CreateConfig();
1276 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "0"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1277
1278 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1279 ASSERT_EQ(OH_HiAppEvent_SetEventConfig(nullptr, configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1280 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("testName", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1281 int maxStrLen = 1024;
1282 std::string longInvalidStr(maxStrLen + 1, 'a');
1283 ASSERT_EQ(OH_HiAppEvent_SetEventConfig(longInvalidStr.c_str(), configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1284
1285 OH_HiAppEvent_DestroyConfig(configDemo);
1286 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_3900 end" << endl;
1287 }
1288
1289 /**
1290 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
1291 * is of the boolean type and the bool value is true.
1292 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_4000
1293 * @author z30053398
1294 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1295 */
1296 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_4000, Function | MediumTest | Level3) {
1297 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4000 start" << endl;
1298 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", nullptr), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1299
1300 HiAppEvent_Config* configDemo = OH_HiAppEvent_CreateConfig();
1301 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1302
1303 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "-1"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1304 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1305
1306 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "abc"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1307 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1308
1309 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", ""), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1310 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1311
1312 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", nullptr), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1313 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1314
1315 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "100"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1316 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1317
1318 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "0"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1319 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1320
1321 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "2"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1322 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1323
1324 OH_HiAppEvent_DestroyConfig(configDemo);
1325 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4000 end" << endl;
1326 }
1327
1328 /**
1329 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
1330 * is of the boolean type and the bool value is true.
1331 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_4100
1332 * @author z30053398
1333 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1334 */
1335 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_4100, Function | MediumTest | Level3) {
1336 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4100 start" << endl;
1337 HiAppEvent_Config* configDemo = OH_HiAppEvent_CreateConfig();
1338 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "1"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1339 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1340
1341 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "ignore_startup_time", "10"),
1342 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1343 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_interval", "100"),
1344 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1345 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "report_times_per_app", "3"),
1346 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1347 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_count", "21"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1348 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1349
1350 OH_HiAppEvent_DestroyConfig(configDemo);
1351 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4100 end" << endl;
1352 }
1353
1354 /**
1355 * @tc.name Test of the HiAppEvent Native Write Interface in which the keyvalue
1356 * is of the boolean type and the bool value is true.
1357 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_4200
1358 * @author z30053398
1359 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1360 */
1361 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_4200, Function | MediumTest | Level3) {
1362 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4200 start" << endl;
1363 HiAppEvent_Config* configDemo = OH_HiAppEvent_CreateConfig();
1364 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "log_type", "1"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1365
1366 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_count", "21"), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1367 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "ignore_startup_time", "10"),
1368 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1369 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "report_times_per_app", "3"),
1370 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1371 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_interval", "50"),
1372 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL); // sample_interval range is [50, 1000]
1373
1374 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1375
1376 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_interval", "-1"),
1377 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1378 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1379
1380 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_interval", "49"),
1381 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1382 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1383
1384 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_interval", "aa"),
1385 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1386 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1387
1388 std::string maxValue = "92233720368547758079223372036854775807";
1389 ASSERT_EQ(OH_HiAppEvent_SetConfigItem(configDemo, "sample_interval", maxValue.c_str()),
1390 ErrorCode::HIAPPEVENT_VERIFY_SUCCESSFUL);
1391 ASSERT_EQ(OH_HiAppEvent_SetEventConfig("MAIN_THREAD_JANK", configDemo), ErrorCode::ERROR_INVALID_PARAM_VALUE);
1392
1393 OH_HiAppEvent_DestroyConfig(configDemo);
1394 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4200 end" << endl;
1395 }
1396
1397 /**
1398 * @tc.name Test of the HiAppEvent Native SetReportRoute Interface in which the keyvalue
1399 * is of the boolean type and the bool value is true.
1400 * @tc.number DFX_DFT_HiviewKit_HiAppEvent_Native_4300
1401 * @author z30053398
1402 * @tc.desc The keyvalue is of the boolean type and the bool value is false.
1403 */
1404
1405 HWTEST_F(HiAppEventCPPTest, DFX_DFT_HiviewKit_HiAppEvent_Native_4300, Function | MediumTest | Level3) {
1406 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4300 start" << endl;
1407 const char * validname = "test_processor";
1408 HiAppEvent_Processor * processor0= OH_HiAppEvent_CreateProcessor (validname);
1409 ASSERT_EQ(OH_HiAppEvent_SetReportRoute(processor0, "com.example.app", "https://hiappevents.com/test"), -200);
1410 ASSERT_EQ(OH_HiAppEvent_SetReportPolicy(processor0, 10, 5, true, false), -200);
1411 ASSERT_EQ(OH_HiAppEvent_SetReportEvent(processor0, "OS", "ADDRESS_SANITIZER", true), -200);
1412 ASSERT_EQ(OH_HiAppEvent_SetCustomConfig(processor0, "test", "test"), -200);
1413 ASSERT_EQ(OH_HiAppEvent_SetConfigId(processor0, 123), -200);
1414 const char* userList[] = {"testprocessor", "processor2", "processor3"};
1415 ASSERT_EQ(OH_HiAppEvent_SetReportUserId(processor0, userList, 1), -200);
1416 ASSERT_EQ(OH_HiAppEvent_SetReportUserProperty(processor0, userList, 1), -200);
1417 ASSERT_EQ(OH_HiAppEvent_AddProcessor(processor0), -200);
1418 ASSERT_EQ(OH_HiAppEvent_RemoveProcessor(123), -200);
1419 GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiAppEvent_Native_4300 end" << endl;
1420 }