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.AssetSystemEventWrapperTest003
111 * @tc.desc: Test asset func ParseDeveloperId, expect true
112 * @tc.type: FUNC
113 * @tc.result:0
114 */
115 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest003, TestSize.Level0)
116 {
117 ConstAssetBlob blob;
118 std::string developerId = "test_developer";
119
120 ParseDeveloperId(developerId, blob);
121 ASSERT_EQ(blob.size, developerId.size());
122 }
123
124 /**
125 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest004
126 * @tc.desc: Test asset func ParseDeveloperId, expect true
127 * @tc.type: FUNC
128 * @tc.result:0
129 */
130 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest004, TestSize.Level0)
131 {
132 ConstAssetBlob blob;
133 std::string developerId = "";
134
135 ParseDeveloperId(developerId, blob);
136 ASSERT_EQ(blob.size, 0);
137 ASSERT_EQ(blob.data, nullptr);
138 }
139
140 /**
141 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest005
142 * @tc.desc: Test asset func ParseGroupIds, expect true
143 * @tc.type: FUNC
144 * @tc.result:0
145 */
146 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest005, TestSize.Level0)
147 {
148 std::string groupIds = "group1,group2,group3";
149 std::vector<std::string> groupIdStrs;
150 std::vector<ConstAssetBlob> groupIdBlobs;
151 ConstAssetBlobArray groupIdBlobArray;
152
153 ParseGroupIds(groupIds, groupIdStrs, groupIdBlobs, groupIdBlobArray);
154
155 ASSERT_EQ(groupIdStrs.size(), 3);
156 ASSERT_EQ(groupIdStrs[0], "group1");
157 ASSERT_EQ(groupIdStrs[1], "group2");
158 ASSERT_EQ(groupIdStrs[2], "group3");
159 ASSERT_EQ(groupIdBlobArray.size, 3);
160 }
161
162 /**
163 * @tc.name: AssetSystemEventWrapperTest.AssetSystemEventWrapperTest006
164 * @tc.desc: Test asset func ParseGroupIds, expect true
165 * @tc.type: FUNC
166 * @tc.result:0
167 */
168 HWTEST_F(AssetSystemEventWrapperTest, AssetSystemEventWrapperTest006, TestSize.Level0)
169 {
170 std::string groupIds = "";
171 std::vector<std::string> groupIdStrs;
172 std::vector<ConstAssetBlob> groupIdBlobs;
173 ConstAssetBlobArray groupIdBlobArray;
174
175 ParseGroupIds(groupIds, groupIdStrs, groupIdBlobs, groupIdBlobArray);
176
177 ASSERT_EQ(groupIdBlobArray.size, 0);
178 ASSERT_EQ(groupIdBlobArray.blob, nullptr);
179 }
180 }