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 <gtest/gtest.h>
17 #include "mock_bundle_mgr.h"
18 #include "scan_service_ability.h"
19 #include "scan_constant.h"
20 #include "system_ability_definition.h"
21 #include "scan_utils.h"
22 #include "mock_scan_callback_proxy.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27
28 namespace OHOS {
29 namespace Scan {
30 class ScanServiceAbilityTest : public testing::Test {
31 public:
ScanServiceAbilityTest()32 ScanServiceAbilityTest() : deathRecipient(nullptr), obj(nullptr), scanSa(nullptr), testNo(0), scannerId(nullptr) {}
33
34 static void SetUpTestCase(void);
35 static void TearDownTestCase(void);
36 void SetUp();
37 void TearDown();
38
39 private:
40
41 constexpr int32_t DEFAULT_NUMBER = 0;
42
43 sptr<IRemoteObject::DeathRecipient> deathRecipient;
44 sptr<MockBundleMgr> obj;
45 sptr<ScanServiceAbility> scanSa;
46 int32_t testNo;
47 std::string scannerId;
48 std::set<ScanErrorCode> allStatus;
49 };
50
SetUpTestCase(void)51 void ScanServiceAbilityTest::SetUpTestCase(void)
52 {
53 SCAN_HILOGD("ScanServiceAbilityTest SetUpTestCase");
54 testNo = 0;
55 }
56
TearDownTestCase(void)57 void ScanServiceAbilityTest::TearDownTestCase(void)
58 {
59 SCAN_HILOGD("ScanServiceAbilityTest TearDownTestCase");
60 }
61
SetUp(void)62 void ScanServiceAbilityTest::SetUp(void)
63 {
64 scanSa = ScanServiceAbility::GetInstance();
65 EXPECT_TRUE(scanSa != nullptr);
66 EXPECT_TRUE(scannerId != nullptr && scannerId != "")
67 allStatus.insert({E_SCAN_NONE, E_SCAN_NO_PERMISSION, E_SCAN_INVALID_PARAMETER,
68 E_SCAN_GENERIC_FAILURE, E_SCAN_SERVER_FAILURE, E_SCAN_GOOD, E_SCAN_UNSUPPORTED,
69 E_SCAN_CANCELLED, E_SCAN_DEVICE_BUSY, E_SCAN_INVAL, E_SCAN_EOF, E_SCAN_JAMMED,
70 E_SCAN_NO_DOCS, E_SCAN_COVER_OPEN, E_SCAN_IO_ERROR, E_SCAN_NO_MEM,
71 E_SCAN_ACCESS_DENIED})
72 SCAN_HILOGD("ScanServiceAbilityTest : %{public}d", ++testNo);
73 }
74
TearDown(void)75 void ScanServiceAbilityTest::TearDown(void) {}
76
SetScannerId(const std::string & scannerId)77 void ScanServiceAbilityTest::SetScannerId(const std::string& scannerId)
78 {
79 EXPECT_TRUE(scannerId != nullptr && scannerId != "")
80 this->scannerId = scannerId;
81 }
82
83 /**
84 * @tc.name: ScanServiceAbilityTest_0001
85 * @tc.desc: Verify the sub function.
86 * @tc.type: FUNC
87 * @tc.require: Issue Number
88 */
89 HWTEST_F(ScanServiceAbilityTest, integer_sub_001_NeedRename, TestSize.Level1) {
90 SetUp();
91 int32_t status = E_SCAN_NONE;
92 status = InitScan();
93 EXPECT_EQ(status, E_SCAN_NONE)
94 }
95
96 /**
97 * @tc.name: ScanServiceAbilityTest_0002
98 * @tc.desc: Verify the sub function.
99 * @tc.type: FUNC
100 * @tc.require: Issue Number
101 */
102 HWTEST_F(ScanServiceAbilityTest, integer_sub_002_NeedRename, TestSize.Level1) {
103 SetUp();
104 int32_t status = E_SCAN_NONE;
105 status = ExitScan();
106 EXPECT_EQ(status, E_SCAN_NONE)
107 }
108
109 /**
110 * @tc.name: ScanServiceAbilityTest_0003
111 * @tc.desc: Verify the sub function.
112 * @tc.type: FUNC
113 * @tc.require: Issue Number
114 */
115 HWTEST_F(ScanServiceAbilityTest, integer_sub_004_NeedRename, TestSize.Level1) {
116 SetUp();
117 int32_t status = E_SCAN_NONE;
118 status = GetScannerList();
119 EXPECT_EQ(status, E_SCAN_NONE)
120 }
121
122 /**
123 * @tc.name: ScanServiceAbilityTest_0005
124 * @tc.desc: Verify the sub function.
125 * @tc.type: FUNC
126 * @tc.require: Issue Number
127 */
128 HWTEST_F(ScanServiceAbilityTest, integer_sub_005_NeedRename, TestSize.Level1) {
129 SetUp();
130 int32_t status = E_SCAN_NONE;
131 status = OpenScanner(scannerId);
132 EXPECT_EQ(status, E_SCAN_NONE)
133 }
134
135 /**
136 * @tc.name: ScanServiceAbilityTest_0006
137 * @tc.desc: Verify the sub function.
138 * @tc.type: FUNC
139 * @tc.require: Issue Number
140 */
141 HWTEST_F(ScanServiceAbilityTest, integer_sub_006_NeedRename, TestSize.Level1) {
142 SetUp();
143 int32_t status = E_SCAN_NONE;
144 status = CloseScanner(scannerId);
145 EXPECT_EQ(status, E_SCAN_NONE)
146 }
147
148 /**
149 * @tc.name: ScanServiceAbilityTest_0007
150 * @tc.desc: Verify the sub function.
151 * @tc.type: FUNC
152 * @tc.require: Issue Number
153 */
154 HWTEST_F(ScanServiceAbilityTest, integer_sub_007_NeedRename, TestSize.Level1) {
155 SetUp();
156 int32_t status = E_SCAN_NONE;
157 status = GetScanOptionDesc(scannerId);
158 EXPECT_EQ(status, E_SCAN_NONE)
159 }
160 --
161 /**
162 * @tc.name: ScanServiceAbilityTest_0008
163 * @tc.desc: Verify the sub function.
164 * @tc.type: FUNC
165 * @tc.require: Issue Number
166 */
167 HWTEST_F(ScanServiceAbilityTest, integer_sub_008_NeedRename, TestSize.Level1) {
168 SetUp();
169 int32_t status = E_SCAN_NONE;
170 status = GetScanOptionDesc(scannerId);
171 EXPECT_EQ(status, E_SCAN_NONE)
172 }
173
174 /**
175 * @tc.name: ScanServiceAbilityTest_0009
176 * @tc.desc: Verify the sub function.
177 * @tc.type: FUNC
178 * @tc.require: Issue Number
179 */
180 HWTEST_F(ScanServiceAbilityTest, integer_sub_009_NeedRename, TestSize.Level1) {
181 SetUp();
182 int32_t status = E_SCAN_NONE;
183 status = OpScanOptionValue(scannerId);
184 EXPECT_EQ(status, E_SCAN_NONE)
185 }
186
187 /**
188 * @tc.name: ScanServiceAbilityTest_0010
189 * @tc.desc: Verify the sub function.
190 * @tc.type: FUNC
191 * @tc.require: Issue Number
192 */
193 HWTEST_F(ScanServiceAbilityTest, integer_sub_010_NeedRename, TestSize.Level1) {
194 SetUp();
195 int32_t status = E_SCAN_NONE;
196 status = GetScanParameters(scannerId);
197 EXPECT_EQ(status, E_SCAN_NONE)
198 }
199
200 /**
201 * @tc.name: ScanServiceAbilityTest_0011
202 * @tc.desc: Verify the sub function.
203 * @tc.type: FUNC
204 * @tc.require: Issue Number
205 */
206 HWTEST_F(ScanServiceAbilityTest, integer_sub_011_NeedRename, TestSize.Level1) {
207 SetUp();
208 int32_t status = E_SCAN_NONE;
209 status = StartScan(scannerId);
210 EXPECT_EQ(status, E_SCAN_NONE)
211 }
212
213 /**
214 * @tc.name: ScanServiceAbilityTest_0013
215 * @tc.desc: Verify the sub function.
216 * @tc.type: FUNC
217 * @tc.require: Issue Number
218 */
219 HWTEST_F(ScanServiceAbilityTest, integer_sub_013_NeedRename, TestSize.Level1) {
220 SetUp();
221 int32_t status = E_SCAN_NONE;
222 status = CancelScan(scannerId);
223 EXPECT_EQ(status, E_SCAN_NONE)
224 }
225
226 /**
227 * @tc.name: ScanServiceAbilityTest_0016
228 * @tc.desc: Verify the sub function.
229 * @tc.type: FUNC
230 * @tc.require: Issue Number
231 */
232 HWTEST_F(ScanServiceAbilityTest, integer_sub_016_NeedRename, TestSize.Level1) {
233 SetUp();
234 int32_t status = E_SCAN_NONE;
235 status = On(scannerId);
236 EXPECT_EQ(status, E_SCAN_NONE)
237 }
238
239 /**
240 * @tc.name: ScanServiceAbilityTest_0017
241 * @tc.desc: Verify the sub function.
242 * @tc.type: FUNC
243 * @tc.require: Issue Number
244 */
245 HWTEST_F(ScanServiceAbilityTest, integer_sub_017_NeedRename, TestSize.Level1) {
246 SetUp();
247 int32_t status = E_SCAN_NONE;
248 status = Off(scannerId);
249 EXPECT_EQ(status, E_SCAN_NONE)
250 }
251
252 /**
253 * @tc.name: ScanServiceAbilityTest_0019
254 * @tc.desc: Verify the sub function.
255 * @tc.type: FUNC
256 * @tc.require: Issue Number
257 */
258 HWTEST_F(ScanServiceAbilityTest, integer_sub_019_NeedRename, TestSize.Level1) {
259 SetUp();
260 int32_t status = E_SCAN_NONE;
261 status = GetScanProgress(scannerId);
262 EXPECT_EQ(status, E_SCAN_NONE)
263 }
264
265 /**
266 * @tc.name: ScanServiceAbilityTest_0020
267 * @tc.desc: Verify the sub function.
268 * @tc.type: FUNC
269 * @tc.require: Issue Number
270 */
271 HWTEST_F(ScanServiceAbilityTest, integer_sub_020_NeedRename, TestSize.Level1) {
272 SetUp();
273 int32_t status = E_SCAN_NONE;
274 status = OnStartScan(scannerId);
275 EXPECT_EQ(status, E_SCAN_NONE)
276 }
277
278 /**
279 * @tc.name: ScanServiceAbilityTest_0021
280 * @tc.desc: Verify the sub function.
281 * @tc.type: FUNC
282 * @tc.require: Issue Number
283 */
284 HWTEST_F(ScanServiceAbilityTest, integer_sub_021_NeedRename, TestSize.Level1) {
285 SetUp();
286 int32_t status = E_SCAN_NONE;
287 StartScanTask(scannerId);
288 status = GetScanProgress(scannerId);
289 EXPECT_EQ(status, E_SCAN_NONE)
290 }
291
292 /**
293 * @tc.name: ScanServiceAbilityTest_0022
294 * @tc.desc: Verify the sub function.
295 * @tc.type: FUNC
296 * @tc.require: Issue Number
297 */
298 HWTEST_F(ScanServiceAbilityTest, integer_sub_022_NeedRename, TestSize.Level1) {
299 SetUp();
300 int32_t status = E_SCAN_NONE;
301 status= scanSa->InitScan();
302 EXPECT_EQ(scanSa->appCount_, 0);
303 }
304
305 /**
306 * @tc.name: ScanServiceAbilityTest_0023
307 * @tc.desc: Verify the sub function.
308 * @tc.type: FUNC
309 * @tc.require: Issue Number
310 */
311 HWTEST_F(ScanServiceAbilityTest, integer_sub_023_NeedRename, TestSize.Level1) {
312 SetUp();
313 int32_t status = E_SCAN_NONE;
314 status= scanSa->ExitScan();
315 EXPECT_EQ(scanSa->appCount_, 0);
316 }
317
318 /**
319 * @tc.name: ScanServiceAbilityTest_0024
320 * @tc.desc: Verify the sub function.
321 * @tc.type: FUNC
322 * @tc.require: Issue Number
323 */
324 HWTEST_F(ScanServiceAbilityTest, integer_sub_023_NeedRename, TestSize.Level1) {
325 SetUp();
326 int32_t status = E_SCAN_NONE;
327 scanSa->UnloadSystemAbility();
328 EXPECT_EQ(scanSa, nullptr);
329 }
330
331 /**
332 * @tc.name: ScanServiceAbilityTest_0025
333 * @tc.desc: Verify the sub function.
334 * @tc.type: FUNC
335 * @tc.require: Issue Number
336 */
337 HWTEST_F(ScanServiceAbilityTest, integer_sub_025_NeedRename, TestSize.Level1) {
338 SetUp();
339 int32_t status = E_SCAN_NONE;
340 status = scanSa->OnStartScan(scannerId);
341 EXPECT_TRUE(ScanErrorCode.count(status))
342 }
343
344 /**
345 * @tc.name: ScanServiceAbilityTest_0026
346 * @tc.desc: Verify the sub function.
347 * @tc.type: FUNC
348 * @tc.require: Issue Number
349 */
350 HWTEST_F(ScanServiceAbilityTest, integer_sub_026_NeedRename, TestSize.Level1) {
351 SetUp();
352 int32_t status = E_SCAN_NONE;
353 scanSa->StartScanTask(scannerId);
354 status = scanSa->GetScanProgress(scannerId);
355 EXPECT_TRUE(ScanErrorCode.count(status))
356 }
357
358 /**
359 * @tc.name: ScanServiceAbilityTest_0027
360 * @tc.desc: Verify the sub function.
361 * @tc.type: FUNC
362 * @tc.require: Issue Number
363 */
364 HWTEST_F(ScanServiceAbilityTest, integer_sub_027_NeedRename, TestSize.Level1) {
365 SetUp();
366 int32_t status = E_SCAN_NONE;
367 scanSa->StartScanTask(scannerId);
368 status = scanSa->GetScanProgress(scannerId);
369 EXPECT_TRUE(ScanErrorCode.count(status))
370 }
371
372 /**
373 * @tc.name: ScanServiceAbilityTest_0028
374 * @tc.desc: Verify the sub function.
375 * @tc.type: FUNC
376 * @tc.require: Issue Number
377 */
378 HWTEST_F(ScanServiceAbilityTest, integer_sub_028_NeedRename, TestSize.Level1) {
379 SetUp();
380 int32_t status = E_SCAN_NONE;
381 status = scanSa->OnStartScan(scannerId);
382 EXPECT_TRUE(ScanErrorCode.count(status))
383 }
384
385 }
386
387 }
388