1/* 2 * Copyright (C) 2024 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 16import usb from '@ohos.usbManager' 17import deviceManager from '@ohos.driver.deviceManager' 18import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' 19 20describe("SystemApiJsTest", function () { 21 const TAG = "[SystemApiJsTest]"; 22 const SYSTEMAPI_DENIED_CODE = 202; 23 const TEST_DEVICE_ID = 0; 24 const TEST_DRIVER_UID = 'testDriverUid' 25 const TEST_FUNCTION = () => { 26 console.info("Test function is called"); 27 }; 28 29 let deviceNum = 0; 30 const isDeviceConnected = done => { 31 if (deviceNum > 0) { 32 console.info("Test USB device is connected"); 33 return true; 34 } 35 console.info("Test USB device is not connected"); 36 expect(true).assertTrue(); 37 if (typeof(done) === 'function') { 38 done(); 39 } 40 return false; 41 } 42 43 beforeAll(function () { 44 console.info('beforeAll called'); 45 try { 46 const devicesList = usb.getDevices(); 47 if (Array.isArray(devicesList)) { 48 deviceNum = devicesList.length; 49 } 50 } catch (err) { 51 console.error(TAG, `getDevices failed, message is ${err.message}`); 52 } 53 }) 54 55 afterAll(function () { 56 console.info('AfterAll called'); 57 }) 58 59 /* 60 * @tc.name:SystemApi_queryDeviceInfo_001 61 * @tc.desc:verify SystemApi of queryDeviceInfo 62 * @tc.type: FUNC 63 */ 64 it("SystemApi_queryDeviceInfo_001", 0, done => { 65 console.info('----------------------SystemApi_queryDeviceInfo_001---------------------------'); 66 if (!isDeviceConnected(done)) { 67 return; 68 } 69 try { 70 deviceManager.queryDeviceInfo(TEST_DEVICE_ID); 71 expect(false).assertTrue(); 72 done(); 73 } catch (err) { 74 expect(err.code).assertEqual(SYSTEMAPI_DENIED_CODE); 75 done(); 76 } 77 }); 78 79 /* 80 * @tc.name:SystemApi_queryDriverInfo_001 81 * @tc.desc:verify SystemApi of queryDriverInfo 82 * @tc.type: FUNC 83 */ 84 it("SystemApi_queryDriverInfo_001", 0, done => { 85 console.info('----------------------SystemApi_queryDriverInfo_001---------------------------'); 86 if (!isDeviceConnected(done)) { 87 return; 88 } 89 try { 90 deviceManager.queryDriverInfo(TEST_DRIVER_UID); 91 expect(false).assertTrue(); 92 done(); 93 } catch (err) { 94 expect(err.code).assertEqual(SYSTEMAPI_DENIED_CODE); 95 done(); 96 } 97 }); 98});