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