• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021 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.usb';
17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
18
19/* usb core functions test */
20describe('UsbFunctionsJsFunctionsTestEx', function () {
21
22  beforeAll(function () {
23    console.log('*************Usb Unit UsbFunctionsJsFunctionsTestEx Begin*************');
24    var Version = usb.getVersion()
25    console.info('begin test getversion :' + Version)
26    //  17 version host currentMode = 2 device currentMode = 1
27    var usbPortList = usb.getPorts()
28    if (usbPortList.length > 0) {
29      if (usbPortList[0].status.currentMode == 2) {
30        usb.setPortRoles(usbPortList[0].id, usb.SINK, usb.DEVICE).then(data => {
31          console.info('usb case setPortRoles return: ' + data);
32        }).catch(error => {
33          console.info('usb case setPortRoles error : ' + error);
34        });
35
36        console.log('*************Usb Unit switch to device Begin*************');
37      }
38    }
39  })
40  beforeEach(function () {
41    console.info('beforeEach: *************Usb Unit Test Case*************');
42  })
43
44  afterEach(function () {
45    console.info('afterEach: *************Usb Unit Test Case*************');
46  })
47
48  afterAll(function () {
49    console.log('*************Usb Unit UsbFunctionsJsFunctionsTest End*************');
50  })
51
52  /**
53   * @tc.number    : SUB_USB_usb_function_to_string_test_01
54   * @tc.name      : usbFunctionsToString
55   * @tc.desc      : 正向测试 0 返回 'none'
56   */
57  it('SUB_USB_usb_function_to_string_test_01', 0, function () {
58    console.info('usb usb_function_to_string_test_01 begin');
59    var maskCode = usb.NONE
60    console.info('usb case maskCode : ' + usb.NONE);
61    var strMaskCode = usb.usbFunctionsToString(maskCode)
62    expect(strMaskCode).assertEqual('none');
63    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
64    console.info('usb usb_function_to_string_test_01 :  PASS');
65  })
66
67  /**
68   * @tc.number    : SUB_USB_usb_function_to_string_test_02
69   * @tc.name      : usbFunctionsToString
70   * @tc.desc      : 正向测试 1 返回 'acm'
71   */
72  it('SUB_USB_usb_function_to_string_test_02', 0, function () {
73    console.info('usb usb_function_to_string_test_02 begin');
74    var maskCode = usb.ACM
75    console.info('usb case maskCode : ' + usb.ACM);
76    var strMaskCode = usb.usbFunctionsToString(maskCode)
77    expect(strMaskCode).assertEqual('acm');
78    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
79    console.info('usb usb_function_to_string_test_02 :  PASS');
80  })
81
82  /**
83   * @tc.number    : SUB_USB_usb_function_to_string_test_03
84   * @tc.name      : usbFunctionsToString
85   * @tc.desc      : 正向测试 2 返回 'ecm'
86   */
87  it('SUB_USB_usb_function_to_string_test_03', 0, function () {
88    console.info('usb usb_function_to_string_test_02 begin');
89    var maskCode = usb.ECM
90    console.info('usb case maskCode : ' + maskCode);
91    var strMaskCode = usb.usbFunctionsToString(maskCode)
92    expect(strMaskCode).assertEqual('ecm');
93    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
94    console.info('usb usb_function_to_string_test_02 :  PASS');
95  })
96
97  /**
98   * @tc.number    : SUB_USB_usb_function_to_string_test_04
99   * @tc.name      : usbFunctionsToString
100   * @tc.desc      : 正向测试 3 返回 'acm,ecm'
101   */
102  it('SUB_USB_usb_function_to_string_test_04', 0, function () {
103    console.info('usb usb_function_to_string_test_02 begin');
104    var maskCode = usb.ACM | usb.ECM
105    console.info('usb case maskCode : ' + maskCode);
106    var strMaskCode = usb.usbFunctionsToString(maskCode)
107    expect(strMaskCode).assertEqual('acm,ecm');
108    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
109    console.info('usb usb_function_to_string_test_02 :  PASS');
110  })
111
112  /**
113   * @tc.number    : SUB_USB_usb_function_to_string_test_05
114   * @tc.name      : usbFunctionsToString
115   * @tc.desc      : 正向测试 4 返回 'hdc'
116   */
117  it('SUB_USB_usb_function_to_string_test_05', 0, function () {
118    console.info('usb usb_function_to_string_test_05 begin');
119    var maskCode = usb.HDC
120    console.info('usb case maskCode : ' + maskCode);
121    var strMaskCode = usb.usbFunctionsToString(maskCode)
122    expect(strMaskCode).assertEqual('hdc');
123    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
124    console.info('usb usb_function_to_string_test_05 :  PASS');
125  })
126
127  /**
128   * @tc.number    : SUB_USB_usb_function_to_string_test_06
129   * @tc.name      : usbFunctionsToString
130   * @tc.desc      : 正向测试 5 返回 'acm,hdc'
131   */
132  it('SUB_USB_usb_function_to_string_test_06', 0, function () {
133    console.info('usb usb_function_to_string_test_06 begin');
134    var maskCode = usb.ACM | usb.HDC
135    console.info('usb case maskCode : ' + maskCode);
136    var strMaskCode = usb.usbFunctionsToString(maskCode)
137    expect(strMaskCode).assertEqual('hdc,acm');
138    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
139    console.info('usb usb_function_to_string_test_06 :  PASS');
140  })
141
142  /**
143   * @tc.number    : SUB_USB_usb_function_to_string_test_07
144   * @tc.name      : usbFunctionsToString
145   * @tc.desc      : 正向测试 6 返回 'ecm,hdc'
146   */
147  it('SUB_USB_usb_function_to_string_test_07', 0, function () {
148    console.info('usb usb_function_to_string_test_07 begin');
149    var maskCode = usb.ECM | usb.HDC
150    console.info('usb case maskCode : ' + maskCode);
151    var strMaskCode = usb.usbFunctionsToString(maskCode)
152    expect(strMaskCode).assertEqual('hdc,ecm');
153    console.info('usb case maskCode ' + maskCode + ' usbFunctionsToString return int: ' + strMaskCode);
154    console.info('usb usb_function_to_string_test_07 :  PASS');
155  })
156
157  /**
158   * @tc.number    : SUB_USB_usb_function_from_string_test_01
159   * @tc.name      : usbFunctionsFromString
160   * @tc.desc      : 正向测试 'none' 返回 0
161   */
162  it('SUB_USB_usb_function_from_string_test_01', 0, function () {
163    console.info('usb usb_function_from_string_test_01 begin');
164    var strMaskCode = 'none'
165    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
166    expect(nMaskCode).assertEqual(usb.NONE);
167    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
168    console.info('usb usb_function_to_string_test_01 :  PASS');
169  })
170
171  /**
172   * @tc.number    : SUB_USB_usb_function_from_string_test_02
173   * @tc.name      : usbFunctionsFromString
174   * @tc.desc      : 正向测试 'acm' 返回 1
175   */
176  it('SUB_USB_usb_function_from_string_test_02', 0, function () {
177    console.info('usb usb_function_from_string_test_02 begin');
178    var strMaskCode = 'acm'
179    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
180    expect(nMaskCode).assertEqual(usb.ACM);
181    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
182    console.info('usb usb_function_from_string_test_02 :  PASS');
183  })
184
185  /**
186   * @tc.number    : SUB_USB_usb_function_from_string_test_03
187   * @tc.name      : usbFunctionsFromString
188   * @tc.desc      : 正向测试 'ecm' 返回 2
189   */
190  it('SUB_USB_usb_function_from_string_test_03', 0, function () {
191    console.info('usb usb_function_from_string_test_03 begin');
192    var strMaskCode = 'ecm'
193    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
194    expect(nMaskCode).assertEqual(usb.ECM);
195    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
196    console.info('usb usb_function_from_string_test_03 :  PASS');
197  })
198
199  /**
200   * @tc.number    : SUB_USB_usb_function_from_string_test_04
201   * @tc.name      : usbFunctionsFromString
202   * @tc.desc      : 正向测试 'acm,ecm' 返回 3
203   */
204  it('SUB_USB_usb_function_from_string_test_04', 0, function () {
205    console.info('usb usb_function_from_string_test_04 begin');
206    var strMaskCode = 'acm,ecm'
207    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
208    expect(nMaskCode).assertEqual(usb.ACM | usb.ECM);
209    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
210    console.info('usb usb_function_from_string_test_04 :  PASS');
211  })
212
213  /**
214   * @tc.number    : SUB_USB_usb_function_from_string_test_05
215   * @tc.name      : usbFunctionsFromString
216   * @tc.desc      : 正向测试 'hdc' 返回 4
217   */
218  it('SUB_USB_usb_function_from_string_test_05', 0, function () {
219    console.info('usb usb_function_from_string_test_05 begin');
220    var strMaskCode = 'hdc'
221    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
222    expect(nMaskCode).assertEqual(usb.HDC);
223    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
224    console.info('usb usb_function_from_string_test_04 :  PASS');
225  })
226
227  /**
228   * @tc.number    : SUB_USB_usb_function_from_string_test_06
229   * @tc.name      : usbFunctionsFromString
230   * @tc.desc      : 正向测试 'acm,hdc' 返回 5
231   */
232  it('SUB_USB_usb_function_from_string_test_06', 0, function () {
233    console.info('usb usb_function_from_string_test_06 begin');
234    var strMaskCode = 'acm,hdc'
235    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
236    expect(nMaskCode).assertEqual(usb.HDC | usb.ACM);
237    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
238    console.info('usb usb_function_from_string_test_06 :  PASS');
239  })
240
241  /**
242   * @tc.number    : SUB_USB_usb_function_from_string_test_07
243   * @tc.name      : usbFunctionsFromString
244   * @tc.desc      : 正向测试 'ecm,hdc' 返回 6
245   */
246  it('SUB_USB_usb_function_from_string_test_07', 0, function () {
247    console.info('usb usb_function_from_string_test_07 begin');
248    var strMaskCode = 'ecm,hdc'
249    var nMaskCode = usb.usbFunctionsFromString(strMaskCode)
250    expect(nMaskCode).assertEqual(usb.HDC | usb.ECM);
251    console.info('usb case strMaskCode ' + strMaskCode + ' usbFunctionsFromString return int: ' + nMaskCode);
252    console.info('usb usb_function_from_string_test_07 :  PASS');
253  })
254
255})
256