提交 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") { ...@@ -20,12 +20,14 @@ ohos_js_hap_suite("kvStore_js_test") {
":kvStore_resources", ":kvStore_resources",
] ]
certificate_profile = "./signature/openharmony_sx.p7b" certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActKvStoreJsTest" hap_name = "ActsKvStoreJsTest"
subsystem_name = "distributeddatamgr" subsystem_name = "distributeddatamgr"
part_name = "distributeddatamgr" part_name = "distributeddatamgr"
} }
ohos_js_assets("kvStore_js_assets") { 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") { ohos_resources("kvStore_resources") {
sources = [ "./src/main/resources" ] sources = [ "./src/main/resources" ]
......
{ {
"description": "Configuration for hjunit demo Tests", "description": "Configuration for hjunit demo Tests",
"driver": { "driver": {
"type": "JSUnitTest", "type": "OHJSUnitTest",
"test-timeout": "1200000", "test-timeout": "1200000",
"package": "ohos.acts.kvStore", "testcase-timeout": 60000,
"bundle-name": "ohos.acts.kvStore",
"package-name": "ohos.acts.kvStore",
"shell-timeout": "60000" "shell-timeout": "60000"
}, },
"kits": [ "kits": [
{ {
"test-file-name": [ "test-file-name": [
"ActKvStoreJsTest.hap" "ActsKvStoreJsTest.hap"
], ],
"type": "AppInstallKit", "type": "AppInstallKit",
"cleanup-apps": true "cleanup-apps": true
......
...@@ -14,8 +14,9 @@ ...@@ -14,8 +14,9 @@
"deviceConfig": {}, "deviceConfig": {},
"module": { "module": {
"package": "ohos.acts.kvStore", "package": "ohos.acts.kvStore",
"name": ".MyApplication", "name": ".entry",
"mainAbility": "ohos.acts.kvStore.MainAbility", "mainAbility": ".MainAbility",
"srcPath":"",
"deviceType": [ "deviceType": [
"phone" "phone"
], ],
...@@ -27,7 +28,6 @@ ...@@ -27,7 +28,6 @@
}, },
"abilities": [ "abilities": [
{ {
"visible": true,
"skills": [ "skills": [
{ {
"entities": [ "entities": [
...@@ -38,11 +38,29 @@ ...@@ -38,11 +38,29 @@
] ]
} }
], ],
"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", "icon": "$media:icon",
"description": "$string:mainability_description", "description": "$string:TestAbility_desc",
"label": "$string:app_name", "label": "$string:TestAbility_label",
"type": "page", "type": "page",
"visible": true,
"launchType": "standard" "launchType": "standard"
} }
], ],
...@@ -56,7 +74,21 @@ ...@@ -56,7 +74,21 @@
"designWidth": 720, "designWidth": 720,
"autoDesignWidth": true "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 @@ ...@@ -12,8 +12,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {Core} from 'deccjsunit/index'
const injectRef = Object.getPrototypeOf(global) || global const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
...@@ -26,10 +24,6 @@ export default { ...@@ -26,10 +24,6 @@ export default {
}, },
onShow() { onShow() {
console.info('onShow finish') console.info('onShow finish')
const core = Core.getInstance()
core.init()
require('../../test/List.test')
core.execute()
}, },
onReady() { 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 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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' import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int_2'; const KEY_TEST_INT_ELEMENT = 'key_test_int_2';
...@@ -54,8 +54,8 @@ function putBatchString(len, prefix) { ...@@ -54,8 +54,8 @@ function putBatchString(len, prefix) {
} }
return entries; return entries;
} }
export default function deviceKvStoreCallbackTest(){
describe('DeviceKvStoreCallbackTest', function () { describe('deviceKvStoreCallbackTest', function () {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -2300,3 +2300,4 @@ describe('DeviceKvStoreCallbackTest', function () { ...@@ -2300,3 +2300,4 @@ describe('DeviceKvStoreCallbackTest', function () {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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' import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int'; const KEY_TEST_INT_ELEMENT = 'key_test_int';
...@@ -54,8 +54,8 @@ function putBatchString(len, prefix) { ...@@ -54,8 +54,8 @@ function putBatchString(len, prefix) {
} }
return entries; return entries;
} }
export default function deviceKvStorePromiseTest(){
describe('DeviceKvStorePromiseTest', function () { describe('deviceKvStorePromiseTest', function () {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -1071,10 +1071,9 @@ describe('DeviceKvStorePromiseTest', function () { ...@@ -1071,10 +1071,9 @@ describe('DeviceKvStorePromiseTest', function () {
kvStore.on('syncComplete', func); kvStore.on('syncComplete', func);
kvStore.on('syncComplete', func1); kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func); kvStore.off('syncComplete', func);
expect(null).assertFail();
}catch(e) { }catch(e) {
console.info('testDeviceKvStoreOffSyncComplete002 put e ' + e); console.info('testDeviceKvStoreOffSyncComplete002 put e ' + e);
expect(true).assertTrue(); expect(null).assertFail();
} }
done(); done();
}) })
...@@ -1097,10 +1096,9 @@ describe('DeviceKvStorePromiseTest', function () { ...@@ -1097,10 +1096,9 @@ describe('DeviceKvStorePromiseTest', function () {
kvStore.on('syncComplete', func1); kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func); kvStore.off('syncComplete', func);
kvStore.off('syncComplete', func1); kvStore.off('syncComplete', func1);
expect(null).assertFail();
}catch(e) { }catch(e) {
console.info('testDeviceKvStoreOffSyncComplete003 put e ' + e); console.info('testDeviceKvStoreOffSyncComplete003 put e ' + e);
expect(true).assertTrue(); expect(null).assertFail();
} }
done(); done();
}) })
...@@ -2533,3 +2531,4 @@ describe('DeviceKvStorePromiseTest', function () { ...@@ -2533,3 +2531,4 @@ describe('DeviceKvStorePromiseTest', function () {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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'; import ddm from '@ohos.data.distributedData';
describe('FieldNodeTest', function() { export default function fieldNodeTest(){
describe('fieldNodeTest', function() {
/** /**
* @tc.number SUB_DISTRIBUTEDDATAMGR_FIELDNODE_APPENDCHILD_0100 * @tc.number SUB_DISTRIBUTEDDATAMGR_FIELDNODE_APPENDCHILD_0100
...@@ -262,3 +263,4 @@ describe('FieldNodeTest', function() { ...@@ -262,3 +263,4 @@ describe('FieldNodeTest', function() {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -22,7 +22,8 @@ const STORE_VALUE = 'value-test-string'; ...@@ -22,7 +22,8 @@ const STORE_VALUE = 'value-test-string';
var kvManager = null; var kvManager = null;
var kvStore = null; var kvStore = null;
describe('KVManagerCallbackTest', function () { export default function kvManagerCallbackTest(){
describe('kvManagerCallbackTest', function () {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -935,17 +936,5 @@ describe('KVManagerCallbackTest', function () { ...@@ -935,17 +936,5 @@ describe('KVManagerCallbackTest', function () {
done(); 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
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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'; import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
...@@ -23,7 +23,8 @@ const STORE_KEY = 'key_test_string'; ...@@ -23,7 +23,8 @@ const STORE_KEY = 'key_test_string';
const STORE_VALUE = 'value-test-string'; const STORE_VALUE = 'value-test-string';
var kvStoreNew = null; var kvStoreNew = null;
describe('KVManagerPromiseTest', function () { export default function kvManagerPromiseTest(){
describe('kvManagerPromiseTest', function () {
const config = { const config = {
bundleName: TEST_BUNDLE_NAME, bundleName: TEST_BUNDLE_NAME,
userInfo: { userInfo: {
...@@ -413,9 +414,9 @@ describe('KVManagerPromiseTest', function () { ...@@ -413,9 +414,9 @@ describe('KVManagerPromiseTest', function () {
try { try {
await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => { await kvManager.getKVStore(TEST_STORE_ID, optionsInfo).then((store) => {
console.info('testKVManagerGetKVStore013 getKVStore success'); console.info('testKVManagerGetKVStore013 getKVStore success');
expect(null).assertFail();
}).catch((err) => { }).catch((err) => {
console.info('testKVManagerGetKVStore013 getKVStore err ' + err); console.info('testKVManagerGetKVStore013 getKVStore err ' + err);
expect(null).assertFail();
}); });
} catch (e) { } catch (e) {
console.info('testKVManagerGetKVStore013 getKVStore e ' + e); console.info('testKVManagerGetKVStore013 getKVStore e ' + e);
...@@ -610,8 +611,8 @@ describe('KVManagerPromiseTest', function () { ...@@ -610,8 +611,8 @@ describe('KVManagerPromiseTest', function () {
console.info('testKVManagerDeleteKVStore001'); console.info('testKVManagerDeleteKVStore001');
await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID).then(() => { await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID).then(() => {
console.info('testKVManagerDeleteKVStore001 deleteKVStore success'); console.info('testKVManagerDeleteKVStore001 deleteKVStore success');
expect(null).assertFail();
}).catch((err) => { }).catch((err) => {
expect(null).assertFail();
console.info('testKVManagerDeleteKVStore001 deleteKVStore err ' + err); console.info('testKVManagerDeleteKVStore001 deleteKVStore err ' + err);
}); });
done(); done();
...@@ -863,6 +864,5 @@ describe('KVManagerPromiseTest', function () { ...@@ -863,6 +864,5 @@ describe('KVManagerPromiseTest', function () {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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'; import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
...@@ -21,7 +21,8 @@ var kvManager = null; ...@@ -21,7 +21,8 @@ var kvManager = null;
var kvStore = null; var kvStore = null;
var resultSet = null; var resultSet = null;
describe('KvStoreResultSetTest', function() { export default function kvStoreResultSetTest(){
describe('kvStoreResultSetTest', function() {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -1085,3 +1086,4 @@ describe('KvStoreResultSetTest', function() { ...@@ -1085,3 +1086,4 @@ describe('KvStoreResultSetTest', function() {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -12,14 +12,28 @@ ...@@ -12,14 +12,28 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
require('./DeviceKvStorePromiseJsunit.test.js')
require('./DeviceKvStoreCallbackJsunit.test.js') import deviceKvStorePromiseTest from './DeviceKvStorePromiseJsunit.test.js'
require('./SingleKvStorePromiseJsunit.test.js') import deviceKvStoreCallbackTest from './DeviceKvStoreCallbackJsunit.test.js'
require('./SingleKvStoreCallbackJsunit.test.js') import singleKvStorePromiseTest from './SingleKvStorePromiseJsunit.test.js'
require('./SingleKvStoreEnumJsunit.test.js') import singleKvStoreCallbackTest from './SingleKvStoreCallbackJsunit.test.js'
require('./KvManagerPromiseJsunit.test.js') import singleKvStoreEnumTest from './SingleKvStoreEnumJsunit.test.js'
require('./KvManagerCallbackJsunit.test.js') import kvManagerPromiseTest from './KvManagerPromiseJsunit.test.js'
require('./KvStoreResultSetJsunit.test.js') import kvManagerCallbackTest from './KvManagerCallbackJsunit.test.js'
require('./QueryJsunit.test.js') import kvStoreResultSetTest from './KvStoreResultSetJsunit.test.js'
require('./FieldNodeJsunit.test.js') import queryTest from './QueryJsunit.test.js'
require('./SchemaJsunit.test.js') import fieldNodeTest from './FieldNodeJsunit.test.js'
\ No newline at end of file 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 @@ ...@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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'; import ddm from '@ohos.data.distributedData';
describe('QueryTest', function() { export default function queryTest(){
describe('queryTest', function() {
/** /**
* @tc.number SUB_DISTRIBUTEDDATAMGR_QUERY_RESET_0100 * @tc.number SUB_DISTRIBUTEDDATAMGR_QUERY_RESET_0100
...@@ -2362,3 +2363,4 @@ describe('QueryTest', function() { ...@@ -2362,3 +2363,4 @@ describe('QueryTest', function() {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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'; import ddm from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore'; const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
...@@ -83,7 +83,8 @@ async function testPutAndGet(kvManager, options) { ...@@ -83,7 +83,8 @@ async function testPutAndGet(kvManager, options) {
} }
} }
describe('SchemaTest', function() { export default function schemaTest(){
describe('schemaTest', function() {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -372,4 +373,4 @@ describe('SchemaTest', function() { ...@@ -372,4 +373,4 @@ describe('SchemaTest', function() {
done(); done();
}) })
}) })
}
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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' import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int_2'; const KEY_TEST_INT_ELEMENT = 'key_test_int_2';
...@@ -54,7 +54,8 @@ function putBatchString(len, prefix) { ...@@ -54,7 +54,8 @@ function putBatchString(len, prefix) {
return entries; return entries;
} }
describe('SingleKvStoreCallbackTest', function () { export default function singleKvStoreCallbackTest(){
describe('singleKvStoreCallbackTest', function () {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -2436,3 +2437,4 @@ describe('SingleKvStoreCallbackTest', function () { ...@@ -2436,3 +2437,4 @@ describe('SingleKvStoreCallbackTest', function () {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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'; import factory from '@ohos.data.distributedData';
describe('KvStoreEnumTest', function () { export default function singleKvStoreEnumTest(){
describe('singleKvStoreEnumTest', function () {
/** /**
* @tc.number SUB_DISTRIBUTEDDATAMGR_USERTYPE_SAMEUSERID_0100 * @tc.number SUB_DISTRIBUTEDDATAMGR_USERTYPE_SAMEUSERID_0100
...@@ -340,3 +341,4 @@ describe('KvStoreEnumTest', function () { ...@@ -340,3 +341,4 @@ describe('KvStoreEnumTest', function () {
expect(s4 == 6).assertTrue() expect(s4 == 6).assertTrue()
}) })
}) })
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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' import factory from '@ohos.data.distributedData'
const KEY_TEST_INT_ELEMENT = 'key_test_int'; const KEY_TEST_INT_ELEMENT = 'key_test_int';
...@@ -54,7 +54,8 @@ function putBatchString(len, prefix) { ...@@ -54,7 +54,8 @@ function putBatchString(len, prefix) {
return entries; return entries;
} }
describe('SingleKvStorePromiseTest', function () { export default function singleKvStorePromiseTest(){
describe('singleKvStorePromiseTest', function () {
const config = { const config = {
bundleName : TEST_BUNDLE_NAME, bundleName : TEST_BUNDLE_NAME,
userInfo : { userInfo : {
...@@ -942,6 +943,7 @@ describe('SingleKvStorePromiseTest', function () { ...@@ -942,6 +943,7 @@ describe('SingleKvStorePromiseTest', function () {
*/ */
it('testSingleKvStoreOffChange002', 0, async function (done) { it('testSingleKvStoreOffChange002', 0, async function (done) {
console.info('testSingleKvStoreOffChange002'); console.info('testSingleKvStoreOffChange002');
let ret = false;
try { try {
var func = function (data) { var func = function (data) {
console.info('testSingleKvStoreOffChange002 ' + JSON.stringify(data)); console.info('testSingleKvStoreOffChange002 ' + JSON.stringify(data));
...@@ -1041,10 +1043,9 @@ describe('SingleKvStorePromiseTest', function () { ...@@ -1041,10 +1043,9 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.on('syncComplete', func); kvStore.on('syncComplete', func);
kvStore.on('syncComplete', func1); kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func); kvStore.off('syncComplete', func);
expect(null).assertFail();
}catch(e) { }catch(e) {
console.info('testSingleKvStoreOffSyncComplete002 put e ' + e); console.info('testSingleKvStoreOffSyncComplete002 put e ' + e);
expect(true).assertTrue(); expect(null).assertFail();
} }
done(); done();
}) })
...@@ -1067,10 +1068,9 @@ describe('SingleKvStorePromiseTest', function () { ...@@ -1067,10 +1068,9 @@ describe('SingleKvStorePromiseTest', function () {
kvStore.on('syncComplete', func1); kvStore.on('syncComplete', func1);
kvStore.off('syncComplete', func); kvStore.off('syncComplete', func);
kvStore.off('syncComplete', func1); kvStore.off('syncComplete', func1);
expect(null).assertFail();
}catch(e) { }catch(e) {
console.info('testSingleKvStoreOffSyncComplete003 put e ' + e); console.info('testSingleKvStoreOffSyncComplete003 put e ' + e);
expect(true).assertTrue(); expect(null).assertFail();
} }
done(); done();
}) })
...@@ -2733,3 +2733,4 @@ describe('SingleKvStorePromiseTest', function () { ...@@ -2733,3 +2733,4 @@ describe('SingleKvStorePromiseTest', function () {
done(); done();
}) })
}) })
}
\ No newline at end of file
...@@ -7,6 +7,22 @@ ...@@ -7,6 +7,22 @@
{ {
"name": "mainability_description", "name": "mainability_description",
"value": "hap sample empty page" "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 @@ ...@@ -13,6 +13,9 @@
* limitations under the License. * 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 storageCallBackTest from './StorageCallBackJsunit.test.js'
import storageHelperTest from './StorageHelperJsunit.test.js' import storageHelperTest from './StorageHelperJsunit.test.js'
import storagePromiseTest from './StoragePromiseJsunit.test.js' import storagePromiseTest from './StoragePromiseJsunit.test.js'
...@@ -24,4 +27,7 @@ storageHelperTest() ...@@ -24,4 +27,7 @@ storageHelperTest()
storagePromiseTest() storagePromiseTest()
storageSyncTest() storageSyncTest()
systemStorageTest() 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.
先完成此消息的编辑!
想要评论请 注册