From 3302258461bc2a0e29850b470aea525b385a7449 Mon Sep 17 00:00:00 2001 From: leiiyb Date: Fri, 4 Nov 2022 19:58:24 +0800 Subject: [PATCH] add xts cases Signed-off-by: leiiyb --- .../src/main/js/test/AVSession.test.js | 247 ++++++++++++----- .../main/js/test/AVSessionController.test.js | 54 ++++ .../main/js/test/AVSessionErrorCode.test.js | 249 ++++++++++++++++++ .../src/main/js/test/AVSessionManager.test.js | 137 ++++++++++ .../src/main/js/test/List.test.js | 2 + 5 files changed, 622 insertions(+), 67 deletions(-) mode change 100644 => 100755 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js mode change 100644 => 100755 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js create mode 100755 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionErrorCode.test.js mode change 100644 => 100755 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js mode change 100644 => 100755 multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js old mode 100644 new mode 100755 index d005cd50d..cfa9cefd0 --- a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSession.test.js @@ -14,7 +14,7 @@ */ import avSession from '@ohos.multimedia.avsession'; -import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from '@ohos/hypium'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; import image from '@ohos.multimedia.image'; import WantAgent from '@ohos.wantAgent'; import featureAbility from '@ohos.ability.featureAbility'; @@ -25,11 +25,12 @@ export default function AVSession() { let type = 'audio'; let session; let controller; - let keyItem = {code:0x49, pressedTime:123456789, deviceId:0}; - let event = {action:2, key:keyItem, keys:[keyItem]}; + let OutputDeviceInfo = { isRemote: false, audioDeviceId: [0], deviceName: ['LocalDevice'] }; + let keyItem = { code: 0x49, pressedTime: 123456789, deviceId: 0 }; + let event = { action: 2, key: keyItem, keys: [keyItem] }; let context = featureAbility.getContext(); - function sleep (ms) { + function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -37,7 +38,7 @@ export default function AVSession() { let color = new ArrayBuffer(96); let bufferArr = new Uint8Array(color); bufferArr.fill('3', 0, 95); - let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, AlphaType: 3}; + let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 }, AlphaType: 3 }; return image.createPixelMap(color, opts); } @@ -118,7 +119,7 @@ export default function AVSession() { * @tc.level : Level0 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0100', 0, async function (done) { - let metadata0 = { + let metadata0 = { assetId: '121278', }; await session.setAVMetadata(metadata0).then(() => { @@ -153,7 +154,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0200', 0, async function (done) { - let metadata1 = { + let metadata1 = { assetId: '121278', artist: 'Eminem', }; @@ -187,7 +188,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0300', 0, async function (done) { - let metadata2 = { + let metadata2 = { assetId: '121278', author: 'ST', }; @@ -221,7 +222,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0400', 0, async function (done) { - let metadata3 = { + let metadata3 = { assetId: '121278', album: 'Slim shady', }; @@ -255,7 +256,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0500', 0, async function (done) { - let metadata4 = { + let metadata4 = { assetId: '121278', writer: 'ST', }; @@ -289,7 +290,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0600', 0, async function (done) { - let metadata5 = { + let metadata5 = { assetId: '121278', composer: 'ST', }; @@ -323,7 +324,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0700', 0, async function (done) { - let metadata6 = { + let metadata6 = { assetId: '121278', duration: 2222, }; @@ -358,7 +359,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0800', 0, async function (done) { - let metadata7 = { + let metadata7 = { assetId: '121278', mediaImage: 'https://img2.baidu.com/it/u=3583435814,2833583486&fm=253&fmt=auto&app=138&f=JPEG?w=526&h=500', }; @@ -397,7 +398,7 @@ export default function AVSession() { let readBuffer0 = new ArrayBuffer(96); await pixelMap.readPixelsToBuffer(readBuffer0); let bufferArr0 = new Uint8Array(readBuffer0); - let metadata8 = { + let metadata8 = { assetId: '121278', mediaImage: pixelMap, }; @@ -443,9 +444,9 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1000', 0, async function (done) { - let metadata9 = { + let metadata9 = { assetId: '121278', - publishDate: new Date(1994,1,1,1), + publishDate: new Date(1994, 1, 1, 1), }; await session.setAVMetadata(metadata9).then(() => { console.info('TestLog: Set publishDate successfully'); @@ -477,7 +478,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1100', 0, async function (done) { - let metadata10 = { + let metadata10 = { assetId: '121278', subtitle: '8 Mile', }; @@ -513,7 +514,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1200', 0, async function (done) { - let metadata11 = { + let metadata11 = { assetId: '121278', description: 'Rap', }; @@ -547,7 +548,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1300', 0, async function (done) { - let metadata12 = { + let metadata12 = { assetId: '121278', lyric: 'https://lyric.tingmall.com/lyric/58/970/589710004-LRC-LRC.lrc?t=1649918948000', }; @@ -583,7 +584,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1400', 0, async function (done) { - let metadata13 = { + let metadata13 = { assetId: '121278', previousAssetId: '121277', nextAssetId: '121279', @@ -621,7 +622,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1500', 0, async function (done) { - let metadata14 = { + let metadata14 = { assetId: '121278', }; await session.destroy(); @@ -645,7 +646,7 @@ export default function AVSession() { * @tc.level : Level2 */ it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_1600', 0, async function (done) { - let metadata15 = { + let metadata15 = { assetId: '121278', duration: -2, }; @@ -669,7 +670,7 @@ export default function AVSession() { */ it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0100', 0, async function (done) { let PlaybackState1 = { - state:avSession.PlaybackState.PLAYBACK_STATE_PLAY, + state: avSession.PlaybackState.PLAYBACK_STATE_PLAY, }; await session.setAVPlaybackState(PlaybackState1).then(() => { console.info('TestLog: Set State successfully'); @@ -742,7 +743,7 @@ export default function AVSession() { */ it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0300', 0, async function (done) { let PlaybackState3 = { - position:{elapsedTime:10, updateTime:(new Date()).getTime()}, + position: { elapsedTime: 10, updateTime: (new Date()).getTime() }, }; await session.setAVPlaybackState(PlaybackState3).then(() => { @@ -816,7 +817,7 @@ export default function AVSession() { */ it('SUB_MULTIMEDIA_AVSESSION_SETAVPLAYBACKSTATE_PROMISE_0500', 0, async function (done) { let PlaybackState5 = { - loopMode:avSession.LoopMode.LOOP_MODE_SEQUENCE, + loopMode: avSession.LoopMode.LOOP_MODE_SEQUENCE, }; await session.setAVPlaybackState(PlaybackState5).then(() => { @@ -1003,7 +1004,7 @@ export default function AVSession() { let PlaybackState10 = { state: avSession.PlaybackState.PLAYBACK_STATE_PLAY, speed: 1.0, - position: {elapsedTime: 10, updateTime: (new Date()).getTime()}, + position: { elapsedTime: 10, updateTime: (new Date()).getTime() }, bufferedTime: 1000, loopMode: avSession.LoopMode.LOOP_MODE_SINGLE, isFavorite: true, @@ -1032,7 +1033,7 @@ export default function AVSession() { let PlaybackState11 = { state: avSession.PlaybackState.PLAYBACK_STATE_PLAY, speed: -2, - position: {elapsedTime: -2, updateTime: (new Date()).getTime()}, + position: { elapsedTime: -2, updateTime: (new Date()).getTime() }, bufferedTime: -4, loopMode: avSession.LoopMode.LOOP_MODE_SINGLE, isFavorite: true, @@ -1277,11 +1278,11 @@ export default function AVSession() { * @tc.type : Function * @tc.level : Level1 */ - it('SUB_MULTIMEDIA_AVSESSION_SETLAUNCHABILITY_PROMISE_0100', 0, async function(done) { + it('SUB_MULTIMEDIA_AVSESSION_SETLAUNCHABILITY_PROMISE_0100', 0, async function (done) { let wantAgentInfo = { - wants : [ + wants: [ { - bundleName : 'com.example.myapplication', + bundleName: 'com.example.myapplication', abilityName: 'com.example.myapplication.MainAbility' } ], @@ -1439,7 +1440,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'play'}).then(() => { + await controller.sendControlCommand({ command: 'play' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1463,7 +1464,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'pause'}).then(() => { + await controller.sendControlCommand({ command: 'pause' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1487,7 +1488,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'stop'}).then(() => { + await controller.sendControlCommand({ command: 'stop' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1511,7 +1512,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'playNext'}).then(() => { + await controller.sendControlCommand({ command: 'playNext' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1535,7 +1536,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'playPrevious'}).then(() => { + await controller.sendControlCommand({ command: 'playPrevious' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1559,7 +1560,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'fastForward'}).then(() => { + await controller.sendControlCommand({ command: 'fastForward' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1583,7 +1584,7 @@ export default function AVSession() { expect(true).assertTrue(); }); - await controller.sendControlCommand({command:'rewind'}).then(() => { + await controller.sendControlCommand({ command: 'rewind' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1612,7 +1613,7 @@ export default function AVSession() { } }); - await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + await controller.sendControlCommand({ command: 'seek', parameter: 10 }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1641,7 +1642,7 @@ export default function AVSession() { } }); - await controller.sendControlCommand({command:'setSpeed', parameter:2.6}).then(() => { + await controller.sendControlCommand({ command: 'setSpeed', parameter: 2.6 }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1670,8 +1671,10 @@ export default function AVSession() { } }); - await controller.sendControlCommand({command:'setLoopMode', parameter: - avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + await controller.sendControlCommand({ + command: 'setLoopMode', parameter: + avSession.LoopMode.LOOP_MODE_SINGLE + }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1701,7 +1704,7 @@ export default function AVSession() { } }); - await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + await controller.sendControlCommand({ command: 'toggleFavorite', parameter: 'false' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1785,7 +1788,7 @@ export default function AVSession() { session.off('play'); - await controller.sendControlCommand({command:'play'}).then(() => { + await controller.sendControlCommand({ command: 'play' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1803,7 +1806,7 @@ export default function AVSession() { * @tc.type : Function * @tc.level : Level2 */ - it ('SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0200', 0, async function (done) { + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0200', 0, async function (done) { function callback1() { console.info('TestLog: Play command registration1 success'); expect(false).assertTrue(); @@ -1820,7 +1823,7 @@ export default function AVSession() { session.off('play', callback1); - await controller.sendControlCommand({command:'play'}).then(() => { + await controller.sendControlCommand({ command: 'play' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1855,7 +1858,7 @@ export default function AVSession() { session.off('pause'); - await controller.sendControlCommand({command:'pause'}).then(() => { + await controller.sendControlCommand({ command: 'pause' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1890,7 +1893,7 @@ export default function AVSession() { session.off('pause', callback1); - await controller.sendControlCommand({command:'pause'}).then(() => { + await controller.sendControlCommand({ command: 'pause' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1926,7 +1929,7 @@ export default function AVSession() { session.off('stop'); - await controller.sendControlCommand({command:'stop'}).then(() => { + await controller.sendControlCommand({ command: 'stop' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1961,7 +1964,7 @@ export default function AVSession() { session.off('stop', callback1) - await controller.sendControlCommand({command:'stop'}).then(() => { + await controller.sendControlCommand({ command: 'stop' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -1996,7 +1999,7 @@ export default function AVSession() { session.off('playNext'); - await controller.sendControlCommand({command:'playNext'}).then(() => { + await controller.sendControlCommand({ command: 'playNext' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2031,7 +2034,7 @@ export default function AVSession() { session.off('playNext', callback1); - await controller.sendControlCommand({command:'playNext'}).then(() => { + await controller.sendControlCommand({ command: 'playNext' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2066,7 +2069,7 @@ export default function AVSession() { session.off('playPrevious'); - await controller.sendControlCommand({command:'playPrevious'}).then(() => { + await controller.sendControlCommand({ command: 'playPrevious' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2101,7 +2104,7 @@ export default function AVSession() { session.off('playPrevious', callback1); - await controller.sendControlCommand({command:'playPrevious'}).then(() => { + await controller.sendControlCommand({ command: 'playPrevious' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2136,7 +2139,7 @@ export default function AVSession() { session.off('fastForward'); - await controller.sendControlCommand({command:'fastForward'}).then(() => { + await controller.sendControlCommand({ command: 'fastForward' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2171,7 +2174,7 @@ export default function AVSession() { session.off('fastForward', callback1); - await controller.sendControlCommand({command:'fastForward'}).then(() => { + await controller.sendControlCommand({ command: 'fastForward' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2206,7 +2209,7 @@ export default function AVSession() { session.off('rewind'); - await controller.sendControlCommand({command:'rewind'}).then(() => { + await controller.sendControlCommand({ command: 'rewind' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2241,7 +2244,7 @@ export default function AVSession() { session.off('rewind', callback1); - await controller.sendControlCommand({command:'rewind'}).then(() => { + await controller.sendControlCommand({ command: 'rewind' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2280,7 +2283,7 @@ export default function AVSession() { session.off('seek'); - await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + await controller.sendControlCommand({ command: 'seek', parameter: 10 }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2319,7 +2322,7 @@ export default function AVSession() { session.off('seek', callback1); - await controller.sendControlCommand({command:'seek', parameter:10}).then(() => { + await controller.sendControlCommand({ command: 'seek', parameter: 10 }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2358,7 +2361,7 @@ export default function AVSession() { session.off('setSpeed'); - await controller.sendControlCommand({command:'setSpeed', parameter:2.0}).then(() => { + await controller.sendControlCommand({ command: 'setSpeed', parameter: 2.0 }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2397,7 +2400,7 @@ export default function AVSession() { session.off('setSpeed', callback1); - await controller.sendControlCommand({command:'setSpeed', parameter:2.0}).then(() => { + await controller.sendControlCommand({ command: 'setSpeed', parameter: 2.0 }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2436,8 +2439,10 @@ export default function AVSession() { session.off('setLoopMode'); - await controller.sendControlCommand({command:'setLoopMode', - parameter:avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + await controller.sendControlCommand({ + command: 'setLoopMode', + parameter: avSession.LoopMode.LOOP_MODE_SINGLE + }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2476,8 +2481,10 @@ export default function AVSession() { session.off('setLoopMode', callback1); - await controller.sendControlCommand({command:'setLoopMode', - parameter:avSession.LoopMode.LOOP_MODE_SINGLE}).then(() => { + await controller.sendControlCommand({ + command: 'setLoopMode', + parameter: avSession.LoopMode.LOOP_MODE_SINGLE + }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2516,7 +2523,7 @@ export default function AVSession() { session.off('toggleFavorite'); - await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + await controller.sendControlCommand({ command: 'toggleFavorite', parameter: 'false' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2555,7 +2562,7 @@ export default function AVSession() { session.off('toggleFavorite', callback1); - await controller.sendControlCommand({command:'toggleFavorite', parameter:'false'}).then(() => { + await controller.sendControlCommand({ command: 'toggleFavorite', parameter: 'false' }).then(() => { console.info('TestLog: Controller send command successfully'); }).catch((err) => { console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); @@ -2651,5 +2658,111 @@ export default function AVSession() { await sleep(500); done(); }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0100 + * @tc.name : GETOUTPUTDEVICE_PROMISE_0100 + * @tc.desc : Testing get output device + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0100', 0, async function (done) { + session.on('outputDeviceChange', (callback) => { + if (!callback.isRemote) { + console.info(callback.audioDeviceId.size); + console.info(callback.deviceName.size); + console.info('outputDeviceChange callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('outputDeviceChange callback registration fail'); + expect(false).assertTrue(); + } + }); + + session.off('outputDeviceChange'); + + await session.getOutputDevice().then((data) => { + if (!data.isRemote) { + expect(true).assertTrue(); + } else { + console.info(avSession.OutputDeviceInfo.isRemote); + console.info(avSession.OutputDeviceInfo.audioDeviceId.size); + console.info(avSession.OutputDeviceInfo.deviceName.size); + console.info('getOutputDevice successfully'); + console.info('Get device information failed'); + expect(false).assertTrue(); + } + }).catch((err) => { + console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }) + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0100 + * @tc.name : GETOUTPUTDEVICE_CALLBACK_0100 + * @tc.desc : Testing get output device + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0100', 0, async function (done) { + session.getOutputDevice((err, value) => { + if (err) { + console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (!value.isRemote) { + console.info('Get device information successfully'); + expect(true).assertTrue(); + } else { + console.info('Get device information failed'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETCONTROLLER_PROMISE_0100 + * @tc.name : GETCONTROLLER_PROMISE_0100 + * @tc.desc : Testing get controller + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETCONTROLLER_PROMISE_0100', 0, async function (done) { + await session.getController().then((data) => { + console.info('Get controller successfully'); + expect(true).assertTrue(); + }).catch((err) => { + console.info('Get controller failed'); + console.info(`Get controller BusinessError: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETCONTROLLER_CALLBACK_0100 + * @tc.name : GETCONTROLLER_CALLBACK_0100 + * @tc.desc : Testing get controller + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETCONTROLLER_CALLBACK_0100', 0, async function (done) { + session.getController((err, data) => { + if (err) { + console.info('Get controller failed'); + expect(false).assertTrue(); + } else { + console.info('Get controller successfully'); + expect(true).assertTrue(); + } + }) + done(); + }) }) } \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js old mode 100644 new mode 100755 index 505963f0e..0893603ec --- a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionController.test.js @@ -1680,5 +1680,59 @@ export default function Controller() { await sleep(500); done(); }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0100 + * @tc.name : GETOUTPUTDEVICE_CALLBACK_0100 + * @tc.desc : Testing get output device + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_CALLBACK_0100', 0, async function (done) { + controller.on('outputDeviceChange', (callback) => { + if (!callback.isRemote) { + console.info('outputDeviceChange callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('outputDeviceChange callback registration fail'); + expect(false).assertTrue(); + } + }); + + controller.off('outputDeviceChange'); + controller.getOutputDevice((err, value) => { + if (err) { + console.info(`Get device information BusinessError: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + } else if (!value.isRemote) { + console.info('Get device information successfully'); + expect(true).assertTrue(); + } else { + console.info('Get device information failed'); + expect(false).assertTrue(); + } + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0100 + * @tc.name : GETOUTPUTDEVICE_PROMISE_0100 + * @tc.desc : Testing get output device + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_GETOUTPUTDEVICE_PROMISE_0100', 0, async function (done) { + await controller.getOutputDevice().then((value) => { + console.info('Get device information successfully'); + expect(true).assertTrue(); + }).catch((err) => { + console.info(`Get device BusinessError: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }) + done(); + }) }) } \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionErrorCode.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionErrorCode.test.js new file mode 100755 index 000000000..82966d218 --- /dev/null +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionErrorCode.test.js @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http:// www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import avSession from '@ohos.multimedia.avsession'; +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import featureAbility from '@ohos.ability.featureAbility'; + +export default function AVSessionErrorCode() { + describe('AVSessionErrorCode', function () { + let tag = 'ApplicationA'; + let type = 'audio'; + let session; + let pid = 100; + let uid = 200; + let audioDevices; + let sessionToken; + let controller; + let id = '9527'; + let sessionId; + let keyItem = {code:10, pressedTime:123456789, deviceId:0}; + let event = {action:2, key:keyItem, keys:[keyItem]}; + let context = featureAbility.getContext(); + + function sleep (ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + + beforeAll(function () { + console.info('TestLog: Start Testing avSession Interfaces'); + }) + + beforeEach(async function () { + console.info('TestLog: Init Session And Controller'); + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + }).catch((err) => { + expect(err.code == 6600101).assertTrue(); + console.info(avSession.AVSessionErrorCode.ERR_CODE_SERVICE_EXCEPTION); + console.info(`TestLog: Session create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await session.activate().then(() => { + console.info('TestLog: Session activate'); + }).catch((err) => { + console.info(`TestLog: Session activate error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + + await avSession.createController(session.sessionId).then((data) => { + controller = data; + }).catch((err) => { + console.info(`TestLog: Controller create error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + }) + + afterEach(async function (done) { + console.info('TestLog: Destroy Session And Controller'); + await session.destroy().then(() => { + console.info('TestLog: Session destroy success'); + }).catch((err) => { + console.info(`TestLog: Session destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await controller.destroy().then(() => { + console.info('TestLog: Controller destroy success'); + }).catch((err) => { + console.info(`TestLog: Controller destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + afterAll(function () { + console.info('TestLog: End Testing avSession Interfaces'); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0100 + * @tc.name : SETMETADATA_0100 + * @tc.desc : Testing set metadata - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_SET_METADATA_PROMISE_0100', 0, async function (done) { + let metadata1 = { + assetId: '121278', + }; + + await sleep(500); + await session.setAVMetadata(metadata1).then(() => { + console.info('TestLog: Set metadata successfully'); + expect(true).assertTrue(); + }).catch((err) => { + expect(err.code == 6600102).assertTrue(); + console.info(avSession.AVSessionErrorCode.ERR_CODE_SESSION_NOT_EXIST); + console.info(`TestLog: Set metadata error: code: ${err.code}, message: ${err.message}`); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_DESTROYCONTROLLER_PROMISE_0100 + * @tc.name : DESTROYCONTROLLER_0100 + * @tc.desc : Testing destroy the controller - promise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level1 + */ + it('SUB_MULTIMEDIA_AVSESSION_DESTROYCONTROLLER_PROMISE_0100', 0, async function (done) { + await controller.destroy().then(() => { + console.info('TestLog: Controller destroy successfully'); + expect(true).assertTrue(); + }).catch((err) => { + expect(err.code == 6600103).assertTrue(); + console.info(avSession.AVSessionErrorCode.ERR_CODE_CONTROLLER_NOT_EXIST); + console.info(`TestLog: Controller destroy error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0100 + * @tc.name : OFFPLAY_0100 + * @tc.desc : Testing offPlay callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_OFFPLAY_0100', 0, async function (done) { + function callback1() { + console.info('TestLog: Play command registration1 success'); + expect(true).assertTrue(); + } + + session.on('play', callback1); + + await controller.sendControlCommand({ command: 'play' }).then(() => { + console.info('TestLog: Controller send command successfully'); + expect(true).assertTrue(); + }).catch((err) => { + expect(err.code == 6600105).assertTrue(); + console.info(avSession.AVSessionErrorCode.ERR_CODE_COMMAND_INVALID); + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0100 + * @tc.name : CAST_AUDIO_0100 + * @tc.desc : Testing cast audio + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0100', 0, async function (done) { + sessionId = session.sessionId; + sessionToken = { sessionId, pid, uid }; + + try { + await avSession.castAudio(sessionToken, audioDevices).then(() => { + console.info('Cast audio to remote'); + }).catch((err) => { + console.info(avSession.AVSessionErrorCode.ERR_CODE_REMOTE_CONNECTION_ERR); + console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + } catch (err) { + console.info(`Testing has failed BusinessError: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONHANDLEKEYEVENT_0100 + * @tc.name : ONHANDLEKEYEVENT_0100 + * @tc.desc : Testing Handle KeyEvent callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONHANDLEKEYEVENT_0100', 0, async function (done) { + session.on('handleKeyEvent', (callback) => { + if (callback.action === 2) { + console.info('TestLog: Handle keyEvent callback registration successful'); + expect(true).assertTrue(); + } else { + console.info('TestLog: Handle keyEvent callback registration error'); + expect(false).assertTrue(); + } + }); + + await controller.sendAVKeyEvent(event).then(() => { + console.info('TestLog: Controller send AVKeyEvent successfully'); + }).catch((err) => { + expect(err.code == 6600106).assertTrue(); + console.info(avSession.AVSessionErrorCode.ERR_CODE_SESSION_INACTIVE); + console.info(`TestLog: Controller send AVKeyEvent error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_ONPLAY_0100 + * @tc.name : ONPLAY_0100 + * @tc.desc : Testing onPlay callback + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_ONPLAY_0100', 0, async function (done) { + session.on('play', () => { + console.info('TestLog: Play command callback registration successful'); + expect(true).assertTrue(); + }); + + await controller.sendControlCommand({ command: 'play' }).then(() => { + console.info('TestLog: Controller send command successfully'); + }).catch((err) => { + expect(err.code == 6600107).assertTrue(); + console.info(avSession.AVSessionErrorCode.ERR_CODE_MESSAGE_OVERLOAD); + console.info(`TestLog: Controller send command error: code: ${err.code}, message: ${err.message}`); + expect(false).assertTrue(); + }); + await sleep(500); + done(); + }) + }) +} \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js old mode 100644 new mode 100755 index 8b76de186..d8bf3764c --- a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/AVSessionManager.test.js @@ -24,6 +24,11 @@ export default function AVSessionManager() { let session; let controller; let id = '9527'; + let sessionId; + let pid = 100; + let uid = 200; + let audioDevices; + let sessionToken; let keyItem = {code:10, pressedTime:123456789, deviceId:0}; let event = {action:2, key:keyItem, keys:[keyItem]}; let context = featureAbility.getContext(); @@ -1140,5 +1145,137 @@ export default function AVSessionManager() { }); done(); }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0100 + * @tc.name : CAST_AUDIO_PROMISE_0100 + * @tc.desc : Testing cast audio + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0100', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + sessionId = session.sessionId; + sessionToken = { sessionId, pid, uid }; + }).catch((err) => { + console.info(`Session create BusinessError: ${err.code}, message: ${err.message}`); + }); + + await avSession.castAudio(sessionToken, audioDevices).then(() => { + console.info('Cast audio to remote'); + }).catch((err) => { + console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0200 + * @tc.name : CAST_AUDIO_PROMISE_0200 + * @tc.desc : Testing cast audio with all session + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_PROMISE_0200', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + sessionId = session.sessionId; + sessionToken = { sessionId, pid, uid }; + }).catch((err) => { + console.info(`Session create BusinessError: ${err.code}, message: ${err.message}`); + }); + + await avSession.castAudio('all', audioDevices).then(() => { + console.info('Cast audio to remote'); + }).catch((err) => { + console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + }); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0100 + * @tc.name : CAST_AUDIO_CALLBACK_0100 + * @tc.desc : Testing cast audio + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0100', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + sessionId = session.sessionId; + sessionToken = { sessionId, pid, uid }; + }).catch((err) => { + console.info(`Session create BusinessError: ${err.code}, message: ${err.message}`); + }); + + avSession.castAudio(sessionToken, audioDevices, (err) => { + if (err) { + console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info('Cast audio to remote device'); + } + }); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + }); + done(); + }) + + /* * + * @tc.number : SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0200 + * @tc.name : CAST_AUDIO_CALLBACK_0200 + * @tc.desc : Testing cast audio + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level2 + */ + it('SUB_MULTIMEDIA_AVSESSION_CAST_AUDIO_CALLBACK_0200', 0, async function (done) { + await avSession.createAVSession(context, tag, type).then((data) => { + session = data; + sessionId = session.sessionId; + sessionToken = { sessionId, pid, uid }; + }).catch((err) => { + console.info(`Session create BusinessError: ${err.code}, message: ${err.message}`); + }); + + avSession.castAudio('all', audioDevices, (err) => { + if (err) { + console.info(`Cast audio to remote BusinessError: ${err.code}, message: ${err.message}`); + expect(true).assertTrue(); + } else { + console.info('Cast audio to remote device'); + } + }); + + await session.destroy().then(() => { + console.info('TestLog: Session Destroy SUCCESS'); + }).catch((err) => { + console.info(`TestLog: Session Destroy error: code: ${err.code}, message: ${err.message}`); + }); + done(); + }) }) } \ No newline at end of file diff --git a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js old mode 100644 new mode 100755 index 25bf126a2..51cdab9c8 --- a/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js +++ b/multimedia/avsession/avsession_js_standard/avsessionManager/src/main/js/test/List.test.js @@ -18,6 +18,7 @@ import AVSessionManager from './AVSessionManager.test.js'; import AVSessionCallback from './AVSessionCallback.test.js'; import AVSessionControllerCallback from './AVSessionControllerCallback.test.js'; import AVSessionManagerCallback from './AVSessionManagerCallback.test.js'; +import AVSessionErrorCode from './AVSessionErrorCode.test'; export default function testsuite() { AVSession() @@ -26,4 +27,5 @@ export default function testsuite() { AVSessionCallback() AVSessionControllerCallback() AVSessionManagerCallback() + AVSessionErrorCode() } \ No newline at end of file -- GitLab