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