From 2299d917f562770c1977e50ea74690719f355eef Mon Sep 17 00:00:00 2001 From: zhangfuzhi Date: Sat, 7 Jan 2023 10:45:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E7=B3=BB=E4=BA=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=94=A8=E4=BE=8B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangfuzhi --- .../src/main/js/test/CallManageAll.test.js | 619 ++-- .../src/main/js/test/List.test.js | 6 +- .../src/main/js/test/ObjectInterface_test.js | 3194 ++++++++--------- .../src/main/js/test/lib/ApiToPromise.js | 40 - .../js/test/lib/ApiToPromisePerfomance.js | 139 - .../js/test/lib/ApiToPromiseReliability.js | 131 - .../src/main/js/test/lib/Const.js | 228 -- .../src/main/js/test/lib/ScenceInCalling.js | 684 ---- .../main/js/test/lib/ScenceLimitCalling.js | 57 - .../src/main/js/test/lib/ScenceTransfer.js | 48 - 10 files changed, 1848 insertions(+), 3298 deletions(-) delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromise.js delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromisePerfomance.js delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromiseReliability.js delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/Const.js delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceInCalling.js delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceLimitCalling.js delete mode 100644 telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceTransfer.js diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/CallManageAll.test.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/CallManageAll.test.js index 16bc74665..188c84df9 100644 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/CallManageAll.test.js +++ b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/CallManageAll.test.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -14,50 +14,45 @@ */ import call from '@ohos.telephony.call'; -import observer from '@ohos.telephony.observer'; -import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' - -import { - AUTO_ACCEPT_NUMBER, - CALL_STATUS_DIALING, - CALL_STATE_UNKNOWN, - CALL_STATE_IDLE, - DEFAULT_SLOT_ID, - MEDIA_TYPE_VOICE, - DIAL_TYPE_OTT, - TEL_CONFERENCE_IDLE -} from './lib/Const.js'; -import {toString} from './lib/ApiToPromise.js'; -import { - hangupCall, - callId as gloabCallId, - callDetailsChangeOff -} from './lib/ScenceInCalling.js'; - +import { afterEach, describe, expect, it } from '@ohos/hypium'; +const AUTO_ACCEPT_NUMBER = '10010'; +const CALL_STATUS_DIALING = 2; +const DEFAULT_SLOT_ID = 0; +const DIAL_TYPE_OTT = 2; +const MEDIA_TYPE_VOICE = 0; +const TEL_CONFERENCE_IDLE = 0; const ERR_SLOT_ID = -1; -var callState = -1; -var timing = 0; -var endTime = 0; -let callId = null; -class RejectMessageOptions { - constructor (str) { - this.messageContent = str; - } -} class EmergencyNumberOptions { - constructor (num) { + slotId; + + constructor(num) { this.slotId = num; } } + class NumberFormatOptions { - constructor (str) { + countryCode; + + constructor(str) { this.countryCode = str; } } + class CallAttributeOptions { - constructor (accountNumber, speakerphoneOn, accountId, videoState, startTime, - isEcc, callType, callId, callState, conferenceState) { + accountNumber; + speakerphoneOn; + accountId; + videoState; + startTime; + isEcc; + callType; + callId; + callState; + conferenceState; + + constructor(accountNumber, speakerphoneOn, accountId, videoState, startTime, + isEcc, callType, callId, callState, conferenceState) { this.accountNumber = accountNumber; this.speakerphoneOn = speakerphoneOn; this.accountId = accountId; @@ -71,345 +66,307 @@ class CallAttributeOptions { } } -const sleep = (time) => { - return new Promise((resolve, reject) => { - setTimeout(() => { - resolve(); - }, time); - }); -}; - - export default function CallManageImsCall() { -describe('CallManageImsCall', function () { + describe('CallManageImsCall', function () { - afterEach(async function () { - try { - const CURRENT_TIME = new Date().valueOf(); - const TEMP_CALL_ID = 10; - const IS_ECC = true; - const SPEAK_ON = true; - let callAttributeOptions = new CallAttributeOptions(AUTO_ACCEPT_NUMBER, SPEAK_ON, DEFAULT_SLOT_ID, - MEDIA_TYPE_VOICE, CURRENT_TIME, IS_ECC, DIAL_TYPE_OTT, TEMP_CALL_ID, CALL_STATUS_DIALING, - TEL_CONFERENCE_IDLE); - console.log(`Telephony_CallManager ${toString(callAttributeOptions)}`); - expect(callAttributeOptions.accountNumber === AUTO_ACCEPT_NUMBER).assertTrue(); - expect(callAttributeOptions.speakerphoneOn === SPEAK_ON).assertTrue(); - expect(callAttributeOptions.accountId === DEFAULT_SLOT_ID).assertTrue(); - expect(callAttributeOptions.videoState === MEDIA_TYPE_VOICE).assertTrue(); - expect(callAttributeOptions.startTime === CURRENT_TIME).assertTrue(); - expect(callAttributeOptions.isEcc === IS_ECC).assertTrue(); - expect(callAttributeOptions.callType === DIAL_TYPE_OTT).assertTrue(); - expect(callAttributeOptions.callId === TEMP_CALL_ID).assertTrue(); - expect(callAttributeOptions.callState === CALL_STATUS_DIALING).assertTrue(); - expect(callAttributeOptions.conferenceState === TEL_CONFERENCE_IDLE).assertTrue(); - } catch (error) { - console.log(`Telephony_CallManager ${toString(error)}`); - } - try { - let callState = await call.getCallState(); - console.log(`Telephony_CallManager callState ${callState} ${gloabCallId}`); - if (callState === CALL_STATE_UNKNOWN || callState === CALL_STATE_IDLE) { - return; + afterEach(async function () { + try { + const CURRENT_TIME = new Date().valueOf(); + const TEMP_CALL_ID = 10; + const IS_ECC = true; + const SPEAK_ON = true; + let callAttributeOptions = new CallAttributeOptions(AUTO_ACCEPT_NUMBER, SPEAK_ON, DEFAULT_SLOT_ID, + MEDIA_TYPE_VOICE, CURRENT_TIME, IS_ECC, DIAL_TYPE_OTT, TEMP_CALL_ID, CALL_STATUS_DIALING, + TEL_CONFERENCE_IDLE); + expect(callAttributeOptions.accountNumber === AUTO_ACCEPT_NUMBER).assertTrue(); + expect(callAttributeOptions.speakerphoneOn === SPEAK_ON).assertTrue(); + expect(callAttributeOptions.accountId === DEFAULT_SLOT_ID).assertTrue(); + expect(callAttributeOptions.videoState === MEDIA_TYPE_VOICE).assertTrue(); + expect(callAttributeOptions.startTime === CURRENT_TIME).assertTrue(); + expect(callAttributeOptions.isEcc === IS_ECC).assertTrue(); + expect(callAttributeOptions.callType === DIAL_TYPE_OTT).assertTrue(); + expect(callAttributeOptions.callId === TEMP_CALL_ID).assertTrue(); + expect(callAttributeOptions.callState === CALL_STATUS_DIALING).assertTrue(); + expect(callAttributeOptions.conferenceState === TEL_CONFERENCE_IDLE).assertTrue(); + } catch (error) { + console.log(JSON.stringify(error)); } - if (gloabCallId) { - let data = await hangupCall('Telephony_CallManager', gloabCallId); - console.log(`Telephony_CallManager hangupCall success ${toString(data)}`); - } - } catch (error) { - console.log('Telephony_CallManager hangupCall or getCallState error'); - } - }); + }); - afterAll(function () { - observer.off('callStateChange'); - callDetailsChangeOff(); - console.log('Telephony_CallManager all 54 case is over for callmanager CallManageImsCall'); - }); + /** + * @tc.number Telephony_CallManager_getCallState_Async_0100 + * @tc.name To get the idle call status, call getCallState() to get the current call status. + * call.CALL_STATE_IDLE is returned + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Async_0100', 0, async function (done) { + call.getCallState((err, data) => { + if (err) { + console.log("Telephony_CallManager_getCallState_Async_0100 : err =" + JSON.stringify(err)); + expect().assertFail(); + done(); + return; + } + console.log("Telephony_CallManager_getCallState_Async_0100 : data =" + JSON.stringify(data)); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_getCallState_Async_0100 - * @tc.name To get the idle call status, call getCallState() to get the current call status. - * call.CALL_STATE_IDLE is returned - * @tc.desc Function test - */ - it('Telephony_CallManager_getCallState_Async_0100', 0, async function (done) { - call.getCallState((err, data) => { - if (err) { - console.log(`Telephony_CallManager_getCallState_Async_0100 : err = ${err.message}`); + /** + * @tc.number Telephony_CallManager_getCallState_Promise_0100 + * @tc.name To get the idle call status, call getCallState() to get the current call status. + * call.CALL_STATE_IDLE is returned + * @tc.desc Function test + */ + it('Telephony_CallManager_getCallState_Promise_0100', 0, async function (done) { + let promise = call.getCallState(); + promise.then(data => { + console.log("Telephony_CallManager_getCallState_Promise_0100 : data =" + JSON.stringify(data)); + done(); + }).catch(err => { + console.log("Telephony_CallManager_getCallState_Promise_0100 : err =" + JSON.stringify(err)); expect().assertFail(); done(); - return; - } - expect(data == call.CALL_STATE_IDLE || - data == call.CALL_STATE_UNKNOWN || - data == call.CALL_STATE_RINGING || - data == call.CALL_STATE_OFFHOOK).assertTrue(); - console.log(`Telephony_CallManager_getCallState_Async_0100 finish data = ${data}`); - done(); + }); }); - }); - - /** - * @tc.number Telephony_CallManager_getCallState_Promise_0100 - * @tc.name To get the idle call status, call getCallState() to get the current call status. - * call.CALL_STATE_IDLE is returned - * @tc.desc Function test - */ - it('Telephony_CallManager_getCallState_Promise_0100', 0, async function (done) { - try { - var data = await call.getCallState(); - expect(data == call.CALL_STATE_IDLE || - data == call.CALL_STATE_UNKNOWN || - data == call.CALL_STATE_RINGING || - data == call.CALL_STATE_OFFHOOK).assertTrue(); - console.log(`Telephony_CallManager_getCallState_Promise_0100 finish data = ${data}`); - done(); - } catch (err) { - console.log(`Telephony_CallManager_getCallState_Promise_0100 : err = ${err.message}`); - expect().assertFail(); - done(); - } - }); + /** + * @tc.number Telephony_CallManager_hasCall_Async_0400 + * @tc.name When idle, hasCall() is called to confirm that there is no current call,returning false + * @tc.desc Function test + */ + it('Telephony_CallManager_hasCall_Async_0400', 0, async function (done) { + call.hasCall((err, data) => { + if (err) { + console.log('Telephony_CallManager_hasCall_Async_0400 fail'); + expect().assertFail(); + done(); + return; + } + console.log(`Telephony_CallManager_hasCall_Async_0400 finish data = ${data}`); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_hasCall_Async_0400 - * @tc.name When idle, hasCall() is called to confirm that there is no current call,returning false - * @tc.desc Function test - */ - it('Telephony_CallManager_hasCall_Async_0400', 0, async function (done) { - call.hasCall((err, data) => { - if (err) { - console.log('Telephony_CallManager_hasCall_Async_0400 fail'); + /** + * @tc.number Telephony_CallManager_hasCall_Promise_0400 + * @tc.name When idle, hasCall() is called to confirm that there is no current call, returning false + * @tc.desc Function test + */ + it('Telephony_CallManager_hasCall_Promise_0400', 0, async function (done) { + try { + var data = await call.hasCall(); + console.log(`Telephony_CallManager_hasCall_Promise_0400 finish data = ${data}`); + done(); + } catch (err) { + console.log('Telephony_CallManager_hasCall_Promise_0400 fail'); expect().assertFail(); done(); - return; + } - console.log(`Telephony_CallManager_hasCall_Async_0400 finish data = ${data}`); - done(); }); - }); - /** - * @tc.number Telephony_CallManager_hasCall_Promise_0400 - * @tc.name When idle, hasCall() is called to confirm that there is no current call, returning false - * @tc.desc Function test - */ - it('Telephony_CallManager_hasCall_Promise_0400', 0, async function (done) { - try { - var data = await call.hasCall(); - console.log(`Telephony_CallManager_hasCall_Promise_0400 finish data = ${data}`); - done(); - } catch (err) { - console.log('Telephony_CallManager_hasCall_Promise_0400 fail'); - expect().assertFail(); - done(); - - } - }); + /** + * @tc.number Telephony_CallManager_formatPhoneNumber_Async_0100 + * @tc.name PhoneNumber is 100000000000. Call formatPhoneNumber() to format the number. + * The return value is 10 000 000 0000 + * @tc.desc Function test + */ + it('Telephony_CallManager_formatPhoneNumber_Async_0100', 0, async function (done) { + call.formatPhoneNumber('100000000000', (err, data) => { + if (err) { + console.log(`Telephony_CallManager_formatPhoneNumber_Async_0100 err = ${err.message}`); + console.log('Telephony_CallManager_formatPhoneNumber_Async_0100 fail'); + expect().assertFail(); + done(); + return; + } + expect(data === '10 000 000 0000').assertTrue(); + console.log(`Telephony_CallManager_formatPhoneNumber_Async_0100 finish data = ${data}`); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_formatPhoneNumber_Async_0100 - * @tc.name PhoneNumber is 100000000000. Call formatPhoneNumber() to format the number. - * The return value is 10 000 000 0000 - * @tc.desc Function test - */ - it('Telephony_CallManager_formatPhoneNumber_Async_0100', 0, async function (done) { - call.formatPhoneNumber('100000000000', (err, data) => { - if (err) { - console.log(`Telephony_CallManager_formatPhoneNumber_Async_0100 err = ${err.message}`); - console.log('Telephony_CallManager_formatPhoneNumber_Async_0100 fail'); + /** + * @tc.number Telephony_CallManager_formatPhoneNumber_Promise_0100 + * @tc.name PhoneNumber is 2000000. Call formatPhoneNumber() to format the number. + * The return value is 200 0000 + * @tc.desc Function test + */ + it('Telephony_CallManager_formatPhoneNumber_Promise_0100', 0, async function (done) { + try { + var data = await call.formatPhoneNumber('2000000'); + expect(data === '200 0000').assertTrue(); + console.log(`Telephony_CallManager_formatPhoneNumber_Promise_0100 finish data = ${data}`); + done(); + } catch (err) { + console.log('Telephony_CallManager_formatPhoneNumber_Promise_0100 fail'); expect().assertFail(); done(); - return; + } - expect(data === '10 000 000 0000').assertTrue(); - console.log(`Telephony_CallManager_formatPhoneNumber_Async_0100 finish data = ${data}`); - done(); }); - }); - /** - * @tc.number Telephony_CallManager_formatPhoneNumber_Promise_0100 - * @tc.name PhoneNumber is 2000000. Call formatPhoneNumber() to format the number. - * The return value is 200 0000 - * @tc.desc Function test - */ - it('Telephony_CallManager_formatPhoneNumber_Promise_0100', 0, async function (done) { - try { - var data = await call.formatPhoneNumber('2000000'); - expect(data === '200 0000').assertTrue(); - console.log(`Telephony_CallManager_formatPhoneNumber_Promise_0100 finish data = ${data}`); - done(); - } catch (err) { - console.log('Telephony_CallManager_formatPhoneNumber_Promise_0100 fail'); - expect().assertFail(); - done(); - - } - }); + /** + * @tc.number Telephony_CallManager_formatPhoneNumber_Async_0200 + * @tc.name testFormatPhoneNumber_0200 + * @tc.desc PhoneNumber is 13900000000, options: CN, test formatPhoneNumber() api by callback. + * The return value is 139 0000 0000 + */ + it('Telephony_CallManager_formatPhoneNumber_Async_0200', 0, async function (done) { + let numberFormatOptions = new NumberFormatOptions('CN'); + call.formatPhoneNumber('13900000000', numberFormatOptions, (err, data) => { + if (err) { + console.log(`Telephony_CallManager_formatPhoneNumber_Async_0200 err = ${err.message}`); + console.log('Telephony_CallManager_formatPhoneNumber_Async_0200 fail'); + expect().assertFail(); + done(); + return; + } + expect(data === '139 0000 0000').assertTrue(); + console.log(`Telephony_CallManager_formatPhoneNumber_Async_0200 finish data = ${data}`); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_formatPhoneNumber_Async_0200 - * @tc.name testFormatPhoneNumber_0200 - * @tc.desc PhoneNumber is 13900000000, options: CN, test formatPhoneNumber() api by callback. - * The return value is 139 0000 0000 - */ - it('Telephony_CallManager_formatPhoneNumber_Async_0200', 0, async function (done) { - let numberFormatOptions = new NumberFormatOptions('CN'); - call.formatPhoneNumber('13900000000', numberFormatOptions, (err, data) => { - if (err) { - console.log(`Telephony_CallManager_formatPhoneNumber_Async_0200 err = ${err.message}`); - console.log('Telephony_CallManager_formatPhoneNumber_Async_0200 fail'); + /** + * @tc.number Telephony_CallManager_formatPhoneNumber_Async_0300 + * @tc.name testFormatPhoneNumber_0300 + * @tc.desc PhoneNumber is 13900000000, options: US, test formatPhoneNumber() api by promise. + * The return value is '1 390-000-0000' + */ + it('Telephony_CallManager_formatPhoneNumber_Promise_0200', 0, async function (done) { + let numberFormatOptions = new NumberFormatOptions('US'); + try { + var data = await call.formatPhoneNumber('13900000000', numberFormatOptions); + expect(data === '1 390-000-0000').assertTrue(); + console.log(`Telephony_CallManager_formatPhoneNumber_Promise_0200 finish data = ${data}`); + done(); + } catch (err) { + console.log('Telephony_CallManager_formatPhoneNumber_Promise_0200 fail'); expect().assertFail(); done(); - return; } - expect(data === '139 0000 0000').assertTrue(); - console.log(`Telephony_CallManager_formatPhoneNumber_Async_0200 finish data = ${data}`); - done(); }); - }); - /** - * @tc.number Telephony_CallManager_formatPhoneNumber_Async_0300 - * @tc.name testFormatPhoneNumber_0300 - * @tc.desc PhoneNumber is 13900000000, options: US, test formatPhoneNumber() api by promise. - * The return value is '1 390-000-0000' - */ - it('Telephony_CallManager_formatPhoneNumber_Promise_0200', 0, async function (done) { - let numberFormatOptions = new NumberFormatOptions('US'); - try { - var data = await call.formatPhoneNumber('13900000000', numberFormatOptions); - expect(data === '1 390-000-0000').assertTrue(); - console.log(`Telephony_CallManager_formatPhoneNumber_Promise_0200 finish data = ${data}`); - done(); - } catch (err) { - console.log('Telephony_CallManager_formatPhoneNumber_Promise_0200 fail'); - expect().assertFail(); - done(); - } - }); + /** + * @tc.number Telephony_CallManager_formatPhoneNumberToE164_Async_0100 + * @tc.name PhoneNumber is 010-0000-0000, options: CN, call formatPhoneNumberToE164() to format the number, + * and return +861000000000 + * @tc.desc Function test + */ + it('Telephony_CallManager_formatPhoneNumberToE164_Async_0100', 0, async function (done) { + let numberFormatOptions = new NumberFormatOptions('CN'); + call.formatPhoneNumberToE164('010-0000-0000', numberFormatOptions.countryCode, (err, data) => { + if (err) { + console.log('Telephony_CallManager_formatPhoneNumberToE164_Async_0100 fail'); + expect().assertFail(); + done(); + return; + } + expect(data === '+861000000000').assertTrue(); + console.log(`Telephony_CallManager_formatPhoneNumberToE164_Async_0100 finish data = ${data}`); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_formatPhoneNumberToE164_Async_0100 - * @tc.name PhoneNumber is 010-0000-0000, options: CN, call formatPhoneNumberToE164() to format the number, - * and return +861000000000 - * @tc.desc Function test - */ - it('Telephony_CallManager_formatPhoneNumberToE164_Async_0100', 0, async function (done) { - let numberFormatOptions = new NumberFormatOptions('CN'); - call.formatPhoneNumberToE164('010-0000-0000', numberFormatOptions.countryCode, (err, data) => { - if (err) { - console.log('Telephony_CallManager_formatPhoneNumberToE164_Async_0100 fail'); + /** + * @tc.number Telephony_CallManager_formatPhoneNumberToE164_Promise_0100 + * @tc.name PhoneNumber is 52300000000, options: CN, call formatPhoneNumberToE164() to format the number, + * return +8652300000000 + * @tc.desc Function test + */ + it('Telephony_CallManager_formatPhoneNumberToE164_Promise_0100', 0, async function (done) { + let numberFormatOptions = new NumberFormatOptions('CN'); + try { + var data = await call.formatPhoneNumberToE164('52300000000', numberFormatOptions.countryCode); + expect(data === '+8652300000000').assertTrue(); + console.log(`Telephony_CallManager_formatPhoneNumberToE164_Promise_0100 finish data = ${data}`); + done(); + } catch (err) { + console.log('Telephony_CallManager_formatPhoneNumberToE164_Promise_0100 fail'); expect().assertFail(); done(); - return; + } - expect(data === '+861000000000').assertTrue(); - console.log(`Telephony_CallManager_formatPhoneNumberToE164_Async_0100 finish data = ${data}`); - done(); }); - }); - - /** - * @tc.number Telephony_CallManager_formatPhoneNumberToE164_Promise_0100 - * @tc.name PhoneNumber is 52300000000, options: CN, call formatPhoneNumberToE164() to format the number, - * return +8652300000000 - * @tc.desc Function test - */ - it('Telephony_CallManager_formatPhoneNumberToE164_Promise_0100', 0, async function (done) { - let numberFormatOptions = new NumberFormatOptions('CN'); - try { - var data = await call.formatPhoneNumberToE164('52300000000', numberFormatOptions.countryCode); - expect(data === '+8652300000000').assertTrue(); - console.log(`Telephony_CallManager_formatPhoneNumberToE164_Promise_0100 finish data = ${data}`); - done(); - } catch (err) { - console.log('Telephony_CallManager_formatPhoneNumberToE164_Promise_0100 fail'); - expect().assertFail(); - done(); - } - }); + /** + * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Async_1300 + * @tc.name PhoneNumber: 110, options -1. Call isEmergencyPhoneNumber() to check whether it is an emergency + * number. The return value is false + * @tc.desc Function test + */ + it('Telephony_CallManager_isEmergencyPhoneNumber_Async_1300', 0, async function (done) { + let emergencyNumberOptions = new EmergencyNumberOptions(ERR_SLOT_ID); + call.isEmergencyPhoneNumber('110', emergencyNumberOptions, (err) => { + if (err) { + console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Async_1300 finish err = ${err}`); + done(); + return; + } + expect().assertFail(); + console.log('Telephony_CallManager_isEmergencyPhoneNumber_Async_1300 fail '); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Async_1300 - * @tc.name PhoneNumber: 110, options -1. Call isEmergencyPhoneNumber() to check whether it is an emergency - * number. The return value is false - * @tc.desc Function test - */ - it('Telephony_CallManager_isEmergencyPhoneNumber_Async_1300', 0, async function (done) { - let emergencyNumberOptions = new EmergencyNumberOptions(ERR_SLOT_ID); - call.isEmergencyPhoneNumber('110', emergencyNumberOptions, (err) => { - if (err) { - console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Async_1300 finish err = ${err}`); + /** + * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300 + * @tc.name PhoneNumber: 120, options -1. Call isEmergencyPhoneNumber() to check whether it is an emergency + * number. The return value is false + * @tc.desc Function test + */ + it('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300', 0, async function (done) { + let emergencyNumberOptions = new EmergencyNumberOptions(ERR_SLOT_ID); + try { + await call.isEmergencyPhoneNumber('120', emergencyNumberOptions); + expect().assertFail(); + console.log('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300 fail '); + done(); + } catch (err) { + console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300 finish err = ${err}`); done(); - return; } - expect().assertFail(); - console.log('Telephony_CallManager_isEmergencyPhoneNumber_Async_1300 fail '); - done(); }); - }); - /** - * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300 - * @tc.name PhoneNumber: 120, options -1. Call isEmergencyPhoneNumber() to check whether it is an emergency - * number. The return value is false - * @tc.desc Function test - */ - it('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300', 0, async function (done) { - let emergencyNumberOptions = new EmergencyNumberOptions(ERR_SLOT_ID); - try { - var data = await call.isEmergencyPhoneNumber('120', emergencyNumberOptions); - expect().assertFail(); - console.log('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300 fail '); - done(); - } catch (err) { - console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Promise_1300 finish err = ${err}`); - done(); - } - }); + /** + * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Async_1400 + * @tc.name testIsEmergencyPhoneNumber_1400 + * @tc.desc PhoneNumber: 110, no options. Call isEmergencyPhoneNumber() api by callback. + * The return value is true + */ + it('Telephony_CallManager_isEmergencyPhoneNumber_Async_1400', 0, async function (done) { + call.isEmergencyPhoneNumber('110', (err) => { + if (err) { + console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Async_1400 finish err = ${err}`); + expect().assertFail(); + done(); + return; + } + expect(true).assertTrue(); + console.log('Telephony_CallManager_isEmergencyPhoneNumber_Async_1400 PASSED '); + done(); + }); + }); - /** - * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Async_1400 - * @tc.name testIsEmergencyPhoneNumber_1400 - * @tc.desc PhoneNumber: 110, no options. Call isEmergencyPhoneNumber() api by callback. - * The return value is true - */ - it('Telephony_CallManager_isEmergencyPhoneNumber_Async_1400', 0, async function (done) { - call.isEmergencyPhoneNumber('110', (err) => { - if (err) { - console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Async_1400 finish err = ${err}`); + /** + * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Async_1500 + * @tc.name testIsEmergencyPhoneNumber_1500 + * @tc.desc PhoneNumber: 120, no options. Call isEmergencyPhoneNumber() api by promise. + * The return value is true + */ + it('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1400', 0, async function (done) { + try { + await call.isEmergencyPhoneNumber('120'); + expect(true).assertTrue(); + console.log('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1400 PASSED '); + done(); + } catch (err) { + console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Promise_1400 finish err = ${err}`); expect().assertFail(); done(); - return; } - expect(true).assertTrue(); - console.log('Telephony_CallManager_isEmergencyPhoneNumber_Async_1400 PASSED '); - done(); }); }); - - /** - * @tc.number Telephony_CallManager_isEmergencyPhoneNumber_Async_1500 - * @tc.name testIsEmergencyPhoneNumber_1500 - * @tc.desc PhoneNumber: 120, no options. Call isEmergencyPhoneNumber() api by promise. - * The return value is true - */ - it('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1400', 0, async function (done) { - try { - var data = await call.isEmergencyPhoneNumber('120'); - expect(true).assertTrue(); - console.log('Telephony_CallManager_isEmergencyPhoneNumber_Promise_1400 PASSED '); - done(); - } catch (err) { - console.log(`Telephony_CallManager_isEmergencyPhoneNumber_Promise_1400 finish err = ${err}`); - expect().assertFail(); - done(); - } - }); -}); } \ No newline at end of file diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/List.test.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/List.test.js index fb2f3e273..53a7ad98b 100644 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/List.test.js +++ b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/List.test.js @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Huawei Device Co., Ltd. + * Copyright (C) 2021-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 @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import CallManageImsCall from './CallManageAll.test.js' -import ObjectInterfaceTest from './ObjectInterface_test.js' +import CallManageImsCall from './CallManageAll.test.js'; +import ObjectInterfaceTest from './ObjectInterface_test.js'; export default function testsuite() { ObjectInterfaceTest(); diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/ObjectInterface_test.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/ObjectInterface_test.js index 37a379490..abbc6f7ce 100644 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/ObjectInterface_test.js +++ b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/ObjectInterface_test.js @@ -13,1651 +13,1571 @@ * limitations under the License. */ -import contactsapi from "@ohos.contact"; +import contact from '@ohos.contact'; import sms from '@ohos.telephony.sms'; -import featureAbility from "@ohos.ability.featureAbility"; -import {afterAll, afterEach, beforeAll, describe, expect, it} from '@ohos/hypium'; -import {UiComponent,UiDriver,Component,Driver,UiWindow,ON,BY} from '@ohos.uitest' +import featureAbility from '@ohos.ability.featureAbility'; +import { afterAll, beforeAll, describe, expect, it } from '@ohos/hypium'; +import { BY, UiDriver } from '@ohos.uitest'; export default function ObjectInterfaceTest() { - describe('ObjectInterfaceTest', function () { - - function sleep(numberMillis) { - var now = new Date(); - var exitTime = now.getTime() + numberMillis; - while (true) { - now = new Date(); - if (now.getTime() > exitTime); - return; - } - } - - async function driveFn() { - console.info("come in driveFn"); - let driver = await UiDriver.create(); - console.info("driver is " + JSON.stringify(driver)); - sleep(2000); - let button = await driver.findComponent(BY.text('允许')); - console.info("button is " + JSON.stringify(button)); - await button.click(); - sleep(5000); - } - - beforeAll(async function () { - var permissions = ["ohos.permission.WRITE_CONTACTS","ohos.permission.READ_CONTACTS"]; - featureAbility.getContext().requestPermissionsFromUser(permissions, 0, () => { - console.info("start requestPermissionsFromUser"); - }); - for(let i=0; i<2; i++){ - await driveFn(); - console.log("get user_grant permission"); - } - }); - - var contactData = { - id: 0, - key: "0", - contactAttributes: { - attributes: [contactsapi.Attribute.ATTR_CONTACT_EVENT, contactsapi.Attribute.ATTR_EMAIL, - contactsapi.Attribute.ATTR_GROUP_MEMBERSHIP, - contactsapi.Attribute.ATTR_IM, contactsapi.Attribute.ATTR_NAME, contactsapi.Attribute.ATTR_NICKNAME, - contactsapi.Attribute.ATTR_NOTE, contactsapi.Attribute.ATTR_ORGANIZATION, contactsapi.Attribute.ATTR_PHONE, - contactsapi.Attribute.ATTR_PORTRAIT, contactsapi.Attribute.ATTR_POSTAL_ADDRESS, - contactsapi.Attribute.ATTR_RELATION, - contactsapi.Attribute.ATTR_SIP_ADDRESS, contactsapi.Attribute.ATTR_WEBSITE] - }, - emails: [{ - email: "email", labelName: "自定义邮箱", labelId: 1, displayName: "emailDisplayName" - }], - events: [{ - eventDate: "event", labelName: "自定义event", labelId: 2 - }], - groups: [{ - groupId: 1, title: "群组" - }], - imAddresses: [{ - imAddress: "imAddress", labelName: "自定义", labelId: 3 - }], - phoneNumbers: [{ - phoneNumber: "183", labelName: "自定义phoneNumbers", labelId: 4 - }], - portrait: { - uri: "content://head/0" - }, - postalAddresses: [{ - city: "南京", - country: "中国", - labelName: "labelName", - neighborhood: "neighborhood", - pobox: "pobox", - postalAddress: "postalAddress", - postcode: "postcode", - region: "region", - street: "street", - labelId: 5 - }], - relations: [{ - relationName: "relationName", labelName: "自定义relationName", labelId: 6 - }], - sipAddresses: [{ - sipAddress: "sipAddress", labelName: "自定义sipAddress", labelId: 6 - }], - websites: [{ - website: "website" - }], - name: { - familyName: "familyName", - familyNamePhonetic: "familyNamePhonetic", - fullName: "小李", - givenName: "givenName", - givenNamePhonetic: "givenNamePhonetic", - middleName: "middleName", - middleNamePhonetic: "middleNamePhonetic", - namePrefix: "namePrefix", - nameSuffix: "nameSuffix" - }, - nickName: { - nickName: "nickName" - }, - note: { - noteContent: "note" - }, - organization: { - name: "TT", title: "开发" - } - }; - - var gRawContactId; - var gGroup; - - - it("contactsApi_contactdata_test_100", 0, async function (done) { - console.info("contactData.id" + contactData.id); - console.info("contactData.id" + (contactData.id == 0)); - expect(contactData.id == 0).assertTrue(); - console.info("contactData.key" + contactData.key); - console.info("contactData.key" + (contactData.key == "0")); - expect(contactData.key).assertEqual("0"); - console.info("contactData.contactAttributes" + contactData.contactAttributes); - console.info("contactData.contactAttributes" + (contactData.contactAttributes != null)); - expect(contactData.contactAttributes != null).assertTrue(); - console.info("contactData.emails" + contactData.emails); - expect(contactData.emails != null).assertTrue(); - expect(contactData.events != null).assertTrue(); - expect(contactData.groups != null).assertTrue(); - expect(contactData.imAddresses != null).assertTrue(); - done(); - }); - - it("contactsApi_contactdata_test_200", 0, async function (done) { - expect(contactData.phoneNumbers != null).assertTrue(); - expect(contactData.portrait != null).assertTrue(); - expect(contactData.postalAddresses != null).assertTrue(); - expect(contactData.relations != null).assertTrue(); - expect(contactData.sipAddresses != null).assertTrue(); - expect(contactData.websites != null).assertTrue(); - expect(contactData.name != null).assertTrue(); - expect(contactData.nickName != null).assertTrue(); - expect(contactData.note != null).assertTrue(); - expect(contactData.organization != null).assertTrue(); - expect(contactData.contactAttributes.attributes != null).assertTrue(); - done(); - }); - - it("contactsApi_contactdata_test_300", 0, async function (done) { - expect(contactData.emails.email === null).assertFalse(); - expect(contactData.emails.labelName === null).assertFalse(); - console.info("contactData.emails.labelId == 1" + contactData.emails.labelId); - expect(contactData.emails.labelId != 0).assertTrue(); - expect(contactData.emails.displayName === null).assertFalse(); - expect(contactData.events.eventDate === null).assertFalse(); - expect(contactData.events.labelName === null).assertFalse(); - expect(contactData.events.labelId != 0).assertTrue(); - expect(contactData.groups.groupId != 0).assertTrue(); - expect(contactData.groups.title === null).assertFalse(); - done(); - }); - it("contactsApi_contactdata_test_400", 0, async function (done) { - expect(contactData.imAddresses.imAddress === null).assertFalse(); - expect(contactData.imAddresses.labelName === null).assertFalse(); - expect(contactData.imAddresses.labelId != 0).assertTrue(); - expect(contactData.name.familyName === null).assertFalse(); - expect(contactData.name.familyNamePhonetic === null).assertFalse(); - expect(contactData.name.fullName === null).assertFalse(); - expect(contactData.name.givenName === null).assertFalse(); - expect(contactData.name.givenNamePhonetic === null).assertFalse(); - expect(contactData.name.middleName === null).assertFalse(); - expect(contactData.name.middleNamePhonetic === null).assertFalse(); - expect(contactData.name.namePrefix === null).assertFalse(); - expect(contactData.name.nameSuffix === null).assertFalse(); - done(); - }); - - it("contactsApi_contactdata_test_500", 0, async function (done) { - expect(contactData.nickName.nickName === null).assertFalse(); - expect(contactData.note.noteContent === null).assertFalse(); - expect(contactData.organization.name === null).assertFalse(); - expect(contactData.organization.title === null).assertFalse(); - expect(contactData.phoneNumbers.labelId != 0).assertTrue(); - expect(contactData.phoneNumbers.labelName === null).assertFalse(); - expect(contactData.phoneNumbers.phoneNumber === null).assertFalse(); - expect(contactData.portrait.uri === null).assertFalse(); - done(); - }); - - it("contactsApi_contactdata_test_600", 0, async function (done) { - console.info("contactData.postalAddresses.city != null" - + contactData.postalAddresses.city - + (contactData.postalAddresses.city != null)); - expect(contactData.postalAddresses.city === null).assertFalse(); - expect(contactData.postalAddresses.country === null).assertFalse(); - expect(contactData.postalAddresses.labelName === null).assertFalse(); - expect(contactData.postalAddresses.neighborhood === null).assertFalse(); - expect(contactData.postalAddresses.pobox === null).assertFalse(); - expect(contactData.postalAddresses.postalAddress === null).assertFalse(); - expect(contactData.postalAddresses.postcode === null).assertFalse(); - expect(contactData.postalAddresses.region === null).assertFalse(); - expect(contactData.postalAddresses.street === null).assertFalse(); - expect(contactData.postalAddresses.labelId != 0).assertTrue(); - done(); - }); - - it("contactsApi_contactdata_test_700", 0, async function (done) { - console.info("contactData.relations.labelName != null" - + contactData.relations.labelName + (contactData.relations.labelName === null)); - expect(contactData.relations.labelId != 0).assertTrue(); - expect(contactData.relations.labelName === null).assertFalse(); - expect(contactData.relations.relationName === null).assertFalse(); - expect(contactData.sipAddresses.labelId != 0).assertTrue(); - expect(contactData.sipAddresses.labelName === null).assertFalse(); - expect(contactData.sipAddresses.sipAddress === null).assertFalse(); - expect(contactData.websites.website === null).assertFalse(); - done(); - }); - - - it("contactsApi_contactdata_test_800", 0, async function (done) { - expect(contactsapi.Contact.INVALID_CONTACT_ID == -1).assertTrue(); - expect(contactsapi.Attribute.ATTR_CONTACT_EVENT == - contactData.contactAttributes.attributes[0]).assertTrue(); - expect(contactsapi.Attribute.ATTR_EMAIL == contactData.contactAttributes.attributes[1]).assertTrue(); - expect(contactsapi.Attribute.ATTR_GROUP_MEMBERSHIP == - contactData.contactAttributes.attributes[2]).assertTrue(); - expect(contactsapi.Attribute.ATTR_IM == contactData.contactAttributes.attributes[3]).assertTrue(); - expect(contactsapi.Attribute.ATTR_NAME == contactData.contactAttributes.attributes[4]).assertTrue(); - expect(contactsapi.Attribute.ATTR_NICKNAME == contactData.contactAttributes.attributes[5]).assertTrue(); - expect(contactsapi.Attribute.ATTR_NOTE == contactData.contactAttributes.attributes[6]).assertTrue(); - expect(contactsapi.Attribute.ATTR_ORGANIZATION == contactData.contactAttributes.attributes[7]).assertTrue(); - expect(contactsapi.Attribute.ATTR_PHONE == contactData.contactAttributes.attributes[8]).assertTrue(); - expect(contactsapi.Attribute.ATTR_PORTRAIT == contactData.contactAttributes.attributes[9]).assertTrue(); - expect(contactsapi.Attribute.ATTR_POSTAL_ADDRESS == - contactData.contactAttributes.attributes[10]).assertTrue(); - expect(contactsapi.Attribute.ATTR_RELATION == contactData.contactAttributes.attributes[11]).assertTrue(); - expect(contactsapi.Attribute.ATTR_SIP_ADDRESS == contactData.contactAttributes.attributes[12]).assertTrue(); - expect(contactsapi.Attribute.ATTR_WEBSITE == contactData.contactAttributes.attributes[13]).assertTrue(); - done(); - }); - - it("contactsApi_contactdata_test_900", 0, async function (done) { - expect(contactsapi.Email.CUSTOM_LABEL == 0).assertTrue(); - expect(contactsapi.Email.EMAIL_HOME == 1).assertTrue(); - expect(contactsapi.Email.EMAIL_WORK == 2).assertTrue(); - expect(contactsapi.Email.EMAIL_OTHER == 3).assertTrue(); - expect(contactsapi.Email.INVALID_LABEL_ID == -1).assertTrue(); - expect(contactsapi.Event.CUSTOM_LABEL == 0).assertTrue(); - expect(contactsapi.Event.EVENT_ANNIVERSARY == 1).assertTrue(); - expect(contactsapi.Event.EVENT_OTHER == 2).assertTrue(); - expect(contactsapi.Event.EVENT_BIRTHDAY == 3).assertTrue(); - expect(contactsapi.Email.INVALID_LABEL_ID == -1).assertTrue(); - expect(contactsapi.ImAddress.CUSTOM_LABEL == -1).assertTrue(); - expect(contactsapi.ImAddress.IM_AIM == 0).assertTrue(); - expect(contactsapi.ImAddress.IM_MSN == 1).assertTrue(); - expect(contactsapi.ImAddress.IM_YAHOO == 2).assertTrue(); - expect(contactsapi.ImAddress.IM_SKYPE == 3).assertTrue(); - expect(contactsapi.ImAddress.IM_QQ == 4).assertTrue(); - expect(contactsapi.ImAddress.IM_ICQ == 6).assertTrue(); - expect(contactsapi.ImAddress.IM_JABBER == 7).assertTrue(); - expect(contactsapi.ImAddress.INVALID_LABEL_ID == -2).assertTrue(); - done(); - }); - - it("contactsApi_contactdata_test_1000", 0, async function (done) { - expect(contactsapi.PhoneNumber.CUSTOM_LABEL == 0).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_HOME == 1).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_MOBILE == 2).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_WORK == 3).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_FAX_WORK == 4).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_FAX_HOME == 5).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_PAGER == 6).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_OTHER == 7).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_CALLBACK == 8).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_CAR == 9).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_COMPANY_MAIN == 10).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_ISDN == 11).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_MAIN == 12).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_OTHER_FAX == 13).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_RADIO == 14).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_TELEX == 15).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_TTY_TDD == 16).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_WORK_MOBILE == 17).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_WORK_PAGER == 18).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_ASSISTANT == 19).assertTrue(); - expect(contactsapi.PhoneNumber.NUM_MMS == 20).assertTrue(); - expect(contactsapi.PhoneNumber.INVALID_LABEL_ID == -1).assertTrue(); - expect(contactsapi.PostalAddress.CUSTOM_LABEL == 0).assertTrue(); - expect(contactsapi.PostalAddress.ADDR_HOME == 1).assertTrue(); - expect(contactsapi.PostalAddress.ADDR_WORK == 2).assertTrue(); - expect(contactsapi.PostalAddress.ADDR_OTHER == 3).assertTrue(); - expect(contactsapi.PostalAddress.INVALID_LABEL_ID == -1).assertTrue(); - done(); - }); - - it("contactsApi_contactdata_test_1100", 0, async function (done) { - expect(contactsapi.Relation.CUSTOM_LABEL == 0).assertTrue(); - expect(contactsapi.Relation.RELATION_ASSISTANT == 1).assertTrue(); - expect(contactsapi.Relation.RELATION_BROTHER == 2).assertTrue(); - expect(contactsapi.Relation.RELATION_CHILD == 3).assertTrue(); - expect(contactsapi.Relation.RELATION_DOMESTIC_PARTNER == 4).assertTrue(); - expect(contactsapi.Relation.RELATION_FATHER == 5).assertTrue(); - expect(contactsapi.Relation.RELATION_FRIEND == 6).assertTrue(); - expect(contactsapi.Relation.RELATION_MANAGER == 7).assertTrue(); - expect(contactsapi.Relation.RELATION_MOTHER == 8).assertTrue(); - expect(contactsapi.Relation.RELATION_PARENT == 9).assertTrue(); - expect(contactsapi.Relation.RELATION_PARTNER == 10).assertTrue(); - expect(contactsapi.Relation.RELATION_REFERRED_BY == 11).assertTrue(); - expect(contactsapi.Relation.RELATION_RELATIVE == 12).assertTrue(); - expect(contactsapi.Relation.RELATION_SISTER == 13).assertTrue(); - expect(contactsapi.Relation.RELATION_SPOUSE == 14).assertTrue(); - expect(contactsapi.Relation.INVALID_LABEL_ID == -1).assertTrue(); - expect(contactsapi.SipAddress.CUSTOM_LABEL == 0).assertTrue(); - expect(contactsapi.SipAddress.SIP_HOME == 1).assertTrue(); - expect(contactsapi.SipAddress.SIP_WORK == 2).assertTrue(); - expect(contactsapi.SipAddress.SIP_OTHER == 3).assertTrue(); - expect(contactsapi.SipAddress.INVALID_LABEL_ID == -1).assertTrue(); - done(); - }); - - /** - * @tc.number - * @tc.name Insert contact information - * @tc.desc Function test - */ - it("contactsApi_insert_test_100", 0, async function (done) { - try { - var rawContactId = await contactsapi.addContact(contactData); - console.info("contactsApi_insert_test_100 : rawContactId = " + rawContactId); - gRawContactId = rawContactId; - expect(gRawContactId > 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_insert_test_100 : raw_contact insert error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_delete_test_200 - * @tc.name Delete contact information - * @tc.desc Function test - */ - it("contactsApi_delete_test_200", 0, async function (done) { - var deleteId = gRawContactId; - try { - var deleteCode = await contactsapi.deleteContact(deleteId); - var gDelete = deleteCode; - console.info("contactsApi_delete_test_200 : deleteCode = " + deleteCode); - expect(gDelete == 0 || gDelete == -1).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_delete_test_200 : delete error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_update_test_300 - * @tc.name Update contact information - * @tc.desc Function test - */ - it("contactsApi_update_test_300", 0, async function (done) { - var rawContactId = await contactsapi.addContact(contactData); - console.info("contactsApi_insert_test_300 : rawContactId = " + rawContactId); - gRawContactId = rawContactId; - expect(rawContactId > 0).assertTrue(); - - var updateValues = { - id: gRawContactId, name: { - fullName: "小红" - } - }; - var condition = { - attributes: [6] - } - try { - var updateCode = await contactsapi.updateContact(updateValues, condition); - console.info("contactsApi_update_test_300 : updateCode = " + updateCode); - expect(updateCode == 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_update_test_300 : update error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contact_test_400 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contact_test_400", 0, async function (done) { - var queryId = await contactsapi.addContact(contactData); - console.info("contactsApi_query_contact_test_400 : queryId = " + queryId); - expect(queryId > 0).assertTrue(); - - try { - var resultSet = await contactsapi.queryContact(queryId); - console.info("contactsApi_query_contact_test_400 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_contact_test_400 query error = " + error); - expect().assertFalse(); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contact_test_500 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contact_test_500", 0, async function (done) { - var queryId = gRawContactId; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - expect(holder.bundleName === null).assertFalse(); - expect(holder.displayName === null).assertFalse(); - expect(holder.holderId != 0).assertTrue(); - try { - var findKey = contactsapi.queryKey(queryId); - var resultSet = await contactsapi.queryContact(findKey, holder); - console.info("contactsApi_query_contact_test_500 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet === null).assertFalse(); - done(); - } catch (error) { - console.info("contactsApi_query_contact_test_500 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contact_test_600 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contact_test_600", 0, async function (done) { - var queryId = gRawContactId; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - }; - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var findKey = contactsapi.queryKey(queryId); - var resultSet = await contactsapi.queryContact(findKey, holder, ContactAttributes); - console.info("contactsApi_query_contact_test_600 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet === null).assertFalse(); - done(); - } catch (error) { - console.info("contactsApi_query_contact_test_600 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contacts_test_700 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contacts_test_700", 0, async function (done) { - try { - var resultSet = await contactsapi.queryContacts(); - console.info("contactsApi_query_contacts_test_700 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_contacts_test_700 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contacts_test_800 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contacts_test_800", 0, async function (done) { - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - try { - var resultSet = await contactsapi.queryContacts(holder); - console.info("contactsApi_query_contacts_test_800 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_contacts_test_800 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contacts_test_900 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contacts_test_900", 0, async function (done) { - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var resultSet = await contactsapi.queryContacts(ContactAttributes); - console.info("contactsApi_query_contacts_test_900 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_contacts_test_900 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_contacts_test_1000 - * @tc.name Query contacts information - * @tc.desc Function test - */ - it("contactsApi_query_contacts_test_1000", 0, async function (done) { - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - }; - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var resultSet = await contactsapi.queryContacts(holder, ContactAttributes); - console.info("contactsApi_query_contacts_test_1000 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_contacts_test_1000 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_email_test_1100 - * @tc.name Query email information - * @tc.desc Function test - */ - it("contactsApi_query_email_test_1100", 0, async function (done) { - var email = "email"; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - try { - var resultSet = await contactsapi.queryContactsByEmail(email, holder); - console.info("contactsApi_query_email_test_1100 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_email_test_1100 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_email_test_1200 - * @tc.name Query email information - * @tc.desc Function test - */ - it("contactsApi_query_email_test_1200", 0, async function (done) { - var email = "email"; - try { - var resultSet = await contactsapi.queryContactsByEmail(email); - console.info("contactsApi_query_email_test_1200 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_email_test_1200 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_email_test_1300 - * @tc.name Query email information - * @tc.desc Function test - */ - it("contactsApi_query_email_test_1300", 0, async function (done) { - var email = "email"; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - }; - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var resultSet = await contactsapi.queryContactsByEmail(email, holder, ContactAttributes); - console.info("contactsApi_query_email_test_1300 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_email_test_1300 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_email_test_1400 - * @tc.name Query email information - * @tc.desc Function test - */ - it("contactsApi_query_email_test_1400", 0, async function (done) { - var email = "email"; - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var resultSet = await contactsapi.queryContactsByEmail(email, ContactAttributes); - console.info("contactsApi_query_email_test_1400 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_email_test_1400 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_phoneNumber_test_1500 - * @tc.name Query phoneNumber information - * @tc.desc Function test - */ - it("contactsApi_query_phoneNumber_test_1500", 0, async function (done) { - var phoneNumber = "183"; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - try { - var resultSet = await contactsapi.queryContactsByPhoneNumber(phoneNumber, holder); - console.info("contactsApi_query_phoneNumber_test_1500 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_phoneNumber_test_1500 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_phoneNumber_test_1600 - * @tc.name Query phoneNumber information - * @tc.desc Function test - */ - it("contactsApi_query_phoneNumber_test_1600", 0, async function (done) { - var phoneNumber = "183"; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - }; - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var resultSet = await contactsapi.queryContactsByPhoneNumber(phoneNumber, holder, ContactAttributes); - console.info("contactsApi_query_phoneNumber_test_1600 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_phoneNumber_test_1600 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_phoneNumber_test_1700 - * @tc.name Query phoneNumber information - * @tc.desc Function test - */ - it("contactsApi_query_phoneNumber_test_1700", 0, async function (done) { - var phoneNumber = "183"; - try { - var resultSet = await contactsapi.queryContactsByPhoneNumber(phoneNumber); - console.info("contactsApi_query_phoneNumber_test_1700 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_phoneNumber_test_1700 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_phoneNumber_test_1800 - * @tc.name Query phoneNumber information - * @tc.desc Function test - */ - it("contactsApi_query_phoneNumber_test_1800", 0, async function (done) { - var phoneNumber = "183"; - var ContactAttributes = { - attributes: [1, 5, 6] - } - try { - var resultSet = await contactsapi.queryContactsByPhoneNumber(phoneNumber, ContactAttributes); - console.info("contactsApi_query_phoneNumber_test_1800 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_phoneNumber_test_1800 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_group_test_1900 - * @tc.name Query group - * @tc.desc Function test - */ - it("contactsApi_query_group_test_1900", 0, async function (done) { - try { - var resultSet = await contactsapi.queryGroups(); - console.info("contactsApi_query_group_test_1900 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_group_test_1900 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_group_test_2000 - * @tc.name Query group - * @tc.desc Function test - */ - it("contactsApi_query_group_test_2000", 0, async function (done) { - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - try { - var resultSet = await contactsapi.queryGroups(holder); - console.info("contactsApi_query_group_test_2000 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_group_test_2000 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_holders_test_2200 - * @tc.name Query holders information - * @tc.desc Function test - */ - it("contactsApi_query_holders_test_2200", 0, async function (done) { - try { - var resultSet = await contactsapi.queryHolders(); - console.info("contactsApi_query_holders_test_2200 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet != null).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_holders_test_2200 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_key_test_2300 - * @tc.name Query key information - * @tc.desc Function test - */ - it("contactsApi_query_key_test_2300", 0, async function (done) { - var idtest = gRawContactId; - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - try { - var resultSet = await contactsapi.queryKey(idtest, holder); - console.info("contactsApi_query_key_test_2300 : query resultSet = " + JSON.stringify(resultSet)); - expect(JSON.stringify(resultSet) === null).assertFalse(); - done(); - } catch (error) { - console.info("contactsApi_query_key_test_2300 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_key_test_2400 - * @tc.name Query key information - * @tc.desc Function test - */ - it("contactsApi_query_key_test_2400", 0, async function (done) { - var idtest = gRawContactId; - console.info("contactsApi_query_key_test_2400 : query gRawContactId = " + idtest); - try { - var resultSet = await contactsapi.queryKey(idtest); - console.info("contactsApi_query_key_test_2400 : query resultSet = " + JSON.stringify(resultSet)); - expect(JSON.stringify(resultSet) === null).assertFalse(); - done(); - } catch (error) { - console.info("contactsApi_query_key_test_2400 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_query_mycard_test_2500 - * @tc.name Query mycard information - * @tc.desc Function test - */ - it("contactsApi_query_mycard_test_2500", 0, async function (done) { - var holder = { - bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 - } - try { - var resultSet = await contactsapi.queryMyCard(holder); - console.info("contactsApi_query_mycard_test_2500 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_mycard_test_2500 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_isMyCard_test_2600 - * @tc.name Query mycard exist - * @tc.desc Function test - */ - it("contactsApi_isMyCard_test_2600", 0, async function (done) { - var id = 1; - try { - var isExist = await contactsapi.isMyCard(id); - console.info("contactsApi_isMyCard_test_2600 : query isExist = " + isExist); - expect(isExist == 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_isMyCard_test_2600 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number contactsApi_isLocalContact_test_2700 - * @tc.name Query isLocalContact exist - * @tc.desc Function test - */ - it("contactsApi_isLocalContact_test_2700", 0, async function (done) { - var id = gRawContactId; - try { - var isExist = await contactsapi.isLocalContact(id); - console.info("logMessage contactsApi_isLocalContact_test_2700 isExist = " + isExist); - expect(isExist != -1).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_isLocalContact_test_2700 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_insert_test_2800 - * @tc.name contactsApi_insert error - * @tc.desc Function test - */ - it("abnormal_contactsApi_insert_test_2800", 0, async function (done) { - var contactDataError = {}; - try { - var rawContactId = await contactsapi.addContact(contactDataError); - console.info("abnormal_contactsApi_insert_test_2800 : rawContactId = " + rawContactId); - expect(rawContactId == -1).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_insert_test_100 : raw_contact insert error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_update_test_3000 - * @tc.name contactsApi_update error - * @tc.desc Function test - */ - it("abnormal_contactsApi_update_test_3000", 0, async function (done) { - var rawContactId = -1; - var updateValues = { - id: rawContactId, name: { - fullName: "小红" - } - }; - var condition = { - attributes: [6] - } - try { - var updateCode = await contactsapi.updateContact(updateValues, condition); - console.info("abnormal_contactsApi_update_test_3000 : updateCode = " + updateCode); - expect(updateCode === 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_update_test_3000 : update error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_contact_test_3100 - * @tc.name contactsApi_query_contact error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_contact_test_3100", 0, async function (done) { - var queryId = "-1"; - try { - var resultSet = await contactsapi.queryContact(queryId); - if (resultSet == null) { - console.info("abnormal_contactsApi_query_contact_test_3100 is null"); - } - if (resultSet == undefined) { - console.info("abnormal_contactsApi_query_contact_test_3100 is undefined"); - } - console.info("abnormal_contactsApi_query_contact_test_3100 : updateCode = " + JSON.stringify(resultSet)); - expect(resultSet == undefined).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_query_contact_test_3100 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_contacts_test_3200 - * @tc.name contactsApi_query_contacts error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_contacts_test_3200", 0, async function (done) { - var ContactAttributes = { - attributes: [100] - } - try { - var resultSet = await contactsapi.queryContacts(ContactAttributes); - if (resultSet == null) { - console.info("abnormal_contactsApi_query_contacts_test_3200 is null"); - } - if (resultSet == undefined) { - console.info("abnormal_contactsApi_query_contacts_test_3200 is undefined"); - } - console.info( - "abnormal_contactsApi_query_contacts_test_3200 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_query_contacts_test_3200 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_email_test_3300 - * @tc.name contactsApi_query_email error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_email_test_3300", 0, async function (done) { - var email = "email2222"; - try { - var resultSet = await contactsapi.queryContactsByEmail(email); - console.info("abnormal_contactsApi_query_email_test_3300 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_query_email_test_3300 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_phoneNumber_test_3400 - * @tc.name contactsApi_query_phoneNumber error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_phoneNumber_test_3400", 0, async function (done) { - var phoneNumber = "19999999"; - try { - var resultSet = await contactsapi.queryContactsByPhoneNumber(phoneNumber); - console.info( - "abnormal_contactsApi_query_phoneNumber_test_3400 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_query_phoneNumber_test_3400 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_group_test_3500 - * @tc.name contactsApi_query_group error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_group_test_3500", 0, async function (done) { - var holder = { - bundleName: "com.ohos.contacts2", displayName: "phone2", holderId: 2 - } - try { - var resultSet = await contactsapi.queryGroups(holder); - console.info("abnormal_contactsApi_query_group_test_3500 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("contactsApi_query_group_test_2000 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_key_test_3600 - * @tc.name contactsApi_query_key error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_key_test_3600", 0, async function (done) { - var idtest = -1; - try { - var resultSet = await contactsapi.queryKey(idtest); - console.info("abnormal_contactsApi_query_key_test_3600 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_query_key_test_3600 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_query_mycard_test_3700 - * @tc.name contactsApi_query_mycard error - * @tc.desc Function test - */ - it("abnormal_contactsApi_query_mycard_test_3700", 0, async function (done) { - var ContactAttributes = { - attributes: [100] - }; - try { - var resultSet = await contactsapi.queryMyCard(ContactAttributes); - console.info( - "abnormal_contactsApi_query_mycard_test_3700 : query resultSet = " + JSON.stringify(resultSet)); - expect(resultSet.length == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_query_mycard_test_3700 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_isMyCard_test_3800 - * @tc.name isMyCard is not exist - * @tc.desc Function test - */ - it("abnormal_contactsApi_isMyCard_test_3800", 0, async function (done) { - var id = 999; - try { - var isExist = await contactsapi.isMyCard(id); - console.info("abnormal_contactsApi_isMyCard_test_3800 : query isExist = " + isExist); - expect(isExist == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_isMyCard_test_3800 query error = " + error); - done(); - } - sleep(500); - }); - - /** - * @tc.number abnormal_contactsApi_isLocalContact_test_3900 - * @tc.name contactsApi_isLocalContact is not exist - * @tc.desc Function test - */ - it("abnormal_contactsApi_isLocalContact_test_3900", 0, async function (done) { - var id = 999; - try { - var isExist = await contactsapi.isLocalContact(id); - console.info("abnormal_contactsApi_isLocalContact_test_3900 : query isExist = " + isExist); - expect(isExist == 0).assertTrue(); - done(); - } catch (error) { - console.info("abnormal_contactsApi_isLocalContact_test_3900 query error = " + error); - done(); - } - sleep(500); - }); - - it("contactsApi_addContact_test_100", 0, async function (done) { - contactsapi.addContact(contactData, (err, data) => { - if (err) { - done(); - return; - } - expect(JSON.stringify(data) != -1).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_deleteContact_test_100", 0, async function (done) { - contactsapi.deleteContact('xxx', (err) => { - if (err) { - expect(JSON.stringify(err) == -1).assertTrue(); - done(); - return; - } - expect(false).assertTrue(); - done(); - }); - - sleep(500); - }); - - - it("contactsApi_queryContact_test_100", 0, async function (done) { - contactsapi.queryContact('xxx', (err, data) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - expect(JSON.stringify(data) == undefined).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContact_test_200", 0, async function (done) { - contactsapi.queryContact('xxx', { - holderId: 0 - }, (err, data) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - expect(JSON.stringify(data) == undefined).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContact_test_300", 0, async function (done) { - contactsapi.queryContact('xxx', { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - expect(JSON.stringify(data) == undefined).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContact_test_400", 0, async function (done) { - contactsapi.queryContact('xxx', { - holderId: 0 - }, { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - expect(JSON.stringify(data) == undefined).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContact_test_500", 0, async function (done) { - let promise = contactsapi.queryContact('xxx', { - holderId: 0 - }, { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }); - promise.then((data) => { - expect(JSON.stringify(data) == undefined).assertTrue(); - done(); - }).catch((err) => { - expect(false).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContacts_test_100", 0, async function (done) { - contactsapi.queryContacts((err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContacts_test_200", 0, async function (done) { - contactsapi.queryContacts({ - holderId: 0 - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContacts_test_300", 0, async function (done) { - contactsapi.queryContacts({ - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryContacts_test_400", 0, async function (done) { - contactsapi.queryContacts({ - holderId: 0 - }, { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryContacts_test_500", 0, async function (done) { - let promise = contactsapi.queryContacts({ - holderId: 0 - }, { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }); - promise.then((data) => { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }).catch((err) => { - expect(false).assertTrue(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContactsByPhoneNumber_test_000", 0, async function (done) { - contactsapi.queryContactsByPhoneNumber('138xxxxxxxx', (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContactsByPhoneNumber_test_100", 0, async function (done) { - contactsapi.queryContactsByPhoneNumber('138xxxxxxxx', { - holderId: 0 - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContactsByPhoneNumber_test_200", 0, async function (done) { - contactsapi.queryContactsByPhoneNumber('138xxxxxxxx', { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContactsByPhoneNumber_test_300", 0, async function (done) { - contactsapi.queryContactsByPhoneNumber('138xxxxxxxx', { - holderId: 0 - }, { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryContactsByEmail_test_100", 0, async function (done) { - contactsapi.queryContactsByEmail('xxx@email.com', (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryContactsByEmail_test_200", 0, async function (done) { - contactsapi.queryContactsByEmail('xxx@email.com', { - holderId: 0 - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryContactsByEmail_test_300", 0, async function (done) { - contactsapi.queryContactsByEmail('xxx@email.com', { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryContactsByEmail_test_400", 0, async function (done) { - contactsapi.queryContactsByEmail('xxx@email.com', { - holderId: 0 - }, { - attributes: ["ATTR_EMAIL", "ATTR_NAME"] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryGroups_test_100", 0, async function (done) { - contactsapi.queryGroups((err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryGroups_test_200", 0, async function (done) { - contactsapi.queryGroups({ - holderId: 0 - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryHolders_test_100", 0, async function (done) { - contactsapi.queryHolders((err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryKey_test_100", 0, async function (done) { - contactsapi.queryKey( /*id*/ - 1, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - it("contactsApi_queryKey_test_200", 0, async function (done) { - contactsapi.queryKey( /*id*/ - 1, { - holderId: 1 - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - + describe('ObjectInterfaceTest', function () { - it("contactsApi_queryMyCard_test_100", 0, async function (done) { - contactsapi.queryMyCard((err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; + function sleep(numberMillis) { + var now = new Date(); + var exitTime = now.getTime() + numberMillis; + while (true) { + now = new Date(); + if (now.getTime() > exitTime)return; + } } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - - - it("contactsApi_queryMyCard_test_200", 0, async function (done) { - contactsapi.queryMyCard({ - attributes: ['ATTR_EMAIL', 'ATTR_NAME'] - }, (err, data) => { - if (err) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - return; - } - expect(JSON.stringify(data) === null).assertFalse(); - done(); - }); - sleep(500); - }); - it("contactsApi_updateContact_test_100", 0, async function (done) { - contactsapi.updateContact({ - name: { - fullName: 'xxx' - }, - phoneNumbers: [{ - phoneNumber: '138xxxxxxxx' - }] - }, (err) => { - if (err) { - expect(true).assertTrue(); - done(); - return; + async function driveFn() { + console.info("come in driveFn"); + let driver = await UiDriver.create(); + console.info("driver is " + JSON.stringify(driver)); + sleep(2000); + let button = await driver.findComponent(BY.text('允许')); + console.info("button is " + JSON.stringify(button)); + await button.click(); + sleep(5000); } - console.info('updateContact success'); - done(); - }); - sleep(500); - }); - it("contactsApi_updateContact_test_200", 0, async function (done) { - contactsapi.updateContact({ - fullName: { - fullName: 'xxx' - }, - phoneNumbers: [{ - phoneNumber: '138xxxxxxxx' - }] - }, { - attributes: ['ATTR_EMAIL', 'ATTR_NAME'] - }, (err) => { - if (err) { - expect(true).assertTrue(); - done(); - return; - } - console.info('updateContact success'); - done(); - }); - sleep(500); - }); - - it("contactsApi_isLocalContact_test_100", 0, async function (done) { - contactsapi.isLocalContact( /*id*/ - 1, (err, data) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - done(); - }); - sleep(500); - }); - - it("contactsApi_isMyCard_test_100", 0, async function (done) { - contactsapi.isMyCard( /*id*/ - 1, (err, data) => { - if (err) { - expect(false).assertTrue(); - done(); - return; - } - done(); - }); - sleep(500); - }); - - it("contactsApi_sendMessage_test_100", 0, async function (done) { - let sendCallback = function (err, data) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - } - let deliveryCallback = function (err, data) { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - } - let slotId = 0; - let content = '短信内容'; - let destinationHost = '+861xxxxxxxxxx'; - let serviceCenter = '+861xxxxxxxxxx'; - let destinationPort = 1000; - let options = { - slotId, - content, - destinationHost, - serviceCenter, - destinationPort, - sendCallback, - deliveryCallback - }; - sms.sendMessage(options); - done(); - sleep(500); - }); - - it("contactsApi_selectContact_test_100", 0, async function (done) { - contactsapi.selectContact((err, data) => { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - sleep(500); - }); - }); - - it("contactsApi_selectContact_test_200", 0, async function (done) { - let promise = contactsapi.selectContact(); - promise.then((data) => { - expect(JSON.stringify(data) === null).assertFalse(); - done(); - sleep(500); - }).catch((err) => { - done(); - }); + beforeAll(async function () { + var permissions = ["ohos.permission.WRITE_CONTACTS", "ohos.permission.READ_CONTACTS"]; + featureAbility.getContext().requestPermissionsFromUser(permissions, 0, () => { + console.info("start requestPermissionsFromUser"); + }); + for (let i = 0; i < 2; i++) { + await driveFn(); + console.log("get user_grant permission"); + } + }); + + afterAll(async function () { + contact.queryContacts((err, data) => { + if (err) { + console.info("contactsApi_selectContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + return; + } + console.info("contactsApi_selectContact_test_100 data = " + JSON.stringify(data)); + if (data.length == 0) { + return; + } + for (var i = 0;i < data.length; i++) { + let promise = contact.deleteContact(data[i].key); + promise.then(() => { + console.info("deleteContact success"); + }).catch((err) => { + console.info("contactsApi_selectContact_test_100 err = " + JSON.stringify(err)); + }); + } + sleep(3000); + }); + }); + + var contactData = { + id: 0, + key: "0", + contactAttributes: { + attributes: [contact.Attribute.ATTR_CONTACT_EVENT, contact.Attribute.ATTR_EMAIL, + contact.Attribute.ATTR_GROUP_MEMBERSHIP, + contact.Attribute.ATTR_IM, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_NICKNAME, + contact.Attribute.ATTR_NOTE, contact.Attribute.ATTR_ORGANIZATION, contact.Attribute.ATTR_PHONE, + contact.Attribute.ATTR_PORTRAIT, contact.Attribute.ATTR_POSTAL_ADDRESS, + contact.Attribute.ATTR_RELATION, + contact.Attribute.ATTR_SIP_ADDRESS, contact.Attribute.ATTR_WEBSITE] + }, + emails: [{ + email: "13800000000@email.com", labelName: "自定义邮箱", labelId: 1, displayName: "emailDisplayName" + }], + events: [{ + eventDate: "event", labelName: "自定义event", labelId: 2 + }], + groups: [{ + groupId: 1, title: "群组" + }], + imAddresses: [{ + imAddress: "imAddress", labelName: "自定义", labelId: 3 + }], + phoneNumbers: [{ + phoneNumber: "13800000000", labelName: "自定义phoneNumbers", labelId: 4 + }], + portrait: { + uri: "content://head/0" + }, + postalAddresses: [{ + city: "南京", + country: "中国", + labelName: "labelName", + neighborhood: "neighborhood", + pobox: "pobox", + postalAddress: "postalAddress", + postcode: "postcode", + region: "region", + street: "street", + labelId: 5 + }], + relations: [{ + relationName: "relationName", labelName: "自定义relationName", labelId: 6 + }], + sipAddresses: [{ + sipAddress: "sipAddress", labelName: "自定义sipAddress", labelId: 6 + }], + websites: [{ + website: "website" + }], + name: { + familyName: "familyName", + familyNamePhonetic: "familyNamePhonetic", + fullName: "小李", + givenName: "givenName", + givenNamePhonetic: "givenNamePhonetic", + middleName: "middleName", + middleNamePhonetic: "middleNamePhonetic", + namePrefix: "namePrefix", + nameSuffix: "nameSuffix" + }, + nickName: { + nickName: "nickName" + }, + note: { + noteContent: "note" + }, + organization: { + name: "TT", title: "开发" + } + }; + + var holder = { + holderId: 1, + bundleName: "com.ohos.contacts", + displayName: "phone" + }; + var attr = { + attributes: [contact.Attribute.ATTR_CONTACT_EVENT, contact.Attribute.ATTR_EMAIL, + contact.Attribute.ATTR_GROUP_MEMBERSHIP, + contact.Attribute.ATTR_IM, contact.Attribute.ATTR_NAME, contact.Attribute.ATTR_NICKNAME, + contact.Attribute.ATTR_NOTE, contact.Attribute.ATTR_ORGANIZATION, contact.Attribute.ATTR_PHONE, + contact.Attribute.ATTR_PORTRAIT, contact.Attribute.ATTR_POSTAL_ADDRESS, + contact.Attribute.ATTR_RELATION, + contact.Attribute.ATTR_SIP_ADDRESS, contact.Attribute.ATTR_WEBSITE] + }; + + it("contactsApi_contactdata_test_100", 0, async function (done) { + console.info("contactData.id" + contactData.id); + console.info("contactData.id" + (contactData.id == 0)); + expect(contactData.id == 0).assertTrue(); + console.info("contactData.key" + contactData.key); + console.info("contactData.key" + (contactData.key == "0")); + expect(contactData.key).assertEqual("0"); + console.info("contactData.contactAttributes" + contactData.contactAttributes); + console.info("contactData.contactAttributes" + (contactData.contactAttributes != null)); + expect(contactData.contactAttributes != null).assertTrue(); + console.info("contactData.emails" + contactData.emails); + expect(contactData.emails != null).assertTrue(); + expect(contactData.events != null).assertTrue(); + expect(contactData.groups != null).assertTrue(); + expect(contactData.imAddresses != null).assertTrue(); + done(); + }); + + it("contactsApi_contactdata_test_200", 0, async function (done) { + expect(contactData.phoneNumbers != null).assertTrue(); + expect(contactData.portrait != null).assertTrue(); + expect(contactData.postalAddresses != null).assertTrue(); + expect(contactData.relations != null).assertTrue(); + expect(contactData.sipAddresses != null).assertTrue(); + expect(contactData.websites != null).assertTrue(); + expect(contactData.name != null).assertTrue(); + expect(contactData.nickName != null).assertTrue(); + expect(contactData.note != null).assertTrue(); + expect(contactData.organization != null).assertTrue(); + expect(contactData.contactAttributes.attributes != null).assertTrue(); + done(); + }); + + it("contactsApi_contactdata_test_300", 0, async function (done) { + expect(contactData.emails[0].email === null).assertFalse(); + expect(contactData.emails[0].labelName === null).assertFalse(); + console.info("contactData.emails.labelId == 1" + contactData.emails[0].labelId); + expect(contactData.emails[0].labelId != 0).assertTrue(); + expect(contactData.emails[0].displayName === null).assertFalse(); + expect(contactData.events[0].eventDate === null).assertFalse(); + expect(contactData.events[0].labelName === null).assertFalse(); + expect(contactData.events[0].labelId != 0).assertTrue(); + expect(contactData.groups[0].groupId != 0).assertTrue(); + expect(contactData.groups[0].title === null).assertFalse(); + done(); + }); + it("contactsApi_contactdata_test_400", 0, async function (done) { + expect(contactData.imAddresses[0].imAddress === null).assertFalse(); + expect(contactData.imAddresses[0].labelName === null).assertFalse(); + expect(contactData.imAddresses[0].labelId != 0).assertTrue(); + expect(contactData.name.familyName === null).assertFalse(); + expect(contactData.name.familyNamePhonetic === null).assertFalse(); + expect(contactData.name.fullName === null).assertFalse(); + expect(contactData.name.givenName === null).assertFalse(); + expect(contactData.name.givenNamePhonetic === null).assertFalse(); + expect(contactData.name.middleName === null).assertFalse(); + expect(contactData.name.middleNamePhonetic === null).assertFalse(); + expect(contactData.name.namePrefix === null).assertFalse(); + expect(contactData.name.nameSuffix === null).assertFalse(); + done(); + }); + + it("contactsApi_contactdata_test_500", 0, async function (done) { + expect(contactData.nickName.nickName === null).assertFalse(); + expect(contactData.note.noteContent === null).assertFalse(); + expect(contactData.organization.name === null).assertFalse(); + expect(contactData.organization.title === null).assertFalse(); + expect(contactData.phoneNumbers[0].labelId != 0).assertTrue(); + expect(contactData.phoneNumbers[0].labelName === null).assertFalse(); + expect(contactData.phoneNumbers[0].phoneNumber === null).assertFalse(); + expect(contactData.portrait.uri === null).assertFalse(); + done(); + }); + + it("contactsApi_contactdata_test_600", 0, async function (done) { + console.info("contactData.postalAddresses.city != null" + + contactData.postalAddresses[0].city + + (contactData.postalAddresses[0].city != null)); + expect(contactData.postalAddresses[0].city === null).assertFalse(); + expect(contactData.postalAddresses[0].country === null).assertFalse(); + expect(contactData.postalAddresses[0].labelName === null).assertFalse(); + expect(contactData.postalAddresses[0].neighborhood === null).assertFalse(); + expect(contactData.postalAddresses[0].pobox === null).assertFalse(); + expect(contactData.postalAddresses[0].postalAddress === null).assertFalse(); + expect(contactData.postalAddresses[0].postcode === null).assertFalse(); + expect(contactData.postalAddresses[0].region === null).assertFalse(); + expect(contactData.postalAddresses[0].street === null).assertFalse(); + expect(contactData.postalAddresses[0].labelId != 0).assertTrue(); + done(); + }); + + it("contactsApi_contactdata_test_700", 0, async function (done) { + console.info("contactData.relations.labelName != null" + + contactData.relations[0].labelName + (contactData.relations[0].labelName === null)); + expect(contactData.relations[0].labelId != 0).assertTrue(); + expect(contactData.relations[0].labelName === null).assertFalse(); + expect(contactData.relations[0].relationName === null).assertFalse(); + expect(contactData.sipAddresses[0].labelId != 0).assertTrue(); + expect(contactData.sipAddresses[0].labelName === null).assertFalse(); + expect(contactData.sipAddresses[0].sipAddress === null).assertFalse(); + expect(contactData.websites[0].website === null).assertFalse(); + done(); + }); + + + it("contactsApi_contactdata_test_800", 0, async function (done) { + expect(contact.Contact.INVALID_CONTACT_ID == -1).assertTrue(); + expect(contact.Attribute.ATTR_CONTACT_EVENT == + contactData.contactAttributes.attributes[0]).assertTrue(); + expect(contact.Attribute.ATTR_EMAIL == contactData.contactAttributes.attributes[1]).assertTrue(); + expect(contact.Attribute.ATTR_GROUP_MEMBERSHIP == + contactData.contactAttributes.attributes[2]).assertTrue(); + expect(contact.Attribute.ATTR_IM == contactData.contactAttributes.attributes[3]).assertTrue(); + expect(contact.Attribute.ATTR_NAME == contactData.contactAttributes.attributes[4]).assertTrue(); + expect(contact.Attribute.ATTR_NICKNAME == contactData.contactAttributes.attributes[5]).assertTrue(); + expect(contact.Attribute.ATTR_NOTE == contactData.contactAttributes.attributes[6]).assertTrue(); + expect(contact.Attribute.ATTR_ORGANIZATION == contactData.contactAttributes.attributes[7]).assertTrue(); + expect(contact.Attribute.ATTR_PHONE == contactData.contactAttributes.attributes[8]).assertTrue(); + expect(contact.Attribute.ATTR_PORTRAIT == contactData.contactAttributes.attributes[9]).assertTrue(); + expect(contact.Attribute.ATTR_POSTAL_ADDRESS == + contactData.contactAttributes.attributes[10]).assertTrue(); + expect(contact.Attribute.ATTR_RELATION == contactData.contactAttributes.attributes[11]).assertTrue(); + expect(contact.Attribute.ATTR_SIP_ADDRESS == contactData.contactAttributes.attributes[12]).assertTrue(); + expect(contact.Attribute.ATTR_WEBSITE == contactData.contactAttributes.attributes[13]).assertTrue(); + done(); + }); + + it("contactsApi_contactdata_test_900", 0, async function (done) { + expect(contact.Email.CUSTOM_LABEL == 0).assertTrue(); + expect(contact.Email.EMAIL_HOME == 1).assertTrue(); + expect(contact.Email.EMAIL_WORK == 2).assertTrue(); + expect(contact.Email.EMAIL_OTHER == 3).assertTrue(); + expect(contact.Email.INVALID_LABEL_ID == -1).assertTrue(); + expect(contact.Event.CUSTOM_LABEL == 0).assertTrue(); + expect(contact.Event.EVENT_ANNIVERSARY == 1).assertTrue(); + expect(contact.Event.EVENT_OTHER == 2).assertTrue(); + expect(contact.Event.EVENT_BIRTHDAY == 3).assertTrue(); + expect(contact.Email.INVALID_LABEL_ID == -1).assertTrue(); + expect(contact.ImAddress.CUSTOM_LABEL == -1).assertTrue(); + expect(contact.ImAddress.IM_AIM == 0).assertTrue(); + expect(contact.ImAddress.IM_MSN == 1).assertTrue(); + expect(contact.ImAddress.IM_YAHOO == 2).assertTrue(); + expect(contact.ImAddress.IM_SKYPE == 3).assertTrue(); + expect(contact.ImAddress.IM_QQ == 4).assertTrue(); + expect(contact.ImAddress.IM_ICQ == 6).assertTrue(); + expect(contact.ImAddress.IM_JABBER == 7).assertTrue(); + expect(contact.ImAddress.INVALID_LABEL_ID == -2).assertTrue(); + done(); + }); + + it("contactsApi_contactdata_test_1000", 0, async function (done) { + expect(contact.PhoneNumber.CUSTOM_LABEL == 0).assertTrue(); + expect(contact.PhoneNumber.NUM_HOME == 1).assertTrue(); + expect(contact.PhoneNumber.NUM_MOBILE == 2).assertTrue(); + expect(contact.PhoneNumber.NUM_WORK == 3).assertTrue(); + expect(contact.PhoneNumber.NUM_FAX_WORK == 4).assertTrue(); + expect(contact.PhoneNumber.NUM_FAX_HOME == 5).assertTrue(); + expect(contact.PhoneNumber.NUM_PAGER == 6).assertTrue(); + expect(contact.PhoneNumber.NUM_OTHER == 7).assertTrue(); + expect(contact.PhoneNumber.NUM_CALLBACK == 8).assertTrue(); + expect(contact.PhoneNumber.NUM_CAR == 9).assertTrue(); + expect(contact.PhoneNumber.NUM_COMPANY_MAIN == 10).assertTrue(); + expect(contact.PhoneNumber.NUM_ISDN == 11).assertTrue(); + expect(contact.PhoneNumber.NUM_MAIN == 12).assertTrue(); + expect(contact.PhoneNumber.NUM_OTHER_FAX == 13).assertTrue(); + expect(contact.PhoneNumber.NUM_RADIO == 14).assertTrue(); + expect(contact.PhoneNumber.NUM_TELEX == 15).assertTrue(); + expect(contact.PhoneNumber.NUM_TTY_TDD == 16).assertTrue(); + expect(contact.PhoneNumber.NUM_WORK_MOBILE == 17).assertTrue(); + expect(contact.PhoneNumber.NUM_WORK_PAGER == 18).assertTrue(); + expect(contact.PhoneNumber.NUM_ASSISTANT == 19).assertTrue(); + expect(contact.PhoneNumber.NUM_MMS == 20).assertTrue(); + expect(contact.PhoneNumber.INVALID_LABEL_ID == -1).assertTrue(); + expect(contact.PostalAddress.CUSTOM_LABEL == 0).assertTrue(); + expect(contact.PostalAddress.ADDR_HOME == 1).assertTrue(); + expect(contact.PostalAddress.ADDR_WORK == 2).assertTrue(); + expect(contact.PostalAddress.ADDR_OTHER == 3).assertTrue(); + expect(contact.PostalAddress.INVALID_LABEL_ID == -1).assertTrue(); + done(); + }); + + it("contactsApi_contactdata_test_1100", 0, async function (done) { + expect(contact.Relation.CUSTOM_LABEL == 0).assertTrue(); + expect(contact.Relation.RELATION_ASSISTANT == 1).assertTrue(); + expect(contact.Relation.RELATION_BROTHER == 2).assertTrue(); + expect(contact.Relation.RELATION_CHILD == 3).assertTrue(); + expect(contact.Relation.RELATION_DOMESTIC_PARTNER == 4).assertTrue(); + expect(contact.Relation.RELATION_FATHER == 5).assertTrue(); + expect(contact.Relation.RELATION_FRIEND == 6).assertTrue(); + expect(contact.Relation.RELATION_MANAGER == 7).assertTrue(); + expect(contact.Relation.RELATION_MOTHER == 8).assertTrue(); + expect(contact.Relation.RELATION_PARENT == 9).assertTrue(); + expect(contact.Relation.RELATION_PARTNER == 10).assertTrue(); + expect(contact.Relation.RELATION_REFERRED_BY == 11).assertTrue(); + expect(contact.Relation.RELATION_RELATIVE == 12).assertTrue(); + expect(contact.Relation.RELATION_SISTER == 13).assertTrue(); + expect(contact.Relation.RELATION_SPOUSE == 14).assertTrue(); + expect(contact.Relation.INVALID_LABEL_ID == -1).assertTrue(); + expect(contact.SipAddress.CUSTOM_LABEL == 0).assertTrue(); + expect(contact.SipAddress.SIP_HOME == 1).assertTrue(); + expect(contact.SipAddress.SIP_WORK == 2).assertTrue(); + expect(contact.SipAddress.SIP_OTHER == 3).assertTrue(); + expect(contact.SipAddress.INVALID_LABEL_ID == -1).assertTrue(); + done(); + }); + + /** + * @tc.number contactsApi_query_key_test_2300 + * @tc.name Query key information + * @tc.desc Function test + */ + it("contactsApi_query_key_test_2300", 0, async function (done) { + var rawContactId = await contact.addContact(contactData); + expect(rawContactId > 0).assertTrue(); + var holder = { + bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 + } + try { + var resultSet = await contact.queryKey(rawContactId, holder); + console.info("contactsApi_query_key_test_2300 : query resultSet = " + JSON.stringify(resultSet)); + expect(JSON.stringify(resultSet) === null).assertFalse(); + done(); + } catch (error) { + console.info("contactsApi_query_key_test_2300 query error = " + error); + done(); + } + sleep(500); + }); + + /** + * @tc.number contactsApi_query_key_test_2400 + * @tc.name Query key information + * @tc.desc Function test + */ + it("contactsApi_query_key_test_2400", 0, async function (done) { + var rawContactId = await contact.addContact(contactData); + expect(rawContactId > 0).assertTrue(); + console.info("contactsApi_query_key_test_2400 : query gRawContactId = " + rawContactId); + try { + var resultSet = await contact.queryKey(rawContactId); + console.info("contactsApi_query_key_test_2400 : query resultSet = " + JSON.stringify(resultSet)); + expect(JSON.stringify(resultSet) === null).assertFalse(); + done(); + } catch (error) { + console.info("contactsApi_query_key_test_2400 query error = " + error); + done(); + } + sleep(500); + }); + + /** + * @tc.number abnormal_contactsApi_insert_test_2800 + * @tc.name contactsApi_insert error + * @tc.desc Function test + */ + it("abnormal_contactsApi_insert_test_2800", 0, async function (done) { + var contactDataError = {}; + try { + var rawContactId = await contact.addContact(contactDataError); + console.info("abnormal_contactsApi_insert_test_2800 : rawContactId = " + rawContactId); + expect(rawContactId == -1).assertTrue(); + done(); + } catch (error) { + console.info("contactsApi_insert_test_100 : raw_contact insert error = " + error); + done(); + } + sleep(500); + }); + + /** + * @tc.number abnormal_contactsApi_query_contact_test_3100 + * @tc.name contactsApi_query_contact error + * @tc.desc Function test + */ + it("abnormal_contactsApi_query_contact_test_3100", 0, async function (done) { + var queryId = "-1"; + try { + var resultSet = await contact.queryContact(queryId); + if (resultSet == null) { + console.info("abnormal_contactsApi_query_contact_test_3100 is null"); + } + if (resultSet == undefined) { + console.info("abnormal_contactsApi_query_contact_test_3100 is undefined"); + } + console.info("abnormal_contactsApi_query_contact_test_3100 : updateCode = " + JSON.stringify(resultSet)); + expect(resultSet == undefined).assertTrue(); + done(); + } catch (error) { + console.info("abnormal_contactsApi_query_contact_test_3100 query error = " + error); + done(); + } + sleep(500); + }); + + /** + * @tc.number abnormal_contactsApi_query_email_test_3300 + * @tc.name contactsApi_query_email error + * @tc.desc Function test + */ + it("abnormal_contactsApi_query_email_test_3300", 0, async function (done) { + var email = "email2222"; + try { + var resultSet = await contact.queryContactsByEmail(email); + console.info("abnormal_contactsApi_query_email_test_3300 : query resultSet = " + JSON.stringify(resultSet)); + expect(resultSet.length == 0).assertTrue(); + done(); + } catch (error) { + console.info("abnormal_contactsApi_query_email_test_3300 query error = " + error); + done(); + } + sleep(500); + }); + + /** + * @tc.number abnormal_contactsApi_query_phoneNumber_test_3400 + * @tc.name contactsApi_query_phoneNumber error + * @tc.desc Function test + */ + it("abnormal_contactsApi_query_phoneNumber_test_3400", 0, async function (done) { + var phoneNumber = "19999999"; + try { + var resultSet = await contact.queryContactsByPhoneNumber(phoneNumber); + console.info( + "abnormal_contactsApi_query_phoneNumber_test_3400 : query resultSet = " + JSON.stringify(resultSet)); + expect(resultSet.length == 0).assertTrue(); + done(); + } catch (error) { + console.info("abnormal_contactsApi_query_phoneNumber_test_3400 query error = " + error); + done(); + } + sleep(500); + }); + + /** + * @tc.number abnormal_contactsApi_query_key_test_3600 + * @tc.name contactsApi_query_key error + * @tc.desc Function test + */ + it("abnormal_contactsApi_query_key_test_3600", 0, async function (done) { + var idtest = -1; + try { + var resultSet = await contact.queryKey(idtest); + console.info("abnormal_contactsApi_query_key_test_3600 : query resultSet = " + JSON.stringify(resultSet)); + expect(resultSet.length == 0).assertTrue(); + done(); + } catch (error) { + console.info("abnormal_contactsApi_query_key_test_3600 query error = " + error); + done(); + } + sleep(500); + }); + + it("contactsApi_addContact_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_addContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_addContact_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.deleteContact(data + '', (err) => { + if (err) { + console.info("contactsApi_addContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.log('deleteContact success'); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_addContact_test_200", 0, async function (done) { + let promise = contact.addContact(contactData); + promise.then((data) => { + console.info("contactsApi_addContact_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.deleteContact(data + ''); + promise.then(() => { + console.log(`deleteContact success`); + done(); + }).catch((err) => { + console.info("contactsApi_addContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }).catch((err) => { + console.info("contactsApi_addContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + sleep(500); + }); + + it("contactsApi_queryContact_test_100", 0, async function (done) { + var holder = { + bundleName: "com.ohos.contacts", displayName: "phone", holderId: 1 + } + expect(holder.bundleName === null).assertFalse(); + expect(holder.displayName === null).assertFalse(); + expect(holder.holderId != 0).assertTrue(); + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContact(data + '', (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_100 data = " + JSON.stringify(data)); + expect(data.emails[0].email != '').assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContact_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContact(data + '', holder, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_200 data = " + JSON.stringify(data)); + expect(data.emails[0].email != '').assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContact_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContact(data + '', attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_300 data = " + JSON.stringify(data)); + expect(data.emails[0].email != '').assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContact_test_400", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_400 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContact(data + '', holder, attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_400 data = " + JSON.stringify(data)); + expect(data.emails[0].email != '').assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContact_test_500", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContact_test_500 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContact_test_500 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.queryContact(data + '', holder, attr); + promise.then((data) => { + console.info("contactsApi_queryContact_test_500 data = " + JSON.stringify(data)); + expect(data.emails[0].email != '').assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryContact_test_500 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_queryContacts_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContacts((err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_100 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContacts_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContacts(holder, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_200 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContacts_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContacts(attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_300 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + + it("contactsApi_queryContacts_test_400", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_400 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContacts(holder, attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_400 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + + it("contactsApi_queryContacts_test_500", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContacts_test_500 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContacts_test_500 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.queryContacts(holder, attr); + promise.then((data) => { + console.info("contactsApi_queryContacts_test_500 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryContacts_test_500 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByPhoneNumber_test_000", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_000 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_000 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByPhoneNumber('13800000000', (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_000 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_000 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByPhoneNumber_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByPhoneNumber('13800000000', holder, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_100 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByPhoneNumber_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByPhoneNumber('13800000000', attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_200 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByPhoneNumber_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByPhoneNumber('13800000000', holder, attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_300 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByPhoneNumber_test_400", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByPhoneNumber_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByPhoneNumber_test_400 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.queryContactsByPhoneNumber('13800000000', holder, attr); + promise.then((data) => { + console.info("contactsApi_queryContactsByPhoneNumber_test_400 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryContactsByPhoneNumber_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByEmail_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByEmail('13800000000@email.com', (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_100 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByEmail_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByEmail('13800000000@email.com', holder, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_200 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + + it("contactsApi_queryContactsByEmail_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByEmail('13800000000@email.com', attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_300 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + + it("contactsApi_queryContactsByEmail_test_400", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_400 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryContactsByEmail('13800000000@email.com', holder, attr, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_400 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_400 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryContactsByEmail_test_500", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryContactsByEmail_test_500 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryContactsByEmail_test_500 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.queryContactsByEmail('13800000000@email.com', holder, attr); + promise.then((data) => { + console.info("contactsApi_queryContactsByEmail_test_500 data = " + JSON.stringify(data)); + expect(data.length > 0).assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryContactsByEmail_test_500 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_queryGroups_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryGroups_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryGroups_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryGroups((err, data) => { + if (err) { + console.info("contactsApi_queryGroups_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryGroups_test_100 data = " + JSON.stringify(data)); + expect(data.length >= 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryGroups_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryGroups_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryGroups_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryGroups(holder, (err, data) => { + if (err) { + console.info("contactsApi_queryGroups_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryGroups_test_200 data = " + JSON.stringify(data)); + expect(data.length >= 0).assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryGroups_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryGroups_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryGroups_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.queryGroups(holder); + promise.then((data) => { + console.info("contactsApi_queryGroups_test_300 data = " + JSON.stringify(data)); + expect(data.length >= 0).assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryGroups_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_queryHolders_test_100", 0, async function (done) { + contact.queryHolders((err, data) => { + if (err) { + console.info("contactsApi_queryHolders_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryHolders_test_100 data = " + JSON.stringify(data)); + expect(data.length >= 0).assertTrue(); + done(); + }); + sleep(500); + }); + + it("contactsApi_queryHolders_test_200", 0, async function (done) { + let promise = contact.queryHolders(); + promise.then((data) => { + console.info("contactsApi_queryHolders_test_200 data = " + JSON.stringify(data)); + expect(data.length >= 0).assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryHolders_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + sleep(500); + }); + + it("contactsApi_queryKey_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryKey_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryKey_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryKey(data, (err, keyData) => { + if (err) { + console.info("contactsApi_queryKey_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryKey_test_100 keyData = " + JSON.stringify(keyData)); + expect(keyData != '').assertTrue(); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_queryKey_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryKey_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryKey_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.queryKey(data, holder, (err, keyData) => { + if (err) { + console.info("contactsApi_queryKey_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryKey_test_200 keyData = " + JSON.stringify(keyData)); + expect(keyData != '').assertTrue(); + done(); + }); + }); + sleep(500); + }); + it("contactsApi_queryKey_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_queryKey_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryKey_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.queryKey(data, holder); + promise.then((keyData) => { + console.info("contactsApi_queryKey_test_300 keyData = " + JSON.stringify(keyData)); + expect(keyData != '').assertTrue(); + done(); + }).catch((err) => { + console.info("contactsApi_queryKey_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + + it("contactsApi_queryMyCard_test_100", 0, async function (done) { + contact.queryMyCard((err, data) => { + if (err) { + console.info("contactsApi_queryMyCard_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryMyCard_test_100 data = " + JSON.stringify(data)); + done(); + }); + sleep(500); + }); + + + it("contactsApi_queryMyCard_test_200", 0, async function (done) { + contact.queryMyCard(attr, (err, data) => { + if (err) { + console.info("contactsApi_queryMyCard_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_queryMyCard_test_200 data = " + JSON.stringify(data)); + done(); + }); + sleep(500); + }); + + it("contactsApi_queryMyCard_test_300", 0, async function (done) { + let promise = contact.queryMyCard(attr); + promise.then((data) => { + console.info("contactsApi_queryMyCard_test_200 data = " + JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("contactsApi_queryMyCard_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + sleep(500); + }); + + it("contactsApi_updateContact_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_updateContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_updateContact_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.updateContact({ + id: data, + key: data + '', + emails: [{ + email: "13800000001@email.com", + labelName: "自定义邮箱", + labelId: 1, + displayName: "emailDisplayName" + }] + }, (err) => { + if (err) { + console.info("contactsApi_updateContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.log('updateContact success'); + contact.queryContact(data + '', (err, data) => { + if (err) { + console.info("contactsApi_updateContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_updateContact_test_100 data = " + JSON.stringify(data)); + expect(data.emails[0].email == "13800000001@email.com").assertTrue(); + done(); + }); + }); + }); + sleep(500); + }); + + it("contactsApi_updateContact_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_updateContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_updateContact_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.updateContact({ + id: data, + key: data + '', + emails: [{ + email: "13800000001@email.com", + labelName: "自定义邮箱", + labelId: 1, + displayName: "emailDisplayName" + }] + }, attr, (err) => { + if (err) { + console.info("contactsApi_updateContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.log('updateContact success'); + contact.queryContact(data + '', (err, data) => { + if (err) { + console.info("contactsApi_updateContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_updateContact_test_200 data = " + JSON.stringify(data)); + expect(data.emails[0].email == "13800000001@email.com").assertTrue(); + done(); + }); + }); + }); + sleep(500); + }); + + it("contactsApi_updateContact_test_300", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_updateContact_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_updateContact_test_300 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.updateContact({ + id: data, + key: data + '', + emails: [{ + email: "13800000001@email.com", + labelName: "自定义邮箱", + labelId: 1, + displayName: "emailDisplayName" + }] + }, attr); + promise.then(() => { + console.log('updateContact success'); + contact.queryContact(data + '', (err, data) => { + if (err) { + console.info("contactsApi_updateContact_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_updateContact_test_300 data = " + JSON.stringify(data)); + expect(data.emails[0].email == "13800000001@email.com").assertTrue(); + done(); + }); + }).catch((err) => { + console.info("contactsApi_updateContact_test_300 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_isLocalContact_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_isLocalContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_isLocalContact_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.isLocalContact(data, (err, data) => { + if (err) { + console.info("contactsApi_isLocalContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_isLocalContact_test_100 data = " + JSON.stringify(data)); + done(); + }); + }); + sleep(500); + }); + + it("contactsApi_isLocalContact_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_isLocalContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_isLocalContact_test_200 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.isLocalContact(data); + promise.then((data) => { + console.info("contactsApi_isLocalContact_test_200 data = " + JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("contactsApi_isLocalContact_test_200 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + it("contactsApi_isMyCard_test_100", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_isMyCard_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_isMyCard_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + contact.isMyCard(data, (err, data) => { + if (err) { + console.info("contactsApi_isMyCard_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_isMyCard_test_100 data = " + JSON.stringify(data)); + done(); + }); + }); + sleep(500); + }); + + + it("contactsApi_isMyCard_test_200", 0, async function (done) { + contact.addContact(contactData, (err, data) => { + if (err) { + console.info("contactsApi_isMyCard_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + } + console.info("contactsApi_isMyCard_test_100 data = " + JSON.stringify(data)); + expect(data > 0).assertTrue(); + let promise = contact.isMyCard(data); + promise.then((data) => { + console.info("contactsApi_isMyCard_test_100 data = " + JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("contactsApi_isMyCard_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + return; + }); + }); + sleep(500); + }); + + + it("contactsApi_sendMessage_test_100", 0, async function (done) { + let sendCallback = function (err, data) { + console.info("contactsApi_sendMessage_test_100 err = " + JSON.stringify(err)); + expect(JSON.stringify(data) === null).assertFalse(); + done(); + } + let deliveryCallback = function (err, data) { + console.info("contactsApi_sendMessage_test_100 err = " + JSON.stringify(err)); + expect(JSON.stringify(data) === null).assertFalse(); + done(); + } + let slotId = 0; + let content = '短信内容'; + let destinationHost = '+861xxxxxxxxxx'; + let serviceCenter = '+861xxxxxxxxxx'; + let destinationPort = 1000; + let options = { + slotId, + content, + destinationHost, + serviceCenter, + destinationPort, + sendCallback, + deliveryCallback + }; + sms.sendMessage(options); + done(); + sleep(500); + }); + + it("contactsApi_selectContact_test_100", 0, async function (done) { + contact.selectContact((err, data) => { + if (err) { + console.info("contactsApi_selectContact_test_100 err = " + JSON.stringify(err)); + done(); + return; + } + console.info("contactsApi_selectContact_test_100 data = " + JSON.stringify(data)); + expect(false).assertTrue(); + done(); + }); + }); + + it("contactsApi_selectContact_test_200", 0, async function (done) { + let promise = contact.selectContact(); + promise.then((data) => { + console.info("contactsApi_selectContact_test_100 data = " + JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("contactsApi_selectContact_test_100 err = " + JSON.stringify(err)); + expect(false).assertTrue(); + done(); + }); + }); }); - }); } \ No newline at end of file diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromise.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromise.js deleted file mode 100644 index 10981333a..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromise.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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. - */ - -export function toString (data) { - if (typeof data === 'object') { - return JSON.stringify(data); - } else { - return data; - } -} - -export function promisify (fn) { - return function () { - let args = Array.prototype.slice.call(arguments); - return new Promise(function (resolve, reject) { - console.log(`Telephony_CallManager promisify args:${toString(arguments)},fn:${fn}`); - args.push(function (error, data) { - console.log(`Telephony_CallManager promisify error:${toString(error)},data:${toString(data)}`); - if (error) { - reject(error); - } else { - resolve(data); - } - }); - fn.apply(null, args); - }); - }; -} \ No newline at end of file diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromisePerfomance.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromisePerfomance.js deleted file mode 100644 index 09c3181de..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromisePerfomance.js +++ /dev/null @@ -1,139 +0,0 @@ - -/** - * 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_PERF_COUNT, PERF_GOAL_TIME} from './Const.js'; -import {toString} from './ApiToPromise.js'; -// packaging the function to the perfomace test function -export async function apiToPromisePerfomace (options, args) { - // recursion plan - let {func, caseName, target, perfTime, compareFunc} = options; - let flag = true; - let count = TEST_PERF_COUNT; - perfTime = perfTime ? perfTime : PERF_GOAL_TIME; - - console.log(`${caseName} apiToPromisePerfomace func ${func}, caseName ${caseName},args:${toString(args)}`); - function excuteCallbackPromise () { - return new Promise((resolve, reject) => { - function excuteCallback () { - target[func](...args); - } - args[args.length - 1] = function (error, data) { - if (count === 0) { - if (flag) { - resolve(flag); - } else { - reject(new Error(`flag:${flag}`)); - } - } else { - flag = flag && !!compareFunc(error, data); - count--; - excuteCallback(); - } - }; - excuteCallback(); - }); - } - - let startTime = new Date().getTime(); - if (typeof args[args.length - 1] === 'function') { - try { - flag = await excuteCallbackPromise(); - } catch (error) { - flag = false; - } - } else { - for (;count > 0;count--) { - let error = null; - let data = null; - try { - data = await target[func](...args); - flag = flag && !!compareFunc(error, data); - } catch (err) { - error = err; - flag = flag && !!compareFunc(error, data); - } - } - } - let endTime = new Date().getTime(); - const cost = endTime - startTime; - console.log(`${caseName} ${func} result flag:${toString(flag)} count:${TEST_PERF_COUNT}` + - ` cost:${cost}ms avarage:${parseInt(cost * 1000 / TEST_PERF_COUNT)}`); - if (flag && cost < perfTime) { - return flag; - } else { - throw new Error(`flag:${flag}`); - } -} - -export async function apiToPerfomace (options, args) { - // recursion plan - let {func, caseName, target, perfTime, compareFunc, runedFunc} = options; - let flag = true; - let count = TEST_PERF_COUNT; - perfTime = perfTime ? perfTime : PERF_GOAL_TIME; - - console.log(`${caseName} apiToPerfomace func ${func}, caseName ${caseName},args:${toString(args)}`); - function excuteCallbackPromise () { - return new Promise((resolve, reject) => { - function excuteCallback () { - target[func](...args); - } - args[args.length - 1] = function (error, data) { - if (count === 0) { - if (flag) { - resolve(flag); - } else { - reject(new Error(`flag:${flag}`)); - } - } else { - flag = flag && !!compareFunc(error, data); - count--; - excuteCallback(); - } - }; - excuteCallback(); - }); - } - - let startTime = new Date().getTime(); - if (typeof args[args.length - 1] === 'function') { - try { - flag = await excuteCallbackPromise(); - } catch (error) { - flag = false; - } - } else { - for (;count > 0;count--) { - let error = null; - let data = null; - try { - data = await target[func](...args); - flag = flag && !!compareFunc(error, data); - } catch (err) { - error = err; - flag = flag && !!compareFunc(error, data); - } - } - } - let endTime = new Date().getTime(); - const cost = endTime - startTime; - console.log(`${caseName} ${func} result flag:${toString(flag)} count:${TEST_PERF_COUNT}` + - ` cost:${cost}ms avarage:${parseInt(cost * 1000 / TEST_PERF_COUNT)}`); - runedFunc(flag && cost < perfTime); -} -export function validate (error, data, func) { - return func(error, data); -} \ No newline at end of file diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromiseReliability.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromiseReliability.js deleted file mode 100644 index 3a65a8520..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ApiToPromiseReliability.js +++ /dev/null @@ -1,131 +0,0 @@ -/** - * 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 {toString} from './ApiToPromise.js'; -import {TEST_RELY_NUMBER} from './Const.js'; -// packaging the function to the reliability test function -export async function apiToPromiseReliability (options, args) { - // recursion plan - let {func, caseName, target, compareFunc} = options; - let flag = true; - let count = TEST_RELY_NUMBER; - - console.log(`${caseName} apiToPromiseReliability func ${func}, caseName ${caseName},args:${toString(args)}`); - function excuteCallbackPromise () { - return new Promise((resolve, reject) => { - function excuteCallback () { - target[func](...args); - } - args[args.length - 1] = function (error, data) { - if (count === 0) { - if (flag) { - resolve(flag); - } else { - reject(new Error(`flag:${flag}`)); - } - } else { - flag = flag && !!compareFunc(error, data); - count--; - excuteCallback(); - } - }; - excuteCallback(); - }); - } - - if (typeof args[args.length - 1] === 'function') { - try { - flag = await excuteCallbackPromise(); - } catch (error) { - flag = false; - } - } else { - for (;count > 0;count--) { - let error = null; - let data = null; - try { - data = await target[func](...args); - flag = flag && !!compareFunc(error, data); - } catch (err) { - error = err; - flag = flag && !!compareFunc(error, data); - } - } - } - console.log(`${caseName} result ${func} flag:${toString(flag)} count:${TEST_RELY_NUMBER}`); - if (flag) { - return flag; - } else { - throw new Error(`flag:${flag}`); - } -} - -export async function apiToReliability (options, args) { - // recursion plan - let {func, caseName, target, compareFunc, runedFunc} = options; - let flag = true; - let count = TEST_RELY_NUMBER; - - console.log(`${caseName} apiToPromiseReliability func ${func}, caseName ${caseName},args:${toString(args)}`); - function excuteCallbackPromise () { - return new Promise((resolve, reject) => { - function excuteCallback () { - target[func](...args); - } - args[args.length - 1] = function (error, data) { - console.log(`${caseName} error ${toString(error)} data ${toString(data)}`); - if (count === 0) { - if (flag) { - resolve(flag); - } else { - reject(new Error(`flag:${flag}`)); - } - } else { - flag = flag && !!compareFunc(error, data); - count--; - console.log(`${caseName} error:${toString(error)},data:${toString(data)},` + - `flag:${flag},count:${count}`); - excuteCallback(); - } - }; - excuteCallback(); - }); - } - - if (typeof args[args.length - 1] === 'function') { - try { - flag = await excuteCallbackPromise(); - } catch (error) { - flag = false; - } - } else { - for (;count > 0;count--) { - let error = null; - let data = null; - try { - data = await target[func](...args); - flag = flag && !!compareFunc(error, data); - } catch (err) { - error = err; - flag = flag && !!compareFunc(error, data); - } - console.log(`${caseName} error:${toString(error)},data:${toString(data)},flag:${flag},count:${count}`); - } - } - console.log(`${caseName} result ${func} flag:${toString(flag)} count:${TEST_RELY_NUMBER}`); - runedFunc(flag); -} - - diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/Const.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/Const.js deleted file mode 100644 index 544249a44..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/Const.js +++ /dev/null @@ -1,228 +0,0 @@ -/** - * 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. - */ - - -export const AUTO_ACCEPT_NUMBER = '10010'; -export const AUTO_ACCEPT_NUMBER2 = '10010'; -export const PHONE_NUMBER_AREA_LAND = '089800000000'; -export const PHONE_NUMBER_LENGTH_8 = '86459751'; - -export const PHONE_NUMBER_LENGTH_11 = '10000000001'; -export const PHONE_NUMBER_VOICE_MAIL = '12599'; -export const PHONE_NUMBER_LONG = '1234567890123456789012345678901234567890123' + - '4567890123456789012345678901234567890123456789012345678901'; -export const EMERGENCY_NUMBER = '112'; -export const RIGHT_PASSWORD = '000001'; -export const ERROR_PASSWORD = '1234567890123456789012345678901234567890123' + -'4567890123456789012345678901234567890123456789012345678901'; -export const CALL_EMERGENCY = 2; -export const PHONE_LIST = ['10000000001']; -export const PHONE_LIST2 = ['10000000001', '10000000002']; -export const NULL_PHONE_NUMBER = ''; -export const SPECIA_CHAR_NUMBER = '"=#$%^&*()+'; -export const PHONE_NUMBER_CHAR = 'abcdefghijk'; -export const BOUNDARY_NUMBER_INT = 2147483649; -export const MINUS_BOUNDARY_NUMBER_INT = -2147483649; -export const MINUS_VALUE = -100; -export const TEST_RELY_NUMBER = 20; // test count for Reliability -export const TEST_PERF_COUNT = 20; // test count for Perfomace -export const PERF_GOAL_TIME = TEST_PERF_COUNT * 0.5; - -export const CALL_STATUS_ACTIVE = 0; -export const CALL_STATUS_HOLDING = 1; -export const CALL_STATUS_DIALING = 2; -export const CALL_STATUS_ALERTING = 3; -export const CALL_STATUS_INCOMING = 4; -export const CALL_STATUS_WAITING = 5; -export const CALL_STATUS_DISCONNECTED = 6; -export const CALL_STATUS_DISCONNECTING = 7; -export const CALL_STATUS_IDLE = 8; - -export const TEL_CONFERENCE_IDLE = 0; -export const TEL_CONFERENCE_ACTIVE = 1; -export const TEL_CONFERENCE_DISCONNECTING = 2; -export const TEL_CONFERENCE_DISCONNECTED = 3; - -export const DEVICE_EARPIECE = 0; -export const DEVICE_SPEAKER = 1; -export const DEVICE_WIRED_HEADSET = 2; -export const DEVICE_BLUETOOTH_SCO = 3; -export const DEVICE_INVALID = -1; -export const DEVICE_INVALID4 = 4; - -export const RESTRICTION_MODE_DEACTIVATION = 0; -export const RESTRICTION_MODE_ACTIVATION = 1; -export const RESTRICTION_MODE_INVALID = -1; -export const RESTRICTION_MODE_INVALID2 = 2; - -export const RESTRICTION_DISABLE = 0; -export const RESTRICTION_ENABLE = 1; - -export const RESTRICTION_TYPE_ALL_INCOMING = 0; -export const RESTRICTION_TYPE_ALL_OUTGOING = 1; -export const RESTRICTION_TYPE_INTERNATIONAL = 2; -export const RESTRICTION_TYPE_INTERNATIONAL_EXCLUDING_HOME = 3; -export const RESTRICTION_TYPE_ROAMING_INCOMING = 4; -export const RESTRICTION_TYPE_INCOMING_SERVICES = 7; -export const RESTRICTION_TYPE_OUTGOING_SERVICES = 6; -export const RESTRICTION_TYPE_ALL_CALLS = 5; -export const RESTRICTION_TYPE_INVALID = -1; -export const RESTRICTION_TYPE_INVALID2 = 8; - -export const DEFAULT_SLOT_ID = 0; -export const SLOT_ID1 = 1; -export const SLOT_ID_INVALID = -1; -export const SLOT_ID_INVALID_2 = 2; -export const CALL_ID_NOT_EXIST = 999; -export const VIDEO_STATE_AUDIO = 0; -export const CALL_TYPE_CS = 0; -export const CALL_TYPE_IMS = 1; - -export const EVENT_START_DTMF_SUCCESS = 3; -export const EVENT_STOP_DTMF_SUCCESS = 5; - -export const CALL_STATE_UNKNOWN = -1; -export const CALL_STATE_IDLE = 0; -export const CALL_STATE_RINGING = 1; -export const CALL_STATE_OFFHOOK = 2; - -export const TIMEOUT_LENTH = 1000; - -// call error code -export const CALL_MANAGER_NUMBER_NULL_NOTICE = '83951616'; - -export const TRANSFER_DISABLE = 0; // tran is close -export const TRANSFER_ENABLE = 1; // tran is open - -export const CALL_TRANSFER_ENABLE = 0; -export const CALL_TRANSFER_DISABLE = 1; -export const CALL_TRANSFER_REGISTRATION = 3; // open tran function -export const CALL_TRANSFER_ERASURE = 4; // close tran function -export const CALL_TRANSFER_INVALID = -1; -export const CALL_TRANSFER_INVALID2 = 5; -export const CALL_TRANSFER_INVALID3 = 2; - -export const TRANSFER_TYPE_BUSY = 1; // tran busy -export const TRANSFER_TYPE_NO_REPLY = 2;// no response tran -export const TRANSFER_TYPE_NOT_REACHABLE = 3; // untouchable(no signal/shut down) tran -export const TRANSFER_TYPE_UNCONDITIONAL = 0; // unconditional tran -export const TRANSFER_TYPE_INVALID = -1; -export const TRANSFER_TYPE_INVALID4 = 4; - -export const REACH_TIMES = 10; -export const AFTER_HANUP_TIMES = 5; - -export const CARMER_ID_NOT_EXIT = 'xtsautotest123456'; -export const CARMER_ID_SPACE = ''; -export const IMAGE_PNG_PATH = '/system/data/callManager.png'; -export const IMAGE_JPG_PATH = '/system/data/callManager.jpg'; -export const IMAGE_BMP_PATH = '/system/data/callManager.bmp'; -export const IMAGE_WEBP_PATH = '/system/data/callManager.webp'; -export const IMAGE_LOCAL_ERROR_PATH = '/system/data/callManager/notexistpath.png'; -export const IMAGE_SPACE_PATH = ''; -export const SENT_STRING_0 = '0'; -export const SENT_STRING_1 = '1'; -export const SENT_STRING_2 = '2'; -export const SENT_STRING_3 = '3'; -export const SENT_STRING_4 = '4'; -export const SENT_STRING_5 = '5'; -export const SENT_STRING_6 = '6'; -export const SENT_STRING_7 = '7'; -export const SENT_STRING_8 = '8'; -export const SENT_STRING_9 = '9'; -export const SENT_STRING_ERROR_10 = '10'; -export const SENT_STRING_A = 'A'; -export const SENT_STRING_Z = 'Z'; -export const SENT_STRING_C = 'C'; -export const SENT_STRING_D = 'D'; -export const SENT_STRING_E = 'E'; -export const SENT_STRING_LOW_A = 'a'; -export const SENT_STRING_LOW_C = 'c'; -export const SENT_STRING_LOW_B = 'b'; -export const SENT_STRING_LOW_D = 'd'; -export const SENT_STRING_STAR = '*'; -export const SENT_STRING_ADD = '+'; -export const SENT_STRING_MINUS = '-'; -export const SENT_STRING_JIN = '#'; -export const CALL_MODE_CS = 0; -export const CALL_MODE_IMS = 3; -export const MEDIA_TYPE_VOICE = 0; -export const MEDIA_TYPE_VIDEO = 1; -export const MEDIA_TYPE_ERROR = -1; -export const MEDIA_TYPE_ERROR2 = 2; -export const DIAL_SCENCE_CALL_NORMAL = 0; -export const DIAL_SCENCE_CALL_PRIVILEGED = 1; -export const DIAL_SCENCE_CALL_CALL_EMERGENCY = 2; -export const DIAL_SCENCE_ERROR = -1; -export const DIAL_SCENCE_ERROR2 = 3; -export const DIAL_CARRIER_TYPE = 0; -export const DIAL_VOICE_MAIL_TYPE = 1; -export const DIAL_OTT_TYPE = 2; -export const DIAL_TYPE_ERROR = -1; -export const DIAL_TYPE_ERROR3 = 3; - -export const POS_700 = 700; -export const POS_10 = 10; -export const POS_Z_0 = 0; -export const POS_Z_1 = 1; -export const POS_Z_ERROR = -1; -export const POS_Z_ERROR2 = 2; -export const POS_LENGTH_300 = 300; -export const POS_LENGTH_600 = 600; - -export const ZOOM_RATIO_5_0 = 5.0; -export const ZOOM_RATIO_15_0 = 15.0; -export const ZOOM_RATIO_0_0 = 0.0; -export const ZOOM_RATIO_10_1 = 10.1; -export const ZOOM_RATIO_MINUS_1_0 = -1.0; - -export const ROTATION_0 = 0; -export const ROTATION_90 = 90; -export const ROTATION_60 = 60; -export const ROTATION_180 = 180; -export const ROTATION_270 = 270; -export const ROTATION_360 = 360; -export const ROTATION_MINUS_1 = -1; - -export const COMMAND_CALL_WAITTING_OPEN = '*43#'; -export const COMMAND_CALL_WAITTING_CLOSE = '#43#'; -export const COMMAND_CALL_WAITTING_QUERY = '*#43#'; -export const COMMAND_CALL_TRANS_OPEN = '*21*10000000001#'; -export const COMMAND_CALL_TRANS_OPEN2 = '**21*10000000001*10#'; -export const COMMAND_CALL_TRANS_RESET = '##21#'; -export const COMMAND_CALL_ERROR = '**21*10000000001******10#'; -export const COMMAND_CALL_ERROR2 = '*ABCDEF123456789#'; -export const COMMAND_CALL_ERROR3 = '#ABCDEF123456789#'; -export const COMMAND_CALL_ERROR4 = '*#ABCDE123456789#'; -export const COMMAND_CALL_ERROR5 = '**ABCDE123456789#'; -export const COMMAND_CALL_ERROR6 = '##ABCDEF123456789#'; - -export const CALL_WAITING_DISABLE = 0; -export const CALL_WAITING_ENABLE = 1; - -export const EVENT_SEND_USSD_SUCCESS = 17; -export const EVENT_SEND_USSD_FAILED = 18; -export const EVENT_SEND_MEDIA_MODE_UPDATE = 19; - -export const RTT_MSG = 'Ab666&#'; - -export const CALL_MODE_AUDIO_ONLY = 0; -export const CALL_MODE_SEND_RECEIVE = 3; -export const CALL_MODE_SEND_ONLY = 1; -export const CALL_MODE_RECEIVE_ONLY = 2; -export const CALL_MODE_VIDEO_PAUSED = 4; -export const CALL_MODE_INVALID_MINUS_1 = -1; -export const CALL_MODE_INVALID_5 = 5; - diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceInCalling.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceInCalling.js deleted file mode 100644 index 301d72023..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceInCalling.js +++ /dev/null @@ -1,684 +0,0 @@ -/** - * 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 { - CALL_MANAGER_NUMBER_NULL_NOTICE, - NULL_PHONE_NUMBER, - CALL_STATUS_HOLDING, - CALL_STATUS_DIALING, - CALL_STATUS_DISCONNECTED, - CALL_STATUS_DISCONNECTING, - TIMEOUT_LENTH, - DEFAULT_SLOT_ID, - CALL_STATUS_ACTIVE, - REACH_TIMES, - AFTER_HANUP_TIMES -} from './Const.js'; -import {toString} from './ApiToPromise.js'; -import call from '@ohos.telephony.call'; -import observer from '@ohos.telephony.observer'; - -let hunupTimeOut = null; - -export function clearHandupTime (caseName) { - console.log(`${caseName} clearHandupTime success`); - clearTimeout(hunupTimeOut); -} - -let stateStorage = []; -export let callId = null; -export function callDetailsChangeOn () { - console.log('Telephony_CallManager callDetailsChangeOn'); - call.on('callDetailsChange', (err, callStateInfo) => { - console.log(`Telephony_CallManager callDetailsChange error ${toString(err)}` + - `,callStateInfo ${toString(callStateInfo)}`); - if (callStateInfo) { - stateStorage.push({...callStateInfo}); - callId = callStateInfo.callId; - } - }); -} -export function callDetailsChangeOff () { - console.log('Telephony_CallManager callDetailsChangeOff'); - call.off('callDetailsChange'); -} - -let reachStateTimeout = null; -export function reachState (caseName, checkState, tag, isHunup, target) { - clearInterval(reachStateTimeout); - stateStorage = []; - let oldTime = new Date(); - let timeoutflag = false; - let timeOutLenth = 2 * REACH_TIMES * TIMEOUT_LENTH; - return new Promise((resolve, reject) => { - reachStateTimeout = setInterval(() => { - let now = new Date(); - console.log(`${caseName} ${tag} reachState now:${toString(now)},stateStorage:${toString({stateStorage})}`); - let find = stateStorage.find(ele => { - if (target && target.callId === null && ele.callState === CALL_STATUS_DIALING) { - target.callId = ele.callId; - } - if (target) { // be satisfied with multing call - return ele.callState === checkState && ele.callId === target.callId; - } else { - return ele.callState === checkState; - } - }); - if (find) { - clearInterval(reachStateTimeout); - const message = `${caseName} ${tag} reachState,get the right state checkState:${checkState}`; - console.log(message); - resolve(find); - return; - } - find = stateStorage.find(ele => { - if (target) { // be satisfied with multing call - return ele.callState === CALL_STATUS_DISCONNECTED && ele.callId === target.callId; - } else { - return ele.callState === CALL_STATUS_DISCONNECTED; - } - }); - if (find) { - clearInterval(reachStateTimeout); - reachStateTimeout = setTimeout(() => { - const message = `${caseName} ${tag} reachState,get the state CALL_STATUS_DISCONNECTED from` + - ` ${timeoutflag ? 'local' : 'opposite'}, callId ${find.callId}`; - console.log(message); - if (target) { // be satisfied with multing call - target.callId = null; - } - reject(new Error(message)); - }, AFTER_HANUP_TIMES * TIMEOUT_LENTH); - return; - } - if (new Date() - oldTime > timeOutLenth) { - if (isHunup) { - const message = `${caseName} ${tag} timeout,hunup is runed`; - console.log(message); - clearInterval(reachStateTimeout); - reject(new Error(message)); - return; - } - if (timeoutflag === false) { - timeoutflag = true; - let callId = target ? target.callId : callId;// be satisfied with multing call - if (!callId) { - clearInterval(reachStateTimeout); - const message = `${caseName} ${tag} timeout reachState,callId is not exit`; - reject(new Error(message)); - return; - } - const message = `${caseName} ${tag} timeout reachState,start hunupCall`; - console.log(message); - hangupCall(caseName, callId).then(data => { - const message = `${caseName} ${tag} timeout hangupCall success,data:${toString(data)}`; - console.log(message); - clearInterval(reachStateTimeout); - reject(new Error(message)); - }).catch(error => { - clearInterval(reachStateTimeout); - const message = `${caseName} ${tag} timeout hangupCall error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - } - } - }, 1 * TIMEOUT_LENTH); - }); -} - -export function clearReachState () { - clearInterval(reachStateTimeout); -} - -// dial call in a nomal scence,when specific state arrive,we get the information of this state -export function scenceInCalling (options) { - console.log(`scenceInCalling options ${toString(options)}`); - if (!options.target) { // be satisfied with multing call - callId = null; - } - return new Promise((resolve, reject) => { - let {caseName, phoneNumber, checkState, dialOptions, target} = options; - try { - reachState(caseName, checkState, 'scenceInCalling', false, target)// be satisfied with multing call - .then(data => { - const message = `${caseName} reach the right state success,data:${toString(data)}`; - console.log(message); - resolve(data); - }) - .catch(error => { - const message = `${caseName} reach the right state error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - const callback = (error, data) => { - if (error) { - const message = `${caseName} scenceInCalling dial error,error:${toString(error)}`; - console.log(message); - clearReachState(); - reject(new Error(message)); - return; - } - if (data !== true) { - const message = `${caseName} scenceInCalling dial data error,data:${toString(data)}`; - console.log(message); - clearReachState(); - reject(new Error(message)); - return; - } - console.log(`${caseName} dial true,run continue`); - }; - let arg = [phoneNumber]; - if (dialOptions) { - arg.push(dialOptions); - } - arg.push(callback); - call.dial(...arg); - } catch (error) { - const message = `${caseName} dial try catch error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - } - }); -} - -/* normal function - dial a call with number '',we shoudld get the error */ -export function scenceInCallingNull (options) { - console.log(`scenceInCallingNull options ${toString(options)}`); - return new Promise((resolve, reject) => { - let {caseName, dialOptions} = options; - const callback = (err, data) => { - if (err && err.message === CALL_MANAGER_NUMBER_NULL_NOTICE) { - console.log(`${caseName} dial call null number,data:${toString(err)}`); - resolve(data); - return; - } - const message = `${caseName} should be CALL_MANAGER_NUMBER_NULL_NOTICE,` + - `dial error:${toString(err)},data:${toString(data)}`; - console.log(message); - reject(new Error(message)); - }; - let arg = [NULL_PHONE_NUMBER]; - if (dialOptions) { - arg.push(dialOptions); - } - arg.push(callback); - try { - call.dial(...arg); - } catch (error) { - const message = `${caseName} error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - } - }); -} - -// holding call scence,use it should base on scenceInCalling,get the information at CALL_STATUS_HOLDING state -export function scenceInHolding (options) { - console.log(`scenceInHolding options ${toString(options)}`); - return new Promise(async (resolve, reject) => { - let {caseName, callId} = options; - if (callId) { - reachState(caseName, CALL_STATUS_HOLDING, 'scenceInHolding', false) - .then(data => { - const message = `${caseName} scenceInHolding get the right state success,data:${toString(data)}`; - console.log(message); - resolve(data); - }) - .catch(error => { - const message = `${caseName} scenceInHolding get the right state error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - call.holdCall(callId, (error, data) => { - if (error) { - const message = `${caseName} scenceInHolding holdCall error,error:${toString(error)}`; - console.log(message); - clearReachState(); - reject(new Error(message)); - } - - }); - } else { - const message = `${caseName} scenceInHolding error,need callId`; - console.log(message); - reject(new Error(message)); - } - }); -} - -export function scenceInUnHolding (options) { - console.log(`scenceInUnHolding options ${toString(options)}`); - return new Promise(async (resolve, reject) => { - let {caseName, callId} = options; - if (callId) { - reachState(caseName, CALL_STATUS_ACTIVE, 'scenceInUnHolding', false) - .then(data => { - const message = `${caseName} scenceInUnHolding get the right state success,data:${toString(data)}`; - console.log(message); - resolve(data); - }) - .catch(error => { - const message = `${caseName} scenceInUnHolding get the right state error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - call.unHoldCall(callId, (error, data) => { - if (error) { - const message = `${caseName} scenceInUnHolding error,error:${toString(error)}`; - console.log(message); - clearReachState(); - reject(new Error(message)); - } - - }); - } else { - const message = `${caseName} scenceInUnHolding error,need callId`; - console.log(message); - reject(new Error(message)); - } - }); -} - -// hunup call scence,use it should base on scenceInCalling,specific state arrive,get the information at this state -export function scenceInHangup (options) { - console.log(`scenceInHangup options ${toString(options)}`); - return new Promise(async (resolve, reject) => { - let {caseName, callId, checkState} = options; - if (callId) { - reachState(caseName, checkState, 'scenceInHangup', true).then(data => { - const message = `${caseName} scenceInHangup get the right state success ,data:${toString(data)}`; - console.log(message); - resolve(data); - }).catch(error => { - const message = `${caseName} scenceInHangup get the right state error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - call.hangup(callId) - .then((data) => { - const message = `${caseName} scenceInHangup data,data:${toString(data)}`; - console.log(message); - }) - .catch(error => { - const message = `${caseName} func hangup,error:${toString(error)}`; - console.log(message); - clearReachState(); - reject(new Error(message)); - }); - - } else { - const message = `${caseName} scenceInHangup error,need callId`; - console.log(message); - reject(new Error(message)); - } - }); -} - -// hunup the call ,used in test case -export function hangupCall2 (caseName, done, callId, delaytime) { - let timeout = null; - if (callId) { - const message = `${caseName} hunup,hangupCall2 callId ${callId}`; - console.log(message); - reachState(caseName, CALL_STATUS_DISCONNECTED, 'hangupCall2', true) - .then(data => { - const message = `${caseName} hangupCall2 get right state success,data:${toString(data)}`; - console.log(message); - clearTimeout(timeout); - timeout = setTimeout(function () { - done(); - }, AFTER_HANUP_TIMES * TIMEOUT_LENTH); - }) - .catch(error => { - const message = `${caseName} hangupCall2 get right state error,error:${toString(error)}`; - console.log(message); - }); - call.hangup(callId) - .then((data) => { - console.log(`${caseName} func hangup success,${toString(data)}`); - }) - .catch(error => { - const message = `${caseName} func hangup,error:${toString(error)}`; - console.log(message); - clearReachState(); - done(); - }); - - } else { - const message = `${caseName} hangupCall2 error,need callId`; - console.log(message); - done(); - } -} - -// hunup the call ,used in packaging function -export function hangupCall (caseName, callId) { - return new Promise((resolve, reject) => { - let timeout = null; - if (callId) { - let message = `${caseName} hunup,hangupCall callId:${callId}`; - console.log(message); - reachState(caseName, CALL_STATUS_DISCONNECTED, 'hangupCall', true) - .then(data => { - const message = `${caseName} hangupCall get right state success,data:${toString(data)}`; - console.log(message); - clearTimeout(timeout); - timeout = setTimeout(function () { - resolve(data); - }, AFTER_HANUP_TIMES * TIMEOUT_LENTH); - }) - .catch(error => { - const message = `${caseName} hangupCall get right state error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - call.hangup(callId) - .then((data) => { - console.log(`${caseName} func hangup success,${toString(data)}`); - }) - .catch(error => { - const message = `${caseName} func hangup,error:${toString(error)}`; - console.log(message); - clearReachState(); - reject(new Error(message)); - }); - } else { - const message = `${caseName} func hangup error,need callId`; - console.log(message); - reject(new Error(message)); - } - - }); -} - -/* dial call in a nomal scence used in third-party applications,when specific state arrive, - we get the information of this state */ -export function scenceInCallingForRegister (options) { - console.log(`scenceInCallingForRegister options ${toString(options)}`); - return new Promise((resolve, reject) => { - let {caseName} = options; - let callId = null; - let callChangeData = null; - let func = null; - let count = 0; - if (options.isOnce) { - func = observer.once; - } else { - func = observer.on; - } - if (typeof func !== 'function') { - let message = `${caseName} observer.once or observer.on is not exit,options:${toString(options)}`; - console.log(message); - reject(new Error(message)); - return; - } - func('callStateChange', {slotId: DEFAULT_SLOT_ID}, (data) => { - console.log(`${caseName} callStateChange,data:${toString(data)}`); - callChangeData = data; - count++; - }); - - scenceInCalling({...options}) - .then(data => { - callId = data.callId; - let tempCallChangeData = {count, ...callChangeData}; - console.log(`${caseName} scenceInCalling data,data:${toString(data)},` + - `tempCallChangeData:${toString(tempCallChangeData)}`); - observer.off('callStateChange'); - hangupCall(caseName, callId) - .then(data => { - console.log(`${caseName} scenceInCalling hangupCall data,data:${toString(data)}`); - resolve(tempCallChangeData); - }) - .catch(error => { - const message = `${caseName} scenceInCalling hangupCall error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} scenceInCalling error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }); -} - -// holding call scence used in third-party applications,we get the information of state at CALL_STATUS_HOLDING state -export function scenceInCallingHoldingForRegister (options) { - console.log(`scenceInCallingHoldingForRegister options ${toString(options)}`); - return new Promise((resolve, reject) => { - let {caseName} = options; - let callId = null; - let callChangeData = null; - let func = null; - let count = 0; - if (options.isOnce) { - func = observer.once; - } else { - func = observer.on; - } - if (typeof func !== 'function') { - reject(new Error(`${caseName} observer.once or observer.on is not exit,options:${toString(options)}`)); - return; - } - func('callStateChange', {slotId: DEFAULT_SLOT_ID}, (data) => { - console.log(`${caseName} callStateChange,data:${toString(data)}`); - count++; - callChangeData = data; - }); - scenceInCalling(options) - .then(data => { - scenceInHolding({callId:data.callId, ...options}) - .then(data => { - callId = data.callId; - let tempCallChangeData = {count, ...callChangeData}; - console.log(`${caseName} scenceInHolding data,data:${toString(data)}` + - `,tempCallChangeData:${toString(tempCallChangeData)}`); - observer.off('callStateChange'); - hangupCall(caseName, callId) - .then(data => { - console.log(`${caseName} hangupCall data,data:${toString(data)}`); - resolve(tempCallChangeData); - }) - .catch(error => { - const message = `${caseName} hangupCall error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} scenceInHolding ,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} scenceInCalling error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }); -} - -// holding call scence used in third-party applications,we get the information of state when unHoldCall the call -export function scenceInCallingNnHoldingForRegister (options) { - console.log(`scenceInCallingNnHoldingForRegister options ${toString(options)}`); - return new Promise((resolve, reject) => { - let {caseName} = options; - let callId = null; - let callChangeData = null; - let func = null; - let count = 0; - if (options.isOnce) { - func = observer.once; - } else { - func = observer.on; - } - if (typeof func !== 'function') { - reject(new Error(`${caseName} observer.once or observer.on is not exit,options:${toString(options)}`)); - return; - } - func('callStateChange', {slotId:DEFAULT_SLOT_ID}, (data) => { - console.log(`${caseName} callStateChange,data:${toString(data)}`); - count++; - callChangeData = data; - }); - scenceInCalling(options) - .then(data => { - scenceInHolding({callId:data.callId, ...options}) - .then(data => { - callId = data.callId; - scenceInUnHolding({callId:data.callId, ...options}) - .then(data => { - let tempCallChangeData = {count, ...callChangeData}; - console.log(`${caseName} unHoldCall data,data:${toString(data)}, - tempCallChangeData:${toString(tempCallChangeData)}`); - observer.off('callStateChange'); - hangupCall(caseName, callId) - .then(data => { - console.log(`${caseName} hangupCall data,data:${toString(data)}`); - resolve(tempCallChangeData); - }) - .catch(error => { - const message = `${caseName} hangupCall error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} unHoldCall error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} scenceInHolding error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} scenceInCalling error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }); -} - -// hunup call scence used in third-party applications,we get the information of state when hunup the call -export function scenceInCallingHangupForRegister (options) { - console.log(`scenceInCallingHangupForRegister options ${toString(options)}`); - return new Promise((resolve, reject) => { - let {caseName} = options; - let callId = null; - let callChangeData = null; - let func = null; - let count = 0; - if (options.isOnce) { - func = observer.once; - } else { - func = observer.on; - } - if (typeof func !== 'function') { - reject(new Error(`${caseName} observer.once or observer.on is not exit,options:${toString(options)}`)); - return; - } - func('callStateChange', {slotId: DEFAULT_SLOT_ID}, (data) => { - console.log(`${caseName} callStateChange,data:${toString(data)}`); - count++; - callChangeData = data; - }); - scenceInCalling(options) - .then(data => { - options.checkState = CALL_STATUS_DISCONNECTED; - scenceInHangup({callId:data.callId, ...options}) - .then(data => { - callId = data.callId; - let tempCallChangeData = {count, ...callChangeData}; - console.log(`${caseName} scenceInHangup data,data:${toString(data)},` + - `tempCallChangeData:${toString(tempCallChangeData)}`); - observer.off('callStateChange'); - resolve(tempCallChangeData); - }) - .catch(error => { - const message = `${caseName} scenceInHangup error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }) - .catch(error => { - const message = `${caseName} scenceInCalling error,error:${toString(error)}`; - console.log(message); - reject(new Error(message)); - }); - }); -} - -export function isHanupEd (state) { - return (state === CALL_STATUS_DISCONNECTING) || (state === CALL_STATUS_DISCONNECTED); -} - -export function reachCallEventState (eventId) { - return new Promise(function (resolve, reject) { - let time = null; - call.on('callEventChange', (err, value) => { - console.log(`Telephony_CallManager callEventChange error ${toString(err)},callStateInfo ${ - toString(value)}`); - if (err) { - let message = `Telephony_CallManager reachCallEventState err message = ${toString(err)}`; - console.log(message); - clearTimeout(time); - reject(new Error(message)); - return; - } - if (eventId === value.eventId) { - let message = `Telephony_CallManager reachCallEventState get the right eventId ${toString(value)}`; - console.log(message); - clearTimeout(time); - resolve(value); - } else { - let message = `Telephony_CallManager reachCallEventState get the error eventId ${toString(value)}`; - console.log(message); - clearTimeout(time); - reject(new Error(message)); - } - }); - time = setTimeout(function () { - let message = 'Telephony_CallManager reachCallEventState time out'; - console.log(message); - reject(new Error(message)); - }, 20 * TIMEOUT_LENTH); - }); -} - -export class TeleCall { - constructor () { - this.callId = null; - } - callScenceInCalling (options) { - this.callId = null; - options.target = this; - return scenceInCalling(options); - } - callReachState (caseName, checkState, tag, isHunup) { - return reachState(caseName, checkState, tag, isHunup, this); - } - callHangupCall (caseName) { - return hangupCall(caseName, this.callId, this); - } -} \ No newline at end of file diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceLimitCalling.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceLimitCalling.js deleted file mode 100644 index d1fe283b1..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceLimitCalling.js +++ /dev/null @@ -1,57 +0,0 @@ -/** - * 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 {RIGHT_PASSWORD, DEFAULT_SLOT_ID, RESTRICTION_MODE_DEACTIVATION} from './Const.js'; -import {toString} from './ApiToPromise.js'; -import call from '@ohos.telephony.call'; - -// limit call scence -export function scenceLimitCalling (caseName, type, mode, slotId) { - return new Promise((resolve, reject) => { - console.log(`${caseName} scenceLimitCalling type:${type},mode:${mode}`); - call.setCallRestriction(slotId ? slotId : DEFAULT_SLOT_ID, { - type, - mode, - password:RIGHT_PASSWORD, - }) - .then(data => { - console.log(`${caseName} setCallRestriction success, data:${toString(data)}`); - resolve(data); - }) - .catch((error) => { - console.log(`${caseName} setCallRestriction error,error:${toString(error)}`); - reject(error); - }); - }); -} - -export function scenceLimitCancel (caseName, type, slotId) { - return new Promise((resolve, reject) => { - console.log(`${caseName} scenceLimitCancel type:${type}`); - call.setCallRestriction(slotId ? slotId : DEFAULT_SLOT_ID, { - type, - mode:RESTRICTION_MODE_DEACTIVATION, - password:RIGHT_PASSWORD, - }) - .then(data => { - console.log(`${caseName} scenceLimitCancel success, data:${toString(data)}`); - resolve(data); - }) - .catch((error) => { - console.log(`${caseName} scenceLimitCancel error,error:${toString(error)}`); - reject(error); - }); - }); -} diff --git a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceTransfer.js b/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceTransfer.js deleted file mode 100644 index e07d2220e..000000000 --- a/telephony/telephonyjstest/call_manager/call_manager_ims2_call/src/main/js/test/lib/ScenceTransfer.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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 call from '@ohos.telephony.call'; -import {toString} from './ApiToPromise.js'; -export function scenceTransferCalling (caseName, settingType, type, phoneNumber) { - return new Promise((resolve, reject) => { - call.setCallTransfer(0, { - settingType, - type, - phoneNumber, - }) - .then(data => { - console.log(`${caseName} scenceTransferCalling success,data:${toString(data)}`); - resolve(data); - }) - .catch((error) => { - console.log(`${caseName} scenceTransferCalling error,error:${toString(error)}`); - reject(error); - }); - }); -} - -export function scenceTransferCancel (caseName) { - return new Promise((resolve, reject) => { - call.dial('##002#') - .then(data => { - console.log(`${caseName} scenceTransferCancel success,data:${toString(data)}`); - resolve(data); - }) - .catch((error) => { - console.log(`${caseName} scenceTransferCancel error,error${toString(error)}`); - reject(error); - }); - }); -} - -- GitLab