提交 5b551af6 编写于 作者: L liangzhenyu123

kv_store部件xts用例适配新框架

Signed-off-by: Nliangzhenyu123 <liangzhenyu6@huawei.com>
上级 5fd1c9d3
......@@ -20,12 +20,14 @@ ohos_js_hap_suite("kvStore_js_test") {
":kvStore_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActKvStoreJsTest"
hap_name = "ActsKvStoreJsTest"
subsystem_name = "distributeddatamgr"
part_name = "distributeddatamgr"
}
ohos_js_assets("kvStore_js_assets") {
source_dir = "./src/main/js/default"
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("kvStore_resources") {
sources = [ "./src/main/resources" ]
......
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "JSUnitTest",
"type": "OHJSUnitTest",
"test-timeout": "1200000",
"package": "ohos.acts.kvStore",
"testcase-timeout": 60000,
"bundle-name": "ohos.acts.kvStore",
"package-name": "ohos.acts.kvStore",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActKvStoreJsTest.hap"
"ActsKvStoreJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
......@@ -14,8 +14,9 @@
"deviceConfig": {},
"module": {
"package": "ohos.acts.kvStore",
"name": ".MyApplication",
"mainAbility": "ohos.acts.kvStore.MainAbility",
"name": ".entry",
"mainAbility": ".MainAbility",
"srcPath":"",
"deviceType": [
"phone"
],
......@@ -27,7 +28,6 @@
},
"abilities": [
{
"visible": true,
"skills": [
{
"entities": [
......@@ -38,13 +38,31 @@
]
}
],
"name": "ohos.acts.kvStore.MainAbility",
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
}
],
"js": [
{
......@@ -56,7 +74,21 @@
"designWidth": 720,
"autoDesignWidth": true
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
]
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
}
}
}
\ No newline at end of file
......@@ -12,8 +12,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Core} from 'deccjsunit/index'
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
......@@ -26,10 +24,6 @@ export default {
},
onShow() {
console.info('onShow finish')
const core = Core.getInstance()
core.init()
require('../../test/List.test')
core.execute()
},
onReady() {
},
......
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* 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.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* 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 AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int_2';
......@@ -54,8 +54,8 @@ function putBatchString(len, prefix) {
}
return entries;
}
describe('DeviceKvStoreCallbackTest', function () {
export default function deviceKvStoreCallbackTest(){
describe('deviceKvStoreCallbackTest', function () {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -2299,4 +2299,5 @@ describe('DeviceKvStoreCallbackTest', function () {
}
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int';
......@@ -54,8 +54,8 @@ function putBatchString(len, prefix) {
}
return entries;
}
describe('DeviceKvStorePromiseTest', function () {
export default function deviceKvStorePromiseTest(){
describe('deviceKvStorePromiseTest', function () {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -1071,10 +1071,9 @@ describe('DeviceKvStorePromiseTest', function () {
kvStore.on('syncComplete', func);
kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func);
expect(null).assertFail();
}catch(e) {
console.info('testDeviceKvStoreOffSyncComplete002 put e ' + e);
expect(true).assertTrue();
expect(null).assertFail();
}
done();
})
......@@ -1097,10 +1096,9 @@ describe('DeviceKvStorePromiseTest', function () {
kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func);
kvStore.off('syncComplete', func1);
expect(null).assertFail();
}catch(e) {
console.info('testDeviceKvStoreOffSyncComplete003 put e ' + e);
expect(true).assertTrue();
expect(null).assertFail();
}
done();
})
......@@ -2532,4 +2530,5 @@ describe('DeviceKvStorePromiseTest', function () {
}
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import ddm from '@ohos.data.distributedData';
describe('FieldNodeTest', function() {
export default function fieldNodeTest(){
describe('fieldNodeTest', function() {
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_FIELDNODE_APPENDCHILD_0100
......@@ -261,4 +262,5 @@ describe('FieldNodeTest', function() {
}
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -22,7 +22,8 @@ const STORE_VALUE = 'value-test-string';
var kvManager = null;
var kvStore = null;
describe('KVManagerCallbackTest', function () {
export default function kvManagerCallbackTest(){
describe('kvManagerCallbackTest', function () {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -935,17 +936,5 @@ describe('KVManagerCallbackTest', function () {
done();
}
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_KVSTORE_ON_1100
* @tc.name [JS-API8]KVStore.On
* @tc.desc Test Js Api KVManager.On testcase 101
*/
// it('testKVStoreOn101', 0, async function (done) {
// kvStoreNew.on('syncComplete', function (data) {
// console.info("testKVStoreOn101 callback call data: " + data);
// expect(true).assertTrue();
// });
// done();
// })
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
......@@ -23,7 +23,8 @@ const STORE_KEY = 'key_test_string';
const STORE_VALUE = 'value-test-string';
var kvStoreNew = null;
describe('KVManagerPromiseTest', function () {
export default function kvManagerPromiseTest(){
describe('kvManagerPromiseTest', function () {
const config = {
bundleName: TEST_BUNDLE_NAME,
userInfo: {
......@@ -413,9 +414,9 @@ describe('KVManagerPromiseTest', function () {
try {
await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
console.info('testKVManagerGetKVStore013 getKVStore success');
expect(null).assertFail();
}).catch((err) => {
console.info('testKVManagerGetKVStore013 getKVStore err ' + err);
expect(null).assertFail();
});
} catch (e) {
console.info('testKVManagerGetKVStore013 getKVStore e ' + e);
......@@ -610,8 +611,8 @@ describe('KVManagerPromiseTest', function () {
console.info('testKVManagerDeleteKVStore001');
await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID).then(() => {
console.info('testKVManagerDeleteKVStore001 deleteKVStore success');
expect(null).assertFail();
}).catch((err) => {
expect(null).assertFail();
console.info('testKVManagerDeleteKVStore001 deleteKVStore err ' + err);
});
done();
......@@ -862,7 +863,6 @@ describe('KVManagerPromiseTest', function () {
}
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
......@@ -21,7 +21,8 @@ var kvManager = null;
var kvStore = null;
var resultSet = null;
describe('KvStoreResultSetTest', function() {
export default function kvStoreResultSetTest(){
describe('kvStoreResultSetTest', function() {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -1084,4 +1085,5 @@ describe('KvStoreResultSetTest', function() {
}
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,14 +12,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
require('./DeviceKvStorePromiseJsunit.test.js')
require('./DeviceKvStoreCallbackJsunit.test.js')
require('./SingleKvStorePromiseJsunit.test.js')
require('./SingleKvStoreCallbackJsunit.test.js')
require('./SingleKvStoreEnumJsunit.test.js')
require('./KvManagerPromiseJsunit.test.js')
require('./KvManagerCallbackJsunit.test.js')
require('./KvStoreResultSetJsunit.test.js')
require('./QueryJsunit.test.js')
require('./FieldNodeJsunit.test.js')
require('./SchemaJsunit.test.js')
\ No newline at end of file
import deviceKvStorePromiseTest from './DeviceKvStorePromiseJsunit.test.js'
import deviceKvStoreCallbackTest from './DeviceKvStoreCallbackJsunit.test.js'
import singleKvStorePromiseTest from './SingleKvStorePromiseJsunit.test.js'
import singleKvStoreCallbackTest from './SingleKvStoreCallbackJsunit.test.js'
import singleKvStoreEnumTest from './SingleKvStoreEnumJsunit.test.js'
import kvManagerPromiseTest from './KvManagerPromiseJsunit.test.js'
import kvManagerCallbackTest from './KvManagerCallbackJsunit.test.js'
import kvStoreResultSetTest from './KvStoreResultSetJsunit.test.js'
import queryTest from './QueryJsunit.test.js'
import fieldNodeTest from './FieldNodeJsunit.test.js'
import schemaTest from './SchemaJsunit.test.js'
export default function testsuite() {
deviceKvStoreCallbackTest()
deviceKvStorePromiseTest()
singleKvStorePromiseTest()
singleKvStoreCallbackTest()
singleKvStoreEnumTest()
kvManagerPromiseTest()
kvManagerCallbackTest()
kvStoreResultSetTest()
queryTest()
fieldNodeTest()
schemaTest()
}
\ No newline at end of file
......@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import ddm from '@ohos.data.distributedData';
describe('QueryTest', function() {
export default function queryTest(){
describe('queryTest', function() {
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_QUERY_RESET_0100
......@@ -2361,4 +2362,5 @@ describe('QueryTest', function() {
query = null;
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import ddm from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
......@@ -83,7 +83,8 @@ async function testPutAndGet(kvManager, options) {
}
}
describe('SchemaTest', function() {
export default function schemaTest(){
describe('schemaTest', function() {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -372,4 +373,4 @@ describe('SchemaTest', function() {
done();
})
})
}
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int_2';
......@@ -54,7 +54,8 @@ function putBatchString(len, prefix) {
return entries;
}
describe('SingleKvStoreCallbackTest', function () {
export default function singleKvStoreCallbackTest(){
describe('singleKvStoreCallbackTest', function () {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -2435,4 +2436,5 @@ describe('SingleKvStoreCallbackTest', function () {
}
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import factory from '@ohos.data.distributedData';
describe('KvStoreEnumTest', function () {
export default function singleKvStoreEnumTest(){
describe('singleKvStoreEnumTest', function () {
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_USERTYPE_SAMEUSERID_0100
......@@ -339,4 +340,5 @@ describe('KvStoreEnumTest', function () {
console.info('s4 = ' + s4);
expect(s4 == 6).assertTrue()
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int';
......@@ -54,7 +54,8 @@ function putBatchString(len, prefix) {
return entries;
}
describe('SingleKvStorePromiseTest', function () {
export default function singleKvStorePromiseTest(){
describe('singleKvStorePromiseTest', function () {
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
......@@ -942,6 +943,7 @@ describe('SingleKvStorePromiseTest', function () {
*/
it('testSingleKvStoreOffChange002', 0, async function (done) {
console.info('testSingleKvStoreOffChange002');
let ret = false;
try {
var func = function (data) {
console.info('testSingleKvStoreOffChange002 ' + JSON.stringify(data));
......@@ -1041,10 +1043,9 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.on('syncComplete', func);
kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func);
expect(null).assertFail();
}catch(e) {
console.info('testSingleKvStoreOffSyncComplete002 put e ' + e);
expect(true).assertTrue();
expect(null).assertFail();
}
done();
})
......@@ -1067,10 +1068,9 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func);
kvStore.off('syncComplete', func1);
expect(null).assertFail();
}catch(e) {
console.info('testSingleKvStoreOffSyncComplete003 put e ' + e);
expect(true).assertTrue();
expect(null).assertFail();
}
done();
})
......@@ -2732,4 +2732,5 @@ describe('SingleKvStorePromiseTest', function () {
});
done();
})
})
\ No newline at end of file
})
}
\ No newline at end of file
......@@ -7,6 +7,22 @@
{
"name": "mainability_description",
"value": "hap sample empty page"
}
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
......@@ -13,6 +13,9 @@
* limitations under the License.
*/
import preferencesCallBackTest from './PreferencesCallBackJsunit.test.js'
import preferencesHelperTest from './PreferencesHelperJsunit.test.js'
import preferencesPromiseTest from './PreferencesPromiseJsunit.test.js'
import storageCallBackTest from './StorageCallBackJsunit.test.js'
import storageHelperTest from './StorageHelperJsunit.test.js'
import storagePromiseTest from './StoragePromiseJsunit.test.js'
......@@ -24,4 +27,7 @@ storageHelperTest()
storagePromiseTest()
storageSyncTest()
systemStorageTest()
preferencesCallBackTest()
preferencesHelperTest()
preferencesPromiseTest()
}
/*
* 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 'deccjsunit/index'
import dataPreferences from '@ohos.data.preferences'
import featureAbility from '@ohos.ability.featureAbility';
const NAME = 'test_preferences';
const KEY_TEST_INT_ELEMENT = 'key_test_int';
const KEY_TEST_LONG_ELEMENT = 'key_test_long';
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean';
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const KEY_TEST_NUMBER_ARRAY_ELEMENT = 'key_test_number_array';
const KEY_TEST_STRING_ARRAY_ELEMENT = 'key_test_string_array';
const KEY_TEST_BOOL_ARRAY_ELEMENT = 'key_test_bool_array';
var mPreferences;
var context;
const TAG = '[PREFERENCES_CALLBACK_JSUNIT_TEST]'
export default function preferencesCallBackTest(){
describe('preferencesCallBackTest', function () {
beforeAll(async function () {
console.info('beforeAll')
context = featureAbility.getContext()
mPreferences = await dataPreferences.getPreferences(context, NAME);
})
afterAll(async function () {
console.info('afterAll')
await dataPreferences.deletePreferences(context, NAME);
})
/**
* @tc.name clear callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0010
* @tc.desc clear callback interface test
*/
it('testPreferencesClear0012', 0, async function (done) {
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
await mPreferences.flush();
await mPreferences.clear(async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect("defaultvalue").assertEqual(pre);
done();
});
})
/**
* @tc.name has string callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0020
* @tc.desc has string callback interface test
*/
it('testPreferencesHasKey0032', 0, async function (done) {
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
await mPreferences.has(KEY_TEST_STRING_ELEMENT, function (err, ret) {
expect(true).assertEqual(ret);
done();
})
})
/**
* @tc.name has int callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0130
* @tc.desc has int callback interface test
*/
it('testPreferencesHasKey0033', 0, async function (done) {
await mPreferences.put(KEY_TEST_INT_ELEMENT, 1);
await mPreferences.has(KEY_TEST_INT_ELEMENT, function (err, ret) {
expect(true).assertEqual(ret);
done();
})
})
/**
* @tc.name has float callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0140
* @tc.desc has float callback interface test
*/
it('testPreferencesHasKey0034', 0, async function (done) {
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 1.1);
await mPreferences.has(KEY_TEST_FLOAT_ELEMENT, function (err, ret) {
expect(true).assertEqual(ret);
done();
})
})
/**
* @tc.name has long callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0150
* @tc.desc has long callback interface test
*/
it('testPreferencesHasKey0035', 0, async function (done) {
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0);
await mPreferences.has(KEY_TEST_LONG_ELEMENT, function (err, ret) {
expect(true).assertEqual(ret);
done();
})
})
/**
* @tc.name has boolean callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0160
* @tc.desc has boolean callback interface test
*/
it('testPreferencesHasKey0036', 0, async function (done) {
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false);
await mPreferences.has(KEY_TEST_BOOLEAN_ELEMENT, function (err, ret) {
expect(true).assertEqual(ret);
done();
})
})
/**
* @tc.name get defaultValue callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0030
* @tc.desc get defaultValue callback interface test
*/
it('testPreferencesGetDefValue0062', 0, async function (done) {
await mPreferences.clear();
await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultValue", function (err, ret) {
expect('defaultValue').assertEqual(ret);
done();
})
})
/**
* @tc.name get float callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0040
* @tc.desc get float callback interface test
*/
it('testPreferencesGetFloat0072', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0);
await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0, function (err, ret) {
expect(3.0).assertEqual(ret);
done();
})
})
/**
* @tc.name get int callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0050
* @tc.desc get int callback interface test
*/
it('testPreferencesGetInt0082', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_INT_ELEMENT, 3);
await mPreferences.get(KEY_TEST_INT_ELEMENT, 0.0, function (err, ret) {
expect(3).assertEqual(ret);
done();
})
})
/**
* @tc.name get long callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0060
* @tc.desc get long callback interface test
*/
it('testPreferencesGetLong0092', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 3);
let pref = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0)
expect(3).assertEqual(pref);
await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0, function (err, ret) {
expect(3).assertEqual(ret);
done();
});
})
/**
* @tc.name get String callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0070
* @tc.desc get String callback interface test
*/
it('testPreferencesGetString102', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
await mPreferences.flush();
await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) {
expect('test').assertEqual(ret);
done();
});
})
/**
* @tc.name put boolean callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0080
* @tc.desc put boolean callback interface test
*/
it('testPreferencesPutBoolean0122', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false);
expect(true).assertEqual(pre);
await mPreferences.flush();
let pre2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false)
expect(true).assertEqual(pre2);
done();
});
})
/**
* @tc.name put float callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0090
* @tc.desc put float callback interface test
*/
it('testPreferencesPutFloat0132', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
expect(4.0).assertEqual(pre);
await mPreferences.flush();
let pre2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
expect(4.0).assertEqual(pre2);
done();
});
})
/**
* @tc.name put int callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0100
* @tc.desc put int callback interface test
*/
it('testPreferencesPutInt0142', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_INT_ELEMENT, 4, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0);
expect(4).assertEqual(pre);
await mPreferences.flush();
let pre2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0);
expect(4).assertEqual(pre2);
done();
});
})
/**
* @tc.name put long callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0110
* @tc.desc put long callback interface test
*/
it('testPreferencesPutLong0152', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 4);
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 4, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
expect(4).assertEqual(pre);
await mPreferences.flush();
let pre2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
expect(4).assertEqual(pre2);
done();
});
})
/**
* @tc.name put String callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0120
* @tc.desc put String callback interface test
*/
it('testPreferencesPutString0162', 0, async function (done) {
await mPreferences.clear();
await mPreferences.put(KEY_TEST_STRING_ELEMENT, '', async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect('').assertEqual(pre);
await mPreferences.flush();
let pre2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect('').assertEqual(pre2);
done();
});
})
/**
* @tc.name clear、put、get、flush String callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0120
* @tc.desc flush String callback interface test
*/
it('testPreferencesCallback0172', 0, function (done) {
console.log(TAG + "testPreferencesCallback0172 begin.");
mPreferences.clear(function (err, val) {
if(err){
expect(null).assertEqual();
}
mPreferences.put(KEY_TEST_STRING_ELEMENT, '', function (err, ret) {
if(err){
expect(null).assertEqual();
}
mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) {
if(err){
expect(null).assertEqual();
}
expect('').assertEqual(pre);
mPreferences.flush(function (err, val) {
if(err){
expect(null).assertEqual();
}
mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre2) {
if(err){
expect(null).assertEqual();
}
expect('').assertEqual(pre2);
done();
console.log(TAG + "testPreferencesCallback0172 end.");
})
});
})
});
});
})
/**
* @tc.name put StringArray callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0001
* @tc.desc put String callback interface test
*/
it('testPreferencesPutStringArray0001', 0, async function (done) {
await mPreferences.clear();
var stringArr = ['11', '22', '33']
await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ['123', '321'])
for (let i = 0; i < stringArr.length; i++) {
expect(stringArr[i]).assertEqual(pre[i]);
}
done();
});
})
/**
* @tc.name put NumberArray callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0002
* @tc.desc put String callback interface test
*/
it('testPreferencesPutNumArray0001', 0, async function (done) {
await mPreferences.clear();
var doubleArr = [11, 22, 33]
await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321])
for (let i = 0; i < doubleArr.length; i++) {
expect(doubleArr[i]).assertEqual(pre[i]);
}
done();
});
})
/**
* @tc.name put BoolArray callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0003
* @tc.desc put String callback interface test
*/
it('testPreferencesPutBoolArray0001', 0, async function (done) {
await mPreferences.clear();
let boolArr = [true, false, false, true]
await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr, async function (err, ret) {
let pre = await mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [true, false])
for (let i = 0; i < boolArr.length; i++) {
expect(boolArr[i]).assertEqual(pre[i]);
}
done();
});
})
/**
* @tc.name getAll callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_CallBack_0004
* @tc.desc getAll callback 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()
await mPreferences.getAll(function (err, 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]);
}
done()
})
})
})
}
\ No newline at end of file
// @ts-nocheck
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import dataPreferences from '@ohos.data.preferences'
import featureAbility from '@ohos.ability.featureAbility';
const NAME = 'test_preferences';
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
var mPreferences;
var context;
export default function preferencesHelperTest(){
describe('preferencesHelperTest', function () {
beforeAll(async function () {
console.info('beforeAll')
context = featureAbility.getContext()
mPreferences = await dataPreferences.getPreferences(context, NAME);
})
afterAll(async function () {
console.info('afterAll')
await dataPreferences.deletePreferences(context, NAME);
})
/**
* @tc.name getPreferencesSync interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0010
* @tc.desc getPreferencesSync interface test
*/
it('testGetPreferencesHelper001', 0, async function () {
mPreferences = await dataPreferences.getPreferences(context, NAME);
await mPreferences.put('test', 2);
await mPreferences.flush();
var value = await mPreferences.get('test', 0);
expect(value).assertEqual(2);
})
/**
* @tc.name getPreferences interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0020
* @tc.desc getPreferences interface test
*/
it('testGetPreferencesHelper002', 0, async function (done) {
const promise = dataPreferences.getPreferences(context, NAME);
promise.then(async (pref) => {
await pref.put('test', 2);
await pref.flush();
var value = await mPreferences.get('test', 0);
expect(value).assertEqual(2);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name removePreferencesFromCache interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0030
* @tc.desc removePreferencesFromCache interface test
*/
it('testRemovePreferencesFromCache001', 0, async function (done) {
let perf = await dataPreferences.getPreferences(context, NAME);
perf = null;
const promise = dataPreferences.removePreferencesFromCache(context, NAME);
promise.then((pref) => {
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name deletePreferences interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0060
* @tc.desc deletePreferences interface test
*/
it('testDeletePreferencesHelper002', 0, async function (done) {
let perf = await dataPreferences.getPreferences(context, NAME);
perf = null;
const promise = dataPreferences.deletePreferences(context, NAME);
promise.then((pref) => {
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name put interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_0140
* @tc.desc put interface test
*/
it('testPreferencesRegisterObserver001', 0, async function () {
await mPreferences.clear();
var observer = function (key) {
console.info('testPreferencesRegisterObserver001 key' + key);
expect('abcd').assertEqual(key);
};
await mPreferences.on('change', observer);
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "abcd");
})
/**
* @tc.name repeat on interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_0150
* @tc.desc repeat on interface test
*/
it('testPreferencesRegisterObserver002', 0, async function () {
await mPreferences.clear();
var observer = function (key) {
console.info('testPreferencesRegisterObserver002 key' + key);
expect('abc').assertEqual(key);
};
await mPreferences.on('change', observer);
await mPreferences.on('change', observer);
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "abc");
})
/**
* @tc.name off interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_0160
* @tc.desc off interface test
*/
it('testPreferencesUnRegisterObserver001', 0, async function () {
var observer = function (key) {
console.info('testPreferencesUnRegisterObserver001 key' + key);
expect('').assertEqual(key);
};
await mPreferences.on('change', observer);
await mPreferences.off('change', observer);
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "abc");
})
})
}
\ 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 'deccjsunit/index'
import dataPreferences from '@ohos.data.preferences'
import featureAbility from '@ohos.ability.featureAbility';
const NAME = 'test_preferences';
const KEY_TEST_INT_ELEMENT = 'key_test_int';
const KEY_TEST_LONG_ELEMENT = 'key_test_long';
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean';
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const KEY_TEST_NUMBER_ARRAY_ELEMENT = 'key_test_number_array'
const KEY_TEST_STRING_ARRAY_ELEMENT = 'key_test_string_array'
const KEY_TEST_BOOL_ARRAY_ELEMENT = 'key_test_bool_array'
var mPreferences;
var context;
export default function preferencesPromiseTest(){
describe('preferencesPromiseTest', function () {
beforeAll(async function () {
console.info('beforeAll')
context = featureAbility.getContext()
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_AppDataFWK_JSPreferences_Preferences_0131
* @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_AppDataFWK_JSPreferences_Preferences_0132
* @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_AppDataFWK_JSPreferences_Preferences_0133
* @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_AppDataFWK_JSPreferences_Preferences_0133
* @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();
})
/**
* @tc.name clear promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Promise_0010
* @tc.desc clear promise interface test
*/
it('testPreferencesClear0011', 0, async function (done) {
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
await mPreferences.flush();
const promise = mPreferences.clear();
promise.then(async (ret) => {
let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue");
expect("defaultvalue").assertEqual(per);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name has string interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0020
* @tc.desc has string interface test
*/
it('testPreferencesHasKey0031', 0, async function (done) {
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test");
const promise = mPreferences.has(KEY_TEST_STRING_ELEMENT);
promise.then((ret) => {
expect(true).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name has int interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0140
* @tc.desc has int interface test
*/
it('testPreferencesHasKey0032', 0, async function (done) {
await mPreferences.put(KEY_TEST_INT_ELEMENT, 1);
const promise = mPreferences.has(KEY_TEST_INT_ELEMENT);
promise.then((ret) => {
expect(true).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name has float interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0150
* @tc.desc has float interface test
*/
it('testPreferencesHasKey0033', 0, async function (done) {
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 2.0);
const promise = mPreferences.has(KEY_TEST_FLOAT_ELEMENT);
promise.then((ret) => {
expect(true).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name has boolean interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0160
* @tc.desc has boolean interface test
*/
it('testPreferencesHasKey0034', 0, async function (done) {
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false);
const promise = mPreferences.has(KEY_TEST_BOOLEAN_ELEMENT);
promise.then((ret) => {
expect(true).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name has long interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0170
* @tc.desc has long interface test
*/
it('testPreferencesHasKey0035', 0, async function (done) {
await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0);
const promise = mPreferences.has(KEY_TEST_LONG_ELEMENT);
promise.then((ret) => {
expect(true).assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name get string promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0030
* @tc.desc get string promise interface test
*/
it('testPreferencesGetDefValue0061', 0, async function (done) {
await mPreferences.clear();
const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultValue");
promise.then((ret) => {
expect('defaultValue').assertEqual(ret);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name get float promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0040
* @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_AppDataFWK_JSPreferences_Preferences_0050
* @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_AppDataFWK_JSPreferences_Preferences_0060
* @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_AppDataFWK_JSPreferences_Preferences_0070
* @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.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0090
* @tc.desc put boolean promise interface test
*/
it('testPreferencesPutBoolean0121', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true);
promise.then(async (ret) => {
let per = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false);
expect(true).assertEqual(per);
await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false);
expect(true).assertEqual(per2);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name put float promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0100
* @tc.desc put float promise interface test
*/
it('testPreferencesPutFloat0131', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0);
promise.then(async (ret) => {
let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
expect(4.0).assertEqual(per);
await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0);
expect(4.0).assertEqual(per2);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name put int promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0110
* @tc.desc put int promise interface test
*/
it('testPreferencesPutInt0141', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_INT_ELEMENT, 4);
promise.then(async (ret) => {
let per = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0);
expect(4).assertEqual(per);
await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0);
expect(4).assertEqual(per2);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name put long promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0120
* @tc.desc put long promise interface test
*/
it('testPreferencesPutLong0151', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_LONG_ELEMENT, 4);
promise.then(async (ret) => {
let per = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
expect(4).assertEqual(per);
await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0);
expect(4).assertEqual(per2);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name put String promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Preferences_0130
* @tc.desc put String promise interface test
*/
it('testPreferencesPutString0161', 0, async function (done) {
const promise = mPreferences.put(KEY_TEST_STRING_ELEMENT, '');
promise.then(async (ret) => {
let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect('').assertEqual(per);
await mPreferences.flush();
let per2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue")
expect('').assertEqual(per2);
}).catch((err) => {
expect(null).assertFail();
});
await promise;
done();
})
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册