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, TestSize.Level1) {
90 SetUp();
91 int32_t scanVersion = DEFAULT_NUMBER;
92 int32_t status = E_SCAN_NONE;
93 status = InitScan(scanVersion);
94 EXPECT_EQ(status, E_SCAN_NONE)
95 EXPECT_NE(scanVersion, DEFAULT_NUMBER);
96 }
97
98 /**
99 * @tc.name: ScanServiceAbilityTest_0002
100 * @tc.desc: Verify the sub function.
101 * @tc.type: FUNC
102 * @tc.require: Issue Number
103 */
104 HWTEST_F(ScanServiceAbilityTest, integer_sub_002, TestSize.Level1) {
105 SetUp();
106 int32_t status = E_SCAN_NONE;
107 status = ExitScan();
108 EXPECT_EQ(status, E_SCAN_NONE)
109 }
110
111 /**
112 * @tc.name: ScanServiceAbilityTest_0003
113 * @tc.desc: Verify the sub function.
114 * @tc.type: FUNC
115 * @tc.require: Issue Number
116 */
117 HWTEST_F(ScanServiceAbilityTest, integer_sub_004, TestSize.Level1) {
118 SetUp();
119 int32_t status = E_SCAN_NONE;
120 status = GetScannerList();
121 EXPECT_EQ(status, E_SCAN_NONE)
122 }
123
124 /**
125 * @tc.name: ScanServiceAbilityTest_0004
126 * @tc.desc: Verify the sub function.
127 * @tc.type: FUNC
128 * @tc.require: Issue Number
129 */
130 HWTEST_F(ScanServiceAbilityTest, integer_sub_004, TestSize.Level1) {
131 SetUp();
132 int32_t status = E_SCAN_NONE;
133 status = StopDiscover();
134 EXPECT_EQ(status, E_SCAN_NONE)
135 }
136
137 /**
138 * @tc.name: ScanServiceAbilityTest_0005
139 * @tc.desc: Verify the sub function.
140 * @tc.type: FUNC
141 * @tc.require: Issue Number
142 */
143 HWTEST_F(ScanServiceAbilityTest, integer_sub_005, TestSize.Level1) {
144 SetUp();
145 int32_t status = E_SCAN_NONE;
146 status = OpenScanner(scannerId);
147 EXPECT_EQ(status, E_SCAN_NONE)
148 }
149
150 /**
151 * @tc.name: ScanServiceAbilityTest_0006
152 * @tc.desc: Verify the sub function.
153 * @tc.type: FUNC
154 * @tc.require: Issue Number
155 */
156 HWTEST_F(ScanServiceAbilityTest, integer_sub_006, TestSize.Level1) {
157 SetUp();
158 int32_t status = E_SCAN_NONE;
159 status = CloseScanner(scannerId);
160 EXPECT_EQ(status, E_SCAN_NONE)
161 }
162
163 /**
164 * @tc.name: ScanServiceAbilityTest_0007
165 * @tc.desc: Verify the sub function.
166 * @tc.type: FUNC
167 * @tc.require: Issue Number
168 */
169 HWTEST_F(ScanServiceAbilityTest, integer_sub_007, TestSize.Level1) {
170 SetUp();
171 int32_t status = E_SCAN_NONE;
172 status = GetScanOptionDesc(scannerId);
173 EXPECT_EQ(status, E_SCAN_NONE)
174 }
175 --
176 /**
177 * @tc.name: ScanServiceAbilityTest_0008
178 * @tc.desc: Verify the sub function.
179 * @tc.type: FUNC
180 * @tc.require: Issue Number
181 */
182 HWTEST_F(ScanServiceAbilityTest, integer_sub_008, TestSize.Level1) {
183 SetUp();
184 int32_t status = E_SCAN_NONE;
185 status = GetScanOptionDesc(scannerId);
186 EXPECT_EQ(status, E_SCAN_NONE)
187 }
188
189 /**
190 * @tc.name: ScanServiceAbilityTest_0009
191 * @tc.desc: Verify the sub function.
192 * @tc.type: FUNC
193 * @tc.require: Issue Number
194 */
195 HWTEST_F(ScanServiceAbilityTest, integer_sub_009, TestSize.Level1) {
196 SetUp();
197 int32_t status = E_SCAN_NONE;
198 status = OpScanOptionValue(scannerId);
199 EXPECT_EQ(status, E_SCAN_NONE)
200 }
201
202 /**
203 * @tc.name: ScanServiceAbilityTest_0010
204 * @tc.desc: Verify the sub function.
205 * @tc.type: FUNC
206 * @tc.require: Issue Number
207 */
208 HWTEST_F(ScanServiceAbilityTest, integer_sub_010, TestSize.Level1) {
209 SetUp();
210 int32_t status = E_SCAN_NONE;
211 status = GetScanParameters(scannerId);
212 EXPECT_EQ(status, E_SCAN_NONE)
213 }
214
215 /**
216 * @tc.name: ScanServiceAbilityTest_0011
217 * @tc.desc: Verify the sub function.
218 * @tc.type: FUNC
219 * @tc.require: Issue Number
220 */
221 HWTEST_F(ScanServiceAbilityTest, integer_sub_011, TestSize.Level1) {
222 SetUp();
223 int32_t status = E_SCAN_NONE;
224 status = StartScan(scannerId);
225 EXPECT_EQ(status, E_SCAN_NONE)
226 }
227
228 /**
229 * @tc.name: ScanServiceAbilityTest_0012
230 * @tc.desc: Verify the sub function.
231 * @tc.type: FUNC
232 * @tc.require: Issue Number
233 */
234 HWTEST_F(ScanServiceAbilityTest, integer_sub_012, TestSize.Level1) {
235 SetUp();
236 int32_t status = E_SCAN_NONE;
237 status = GetSingleFrameFD(scannerId);
238 EXPECT_EQ(status, E_SCAN_NONE)
239 }
240
241 /**
242 * @tc.name: ScanServiceAbilityTest_0013
243 * @tc.desc: Verify the sub function.
244 * @tc.type: FUNC
245 * @tc.require: Issue Number
246 */
247 HWTEST_F(ScanServiceAbilityTest, integer_sub_013, TestSize.Level1) {
248 SetUp();
249 int32_t status = E_SCAN_NONE;
250 status = CancelScan(scannerId);
251 EXPECT_EQ(status, E_SCAN_NONE)
252 }
253
254 /**
255 * @tc.name: ScanServiceAbilityTest_0014
256 * @tc.desc: Verify the sub function.
257 * @tc.type: FUNC
258 * @tc.require: Issue Number
259 */
260 HWTEST_F(ScanServiceAbilityTest, integer_sub_014, TestSize.Level1) {
261 SetUp();
262 int32_t status = E_SCAN_NONE;
263 status = SetScanIOMode(scannerId);
264 EXPECT_EQ(status, E_SCAN_NONE)
265 }
266
267 /**
268 * @tc.name: ScanServiceAbilityTest_0015
269 * @tc.desc: Verify the sub function.
270 * @tc.type: FUNC
271 * @tc.require: Issue Number
272 */
273 HWTEST_F(ScanServiceAbilityTest, integer_sub_015, TestSize.Level1) {
274 SetUp();
275 int32_t status = E_SCAN_NONE;
276 status = GetScanSelectFd(scannerId);
277 EXPECT_EQ(status, E_SCAN_NONE)
278 }
279
280 /**
281 * @tc.name: ScanServiceAbilityTest_0016
282 * @tc.desc: Verify the sub function.
283 * @tc.type: FUNC
284 * @tc.require: Issue Number
285 */
286 HWTEST_F(ScanServiceAbilityTest, integer_sub_016, TestSize.Level1) {
287 SetUp();
288 int32_t status = E_SCAN_NONE;
289 status = On(scannerId);
290 EXPECT_EQ(status, E_SCAN_NONE)
291 }
292
293 /**
294 * @tc.name: ScanServiceAbilityTest_0017
295 * @tc.desc: Verify the sub function.
296 * @tc.type: FUNC
297 * @tc.require: Issue Number
298 */
299 HWTEST_F(ScanServiceAbilityTest, integer_sub_017, TestSize.Level1) {
300 SetUp();
301 int32_t status = E_SCAN_NONE;
302 status = Off(scannerId);
303 EXPECT_EQ(status, E_SCAN_NONE)
304 }
305
306 /**
307 * @tc.name: ScanServiceAbilityTest_0018
308 * @tc.desc: Verify the sub function.
309 * @tc.type: FUNC
310 * @tc.require: Issue Number
311 */
312
313 HWTEST_F(ScanServiceAbilityTest, integer_sub_018, TestSize.Level1) {
314 SetUp();
315 int32_t status = E_SCAN_NONE;
316 status = GetScannerState(scannerId);
317 EXPECT_EQ(status, E_SCAN_NONE)
318 }
319
320 /**
321 * @tc.name: ScanServiceAbilityTest_0019
322 * @tc.desc: Verify the sub function.
323 * @tc.type: FUNC
324 * @tc.require: Issue Number
325 */
326 HWTEST_F(ScanServiceAbilityTest, integer_sub_019, TestSize.Level1) {
327 SetUp();
328 int32_t status = E_SCAN_NONE;
329 status = GetScanProgress(scannerId);
330 EXPECT_EQ(status, E_SCAN_NONE)
331 }
332
333 /**
334 * @tc.name: ScanServiceAbilityTest_0020
335 * @tc.desc: Verify the sub function.
336 * @tc.type: FUNC
337 * @tc.require: Issue Number
338 */
339 HWTEST_F(ScanServiceAbilityTest, integer_sub_020, TestSize.Level1) {
340 SetUp();
341 int32_t status = E_SCAN_NONE;
342 status = OnStartScan(scannerId);
343 EXPECT_EQ(status, E_SCAN_NONE)
344 }
345
346 /**
347 * @tc.name: ScanServiceAbilityTest_0021
348 * @tc.desc: Verify the sub function.
349 * @tc.type: FUNC
350 * @tc.require: Issue Number
351 */
352 HWTEST_F(ScanServiceAbilityTest, integer_sub_021, TestSize.Level1) {
353 SetUp();
354 int32_t status = E_SCAN_NONE;
355 StartScanTask(scannerId);
356 status = GetScanProgress(scannerId);
357 EXPECT_EQ(status, E_SCAN_NONE)
358 }
359
360 /**
361 * @tc.name: ScanServiceAbilityTest_0022
362 * @tc.desc: Verify the sub function.
363 * @tc.type: FUNC
364 * @tc.require: Issue Number
365 */
366 HWTEST_F(ScanServiceAbilityTest, integer_sub_022, TestSize.Level1) {
367 SetUp();
368 int32_t status = E_SCAN_NONE;
369 int32_t scanVersion = 0;
370 status= scanSa->InitScan(scanVersion);
371 EXPECT_EQ(scanSa->appCount_, 0);
372 }
373
374 /**
375 * @tc.name: ScanServiceAbilityTest_0023
376 * @tc.desc: Verify the sub function.
377 * @tc.type: FUNC
378 * @tc.require: Issue Number
379 */
380 HWTEST_F(ScanServiceAbilityTest, integer_sub_023, TestSize.Level1) {
381 SetUp();
382 int32_t status = E_SCAN_NONE;
383 status= scanSa->ExitScan();
384 EXPECT_EQ(scanSa->appCount_, 0);
385 }
386
387 /**
388 * @tc.name: ScanServiceAbilityTest_0024
389 * @tc.desc: Verify the sub function.
390 * @tc.type: FUNC
391 * @tc.require: Issue Number
392 */
393 HWTEST_F(ScanServiceAbilityTest, integer_sub_023, TestSize.Level1) {
394 SetUp();
395 int32_t status = E_SCAN_NONE;
396 scanSa->UnloadSystemAbility();
397 EXPECT_EQ(scanSa, nullptr);
398 }
399
400 /**
401 * @tc.name: ScanServiceAbilityTest_0025
402 * @tc.desc: Verify the sub function.
403 * @tc.type: FUNC
404 * @tc.require: Issue Number
405 */
406 HWTEST_F(ScanServiceAbilityTest, integer_sub_025, TestSize.Level1) {
407 SetUp();
408 int32_t status = E_SCAN_NONE;
409 status = scanSa->OnStartScan(scannerId);
410 EXPECT_TRUE(ScanErrorCode.count(status))
411 }
412
413 /**
414 * @tc.name: ScanServiceAbilityTest_0026
415 * @tc.desc: Verify the sub function.
416 * @tc.type: FUNC
417 * @tc.require: Issue Number
418 */
419 HWTEST_F(ScanServiceAbilityTest, integer_sub_026, TestSize.Level1) {
420 SetUp();
421 int32_t status = E_SCAN_NONE;
422 scanSa->StartScanTask(scannerId);
423 status = scanSa->GetScanProgress(scannerId);
424 EXPECT_TRUE(ScanErrorCode.count(status))
425 }
426
427 /**
428 * @tc.name: ScanServiceAbilityTest_0027
429 * @tc.desc: Verify the sub function.
430 * @tc.type: FUNC
431 * @tc.require: Issue Number
432 */
433 HWTEST_F(ScanServiceAbilityTest, integer_sub_027, TestSize.Level1) {
434 SetUp();
435 int32_t status = E_SCAN_NONE;
436 scanSa->StartScanTask(scannerId);
437 status = scanSa->GetScanProgress(scannerId);
438 EXPECT_TRUE(ScanErrorCode.count(status))
439 }
440
441 /**
442 * @tc.name: ScanServiceAbilityTest_0028
443 * @tc.desc: Verify the sub function.
444 * @tc.type: FUNC
445 * @tc.require: Issue Number
446 */
447 HWTEST_F(ScanServiceAbilityTest, integer_sub_028, TestSize.Level1) {
448 SetUp();
449 int32_t status = E_SCAN_NONE;
450 status = scanSa->OnStartScan(scannerId);
451 EXPECT_TRUE(ScanErrorCode.count(status))
452 }
453
454 }
455
456 }
457