1 /*
2 * Copyright (c) 2023-2025 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 <iostream>
16 #include <unistd.h>
17
18 #include <gtest/gtest.h>
19
20 #include "app_event_processor_mgr.h"
21 #include "app_event_observer_mgr.h"
22 #include "application_context.h"
23 #include "hiappevent_base.h"
24 #include "hiappevent_config.h"
25 #include "hiappevent_test_common.h"
26
27 using namespace testing::ext;
28 using namespace OHOS::HiviewDFX;
29 using namespace OHOS::HiviewDFX::ErrorCode;
30 using namespace OHOS::HiviewDFX::HiAppEvent;
31 namespace {
32 const std::string TEST_PROCESSOR_NAME = "test_processor";
33 const std::string TEST_EVENT_DOMAIN = "test_domain";
34 const std::string TEST_EVENT_NAME = "test_name";
35 constexpr int TEST_EVENT_TYPE = 1;
36 constexpr int32_t TEST_UID = 200000 * 100;
37
WriteEventOnce()38 void WriteEventOnce()
39 {
40 auto event = std::make_shared<AppEventPack>(TEST_EVENT_DOMAIN, TEST_EVENT_NAME, TEST_EVENT_TYPE);
41 constexpr int testInt = 1;
42 event->AddParam("int_key", testInt);
43 constexpr double testDou = 1.2;
44 event->AddParam("double_key", testDou);
45 constexpr bool testBool = false;
46 event->AddParam("bool_key", testBool);
47 const std::string testStr = "str";
48 event->AddParam("str_key", testStr);
49 std::vector<std::shared_ptr<AppEventPack>> events;
50 events.emplace_back(event);
51 AppEventObserverMgr::GetInstance().HandleEvents(events);
52 sleep(1); // 1s
53 }
54
CheckRegisterObserver(const std::string & observer,std::shared_ptr<AppEventProcessor> processor,int64_t & processorSeq)55 void CheckRegisterObserver(const std::string& observer,
56 std::shared_ptr<AppEventProcessor> processor, int64_t& processorSeq)
57 {
58 ASSERT_EQ(AppEventProcessorMgr::RegisterProcessor(observer, processor), 0);
59 processorSeq = AppEventObserverMgr::GetInstance().AddProcessor(observer);
60 ASSERT_GT(processorSeq, 0);
61 }
62
CheckRegisterObserverWithConfig(const std::string & observer,std::shared_ptr<AppEventProcessor> processor,const ReportConfig & config,int64_t & processorSeq)63 void CheckRegisterObserverWithConfig(
64 const std::string& observer,
65 std::shared_ptr<AppEventProcessor> processor,
66 const ReportConfig& config,
67 int64_t& processorSeq)
68 {
69 ASSERT_EQ(AppEventProcessorMgr::RegisterProcessor(observer, processor), 0);
70 processorSeq = AppEventObserverMgr::GetInstance().AddProcessor(observer, config);
71 ASSERT_GT(processorSeq, 0);
72 }
73
CheckUnregisterObserver(const std::string & observer)74 void CheckUnregisterObserver(const std::string& observer)
75 {
76 ASSERT_EQ(AppEventProcessorMgr::UnregisterProcessor(observer), 0);
77 }
78
CheckGetEmptyConfig(int64_t processorSeq)79 void CheckGetEmptyConfig(int64_t processorSeq)
80 {
81 ReportConfig config;
82 ASSERT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorSeq, config), 0);
83 ASSERT_TRUE(config.name.empty());
84 ASSERT_FALSE(config.debugMode);
85 ASSERT_TRUE(config.routeInfo.empty());
86 ASSERT_TRUE(config.appId.empty());
87 ASSERT_EQ(config.triggerCond.row, 0);
88 ASSERT_EQ(config.triggerCond.size, 0);
89 ASSERT_EQ(config.triggerCond.timeout, 0);
90 ASSERT_FALSE(config.triggerCond.onStartup);
91 ASSERT_FALSE(config.triggerCond.onBackground);
92 ASSERT_TRUE(config.userIdNames.empty());
93 ASSERT_TRUE(config.userPropertyNames.empty());
94 ASSERT_TRUE(config.eventConfigs.empty());
95 ASSERT_EQ(config.configId, 0);
96 ASSERT_TRUE(config.customConfigs.empty());
97 }
98
CheckGetSeqs(const std::string & observer,const std::vector<int64_t> & expectSeqs)99 void CheckGetSeqs(const std::string& observer, const std::vector<int64_t>& expectSeqs)
100 {
101 std::vector<int64_t> processorSeqs;
102 ASSERT_EQ(AppEventProcessorMgr::GetProcessorSeqs(observer, processorSeqs), 0);
103 ASSERT_EQ(processorSeqs.size(), expectSeqs.size());
104
105 // test repeated getting seqs
106 ASSERT_EQ(AppEventProcessorMgr::GetProcessorSeqs(observer, processorSeqs), 0);
107 ASSERT_EQ(processorSeqs.size(), expectSeqs.size());
108 }
109
CheckSameConfig(const ReportConfig & configA,const ReportConfig & configB)110 void CheckSameConfig(const ReportConfig& configA, const ReportConfig& configB)
111 {
112 ASSERT_EQ(configA.name, configB.name);
113 ASSERT_EQ(configA.debugMode, configB.debugMode);
114 ASSERT_EQ(configA.routeInfo, configB.routeInfo);
115 ASSERT_EQ(configA.appId, configB.appId);
116 ASSERT_EQ(configA.triggerCond.row, configB.triggerCond.row);
117 ASSERT_EQ(configA.triggerCond.size, configB.triggerCond.size);
118 ASSERT_EQ(configA.triggerCond.timeout, configB.triggerCond.timeout);
119 ASSERT_EQ(configA.triggerCond.onStartup, configB.triggerCond.onStartup);
120 ASSERT_EQ(configA.triggerCond.onBackground, configB.triggerCond.onBackground);
121 ASSERT_EQ(configA.userIdNames.size(), configB.userIdNames.size());
122 ASSERT_EQ(configA.userPropertyNames.size(), configB.userPropertyNames.size());
123 ASSERT_EQ(configA.eventConfigs.size(), configB.eventConfigs.size());
124 ASSERT_EQ(configA.configId, configB.configId);
125 ASSERT_EQ(configA.customConfigs.size(), configB.customConfigs.size());
126 }
127
CheckSameConfig(int64_t processorSeq,const ReportConfig & testConfig)128 void CheckSameConfig(int64_t processorSeq, const ReportConfig& testConfig)
129 {
130 ReportConfig getConfig;
131 ASSERT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorSeq, getConfig), 0);
132 CheckSameConfig(testConfig, getConfig);
133 }
134
CheckSetConfig(int64_t processorSeq)135 void CheckSetConfig(int64_t processorSeq)
136 {
137 ReportConfig testConfig = {
138 .name = "test_name",
139 .debugMode = true,
140 .routeInfo = "test_routeInfo",
141 .appId = "test_appid",
142 .triggerCond = {1, 1, 1, true, true},
143 .userIdNames = {"test_id"},
144 .userPropertyNames = {"test_property"},
145 .eventConfigs = {{"test_domain", "test_name", true}},
146 .configId = 1,
147 .customConfigs = {{"str_key", "str_value"}},
148 };
149 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, testConfig), 0);
150 ReportConfig getConfig;
151 ASSERT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorSeq, getConfig), 0);
152 CheckSameConfig(testConfig, getConfig);
153 }
154
CheckSetRealTimeConfig(int64_t processorSeq)155 void CheckSetRealTimeConfig(int64_t processorSeq)
156 {
157 ReportConfig testConfig = {
158 .eventConfigs = {{TEST_EVENT_DOMAIN, TEST_EVENT_NAME, true}},
159 };
160 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, testConfig), 0);
161 }
162
CheckSetRowConfig(int64_t processorSeq)163 void CheckSetRowConfig(int64_t processorSeq)
164 {
165 ReportConfig testConfig = {
166 .triggerCond = {
167 .row = 2, // 2 events
168 },
169 .eventConfigs = {{TEST_EVENT_DOMAIN, TEST_EVENT_NAME}},
170 };
171 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, testConfig), 0);
172 }
173
CheckSetSizeConfig(int64_t processorSeq)174 void CheckSetSizeConfig(int64_t processorSeq)
175 {
176 ReportConfig testConfig = {
177 .triggerCond = {
178 .size = 300, // 300 byte, 2 events
179 },
180 .eventConfigs = {{TEST_EVENT_DOMAIN, TEST_EVENT_NAME}},
181 };
182 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, testConfig), 0);
183 }
184
CheckSetTimeoutConfig(int64_t processorSeq)185 void CheckSetTimeoutConfig(int64_t processorSeq)
186 {
187 ReportConfig testConfig = {
188 .triggerCond = {
189 .timeout = 2, // 2s
190 },
191 .eventConfigs = {{TEST_EVENT_DOMAIN, TEST_EVENT_NAME}},
192 };
193 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, testConfig), 0);
194 }
195
CheckSetOnBackgroundConfig(int64_t processorSeq)196 void CheckSetOnBackgroundConfig(int64_t processorSeq)
197 {
198 ReportConfig testConfig = {
199 .triggerCond = {
200 .onBackground = true,
201 },
202 .eventConfigs = {{TEST_EVENT_DOMAIN, TEST_EVENT_NAME}},
203 };
204 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, testConfig), 0);
205 }
206
CheckOnReport(const std::vector<UserId> & userIds,const std::vector<UserProperty> & userProperties,const std::vector<AppEventInfo> & events)207 void CheckOnReport(
208 const std::vector<UserId>& userIds,
209 const std::vector<UserProperty>& userProperties,
210 const std::vector<AppEventInfo>& events)
211 {
212 ASSERT_EQ(userIds.size(), 0);
213 ASSERT_EQ(userProperties.size(), 0);
214 ASSERT_GT(events.size(), 0);
215 for (const auto& event : events) {
216 ASSERT_EQ(event.domain, TEST_EVENT_DOMAIN);
217 ASSERT_EQ(event.name, TEST_EVENT_NAME);
218 ASSERT_EQ(event.eventType, TEST_EVENT_TYPE);
219 ASSERT_GT(event.timestamp, 0);
220 ASSERT_EQ(event.params, "{\"int_key\":1,\"double_key\":1.2,\"bool_key\":false,\"str_key\":\"str\"}\n");
221 }
222 }
223 }
224
225 class HiAppEventInnerApiTest : public testing::Test {
226 public:
SetUpTestCase()227 static void SetUpTestCase()
228 {
229 // set app uid
230 setuid(TEST_UID);
231 HiAppEventConfig::GetInstance().SetStorageDir("/data/test/hiappevent/");
232 // set context bundle name
233 auto context = OHOS::AbilityRuntime::ApplicationContext::GetInstance();
234 if (context != nullptr) {
235 auto contextImpl = std::make_shared<TestContextImpl>("ohos.hiappevent.innerapi.test");
236 context->AttachContextImpl(contextImpl);
237 std::cout << "set bundle name." << std::endl;
238 return;
239 }
240 std::cout << "context is null." << std::endl;
241 }
242
TearDownTestCase()243 static void TearDownTestCase() {}
SetUp()244 void SetUp() {}
TearDown()245 void TearDown() {}
246 };
247
248 class AppEventProcessorTest : public AppEventProcessor {
249 public:
250 int OnReport(
251 int64_t processorSeq,
252 const std::vector<UserId>& userIds,
253 const std::vector<UserProperty>& userProperties,
254 const std::vector<AppEventInfo>& events) override;
255 int ValidateUserId(const UserId& userId) override;
256 int ValidateUserProperty(const UserProperty& userProperty) override;
257 int ValidateEvent(const AppEventInfo& event) override;
GetReportTimes()258 int GetReportTimes() { return reportTimes_; }
259
260 private:
261 int reportTimes_ = 0;
262 };
263
OnReport(int64_t processorSeq,const std::vector<UserId> & userIds,const std::vector<UserProperty> & userProperties,const std::vector<AppEventInfo> & events)264 int AppEventProcessorTest::OnReport(
265 int64_t processorSeq,
266 const std::vector<UserId>& userIds,
267 const std::vector<UserProperty>& userProperties,
268 const std::vector<AppEventInfo>& events)
269 {
270 reportTimes_++;
271
272 std::cout << "UserId size=" << userIds.size() << std::endl;
273 std::cout << "UserProperty size=" << userProperties.size() << std::endl;
274 std::cout << "AppEventInfo size=" << events.size() << std::endl;
275 for (const auto& event : events) {
276 std::cout << "AppEventInfo.domain=" << event.domain << std::endl;
277 std::cout << "AppEventInfo.name=" << event.name << std::endl;
278 std::cout << "AppEventInfo.eventType=" << event.eventType << std::endl;
279 std::cout << "AppEventInfo.timestamp=" << event.timestamp << std::endl;
280 std::cout << "AppEventInfo.params=" << event.params << std::endl;
281 }
282 CheckOnReport(userIds, userProperties, events);
283 return 0;
284 }
285
ValidateUserId(const UserId & userId)286 int AppEventProcessorTest::ValidateUserId(const UserId& userId)
287 {
288 return (userId.name.find("test") == std::string::npos) ? -1 : 0;
289 }
290
ValidateUserProperty(const UserProperty & userProperty)291 int AppEventProcessorTest::ValidateUserProperty(const UserProperty& userProperty)
292 {
293 return (userProperty.name.find("test") == std::string::npos) ? -1 : 0;
294 }
295
ValidateEvent(const AppEventInfo & event)296 int AppEventProcessorTest::ValidateEvent(const AppEventInfo& event)
297 {
298 return (event.domain.find("test") == std::string::npos) ? -1 : 0;
299 }
300
301 /**
302 * @tc.name: HiAppEventInnerApiTest001
303 * @tc.desc: check the api AppEventProcessorMgr.
304 * @tc.type: FUNC
305 */
306 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest001, TestSize.Level0)
307 {
308 /**
309 * @tc.steps: step1. Create an AppEventProcessor object.
310 * @tc.steps: step2. Register the AppEventProcessor object.
311 * @tc.steps: step3. Get processor sequence by name.
312 * @tc.steps: step4. Get processor config by sequence.
313 * @tc.steps: step5. Set processor config by sequence.
314 * @tc.steps: step6. Unregister the AppEventProcessor object.
315 */
316 auto processor = std::make_shared<AppEventProcessorTest>();
317 int64_t processorSeq = 0;
318 CheckRegisterObserver(TEST_PROCESSOR_NAME, processor, processorSeq);
319 CheckGetSeqs(TEST_PROCESSOR_NAME, {processorSeq});
320 CheckGetEmptyConfig(processorSeq);
321 CheckSetConfig(processorSeq);
322 WriteEventOnce();
323 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
324 }
325
326 /**
327 * @tc.name: HiAppEventInnerApiTest002
328 * @tc.desc: check the api AppEventProcessorMgr.
329 * @tc.type: FUNC
330 */
331 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest002, TestSize.Level0)
332 {
333 /**
334 * @tc.steps: step1. Create an AppEventProcessor object.
335 * @tc.steps: step2. Register the AppEventProcessor object.
336 * @tc.steps: step3. Register the same AppEventProcessor object.
337 * @tc.steps: step4. Unregister the AppEventProcessor object.
338 * @tc.steps: step5. Unregister the same AppEventProcessor object.
339 */
340 auto processor = std::make_shared<AppEventProcessorTest>();
341 auto ret = AppEventProcessorMgr::RegisterProcessor(TEST_PROCESSOR_NAME, processor);
342 ASSERT_EQ(ret, 0);
343 ret = AppEventProcessorMgr::RegisterProcessor(TEST_PROCESSOR_NAME, processor);
344 ASSERT_EQ(ret, -1);
345 ret = AppEventProcessorMgr::UnregisterProcessor(TEST_PROCESSOR_NAME);
346 ASSERT_EQ(ret, 0);
347 ret = AppEventProcessorMgr::UnregisterProcessor(TEST_PROCESSOR_NAME);
348 ASSERT_EQ(ret, -1);
349 }
350
351 /**
352 * @tc.name: HiAppEventInnerApiTest003
353 * @tc.desc: check the real-time event callback AppEventProcessor.
354 * @tc.type: FUNC
355 */
356 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest003, TestSize.Level0)
357 {
358 /**
359 * @tc.steps: step1. Register an AppEventProcessor object.
360 * @tc.steps: step2. Set config to the AppEventProcessor object.
361 * @tc.steps: step3. Write an test event.
362 * @tc.steps: step4. Unregister the AppEventProcessor object.
363 */
364 auto processor = std::make_shared<AppEventProcessorTest>();
365 int64_t processorSeq = 0;
366 CheckRegisterObserver(TEST_PROCESSOR_NAME, processor, processorSeq);
367 CheckSetRealTimeConfig(processorSeq);
368 WriteEventOnce();
369 ASSERT_EQ(processor->GetReportTimes(), 1);
370 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
371 }
372
373 /**
374 * @tc.name: HiAppEventInnerApiTest004
375 * @tc.desc: check the row callback AppEventProcessor.
376 * @tc.type: FUNC
377 */
378 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest004, TestSize.Level0)
379 {
380 /**
381 * @tc.steps: step1. Register an AppEventProcessor object.
382 * @tc.steps: step2. Set config to the AppEventProcessor object.
383 * @tc.steps: step3. Write an test event.
384 * @tc.steps: step4. Unregister the AppEventProcessor object.
385 */
386 auto processor = std::make_shared<AppEventProcessorTest>();
387 int64_t processorSeq = 0;
388 CheckRegisterObserver(TEST_PROCESSOR_NAME, processor, processorSeq);
389 CheckSetRowConfig(processorSeq);
390
391 ASSERT_EQ(processor->GetReportTimes(), 0);
392 WriteEventOnce();
393 ASSERT_EQ(processor->GetReportTimes(), 0);
394 WriteEventOnce();
395 ASSERT_EQ(processor->GetReportTimes(), 1);
396
397 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
398 }
399
400 /**
401 * @tc.name: HiAppEventInnerApiTest005
402 * @tc.desc: check the size callback AppEventProcessor.
403 * @tc.type: FUNC
404 */
405 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest005, TestSize.Level0)
406 {
407 /**
408 * @tc.steps: step1. Register an AppEventProcessor object.
409 * @tc.steps: step2. Set config to the AppEventProcessor object.
410 * @tc.steps: step3. Write an test event.
411 * @tc.steps: step4. Unregister the AppEventProcessor object.
412 */
413 auto processor = std::make_shared<AppEventProcessorTest>();
414 int64_t processorSeq = 0;
415 CheckRegisterObserver(TEST_PROCESSOR_NAME, processor, processorSeq);
416 CheckSetSizeConfig(processorSeq);
417
418 ASSERT_EQ(processor->GetReportTimes(), 0);
419 WriteEventOnce();
420 ASSERT_EQ(processor->GetReportTimes(), 0);
421 WriteEventOnce();
422 ASSERT_EQ(processor->GetReportTimes(), 1);
423
424 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
425 }
426
427 /**
428 * @tc.name: HiAppEventInnerApiTest006
429 * @tc.desc: check the timeout callback AppEventProcessor.
430 * @tc.type: FUNC
431 */
432 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest006, TestSize.Level0)
433 {
434 /**
435 * @tc.steps: step1. Register an AppEventProcessor object.
436 * @tc.steps: step2. Set config to the AppEventProcessor object.
437 * @tc.steps: step3. Write an test event.
438 * @tc.steps: step4. Unregister the AppEventProcessor object.
439 */
440 auto processor = std::make_shared<AppEventProcessorTest>();
441 int64_t processorSeq = 0;
442 CheckRegisterObserver(TEST_PROCESSOR_NAME, processor, processorSeq);
443 CheckSetTimeoutConfig(processorSeq);
444
445 ASSERT_EQ(processor->GetReportTimes(), 0);
446 WriteEventOnce();
447 ASSERT_EQ(processor->GetReportTimes(), 0);
448 sleep(HiAppEvent::TIMEOUT_STEP + 1); // 31s
449 ASSERT_EQ(processor->GetReportTimes(), 1);
450
451 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
452 }
453
454 /**
455 * @tc.name: HiAppEventInnerApiTest007
456 * @tc.desc: check the background callback AppEventProcessor.
457 * @tc.type: FUNC
458 */
459 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest007, TestSize.Level0)
460 {
461 /**
462 * @tc.steps: step1. Register an AppEventProcessor object.
463 * @tc.steps: step2. Set config to the AppEventProcessor object.
464 * @tc.steps: step3. Write an test event.
465 * @tc.steps: step4. Unregister the AppEventProcessor object.
466 */
467 auto processor = std::make_shared<AppEventProcessorTest>();
468 int64_t processorSeq = 0;
469 CheckRegisterObserver(TEST_PROCESSOR_NAME, processor, processorSeq);
470 CheckSetOnBackgroundConfig(processorSeq);
471
472 ASSERT_EQ(processor->GetReportTimes(), 0);
473 WriteEventOnce();
474 ASSERT_EQ(processor->GetReportTimes(), 0);
475 AppEventObserverMgr::GetInstance().HandleBackground();
476 sleep(1); // 1s
477 ASSERT_EQ(processor->GetReportTimes(), 1);
478
479 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
480 }
481
482 /**
483 * @tc.name: HiAppEventInnerApiTest008
484 * @tc.desc: check the startup callback AppEventProcessor.
485 * @tc.type: FUNC
486 */
487 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest008, TestSize.Level0)
488 {
489 /**
490 * @tc.steps: step1. Register an AppEventProcessor object.
491 * @tc.steps: step2. Write an test event.
492 * @tc.steps: step3. Register an AppEventProcessor object with same configuration.
493 * @tc.steps: step4. Unregister the AppEventProcessor object.
494 */
495 auto processor = std::make_shared<AppEventProcessorTest>();
496 int64_t processorSeq1 = 0;
497 ReportConfig config = {
498 .name = TEST_PROCESSOR_NAME,
499 .triggerCond = {
500 .onStartup = true,
501 },
502 .eventConfigs = {{TEST_EVENT_DOMAIN, TEST_EVENT_NAME}},
503 };
504 CheckRegisterObserverWithConfig(TEST_PROCESSOR_NAME, processor, config, processorSeq1);
505
506 ASSERT_EQ(processor->GetReportTimes(), 0);
507 WriteEventOnce();
508 ASSERT_EQ(processor->GetReportTimes(), 0);
509
510 int64_t processorSeq2 = AppEventObserverMgr::GetInstance().AddProcessor(TEST_PROCESSOR_NAME, config);
511 ASSERT_EQ(processorSeq1, processorSeq2);
512 ASSERT_EQ(processor->GetReportTimes(), 0);
513
514 CheckUnregisterObserver(TEST_PROCESSOR_NAME);
515 }
516
517 /**
518 * @tc.name: HiAppEventInnerApiTest009
519 * @tc.desc: Adding a processor that does not exist.
520 * @tc.type: FUNC
521 */
522 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest009, TestSize.Level1)
523 {
524 ReportConfig config = {
525 .name = "invalid_processor",
526 };
527 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
528 ASSERT_EQ(processorId, -1);
529 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
530 }
531
532 /**
533 * @tc.name: HiAppEventInnerApiTest010
534 * @tc.desc: Adding an existing processor.
535 * @tc.type: FUNC
536 */
537 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest010, TestSize.Level1)
538 {
539 ReportConfig config = {
540 .name = "test_processor",
541 .debugMode = true,
542 .routeInfo = "test_routeInfo",
543 .appId = "test_appid",
544 .triggerCond = {
545 .row = 1,
546 .timeout = 0,
547 .onStartup = false,
548 .onBackground = false,
549 },
550 .userIdNames = {"test_id"},
551 .userPropertyNames = {"test_property"},
552 .eventConfigs = {{"test_domain", "test_name", true}, {"test_domain", "test_realtime"}},
553 .configId = 1,
554 .customConfigs = {{"str_key", "str_value"}, {"str_key1", "str_value1"}},
555 };
556 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
557 ASSERT_GT(processorId, 0);
558 CheckSameConfig(processorId, config);
559 WriteEventOnce();
560 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
561 }
562
563 /**
564 * @tc.name: HiAppEventInnerApiTest011
565 * @tc.desc: Adding an invalid processor with invalid name.
566 * @tc.type: FUNC
567 */
568 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest011, TestSize.Level1)
569 {
570 ReportConfig config = {
571 .name = "",
572 };
573 ASSERT_EQ(AppEventProcessorMgr::AddProcessor(config), -1);
574
575 constexpr size_t limitLen = 256;
576 config.name = std::string(limitLen, 'a');
577 ASSERT_EQ(AppEventProcessorMgr::AddProcessor(config), -1);
578
579 config.name = "***dddd";
580 ASSERT_EQ(AppEventProcessorMgr::AddProcessor(config), -1);
581
582 config.name = "999aaaa";
583 ASSERT_EQ(AppEventProcessorMgr::AddProcessor(config), -1);
584 }
585
586 /**
587 * @tc.name: HiAppEventInnerApiTest012
588 * @tc.desc: Adding an processor with invalid routeInfo.
589 * @tc.type: FUNC
590 */
591 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest012, TestSize.Level1)
592 {
593 constexpr size_t limitLen = 8 * 1024;
594 ReportConfig config = {
595 .name = "test_processor",
596 .routeInfo = std::string(limitLen, 'a'),
597 };
598 int64_t processorId1 = AppEventProcessorMgr::AddProcessor(config);
599 ASSERT_GT(processorId1, 0);
600 CheckSameConfig(processorId1, config);
601 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId1), 0);
602
603 config.routeInfo = std::string(limitLen + 1, 'a');
604 int64_t processorId2 = AppEventProcessorMgr::AddProcessor(config);
605 ASSERT_GT(processorId2, 0);
606
607 ReportConfig expectConfig = {
608 .name = "test_processor",
609 .routeInfo = "", // default routeInfo value
610 };
611 CheckSameConfig(processorId2, expectConfig);
612
613 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId2), 0);
614 }
615
616 /**
617 * @tc.name: HiAppEventInnerApiTest013
618 * @tc.desc: Adding an processor with invalid appId.
619 * @tc.type: FUNC
620 */
621 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest013, TestSize.Level1)
622 {
623 constexpr size_t limitLen = 8 * 1024;
624 ReportConfig config = {
625 .name = "test_processor",
626 .appId = std::string(limitLen, 'a'),
627 };
628 int64_t processorId1 = AppEventProcessorMgr::AddProcessor(config);
629 ASSERT_GT(processorId1, 0);
630 CheckSameConfig(processorId1, config);
631 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId1), 0);
632
633 config.appId = std::string(limitLen + 1, 'a');
634 int64_t processorId2 = AppEventProcessorMgr::AddProcessor(config);
635 ASSERT_GT(processorId2, 0);
636
637 ReportConfig expectConfig = {
638 .name = "test_processor",
639 .appId = "", // default appId value
640 };
641 CheckSameConfig(processorId2, expectConfig);
642
643 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId2), 0);
644 }
645
646 /**
647 * @tc.name: HiAppEventInnerApiTest014
648 * @tc.desc: Adding an processor with invalid triggerCond.row.
649 * @tc.type: FUNC
650 */
651 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest014, TestSize.Level1)
652 {
653 constexpr int limitRow = 1000;
654 ReportConfig config = {
655 .name = "test_processor",
656 .triggerCond = {
657 .row = limitRow,
658 },
659 };
660 int64_t processorId1 = AppEventProcessorMgr::AddProcessor(config);
661 ASSERT_GT(processorId1, 0);
662 CheckSameConfig(processorId1, config);
663 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId1), 0);
664
665 config.triggerCond.row = -1;
666 int64_t processorId2 = AppEventProcessorMgr::AddProcessor(config);
667 ASSERT_GT(processorId2, 0);
668 ReportConfig expectConfig = {
669 .name = "test_processor",
670 .triggerCond.row = 0, // default row value
671 };
672 CheckSameConfig(processorId2, expectConfig);
673 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId2), 0);
674
675 config.triggerCond.row = limitRow + 1;
676 int64_t processorId3 = AppEventProcessorMgr::AddProcessor(config);
677 ASSERT_GT(processorId3, 0);
678 CheckSameConfig(processorId3, expectConfig);
679 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId3), 0);
680 }
681
682 /**
683 * @tc.name: HiAppEventInnerApiTest015
684 * @tc.desc: Adding an processor with invalid triggerCond.timeout.
685 * @tc.type: FUNC
686 */
687 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest015, TestSize.Level1)
688 {
689 ReportConfig config = {
690 .name = "test_processor",
691 .triggerCond = {
692 .timeout = -1,
693 },
694 };
695 int64_t processorId1 = AppEventProcessorMgr::AddProcessor(config);
696 ASSERT_GT(processorId1, 0);
697 ReportConfig expectConfig = {
698 .name = "test_processor",
699 .triggerCond.timeout = 0, // default timeout value
700 };
701 CheckSameConfig(processorId1, expectConfig);
702 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId1), 0);
703 }
704
705 /**
706 * @tc.name: HiAppEventInnerApiTest016
707 * @tc.desc: Adding an processor with invalid userIdNames.
708 * @tc.type: FUNC
709 */
710 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest016, TestSize.Level1)
711 {
712 constexpr size_t limitLen = 256;
713 ReportConfig config = {
714 .name = "test_processor",
715 .userIdNames = {
716 std::string(limitLen, 'a'), "id1"
717 },
718 };
719 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
720 ASSERT_GT(processorId, 0);
721 CheckSameConfig(processorId, config);
722 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
723
724 config.userIdNames = {"***xxxx", "id1"};
725 processorId = AppEventProcessorMgr::AddProcessor(config);
726 ASSERT_GT(processorId, 0);
727 ReportConfig expectConfig = {
728 .name = "test_processor",
729 .userIdNames = {}, // default userIdNames value
730 };
731 CheckSameConfig(processorId, expectConfig);
732 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
733
734 config.userIdNames = {"", "id1"};
735 processorId = AppEventProcessorMgr::AddProcessor(config);
736 ASSERT_GT(processorId, 0);
737 CheckSameConfig(processorId, expectConfig);
738 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
739
740 config.userIdNames = {std::string(limitLen + 1, 'a'), "id1"};
741 processorId = AppEventProcessorMgr::AddProcessor(config);
742 ASSERT_GT(processorId, 0);
743 CheckSameConfig(processorId, expectConfig);
744 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
745 }
746
747 /**
748 * @tc.name: HiAppEventInnerApiTest017
749 * @tc.desc: Adding an processor with invalid userIdNames.
750 * @tc.type: FUNC
751 */
752 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest017, TestSize.Level1)
753 {
754 constexpr size_t limitLen = 256;
755 ReportConfig config = {
756 .name = "test_processor",
757 .userPropertyNames = {
758 std::string(limitLen, 'a'), "id1"
759 },
760 };
761 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
762 ASSERT_GT(processorId, 0);
763 CheckSameConfig(processorId, config);
764 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
765
766 config.userPropertyNames = {"***xxxx", "id1"};
767 processorId = AppEventProcessorMgr::AddProcessor(config);
768 ASSERT_GT(processorId, 0);
769 ReportConfig expectConfig = {
770 .name = "test_processor",
771 .userPropertyNames = {}, // default userPropertyNames value
772 };
773 CheckSameConfig(processorId, expectConfig);
774 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
775
776 config.userPropertyNames = {"", "id1"};
777 processorId = AppEventProcessorMgr::AddProcessor(config);
778 ASSERT_GT(processorId, 0);
779 CheckSameConfig(processorId, expectConfig);
780 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
781
782 config.userPropertyNames = {std::string(limitLen + 1, 'a'), "id1"};
783 processorId = AppEventProcessorMgr::AddProcessor(config);
784 ASSERT_GT(processorId, 0);
785 CheckSameConfig(processorId, expectConfig);
786 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
787 }
788
789 /**
790 * @tc.name: HiAppEventInnerApiTest018
791 * @tc.desc: Adding an processor with invalid eventConfigs.
792 * @tc.type: FUNC
793 */
794 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest018, TestSize.Level1)
795 {
796 ReportConfig config = {
797 .name = "test_processor",
798 .eventConfigs = {
799 {"***domain", "name"}
800 },
801 };
802 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
803 ASSERT_GT(processorId, 0);
804 ReportConfig expectConfig = {
805 .name = "test_processor",
806 .eventConfigs = {}, // default eventConfigs value
807 };
808 CheckSameConfig(processorId, expectConfig);
809 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
810
811 config.eventConfigs = {{"domain", "***name"}};
812 processorId = AppEventProcessorMgr::AddProcessor(config);
813 ASSERT_GT(processorId, 0);
814 CheckSameConfig(processorId, expectConfig);
815 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
816
817 config.eventConfigs = {{"", "", true}, {"test_domain", "test_name"}};
818 processorId = AppEventProcessorMgr::AddProcessor(config);
819 ASSERT_GT(processorId, 0);
820 CheckSameConfig(processorId, expectConfig);
821 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
822 }
823
824 /**
825 * @tc.name: HiAppEventInnerApiTest019
826 * @tc.desc: Adding an existing processor with empty domain.
827 * @tc.type: FUNC
828 */
829 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest019, TestSize.Level1)
830 {
831 ReportConfig config = {
832 .name = "test_processor",
833 .eventConfigs = {
834 {"", TEST_EVENT_NAME, true}
835 },
836 };
837 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
838 ASSERT_GT(processorId, 0);
839 CheckSameConfig(processorId, config);
840 WriteEventOnce();
841 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
842 }
843
844 /**
845 * @tc.name: HiAppEventInnerApiTest020
846 * @tc.desc: Adding an existing processor with empty name.
847 * @tc.type: FUNC
848 */
849 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest020, TestSize.Level1)
850 {
851 ReportConfig config = {
852 .name = "test_processor",
853 .eventConfigs = {
854 {TEST_EVENT_DOMAIN, "", true}
855 },
856 };
857 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
858 ASSERT_GT(processorId, 0);
859 CheckSameConfig(processorId, config);
860 WriteEventOnce();
861 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
862 }
863
864 /**
865 * @tc.name: HiAppEventInnerApiTest021
866 * @tc.desc: Adding an processor with same processorId.
867 * @tc.type: FUNC
868 */
869 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest021, TestSize.Level1)
870 {
871 ReportConfig config = {
872 .name = "test_processor",
873 .configId = 1,
874 };
875 int64_t processorId1 = AppEventProcessorMgr::AddProcessor(config);
876 ASSERT_GT(processorId1, 0);
877
878 config.eventConfigs = {{"test_domain", "test_name", true}, {"test_domain", "test_realtime"}};
879 int64_t processorId2 = AppEventProcessorMgr::AddProcessor(config);
880 ASSERT_GT(processorId2, 0);
881 ASSERT_EQ(processorId1, processorId2);
882
883 config.configId = 0;
884 int64_t processorId3 = AppEventProcessorMgr::AddProcessor(config);
885 ASSERT_GT(processorId3, 0);
886 ASSERT_NE(processorId2, processorId3);
887
888 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId1), 0);
889 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId2), 0);
890 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId3), 0);
891 }
892
893 /**
894 * @tc.name: HiAppEventInnerApiTest022
895 * @tc.desc: Adding an processor with invalid configId.
896 * @tc.type: FUNC
897 */
898 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest022, TestSize.Level1)
899 {
900 ReportConfig config = {
901 .name = "test_processor",
902 .configId = -1,
903 };
904 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
905 ASSERT_GT(processorId, 0);
906 ReportConfig expectConfig = {
907 .name = "test_processor",
908 .configId = 0, // default configId
909 };
910 CheckSameConfig(processorId, expectConfig);
911 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
912 }
913
914 /**
915 * @tc.name: HiAppEventInnerApiTest023
916 * @tc.desc: Adding an processor with invalid customConfigs.
917 * @tc.type: FUNC
918 */
919 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest023, TestSize.Level1)
920 {
921 ReportConfig config = {
922 .name = "test_processor",
923 .customConfigs = {{"", "test_str"}},
924 };
925 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
926 ASSERT_GT(processorId, 0);
927 ReportConfig expectConfig = {
928 .name = "test_processor",
929 .customConfigs = {}, // default customConfigs value
930 };
931 CheckSameConfig(processorId, expectConfig);
932 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
933
934 config.customConfigs = {{"**name", "value"}};
935 processorId = AppEventProcessorMgr::AddProcessor(config);
936 ASSERT_GT(processorId, 0);
937 CheckSameConfig(processorId, expectConfig);
938 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
939
940 constexpr size_t limitLen = 1024;
941 config.customConfigs = {{"test_name", std::string(limitLen + 1, 'a')}};
942 processorId = AppEventProcessorMgr::AddProcessor(config);
943 ASSERT_GT(processorId, 0);
944 CheckSameConfig(processorId, expectConfig);
945 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
946 }
947
948 /**
949 * @tc.name: HiAppEventInnerApiTest024
950 * @tc.desc: check the api AppEventProcessorMgr not app.
951 * @tc.type: FUNC
952 */
953 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest024, TestSize.Level0)
954 {
955 setuid(0); // 0 means root uid
956
957 auto processor = std::make_shared<AppEventProcessorTest>();
958 ASSERT_EQ(AppEventProcessorMgr::RegisterProcessor(TEST_PROCESSOR_NAME, processor), ERROR_NOT_APP);
959 ASSERT_EQ(AppEventProcessorMgr::UnregisterProcessor(TEST_PROCESSOR_NAME), ERROR_NOT_APP);
960
961 std::vector<int64_t> processorSeqs;
962 ASSERT_EQ(AppEventProcessorMgr::GetProcessorSeqs(TEST_PROCESSOR_NAME, processorSeqs), ERROR_NOT_APP);
963
964 int64_t processorSeq = 0;
965 ReportConfig config = {
966 .name = TEST_PROCESSOR_NAME,
967 };
968 ASSERT_EQ(AppEventProcessorMgr::SetProcessorConfig(processorSeq, config), ERROR_NOT_APP);
969 ASSERT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorSeq, config), ERROR_NOT_APP);
970
971 ASSERT_EQ(AppEventProcessorMgr::AddProcessor(config), ERROR_NOT_APP);
972 ASSERT_EQ(AppEventProcessorMgr::RemoveProcessor(processorSeq), ERROR_NOT_APP);
973
974 // set app uid
975 setuid(TEST_UID);
976 }
977
978 /**
979 * @tc.name: HiAppEventInnerApiTest025
980 * @tc.desc: test ReportConfig ToString func.
981 * @tc.type: FUNC
982 */
983 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest025, TestSize.Level0)
984 {
985 ReportConfig config = {
986 .name = "test_processor",
987 .debugMode = true,
988 .routeInfo = "test_routeInfo",
989 .appId = "test_appid",
990 .triggerCond = {
991 .row = 1,
992 .timeout = 0,
993 .onStartup = false,
994 .onBackground = false,
995 },
996 .userIdNames = {"test_id"},
997 .userPropertyNames = {"test_property"},
998 .eventConfigs = {{"test_domain", "test_name", true}, {"test_domain", "test_realtime"}},
999 .configId = 1,
1000 .customConfigs = {{"str_key", "str_value"}, {"str_key1", "str_value1"}},
1001 .configName = "test_configName",
1002 };
1003 std::string expectStr = std::string("{test_processor,1,test_routeInfo,test_appid,{1,0,0,0,0},[test_id],") +
1004 "[test_property],[{test_domain,test_name,1},{test_domain,test_realtime,0}],1,[{str_key1,str_value1}," +
1005 "{str_key,str_value}],test_configName}";
1006 EXPECT_TRUE(config.ToString() == expectStr);
1007 }
1008
1009 /**
1010 * @tc.name: HiAppEventInnerApiTest026
1011 * @tc.desc: Adding a processor with valid configName.
1012 * @tc.type: FUNC
1013 */
1014 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest026, TestSize.Level1)
1015 {
1016 ReportConfig config = {
1017 .name = "test_processor",
1018 .configName = "SDK_OCG",
1019 };
1020 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
1021 EXPECT_GT(processorId, 0);
1022
1023 EXPECT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
1024 }
1025
1026 /**
1027 * @tc.name: HiAppEventInnerApiTest027
1028 * @tc.desc: Adding an invalid processor with invalid configName.
1029 * @tc.type: FUNC
1030 */
1031 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest027, TestSize.Level1)
1032 {
1033 ReportConfig config = {
1034 .name = "test_processor",
1035 .configName = "undefine",
1036 };
1037 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
1038 EXPECT_GT(processorId, 0);
1039
1040 ReportConfig realConfig;
1041 EXPECT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorId, realConfig), 0);
1042 std::string expectStr = "{test_processor,0,,,{0,0,0,0,0},[],[],[],0,[],undefine}";
1043 EXPECT_EQ(realConfig.ToString(), expectStr);
1044
1045 EXPECT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
1046 }
1047
1048 /**
1049 * @tc.name: HiAppEventInnerApiTest028
1050 * @tc.desc: Adding an invalid processor with invalid configName.
1051 * @tc.type: FUNC
1052 */
1053 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest028, TestSize.Level1)
1054 {
1055 ReportConfig config = {
1056 .name = "test_processor",
1057 .configName = "",
1058 };
1059 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
1060 EXPECT_GT(processorId, 0);
1061
1062 ReportConfig realConfig;
1063 EXPECT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorId, realConfig), 0);
1064 std::string expectStr = "{test_processor,0,,,{0,0,0,0,0},[],[],[],0,[],}";
1065 EXPECT_EQ(realConfig.ToString(), expectStr);
1066
1067 EXPECT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
1068 }
1069
1070 /**
1071 * @tc.name: HiAppEventInnerApiTest029
1072 * @tc.desc: Adding an invalid processor with invalid configName.
1073 * @tc.type: FUNC
1074 */
1075 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest029, TestSize.Level1)
1076 {
1077 ReportConfig config = {
1078 .name = "test_processor",
1079 .configName = "xxx***",
1080 };
1081 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
1082 EXPECT_GT(processorId, 0);
1083
1084 ReportConfig realConfig;
1085 EXPECT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorId, realConfig), 0);
1086 std::string expectStr = "{test_processor,0,,,{0,0,0,0,0},[],[],[],0,[],}";
1087 EXPECT_EQ(realConfig.ToString(), expectStr);
1088
1089 EXPECT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
1090 }
1091
1092 /**
1093 * @tc.name: HiAppEventInnerApiTest030
1094 * @tc.desc: Adding an invalid processor with invalid configName.
1095 * @tc.type: FUNC
1096 */
1097 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest030, TestSize.Level1)
1098 {
1099 ReportConfig config = {
1100 .name = "test_processor",
1101 .configName = "123_processor",
1102 };
1103 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
1104 EXPECT_GT(processorId, 0);
1105
1106 ReportConfig realConfig;
1107 EXPECT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorId, realConfig), 0);
1108 std::string expectStr = "{test_processor,0,,,{0,0,0,0,0},[],[],[],0,[],}";
1109 EXPECT_EQ(realConfig.ToString(), expectStr);
1110
1111 EXPECT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
1112 }
1113
1114 /**
1115 * @tc.name: HiAppEventInnerApiTest031
1116 * @tc.desc: Adding an invalid processor with invalid configName.
1117 * @tc.type: FUNC
1118 */
1119 HWTEST_F(HiAppEventInnerApiTest, HiAppEventInnerApiTest031, TestSize.Level1)
1120 {
1121 constexpr size_t limitLen = 256 + 1;
1122 ReportConfig config = {
1123 .name = "test_processor",
1124 .configName = std::string(limitLen, 'a'),
1125 };
1126
1127 int64_t processorId = AppEventProcessorMgr::AddProcessor(config);
1128 EXPECT_GT(processorId, 0);
1129
1130 ReportConfig realConfig;
1131 EXPECT_EQ(AppEventProcessorMgr::GetProcessorConfig(processorId, realConfig), 0);
1132 std::string expectStr = "{test_processor,0,,,{0,0,0,0,0},[],[],[],0,[],}";
1133 EXPECT_EQ(realConfig.ToString(), expectStr);
1134
1135 EXPECT_EQ(AppEventProcessorMgr::RemoveProcessor(processorId), 0);
1136 }