From be2c990398cfce9c662cc7d63be54d9577555622 Mon Sep 17 00:00:00 2001 From: lwx1121892 Date: Wed, 15 Feb 2023 15:51:26 +0800 Subject: [PATCH] Signed-off-by: lwx1121892 --- .../main/js/test/AudioRoutingManager.test.js | 329 ++++++++++++++++++ .../src/main/js/test/List.test.js | 2 + 2 files changed, 331 insertions(+) create mode 100644 multimedia/audio/audio_js_standard/audioManager/src/main/js/test/AudioRoutingManager.test.js diff --git a/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/AudioRoutingManager.test.js b/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/AudioRoutingManager.test.js new file mode 100644 index 000000000..8e6d13fb5 --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/AudioRoutingManager.test.js @@ -0,0 +1,329 @@ +/* + * Copyright (c) 2023 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 audio from '@ohos.multimedia.audio'; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from '@ohos/hypium'; +export default function audioRoutingManager() { + +const TAG = "[AudioRoutingManagerJsTest]"; +const stringParameter = 'stringParameter'; +const numberParameter = 12345678; + +describe("AudioRoutingManagerJsTest", function () { + + beforeAll(async function () { + + console.info(TAG + "beforeAll called"); + }) + + afterAll(function () { + console.info(TAG + 'afterAll called') + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach called') + }) + + afterEach(function () { + console.info(TAG + 'afterEach called') + }) + + function sleep(time) { + return new Promise((resolve) => setTimeout(resolve, time)); + } + + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 + *@tc.name : Get prefer output device - promise + *@tc.desc : Get prefer output device - promise + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETPREFEROUTUTDEVICEFORRENDERERINFOTEST_0100", 0, async function (done) { + let rendererInfo = { + content : audio.ContentType.CONTENT_TYPE_MUSIC, + usage : audio.StreamUsage.STREAM_USAGE_MEDIA, + rendererFlags : 0 } + + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + let data = await routingManager.getPreferOutputDeviceForRendererInfo(rendererInfo); + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 SUCCESS`+JSON.stringify(data)); + expect(true).assertTrue(); + done(); + } catch(e) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + }) + + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 + *@tc.name : Get prefer output device no parameter- promise + *@tc.desc : Get prefer output device no parameter- promise + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0200", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + let data = await routingManager.getPreferOutputDeviceForRendererInfo(); + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 parameter check ERROR: ${JSON.stringify(data)}`); + expect().assertFail(); + } catch(e) { + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 check no parameter PASS`); + expect(true).assertTrue(); + } + done(); + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 + *@tc.name : Get prefer output device check number parameter- promise + *@tc.desc : Get prefer output device check number parameter- promise + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0300", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + let data = await routingManager.getPreferOutputDeviceForRendererInfo(numberParameter); + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETPREFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 parameter check ERROR: `+JSON.stringify(data)); + expect().assertFail(); + } catch(e) { + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 check number parameter PASS`); + expect(true).assertTrue(); + } + done(); + }) + + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0400 + *@tc.name : Get prefer output device check string parameter- promise + *@tc.desc : Get prefer output device check string parameter- promise + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0400", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + let data = await routingManager.getPreferOutputDeviceForRendererInfo(stringParameter); + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0400 parameter check ERROR: `+JSON.stringify(data)); + expect().assertFail(); + } catch(e) { + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0400 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0400 check string parameter PASS`); + expect(true).assertTrue(); + } + done(); + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0500 + *@tc.name : Get prefer output device - callback + *@tc.desc : Get prefer output device - callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0500", 0, async function (done) { + let rendererInfo = { + content : audio.ContentType.CONTENT_TYPE_MUSIC, + usage : audio.StreamUsage.STREAM_USAGE_MEDIA, + rendererFlags : 0 } + + let routingManager = audio.getAudioManager().getRoutingManager(); + routingManager.getPreferOutputDeviceForRendererInfo(rendererInfo, (e, data)=>{ + if (e) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0500 ERROR: ${e.message}`); + expect(false).assertTrue(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0500 SUCCESS`); + expect(true).assertTrue(); + done(); + }); + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETPREFEROUTPUTDEVICEFORRENDERERINFOTEST_0600 + *@tc.name : Get prefer output device check number parameter- callback + *@tc.desc : Get prefer output device check number parameter- callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0600", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + routingManager.getPreferOutputDeviceForRendererInfo(numberParameter, (e, data)=>{ + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0600 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0600 check number parameter PASS`); + expect(true).assertTrue(); + done(); + }); + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0700 + *@tc.name : Get prefer output device check number parameter- callback + *@tc.desc : Get prefer output device check number parameter- callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0700", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + routingManager.getPreferOutputDeviceForRendererInfo(stringParameter, (e, data)=>{ + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0700 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_GETREFEROUTPUTDEVICEFORRENDERERINFOTEST_0700 check string parameter PASS`); + expect(true).assertTrue(); + done(); + }); + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 + *@tc.name : Get prefer output device check number parameter- callback + *@tc.desc : Get prefer output device check number parameter- callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0100", 0, async function (done) { + let rendererInfo = { + content : audio.ContentType.CONTENT_TYPE_MUSIC, + usage : audio.StreamUsage.STREAM_USAGE_MEDIA, + rendererFlags : 0 } + + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + routingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (data)=>{}); + expect(true).assertTrue(); + done(); + } catch (e) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 + *@tc.name : On prefer output device check string parameter- callback + *@tc.desc : On prefer output device check string parameter- callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0200", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + routingManager.on('preferOutputDeviceChangeForRendererInfo', stringParameter, (data)=>{}); + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 with string patameter ERROR: ${e.message}`); + expect().assertFail(); + done(); + } catch (e) { + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 check string parameter ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0200 PASS: ${e.message}`); + expect(true).assertTrue(); + done(); + } + }) + + /** + *@tc.number : SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 + *@tc.name : On prefer output device check number parameter- callback + *@tc.desc : On prefer output device check number parameter- callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0300", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + routingManager.on('preferOutputDeviceChangeForRendererInfo', numberParameter, (data)=>{}); + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 with number patameter ERROR: ${e.message}`); + expect().assertFail(); + done(); + } catch (e) { + if (e.code != audio.AudioErrors.ERROR_INVALID_PARAM) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 check number parameter ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_ON_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0300 PASS: ${e.message}`); + expect(true).assertTrue(); + done(); + } + }) + + /** + *@tc.number : s + *@tc.name : Off prefer output device - callback + *@tc.desc : Off prefer output device - callback + *@tc.size : MEDIUM + *@tc.type : Function + *@tc.level : Level 0 + */ + it("SUB_MULTIMEDIA_AUDIO_OFF_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0100", 0, async function (done) { + let routingManager = audio.getAudioManager().getRoutingManager(); + try { + routingManager.off('preferOutputDeviceChangeForRendererInfo', (data)=>{}); + console.info(`${TAG} SUB_MULTIMEDIA_AUDIO_OFF_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 SUCCESS`); + expect(true).assertTrue(); + done(); + } catch (e) { + console.error(`${TAG} SUB_MULTIMEDIA_AUDIO_OFF_REFEROUTPUTDEVICEFORRENDERERINFOTEST_0100 ERROR: ${e.message}`); + expect().assertFail(); + done(); + } + }) + +}) +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/List.test.js b/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/List.test.js index 4e1b933bc..c2e8b6391 100644 --- a/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/List.test.js +++ b/multimedia/audio/audio_js_standard/audioManager/src/main/js/test/List.test.js @@ -15,10 +15,12 @@ import audioFramework from './AudioFramework.test.js' import audioManagerApi9 from './AudioManagerApi9.test.js' + import audioRoutingManager from './AudioRoutingManager.test.js' export default function testsuite() { audioFramework() audioManagerApi9() + audioRoutingManager() } -- GitLab