未验证 提交 98e80453 编写于 作者: O openharmony_ci 提交者: Gitee

!5442 【Distributeddatamgr】【master】覆盖率补齐;用例优化

Merge pull request !5442 from 梁梁/master
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
import pasteBoardJEtsunitTest from './PasteBoardEtsunitTest'; import pasteBoardJEtsunitTest from './PasteBoardEtsunitTest';
import pasteBoardTest from './PasteBoeadPixelMapJsunit.test'; import pasteBoardTest from './PasteBoeadPixelMapJsunit.test';
import pasteBoardSupportBinaryDataTest from './PasteBoardSupportBinaryData.test';
export default function testsuite() { export default function testsuite() {
pasteBoardSupportBinaryDataTest()
pasteBoardJEtsunitTest() pasteBoardJEtsunitTest()
pasteBoardTest() pasteBoardTest()
} }
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import pasteboard from '@ohos.pasteboard'
export default function pasteBoardSupportBinaryDataTest(){
describe('pasteBoardSupportBinaryDataTest', function() {
console.info('start################################start');
/**
* @tc.number SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0100
* @tc.name Create pasteData use binary parameter
* @tc.desc Test pasteBoard API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0100', 0, async function (done) {
console.info("SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0100 start")
var systemPasteBoard = pasteboard.getSystemPasteboard();
await systemPasteBoard.clear().then(async () => {
var pasteData = undefined;
console.info("systemPasteBoard clear data success")
var dataUri = new ArrayBuffer(256)
pasteData = pasteboard.createData("text/uri",dataUri)
var addUri = new ArrayBuffer(128)
pasteData.addRecord("text/uri", addUri)
var recordUri = new ArrayBuffer(96)
var pasteDataRecord = pasteboard.createRecord("text/uri", recordUri)
pasteData.addRecord(pasteDataRecord)
await systemPasteBoard.setPasteData(pasteData).then(async () => {
console.info("Set pastedata success")
await systemPasteBoard.hasPasteData().then(async (data) => {
console.info("Check pastedata has data success, result: " + data)
expect(data).assertTrue();
await systemPasteBoard.getPasteData().then(async (data) => {
console.info("Get paste data success")
expect(data.getRecordCount()).assertEqual(3)
})
})
})
})
done();
})
/**
* @tc.number SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0200
* @tc.name Create pasteData use binary parameter
* @tc.desc Test pasteBoard API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0200', 0, async function (done) {
console.info("SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0200 start")
var systemPasteBoard = pasteboard.getSystemPasteboard();
await systemPasteBoard.clear().then(async () => {
var pasteData = undefined;
console.info("systemPasteBoard clear data success")
var dataHtml = new ArrayBuffer(256)
pasteData = pasteboard.createData("text/html",dataHtml)
var addHtml = new ArrayBuffer(128)
pasteData.addRecord("text/html", addHtml)
var recordHtml = new ArrayBuffer(64)
var pasteDataRecord = pasteboard.createRecord("text/html", recordHtml)
pasteData.addRecord(pasteDataRecord)
await systemPasteBoard.setPasteData(pasteData).then(async () => {
console.info("set pastedata success")
await systemPasteBoard.hasPasteData().then(async (data) => {
console.info("Check pastedata has data success, result: " + data)
expect(data).assertTrue();
await systemPasteBoard.getPasteData().then(async (data) => {
console.info("get paste data success")
expect(data.getRecordCount()).assertEqual(3)
})
})
})
})
done();
})
/**
* @tc.number SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0300
* @tc.name Create pasteData use binary parameter
* @tc.desc Test pasteBoard API functionality.
* @tc.size : MEDIUM
* @tc.type : Function
* @tc.level : Level 2
*/
it('SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0300', 0, async function (done) {
console.info("SUB_PASTEBOARD_BINARY_FUNCTION_ETS_TEST_0300 start")
var systemPasteBoard = pasteboard.getSystemPasteboard();
await systemPasteBoard.clear().then(async () => {
console.info("systemPasteBoard clear data success")
var pasteData = undefined
var pasteRecord = undefined;
var dataHtml = new ArrayBuffer(256)
pasteData = pasteboard.createData("x".repeat(1025),dataHtml)
expect(pasteData).assertEqual(undefined)
pasteData = pasteboard.createData("x".repeat(1024),dataHtml)
expect(pasteData != undefined).assertTrue();
var addHtml = new ArrayBuffer(128)
pasteData.addRecord("x".repeat(1025),dataHtml)
expect(pasteData.getRecordCount()).assertEqual(1)
pasteData.addRecord("x".repeat(1024),dataHtml)
expect(pasteData.getRecordCount()).assertEqual(2)
var recordHtml = new ArrayBuffer(64)
pasteRecord = pasteboard.createRecord("x".repeat(1025),dataHtml)
expect(pasteRecord).assertEqual(undefined);
pasteRecord = pasteboard.createRecord("x".repeat(1024),dataHtml)
expect(pasteRecord != undefined).assertTrue();;
pasteData.addRecord(pasteRecord)
await systemPasteBoard.setPasteData(pasteData).then(async () => {
console.info("set pastedata success")
await systemPasteBoard.hasPasteData().then(async (data) => {
console.info("Check pastedata has data success, result: " + data)
expect(data).assertTrue();
await systemPasteBoard.getPasteData().then(async (data) => {
console.info("get paste data success")
expect(data.getRecordCount()).assertEqual(3)
})
})
})
})
done();
})
console.info('end################################end');
});
}
...@@ -29,443 +29,426 @@ var mPreferences; ...@@ -29,443 +29,426 @@ var mPreferences;
var context; var context;
export default function preferencesPromiseTest(){ export default function preferencesPromiseTest(){
describe('preferencesPromiseTest', function () { describe('preferencesPromiseTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info('beforeAll') console.info('beforeAll')
context = featureAbility.getContext() context = featureAbility.getContext()
mPreferences = await dataPreferences.getPreferences(context, NAME); mPreferences = await dataPreferences.getPreferences(context, NAME);
})
afterAll(async function () {
console.info('afterAll')
await dataPreferences.deletePreferences(context, NAME);
})
/**
* @tc.name put StringArray promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0010
* @tc.desc put StringArray promise interface test
*/
it('testPreferencesPutStringArray0131', 0, async function (done) {
await mPreferences.clear();
var stringArr = ['1', '2', '3']
let promise1 = mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr)
await promise1
let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ['123', '321'])
promise2.then((pre) => {
for (let i = 0; i < stringArr.length; i++) {
expect(stringArr[i]).assertEqual(pre[i]);
}
}).catch((err) => {
expect(null).assertFail();
}) })
await promise2
done();
});
/**
* @tc.name put NumberArray promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0020
* @tc.desc put NumberArray promise interface test
*/
it('testPreferencesPutNumberArray0132', 0, async function (done) {
await mPreferences.clear();
var numberArr = [11, 22, 33, 44, 55]
let promise1 = mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr)
await promise1
let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321])
promise2.then((pre) => {
for (let i = 0; i < numberArr.length; i++) {
expect(numberArr[i]).assertEqual(pre[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise2
done();
});
/**
* @tc.name put BoolArray promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0030
* @tc.desc put BoolArray promise interface test
*/
it('testPreferencesPutBoolArray0133', 0, async function (done) {
await mPreferences.clear();
var boolArr = [true, true, false]
let promise1 = mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr)
await promise1
let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true])
promise2.then((pre) => {
for (let i = 0; i < boolArr.length; i++) {
expect(boolArr[i]).assertEqual(pre[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise2
done();
});
/**
* @tc.name getAll promise interface test
* @tc.number SUB_DDM_Preferences_GetAll_Promise_0040
* @tc.desc getAll promise interface test
*/
it('testPreferencesGetAll0001', 0, async function (done) {
await mPreferences.clear();
let doubleArr = [11, 22, 33]
let stringArr = ['11', '22', '33']
let boolArr = [true, false, false, true]
await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr)
await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr)
await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr)
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false)
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123")
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1)
await mPreferences.flush()
let promise = mPreferences.getAll()
promise.then((obj) => {
expect(false).assertEqual(obj.key_test_boolean)
expect("123").assertEqual(obj.key_test_string)
expect(123.1).assertEqual(obj.key_test_float)
let sArr = obj.key_test_string_array
for (let i = 0; i < sArr.length; i++) {
expect(sArr[i]).assertEqual(stringArr[i]);
}
let bArr = obj.key_test_bool_array
for (let i = 0; i < bArr.length; i++) {
expect(bArr[i]).assertEqual(boolArr[i]);
}
let nArr = obj.key_test_number_array
for (let i = 0; i < nArr.length; i++) {
expect(nArr[i]).assertEqual(doubleArr[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise
done(); afterAll(async function () {
}) console.info('afterAll')
await dataPreferences.deletePreferences(context, NAME);
})
/** /**
* @tc.name clear promise interface test * @tc.name put StringArray promise interface test
* @tc.number SUB_DDM_Preferences_Clear_Promise_0050 * @tc.number SUB_DDM_Preferences_Put_Promise_0010
* @tc.desc clear promise interface test * @tc.desc put StringArray promise interface test
*/ */
it('testPreferencesClear0011', 0, async function (done) { it('testPreferencesPutStringArray0131', 0, async function (done) {
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); await mPreferences.clear();
await mPreferences.flush(); var stringArr = ['1', '2', '3']
const promise = mPreferences.clear(); let promise1 = mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr)
promise.then(async (ret) => { await promise1
let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ['123', '321'])
expect("defaultvalue").assertEqual(per); promise2.then((pre) => {
}).catch((err) => { for (let i = 0; i < stringArr.length; i++) {
expect(null).assertFail(); expect(stringArr[i]).assertEqual(pre[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise2
done();
}); });
await promise;
done();
})
/** /**
* @tc.name has string interface test * @tc.name put NumberArray promise interface test
* @tc.number SUB_DDM_Preferences_Has_Promise_0060 * @tc.number SUB_DDM_Preferences_Put_Promise_0020
* @tc.desc has string interface test * @tc.desc put NumberArray promise interface test
*/ */
it('testPreferencesHasKey0031', 0, async function (done) { it('testPreferencesPutNumberArray0132', 0, async function (done) {
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); await mPreferences.clear();
const promise = mPreferences.has(KEY_TEST_STRING_ELEMENT); var numberArr = [11, 22, 33, 44, 55]
promise.then((ret) => { let promise1 = mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr)
expect(true).assertEqual(ret); await promise1
}).catch((err) => { let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321])
expect(null).assertFail(); promise2.then((pre) => {
for (let i = 0; i < numberArr.length; i++) {
expect(numberArr[i]).assertEqual(pre[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise2
done();
}); });
await promise;
done();
})
/** /**
* @tc.name has int interface test * @tc.name put BoolArray promise interface test
* @tc.number SUB_DDM_Preferences_Has_Promise_0070 * @tc.number SUB_DDM_Preferences_Put_Promise_0030
* @tc.desc has int interface test * @tc.desc put BoolArray promise interface test
*/ */
it('testPreferencesHasKey0032', 0, async function (done) { it('testPreferencesPutBoolArray0133', 0, async function (done) {
await mPreferences.put(KEY_TEST_INT_ELEMENT, 1); await mPreferences.clear();
const promise = mPreferences.has(KEY_TEST_INT_ELEMENT); var boolArr = [true, true, false]
promise.then((ret) => { let promise1 = mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr)
expect(true).assertEqual(ret); await promise1
}).catch((err) => { let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true])
expect(null).assertFail(); promise2.then((pre) => {
for (let i = 0; i < boolArr.length; i++) {
expect(boolArr[i]).assertEqual(pre[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise2
done();
}); });
await promise;
done();
})
/** /**
* @tc.name has float interface test * @tc.name getAll promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0080 * @tc.number SUB_DDM_Preferences_GetAll_Promise_0040
* @tc.desc has float interface test * @tc.desc getAll promise interface test
*/ */
it('testPreferencesHasKey0033', 0, async function (done) { it('testPreferencesGetAll0001', 0, async function (done) {
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 2.0); await mPreferences.clear();
const promise = mPreferences.has(KEY_TEST_FLOAT_ELEMENT); let doubleArr = [11, 22, 33]
promise.then((ret) => { let stringArr = ['11', '22', '33']
expect(true).assertEqual(ret); let boolArr = [true, false, false, true]
}).catch((err) => { await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr)
expect(null).assertFail(); await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr)
}); await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr)
await promise; await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false)
done(); await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123")
}) await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1)
await mPreferences.flush()
let promise = mPreferences.getAll()
promise.then((obj) => {
expect(false).assertEqual(obj.key_test_boolean)
expect("123").assertEqual(obj.key_test_string)
expect(123.1).assertEqual(obj.key_test_float)
let sArr = obj.key_test_string_array
for (let i = 0; i < sArr.length; i++) {
expect(sArr[i]).assertEqual(stringArr[i]);
}
let bArr = obj.key_test_bool_array
for (let i = 0; i < bArr.length; i++) {
expect(bArr[i]).assertEqual(boolArr[i]);
}
let nArr = obj.key_test_number_array
for (let i = 0; i < nArr.length; i++) {
expect(nArr[i]).assertEqual(doubleArr[i]);
}
}).catch((err) => {
expect(null).assertFail();
})
await promise
done();
})
/** /**
* @tc.name has boolean interface test * @tc.name clear promise interface test
* @tc.number SUB_DDM_Preferences_Has_Promise_0090 * @tc.number SUB_DDM_Preferences_Clear_Promise_0050
* @tc.desc has boolean interface test * @tc.desc clear promise interface test
*/ */
it('testPreferencesHasKey0034', 0, async function (done) { it('testPreferencesClear0011', 0, async function (done) {
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
const promise = mPreferences.has(KEY_TEST_BOOLEAN_ELEMENT); await mPreferences.flush();
promise.then((ret) => { const promise = mPreferences.clear();
expect(true).assertEqual(ret); promise.then(async (ret) => {
}).catch((err) => { let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue");
expect(null).assertFail(); expect("defaultvalue").assertEqual(per);
}); }).catch((err) => {
await promise; expect(null).assertFail();
done(); });
}) await promise;
done();
})
/** /**
* @tc.name has long interface test * @tc.name has string interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0100 * @tc.number SUB_DDM_Preferences_Has_Promise_0060
* @tc.desc has long interface test * @tc.desc has string interface test
*/ */
it('testPreferencesHasKey0035', 0, async function (done) { it('testPreferencesHasKey0031', 0, async function (done) {
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0); await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
const promise = mPreferences.has(KEY_TEST_LONG_ELEMENT); const promise = mPreferences.has(KEY_TEST_STRING_ELEMENT);
promise.then((ret) => { promise.then((ret) => {
expect(true).assertEqual(ret); expect(true).assertEqual(ret);
}).catch((err) => { }).catch((err) => {
expect(null).assertFail(); expect(null).assertFail();
}); });
await promise; await promise;
done(); done();
}) })
/** /**
* @tc.name get string promise interface test * @tc.name has int interface test
* @tc.number SUB_DDM_Preferences_Get_Promise_0110 * @tc.number SUB_DDM_Preferences_Has_Promise_0070
* @tc.desc get string promise interface test * @tc.desc has int interface test
*/ */
it('testPreferencesGetDefValue0061', 0, async function (done) { it('testPreferencesHasKey0032', 0, async function (done) {
await mPreferences.clear(); await mPreferences.put(KEY_TEST_INT_ELEMENT, 1);
const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultValue"); const promise = mPreferences.has(KEY_TEST_INT_ELEMENT);
promise.then((ret) => { promise.then((ret) => {
expect('defaultValue').assertEqual(ret); expect(true).assertEqual(ret);
}).catch((err) => { }).catch((err) => {
expect(null).assertFail(); expect(null).assertFail();
}); });
await promise; await promise;
done(); done();
}) })
/** /**
* @tc.name get float promise interface test * @tc.name has float interface test
* @tc.number SUB_DDM_Preferences_Get_Promise_0120 * @tc.number SUB_DDM_Preferences_Put_Promise_0080
* @tc.desc get float promise interface test * @tc.desc has float interface test
*/ */
it('testPreferencesGetFloat0071', 0, async function (done) { it('testPreferencesHasKey0033', 0, async function (done) {
await mPreferences.clear(); await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 2.0);
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); const promise = mPreferences.has(KEY_TEST_FLOAT_ELEMENT);
const promise = mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); promise.then((ret) => {
promise.then((ret) => { expect(true).assertEqual(ret);
expect(3.0).assertEqual(ret); }).catch((err) => {
}).catch((err) => { expect(null).assertFail();
expect(null).assertFail(); });
}); await promise;
await promise; done();
done(); })
})
/** /**
* @tc.name get int promise interface test * @tc.name has boolean interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0130 * @tc.number SUB_DDM_Preferences_Has_Promise_0090
* @tc.desc get int promise interface test * @tc.desc has boolean interface test
*/ */
it('testPreferencesGetInt0081', 0, async function (done) { it('testPreferencesHasKey0034', 0, async function (done) {
await mPreferences.clear(); await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false);
await mPreferences.put(KEY_TEST_INT_ELEMENT, 3); const promise = mPreferences.has(KEY_TEST_BOOLEAN_ELEMENT);
const promise = mPreferences.get(KEY_TEST_INT_ELEMENT, 0.0); promise.then((ret) => {
promise.then((ret) => { expect(true).assertEqual(ret);
expect(3).assertEqual(ret); }).catch((err) => {
}).catch((err) => { expect(null).assertFail();
expect(null).assertFail(); });
}); await promise;
await promise; done();
done(); })
})
/** /**
* @tc.name get long promise interface test * @tc.name has long interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0140 * @tc.number SUB_DDM_Preferences_Put_Promise_0100
* @tc.desc get long promise interface test * @tc.desc has long interface test
*/ */
it('testPreferencesGetLong0091', 0, async function (done) { it('testPreferencesHasKey0035', 0, async function (done) {
await mPreferences.clear(); await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0);
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 3); const promise = mPreferences.has(KEY_TEST_LONG_ELEMENT);
const promise = mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); promise.then((ret) => {
promise.then((ret) => { expect(true).assertEqual(ret);
expect(3).assertEqual(ret); }).catch((err) => {
}).catch((err) => { expect(null).assertFail();
expect(null).assertFail(); });
}); await promise;
await promise; done();
done(); })
})
/** /**
* @tc.name get String promise interface test * @tc.name get string promise interface test
* @tc.number SUB_DDM_Preferences_Get_Promise_0150 * @tc.number SUB_DDM_Preferences_Get_Promise_0110
* @tc.desc get String promise interface test * @tc.desc get string promise interface test
*/ */
it('tesPreferencesGetString101', 0, async function (done) { it('testPreferencesGetDefValue0061', 0, async function (done) {
await mPreferences.clear(); await mPreferences.clear();
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultValue");
await mPreferences.flush(); promise.then((ret) => {
const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); expect('defaultValue').assertEqual(ret);
promise.then((ret) => { }).catch((err) => {
expect('test').assertEqual(ret); expect(null).assertFail();
}).catch((err) => { });
expect(null).assertFail(); await promise;
}); done();
await promise; })
done();
}) /**
* @tc.name get float promise interface test
* @tc.number SUB_DDM_Preferences_Get_Promise_0120
* @tc.desc get float promise interface test
*/
it('testPreferencesGetFloat0071', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0);
const promise = mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
promise.then((ret) => {
expect(3.0).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name get int promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0130
* @tc.desc get int promise interface test
*/
it('testPreferencesGetInt0081', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_INT_ELEMENT, 3);
const promise = mPreferences.get(KEY_TEST_INT_ELEMENT, 0.0);
promise.then((ret) => {
expect(3).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name get long promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0140
* @tc.desc get long promise interface test
*/
it('testPreferencesGetLong0091', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 3);
const promise = mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
promise.then((ret) => {
expect(3).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name get String promise interface test
* @tc.number SUB_DDM_Preferences_Get_Promise_0150
* @tc.desc get String promise interface test
*/
it('tesPreferencesGetString101', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
await mPreferences.flush();
const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue");
promise.then((ret) => {
expect('test').assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/** /**
* @tc.name put boolean promise interface test * @tc.name put boolean promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0160 * @tc.number SUB_DDM_Preferences_Put_Promise_0160
* @tc.desc put boolean promise interface test * @tc.desc put boolean promise interface test
*/ */
it('testPreferencesPutBoolean0121', 0, async function (done) { it('testPreferencesPutBoolean0121', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true); await mPreferences.clear();
promise.then(async (ret) => { let promise = mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true);
await promise;
let per = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); let per = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false);
expect(true).assertEqual(per); expect(true).assertEqual(per);
await mPreferences.flush(); await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); let per2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false);
expect(true).assertEqual(per2); expect(true).assertEqual(per2);
}).catch((err) => { done();
expect(null).assertFail(); })
});
await promise;
done();
})
/** /**
* @tc.name put float promise interface test * @tc.name put float promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0170 * @tc.number SUB_DDM_Preferences_Put_Promise_0170
* @tc.desc put float promise interface test * @tc.desc put float promise interface test
*/ */
it('testPreferencesPutFloat0131', 0, async function (done) { it('testPreferencesPutFloat0131', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0); await mPreferences.clear();
promise.then(async (ret) => { const promise = mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0);
await promise;
let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
expect(4.0).assertEqual(per); expect(4.0).assertEqual(per);
await mPreferences.flush(); await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); let per2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
expect(4.0).assertEqual(per2); expect(4.0).assertEqual(per2);
}).catch((err) => { done();
expect(null).assertFail(); })
});
await promise;
done();
})
/** /**
* @tc.name put int promise interface test * @tc.name put int promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0180 * @tc.number SUB_DDM_Preferences_Put_Promise_0180
* @tc.desc put int promise interface test * @tc.desc put int promise interface test
*/ */
it('testPreferencesPutInt0141', 0, async function (done) { it('testPreferencesPutInt0141', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_INT_ELEMENT, 4); await mPreferences.clear();
promise.then(async (ret) => { let promise = mPreferences.put(KEY_TEST_INT_ELEMENT, 4);
await promise;
let per = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); let per = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0);
expect(4).assertEqual(per); expect(4).assertEqual(per);
await mPreferences.flush(); await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); let per2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0);
expect(4).assertEqual(per2); expect(4).assertEqual(per2);
}).catch((err) => { done();
expect(null).assertFail(); })
});
await promise;
done();
})
/** /**
* @tc.name put long promise interface test * @tc.name put long promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0190 * @tc.number SUB_DDM_Preferences_Put_Promise_0190
* @tc.desc put long promise interface test * @tc.desc put long promise interface test
*/ */
it('testPreferencesPutLong0151', 0, async function (done) { it('testPreferencesPutLong0151', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_LONG_ELEMENT, 4); let promise = mPreferences.put(KEY_TEST_LONG_ELEMENT, 4);
promise.then(async (ret) => { await promise;
let per = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); let per = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
expect(4).assertEqual(per); expect(4).assertEqual(per);
await mPreferences.flush(); await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); let per2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
expect(4).assertEqual(per2); expect(4).assertEqual(per2);
}).catch((err) => { done();
expect(null).assertFail(); })
});
await promise;
done();
})
/** /**
* @tc.name put String promise interface test * @tc.name put String promise interface test
* @tc.number SUB_DDM_Preferences_Put_Promise_0200 * @tc.number SUB_DDM_Preferences_Put_Promise_0200
* @tc.desc put String promise interface test * @tc.desc put String promise interface test
*/ */
it('testPreferencesPutString0161', 0, async function (done) { it('testPreferencesPutString0161', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_STRING_ELEMENT, ''); let promise = mPreferences.put(KEY_TEST_STRING_ELEMENT, '');
promise.then(async (ret) => { await promise;
let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue") let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect('').assertEqual(per); expect('').assertEqual(per);
await mPreferences.flush(); await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue") let per2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect('').assertEqual(per2); expect('').assertEqual(per2);
}).catch((err) => { done();
expect(null).assertFail(); })
});
await promise;
done();
})
/** /**
* @tc.name get string promise interface test * @tc.name get string promise interface test
* @tc.number SUB_DDM_Preferences_Get_Promise_0210 * @tc.number SUB_DDM_Preferences_Get_Promise_0210
* @tc.desc get string promise interface test * @tc.desc get string promise interface test
*/ */
it('testPreferencesGetDefValue00162', 0, async function (done) { it('testPreferencesGetDefValue00162', 0, async function (done) {
await mPreferences.clear(); await mPreferences.clear();
const promise = mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, true); let promise = mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, true);
promise.then((ret) => { promise.then((ret) => {
expect(true).assertEqual(ret); expect(true).assertEqual(ret);
}).catch((err) => { }).catch((err) => {
expect(null).assertFail(); expect(null).assertFail();
}); });
await promise; await promise;
done(); done();
})
}) })
})
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册