• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #define private public
17 #define protected public
18 
19 #include <string>
20 
21 #include <gtest/gtest.h>
22 #include "system_ability_definition.h"
23 
24 #include "bundle_active_client.h"
25 #include "bundle_active_event.h"
26 #include "app_group_callback_stub.h"
27 #include "bundle_active_group_map.h"
28 #include "app_group_callback_info.h"
29 #include "bundle_active_form_record.h"
30 #include "bundle_active_event_stats.h"
31 #include "bundle_active_module_record.h"
32 #include "bundle_active_package_stats.h"
33 #include "app_group_callback_proxy.h"
34 #include "iapp_group_callback.h"
35 
36 using namespace testing::ext;
37 
38 namespace OHOS {
39 namespace DeviceUsageStats {
40 static std::string g_defaultBundleName = "com.ohos.camera";
41 static std::string g_defaultMoudleName = "defaultmodulename";
42 static std::string g_defaultFormName = "defaultformname";
43 static int32_t DEFAULT_DIMENSION = 4;
44 static int64_t DEFAULT_FORMID = 1;
45 static int32_t DEFAULT_USERID = 0;
46 static int32_t COMMON_USERID = 100;
47 static int32_t DEFAULT_ERRCODE = 0;
48 static int64_t LARGE_NUM = 20000000000000;
49 static int32_t DEFAULT_GROUP = 10;
50 static std::vector<int32_t> GROUP_TYPE {10, 20, 30, 40, 50};
51 static sptr<IAppGroupCallback> observer = nullptr;
52 
53 class DeviceUsageStatisticsTest : public testing::Test {
54 public:
55     static void SetUpTestCase(void);
56     static void TearDownTestCase(void);
57     void SetUp();
58     void TearDown();
59 };
60 
SetUpTestCase(void)61 void DeviceUsageStatisticsTest::SetUpTestCase(void)
62 {
63 }
64 
TearDownTestCase(void)65 void DeviceUsageStatisticsTest::TearDownTestCase(void)
66 {
67 }
68 
SetUp(void)69 void DeviceUsageStatisticsTest::SetUp(void)
70 {
71 }
72 
TearDown(void)73 void DeviceUsageStatisticsTest::TearDown(void)
74 {
75 }
76 
77 class TestAppGroupChangeCallback : public AppGroupCallbackStub {
78 public:
79     void OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo) override;
80 };
81 
OnAppGroupChanged(const AppGroupCallbackInfo & appGroupCallbackInfo)82 void TestAppGroupChangeCallback::OnAppGroupChanged(const AppGroupCallbackInfo &appGroupCallbackInfo)
83 {
84     BUNDLE_ACTIVE_LOGI("TestAppGroupChangeCallback::OnAppGroupChanged!");
85     MessageParcel data;
86     if (!appGroupCallbackInfo.Marshalling(data)) {
87         BUNDLE_ACTIVE_LOGE("Marshalling fail");
88     }
89     appGroupCallbackInfo.Unmarshalling(data);
90 }
91 
92 /*
93  * @tc.name: DeviceUsageStatisticsTest_GetServiceObject_001
94  * @tc.desc: get service object
95  * @tc.type: FUNC
96  * @tc.require: SR000GGTO8 AR000GH6PK
97  */
98 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_GetServiceObject_001, Function | MediumTest | Level0)
99 {
100     sptr<ISystemAbilityManager> systemAbilityManager =
101         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
102     EXPECT_NE(systemAbilityManager, nullptr);
103 
104     sptr<IRemoteObject> remoteObject =
105         systemAbilityManager->GetSystemAbility(DEVICE_USAGE_STATISTICS_SYS_ABILITY_ID);
106     EXPECT_NE(remoteObject, nullptr);
107 }
108 
109 /*
110  * @tc.name: DeviceUsageStatisticsTest_ReportEvent_001
111  * @tc.desc: report a mock event
112  * @tc.type: FUNC
113  * @tc.require: SR000GGTO7 SR000GU31B AR000GH6PJ AR000GU380
114  */
115 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ReportEvent_001, Function | MediumTest | Level0)
116 {
117     BundleActiveEvent eventA(g_defaultBundleName, g_defaultMoudleName, g_defaultFormName,
118         DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED);
119     BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID);
120     BundleActiveEvent eventB(g_defaultBundleName, g_defaultMoudleName, g_defaultFormName,
121         DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_REMOVED);
122     BundleActiveClient::GetInstance().ReportEvent(eventB, DEFAULT_USERID);
123 }
124 
125 /*
126  * @tc.name: DeviceUsageStatisticsTest_QueryBundleEvents_001
127  * @tc.desc: QueryBundleEvents
128  * @tc.type: FUNC
129  * @tc.require: SR000GGTO6 AR000GH6PH
130  */
131 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryBundleEvents_001, Function | MediumTest | Level0)
132 {
133     std::vector<BundleActiveEvent> result;
134     BundleActiveClient::GetInstance().QueryBundleEvents(result, 0, LARGE_NUM, 100);
135     EXPECT_EQ(result.size() > 0, true);
136     EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleEvents(result, LARGE_NUM, LARGE_NUM, 100), 0);
137 }
138 
139 /*
140  * @tc.name: DeviceUsageStatisticsTest_QueryCurrentBundleEvents_001
141  * @tc.desc: QueryCurrentBundleEvents
142  * @tc.type: FUNC
143  * @tc.require: SR000GGTO4 AR000GH6PF
144  */
145 HWTEST_F(DeviceUsageStatisticsTest,
146     DeviceUsageStatisticsTest_QueryCurrentBundleEvents_001, Function | MediumTest | Level0)
147 {
148     std::vector<BundleActiveEvent> result;
149     BundleActiveClient::GetInstance().QueryCurrentBundleEvents(result, 0, LARGE_NUM);
150     EXPECT_EQ(result.size(), 0);
151 }
152 
153 /*
154  * @tc.name: DeviceUsageStatisticsTest_QueryPackagesStats_001
155  * @tc.desc: querypackagestats
156  * @tc.type: FUNC
157  * @tc.require: SR000GGTO3 AR000GH6PD
158  */
159 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackagesStats_001, Function | MediumTest | Level0)
160 {
161     std::vector<BundleActivePackageStats> result;
162     BundleActiveClient::GetInstance().QueryBundleStatsInfoByInterval(result, 4, 0, LARGE_NUM);
163     EXPECT_EQ(result.size(), 0);
164     EXPECT_NE(BundleActiveClient::GetInstance().QueryBundleStatsInfoByInterval(result, 4, LARGE_NUM, LARGE_NUM), 0);
165 }
166 
167 /*
168  * @tc.name: DeviceUsageStatisticsTest_QueryBundleStatsInfos_001
169  * @tc.desc: QueryBundleStatsInfos
170  * @tc.type: FUNC
171  * @tc.require: issuesI5QJD9
172  */
173 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryBundleStatsInfos_001,
174     Function | MediumTest | Level0)
175 {
176     std::vector<BundleActivePackageStats> result;
177     BundleActiveClient::GetInstance().QueryBundleStatsInfos(result, 4, 0, LARGE_NUM);
178     EXPECT_EQ(result.size(), 0);
179 }
180 
181 /*
182  * @tc.name: DeviceUsageStatisticsTest_IsBundleIdle_001
183  * @tc.desc: isbundleidle
184  * @tc.type: FUNC
185  * @tc.require: SR000GGTO5 AR000GH6PG
186  */
187 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_IsBundleIdle_001, Function | MediumTest | Level0)
188 {
189     bool result = false;
190     int32_t errCode = BundleActiveClient::GetInstance().IsBundleIdle(result, g_defaultBundleName, DEFAULT_USERID);
191     EXPECT_EQ(result, false);
192     EXPECT_EQ(errCode, 0);
193 }
194 
195 /*
196  * @tc.name: DeviceUsageStatisticsTest_QueryModuleUsageRecords_001
197  * @tc.desc: QueryModuleUsageRecords
198  * @tc.type: FUNC
199  * @tc.require: SR000GU2T1 AR000GU37U
200  */
201 HWTEST_F(DeviceUsageStatisticsTest,
202     DeviceUsageStatisticsTest_QueryModuleUsageRecords_001, Function | MediumTest | Level0)
203 {
204     int32_t maxNum = 1;
205     BundleActiveEvent eventA(g_defaultBundleName, g_defaultMoudleName, g_defaultFormName,
206         DEFAULT_DIMENSION, DEFAULT_FORMID, BundleActiveEvent::FORM_IS_CLICKED);
207     BundleActiveClient::GetInstance().ReportEvent(eventA, DEFAULT_USERID);
208     std::vector<BundleActiveModuleRecord> results;
209     int32_t errCode = BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, results, DEFAULT_USERID);
210     EXPECT_EQ(errCode, 0);
211     EXPECT_EQ(results.size(), 0);
212 
213     results.clear();
214     maxNum = 0;
215     errCode = BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, results, DEFAULT_USERID);
216     EXPECT_NE(errCode, 0);
217 
218     results.clear();
219     maxNum = 1001;
220     errCode = BundleActiveClient::GetInstance().QueryModuleUsageRecords(maxNum, results, DEFAULT_USERID);
221     EXPECT_NE(errCode, 0);
222 }
223 
224 /*
225  * @tc.name: DeviceUsageStatisticsTest_RegisterAppGroupCallBack_001
226  * @tc.desc: RegisterAppGroupCallBack
227  * @tc.type: FUNC
228  * @tc.require: SR000H0HAQ AR000H0ROE
229  */
230 HWTEST_F(DeviceUsageStatisticsTest,
231     DeviceUsageStatisticsTest_RegisterAppGroupCallBack_001, Function | MediumTest | Level0)
232 {
233     if (!observer) {
234         BUNDLE_ACTIVE_LOGI("RegisterAppGroupCallBack construct observer!");
235         observer = new (std::nothrow) TestAppGroupChangeCallback();
236     }
237     ASSERT_NE(observer, nullptr);
238     int32_t result = BundleActiveClient::GetInstance().RegisterAppGroupCallBack(observer);
239     EXPECT_EQ(result, DEFAULT_ERRCODE);
240 }
241 
242 /*
243  * @tc.name: DeviceUsageStatisticsTest_SetBundleGroup_001
244  * @tc.desc: setbundlename
245  * @tc.type: FUNC
246  * @tc.require: SR000H0HAQ AR000H0ROE
247  */
248 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_SetAppGroup_001, Function | MediumTest | Level0)
249 {
250     int32_t result = 0;
251     BundleActiveClient::GetInstance().QueryAppGroup(result, g_defaultBundleName, COMMON_USERID);
252     DEFAULT_GROUP = (result == DEFAULT_GROUP) ? (result + 10) : DEFAULT_GROUP;
253     result = BundleActiveClient::GetInstance().SetAppGroup(g_defaultBundleName, DEFAULT_GROUP, COMMON_USERID);
254     EXPECT_EQ(result, DEFAULT_ERRCODE);
255 
256     result = BundleActiveClient::GetInstance().SetAppGroup(g_defaultBundleName, DEFAULT_GROUP, -1);
257     EXPECT_NE(result, DEFAULT_ERRCODE);
258 }
259 
260 /*
261  * @tc.name: DeviceUsageStatisticsTest_QueryAppGroup_001
262  * @tc.desc: QueryAppGroup, no bundleName
263  * @tc.type: FUNC
264  * @tc.require: SR000H0HAQ AR000H0ROE
265  */
266 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryAppGroup_001, Function | MediumTest | Level0)
267 {
268     BundleActiveClient::GetInstance().SetAppGroup(g_defaultBundleName, DEFAULT_GROUP, COMMON_USERID);
269     int32_t result = 0;
270     BundleActiveClient::GetInstance().QueryAppGroup(result, g_defaultBundleName, COMMON_USERID);
271     bool flag = false;
272     for (auto item = GROUP_TYPE.begin(); item != GROUP_TYPE.end(); item++) {
273         if (*item == result) {
274             flag = true;
275             break;
276         }
277     }
278     EXPECT_EQ(flag, true);
279 }
280 
281 /*
282  * @tc.name: DeviceUsageStatisticsTest_UnRegisterAppGroupCallBack_001
283  * @tc.desc: UnRegisterAppGroupCallBack
284  * @tc.type: FUNC
285  * @tc.require: SR000H0HAQ AR000H0ROE
286  */
287 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_UnRegisterAppGroupCallBack_001,
288     Function | MediumTest | Level0)
289 {
290     if (!observer) {
291         BUNDLE_ACTIVE_LOGI("observer has been delete");
292     }
293     ASSERT_NE(observer, nullptr);
294     int32_t result = BundleActiveClient::GetInstance().UnRegisterAppGroupCallBack(observer);
295     observer = nullptr;
296     EXPECT_EQ(result, DEFAULT_ERRCODE);
297 }
298 
299 /*
300  * @tc.name: DeviceUsageStatisticsTest_QueryDeviceEventStats_001
301  * @tc.desc: QueryDeviceEventStats
302  * @tc.type: FUNC
303  * @tc.require: SR000H0H9H AR000H0ROG
304  */
305 HWTEST_F(DeviceUsageStatisticsTest,
306     DeviceUsageStatisticsTest_QueryDeviceEventStats_001, Function | MediumTest | Level0)
307 {
308     std::vector<BundleActiveEventStats> eventStats;
309     int32_t errCode = BundleActiveClient::GetInstance().QueryDeviceEventStats(0, LARGE_NUM, eventStats);
310     EXPECT_EQ(errCode, 0);
311     errCode = BundleActiveClient::GetInstance().QueryDeviceEventStats(0, LARGE_NUM, eventStats, COMMON_USERID);
312     EXPECT_EQ(errCode, 0);
313 }
314 
315 /*
316  * @tc.name: DeviceUsageStatisticsTest_QueryNotificationEventStats_001
317  * @tc.desc: QueryNotificationEventStats
318  * @tc.type: FUNC
319  * @tc.require: SR000H0H7D AR000H0RR6
320  */
321 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryNotificationEventStats_001, Function
322     | MediumTest | Level0)
323 {
324     std::vector<BundleActiveEventStats> eventStats;
325     int32_t errCode = BundleActiveClient::GetInstance().QueryNotificationEventStats(0, LARGE_NUM, eventStats);
326     EXPECT_EQ(errCode, 0);
327     errCode = BundleActiveClient::GetInstance().QueryNotificationEventStats(0, LARGE_NUM, eventStats, COMMON_USERID);
328     EXPECT_EQ(errCode, 0);
329 }
330 
331 /*
332  * @tc.name: DeviceUsageStatisticsTest_BundleActiveGroupMap_001
333  * @tc.desc: BundleActiveGroupMap
334  * @tc.type: FUNC
335  * @tc.require: SR000H0G4F AR000H2US8
336  */
337 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveGroupMap_001, Function | MediumTest | Level0)
338 {
339     int64_t minInterval = DeviceUsageStatsGroupMap::groupIntervalMap_
340         .at(DeviceUsageStatsGroupConst::ACTIVE_GROUP_FORCED_SET);
341     EXPECT_EQ(minInterval, 0);
342     minInterval = DeviceUsageStatsGroupMap::groupIntervalMap_
343         .at(DeviceUsageStatsGroupConst::ACTIVE_GROUP_ALIVE);
344     EXPECT_EQ(minInterval, DeviceUsageStatsGroupConst::TWO_HOUR);
345     minInterval = DeviceUsageStatsGroupMap::groupIntervalMap_
346         .at(DeviceUsageStatsGroupConst::ACTIVE_GROUP_DAILY);
347     EXPECT_EQ(minInterval, 2 * DeviceUsageStatsGroupConst::TWO_HOUR);
348     minInterval = DeviceUsageStatsGroupMap::groupIntervalMap_
349         .at(DeviceUsageStatsGroupConst::ACTIVE_GROUP_FIXED);
350     EXPECT_EQ(minInterval, DeviceUsageStatsGroupConst::TWENTY_FOUR_HOUR);
351     minInterval = DeviceUsageStatsGroupMap::groupIntervalMap_
352         .at(DeviceUsageStatsGroupConst::ACTIVE_GROUP_RARE);
353     EXPECT_EQ(minInterval, DeviceUsageStatsGroupConst::FOURTY_EIGHT_HOUR);
354 }
355 
356 /*
357  * @tc.name: DeviceUsageStatisticsTest_DeathRecipient_001
358  * @tc.desc: DeathRecipient_001
359  * @tc.type: FUNC
360  * @tc.require: issuesI5SOZY
361  */
362 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_DeathRecipient_001, Function | MediumTest | Level0)
363 {
364     auto deathTest = std::make_shared<BundleActiveClient::BundleActiveClientDeathRecipient>();
365     deathTest->AddObserver(observer);
366     deathTest->RemoveObserver();
367     deathTest->OnServiceDiedInner();
368 
369     deathTest->observer_ = new (std::nothrow) TestAppGroupChangeCallback();
370     deathTest->OnServiceDiedInner();
371     EXPECT_TRUE(deathTest != nullptr);
372     deathTest->OnRemoteDied(nullptr);
373 }
374 
375 /*
376  * @tc.name: DeviceUsageStatisticsTest_AppGroupCallbackInfo_001
377  * @tc.desc: AppGroupCallbackInfo_001
378  * @tc.type: FUNC
379  * @tc.require: issuesI5SOZY
380  */
381 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_AppGroupCallbackInfo_001, Function | MediumTest | Level0)
382 {
383     int32_t oldGroup = 60;
384     int32_t newGroup = 10;
385     uint32_t changeReason = 1;
386     auto appGroupCallbackInfo =
387         std::make_shared<AppGroupCallbackInfo>(COMMON_USERID, oldGroup, newGroup, changeReason, g_defaultBundleName);
388 
389     MessageParcel data;
390     EXPECT_TRUE(appGroupCallbackInfo->Marshalling(data));
391     auto appGroupCallback = appGroupCallbackInfo->Unmarshalling(data);
392     EXPECT_TRUE(appGroupCallback != nullptr);
393 
394     EXPECT_EQ(appGroupCallback->GetUserId(), COMMON_USERID);
395     EXPECT_EQ(appGroupCallback->GetOldGroup(), oldGroup);
396     EXPECT_EQ(appGroupCallback->GetNewGroup(), newGroup);
397     EXPECT_EQ(appGroupCallback->GetChangeReason(), changeReason);
398     EXPECT_EQ(appGroupCallback->GetBundleName(), g_defaultBundleName);
399     delete appGroupCallback;
400 }
401 
402 /*
403  * @tc.name: DeviceUsageStatisticsTest_BundleActiveEventStat_001
404  * @tc.desc: BundleActiveEventStats_001
405  * @tc.type: FUNC
406  * @tc.require: issuesI5SOZY
407  */
408 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveEventStat_001, Function | MediumTest | Level0)
409 {
410     auto bundleActiveEventStats = std::make_shared<BundleActiveEventStats>();
411     bundleActiveEventStats->eventId_ = COMMON_USERID;
412     bundleActiveEventStats->beginTimeStamp_ = 0;
413     bundleActiveEventStats->endTimeStamp_ = LARGE_NUM;
414     bundleActiveEventStats->lastEventTime_ = LARGE_NUM;
415     bundleActiveEventStats->totalTime_ = LARGE_NUM;
416     bundleActiveEventStats->count_ = 1;
417 
418     MessageParcel data;
419     EXPECT_TRUE(bundleActiveEventStats->Marshalling(data));
420     auto tempEventStats = bundleActiveEventStats->UnMarshalling(data);
421     EXPECT_TRUE(tempEventStats != nullptr);
422 
423     auto bundleActiveEvent = std::make_shared<BundleActiveEvent>();
424     EXPECT_TRUE(bundleActiveEvent->Marshalling(data));
425     auto tempEvent = bundleActiveEvent->UnMarshalling(data);
426     EXPECT_TRUE(tempEvent != nullptr);
427 
428     EXPECT_EQ(tempEventStats->GetEventId(), COMMON_USERID);
429     EXPECT_EQ(tempEventStats->GetFirstTimeStamp(), 0);
430     EXPECT_EQ(tempEventStats->GetLastTimeStamp(), LARGE_NUM);
431     EXPECT_EQ(tempEventStats->GetLastEventTime(), LARGE_NUM);
432     EXPECT_EQ(tempEventStats->GetTotalTime(), LARGE_NUM);
433     EXPECT_EQ(tempEventStats->GetCount(), 1);
434 }
435 
436 /*
437  * @tc.name: DeviceUsageStatisticsTest_FormRecord_001
438  * @tc.desc: BundleActiveFormRecord_001
439  * @tc.type: FUNC
440  * @tc.require: issuesI5SOZY
441  */
442 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_FormRecord_001, Function | MediumTest | Level0)
443 {
444     auto bundleActiveFormRecord = std::make_shared<BundleActiveFormRecord>();
445     EXPECT_NE(bundleActiveFormRecord->ToString(), " ");
446 
447     MessageParcel data;
448     EXPECT_TRUE(bundleActiveFormRecord->Marshalling(data));
449     EXPECT_TRUE(bundleActiveFormRecord->UnMarshalling(data) != nullptr);
450 
451     BundleActiveFormRecord bundleActiveFormRecordA;
452     bundleActiveFormRecordA.count_ = 2;
453     BundleActiveFormRecord bundleActiveFormRecordB;
454     bundleActiveFormRecordB.count_ = 1;
455     EXPECT_TRUE(bundleActiveFormRecord->cmp(bundleActiveFormRecordA, bundleActiveFormRecordB));
456 }
457 
458 /*
459  * @tc.name: DeviceUsageStatisticsTest_BundleActiveEvent_001
460  * @tc.desc: BundleActiveEvent_001
461  * @tc.type: FUNC
462  * @tc.require: issuesI5SOZY
463  */
464 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_BundleActiveEvent_001, Function | MediumTest | Level0)
465 {
466     BundleActiveEvent bundleActiveEvent;
467     BundleActiveEvent bundleActiveEventA;
468     EXPECT_NE(bundleActiveEvent.ToString(), " ");
469     bundleActiveEvent = bundleActiveEventA;
470 }
471 
472 /*
473  * @tc.name: DeviceUsageStatisticsTest_PackageStats_001
474  * @tc.desc: BundleActivePackageStats_001
475  * @tc.type: FUNC
476  * @tc.require: issuesI5SOZY
477  */
478 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_PackageStats_001, Function | MediumTest | Level0)
479 {
480     auto bundleActivePackageStats = std::make_shared<BundleActivePackageStats>();
481     bundleActivePackageStats->IncrementBundleLaunchedCount();
482     EXPECT_NE(bundleActivePackageStats->ToString(), " ");
483 
484     MessageParcel data;
485     EXPECT_TRUE(bundleActivePackageStats->Marshalling(data));
486     EXPECT_TRUE(bundleActivePackageStats->UnMarshalling(data) != nullptr);
487 }
488 
489 /*
490  * @tc.name: DeviceUsageStatisticsTest_ModuleRecord_001
491  * @tc.desc: BundleActiveModuleRecord_001
492  * @tc.type: FUNC
493  * @tc.require: issuesI5SOZY
494  */
495 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_ModuleRecord_001, Function | MediumTest | Level0)
496 {
497     auto bundleActiveModuleRecord = std::make_shared<BundleActiveModuleRecord>();
498     EXPECT_NE(bundleActiveModuleRecord->ToString(), " ");
499 
500     MessageParcel data;
501     EXPECT_TRUE(bundleActiveModuleRecord->Marshalling(data));
502     EXPECT_TRUE(bundleActiveModuleRecord->UnMarshalling(data) != nullptr);
503 
504     BundleActiveModuleRecord bundleActiveModuleRecordA;
505     bundleActiveModuleRecordA.lastModuleUsedTime_ = 2;
506     BundleActiveModuleRecord bundleActiveModuleRecordB;
507     bundleActiveModuleRecordB.lastModuleUsedTime_ = 1;
508     EXPECT_TRUE(bundleActiveModuleRecord->cmp(bundleActiveModuleRecordA, bundleActiveModuleRecordB));
509 }
510 
511 /*
512  * @tc.name: DeviceUsageStatisticsTest_AppGroupCallbackProxy_001
513  * @tc.desc: AppGroupCallbackProxy_001
514  * @tc.type: FUNC
515  * @tc.require: issuesI5SOZY
516  */
517 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_AppGroupCallbackProxy_001, Function | MediumTest | Level0)
518 {
519     int32_t oldGroup = 60;
520     int32_t newGroup = 10;
521     uint32_t changeReason = 1;
522     AppGroupCallbackInfo appGroupCallbackInfo(COMMON_USERID, oldGroup, newGroup, changeReason, g_defaultBundleName);
523 
524     auto appGroupCallbackProxy = std::make_shared<BundleActiveGroupCallbackProxy>(nullptr);
525     appGroupCallbackProxy->OnAppGroupChanged(appGroupCallbackInfo);
526     EXPECT_NE(appGroupCallbackProxy, nullptr);
527 }
528 
529 /*
530  * @tc.name: DeviceUsageStatisticsTest_AppGroupCallbackStub_001
531  * @tc.desc: AppGroupCallbackStub_001
532  * @tc.type: FUNC
533  * @tc.require: issuesI5SOZY
534  */
535 HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_AppGroupCallbackStub_001, Function | MediumTest | Level0)
536 {
537     int32_t oldGroup = 60;
538     int32_t newGroup = 10;
539     uint32_t changeReason = 1;
540     AppGroupCallbackInfo appGroupCallbackInfo(COMMON_USERID, oldGroup, newGroup, changeReason, g_defaultBundleName);
541 
542     auto appGroupCallbackStub = std::make_shared<AppGroupCallbackStub>();
543     appGroupCallbackStub->OnAppGroupChanged(appGroupCallbackInfo);
544     MessageParcel data1;
545     MessageParcel reply;
546     MessageOption option;
547     EXPECT_EQ(appGroupCallbackStub->OnRemoteRequest(1, data1, reply, option), -1);
548 }
549 }  // namespace DeviceUsageStats
550 }  // namespace OHOS
551 
552