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