1 /*
2 * Copyright (c) 2023 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 "system_event_wrapper_test.h"
17
18 #include <cstring>
19 #include <gtest/gtest.h>
20
21 #include "system_ability_wrapper.h"
22 #include "system_event_wrapper.h"
23 #include "system_event_wrapper.cpp"
24
25 using namespace testing::ext;
26 namespace UnitTest::AssetSystemEventWrapperTest {
27 class AssetSystemEventWrapperTest : public testing::Test {
28 public:
29 static void SetUpTestCase(void);
30
31 static void TearDownTestCase(void);
32
33 void SetUp(void);
34
35 void TearDown(void);
36 };
37
SetUpTestCase(void)38 void AssetSystemEventWrapperTest::SetUpTestCase(void)
39 {
40 }
41
TearDownTestCase(void)42 void AssetSystemEventWrapperTest::TearDownTestCase(void)
43 {
44 }
45
SetUp(void)46 void AssetSystemEventWrapperTest::SetUp(void)
47 {
48 }
49
TearDown(void)50 void AssetSystemEventWrapperTest::TearDown(void)
51 {
52 }
53
PackageRemovedCallback(PackageInfo)54 void PackageRemovedCallback(PackageInfo)
55 {
56 }
57
OnUserRemovedCallback(int32_t userId)58 void OnUserRemovedCallback(int32_t userId)
59 {
60 }
61
OnScreenOffCallback(void)62 void OnScreenOffCallback(void)
63 {
64 }
65
OnChargingCallback(void)66 void OnChargingCallback(void)
67 {
68 }
69
OnAppRestore(int32_t packageId,const uint8_t * owner,int32_t appIndex)70 void OnAppRestore(int32_t packageId, const uint8_t *owner, int32_t appIndex)
71 {
72 }
73
OnUserUnlocked(int32_t userId)74 void OnUserUnlocked(int32_t userId)
75 {
76 }
77
78 /**
79 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest001
80 * @tc.desc: Test asset func SubscribeSystemEvent, expect true
81 * @tc.type: FUNC
82 * @tc.result:0
83 */
84 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest001, TestSize.Level0)
85 {
86 EventCallBack call_back = {
87 PackageRemovedCallback,
88 OnUserRemovedCallback,
89 OnScreenOffCallback,
90 OnChargingCallback,
91 OnAppRestore,
92 OnUserUnlocked
93 };
94 ASSERT_EQ(true, SubscribeSystemEvent(call_back));
95 }
96
97 /**
98 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest002
99 * @tc.desc: Test asset func UnSubscribeSystemEvent, expect true
100 * @tc.type: FUNC
101 * @tc.result:0
102 */
103 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest002, TestSize.Level0)
104 {
105 ASSERT_EQ(true, UnSubscribeSystemEvent());
106 ASSERT_EQ(false, UnSubscribeSystemEvent());
107 }
108
109 /**
110 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest005
111 * @tc.desc: Test asset func ParseGroupIds, expect true
112 * @tc.type: FUNC
113 * @tc.result:0
114 */
115 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest005, TestSize.Level0)
116 {
117 std::string groupIds = "group1,group2,group3";
118 std::vector<std::string> groupIdStrs;
119 std::vector<ConstAssetBlob> groupIdBlobs;
120 ConstAssetBlobArray groupIdBlobArray;
121
122 ParseGroupIds(groupIds, groupIdStrs, groupIdBlobs, groupIdBlobArray);
123
124 ASSERT_EQ(groupIdStrs.size(), 3);
125 ASSERT_EQ(groupIdStrs[0], "group1");
126 ASSERT_EQ(groupIdStrs[1], "group2");
127 ASSERT_EQ(groupIdStrs[2], "group3");
128 ASSERT_EQ(groupIdBlobArray.size, 3);
129 }
130
131 /**
132 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest006
133 * @tc.desc: Test asset func ParseGroupIds, expect true
134 * @tc.type: FUNC
135 * @tc.result:0
136 */
137 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest006, TestSize.Level0)
138 {
139 std::string groupIds = "";
140 std::vector<std::string> groupIdStrs;
141 std::vector<ConstAssetBlob> groupIdBlobs;
142 ConstAssetBlobArray groupIdBlobArray;
143
144 ParseGroupIds(groupIds, groupIdStrs, groupIdBlobs, groupIdBlobArray);
145
146 ASSERT_EQ(groupIdBlobArray.size, 0);
147 ASSERT_EQ(groupIdBlobArray.blob, nullptr);
148 }
149 }