diff --git a/multimedia/BUILD.gn b/multimedia/BUILD.gn index 9f9379072783b416ee03cab1967c93cef282c00e..a8fd227ea89239d2dc88bb277188915d5f779adb 100755 --- a/multimedia/BUILD.gn +++ b/multimedia/BUILD.gn @@ -16,11 +16,12 @@ import("//test/xts/tools/build/suite.gni") group("multimedia") { testonly = true if (is_standard_system) { - deps = [ + deps = [ + "audio/audio_js_standard/audioManager:audio_manager_js_hap", "audio/audio_js_standard/audioPlayer:audio_player_js_hap", "audio/audio_js_standard/audioPlayer_API:audio_player_api_js_hap", - "audio/audio_js_standard/audioManager:audio_manager_js_hap", - "media/media_cpp_test_standard:ActsMediaCppStandardTest" + "audio/audio_js_standard/audioRecorder:audio_recorder_js_hap", + "media/media_cpp_test_standard:ActsMediaCppStandardTest", ] } else { deps = [ diff --git a/multimedia/audio/audio_js_standard/audioRecorder/BUILD.gn b/multimedia/audio/audio_js_standard/audioRecorder/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..57f1d57a78afb1dced4b7e96bbe53d6e3da2c945 --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/BUILD.gn @@ -0,0 +1,38 @@ +# Copyright (C) 2021 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("//test/xts/tools/build/suite.gni") +ohos_js_hap_suite("audio_recorder_js_hap") { + hap_profile = "./src/main/config.json" + deps = [ + ":audio_recorder_js_assets", + ":audio_recorder_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "AudioRecorderJsTest" + + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("audio_recorder_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("audio_recorder_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/multimedia/audio/audio_js_standard/audioRecorder/Test.json b/multimedia/audio/audio_js_standard/audioRecorder/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..ea3e47996b3e015c77d3d17efbfa6ea200b68c8c --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/Test.json @@ -0,0 +1,18 @@ +{ + "description": "Configuration for audio manager Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "60000", + "package": "ohos.acts.multimedia.audio.function", + "shell-timeout": "60000" + }, + "kits": [ + { + "test-file-name": [ + "AudioRecorderJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/config.json b/multimedia/audio/audio_js_standard/audioRecorder/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..31b9a1b5a0f828e620d2db6f973f3f8266a176dd --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/config.json @@ -0,0 +1,60 @@ +{ + "app": { + "bundleName": "ohos.acts.multimedia.audio.function", + "vendor": "acts", + "version": { + "code": 1000000, + "name": "1.0.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.multimedia.audio.function", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "ohos.acts.multimedia.audio.function.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:app_name", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} diff --git a/multimedia/media/media_cpp_test_standard/player/include/common.h b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/app.js old mode 100755 new mode 100644 similarity index 68% rename from multimedia/media/media_cpp_test_standard/player/include/common.h rename to multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/app.js index 158035d056ac0a0f20b51305562e15965f0c967f..e0b2e05a461ecda7b070d1bb20829b7bde8d5a8a --- a/multimedia/media/media_cpp_test_standard/player/include/common.h +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/app.js @@ -1,18 +1,25 @@ -/* - * Copyright (C) 2021 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. - */ - -#ifndef DISABLE_COMMON_TEST_H -#define DISABLE_COMMON_TEST_H -#endif \ No newline at end of file +/* + * Copyright (C) 2021 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 device from '@system.device'; + +export default { + onCreate() { + console.info('AceApplication onCreate'); + }, + onDestroy() { + console.info('AceApplication onDestroy'); + } +}; diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/i18n/en-US.json b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/i18n/zn-CN.json b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/i18n/zn-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/i18n/zn-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.css b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.hml b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.js b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..770b1218eb08c0c46fed349f0f5baff40c02f215 --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/pages/index/index.js @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2021 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 app from '@system.app' +import {Core, ExpectExtend} from 'deccjsunit/index' + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + core.init() + const configService = core.getDefaultService('config') + configService.setConfig(this) + + require('../../test/List.test') + core.execute() + }, + onReady() { + }, +} \ No newline at end of file diff --git a/multimedia/media/media_cpp_test_standard/player/include/Testplayer.h b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/List.test.js old mode 100755 new mode 100644 similarity index 79% rename from multimedia/media/media_cpp_test_standard/player/include/Testplayer.h rename to multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/List.test.js index c7099d4cb9b73c19ae13671386a4e4f25243d715..489ace8762489266f6c1ec3cc2e287535fa36e1c --- a/multimedia/media/media_cpp_test_standard/player/include/Testplayer.h +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/List.test.js @@ -1,18 +1,17 @@ -/* - * Copyright (C) 2021 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. - */ - -#ifndef DISABLE_PLAYER_TEST_H -#define DISABLE_PLAYER_TEST_H -#endif \ No newline at end of file +/* + * Copyright (C) 2021 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. + */ + +require('./RecorderLocalTestAudioFUNC.test.js') +require('./RecorderLocalTestAudioAPI.test.js') \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/RecorderLocalTestAudioAPI.test.js b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/RecorderLocalTestAudioAPI.test.js new file mode 100644 index 0000000000000000000000000000000000000000..cff24bbbde551cd449d363c27d2eeb2df59ffc73 --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/RecorderLocalTestAudioAPI.test.js @@ -0,0 +1,638 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('RecorderLocalTestAudioAPI', function () { + let audioRecorder = media.createAudioRecorder(); + let isTimeOut = false; + const END_STATE = 0; + const PRE_STATE = 1; + const START_STATE = 2; + const PAUSE_STATE = 3; + const RESUME_STATE = 4; + const STOP_STATE = 5; + const RESET_STATE = 6; + const RELEASE_STATE = 7; + const ERROR_STATE = 8; + const TIME_OUT = 15000; // 15s + const FORMAT_M4A = 6; + const SOURCE_TYPE = 1; + const ENCORDER_AACLC = 3; + const CHANNEL_TWO = 2; + let audioConfig = { + audioSourceType : SOURCE_TYPE, + audioEncoder : ENCORDER_AACLC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : CHANNEL_TWO, + format : FORMAT_M4A, + uri : 'file:///data/accounts/account_0/appdata/recorder/testAPI.m4a', + location : { latitude : 1, longitude : 1 }, + } + + function initAudioRecorder() { + if (typeof (audioRecorder) != 'undefined') { + audioRecorder.release(); + audioRecorder = undefined; + } + audioRecorder = media.createAudioRecorder(); + } + + function nextStep(mySteps) { + if (mySteps[0] == END_STATE) { + console.info('case end!!!'); + isTimeOut = true; + return; + } + switch (mySteps[0]) { + case PRE_STATE: + console.info('case to prepare'); + audioRecorder.prepare(audioConfig); + break; + case START_STATE: + console.info('case to start'); + audioRecorder.start(); + break; + case PAUSE_STATE: + console.info('case to pause'); + audioRecorder.pause(); + break; + case RESUME_STATE: + console.info('case to resume'); + audioRecorder.resume(); + break; + case STOP_STATE: + console.info('case to stop'); + audioRecorder.stop(); + break; + case RESET_STATE: + console.info('case to reset'); + audioRecorder.reset(); + break; + case RELEASE_STATE: + console.info('case to release'); + audioRecorder.release(); + break; + case ERROR_STATE: + console.info('case to wait error callback'); + break; + default: + break; + } + } + + function setErrorCallback(mySteps) { + audioRecorder.on('error', (err) => { + console.info(`case error called,errName is ${err.name}`); + console.info(`case error called,errCode is ${err.code}`); + console.info(`case error called,errMessage is ${err.message}`); + console.info('case err returned in error() case callback'); + mySteps.shift(); + expect(mySteps[0]).assertEqual(ERROR_STATE); + mySteps.shift(); + nextStep(mySteps); + }); + } + + function setCallback(mySteps, done) { + audioRecorder.on('prepare', () => { + console.info('setCallback prepare() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('start', () => { + console.info('setCallback start() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('pause', () => { + console.info('setCallback pause() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('resume', () => { + console.info('setCallback resume() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('stop', () => { + console.info('setCallback stop() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('reset', () => { + console.info('setCallback reset() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('release', () => { + console.info('setCallback release() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + audioRecorder = undefined; + }); + + setErrorCallback(mySteps); + setTimeout(function() { + if (!isTimeOut) { + console.info('case is time out!'); + expect(isTimeOut).assertTrue(); + } + mySteps = undefined; + done(); + }, TIME_OUT); + } + + beforeAll(function () { + console.info('beforeAll case'); + }) + + beforeEach(function () { + isTimeOut = false; + console.info('beforeEach case'); + }) + + afterEach(function () { + console.info('afterEach case'); + }) + + afterAll(function () { + console.info('afterAll case'); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_createAudioRecorder_API_0100 + * @tc.name : Create an AudioRecoder Object by function of createAudioRecorder + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_createAudioRecorder_API_0100', 0, async function (done) { + let testAudioRecorder; + expect(testAudioRecorder).assertNull(); + testAudioRecorder= media.createAudioRecorder(); + expect(testAudioRecorder != undefined).assertTrue(); + done(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0100 + * @tc.name : 01.creatAudioRecorder->prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0100', 0, async function (done) { + let testAudioRecorder= media.createAudioRecorder(); + expect(testAudioRecorder != null).assertTrue(); + testAudioRecorder.prepare(audioConfig); + done(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0200 + * @tc.name : 02.start->prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0200', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(START_STATE, ERROR_STATE, PRE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.start(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0500 + * @tc.name : 05.stop->prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0500', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RESET_STATE, PRE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0600 + * @tc.name : 06.reset->prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0600', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, PRE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0800 + * @tc.name : 08.all steps->prepare + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0800', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, PRE_STATE, ERROR_STATE, STOP_STATE, + PRE_STATE, RESET_STATE, PRE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0900 + * @tc.name : 09.prepare called three times + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Prepare_API_0900', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, PRE_STATE, ERROR_STATE, PRE_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0100 + * @tc.name : 01.creatAudioRecorder->start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0100', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(START_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.start(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0200 + * @tc.name : 02.prepare->start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0200', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0500 + * @tc.name : 05.stop->start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0500', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, START_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0600 + * @tc.name : 06.reset->start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0600', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, START_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0800 + * @tc.name : 08.all steps->start + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0800', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, START_STATE, ERROR_STATE, + PRE_STATE, START_STATE, RESET_STATE, START_STATE, ERROR_STATE, PRE_STATE, START_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0900 + * @tc.name : 09.start called three times + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Start_API_0900', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, START_STATE, START_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0100 + * @tc.name : 01.creatAudioRecorder->stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0100', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(STOP_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.stop(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0200 + * @tc.name : 02.prepare->stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0200', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, STOP_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0300 + * @tc.name : 03.start->stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0300', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0600 + * @tc.name : 06.reset->stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0600', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, STOP_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0800 + * @tc.name : 08.all steps->stop + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0800', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, STOP_STATE, ERROR_STATE, RESET_STATE, PRE_STATE, START_STATE, STOP_STATE, + RESET_STATE, PRE_STATE, RESET_STATE, STOP_STATE, ERROR_STATE, PRE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0900 + * @tc.name : 09.stop called three times + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Stop_API_0900', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, STOP_STATE, ERROR_STATE, + STOP_STATE, ERROR_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0100 + * @tc.name : 01.creatAudioRecorder->reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0100', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(RESET_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.reset(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0200 + * @tc.name : 02.prepare->reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0200', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, RESET_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0300 + * @tc.name : 03.start->reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0300', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0600 + * @tc.name : 06.stop->reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0600', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RESET_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0800 + * @tc.name : 08.all steps->reset + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0800', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, RESET_STATE, PRE_STATE, START_STATE, RESET_STATE, PRE_STATE, START_STATE, + STOP_STATE, RESET_STATE, PRE_STATE, START_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0900 + * @tc.name : 09.reset callend three times + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Reset_API_0900', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, RESET_STATE, RESET_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0100 + * @tc.name : 01.creatAudioRecorder->release + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0100', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.release(); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0200 + * @tc.name : 02.prepare->release + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0200', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0300 + * @tc.name : 03.start->release + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0300', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0600 + * @tc.name : 06.stop->release + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0600', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0700 + * @tc.name : 07.reset->release + * @tc.desc : Reliability Test + * @tc.size : MediumTest + * @tc.type : Reliability + * @tc.level : Level2 + */ + it('SUB_MEDIA_RECORDER_AudioRecorder_Release_API_0700', 0, async function (done) { + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) +}) \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/RecorderLocalTestAudioFUNC.test.js b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/RecorderLocalTestAudioFUNC.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ad6b610e5b018e84fa53634a57a74abf765e947e --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/js/default/test/RecorderLocalTestAudioFUNC.test.js @@ -0,0 +1,524 @@ +/* + * Copyright (C) 2021 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 media from '@ohos.multimedia.media' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' + +describe('RecorderLocalTestAudioFUNC', function () { + let audioRecorder = media.createAudioRecorder(); + let isTimeOut = false; + const BASIC_PATH = 'file:///data/accounts/account_0/appdata/recorder/' + const END_STATE = 0; + const PRE_STATE = 1; + const START_STATE = 2; + const PAUSE_STATE = 3; + const RESUME_STATE = 4; + const STOP_STATE = 5; + const RESET_STATE = 6; + const RELEASE_STATE = 7; + const ERROR_STATE = 8; + const RECORDER_TIME = 5000; + const TIME_OUT = 20000; // 20s + const CHANNEL_ONE = 1; + const CHANNEL_TWO = 2; + const FORMAT_MP4 = 2; + const FORMAT_M4A = 6; + const SOURCE_TYPE = 1; + const ENCORDER_AACLC = 3; + let audioConfig = { + audioSourceType : SOURCE_TYPE, + audioEncoder : ENCORDER_AACLC, + audioEncodeBitRate : 22050, + audioSampleRate : 22050, + numberOfChannels : CHANNEL_TWO, + format : FORMAT_M4A, + uri : 'file:///data/accounts/account_0/appdata/appdata/recorder/test.m4a', + location : { latitude : 1, longitude : 1 }, + } + + function sleep(time) { + for(let t = Date.now();Date.now() - t <= time;); + }; + + function initAudioRecorder() { + if (typeof (audioRecorder) != 'undefined') { + audioRecorder.release(); + audioRecorder = undefined; + } + audioRecorder = media.createAudioRecorder(); + } + + beforeAll(function () { + console.info('beforeAll case'); + }) + + beforeEach(function () { + isTimeOut = false; + console.info('beforeEach case'); + }) + + afterEach(function () { + console.info('afterEach case'); + }) + + afterAll(function () { + console.info('afterAll case'); + }) + + function nextStep(mySteps) { + if (mySteps[0] == END_STATE) { + isTimeOut = true; + return; + } + switch (mySteps[0]) { + case PRE_STATE: + console.info('case to prepare'); + audioRecorder.prepare(audioConfig); + break; + case START_STATE: + console.info('case to start'); + audioRecorder.start(); + break; + case PAUSE_STATE: + console.info('case to pause'); + audioRecorder.pause(); + break; + case RESUME_STATE: + console.info('case to resume'); + audioRecorder.resume(); + break; + case STOP_STATE: + console.info('case to stop'); + audioRecorder.stop(); + break; + case RESET_STATE: + console.info('case to reset'); + audioRecorder.reset(); + break; + case RELEASE_STATE: + console.info('case to release'); + audioRecorder.release(); + break; + case ERROR_STATE: + console.info('case to wait error callback'); + break; + default: + break; + } + } + + function setErrorCallback(mySteps) { + audioRecorder.on('error', (err) => { + console.info(`case error called,errName is ${err.name}`); + console.info(`case error called,errCode is ${err.code}`); + console.info(`case error called,errMessage is ${err.message}`); + mySteps.shift(); + expect(mySteps[0]).assertEqual(ERROR_STATE); + mySteps.shift(); + nextStep(mySteps); + }); + } + + function setCallback(mySteps, done) { + audioRecorder.on('prepare', () => { + console.info('setCallback prepare() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('start', () => { + console.info('setCallback start() case callback is called'); + sleep(RECORDER_TIME); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('pause', () => { + console.info('setCallback pause() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('resume', () => { + console.info('setCallback resume() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('stop', () => { + console.info('setCallback stop() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('reset', () => { + console.info('setCallback reset() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + audioRecorder.on('release', () => { + console.info('setCallback release() case callback is called'); + mySteps.shift(); + nextStep(mySteps); + }); + + setErrorCallback(mySteps); + setTimeout(function() { + if (!isTimeOut) { + console.info('case is time out!'); + expect(isTimeOut).assertTrue(); + } + mySteps = undefined; + done(); + }, TIME_OUT); + } + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0100 + * @tc.name : 01.AAC + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0100', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test1.m4a'; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0210 + * @tc.name : 02.AAC_Different Channels 1 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0210', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test2.m4a'; + audioConfig.numberOfChannels = CHANNEL_ONE; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0220 + * @tc.name : 02.AAC_Different Channels 2 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0220', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test3.m4a'; + audioConfig.numberOfChannels = CHANNEL_TWO; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0310 + * @tc.name : 03.AAC_DifferentSampleRate 8000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0310', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test4.m4a'; + audioConfig.audioSampleRate = 8000; // samplerate 8000 + audioConfig.numberOfChannels = CHANNEL_TWO; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0320 + * @tc.name : 03.AAC_DifferentSampleRate 32000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0320', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test5.mp4'; + audioConfig.audioSampleRate = 32000; // samplerate 32000 + audioConfig.numberOfChannels = CHANNEL_ONE; + audioConfig.fileFormat = FORMAT_MP4; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0330 + * @tc.name : 03.AAC_DifferentSampleRate 44100 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0330', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test6.mp4'; + audioConfig.audioSampleRate = 44100; // samplerate 44100 + audioConfig.numberOfChannels = CHANNEL_TWO; + audioConfig.fileFormat = FORMAT_MP4; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0340 + * @tc.name : 03.AAC_DifferentSampleRate 64000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0340', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test7.m4a'; + audioConfig.audioSampleRate = 64000; // samplerate 64000 + audioConfig.numberOfChannels = CHANNEL_ONE; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0350 + * @tc.name : 03.AAC_DifferentSampleRate 96000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0340', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test8.m4a'; + audioConfig.audioSampleRate = 96000; // samplerate 96000 + audioConfig.numberOfChannels = CHANNEL_TWO; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0410 + * @tc.name : 04.AAC_DifferentBitrate 8000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0410', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test9.mp4'; + audioConfig.audioSampleRate = 22050; // samplerate 22050 + audioConfig.audioEncodeBitRate = 8000; // encodeBitrate 8000 + audioConfig.numberOfChannels = CHANNEL_TWO; + audioConfig.fileFormat = FORMAT_MP4; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0420 + * @tc.name : 04.AAC_DifferentBitrate 16000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0420', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test10.mp4'; + audioConfig.audioSampleRate = 44100; // samplerate 44100 + audioConfig.audioEncodeBitRate = 16000; // encodeBitrate 16000 + audioConfig.numberOfChannels = CHANNEL_ONE; + audioConfig.fileFormat = FORMAT_MP4; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0430 + * @tc.name : 04.AAC_DifferentBitrate 32000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0430', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test11.m4a'; + audioConfig.audioSampleRate = 44100; // samplerate 44100 + audioConfig.audioEncodeBitRate = 32000; // encodeBitrate 32000 + audioConfig.numberOfChannels = CHANNEL_ONE; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0440 + * @tc.name : 04.AAC_DifferentBitrate 64000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0440', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test12.m4a'; + audioConfig.audioSampleRate = 44100; // samplerate 44100 + audioConfig.audioEncodeBitRate = 64000; // encodeBitrate 64000 + audioConfig.numberOfChannels = CHANNEL_TWO; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Codec_AAC_Function_0450 + * @tc.name : 04.AAC_DifferentBitrate 112000 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Codec_AAC_Function_0450', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test13.m4a'; + audioConfig.audioSampleRate = 44100; // samplerate 44100 + audioConfig.audioEncodeBitRate = 112000; // encodeBitrate 112000 + audioConfig.numberOfChannels = CHANNEL_TWO; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Format_MP4_Function_0200 + * @tc.name : 02.AAC,mp4 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Format_MP4_Function_0200', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test14.mp4'; + audioConfig.audioEncodeBitRate = 22050; // samplerate 22050 + audioConfig.audioSampleRate = 22050; // encodeBitrate 22050 + audioConfig.fileFormat = FORMAT_MP4; + audioConfig.numberOfChannels = CHANNEL_TWO; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_Format_M4A_Function_0200 + * @tc.name : 02.AAC,mp4 + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_Format_MP4_Function_0200', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test15.m4a'; + audioConfig.audioEncodeBitRate = 22050; // samplerate 22050 + audioConfig.audioSampleRate = 22050; // encodeBitrate 22050 + audioConfig.fileFormat = FORMAT_M4A; + audioConfig.numberOfChannels = CHANNEL_TWO; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_LOCAL_AUDIO_Function_06_0100 + * @tc.name : 001.start + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_LOCAL_AUDIO_Function_06_0100', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test16.m4a'; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_LOCAL_AUDIO_Function_06_0500 + * @tc.name : 005.reset + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_LOCAL_AUDIO_Function_06_0500', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test17.m4a'; + audioConfig.fileFormat = FORMAT_M4A; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) + + /* * + * @tc.number : SUB_MEDIA_RECORDER_LOCAL_AUDIO_Function_06_1100 + * @tc.name : 011.start->reset->start->stop + * @tc.desc : Audio recordr control test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level0 + */ + it('SUB_MEDIA_RECORDER_LOCAL_AUDIO_Function_06_1100', 0, async function (done) { + audioConfig.uri = BASIC_PATH + 'test18.mp4'; + audioConfig.fileFormat = FORMAT_MP4; + initAudioRecorder(); + let mySteps = new Array(PRE_STATE, START_STATE, RESET_STATE, PRE_STATE, + START_STATE, STOP_STATE, RELEASE_STATE, END_STATE); + setCallback(mySteps, done); + audioRecorder.prepare(audioConfig); + }) +}) \ No newline at end of file diff --git a/multimedia/audio/audio_js_standard/audioRecorder/src/main/resources/base/element/string.json b/multimedia/audio/audio_js_standard/audioRecorder/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..2f9470d82c49675a64972657d8d367cd95e51c63 --- /dev/null +++ b/multimedia/audio/audio_js_standard/audioRecorder/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h b/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h index 9269d8ca0b9fae5cd2287593b22b26ec1f5bf114..7dd477ceca45eaddcfa82980461db10fb23d3b58 100644 --- a/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h +++ b/multimedia/media/media_cpp_test_standard/player/include/TestPlayer.h @@ -1,120 +1,120 @@ -/* - * Copyright (C) 2021 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. - */ - -#ifndef PLAYER_TEST_H -#define PLAYER_TEST_H - -#include "securec.h" -#include "TestParamsConfig.h" -#include "window_manager.h" -#include "surface_type.h" -#include "display_type.h" - -namespace OHOS { -namespace Media { -static const std::string SURFACE_STRIDE_ALIGNMENT = "SURFACE_STRIDE_ALIGNMENT"; -static const std::string SURFACE_FORMAT = "SURFACE_FORMAT"; -static WindowConfig g_config = { - 1920, - 1080, - PIXEL_FMT_RGBA_8888, - 0, - 0, - WINDOW_TYPE_NORMAL -}; -static WindowConfig g_sub_config = { - 720, - 480, - PIXEL_FMT_YCRCB_420_SP, - 0, - 0, - WINDOW_TYPE_VIDEO, -}; - -class PlayerSignal { -public: - PlayerStates state_ = PLAYER_IDLE; - int32_t seekPositon_; - bool seekDoneFlag_; - bool mutexFlag_ = true; - std::mutex mutexSeek_; - std::mutex mutexReset_; - std::mutex mutexPrepare_; - std::mutex mutexPlay_; - std::mutex mutexPause_; - std::mutex mutexStop_; - std::condition_variable condVarSeek_; - std::condition_variable condVarReset_; - std::condition_variable condVarPrepare_; - std::condition_variable condVarPlay_; - std::condition_variable condVarPause_; - std::condition_variable condVarStop_; - - void SetState(PlayerStates state); - void SetSeekResult(bool seekDoneFlag); -}; -class TestPlayer { -public: - std::shared_ptr player_ = nullptr; - sptr window_ = nullptr; - explicit TestPlayer(std::shared_ptr test); - virtual ~TestPlayer(); - bool CreatePlayer(); - int32_t SetSource(const std::string &uri); - int32_t SetDataSrc(const std::string &uri, bool seekable); - int32_t Play(); - int32_t Prepare(); - int32_t PrepareAsync(); - int32_t Pause(); - int32_t Stop(); - int32_t Reset(); - int32_t Release(); - int32_t SetVolume(float leftVolume, float rightVolume); - int32_t Seek(int32_t mseconds, PlayerSeekMode mode); - int32_t GetCurrentTime(int32_t ¤tTime); - int32_t GetDuration(int32_t &duration); - int32_t SetPlaybackSpeed(PlaybackRateMode mode); - int32_t GetPlaybackSpeed(PlaybackRateMode &mode); - sptr GetVideoSurface(WindowConfig g_sub_config); - int32_t SetVideoSurface(sptr surface); - bool IsPlaying(); - bool IsLooping(); - int32_t SetLooping(bool loop); - int32_t SetPlayerCallback(const std::shared_ptr &callback); -private: - std::shared_ptr test_; -}; -class TestPlayerCallback : public PlayerCallback { -public: - int errorNum_ = 0; - PlayerStates state_ = PLAYER_STATE_ERROR; - explicit TestPlayerCallback(std::shared_ptr test); - virtual ~TestPlayerCallback(); - void OnError(PlayerErrorType errorType, int32_t errorCode); - int WaitForSeekDone(int32_t currentPositon); - void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}); - int WaitForState(PlayerStates state); -private: - void PrintState(PlayerStates state); - - PlayerErrorType errorType_ = PLAYER_ERROR_UNKNOWN; - int32_t errorCode_ = -1; - bool seekDoneFlag_ = false; - int32_t postion_ = 0; - std::shared_ptr test_; -}; -} -} +/* + * Copyright (C) 2021 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. + */ + +#ifndef PLAYER_TEST_H +#define PLAYER_TEST_H + +#include "securec.h" +#include "TestParamsConfig.h" +#include "window_manager.h" +#include "surface_type.h" +#include "display_type.h" + +namespace OHOS { +namespace Media { +static const std::string SURFACE_STRIDE_ALIGNMENT = "SURFACE_STRIDE_ALIGNMENT"; +static const std::string SURFACE_FORMAT = "SURFACE_FORMAT"; +static WindowConfig g_config = { + 1920, + 1080, + PIXEL_FMT_RGBA_8888, + 0, + 0, + WINDOW_TYPE_NORMAL +}; +static WindowConfig g_sub_config = { + 720, + 480, + PIXEL_FMT_YCRCB_420_SP, + 0, + 0, + WINDOW_TYPE_VIDEO, +}; + +class PlayerSignal { +public: + PlayerStates state_ = PLAYER_IDLE; + int32_t seekPositon_; + bool seekDoneFlag_; + bool mutexFlag_ = true; + std::mutex mutexSeek_; + std::mutex mutexReset_; + std::mutex mutexPrepare_; + std::mutex mutexPlay_; + std::mutex mutexPause_; + std::mutex mutexStop_; + std::condition_variable condVarSeek_; + std::condition_variable condVarReset_; + std::condition_variable condVarPrepare_; + std::condition_variable condVarPlay_; + std::condition_variable condVarPause_; + std::condition_variable condVarStop_; + + void SetState(PlayerStates state); + void SetSeekResult(bool seekDoneFlag); +}; +class TestPlayer { +public: + std::shared_ptr player_ = nullptr; + sptr window_ = nullptr; + explicit TestPlayer(std::shared_ptr test); + virtual ~TestPlayer(); + bool CreatePlayer(); + int32_t SetSource(const std::string &uri); + int32_t SetDataSrc(const std::string &uri, bool seekable); + int32_t Play(); + int32_t Prepare(); + int32_t PrepareAsync(); + int32_t Pause(); + int32_t Stop(); + int32_t Reset(); + int32_t Release(); + int32_t SetVolume(float leftVolume, float rightVolume); + int32_t Seek(int32_t mseconds, PlayerSeekMode mode); + int32_t GetCurrentTime(int32_t ¤tTime); + int32_t GetDuration(int32_t &duration); + int32_t SetPlaybackSpeed(PlaybackRateMode mode); + int32_t GetPlaybackSpeed(PlaybackRateMode &mode); + sptr GetVideoSurface(WindowConfig g_sub_config); + int32_t SetVideoSurface(sptr surface); + bool IsPlaying(); + bool IsLooping(); + int32_t SetLooping(bool loop); + int32_t SetPlayerCallback(const std::shared_ptr &callback); +private: + std::shared_ptr test_; +}; +class TestPlayerCallback : public PlayerCallback { +public: + int errorNum_ = 0; + PlayerStates state_ = PLAYER_STATE_ERROR; + explicit TestPlayerCallback(std::shared_ptr test); + virtual ~TestPlayerCallback(); + void OnError(PlayerErrorType errorType, int32_t errorCode); + int WaitForSeekDone(int32_t currentPositon); + void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody = {}); + int WaitForState(PlayerStates state); +private: + void PrintState(PlayerStates state); + + PlayerErrorType errorType_ = PLAYER_ERROR_UNKNOWN; + int32_t errorCode_ = -1; + bool seekDoneFlag_ = false; + int32_t postion_ = 0; + std::shared_ptr test_; +}; +} +} #endif \ No newline at end of file