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