1 /*
2 * Copyright (c) 2022 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 <chrono>
16 #include <cinttypes>
17 #include <cstring>
18 #include <map>
19 #include <unistd.h>
20
21 #include <gtest/gtest.h>
22 #include "hilog/log.h"
23 #include "hisysevent_manager_c.h"
24 #include "hisysevent_record_c.h"
25 #include "ret_code.h"
26 #include "string_util.h"
27
28 using namespace testing::ext;
29 using namespace OHOS::HiviewDFX;
30
31 namespace {
32 constexpr HiLogLabel LABEL = { LOG_CORE, 0xD002D08, "HISYSEVENT_TEST" };
33 constexpr int64_t MAX_NUM_OF_QUERY = 10;
34 constexpr size_t MAX_LEN_OF_DOMAIN = 16;
35 constexpr size_t MAX_LEN_OF_NAME = 32;
36 constexpr char TEST_DOMAIN[] = "HIVIEWDFX";
37 constexpr char TEST_NAME[] = "PLUGIN_LOAD";
38 constexpr uint32_t QUERY_INTERVAL_TIME = 2;
39 constexpr int ERR_NULL = -1;
40
GetMilliseconds()41 int64_t GetMilliseconds()
42 {
43 auto now = std::chrono::system_clock::now();
44 auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch());
45 return millisecs.count();
46 }
47
InitQueryArg(HiSysEventQueryArg & arg)48 void InitQueryArg(HiSysEventQueryArg& arg)
49 {
50 arg.beginTime = 0;
51 arg.endTime = GetMilliseconds();
52 arg.maxEvents = MAX_NUM_OF_QUERY;
53 }
54
InitQueryRule(HiSysEventQueryRule & rule)55 void InitQueryRule(HiSysEventQueryRule& rule)
56 {
57 (void)StringUtil::CopyCString(rule.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
58 (void)StringUtil::CopyCString(rule.eventList[0], TEST_NAME, MAX_LEN_OF_NAME);
59 rule.eventListSize = 1;
60 rule.condition = nullptr;
61 }
62
InitQueryRuleWithCondition(HiSysEventQueryRule & rule,const std::string & cond)63 void InitQueryRuleWithCondition(HiSysEventQueryRule& rule, const std::string& cond)
64 {
65 (void)StringUtil::CopyCString(rule.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
66 (void)StringUtil::CopyCString(rule.eventList[0], TEST_NAME, MAX_LEN_OF_NAME);
67 rule.eventListSize = 1;
68 (void)StringUtil::CreateCString(&rule.condition, cond);
69 }
70
RecordBaseParamPrint(const HiSysEventRecord & record)71 void RecordBaseParamPrint(const HiSysEventRecord& record)
72 {
73 HiLog::Debug(LABEL, "event: domain=%{public}s, name=%{public}s, type=%{public}d, tz=%{public}s, "
74 "time=%{public}" PRIu64 ", pid=%{public}" PRId64 ", tid=%{public}" PRId64 ", uid=%{public}"
75 PRId64 ", traceId=%{public}" PRIu64 ", spandId=%{public}" PRIu64 ", pspanId=%{public}"
76 PRIu64 ", level=%{public}s" ", tag=%{public}s",
77 record.domain, record.eventName, record.type,
78 record.tz, record.time, record.pid, record.tid, record.uid,
79 record.traceId, record.spandId, record.pspanId,
80 record.level, record.tag == nullptr ? "null" : record.tag);
81 }
82
OnQueryTest(HiSysEventRecord records[],size_t size)83 void OnQueryTest(HiSysEventRecord records[], size_t size)
84 {
85 HiLog::Info(LABEL, "OnQuery: size of records is %{public}zu", size);
86 for (size_t i = 0; i < size; i++) {
87 HiSysEventRecord record = records[i];
88 ASSERT_EQ(strcmp(record.domain, TEST_DOMAIN), 0);
89 ASSERT_TRUE(strlen(record.eventName) > 0);
90 ASSERT_TRUE(strlen(record.tz) > 0);
91 ASSERT_TRUE(record.type > 0);
92 ASSERT_TRUE(record.time > 0);
93 ASSERT_TRUE(record.pid >= 0);
94 ASSERT_TRUE(record.tid >= 0);
95 ASSERT_TRUE(record.uid >= 0);
96 ASSERT_TRUE(record.traceId >= 0);
97 ASSERT_TRUE(record.spandId >= 0);
98 ASSERT_TRUE(record.pspanId >= 0);
99 ASSERT_TRUE(strlen(record.level) > 0);
100 if (record.tag != nullptr) {
101 ASSERT_TRUE(strlen(record.tag) > 0);
102 }
103 ASSERT_TRUE(strlen(record.jsonStr) > 0);
104 RecordBaseParamPrint(record);
105 HiLog::Info(LABEL, "OnQuery: event=%{public}s", record.jsonStr);
106 }
107 }
108
OnCompleteTest(int32_t reason,int32_t total)109 void OnCompleteTest(int32_t reason, int32_t total)
110 {
111 HiLog::Info(LABEL, "OnCompleted, res=%{public}d, total=%{public}d", reason, total);
112 }
113
InitCallck(HiSysEventQueryCallback & callback)114 void InitCallck(HiSysEventQueryCallback& callback)
115 {
116 callback.OnQuery = OnQueryTest;
117 callback.OnComplete = OnCompleteTest;
118 }
119
QueryTestWithCondition(const std::string & cond)120 void QueryTestWithCondition(const std::string& cond)
121 {
122 sleep(QUERY_INTERVAL_TIME); // avoid triggering high frequency queries
123 HiSysEventQueryArg arg;
124 InitQueryArg(arg);
125
126 HiSysEventQueryRule rule;
127 InitQueryRuleWithCondition(rule, cond);
128 HiSysEventQueryRule rules[] = { rule };
129
130 HiSysEventQueryCallback callback;
131 InitCallck(callback);
132
133 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
134 ASSERT_EQ(res, 0);
135 StringUtil::DeletePointer<char>(&rule.condition);
136 }
137
BuildRecordString(const std::map<std::string,std::string> & recordData)138 std::string BuildRecordString(const std::map<std::string, std::string>& recordData)
139 {
140 std::string recordStr = "{";
141 for (auto& recordParam : recordData) {
142 recordStr.append(recordParam.first).append(":").append(recordParam.second).append(",");
143 }
144 if (recordData.size() > 0) {
145 recordStr.pop_back();
146 }
147 recordStr.append("}");
148 return recordStr;
149 }
150
RecordParamNameTest(const HiSysEventRecord & record,const std::map<std::string,std::string> & recordData)151 void RecordParamNameTest(const HiSysEventRecord& record, const std::map<std::string, std::string>& recordData)
152 {
153 char** params = nullptr;
154 size_t len = 0;
155 OH_HiSysEvent_GetParamNames(record, ¶ms, len);
156 ASSERT_EQ(len, recordData.size());
157 for (size_t i = 0; i < len; i++) {
158 HiLog::Debug(LABEL, "param[%{public}zu]=%{public}s", i, params[i]);
159 ASSERT_TRUE(recordData.find("\"" + std::string(params[i]) + "\"") != recordData.end());
160 }
161 StringUtil::DeletePointers<char>(¶ms, len);
162 }
163
RecordParamIntValueTest(const HiSysEventRecord & record,const std::string & name,int64_t value)164 void RecordParamIntValueTest(const HiSysEventRecord& record, const std::string& name, int64_t value)
165 {
166 int64_t testValue = 0;
167 int res = OH_HiSysEvent_GetParamInt64Value(record, name.c_str(), testValue);
168 ASSERT_EQ(res, 0);
169 ASSERT_EQ(testValue, value);
170 }
171
RecordParamUintValueTest(const HiSysEventRecord & record,const std::string & name,uint64_t value)172 void RecordParamUintValueTest(const HiSysEventRecord& record, const std::string& name, uint64_t value)
173 {
174 uint64_t testValue = 0;
175 int res = OH_HiSysEvent_GetParamUint64Value(record, name.c_str(), testValue);
176 ASSERT_EQ(res, 0);
177 ASSERT_EQ(testValue, value);
178 }
179
RecordParamDouValueTest(const HiSysEventRecord & record,const std::string & name,double value)180 void RecordParamDouValueTest(const HiSysEventRecord& record, const std::string& name, double value)
181 {
182 double testValue = 0;
183 int res = OH_HiSysEvent_GetParamDoubleValue(record, name.c_str(), testValue);
184 ASSERT_EQ(res, 0);
185 ASSERT_EQ(testValue, value);
186 }
187
RecordParamStrValueTest(const HiSysEventRecord & record,const std::string & name,const std::string & value)188 void RecordParamStrValueTest(const HiSysEventRecord& record, const std::string& name, const std::string& value)
189 {
190 char* testValue = nullptr;
191 int res = OH_HiSysEvent_GetParamStringValue(record, name.c_str(), &testValue);
192 ASSERT_EQ(res, 0);
193 ASSERT_EQ(strcmp(testValue, value.c_str()), 0);
194 StringUtil::DeletePointer<char>(&testValue);
195 }
196
RecordParamIntValuesTest(const HiSysEventRecord & record,const std::string & name,const std::vector<int64_t> & values)197 void RecordParamIntValuesTest(const HiSysEventRecord& record, const std::string& name,
198 const std::vector<int64_t>& values)
199 {
200 int64_t* testValues = nullptr;
201 size_t len = 0;
202 int res = OH_HiSysEvent_GetParamInt64Values(record, name.c_str(), &testValues, len);
203 ASSERT_EQ(res, 0);
204 ASSERT_EQ(values.size(), len);
205 for (size_t i = 0; i < len; i++) {
206 ASSERT_EQ(testValues[i], values[i]);
207 }
208 StringUtil::DeletePointer<int64_t>(&testValues);
209 }
210
RecordParamUintValuesTest(const HiSysEventRecord & record,const std::string & name,const std::vector<uint64_t> & values)211 void RecordParamUintValuesTest(const HiSysEventRecord& record, const std::string& name,
212 const std::vector<uint64_t>& values)
213 {
214 uint64_t* testValues = nullptr;
215 size_t len = 0;
216 int res = OH_HiSysEvent_GetParamUint64Values(record, name.c_str(), &testValues, len);
217 ASSERT_EQ(res, 0);
218 ASSERT_EQ(values.size(), len);
219 for (size_t i = 0; i < len; i++) {
220 ASSERT_EQ(testValues[i], values[i]);
221 }
222 StringUtil::DeletePointer<uint64_t>(&testValues);
223 }
224
RecordParamDouValuesTest(const HiSysEventRecord & record,const std::string & name,const std::vector<double> & values)225 void RecordParamDouValuesTest(const HiSysEventRecord& record, const std::string& name,
226 const std::vector<double>& values)
227 {
228 double* testValues = nullptr;
229 size_t len = 0;
230 int res = OH_HiSysEvent_GetParamDoubleValues(record, name.c_str(), &testValues, len);
231 ASSERT_EQ(res, 0);
232 ASSERT_EQ(values.size(), len);
233 for (size_t i = 0; i < len; i++) {
234 ASSERT_EQ(testValues[i], values[i]);
235 }
236 StringUtil::DeletePointer<double>(&testValues);
237 }
238
RecordParamStrValuesTest(const HiSysEventRecord & record,const std::string & name,const std::vector<std::string> & values)239 void RecordParamStrValuesTest(const HiSysEventRecord& record, const std::string& name,
240 const std::vector<std::string>& values)
241 {
242 char** testValues = nullptr;
243 size_t len = 0;
244 int res = OH_HiSysEvent_GetParamStringValues(record, name.c_str(), &testValues, len);
245 ASSERT_EQ(res, 0);
246 for (size_t i = 0; i < len; i++) {
247 ASSERT_EQ(strcmp(testValues[i], values[i].c_str()), 0);
248 }
249 StringUtil::DeletePointers<char>(&testValues, len);
250 }
251
RecordParamNameInvalidTest(const HiSysEventRecord & record)252 void RecordParamNameInvalidTest(const HiSysEventRecord& record)
253 {
254 char** params = nullptr;
255 size_t len = 0;
256 OH_HiSysEvent_GetParamNames(record, ¶ms, len);
257 ASSERT_EQ(len, 0);
258 }
259
RecordParamIntValueInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)260 void RecordParamIntValueInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
261 {
262 int64_t testValue = 0;
263 int res = OH_HiSysEvent_GetParamInt64Value(record, name.c_str(), testValue);
264 ASSERT_EQ(res, expRes);
265 }
266
RecordParamUintValueInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)267 void RecordParamUintValueInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
268 {
269 uint64_t testValue = 0;
270 int res = OH_HiSysEvent_GetParamUint64Value(record, name.c_str(), testValue);
271 ASSERT_EQ(res, expRes);
272 }
273
RecordParamDouValueInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)274 void RecordParamDouValueInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
275 {
276 double testValue = 0;
277 int res = OH_HiSysEvent_GetParamDoubleValue(record, name.c_str(), testValue);
278 ASSERT_EQ(res, expRes);
279 }
280
RecordParamStrValueInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)281 void RecordParamStrValueInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
282 {
283 char* testValue = nullptr;
284 int res = OH_HiSysEvent_GetParamStringValue(record, name.c_str(), &testValue);
285 ASSERT_EQ(res, expRes);
286 }
287
RecordParamIntValuesInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)288 void RecordParamIntValuesInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
289 {
290 int64_t* testValues = nullptr;
291 size_t len = 0;
292 int res = OH_HiSysEvent_GetParamInt64Values(record, name.c_str(), &testValues, len);
293 ASSERT_EQ(res, expRes);
294 }
295
RecordParamUintValuesInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)296 void RecordParamUintValuesInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
297 {
298 uint64_t* testValues = nullptr;
299 size_t len = 0;
300 int res = OH_HiSysEvent_GetParamUint64Values(record, name.c_str(), &testValues, len);
301 ASSERT_EQ(res, expRes);
302 }
303
RecordParamDouValuesInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)304 void RecordParamDouValuesInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
305 {
306 double* testValues = nullptr;
307 size_t len = 0;
308 int res = OH_HiSysEvent_GetParamDoubleValues(record, name.c_str(), &testValues, len);
309 ASSERT_EQ(res, expRes);
310 }
311
RecordParamStrValuesInvalidTest(const HiSysEventRecord & record,const std::string & name,int expRes)312 void RecordParamStrValuesInvalidTest(const HiSysEventRecord& record, const std::string& name, int expRes)
313 {
314 char** testValues = nullptr;
315 size_t len = 0;
316 int res = OH_HiSysEvent_GetParamStringValues(record, name.c_str(), &testValues, len);
317 ASSERT_EQ(res, expRes);
318 }
319 }
320
321 class HiSysEventManagerCTest : public testing::Test {
322 public:
323 void SetUp();
324 void TearDown();
325 };
326
SetUp()327 void HiSysEventManagerCTest::SetUp()
328 {}
329
TearDown()330 void HiSysEventManagerCTest::TearDown()
331 {}
332
333 /**
334 * @tc.name: HiSysEventMgrCQueryTest001
335 * @tc.desc: Testing to query events.
336 * @tc.type: FUNC
337 * @tc.require: issueI5X08B
338 */
339 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest001, TestSize.Level3)
340 {
341 /**
342 * @tc.steps: step1. create HiSysEventQueryArg.
343 * @tc.steps: step2. create HiSysEventQueryRule.
344 * @tc.steps: step3. create HiSysEventQueryCallback.
345 * @tc.steps: step4. query event.
346 */
347 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest001 start");
348 HiSysEventQueryArg arg;
349 InitQueryArg(arg);
350
351 HiSysEventQueryRule rule;
352 InitQueryRule(rule);
353 HiSysEventQueryRule rules[] = { rule };
354
355 HiSysEventQueryCallback callback;
356 InitCallck(callback);
357
358 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
359 ASSERT_EQ(res, 0);
360 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest001 end");
361 }
362
363 /**
364 * @tc.name: HiSysEventMgrCQueryTest002
365 * @tc.desc: Testing to query events with condition.
366 * @tc.type: FUNC
367 * @tc.require: issueI5X08B
368 */
369 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest002, TestSize.Level3)
370 {
371 /**
372 * @tc.steps: step1. create HiSysEventQueryArg.
373 * @tc.steps: step2. create HiSysEventQueryRule.
374 * @tc.steps: step3. create HiSysEventQueryCallback.
375 * @tc.steps: step4. query event.
376 */
377 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest002 start");
378 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"NAME","op":"=",
379 "value":"SysEventService"}]}})~";
380 QueryTestWithCondition(cond);
381 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest002 end");
382 }
383
384 /**
385 * @tc.name: HiSysEventMgrCQueryTest003
386 * @tc.desc: Testing to query events with condition.
387 * @tc.type: FUNC
388 * @tc.require: issueI5X08B
389 */
390 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest003, TestSize.Level3)
391 {
392 /**
393 * @tc.steps: step1. create HiSysEventQueryArg.
394 * @tc.steps: step2. create HiSysEventQueryRule.
395 * @tc.steps: step3. create HiSysEventQueryCallback.
396 * @tc.steps: step4. query event.
397 */
398 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest003 start");
399 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"uid_","op":"=","value":1201}]}})~";
400 QueryTestWithCondition(cond);
401 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest003 end");
402 }
403
404 /**
405 * @tc.name: HiSysEventMgrCQueryTest004
406 * @tc.desc: Testing to query events with condition.
407 * @tc.type: FUNC
408 * @tc.require: issueI5X08B
409 */
410 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest004, TestSize.Level3)
411 {
412 /**
413 * @tc.steps: step1. create HiSysEventQueryArg.
414 * @tc.steps: step2. create HiSysEventQueryRule.
415 * @tc.steps: step3. create HiSysEventQueryCallback.
416 * @tc.steps: step4. query event.
417 */
418 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest004 start");
419 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"pid_","op":">=","value":0}]}})~";
420 QueryTestWithCondition(cond);
421 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest004 end");
422 }
423
424 /**
425 * @tc.name: HiSysEventMgrCQueryTest005
426 * @tc.desc: Testing to query events with condition.
427 * @tc.type: FUNC
428 * @tc.require: issueI5X08B
429 */
430 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest005, TestSize.Level3)
431 {
432 /**
433 * @tc.steps: step1. create HiSysEventQueryArg.
434 * @tc.steps: step2. create HiSysEventQueryRule.
435 * @tc.steps: step3. create HiSysEventQueryCallback.
436 * @tc.steps: step4. query event.
437 */
438 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest005 start");
439 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"type_","op":"<=","value":4}]}})~";
440 QueryTestWithCondition(cond);
441 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest005 end");
442 }
443
444 /**
445 * @tc.name: HiSysEventMgrCQueryTest006
446 * @tc.desc: Testing to query events with condition.
447 * @tc.type: FUNC
448 * @tc.require: issueI5X08B
449 */
450 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest006, TestSize.Level3)
451 {
452 /**
453 * @tc.steps: step1. create HiSysEventQueryArg.
454 * @tc.steps: step2. create HiSysEventQueryRule.
455 * @tc.steps: step3. create HiSysEventQueryCallback.
456 * @tc.steps: step4. query event.
457 */
458 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest006 start");
459 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"pid_","op":">","value":0}]}})~";
460 QueryTestWithCondition(cond);
461 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest006 end");
462 }
463
464 /**
465 * @tc.name: HiSysEventMgrCQueryTest007
466 * @tc.desc: Testing to query events with condition.
467 * @tc.type: FUNC
468 * @tc.require: issueI5X08B
469 */
470 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest007, TestSize.Level3)
471 {
472 /**
473 * @tc.steps: step1. create HiSysEventQueryArg.
474 * @tc.steps: step2. create HiSysEventQueryRule.
475 * @tc.steps: step3. create HiSysEventQueryCallback.
476 * @tc.steps: step4. query event.
477 */
478 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest007 start");
479 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"pid_","op":"<","value":0}]}})~";
480 QueryTestWithCondition(cond);
481 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest007 end");
482 }
483
484 /**
485 * @tc.name: HiSysEventMgrCQueryTest008
486 * @tc.desc: Testing to query events with many rules.
487 * @tc.type: FUNC
488 * @tc.require: issueI5X08B
489 */
490 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest008, TestSize.Level3)
491 {
492 /**
493 * @tc.steps: step1. create HiSysEventQueryArg.
494 * @tc.steps: step2. create HiSysEventQueryRule.
495 * @tc.steps: step3. create HiSysEventQueryCallback.
496 * @tc.steps: step4. query event.
497 */
498 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest008 start");
499 sleep(QUERY_INTERVAL_TIME);
500 HiSysEventQueryArg arg;
501 InitQueryArg(arg);
502
503 HiSysEventQueryRule rule1;
504 (void)StringUtil::CopyCString(rule1.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
505 (void)StringUtil::CopyCString(rule1.eventList[0], TEST_NAME, MAX_LEN_OF_NAME);
506 (void)StringUtil::CopyCString(rule1.eventList[1], "PLUGIN_UNLOAD", MAX_LEN_OF_NAME);
507 rule1.eventListSize = 2;
508 HiSysEventQueryRule rule2;
509 (void)StringUtil::CopyCString(rule2.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
510 (void)StringUtil::CopyCString(rule2.eventList[0], "APP_USAGE", MAX_LEN_OF_NAME);
511 (void)StringUtil::CopyCString(rule2.eventList[1], "SYS_USAGE", MAX_LEN_OF_NAME);
512 rule2.eventListSize = 2;
513 HiSysEventQueryRule rules[] = { rule1, rule2 };
514
515 HiSysEventQueryCallback callback;
516 InitCallck(callback);
517
518 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
519 ASSERT_EQ(res, 0);
520 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest008 end");
521 }
522
523 /**
524 * @tc.name: HiSysEventMgrCQueryTest009
525 * @tc.desc: Testing to query events with many conditions.
526 * @tc.type: FUNC
527 * @tc.require: issueI5X08B
528 */
529 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest009, TestSize.Level3)
530 {
531 /**
532 * @tc.steps: step1. create HiSysEventQueryArg.
533 * @tc.steps: step2. create HiSysEventQueryRule.
534 * @tc.steps: step3. create HiSysEventQueryCallback.
535 * @tc.steps: step4. query event.
536 */
537 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest009 start");
538 std::string cond1 = R"~({"version":"V1","condition":{"or":[{"param":"NAME","op":"=",
539 "value":"SysEventService"},{"param":"NAME","op":"=","value":"SysEventSource"}]}})~";
540 QueryTestWithCondition(cond1);
541
542 std::string cond2 = R"~({"version":"V1","condition":{"and":[{"param":"NAME","op":"=",
543 "value":"SysEventService"},{"param":"uid_","op":"=","value":1201}]}})~";
544 QueryTestWithCondition(cond2);
545
546 std::string cond3 = R"~({"version":"V1","condition":{"and":[{"param":"type_","op":">","value":0},
547 {"param":"uid_","op":"=","value":1201}],"or":[{"param":"NAME","op":"=","value":"SysEventService"},
548 {"param":"NAME","op":"=","value":"SysEventSource"}]}})~";
549 QueryTestWithCondition(cond3);
550 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest009 end");
551 }
552
553 /**
554 * @tc.name: HiSysEventMgrCQueryTest010
555 * @tc.desc: Testing to query events with many rules and condtions.
556 * @tc.type: FUNC
557 * @tc.require: issueI5X08B
558 */
559 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest010, TestSize.Level3)
560 {
561 /**
562 * @tc.steps: step1. create HiSysEventQueryArg.
563 * @tc.steps: step2. create HiSysEventQueryRule.
564 * @tc.steps: step3. create HiSysEventQueryCallback.
565 * @tc.steps: step4. query event.
566 */
567 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest010 start");
568 sleep(QUERY_INTERVAL_TIME);
569 HiSysEventQueryArg arg;
570 InitQueryArg(arg);
571
572 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"time_","op":">",
573 "value":0},{"param":"type_","op":">","value":0}]}})~";
574 HiSysEventQueryRule rule1;
575 (void)StringUtil::CopyCString(rule1.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
576 (void)StringUtil::CopyCString(rule1.eventList[0], TEST_NAME, MAX_LEN_OF_NAME);
577 (void)StringUtil::CopyCString(rule1.eventList[1], "PLUGIN_UNLOAD", MAX_LEN_OF_NAME);
578 rule1.eventListSize = 2;
579 (void)StringUtil::CreateCString(&rule1.condition, cond);
580 HiSysEventQueryRule rule2;
581 (void)StringUtil::CopyCString(rule2.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
582 (void)StringUtil::CopyCString(rule2.eventList[0], "APP_USAGE", MAX_LEN_OF_NAME);
583 (void)StringUtil::CopyCString(rule2.eventList[1], "SYS_USAGE", MAX_LEN_OF_NAME);
584 rule2.eventListSize = 2;
585 (void)StringUtil::CreateCString(&rule2.condition, cond);
586 HiSysEventQueryRule rules[] = { rule1, rule2 };
587
588 HiSysEventQueryCallback callback;
589 InitCallck(callback);
590
591 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
592 ASSERT_EQ(res, 0);
593 StringUtil::DeletePointer<char>(&rule1.condition);
594 StringUtil::DeletePointer<char>(&rule2.condition);
595 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest010 end");
596 }
597
598 /**
599 * @tc.name: HiSysEventMgrCQueryTest011
600 * @tc.desc: Testing to query events with invalid condition.
601 * @tc.type: FUNC
602 * @tc.require: issueI5X08B
603 */
604 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest011, TestSize.Level3)
605 {
606 /**
607 * @tc.steps: step1. create HiSysEventQueryArg.
608 * @tc.steps: step2. create HiSysEventQueryRule.
609 * @tc.steps: step3. create HiSysEventQueryCallback.
610 * @tc.steps: step4. query event.
611 */
612 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest011 start");
613
614 std::string cond1 = R"~({"version":"xx","condition":{}})~";
615 QueryTestWithCondition(cond1);
616
617 std::string cond2 = "invalid condition";
618 QueryTestWithCondition(cond2);
619
620 std::string cond3 = R"~({"version":"V1","condition":{"invalid":[]}})~";
621 QueryTestWithCondition(cond3);
622
623 std::string cond4 = R"~({"version":"V1","condition":{"and":[{"invalid":"PLUGIN_NAME","op":"=",
624 "value":"SysEventService"}]}})~";
625 QueryTestWithCondition(cond4);
626
627 std::string cond5 = R"~({"version":"V1","condition":{"and":[{"param":"PLUGIN_NAME","invalid":"=",
628 "value":"SysEventService"}]}})~";
629 QueryTestWithCondition(cond5);
630
631 std::string cond6 = R"~({"version":"V1","condition":{"and":[{"param":"PLUGIN_NAME","op":"**",
632 "value":"SysEventService"}]}})~";
633 QueryTestWithCondition(cond6);
634
635 std::string cond7 = R"~({"version":"V1","condition":{"and":[{"param":"PLUGIN_NAME","op":"=",
636 "invalid":"SysEventService"}]}})~";
637 QueryTestWithCondition(cond7);
638
639 std::string cond8 = R"~({"version":"V1","condition":{"and":[{"param":"PLUGIN_NAME","op":"=",
640 "value":[]}]}})~";
641 QueryTestWithCondition(cond8);
642
643 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest011 end");
644 }
645
646 /**
647 * @tc.name: HiSysEventMgrCQueryTest012
648 * @tc.desc: Testing to query events only with domain.
649 * @tc.type: FUNC
650 * @tc.require: issueI5X08B
651 */
652 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest012, TestSize.Level3)
653 {
654 /**
655 * @tc.steps: step1. create HiSysEventQueryArg.
656 * @tc.steps: step2. create HiSysEventQueryRule.
657 * @tc.steps: step3. create HiSysEventQueryCallback.
658 * @tc.steps: step4. query event.
659 */
660 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest012 start");
661 sleep(QUERY_INTERVAL_TIME);
662 HiSysEventQueryArg arg;
663 InitQueryArg(arg);
664 HiSysEventQueryRule rule;
665 (void)StringUtil::CopyCString(rule.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
666 rule.eventListSize = 0;
667 HiSysEventQueryRule rules[] = { rule };
668 HiSysEventQueryCallback callback;
669 InitCallck(callback);
670 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
671 ASSERT_EQ(res, ERR_QUERY_RULE_INVALID);
672 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest012 end");
673 }
674
675 /**
676 * @tc.name: HiSysEventMgrCQueryTest013
677 * @tc.desc: Testing to query events only with name.
678 * @tc.type: FUNC
679 * @tc.require: issueI5X08B
680 */
681 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest013, TestSize.Level3)
682 {
683 /**
684 * @tc.steps: step1. create HiSysEventQueryArg.
685 * @tc.steps: step2. create HiSysEventQueryRule.
686 * @tc.steps: step3. create HiSysEventQueryCallback.
687 * @tc.steps: step4. query event.
688 */
689 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest013 start");
690 sleep(QUERY_INTERVAL_TIME);
691 HiSysEventQueryArg arg;
692 InitQueryArg(arg);
693 HiSysEventQueryRule rule;
694 (void)StringUtil::CopyCString(rule.eventList[0], TEST_NAME, MAX_LEN_OF_NAME);
695 rule.eventListSize = 1;
696 HiSysEventQueryRule rules[] = { rule };
697 HiSysEventQueryCallback callback;
698 InitCallck(callback);
699 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
700 ASSERT_EQ(res, ERR_QUERY_RULE_INVALID);
701 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest013 end");
702 }
703
704 /**
705 * @tc.name: HiSysEventMgrCQueryTest014
706 * @tc.desc: Testing to query events only with domain and condition.
707 * @tc.type: FUNC
708 * @tc.require: issueI5X08B
709 */
710 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest014, TestSize.Level3)
711 {
712 /**
713 * @tc.steps: step1. create HiSysEventQueryArg.
714 * @tc.steps: step2. create HiSysEventQueryRule.
715 * @tc.steps: step3. create HiSysEventQueryCallback.
716 * @tc.steps: step4. query event.
717 */
718 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest014 start");
719 sleep(QUERY_INTERVAL_TIME);
720 HiSysEventQueryArg arg;
721 InitQueryArg(arg);
722 HiSysEventQueryRule rule;
723 (void)StringUtil::CopyCString(rule.domain, TEST_DOMAIN, MAX_LEN_OF_DOMAIN);
724 rule.eventListSize = 0;
725 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"NAME","op":"=",
726 "value":"SysEventService"}]}})~";
727 (void)StringUtil::CreateCString(&rule.condition, cond);
728 HiSysEventQueryRule rules[] = { rule };
729 HiSysEventQueryCallback callback;
730 InitCallck(callback);
731 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
732 ASSERT_EQ(res, ERR_QUERY_RULE_INVALID);
733 StringUtil::DeletePointer<char>(&rule.condition);
734 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest014 end");
735 }
736
737 /**
738 * @tc.name: HiSysEventMgrCQueryTest015
739 * @tc.desc: Testing to query events only with name and condition.
740 * @tc.type: FUNC
741 * @tc.require: issueI5X08B
742 */
743 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest015, TestSize.Level3)
744 {
745 /**
746 * @tc.steps: step1. create HiSysEventQueryArg.
747 * @tc.steps: step2. create HiSysEventQueryRule.
748 * @tc.steps: step3. create HiSysEventQueryCallback.
749 * @tc.steps: step4. query event.
750 */
751 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest015 start");
752 sleep(QUERY_INTERVAL_TIME);
753 HiSysEventQueryArg arg;
754 InitQueryArg(arg);
755 HiSysEventQueryRule rule;
756 (void)StringUtil::CopyCString(rule.eventList[0], TEST_NAME, MAX_LEN_OF_NAME);
757 rule.eventListSize = 1;
758 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"NAME","op":"=",
759 "value":"SysEventService"}]}})~";
760 (void)StringUtil::CreateCString(&rule.condition, cond);
761 HiSysEventQueryRule rules[] = { rule };
762 HiSysEventQueryCallback callback;
763 InitCallck(callback);
764 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
765 ASSERT_EQ(res, ERR_QUERY_RULE_INVALID);
766 StringUtil::DeletePointer<char>(&rule.condition);
767 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest015 end");
768 }
769
770 /**
771 * @tc.name: HiSysEventMgrCQueryTest016
772 * @tc.desc: Testing to query events only with condition.
773 * @tc.type: FUNC
774 * @tc.require: issueI5X08B
775 */
776 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest016, TestSize.Level3)
777 {
778 /**
779 * @tc.steps: step1. create HiSysEventQueryArg.
780 * @tc.steps: step2. create HiSysEventQueryRule.
781 * @tc.steps: step3. create HiSysEventQueryCallback.
782 * @tc.steps: step4. query event.
783 */
784 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest016 start");
785 sleep(QUERY_INTERVAL_TIME);
786 HiSysEventQueryArg arg;
787 InitQueryArg(arg);
788 HiSysEventQueryRule rule;
789 rule.eventListSize = 0;
790 std::string cond = R"~({"version":"V1","condition":{"and":[{"param":"NAME","op":"=",
791 "value":"SysEventService"}]}})~";
792 (void)StringUtil::CreateCString(&rule.condition, cond);
793 HiSysEventQueryRule rules[] = { rule };
794 HiSysEventQueryCallback callback;
795 InitCallck(callback);
796 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
797 ASSERT_EQ(res, ERR_QUERY_RULE_INVALID);
798 StringUtil::DeletePointer<char>(&rule.condition);
799 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest016 end");
800 }
801
802 /**
803 * @tc.name: HiSysEventMgrCQueryTest017
804 * @tc.desc: Testing to query events are too frequent.
805 * @tc.type: FUNC
806 * @tc.require: issueI5X08B
807 */
808 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest017, TestSize.Level3)
809 {
810 /**
811 * @tc.steps: step1. create HiSysEventQueryArg.
812 * @tc.steps: step2. create HiSysEventQueryRule.
813 * @tc.steps: step3. create HiSysEventQueryCallback.
814 * @tc.steps: step4. query event.
815 */
816 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest017 start");
817 sleep(QUERY_INTERVAL_TIME);
818 HiSysEventQueryArg arg;
819 InitQueryArg(arg);
820
821 HiSysEventQueryRule rule;
822 InitQueryRule(rule);
823 HiSysEventQueryRule rules[] = { rule };
824
825 HiSysEventQueryCallback callback;
826 InitCallck(callback);
827
828 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
829 ASSERT_EQ(res, 0);
830 res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
831 ASSERT_EQ(res, ERR_QUERY_TOO_FREQUENTLY);
832
833 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest017 end");
834 }
835
836 /**
837 * @tc.name: HiSysEventMgrCQueryTest018
838 * @tc.desc: Testing to query events with too many rules.
839 * @tc.type: FUNC
840 * @tc.require: issueI5X08B
841 */
842 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCQueryTest018, TestSize.Level3)
843 {
844 /**
845 * @tc.steps: step1. create HiSysEventQueryArg.
846 * @tc.steps: step2. create HiSysEventQueryRule.
847 * @tc.steps: step3. create HiSysEventQueryCallback.
848 * @tc.steps: step4. query event.
849 */
850 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest018 start");
851 sleep(QUERY_INTERVAL_TIME);
852 HiSysEventQueryArg arg;
853 InitQueryArg(arg);
854
855 HiSysEventQueryRule rule;
856 InitQueryRule(rule);
857 HiSysEventQueryRule rules[] = { rule, rule, rule, rule, rule, rule, rule, rule, rule, rule, rule };
858
859 HiSysEventQueryCallback callback;
860 InitCallck(callback);
861
862 auto res = OH_HiSysEvent_Query(arg, rules, sizeof(rules) / sizeof(HiSysEventQueryRule), callback);
863 ASSERT_EQ(res, ERR_TOO_MANY_QUERY_RULES);
864
865 HiLog::Info(LABEL, "HiSysEventMgrCQueryTest018 end");
866 }
867
868 /**
869 * @tc.name: HiSysEventMgrCRecordTest001
870 * @tc.desc: Testing to get the record information.
871 * @tc.type: FUNC
872 * @tc.require: issueI5X08B
873 */
874 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCRecordTest001, TestSize.Level3)
875 {
876 /**
877 * @tc.steps: step1. build record.
878 * @tc.steps: step2. check the information from record.
879 */
880 HiLog::Info(LABEL, "HiSysEventMgrCRecordTest001 start");
881 const std::map<std::string, std::string> recordData = {
882 {"\"domain_\"", "\"TEST_DOMAIN\""},
883 {"\"name_\"", "\"TEST_NAME\""},
884 {"\"type_\"", "4"},
885 {"\"PARAM_INT\"", "-123"},
886 {"\"PARAM_INTS\"", "[-1,-2,3]"},
887 {"\"PARAM_UINT\"", "123"},
888 {"\"PARAM_UINTS\"", "[1,2,3]"},
889 {"\"PARAM_DOU\"", "123.456"},
890 {"\"PARAM_DOUS\"", "[1.1,-2.2,3.3]"},
891 {"\"PARAM_STR\"", "\"test\""},
892 {"\"PARAM_STRS\"", "[\"test1\",\"test2\",\"test3\"]"}
893 };
894 HiSysEventRecord record;
895 auto res = StringUtil::CreateCString(&record.jsonStr, BuildRecordString(recordData));
896 if (res != 0) {
897 HiLog::Warn(LABEL, "failed to create record string");
898 return;
899 }
900
901 RecordParamNameTest(record, recordData);
902 RecordParamIntValueTest(record, "PARAM_INT", -123);
903 RecordParamUintValueTest(record, "PARAM_UINT", 123);
904 RecordParamDouValueTest(record, "PARAM_DOU", 123.456);
905 RecordParamStrValueTest(record, "PARAM_STR", "test");
906 RecordParamIntValuesTest(record, "PARAM_INTS", {-1, -2, 3});
907 RecordParamUintValuesTest(record, "PARAM_UINTS", {1, 2, 3});
908 RecordParamDouValuesTest(record, "PARAM_DOUS", {1.1, -2.2, 3.3});
909 RecordParamStrValuesTest(record, "PARAM_STRS", {"test1", "test2", "test3"});
910
911 int expRes = -3;
912 RecordParamIntValueInvalidTest(record, "PARAM_STR", expRes);
913 RecordParamUintValueInvalidTest(record, "PARAM_STR", expRes);
914 RecordParamDouValueInvalidTest(record, "PARAM_STR", expRes);
915 RecordParamIntValuesInvalidTest(record, "PARAM_STRS", expRes);
916 RecordParamUintValuesInvalidTest(record, "PARAM_STRS", expRes);
917 RecordParamDouValuesInvalidTest(record, "PARAM_STRS", expRes);
918
919 // number is automatically converted to string
920 RecordParamStrValueTest(record, "PARAM_INT", "-123");
921 RecordParamStrValuesTest(record, "PARAM_INTS", {"-1", "-2", "3"});
922
923 StringUtil::DeletePointer<char>(&record.jsonStr);
924 HiLog::Info(LABEL, "HiSysEventMgrCRecordTest001 end");
925 }
926
927 /**
928 * @tc.name: HiSysEventMgrCRecordTest002
929 * @tc.desc: Testing to get the record information.
930 * @tc.type: FUNC
931 * @tc.require: issueI5X08B
932 */
933 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCRecordTest002, TestSize.Level3)
934 {
935 /**
936 * @tc.steps: step1. build record.
937 * @tc.steps: step2. check the information from record.
938 */
939 HiLog::Info(LABEL, "HiSysEventMgrCRecordTest002 start");
940 HiSysEventRecord record;
941 auto res = StringUtil::CreateCString(&record.jsonStr, "invalid record");
942 if (res != 0) {
943 HiLog::Warn(LABEL, "failed to create record string");
944 return;
945 }
946
947 int expRes = -1;
948 RecordParamNameInvalidTest(record);
949 RecordParamIntValueInvalidTest(record, "PARAM_INT", expRes);
950 RecordParamUintValueInvalidTest(record, "PARAM_UINT", expRes);
951 RecordParamDouValueInvalidTest(record, "PARAM_DOU", expRes);
952 RecordParamStrValueInvalidTest(record, "PARAM_STR", expRes);
953 RecordParamIntValuesInvalidTest(record, "PARAM_INTS", expRes);
954 RecordParamUintValuesInvalidTest(record, "PARAM_UINTS", expRes);
955 RecordParamDouValuesInvalidTest(record, "PARAM_DOUS", expRes);
956 RecordParamStrValuesInvalidTest(record, "PARAM_STRS", expRes);
957
958 StringUtil::DeletePointer<char>(&record.jsonStr);
959 HiLog::Info(LABEL, "HiSysEventMgrCRecordTest002 end");
960 }
961
962 /**
963 * @tc.name: HiSysEventMgrCRecordTest003
964 * @tc.desc: Testing to get the record information.
965 * @tc.type: FUNC
966 * @tc.require: issueI5X08B
967 */
968 HWTEST_F(HiSysEventManagerCTest, HiSysEventMgrCRecordTest003, TestSize.Level3)
969 {
970 /**
971 * @tc.steps: step1. build record.
972 * @tc.steps: step2. check the information from record.
973 */
974 HiLog::Info(LABEL, "HiSysEventMgrCRecordTest003 start");
975 HiSysEventRecord record;
976 auto res = StringUtil::CreateCString(&record.jsonStr, R"~({})~");
977 if (res != 0) {
978 HiLog::Warn(LABEL, "failed to create record string");
979 return;
980 }
981
982 int expRes = -2;
983 RecordParamNameTest(record, {});
984 RecordParamIntValueInvalidTest(record, "PARAM_INT", expRes);
985 RecordParamUintValueInvalidTest(record, "PARAM_UINT", expRes);
986 RecordParamDouValueInvalidTest(record, "PARAM_DOU", expRes);
987 RecordParamStrValueInvalidTest(record, "PARAM_STR", expRes);
988 RecordParamIntValuesInvalidTest(record, "PARAM_INTS", expRes);
989 RecordParamUintValuesInvalidTest(record, "PARAM_UINTS", expRes);
990 RecordParamDouValuesInvalidTest(record, "PARAM_DOUS", expRes);
991 RecordParamStrValuesInvalidTest(record, "PARAM_STRS", expRes);
992
993 StringUtil::DeletePointer<char>(&record.jsonStr);
994 HiLog::Info(LABEL, "HiSysEventMgrCRecordTest003 end");
995 }
996
997 /**
998 * @tc.name: HiSysEventRecordCTest001
999 * @tc.desc: Test apis of HisysventRecordC
1000 * @tc.type: FUNC
1001 * @tc.require: issueI62WJT
1002 */
1003 HWTEST_F(HiSysEventManagerCTest, HiSysEventRecordCTest001, TestSize.Level3)
1004 {
1005 struct HiSysEventRecord record;
1006 char*** testp = nullptr;
1007 size_t len = 0;
1008 OH_HiSysEvent_GetParamNames(record, testp, len);
1009 ASSERT_TRUE(true);
1010 int64_t value1;
1011 auto ret = OH_HiSysEvent_GetParamInt64Value(record, "KEY", value1);
1012 ASSERT_TRUE(ret == ERR_NULL);
1013 ret = OH_HiSysEvent_GetParamInt64Value(record, nullptr, value1);
1014 ASSERT_TRUE(ret == ERR_NULL);
1015 uint64_t value2;
1016 ret = OH_HiSysEvent_GetParamUint64Value(record, "KEY", value2);
1017 ASSERT_TRUE(ret == ERR_NULL);
1018 ret = OH_HiSysEvent_GetParamUint64Value(record, nullptr, value2);
1019 ASSERT_TRUE(ret == ERR_NULL);
1020 double value3;
1021 ret = OH_HiSysEvent_GetParamDoubleValue(record, "KEY", value3);
1022 ASSERT_TRUE(ret == ERR_NULL);
1023 ret = OH_HiSysEvent_GetParamDoubleValue(record, nullptr, value3);
1024 ASSERT_TRUE(ret == ERR_NULL);
1025 char value4[100];
1026 char* value4p = value4;
1027 char** value4pp = &value4p;
1028 ret = OH_HiSysEvent_GetParamStringValue(record, "KEY", value4pp);
1029 ASSERT_TRUE(ret == ERR_NULL);
1030 ret = OH_HiSysEvent_GetParamStringValue(record, nullptr, value4pp);
1031 ASSERT_TRUE(ret == ERR_NULL);
1032 size_t dataLen;
1033 int64_t value5[10];
1034 int64_t* value5p = value5;
1035 int64_t** value5pp = &value5p;
1036 ret = OH_HiSysEvent_GetParamInt64Values(record, "KEY", value5pp, dataLen);
1037 ASSERT_TRUE(ret == ERR_NULL);
1038 ret = OH_HiSysEvent_GetParamInt64Values(record, nullptr, value5pp, dataLen);
1039 ASSERT_TRUE(ret == ERR_NULL);
1040 uint64_t value6[10];
1041 uint64_t* value6p = value6;
1042 uint64_t** value6pp = &value6p;
1043 ret = OH_HiSysEvent_GetParamUint64Values(record, "KEY", value6pp, dataLen);
1044 ASSERT_TRUE(ret == ERR_NULL);
1045 ret = OH_HiSysEvent_GetParamUint64Values(record, nullptr, value6pp, dataLen);
1046 ASSERT_TRUE(ret == ERR_NULL);
1047 double value7[10];
1048 double* value7p = value7;
1049 double** value7pp = &value7p;
1050 ret = OH_HiSysEvent_GetParamDoubleValues(record, "KEY", value7pp, dataLen);
1051 ASSERT_TRUE(ret == ERR_NULL);
1052 ret = OH_HiSysEvent_GetParamDoubleValues(record, nullptr, value7pp, dataLen);
1053 ASSERT_TRUE(ret == ERR_NULL);
1054 char v3[10][100] {};
1055 char* dest3p = v3[0];
1056 char** dest3pp = &dest3p;
1057 char*** dest3ppp = &dest3pp;
1058 ret = OH_HiSysEvent_GetParamStringValues(record, "KEY", dest3ppp, dataLen);
1059 ASSERT_TRUE(ret == ERR_NULL);
1060 ret = OH_HiSysEvent_GetParamStringValues(record, nullptr, dest3ppp, dataLen);
1061 ASSERT_TRUE(ret == ERR_NULL);
1062 }
1063
1064