• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import tag from '@ohos.nfc.tag';
18import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect, Level} from '@ohos/hypium'
19import cardEmulation from '@ohos.nfc.cardEmulation';
20import controller from '@ohos.nfc.controller';
21
22function sleep(delay) {
23    return new Promise(resovle => setTimeout(resovle, delay))
24}
25
26let isoDepTaginfo = {
27    "uid": [0x01, 0x02, 0x03, 0x04],
28    "technology": [1, 3],
29    "extrasData": [
30        {
31            "Sak": 0x08, "Atqa": "B000",
32        },
33        {
34            "HistoricalBytes": "4D54000500308693695B", "HiLayerResponse": "",
35        },
36    ],
37    "tagRfDiscId": 1,
38};
39
40let CardType = {
41    PAYMENT : "payment",
42    OTHER : "other",
43};
44
45let IsoDepTag ;
46
47export default function nfcIsoDepTagTest() {
48    describe('nfcIsoDepTagTest', function () {
49        beforeAll(function () {
50            console.info('rbeforeAll called')
51            try {
52                IsoDepTag = tag.getIsoDep(isoDepTaginfo);
53            } catch (error) {
54                console.info('getIsoDep is ->' + error)
55            }
56        })
57        beforeEach(function() {
58            console.info('beforeEach called')
59        })
60        afterEach(function () {
61            console.info('afterEach called')
62        })
63        afterAll(function () {
64            console.info('afterAll called')
65        })
66
67        /**
68         * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0100
69         * @tc.name Test getHistoricalBytes IsoDep
70         * @tc.desc Obtains the history bytes of a label.
71         * @tc.size since 9
72         * @tc.type Function
73         * @tc.level Level 0
74         */
75        it('SUB_Communication_NFC_nfcIsoDep_js_0100', Level.LEVEL0, function ()  {
76            if (IsoDepTag != null && IsoDepTag != undefined) {
77                let ResponseFlags = IsoDepTag.getHistoricalBytes();
78                expect(ResponseFlags).assertInstanceOf('Array')
79                console.info('[NFC_test] Isodep1 test ResponseFlags data>:' + ResponseFlags);
80            } else {
81                console.info("[NFC_test]IsoDepTag1 = null & = undefined: ");
82                expect().assertFail();
83            }
84        })
85
86        /**
87         * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0200
88         * @tc.name Test getHiLayerResponse IsoDep
89         * @tc.desc HiLayer response byte for obtaining the tag.
90         * @tc.size since 9
91         * @tc.type Function
92         * @tc.level Level 0
93         */
94        it('SUB_Communication_NFC_nfcIsoDep_js_0200', Level.LEVEL0, function ()  {
95            if (IsoDepTag != null && IsoDepTag != undefined) {
96                let HiLayerResponse = IsoDepTag.getHiLayerResponse();
97                expect(HiLayerResponse).assertInstanceOf('Array')
98                console.info('[NFC_test] Isodep2 test ResponseFlags data2>:' + HiLayerResponse);
99            } else {
100                console.info("[NFC_test]IsoDepTag2 = null & = undefined: ");
101                expect().assertFail();
102            }
103        })
104
105        /**
106         * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0300
107         * @tc.name Test isExtendedApduSupported IsoDep
108         * @tc.desc Check whether extended APDUs are supported.Promise
109         * @tc.size since 9
110         * @tc.type Function
111         * @tc.level Level 0
112         */
113        it('SUB_Communication_NFC_nfcIsoDep_js_0300', Level.LEVEL0, async function (done) {
114            if (IsoDepTag != null && IsoDepTag != undefined) {
115                await IsoDepTag.isExtendedApduSupported().then((data) => {
116                    console.info("[NFC_test] Isodep3 isExtendedApduSupported data: " + data);
117                    expect(true).assertEqual(data);
118                    done();
119                }).catch((err)=> {
120                    console.info("[NFC_test] Isodep3 isExtendedApduSupported data");
121                    if (err.code == 201) {
122                        console.info("[NFC_test] Isodep3 isExtendedApduSupported err: " + err + err.code);
123                        expect(true).assertTrue();
124                    } else if (err.code == 401) {
125                        console.info("[NFC_test] Isodep3 isExtendedApduSupported err: " + err + err.code);
126                        expect(true).assertTrue();
127                    } else if (err.code == 3100201) {
128                        console.info("[NFC_test] Isodep3 isExtendedApduSupported err: " + err + err.code);
129                        expect(true).assertTrue();
130                    } else if (err.code == 3100204) {
131                        console.info("[NFC_test] Isodep3 isExtendedApduSupported err: " + err + err.code);
132                        expect(true).assertTrue();
133                    } else {
134                        console.info("[NFC_test] Isodep3 isExtendedApduSupported err: " + err + err.code);
135                        expect().assertFail();
136                    }
137                    done();
138                });
139            } else {
140                console.info("[NFC_test]IsoDepTag3 = null & = undefined: ");
141                expect().assertFail();
142            }
143        })
144
145        /**
146         * @tc.number SUB_Communication_NFC_nfcIsoDep_js_0400
147         * @tc.name Test isExtendedApduSupported IsoDep
148         * @tc.desc Check whether extended APDUs are supported.callback
149         * @tc.size since 9
150         * @tc.type Function
151         * @tc.level Level 0
152         */
153        it('SUB_Communication_NFC_nfcIsoDep_js_0400', Level.LEVEL0, async function (done) {
154            if (IsoDepTag != null && IsoDepTag != undefined) {
155                console.info("[NFC_test] Isodep4 00isExtendedApduSupported: " );
156                IsoDepTag.isExtendedApduSupported((err, data)=> {
157                    console.info("[NFC_test] Isodep4 isExtendedApduSupported err: " + err);
158                    if (err== 201) {
159                        console.info("[NFC_test] Isodep4 isExtendedApduSupported err: " + err);
160                        expect(true).assertTrue();
161                    } else if (err == 3100201) {
162                        console.info("[NFC_test] Isodep4 isExtendedApduSupported err: " + err);
163                        expect(true).assertTrue();
164                    } else if (err == 3100204) {
165                        console.info("[NFC_test] Isodep4 isExtendedApduSupported err: " + err);
166                        expect(true).assertTrue();
167                    } else {
168                        console.info("[NFC_test] Isodep4 isExtendedApduSupported data: " + data);
169                        expect(true).assertEqual(data);
170                    }
171                    done();
172                });
173            } else {
174                console.info("[NFC_test]IsoDepTag4 = null & = undefined: ");
175                expect().assertFail();
176            }
177        })
178
179        /**
180         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0500
181         * @tc.name Test cardEmulationnfc
182         * @tc.desc Whether to support a certain type of card emulation.
183         * @tc.size since 9
184         * @tc.type Function
185         * @tc.level Level 0
186         */
187         it('SUB_Communication_NFC_nfccardEmulationnfc_js_0500', Level.LEVEL0, function ()  {
188            if (IsoDepTag != null && IsoDepTag != undefined) {
189                let cardEmulationnfc ;
190                try {
191                    cardEmulationnfc = cardEmulation.isSupported(cardEmulation.FeatureType.ESE);
192                    console.info('[NFC_test] cardEmulationnfc5 type ->' + cardEmulationnfc )
193                    expect(cardEmulationnfc).assertFalse();
194                } catch (error) {
195                    console.info('[NFC_test] cardEmulationnfc5 error' + error)
196                    expect().assertFail();
197                }
198            } else {
199                console.info("[NFC_test]IsoDepTag5 = null & = undefined: ");
200                expect().assertFail();
201            }
202        })
203
204       /**
205         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0600
206         * @tc.name Test cardEmulationnfc
207         * @tc.desc hasHceCapability to support a certain type of card emulation.
208         * @tc.size since 9
209         * @tc.type Function
210         * @tc.level Level 0
211         */
212        it('SUB_Communication_NFC_nfccardEmulationnfc_js_0600', Level.LEVEL0, function ()  {
213            let cardEmulationnfc ;
214            try {
215                cardEmulationnfc = cardEmulation.hasHceCapability();
216                console.info('[NFC_test] cardEmulationnfc6 hasHceCapability type ->' + cardEmulationnfc )
217                expect(cardEmulationnfc).assertTrue();
218            } catch (error) {
219                console.info('[NFC_test] cardEmulationnfc6 error' + error + "/" + error.code)
220                expect(801).assertEqual(error.code);
221            }
222        })
223
224        /**
225         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0700
226         * @tc.name Test cardEmulationnfc
227         * @tc.desc Whether to support a certain type of card isDefaultService.
228         * @tc.size since 9
229         * @tc.type Function
230         * @tc.level Level 0
231         */
232        it('SUB_Communication_NFC_nfccardEmulationnfc_js_0700', Level.LEVEL0, function ()  {
233            let cardEmulationnfc ;
234            let elementName = {
235                "bundleName": "com.test.cardemulation",
236                "abilityName": "com.test.cardemulation.MainAbility",
237            };
238            try {
239                cardEmulationnfc = cardEmulation.isDefaultService(elementName, CardType.PAYMENT);
240                console.info('[NFC_test] cardEmulationnfc7 isDefaultService type ->' + cardEmulationnfc )
241                expect(cardEmulationnfc).assertFalse();
242            } catch (error) {
243                console.info('[NFC_test] cardEmulationnfc7 error' + error + "/" + error.code)
244                expect(801).assertEqual(error.code);
245            }
246            try {
247                cardEmulationnfc = cardEmulation.isDefaultService();
248                console.info('[NFC_test] cardEmulationnfc7 isDefaultService 401 ->' + cardEmulationnfc )
249                expect().assertFail();
250            } catch (error) {
251                console.info('[NFC_test] cardEmulationnfc7 401' + error + "/" + error.code)
252                expect(401).assertEqual(error.code);
253            }
254        })
255
256        /**
257         * @tc.number SUB_Communication_NFC_Enumerated_js_0800
258         * @tc.name Test Enumerated
259         * @tc.desc Enumeration return value test
260         * @tc.size since 9
261         * @tc.type Function
262         * @tc.level Level 2
263         */
264         it('SUB_Communication_NFC_Enumerated_js_0800', Level.LEVEL2, function ()  {
265            console.info('[nfc_test]1 PAYMENT Enumerated value test pass:' + cardEmulation.CardType.PAYMENT)
266            expect(cardEmulation.CardType.PAYMENT).assertEqual("payment");
267            console.info('[nfc_test]2 OTHER Enumerated value test pass:' + cardEmulation.CardType.OTHER)
268            expect(cardEmulation.CardType.OTHER).assertEqual("other");
269            console.info('[nfc_test]3 NFC_FORUM_TYPE_1 Enumerated value test pass:' + tag.NfcForumType.NFC_FORUM_TYPE_1)
270            expect(tag.NfcForumType.NFC_FORUM_TYPE_1).assertEqual(1);
271            console.info('[nfc_test]4 NFC_FORUM_TYPE_2 Enumerated value test pass:' + tag.NfcForumType.NFC_FORUM_TYPE_2)
272            expect(tag.NfcForumType.NFC_FORUM_TYPE_2).assertEqual(2);
273            console.info('[nfc_test]5 NFC_FORUM_TYPE_3 Enumerated value test pass:' + tag.NfcForumType.NFC_FORUM_TYPE_3)
274            expect(tag.NfcForumType.NFC_FORUM_TYPE_3).assertEqual(3);
275            console.info('[nfc_test]6 NFC_FORUM_TYPE_4 Enumerated value test pass:' + tag.NfcForumType.NFC_FORUM_TYPE_4)
276            expect(tag.NfcForumType.NFC_FORUM_TYPE_4).assertEqual(4);
277            console.info('[nfc_test]7 MIFARE_CLASSIC Enumerated value test pass:' + tag.NfcForumType.MIFARE_CLASSIC)
278            expect(tag.NfcForumType.MIFARE_CLASSIC).assertEqual(101);
279            console.info('[nfc_test]8 HCE Enumerated value test pass:' + cardEmulation.FeatureType.HCE)
280            expect(cardEmulation.FeatureType.HCE).assertEqual(0);
281            console.info('[nfc_test]9 UICC Enumerated value test pass:' + cardEmulation.FeatureType.UICC)
282            expect(cardEmulation.FeatureType.UICC).assertEqual(1);
283            console.info('[nfc_test]10 ESE Enumerated value test pass:' + cardEmulation.FeatureType.ESE)
284            expect(cardEmulation.FeatureType.ESE).assertEqual(2);
285            console.info('[nfc_test]11 TYPE_UNKNOWN Enumerated value test pass:' + tag.MifareClassicType.TYPE_UNKNOWN)
286            expect(tag.MifareClassicType.TYPE_UNKNOWN).assertEqual(0);
287            console.info('[nfc_test]12 TYPE_CLASSIC Enumerated value test pass:' + tag.MifareClassicType.TYPE_CLASSIC)
288            expect(tag.MifareClassicType.TYPE_CLASSIC).assertEqual(1);
289            console.info('[nfc_test]13 TYPE_PLUS Enumerated value test pass:' + tag.MifareClassicType.TYPE_PLUS)
290            expect(tag.MifareClassicType.TYPE_PLUS).assertEqual(2);
291            console.info('[nfc_test]14 TYPE_PRO Enumerated value test pass:' + tag.MifareClassicType.TYPE_PRO)
292            expect(tag.MifareClassicType.TYPE_PRO).assertEqual(3);
293            console.info('[nfc_test]15 MC_SIZE_MINI Enumerated value test pass:' + tag.MifareClassicSize.MC_SIZE_MINI)
294            expect(tag.MifareClassicSize.MC_SIZE_MINI).assertEqual(320);
295            console.info('[nfc_test]16 MC_SIZE_1K Enumerated value test pass:' + tag.MifareClassicSize.MC_SIZE_1K)
296            expect(tag.MifareClassicSize.MC_SIZE_1K).assertEqual(1024);
297            console.info('[nfc_test]17 MC_SIZE_2K Enumerated value test pass:' + tag.MifareClassicSize.MC_SIZE_2K)
298            expect(tag.MifareClassicSize.MC_SIZE_2K).assertEqual(2048);
299            console.info('[nfc_test]18 MC_SIZE_4K Enumerated value test pass:' + tag.MifareClassicSize.MC_SIZE_4K)
300            expect(tag.MifareClassicSize.MC_SIZE_4K).assertEqual(4096);
301            console.info('[nfc_test]19 TYPE_UNKNOWN Enumerated value test pass:' + tag.MifareUltralightType.TYPE_UNKNOWN)
302            expect(tag.MifareUltralightType.TYPE_UNKNOWN).assertEqual(0);
303            console.info('[nfc_test]20 TYPE_ULTRALIGHT Enumerated value pass:' + tag.MifareUltralightType.TYPE_ULTRALIGHT)
304            expect(tag.MifareUltralightType.TYPE_ULTRALIGHT).assertEqual(1);
305            console.info('[nfc_test]21 TYPE_ULTRALIGHT_C Enumerated value pass:' + tag.MifareUltralightType.TYPE_ULTRALIGHT_C)
306            expect(tag.MifareUltralightType.TYPE_ULTRALIGHT_C).assertEqual(2);
307            console.info('[nfc_test]22 TNF_EMPTY Enumerated value test pass:' + tag.TnfType.TNF_EMPTY)
308            expect(tag.TnfType.TNF_EMPTY).assertEqual(0x0);
309            console.info('[nfc_test]23 TNF_WELL_KNOWN Enumerated value test pass:' + tag.TnfType.TNF_WELL_KNOWN)
310            expect(tag.TnfType.TNF_WELL_KNOWN).assertEqual(0x01);
311            console.info('[nfc_test]24 TNF_MEDIA Enumerated value test pass:' + tag.TnfType.TNF_MEDIA)
312            expect(tag.TnfType.TNF_MEDIA).assertEqual(0x02);
313            console.info('[nfc_test]25 TNF_ABSOLUTE_URI Enumerated value test pass:' + tag.TnfType.TNF_ABSOLUTE_URI)
314            expect(tag.TnfType.TNF_ABSOLUTE_URI).assertEqual(0x03);
315            console.info('[nfc_test]26 TNF_EXT_APP Enumerated value test pass:' + tag.TnfType.TNF_EXT_APP)
316            expect(tag.TnfType.TNF_EXT_APP).assertEqual(0x04);
317            console.info('[nfc_test]27 TNF_UNKNOWN Enumerated value test pass:' + tag.TnfType.TNF_UNKNOWN)
318            expect(tag.TnfType.TNF_UNKNOWN).assertEqual(0x05);
319            console.info('[nfc_test]28 TNF_UNCHANGED Enumerated value test pass:' + tag.TnfType.TNF_UNCHANGED)
320            expect(tag.TnfType.TNF_UNCHANGED).assertEqual(0x06);
321            console.info('[nfc_test]29 RTD_TEXT Enumerated value pass:' + String(tag.RtdType.RTD_TEXT) + '--' + String(0x54))
322            expect(String(tag.RtdType.RTD_TEXT)).assertEqual(String(0x54));
323            console.info('[nfc_test]30 RTD_URI Enumerated value pass:' + String(tag.RtdType.RTD_URI) + '--' + String(0x55))
324            expect(String(tag.RtdType.RTD_URI)).assertEqual(String(0x55));
325            console.info('[nfc_test]31 STATE_OFF Enumerated value test pass:' + controller.NfcState.STATE_OFF)
326            expect(controller.NfcState.STATE_OFF).assertEqual(1);
327            console.info('[nfc_test]32 STATE_TURNING_ON Enumerated value test pass:' + controller.NfcState.STATE_TURNING_ON)
328            expect(controller.NfcState.STATE_TURNING_ON).assertEqual(2);
329            console.info('[nfc_test]33 STATE_ON Enumerated value test pass:' + controller.NfcState.STATE_ON)
330            expect(controller.NfcState.STATE_ON).assertEqual(3);
331            console.info('[nfc_test]34 STATE_TURNING_OFF Enumerated value test pass:' + controller.NfcState.STATE_TURNING_OFF)
332            expect(controller.NfcState.STATE_TURNING_OFF).assertEqual(4);
333            console.info('[nfc_test]35 NFC_A Enumerated value test pass:' + tag.NFC_A)
334            expect(tag.NFC_A).assertEqual(1);
335            console.info('[nfc_test]36 NFC_B Enumerated value test pass:' + tag.NFC_B)
336            expect(tag.NFC_B).assertEqual(2);
337            console.info('[nfc_test]37 ISO_DEP Enumerated value test pass:' + tag.ISO_DEP)
338            expect(tag.ISO_DEP).assertEqual(3);
339            console.info('[nfc_test]38 NFC_F Enumerated value test pass:' + tag.NFC_F)
340            expect(tag.NFC_F).assertEqual(4);
341            console.info('[nfc_test]39 NFC_V Enumerated value test pass:' + tag.NFC_V)
342            expect(tag.NFC_V).assertEqual(5);
343            console.info('[nfc_test]40 NDEF Enumerated value test pass:' + tag.NDEF)
344            expect(tag.NDEF).assertEqual(6);
345            console.info('[nfc_test]41 MIFARE_CLASSIC Enumerated value test pass:' + tag.MIFARE_CLASSIC)
346            expect(tag.MIFARE_CLASSIC).assertEqual(8);
347            console.info('[nfc_test]42 MIFARE_ULTRALIGHT Enumerated value test pass:' + tag.MIFARE_ULTRALIGHT)
348            expect(tag.MIFARE_ULTRALIGHT).assertEqual(9);
349            console.info('[nfc_test]43 NDEF_FORMATABLE Enumerated value test pass:' + tag.NDEF_FORMATABLE)
350            expect(tag.NDEF_FORMATABLE).assertEqual(7);
351        })
352
353        /**
354         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_0900
355         * @tc.name Test cardEmulationnfc
356         * @tc.desc Whether to support a certain type of card HceService on/off
357         * @tc.size since 9
358         * @tc.type Function
359         * @tc.level Level 0
360         */
361        it('SUB_Communication_NFC_nfccardEmulationnfc_js_0900', Level.LEVEL0, function ()  {
362            let hceService = new cardEmulation.HceService();
363            console.info('[NFC_test]09 hceService state is' + hceService )
364            const apduCallback = (err, data) => {
365                if (err){
366                  console.error('[NFC_test]0900 apduCallback err is' + err );
367                }else{
368                    console.log('[NFC_test]0900 got apdu data ' + data );
369                }
370            };
371            let hceElementName = {
372                bundleName: "ohos.acts.communication.nfc.nfcdevice",
373                abilityName: ".TestAbility",
374                moduleName: "nfc_standard_test"
375            }
376            let aidList = ["A0000000031010", "A0000000031011"]
377            console.info('[NFC_test]0900 TestCase Start hceElementName: ' + hceElementName.bundleName)
378            console.info('[NFC_test]0900 TestCase Start hceElementName: ' + hceElementName.moduleName)
379            try {
380                console.info('[NFC_test]0900 hceServicestart beforeInvoke hceElementName: ' + hceElementName.bundleName)
381                console.info('[NFC_test]0900 hceServicestart beforeInvoke hceElementName: ' + hceElementName.moduleName)
382                hceService.start(hceElementName, aidList);
383                console.info('[NFC_test]0900  hceServicestart afterInvoke hceElementName:  ' + hceElementName.bundleName)
384                console.info('[NFC_test]0900  hceServicestart afterInvoke hceElementName:  ' + hceElementName.moduleName)
385                console.info('[NFC_test]0900 hceServicestart success ')
386                hceService.on("hceCmd", apduCallback)
387                console.info('[NFC_test]0900 hceServiceon success ')
388                sleep(900)
389                hceService.off("hceCmd", apduCallback)
390                console.info('[NFC_test]0900 hceServicesoff success ')
391                hceService.stop(hceElementName)
392                expect(true).assertTrue();
393                console.info('[NFC_test]0900 hceServicestop success ')
394            } catch (error) {
395                console.info('[NFC_test]0900 hceService on/off error' + error + "/" + error.code)
396                expect(801).assertEqual(error.code);
397            }
398        })
399
400        /**
401         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1000
402         * @tc.name Test cardEmulationnfc
403         * @tc.desc Whether to support a certain type of card HceService transmit
404         * @tc.size since 9
405         * @tc.type Function
406         * @tc.level Level 0
407         */
408        it('SUB_Communication_NFC_nfccardEmulationnfc_js_1000', Level.LEVEL0,async function (done)  {
409            let hceService = new cardEmulation.HceService();
410            console.info('[NFC_test]10 hceService state is' + hceService )
411            let responseData = [0x1, 0x2];
412            await hceService.transmit(responseData).then(() =>{
413                console.info('[NFC_test]10 hceService.transmit success ');
414                done();
415            }).catch((err)=> {
416                console.info('[NFC_test]10 hceService.transmit err:  ' + err);
417                expect().assertFail();
418                done();
419            })
420        })
421
422        /**
423         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1100
424         * @tc.name Test cardEmulationnfc
425         * @tc.desc Whether to support a certain type of card HceService transmit
426         * @tc.size since 9
427         * @tc.type Function
428         * @tc.level Level 0
429         */
430        it('SUB_Communication_NFC_nfccardEmulationnfc_js_1100', Level.LEVEL0,async function (done)  {
431            let hceService = new cardEmulation.HceService();
432            console.info('[NFC_test]11 hceService state is' + hceService )
433            let responseData = [0x1, 0x2];
434            hceService.transmit(responseData, (err, data) => {
435                if (err){
436                    console.info('[NFC_test]11 hceService.transmit err: ' + err);
437                    expect().assertFail();
438                    done();
439                } else {
440                    console.info('[NFC_test]11 hceService.transmit data: ' + data);
441                    done();
442                }
443            })
444        })
445
446        /**
447         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1200
448         * @tc.name Test cardEmulationnfc
449         * @tc.desc Whether to support a certain type of card HceService on/off
450         * @tc.size since 9
451         * @tc.type Function
452         * @tc.level Level 0
453         */
454        it('SUB_Communication_NFC_nfccardEmulationnfc_js_1200', Level.LEVEL0, function ()  {
455            let hceService = new cardEmulation.HceService();
456            console.info('[NFC_test]12 hceService state is' + hceService )
457            let hceElementName = {
458                bundleName: "com.example.myapplication",
459                abilityName: "EntryAbility",
460                moduleName: "EntrymoduleName"
461            }
462            let aidList = ["A0000000031010", "A0000000031011"]
463            try {
464                hceService.start();
465                console.info('[NFC_test]12 hceServicestart success ')
466                expect().assertFail();
467            } catch (error) {
468                console.info('[NFC_test]12 hceServicestart error' + error + "/" + error.code)
469                expect(401).assertEqual(error.code);
470            }
471
472            try {
473                hceService.start(hceElementName, aidList);
474                console.info('[NFC_test]12 hceServicestart success ')
475                hceService.stop()
476                console.info('[NFC_test]12 hceServicestop success ')
477                expect().assertFail();
478            } catch (error) {
479                console.info('[NFC_test]12 hceServicestop error' + error + "/" + error.code)
480                expect(401).assertEqual(error.code);
481            }
482        })
483
484        /**
485         * @tc.number SUB_Communication_NFC_nfccardEmulationnfc_js_1400
486         * @tc.name Test cardEmulationnfc
487         * @tc.desc Whether to support a certain type of card HceService startHCE/stopHCE/sendResponse
488         * @tc.size since 8
489         * @tc.type Function
490         * @tc.level Level 0
491         */
492        it('SUB_Communication_NFC_nfccardEmulationnfc_js_1400', Level.LEVEL0, function ()  {
493            let hceService = new cardEmulation.HceService();
494            console.info('[NFC_test]14 hceService state is' + hceService )
495            let aidList = ["A0000000031010", "A0000000031011"]
496            let responseData = [0x1, 0x2];
497            try {
498                hceService.startHCE(aidList);
499                console.info('[NFC_test]14 hceService startHCE is success ')
500                hceService.stopHCE();
501                console.info('[NFC_test]14 hceService stopHCE is success ')
502                hceService.sendResponse(responseData);
503                console.info('[NFC_test]14 hceService sendResponse is success ')
504            } catch (error) {
505                console.info('[NFC_test]14 hceService startHCE/stopHCE/sendResponse ' + error + "/" + error.code)
506                expect().assertFail();
507            }
508        })
509
510        console.info("*************[nfc_test] start nfc js unit test end*************");
511    })
512}