diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/List.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/List.test.ets index 38a460a83beb6ff912abe6f8f49b7477fdb1f3db..157eb413b4cf85ceb2d280236bcb2eeff58524b3 100644 --- a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/List.test.ets +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/List.test.ets @@ -14,6 +14,7 @@ */ import apiCoverAbility from './ApiCoverAbility.test' +import newApiCoverAbility from './NewApiCoverAbility.test' import verificationTest from './VerificationTest' import wantAgentCover from './WantAgentCover.test' import contextEnvironmentTest from './ContextEnvironmentTest.test'; @@ -21,6 +22,7 @@ import contextEnvironmentTest from './ContextEnvironmentTest.test'; export default function List() { apiCoverAbility() + newApiCoverAbility() verificationTest() wantAgentCover() contextEnvironmentTest(globalThis.applicationContext) diff --git a/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..97e30ee93cd61b3d6bd46f6ae8a98c4f3ac07e02 --- /dev/null +++ b/ability/ability_runtime/apicover/apicoverhaptest/entry/src/main/ets/test/NewApiCoverAbility.test.ets @@ -0,0 +1,82 @@ +/* + * 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' + +import errorManager from '@ohos.app.ability.errorManager'; + +function sleep(time) { + return new Promise((resolve)=>setTimeout(resolve,time)); +} + +export default function ApiCoverTest() { + describe('NewApiCoverTestTest', function () { + afterEach(async (done) => { + setTimeout(function () { + done(); + }, 2500); + }) + + /* + * @tc.number SUB_AA_ReisterErrorObserver_New_0100 + * @tc.name Test ReisterErrorObserver. + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_ReisterErrorObserver_New_0100', 0, async function (done) { + let errorObserver:errorManager.ErrorObserver; + errorObserver = { + onUnhandledException:(errMessage) => { + console.info("SUB_AA_ReisterErrorObserver_0100" + JSON.stringify(errMessage)); + } + } + try { + let errCodeId = errorManager.on("error", errorObserver) + expect(errCodeId).assertEqual(0) + errorManager.off("error", errCodeId).then((data)=>{ + expect(data).assertEqual(undefined) + done(); + }).catch((err)=>{ + expect().assertFail() + done(); + }) + } catch (error) { + expect().assertFail() + done(); + } + + }); + + /* + * @tc.number SUB_AA_ReisterErrorObserver_0200 + * @tc.name Test unregisterErrorObserver with error number. + * @tc.desc Function test + * @tc.level 3 + */ + it('SUB_AA_ReisterErrorObserver_New_0200', 0, async function (done) { + try { + errorManager.off("error", -1).then((data)=>{ + expect().assertFail() + done(); + }).catch((err)=>{ + expect(err.code).assertEqual(401) + done(); + }) + } catch (error) { + expect().assertFail() + done(); + } + }); + }) +}