提交 a1cdc91c 编写于 作者: Y yanglifeng1217

<yanglifeng5@huawei.com>

Signed-off-by: Nyanglifeng1217 <yanglifeng5@huawei.com>
上级 615b162a
......@@ -16,15 +16,16 @@ group("distributeddatamgr") {
testonly = true
if (is_standard_system) {
deps = [
"appdatamgrjstest/hap:appdatamgr_js_test",
"distributeddataObjectjstest/hap:distributeddataObject_js_test",
"distributeddatamgrjstest/hap:distributeddatamgr_js_test",
"windowStage:windowStage",
"dataObjectjstest/hap:dataObject_js_test",
"dataShare:dataShare",
"kvStorejstest/hap:kvStore_js_test",
"preferencesjstest/hap:preferences_js_test",
"relationalStorejstest/hap:relationalstore_js_test",
]
} else {
deps = [
"appdatamgrtest/hap:appdatamgrfunctest_hap",
"distributeddatamgrtest/hap:distributeddatamgrfunctest_hap",
"kvStorejstest/hap:distributeddatamgrfunctest_hap",
"relationalStorejstest/hap:appdatamgrfunctest_hap",
"searchtest/hap:searchfunctest_hap",
]
}
......
......@@ -13,21 +13,23 @@
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("distributeddataObject_js_test") {
ohos_js_hap_suite("dataObject_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":distributeddataObject_js_assets",
":distributeddataObject_resources",
":dataObject_js_assets",
":dataObject_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsDistributedDataObjectJsTest"
hap_name = "ActsDataObjectJsTest"
subsystem_name = "distributeddatamgr"
part_name = "data_object"
}
ohos_js_assets("distributeddataObject_js_assets") {
ohos_js_assets("dataObject_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("distributeddataObject_resources") {
ohos_resources("dataObject_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
......@@ -4,13 +4,13 @@
"type": "OHJSUnitTest",
"test-timeout": "1200000",
"shell-timeout": "1200000",
"bundle-name": "ohos.acts.distributeddataObject",
"package-name": "ohos.acts.distributeddataObject"
"bundle-name": "ohos.acts.dataObject",
"package-name": "ohos.acts.dataObject"
},
"kits": [
{
"test-file-name": [
"ActsDistributedDataObjectJsTest.hap"
"ActsDataObjectJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
{
"app": {
"bundleName": "ohos.acts.distributeddataObject",
"bundleName": "ohos.acts.dataObject",
"vendor": "example",
"version": {
"code": 1000000,
......@@ -13,7 +13,7 @@
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.distributeddataObject",
"package": "ohos.acts.dataObject",
"name": ".entry",
"mainAbility": ".MainAbility",
"deviceType": [
......
......@@ -13,11 +13,14 @@
import("//test/xts/tools/build/suite.gni")
group("windowStage") {
group("dataShare") {
testonly = true
if (is_standard_system) {
deps = [
"dataShareKvtest:ActsDataShareKvTest",
"dataShareRdbtest:ActsDataShareRdbTest",
"dataSharejstest/hap:dataShare_js_test",
"server/kvService:ActsKvServiceHap",
"server/rdbService:ActsRdbServiceHap",
]
}
......
{
"app": {
"bundleName": "com.example.myapplication2",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"debug": false,
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
{
"string": [
{
"name": "app_name",
"value": "MyApplication2"
}
]
}
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("ActsDataShareKvTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":dataShareKv_js_assets",
":dataShareKv_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsDataShareKvTest"
subsystem_name = "distributeddatamgr"
part_name = "data_share"
}
ohos_app_scope("dataShareKv_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("dataShareKv_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("dataShareKv_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":dataShareKv_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "com.example.myapplication2",
"module-name": "entry",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [{
"test-file-name": [
"ActsDataShareKvTest.hap",
"ActsKvServiceHap.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
\ No newline at end of file
/*
* 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 AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
/*
* 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 Ability from '@ohos.application.Ability'
import dataShare from '@ohos.data.dataShare'
import rpc from "@ohos.rpc";
var seConnect = {
onConnect:function (elementName, proxy) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect called.");
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect elementName = " + elementName);
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect proxy = " + proxy);
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
let option = new rpc.MessageOption();
data.writeInterfaceToken("connect-test");
data.writeInt(111);
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect sendRequest.");
proxy.sendRequest(1, data, reply, option)
.then(function (result) {
if (result.errCode === 0) {
// let msg = reply.readString();
let msg = result.reply.readInt();
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect reply msg: " + msg);
} else {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest failed, errCode: " + result.errCode);
}
// callback没有返回值,默认返回undefined
}).catch(function (e) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest got exception: " + e);
}).finally (async () => {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest ends, reclaim parcel");
data.reclaim();
reply.reclaim();
})
},
onDisconnect:function (elementName) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onDisconnect");
},
onFailed:function (code) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onFailed");
}
};
let dseProxy = 0;
let dseUri = ("datashare:///com.samples.datasharekvtest.DataShare");
var dseConnect = {
onConnect:function (elementName, proxy) {
console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect called.");
// console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect elementName = " + elementName);
// console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect proxy = " + proxy);
dseProxy = proxy;
},
onDisconnect:function (elementName) {
console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onDisconnect, elementName:" + elementName);
},
onFailed:function (code) {
console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onFailed, code:" + code);
}
};
let seConnectionId = -1;
let dseConnectionId = -1;
let seWant = {
"bundleName": "com.samples.datasharetest",
"abilityName": "ServiceExtAbility",
}
let dseWant = {
"bundleName": "com.samples.datasharetest",
"abilityName": "DataShareExtAbility",
}
export function onCallback() {
console.info("[ttt] [DataShareTest] <<Consumer>> **** Observer on callback ****");
}
export function offCallback() {
console.info("[ttt] [DataShareTest] <<Consumer>> **** Observer off callback ****");
}
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context;
let context = this.context;
dseConnectionId = context.connectAbility(dseWant, dseConnect);
globalThis.connectDataShareExtAbility = (async () => {
console.log("[ttt] [DataShareTest] <<Consumer>> connectDataShareExtAbility begin");
await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{
globalThis.helper = data;
globalThis.testhelper = data;
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 1 -----, globalThis.helper = " + globalThis.helper);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 2 -----, data = " + data);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 3 -----, err = " + err);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err));
});
dseConnectionId = await context.connectAbility(dseWant, dseConnect);
})
windowStage.setUIContent(this.context, "MainAbility/pages/index", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onBackground")
}
};
/*
* 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 file from '@system.file';
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../test/List.test'
//InstrumentLog, ReportExtend
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* 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 TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a com.example.myapplication2.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import dataShare from '@ohos.data.dataShare'
import * as pubfun from './DataSharePublicfunction_Promise'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
//CreateDataShareHelper
let uri = "datashare:///com.samples.datasharekvtest.DataShare";
//InsertValuesBucket
let Insert = { "name": "sun", "age": 1, "isStudent": true };
let BatchInsert = new Array(
{ "name": "sun", "age": 1, "isStudent": true },
{ "name": "sun", "age": 10, "isStudent": false });
let Insert100 = new Array();
for (let i = 0; i < 100; i++) {
Insert100.push({ "name": "sun", "age": i + 1, "isStudent": true });
}
//UpdateValuesBucket
let Update = { "name": "suns", "age": 1, "isStudent": false };
//Predicates
let EqualTo = new dataSharePredicates.DataSharePredicates();
EqualTo.equalTo("$.age", 1);
let ResultSetEqualTo = new dataSharePredicates.DataSharePredicates();
ResultSetEqualTo.equalTo("$.name", "sun");
let PredicatesDelete0 = new dataSharePredicates.DataSharePredicates();
PredicatesDelete0.inKeys(["testkey0"]);
let PredicatesDelete1 = new dataSharePredicates.DataSharePredicates();
PredicatesDelete1.inKeys(["testkey1"]);
//getColumnIndex
const IndexValue = "value";
//Return Expect
const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" };
const ResultSetUpdate = { "name": "suns", "age": 1, "isStudent": "false" };
const DataProcessResultOne = 1;
const DataProcessResultThree = 3;
const column = 1;
let Delete = 0;
function onChangeNotify() {
console.info("===>onChangeNotify===>");
};
function notifyChangeCallback() {
console.info("===>notifyChangeCallback===>");
};
export default function DataShareCombinationKvdb() {
describe('DataShareCombinationKvdb', function () {
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('sleep finished');
}, time);
})
}
beforeAll(async () => {
await globalThis.connectDataShareExtAbility();
await sleep(2000);
console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Insert Update Query Delete in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareCombinationKvdb0101', 1, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0101 insert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0101 update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareCombinationKvdb0101 query err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareCombinationKvdb0101 delete err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareCombinationKvdb0101 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0102
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : BatchInsert Update Query Delete in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareCombinationKvdb0102', 1, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0102 batchInsert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0102 update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareCombinationKvdb0102 query err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0102 delete err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareCombinationKvdb0102 delete err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareCombinationKvdb0102 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0104
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : On on
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareCombinationKvdb0104', 1, function () {
try {
globalThis.helper.on("dataChange", uri, onChangeNotify);
console.info("TestDataShare going On 1");
globalThis.helper.on("dataChange", uri, onChangeNotify);
console.info("TestDataShare going On 2");
} catch (err) {
console.info("DataShareCombinationKvdb0104 fail" + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb005
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Off off
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareCombinationKvdb0105', 1, function () {
try {
globalThis.helper.on("dataChange", uri, onChangeNotify);
console.info("TestDataShare going On 1");
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare going Off 1");
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare going Off 2");
} catch (err) {
console.info("DataShareCombinationKvdb0105 fail" + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationKvdb0106
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : BatchInsert Update Query Delete in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('DataShareCombinationKvdb0106', 2, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, Insert100).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0106 batchInsert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareCombinationKvdb0106 update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareCombinationKvdb0106 query err" + JSON.stringify(err));
expect(err).assertFail();
})
for (let i = 0; i < 100; i++) {
let PredicatesDelete = new dataSharePredicates.DataSharePredicates();
PredicatesDelete.inKeys(["testkey" + Delete]);
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete).then((data) => {
console.info("TestDataShare going delete " + Delete + "=" + data);
expect(DataProcessResultOne).assertEqual(data);
})
Delete++;
}
done();
} catch (err) {
console.info("DataShareCombinationKvdb0106 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareNotifyChangeKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : NotifyChange
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareNotifyChangeKvdb0101', 1, async function (done) {
try {
let Count = 1;
globalThis.helper.on("dataChange", uri, function (err,data) {
if (Count < 4) {
console.info("TestDataShare notifyChange err = " + err);
console.info("TestDataShare notifyChange data = " + data);
expect(true).assertEqual(err == null);
expect(true).assertEqual(data == null);
Count = Count + 1;
} else {
console.info("TestDataShare notifyChange err = " + err);
console.info("TestDataShare notifyChange data = " + data);
expect(true).assertEqual(err == null);
expect(true).assertEqual(data == null);
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare off");
done();
}
})
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
globalThis.helper.notifyChange(uri, notifyChangeCallback);
}).catch((err) => {
console.info("DataShareNotifyChangeKvdb0101 insert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
globalThis.helper.notifyChange(uri, notifyChangeCallback);
}).catch((err) => {
console.info("DataShareNotifyChangeKvdb0101 update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.helper.notifyChange(uri, notifyChangeCallback);
}).catch((err) => {
console.info("DataShareNotifyChangeKvdb0101 query err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
globalThis.helper.notifyChange(uri, notifyChangeCallback);
}).catch((err) => {
console.info("DataShareNotifyChangeKvdb0101 delete err" + JSON.stringify(err));
expect(err).assertFail();
})
} catch (err) {
console.info("DataShareNotifyChangeKvdb0101 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports ResultSet
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareResultSetKvdb0101', 1, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
}).catch((err) => {
console.info("DataShareResultSetKvdb0101 batchInsert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, ResultSetEqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
expect(true).assertEqual(globalThis.ResultSet.goToFirstRow());
expect(true).assertEqual(globalThis.ResultSet.goToNextRow());
expect(true).assertEqual(globalThis.ResultSet.goToLastRow());
expect(true).assertEqual(globalThis.ResultSet.goToPreviousRow());
expect(true).assertEqual(globalThis.ResultSet.goTo(column));
expect(true).assertEqual(globalThis.ResultSet.goToRow(column));
globalThis.ResultSet.close()
}).catch((err) => {
console.info("DataShareResultSetKvdb0101 query err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete0 = " + data);
}).catch((err) => {
console.info("DataShareResultSetKvdb0101 delete0 err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete1 = " + data);
done();
}).catch((err) => {
console.info("DataShareResultSetKvdb0101 delete1 err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareResultSetKvdb001 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0102
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports ResultSet
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareResultSetKvdb0102', 1, async function (done) {
try {
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
expect(false).assertEqual(globalThis.ResultSet.goToFirstRow());
expect(false).assertEqual(globalThis.ResultSet.goToNextRow());
expect(false).assertEqual(globalThis.ResultSet.goToLastRow());
expect(false).assertEqual(globalThis.ResultSet.goToPreviousRow());
expect(false).assertEqual(globalThis.ResultSet.goTo(column));
expect(false).assertEqual(globalThis.ResultSet.goToRow(column));
done();
}).catch((err) => {
console.info("DataShareResultSetKvdb0102 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareResultSetKvdb0102 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0103
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports ResultSet
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareResultSetKvdb0103', 1, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
}).catch((err) => {
console.info("DataShareResultSetKvdb0103 insert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
expect(DataProcessResultThree).assertEqual(globalThis.ResultSet.getDataType(1));
}).catch((err) => {
console.info("DataShareResultSetKvdb0103 query err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going deleteall = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareResultSetKvdb0103 deleteall err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareResultSetKvdb0103 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetKvdb0108
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports ResultSet
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataShareResultSetKvdb0108', 1, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
}).catch((err) => {
console.info("DataShareResultSetKvdb0108 insert err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(DataProcessResultOne).assertEqual(globalThis.ResultSet.getColumnIndex(IndexValue));
expect(IndexValue).assertEqual(globalThis.ResultSet.getColumnName(DataProcessResultOne));
}).catch((err) => {
console.info("DataShareResultSetKvdb0108 query err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going deleteall = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareResultSetKvdb0108 deleteall err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareResultSetKvdb0108 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import dataShare from '@ohos.data.dataShare'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import * as pubfun from './DataSharePublicfunction_Promise'
//CreateDataShareHelper
let uri = "datashare:///com.samples.datasharekvtest.DataShare";
//InsertValuesBucket
let Insert = { "name": "sun", "age": 1, "isStudent": true };
//UpdateValuesBucket
let Update = { "name": "sun", "age": 1, "isStudent": false };
//Predicates
let EqualTo = new dataSharePredicates.DataSharePredicates();
EqualTo.equalTo("$.age", 1);
let NotEqualTo = new dataSharePredicates.DataSharePredicates();
NotEqualTo.notEqualTo("$.age", 2);
let GreaterThan = new dataSharePredicates.DataSharePredicates();
GreaterThan.greaterThan("$.age", 0);
let LessThan = new dataSharePredicates.DataSharePredicates();
LessThan.lessThan("$.age", 3);
let GreaterThanOrEqualTo = new dataSharePredicates.DataSharePredicates();
GreaterThanOrEqualTo.greaterThanOrEqualTo("$.age", 1);
let LessThanOrEqualTo = new dataSharePredicates.DataSharePredicates();
LessThanOrEqualTo.lessThanOrEqualTo("$.age", 1);
let IsNull = new dataSharePredicates.DataSharePredicates();
IsNull.isNull("$.age");
let IsNotNull = new dataSharePredicates.DataSharePredicates();
IsNotNull.isNotNull("$.age");
let In = new dataSharePredicates.DataSharePredicates();
In.in("$.age", [1]);
let NotIn = new dataSharePredicates.DataSharePredicates();
NotIn.notIn("$.age", [2]);
let Like = new dataSharePredicates.DataSharePredicates();
Like.like("$.name", "%u%");
let UnLike = new dataSharePredicates.DataSharePredicates();
UnLike.unlike("$.name", "%i%");
let And = new dataSharePredicates.DataSharePredicates();
And.notEqualTo("$.age", 2).and().equalTo("$.age", 1);
let Or = new dataSharePredicates.DataSharePredicates();
Or.equalTo("$.isStudent", true).or().equalTo("$.age", 1);
let OrderByAsc = new dataSharePredicates.DataSharePredicates();
OrderByAsc.orderByAsc("$.age");
let OrderByDesc = new dataSharePredicates.DataSharePredicates();
OrderByDesc.orderByDesc("$.age");
let Limit = new dataSharePredicates.DataSharePredicates();
Limit.equalTo("$.age", 1).limit(1,0);
let InKeys = new dataSharePredicates.DataSharePredicates();
InKeys.inKeys(["testkey0"]);
let PrefixKey = new dataSharePredicates.DataSharePredicates();
PrefixKey.prefixKey("testkey");
let PredicatesDelete = new dataSharePredicates.DataSharePredicates();
PredicatesDelete.inKeys(["testkey0"]);
//Return Expect
const DataProcessResultOne = 1;
const ResultSetUpdate = { "name": "sun", "age": 1, "isStudent": "false" };
const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" };
export default function DataSharePredicatesKvdb() {
describe('DataSharePredicatesKvdb', function () {
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('sleep finished');
}, time);
})
}
beforeAll(async () => {
await globalThis.connectDataShareExtAbility();
await sleep(2000);
console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
})
beforeEach(async function () {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going Insert = " + data);
})
})
afterEach(async function () {
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete).then((data) => {
console.info("TestDataShare going deleteall = " + data);
})
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0101', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0101 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0101 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0101 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0102
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0102', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, NotEqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0102 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, NotEqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0102 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0102 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0103
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0103', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, GreaterThan, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0103 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, GreaterThan, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0103 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0103 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0104
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0104', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, LessThan, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0104 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, LessThan, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0104 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0104 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0105
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0105', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, GreaterThanOrEqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0105 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, GreaterThanOrEqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0105 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0105 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0106
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0106', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, LessThanOrEqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0106 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, LessThanOrEqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0106 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb006 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0107
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0107', 1, async function (done) {
try {
await pubfun.publicquery(globalThis.helper, uri, IsNull, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
expect(false).assertEqual(globalThis.ResultSet.goToLastRow());
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0107 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0107 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0108
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0108', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, IsNotNull, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0108 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, IsNotNull, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0108 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0108 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0109
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0109', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, In, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0109 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, In, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0109 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0109 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0110
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0110', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, NotIn, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0110 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, NotIn, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0110 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0110 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0111
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0111', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, Like, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0111 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, Like, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0111 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0111 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0112
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0112', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, UnLike, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0112 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, Like, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0112 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0112 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0113
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0113', 1, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, And, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0113 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, And, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0113 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0113 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0114
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0114', 0, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, Or, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0114 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, Or, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0114 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0114 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0115
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0115', 1, async function (done) {
try {
await pubfun.publicquery(globalThis.helper, uri, OrderByAsc, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0115 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0115 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0116
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0116', 1, async function (done) {
try {
await pubfun.publicquery(globalThis.helper, uri, OrderByAsc, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0116 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0116 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0118
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0118', 0, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, InKeys, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0118 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, InKeys, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0118 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0118 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesKvdb0119
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : DataShare Supports Predicates
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
it('DataSharePredicatesKvdb0119', 0, async function (done) {
try {
await pubfun.publicupdate(globalThis.helper, uri, PrefixKey, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharePredicatesKvdb0118 Update err" + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicquery(globalThis.helper, uri, PrefixKey, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetUpdate)).assertEqual(globalThis.ResultSet.getString(1));
done();
}).catch((err) => {
console.info("DataSharePredicatesKvdb0119 query err" + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataSharePredicatesKvdb0119 fail" + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import dataShare from '@ohos.data.dataShare'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import * as pubfun from './DataSharePublicfunction_Callback'
//CreateDataShareHelper
let uri = ("datashare:///com.samples.datasharekvtest.DataShare");
//InsertValuesBucket
let Insert = { "name": "sun", "age": 1, "isStudent": true };
let BatchInsert = new Array(
{ "name": "sun", "age": 1, "isStudent": true },
{ "name": "sunn", "age": 10, "isStudent": false });
//UpdateValuesBucket
let Update = { "name": "suns", "age": 2, "isStudent": false };
//Predicates
let EqualTo = new dataSharePredicates.DataSharePredicates();
EqualTo.equalTo("$.age", 1);
let PredicatesDelete0 = new dataSharePredicates.DataSharePredicates();
PredicatesDelete0.inKeys(["testkey0"]);
let PredicatesDelete1 = new dataSharePredicates.DataSharePredicates();
PredicatesDelete1.inKeys(["testkey1"]);
//Return Expect
const DataProcessResultOne = 1;
const GetType = "image";
const GetFileTypes = new Array("type01", "type02", "type03");
const Normalize = "normalize+" + uri;
const Denormalize = "denormalize+" + uri;
const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" };
const Mode = "rwt";
function onChangeNotify() {
console.info("===>onChangeNotify===>");
};
export default function DataShareSingleKvdb_Callback() {
describe('DataShareSingleKvdb_Callback', function () {
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('sleep finished');
}, time);
})
}
beforeAll(async () => {
await globalThis.connectDataShareExtAbility();
await sleep(2000);
console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Insert All type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareInsertKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareInsertKvdb0101 fail err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareInsertKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Update All type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareUpdateKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareUpdateKvdb0101 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareUpdateKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Query All type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareQueryKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareQueryKvdb0101 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareQueryKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Delete number type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareDeleteKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareDeleteKvdb0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareDeleteKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : BatchInsert data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0101', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharebatchKvdb001 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataSharebatchKvdb001 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0102
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Update data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0102', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareBatchKvdb0102 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareBatchKvdb0102 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0103
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Query data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0103', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareBatchKvdb003 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareBatchKvdb003 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0104
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Delete data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0104', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareBatchKvdb0104 delete 0 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareBatchKvdb0104 delete 1 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareBatchKvdb0104 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareGetType0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support GetType function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareGetType0101', 0, async function (done) {
try {
await pubfun.publicgetType(globalThis.helper, uri).then((data) => {
console.info("TestDataShare going getType = " + data);
expect(GetType).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareGetType0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareGetType0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareGetFileTypes0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support GetFileTypes function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareGetFileTypes0101', 0, async function (done) {
try {
await pubfun.publicgetFileTypes(globalThis.helper, uri, "image/*").then((data) => {
console.info("TestDataShare going getFileTypes = " + data);
expect(JSON.stringify(GetFileTypes)).assertEqual(JSON.stringify(data));
done();
}).catch((err) => {
console.info("DataShareGetFileTypes0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareGetFileTypes0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareNormalizeUri0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support NormalizeUri function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareNormalizeUri0101', 0, async function (done) {
try {
await pubfun.publicnormalizeUri(globalThis.helper, uri).then((data) => {
console.info("TestDataShare going NormalizeUri = " + data);
expect(Normalize).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareNormalizeUri0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareNormalizeUri0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareDenormalizeUri0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support DenormalizeUri function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareDenormalizeUri0101', 0, async function (done) {
try {
await pubfun.publicdenormalizeUri(globalThis.helper, uri).then((data) => {
console.info("TestDataShare going denormalizeUri = " + data);
expect(Denormalize).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareDenormalizeUri0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareDenormalizeUri0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareOnKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support On function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareOnKvdb0101', 0, function () {
try {
globalThis.helper.on("dataChange", uri, onChangeNotify);
console.info("TestDataShare going on");
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare going off");
} catch (err) {
console.info("DataShareOnKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareOffKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support Off function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareOffKvdb0101', 0, function () {
try {
globalThis.helper.off("dataChange", uri, onChangeNotify);
console.info("TestDataShare going off");
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare going off");
} catch (err) {
console.info("DataShareOffKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareTypeErr0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Cannot on off operate
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('DataShareTypeErr0101', 2, function () {
try {
globalThis.helper.on(null, uri, onChangeNotify);
console.info("TestDataShare going on");
globalThis.helper.off(null, uri);
console.info("TestDataShare going off");
} catch (err) {
console.info("DataShareTypeErr0101 fail" + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_CreateDataSharePromise0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : CreateDataShareHelperPromise
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('CreateDataSharePromise0101', 0, async function (done) {
try {
await dataShare.createDataShareHelper(globalThis.abilityContext, uri).then((data) => {
console.info("TestDataShare CreateDataShareHelper = " + data);
expect(true).assertEqual(data != undefined);
done();
}).catch((err) => {
console.info("CreateDataSharePromise0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("CreateDataSharePromise0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareOpenFile0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support OpenFile function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareOpenFile0101', 0, async function (done) {
try {
await pubfun.publicopenFile(globalThis.helper, uri, Mode).then((data) => {
console.info("TestDataShare going openFile = " + data);
expect(true).assertEqual(data != null);
done();
}).catch((err) => {
console.info("DataShareOpenFile0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareOpenFile0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import dataShare from '@ohos.data.dataShare'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import * as pubfun from './DataSharePublicfunction_Promise'
//CreateDataShareHelper
let uri = ("datashare:///com.samples.datasharekvtest.DataShare");
//InsertValuesBucket
let Insert = { "name": "sun", "age": 1, "isStudent": true };
let BatchInsert = new Array(
{ "name": "sun", "age": 1, "isStudent": true },
{ "name": "sunn", "age": 10, "isStudent": false });
//UpdateValuesBucket
let Update = { "name": "suns", "age": 2, "isStudent": false };
//Predicates
let EqualTo = new dataSharePredicates.DataSharePredicates();
EqualTo.equalTo("$.age", 1);
let PredicatesDelete0 = new dataSharePredicates.DataSharePredicates();
PredicatesDelete0.inKeys(["testkey0"]);
let PredicatesDelete1 = new dataSharePredicates.DataSharePredicates();
PredicatesDelete1.inKeys(["testkey1"]);
//Return Expect
const DataProcessResultOne = 1;
const GetType = "image";
const GetFileTypes = new Array("type01", "type02", "type03");
const Normalize = "normalize+" + uri;
const Denormalize = "denormalize+" + uri;
const ResultSetInsert = { "name": "sun", "age": 1, "isStudent": "true" };
const Mode = "rwt";
function onChangeNotify() {
console.info("===>onChangeNotify===>");
};
export default function DataShareSingleKvdb_Promise() {
describe('DataShareSingleKvdb_Promise', function () {
function sleep(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('sleep finished');
}, time);
})
}
beforeAll(async () => {
await globalThis.connectDataShareExtAbility();
await sleep(2000);
console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Insert All type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareInsertKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareInsertKvdb0101 fail err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareInsertKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Update All type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareUpdateKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareUpdateKvdb0101 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareUpdateKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Query All type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareQueryKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareQueryKvdb0101 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareQueryKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Delete number type data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareDeleteKvdb0101', 0, async function (done) {
try {
await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => {
console.info("TestDataShare going insert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareDeleteKvdb0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareDeleteKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : BatchInsert data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0101', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataSharebatchKvdb001 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataSharebatchKvdb001 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0102
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Update data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0102', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicupdate(globalThis.helper, uri, EqualTo, Update).then((data) => {
console.info("TestDataShare going update = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareBatchKvdb0102 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareBatchKvdb0102 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0103
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Query data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0103', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data);
globalThis.ResultSet.goToFirstRow();
expect(JSON.stringify(ResultSetInsert)).assertEqual(globalThis.ResultSet.getString(1));
}).catch((err) => {
console.info("DataShareBatchKvdb003 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
})
} catch (err) {
console.info("DataShareBatchKvdb003 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchKvdb0104
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Delete data in Kvdb
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareBatchKvdb0104', 0, async function (done) {
try {
await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => {
console.info("TestDataShare going batchInsert = " + data);
expect(DataProcessResultOne).assertEqual(data);
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete0).then((data) => {
console.info("TestDataShare going delete 0 = " + data);
expect(DataProcessResultOne).assertEqual(data);
}).catch((err) => {
console.info("DataShareBatchKvdb0104 delete 0 err " + JSON.stringify(err));
expect(err).assertFail();
})
await pubfun.publicdelete(globalThis.helper, uri, PredicatesDelete1).then((data) => {
console.info("TestDataShare going delete 1 = " + data);
expect(DataProcessResultOne).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareBatchKvdb0104 delete 1 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareBatchKvdb0104 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareGetType0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support GetType function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareGetType0101', 0, async function (done) {
try {
await pubfun.publicgetType(globalThis.helper, uri).then((data) => {
console.info("TestDataShare going getType = " + data);
expect(GetType).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareGetType0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareGetType0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareGetFileTypes0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support GetFileTypes function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareGetFileTypes0101', 0, async function (done) {
try {
await pubfun.publicgetFileTypes(globalThis.helper, uri, "image/*").then((data) => {
console.info("TestDataShare going getFileTypes = " + data);
expect(JSON.stringify(GetFileTypes)).assertEqual(JSON.stringify(data));
done();
}).catch((err) => {
console.info("DataShareGetFileTypes0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareGetFileTypes0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareNormalizeUri0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support NormalizeUri function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareNormalizeUri0101', 0, async function (done) {
try {
await pubfun.publicnormalizeUri(globalThis.helper, uri).then((data) => {
console.info("TestDataShare going NormalizeUri = " + data);
expect(Normalize).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareNormalizeUri0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareNormalizeUri0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareDenormalizeUri0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support DenormalizeUri function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareDenormalizeUri0101', 0, async function (done) {
try {
await pubfun.publicdenormalizeUri(globalThis.helper, uri).then((data) => {
console.info("TestDataShare going denormalizeUri = " + data);
expect(Denormalize).assertEqual(data);
done();
}).catch((err) => {
console.info("DataShareDenormalizeUri0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareDenormalizeUri0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareOnKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support On function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareOnKvdb0101', 0, function () {
try {
globalThis.helper.on("dataChange", uri, onChangeNotify);
console.info("TestDataShare going on");
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare going off");
} catch (err) {
console.info("DataShareOnKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareOffKvdb0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support Off function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareOffKvdb0101', 0, function () {
try {
globalThis.helper.off("dataChange", uri, onChangeNotify);
console.info("TestDataShare going off");
globalThis.helper.off("dataChange", uri);
console.info("TestDataShare going off");
} catch (err) {
console.info("DataShareOffKvdb0101 fail " + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareTypeErr0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Cannot on off operate
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 2
*/
it('DataShareTypeErr0101', 2, function () {
try {
globalThis.helper.on(null, uri, onChangeNotify);
console.info("TestDataShare going on");
globalThis.helper.off(null, uri);
console.info("TestDataShare going off");
} catch (err) {
console.info("DataShareTypeErr0101 fail" + JSON.stringify(err));
expect(err).assertFail();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_CreateDataSharePromise0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : CreateDataShareHelperPromise
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('CreateDataSharePromise0101', 0, async function (done) {
try {
await dataShare.createDataShareHelper(globalThis.abilityContext, uri).then((data) => {
console.info("TestDataShare CreateDataShareHelper = " + data);
expect(true).assertEqual(data != undefined);
done();
}).catch((err) => {
console.info("CreateDataSharePromise0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("CreateDataSharePromise0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
/*
* @tc.number : SUB_DDM_DataShare_ETS_DataShareOpenFile0101
* @tc.name : Use getEntries get the value by mixing the string key
* @tc.desc : Support OpenFile function
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 0
*/
it('DataShareOpenFile0101', 0, async function (done) {
try {
await pubfun.publicopenFile(globalThis.helper, uri, Mode).then((data) => {
console.info("TestDataShare going openFile = " + data);
expect(true).assertEqual(data != null);
done();
}).catch((err) => {
console.info("DataShareOpenFile0101 err " + JSON.stringify(err));
expect(err).assertFail();
done();
})
} catch (err) {
console.info("DataShareOpenFile0101 fail " + JSON.stringify(err));
expect(err).assertFail();
done();
}
})
})
}
\ No newline at end of file
/*
* 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 DataShareSingleKvdb_Callback from "./DataShareSingleKvdb_Callback"
import DataShareSingleKvdb_Promise from "./DataShareSingleKvdb_Promise"
import DataSharePredicatesKvdb from "./DataSharePredicatesKvdb"
import DataShareCombinationKvdb from "./DataShareCombinationKvdb"
export default function testsuite() {
DataShareSingleKvdb_Callback()
DataShareSingleKvdb_Promise()
DataSharePredicatesKvdb()
DataShareCombinationKvdb()
}
\ No newline at end of file
{
"module": {
"package": "com.example.myapplication2",
"name": "entry",
"mainAbility": "com.example.myapplication2.MainAbility",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "com.example.myapplication2.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "ActsDataShareKvTest"
}
]
}
\ No newline at end of file
......@@ -23,6 +23,8 @@ ohos_js_hap_suite("ActsDataShareRdbTest") {
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsDataShareRdbTest"
subsystem_name = "distributeddatamgr"
part_name = "data_share"
}
ohos_app_scope("dataShareRdb_app_profile") {
......
/*
* 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 Ability from '@ohos.application.Ability'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.loadContent("TestAbility/pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
};
\ No newline at end of file
/*
* 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 router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
......@@ -293,7 +293,7 @@ export default function DataShareCombinationRdb() {
* @tc.size : MediumTest
* @tc.type : Function
* @tc.level : Level 1
*/
*/
it('DataShareNotifyChangeRdb0101', 1, async function (done) {
try {
let Count = 1;
......
/*
* 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 file from '@system.file';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import dataShare from '@ohos.data.dataShare'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import DataShareResultSet from '@ohos.data.DataShareResultSet'
//insert公共方法
function publicinsert(helper, uri, DataShareValuesBucket) {
return new Promise(function (resolve, reject) {
helper.insert(uri, DataShareValuesBucket, (err, data) => {
console.info("[ttt] [TestDataShare] publicinsert Callback=" + JSON.stringify(data));
globalThis.insertdata = data;
if (err) {
console.info("test insert err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//delete公共方法
async function publicdelete(helper, uri, DataSharePredicates) {
return new Promise(function (resolve, reject) {
console.info("[ttt] [DataShareTest] <<XTS>> 12345648564185645314");
helper.delete(uri, DataSharePredicates, (err, data) => {
console.info("[ttt] [TestDataShare] publicdelete Callback=" + JSON.stringify(data));
if (err) {
console.info("test delete err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//query公共方法
function publicquery(helper, uri, DataSharePredicates, columns) {
return new Promise(function (resolve, reject) {
helper.query(uri, DataSharePredicates, columns, (err, data) => {
console.info("[ttt] [TestDataShare] publicquery Callback=" + JSON.stringify(data));
globalThis.ResultSet = data;
if (err) {
console.info("test query err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//update公共方法
function publicupdate(helper, uri, DataSharePredicates, DataShareValuesBucket) {
return new Promise(function (resolve, reject) {
helper.update(uri, DataSharePredicates, DataShareValuesBucket, (err, data) => {
console.info("[ttt] [TestDataShare] publicupdate Callback=" + JSON.stringify(data));
if (err) {
console.info("test update err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//batchInsert公共方法
function publicbatchInsert(helper, uri, DataShareValuesBucket) {
return new Promise(function (resolve, reject) {
helper.batchInsert(uri, DataShareValuesBucket, (err, data) => {
console.info("[ttt] [TestDataShare] publicbatchInsert Callback=" + JSON.stringify(data));
if (err) {
console.info("test batchInsert err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//getType公共方法
function publicgetType(helper, uri) {
return new Promise(function (resolve, reject) {
helper.getType(uri, (err, data) => {
console.info("[ttt] [TestDataShare] publicgetType Callback=" + JSON.stringify(data));
if (err) {
console.info("test getType err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//getFileTypes公共方法
function publicgetFileTypes(helper, uri, mimeTypeFilter) {
return new Promise(function (resolve, reject) {
helper.getFileTypes(uri, mimeTypeFilter, (err, data) => {
console.info("[ttt] [TestDataShare] publicgetFileTypes Callback=" + JSON.stringify(data));
if (err) {
console.info("test getFileTypes err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//normalizeUri公共方法
function publicnormalizeUri(helper, uri) {
return new Promise(function (resolve, reject) {
helper.normalizeUri(uri, (err, data) => {
console.info("[ttt] [TestDataShare] publicnormalizeUri Callback=" + JSON.stringify(data));
if (err) {
console.info("test normalizeUri err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//denormalizeUri公共方法
function publicdenormalizeUri(helper, uri) {
return new Promise(function (resolve, reject) {
helper.denormalizeUri(uri, (err, data) => {
console.info("[ttt] [TestDataShare] publicdenormalizeUri Callback=" + JSON.stringify(data));
if (err) {
console.info("test denormalizeUri err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
//denormalizeUri公共方法
function publicopenFile(helper, uri, mode) {
return new Promise(function (resolve, reject) {
helper.denormalizeUri(uri, mode, (err, data) => {
console.info("[ttt] [TestDataShare] publicopenFile Callback=" + JSON.stringify(data));
if (err) {
console.info("test openFile err information: " + JSON.stringify(err));
reject(err);
} else {
resolve(data);
}
})
})
}
export { publicinsert, publicdelete, publicquery, publicupdate, publicbatchInsert, publicgetType, publicgetFileTypes,
publicnormalizeUri, publicdenormalizeUri, publicopenFile
}
\ No newline at end of file
/*
* 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 file from '@system.file';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from "@ohos/hypium"
import dataShare from '@ohos.data.dataShare'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import DataShareResultSet from '@ohos.data.DataShareResultSet'
//insert公共方法
function publicinsert(helper, uri, DataShareValuesBucket) {
return new Promise(function (resolve, reject) {
helper.insert(uri, DataShareValuesBucket).then((data) => {
console.info("[ttt] [TestDataShare] publicinsert Callback=" + JSON.stringify(data));
globalThis.insertdata = data;
resolve(data);
}).catch((err) => {
console.info("test insert err information: " + JSON.stringify(err));
reject(err);
})
})
}
//delete公共方法
function publicdelete(helper, uri, DataSharePredicates) {
return new Promise(function (resolve, reject) {
helper.delete(uri, DataSharePredicates).then((data) => {
console.info("[ttt] [TestDataShare] publicdelete Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test delete err information: " + JSON.stringify(err));
reject(err);
})
})
}
//query公共方法
function publicquery(helper, uri, columns, DataSharePredicates) {
return new Promise(function (resolve, reject) {
helper.query(uri, columns, DataSharePredicates).then((data) => {
console.info("[ttt] [TestDataShare] publicquery Callback=" + JSON.stringify(data));
globalThis.ResultSet = data;
resolve(data);
}).catch((err) => {
console.info("test query err information: " + JSON.stringify(err));
reject(err);
})
})
}
//update公共方法
function publicupdate(helper, uri, DataShareValuesBucket, DataSharePredicates) {
return new Promise(function (resolve, reject) {
helper.update(uri, DataShareValuesBucket, DataSharePredicates).then((data) => {
console.info("[ttt] [TestDataShare] publicupdate Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test update err information: " + JSON.stringify(err));
reject(err);
})
})
}
//batchInsert公共方法
function publicbatchInsert(helper, uri, DataShareValuesBucket) {
return new Promise(function (resolve, reject) {
helper.batchInsert(uri, DataShareValuesBucket).then((data) => {
console.info("[ttt] [TestDataShare] publicbatchInsert Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test batchInsert err information: " + JSON.stringify(err));
reject(err);
})
})
}
//getType公共方法
function publicgetType(helper, uri) {
return new Promise(function (resolve, reject) {
helper.getType(uri).then((data) => {
console.info("[ttt] [TestDataShare] publicgetType Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test getType err information: " + JSON.stringify(err));
reject(err);
})
})
}
//getFileTypes公共方法
function publicgetFileTypes(helper, uri, mimeTypeFilter) {
return new Promise(function (resolve, reject) {
helper.getFileTypes(uri, mimeTypeFilter).then((data) => {
console.info("[ttt] [TestDataShare] publicgetFileTypes Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test getFileTypes err information: " + JSON.stringify(err));
reject(err);
})
})
}
//normalizeUri公共方法
function publicnormalizeUri(helper, uri) {
return new Promise(function (resolve, reject) {
helper.normalizeUri(uri).then((data) => {
console.info("[ttt] [TestDataShare] publicnormalizeUri Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test normalizeUri err information: " + JSON.stringify(err));
reject(err);
})
})
}
//denormalizeUri公共方法
function publicdenormalizeUri(helper, uri) {
return new Promise(function (resolve, reject) {
helper.denormalizeUri(uri).then((data) => {
console.info("[ttt] [TestDataShare] publicdenormalizeUri Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test denormalizeUri err information: " + JSON.stringify(err));
reject(err);
})
})
}
//denormalizeUri公共方法
function publicopenFile(helper, uri, mode) {
return new Promise(function (resolve, reject) {
helper.openFile(uri, mode).then((data) => {
console.info("[ttt] [TestDataShare] publicopenFile Callback=" + JSON.stringify(data));
resolve(data);
}).catch((err) => {
console.info("test openFile err information: " + JSON.stringify(err));
reject(err);
})
})
}
export { publicinsert, publicdelete, publicquery, publicupdate, publicbatchInsert, publicgetType, publicgetFileTypes,
publicnormalizeUri, publicdenormalizeUri, publicopenFile
}
\ No newline at end of file
......@@ -13,21 +13,23 @@
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("appdatamgr_js_test") {
ohos_js_hap_suite("dataShare_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":appdatamgr_js_assets",
":appdatamgr_resources",
":dataShare_js_assets",
":dataShare_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsAppdatamagrJsTest"
hap_name = "ActsDataShareJsTest"
subsystem_name = "distributeddatamgr"
part_name = "data_share"
}
ohos_js_assets("appdatamgr_js_assets") {
ohos_js_assets("dataShare_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("appdatamgr_resources") {
ohos_resources("dataShare_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
......@@ -4,13 +4,13 @@
"type": "OHJSUnitTest",
"test-timeout": "1000000",
"shell-timeout": "1000000",
"bundle-name": "ohos.acts.appdatamgrjstest",
"package-name": "ohos.acts.appdatamgrjstest"
"bundle-name": "ohos.acts.dataSharejstest",
"package-name": "ohos.acts.dataSharejstest"
},
"kits": [
{
"test-file-name": [
"ActsAppdatamagrJsTest.hap"
"ActsDataShareJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
{
"app": {
"bundleName": "ohos.acts.appdatamgrjstest",
"bundleName": "ohos.acts.dataSharejstest",
"vendor": "example",
"version": {
"code": 1,
......@@ -13,7 +13,7 @@
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.appdatamgrjstest",
"package": "ohos.acts.dataSharejstest",
"name": ".entry",
"deviceType": [
"phone"
......
/*
* 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 dataAbilityPredicatesTest from './DataAbilityPredicatesJsunit.test.js'
import rdbStoreDataSharePredicatesTest from './RdbStoreDataShareJsunit.test.js'
export default function testsuite() {
dataAbilityPredicatesTest()
rdbStoreDataSharePredicatesTest()
}
{
"app": {
"bundleName": "com.samples.datasharekvtest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"debug": false,
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
{
"string": [
{
"name": "app_name",
"value": "ActsKvServiceHap"
}
]
}
# 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("//test/xts/tools/build/suite.gni")
ohos_hap_assist_suite("ActsKvServiceHap") {
hap_profile = "./entry/src/main/module.json"
hap_name = "ActsKvServiceHap"
subsystem_name = "distributeddatamgr"
part_name = "data_share"
js_build_mode = "debug"
deps = [
":kvService_js_assets",
":kvService_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
}
ohos_app_scope("dataShareKv_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("kvService_js_assets") {
source_dir = "./entry/src/main/ets"
}
ohos_resources("kvService_resources") {
sources = [ "./entry/src/main/resources" ]
deps = [ ":dataShareKv_app_profile" ]
hap_profile = "./entry/src/main/module.json"
}
/*
* 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 AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[ttt] [DataShareTest] MyAbilityStage onCreate");
}
}
\ No newline at end of file
/*
* 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 Extension from '@ohos.application.DataShareExtensionAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import distributedData from '@ohos.data.distributedData';
import fileIo from '@ohos.fileio'
let kvManager;
let kvdbStore;
let kvResultSet;
let result;
const BUNDLE_NAME = 'com.samples.datasharetest';
const STORE_ID = 'storeId';
export default class DataShareExtAbility extends Extension {
private rdbStore_;
private kvdbStore_;
onCreate(want,callback) {
console.info('[ttt] [DataShareTest] <<Provider>> DataShareExtAbility onCreate, want:' + want.abilityName);
let mKVMgrConfig = {
userInfo : {
userId : '0',
userType : distributedData.UserType.SAME_USER_ID
},
bundleName: BUNDLE_NAME,
context : this.context
}
var options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : distributedData.KVStoreType.SINGLE_VERSION,
schema : {},
securityLevel : distributedData.SecurityLevel.NO_LEVEL,
}
let name = new distributedData.FieldNode('name');
name.type = distributedData.ValueType.STRING;
name.nullable = false;
name.default = 'name';
let age = new distributedData.FieldNode('age');
age.type = distributedData.ValueType.INTEGER;
age.nullable = false;
age.default = '0';
let isStudent = new distributedData.FieldNode('isStudent');
isStudent.type = distributedData.ValueType.STRING;
isStudent.nullable = false;
isStudent.default = 'false';
let schema1 = new distributedData.Schema();
schema1.root.appendChild(name);
schema1.root.appendChild(age);
schema1.root.appendChild(isStudent);
schema1.indexes = ['$.name', "$.age", "$.isStudent"];
// options.kvStoreType = distributedData.KVStoreType.DEVICE_COLLABORATION;
options.schema = schema1;
distributedData.createKVManager(mKVMgrConfig, function (err, manager) {
if (err) {
console.info("[ttt] [DataShareTest] <<Provider>> createKVManager err: " + err);
return;
}
console.info("[ttt] [DataShareTest] <<Provider>> createKVManager success");
kvManager = manager;
console.info('[ttt] [DataShareTest] <<Provider>> createKVManager kvManager = ' + kvManager);
kvManager.getKVStore(STORE_ID, options, function (err, store) {
if (err) {
console.info("[ttt] [DataShareTest] <<Provider>> getKVStore err: " + err);
return;
}
console.info("[ttt] [DataShareTest] <<Provider>> getKVStore success");
kvdbStore = store;
console.info('[ttt] [DataShareTest] <<Provider>> createKVManager kvdbStore = ' + kvdbStore);
});
callback();
});
result = this.context.cacheDir + '/datashare.txt'
console.info('[ttt] [DataAbilityTest] <<Provider>> resultpath = ' + result);
}
getFileTypes(uri: string, mimeTypeFilter: string, callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [getFileTypes] enter');
let ret = new Array("type01", "type02", "type03");
console.info('[ttt] [DataShareTest] <<Provider>> [getFileTypes] leave, ret:' + ret);
let err = {"code":2};
callback(err,ret);
return ret;
}
async insert(uri, value, callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [insert] enterkvdb');
if (value == null) {
console.info('[ttt] [DataShareTest] <<Provider>> [insert] invalid valueBuckets');
return;
}
console.info('[ttt] [DataShareTest] <<Provider>> [insert] kvdb value = ' + JSON.stringify(value));
let vbArr = new Array();
let insertBucket = {"name":value.name, "age":value.age, "isStudent":String(value.isStudent)}
console.info('[ttt] [DataShareTest] <<Provider>> [insert] kvdb insertBucket = ' + JSON.stringify(insertBucket));
vbArr.push({
"key":"testkey0",
"value": JSON.stringify(insertBucket)
});
console.info('[ttt] [DataShareTest] <<Provider>> [insert] kvdb vbArr = ' + JSON.stringify(vbArr) + "?????????????");
kvdbStore.putBatch(vbArr, function (err,data) {
if (err != undefined) {
console.info("[ttt] [DataShareTest] <<Provider>> [insert kvdb put] callback err: " + err);
if (callback != undefined) {
callback(-1,-1);
}
}else{
if (callback != undefined) {
callback(0,1);
}
}
console.info("[ttt] [DataShareTest] <<Provider>> [insert kvdb put] callback data:" + JSON.stringify(data));
});
console.info('[ttt] [DataShareTest] <<Provider>> [insert] leave');
}
update(uri, predicates, value, callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [update] enter');
console.info('[ttt] [DataShareTest] <<Provider>> [update] value = ' + JSON.stringify(value));
console.info('[ttt] [DataShareTest] <<Provider>> [update] predicates = ' + predicates);
if (predicates == null || predicates == undefined) {
console.info('[ttt] [DataShareTest] <<Provider>> [update] invalid predicates');
return;
}
let vbArr = new Array();
let keyName = "testkey0";
let updateBucket = {"name":value.name, "age":value.age, "isStudent":String(value.isStudent)}
// let da = new dataShare.DataSharePredicates();
// da.notEqualTo("$.name", "789");
// kvdbStore.getResultSet(da, function (err, data) {
// if (err != undefined) {
// console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb get] callback err: " + err);
// return;
// }
// console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb get] callback data:" + JSON.stringify(data));
// if (callback != undefined) {
// callback(err, data);
// }
// })
console.info('[ttt] [DataShareTest] <<Provider>> [update] updateBucket = ' + JSON.stringify(updateBucket));
console.info('[ttt] [DataShareTest] <<Provider>> [update] keyName = ' + keyName);
vbArr.push({
"key": keyName,
"value": JSON.stringify(updateBucket)
});
console.info('[ttt] [DataShareTest] <<Provider>> [update] vbArr = ' + JSON.stringify(vbArr));
kvdbStore.putBatch(vbArr, function (err,data) {
if (err != undefined) {
console.info("[ttt] [DataShareTest] <<Provider>> [update kvdb put] callback err: " + JSON.stringify(err));
if (callback != undefined) {
callback(-1,-1);
}
}else{
if (callback != undefined) {
callback(0,1);
}
}
console.info("[ttt] [DataShareTest] <<Provider>> [update kvdb put] callback data:" + JSON.stringify(data));
});
console.info('[ttt] [DataShareTest] <<Provider>> [update] leave');
}
delete(uri, predicates, callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [delete] enter');
if (predicates == null || predicates == undefined) {
console.info('[ttt] [DataShareTest] <<Provider>> [delete] invalid predicates');
return;
}
kvdbStore.delete(predicates, function(err, data) {
if (err != undefined) {
console.info("[ttt] [DataShareTest] <<Provider>> [delete kvdb] callback err: " + err);
if (callback != undefined) {
callback(-1, -1);
}
}else {
console.info("[ttt] [DataShareTest] <<Provider>> [delete kvdb] callback data:" + JSON.stringify(data));
if (callback != undefined) {
callback(0, 1);
}
}
});
console.info('[ttt] [DataShareTest] <<Provider>> [delete] leave');
}
query(uri, predicates, columns, callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [query] enter');
if (predicates == null || predicates == undefined) {
console.info('[ttt] [DataShareTest] <<Provider>> [query] invalid predicates');
}
console.info("[ttt] [DataShareTest] <<Provider>> [query] getDADADADADADADA!!!")
if(kvResultSet != null || kvResultSet != undefined){
kvdbStore.closeResultSet(kvResultSet,function (err, data) {
if (err != undefined) {
console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb closeResultSet] callback err: " + err);
return;
}
console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb closeResultSet] callback data:" + JSON.stringify(data));
})
}
console.info("[ttt] [DataShareTest] <<Provider>> [RPF66666] " );
// let da = new dataSharePredicates.DataSharePredicates();
// da.notEqualTo("$.name", "789");
// da.limit(1, 0);
// var query = new distributedData.Query();
// query.notEqualTo("$.name", 3);
// query.limit(1, 0);
kvdbStore.getResultSet(predicates, function (err, data) {
if (err != undefined) {
console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb get] callback err: " + err);
return;
}
kvResultSet = data;
console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb get] getCount = " + kvResultSet.getCount())
console.info("[ttt] [DataShareTest] <<Provider>> [query kvdb get] callback data:" + JSON.stringify(data));
if (callback != undefined) {
callback(err, data);
}
})
console.info('[ttt] [DataShareTest] <<Provider>> [query] leave');
}
getType(uri: string,callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [getType] enter');
let ret = "image";
console.info('[ttt] [DataShareTest] <<Provider>> [getType] leave, ret:' + ret);
let err = {"code":2};
callback(err,ret);
return ret;
}
batchInsert(uri, valueBuckets, callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] enter');
if (valueBuckets == null || valueBuckets.length == undefined) {
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] invalid valueBuckets');
return;
}
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] valueBuckets.length:' + valueBuckets.length);
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] valueBuckets.isStudent :' + JSON.stringify(valueBuckets[0].isStudent));
let vbArr = new Array();
let batchInsertBucket = new Array();
let num = 0;
for(let i = 0; i < valueBuckets.length; i++) {
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] valueBuckets.boolean :' + JSON.stringify(valueBuckets[i].isStudent));
batchInsertBucket[i] = {"name":valueBuckets[i].name, "age":valueBuckets[i].age, "isStudent":String(valueBuckets[i].isStudent)}
vbArr.push({
"key":"testkey"+num,
"value": JSON.stringify(batchInsertBucket[i])
});
num++;
}
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] valueBuckets :' + JSON.stringify(batchInsertBucket));
kvdbStore.putBatch(vbArr, function(err, data) {
if (err != undefined) {
console.info("[ttt] [DataShareTest] <<Provider>> [batchInsert kvdb] callback err: " + err);
if (callback != undefined) {
callback(-1, -1);
}
return;
}else{
if (callback != undefined) {
callback(0,1);
}
}
console.info("[ttt] [DataShareTest] <<Provider>> [batchInsert kvdb] callback data:" + JSON.stringify(data));
});
console.info('[ttt] [DataShareTest] <<Provider>> [batchInsert] leave');
}
openFile(uri: string, mode: string, callback) {
console.info('[ttt] [DataAbilityTest] <<Provider>> DataAbility openFile in');
fileIo.open(result, 0o2 | 0o100, 0o666, function(err, fd) {
if(err) {
console.info('[ttt] [DataAbilityTest] <<Provider>> OpenFile err = ' + err);
console.info('[ttt] [DataAbilityTest] <<Provider>> OpenFile err = ' + JSON.stringify(err));
}
console.log('[ttt] [DataAbilityTest] <<Provider>> EtsFileIo fd =' + fd);
let num = fileIo.writeSync(fd, "this is a boring test of DataShare");
console.info("[ttt] [DataAbillityTest] <<Provider>> WriteSync length = " + num);
console.info("[ttt] [DataAbillityTest] <<Provider>> WriteSync fd = " + fd);
callback(err,fd);
})
}
normalizeUri(uri: string,callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [normalizeUri] enter');
let ret = "normalize+" + uri;
console.info('[ttt] [DataShareTest] <<Provider>> [normalizeUri] leave, ret:' + ret);
let err = {"code":2};
console.info('[ttt] [DataShareTest] <<Provider>> [normalizeUri] enter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
callback(err,ret);
console.info('[ttt] [DataShareTest] <<Provider>> [normalizeUri] leave!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
}
denormalizeUri(uri: string,callback) {
console.info('[ttt] [DataShareTest] <<Provider>> [denormalizeUri] enter');
let ret = "denormalize+" + uri;
console.info('[ttt] [DataShareTest] <<Provider>> [denormalizeUri] leave, ret:' + ret);
let err = {"code":2};
callback(err,ret);
return ret;
}
};
\ No newline at end of file
/*
* 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 Ability from '@ohos.application.Ability'
import ability_particleAbility from '@ohos.ability.particleAbility'
import dataSharePredicates from '@ohos.data.dataSharePredicates'
import dataShare from '@ohos.data.dataShare'
import dataAbility from '@ohos.data.dataAbility'
import rdb from '@ohos.data.rdb';
import rpc from "@ohos.rpc";
import distributedData from '@ohos.data.distributedData';
let kvManager;
let kvdbStore;
var seConnect = {
onConnect:function (elementName, proxy) {
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect called.");
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect elementName = " + elementName);
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect proxy = " + proxy);
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
let option = new rpc.MessageOption();
data.writeInterfaceToken("connect-test");
data.writeInt(111);
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect sendRequest.");
proxy.sendRequest(1, data, reply, option)
.then(function (result) {
if (result.errCode === 0) {
// let msg = reply.readString();
let msg = result.reply.readInt();
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect reply msg: " + msg);
} else {
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest failed, errCode: " + result.errCode);
}
// callback没有返回值,默认返回undefined
}).catch(function (e) {
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest got exception: " + e);
}).finally (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest ends, reclaim parcel");
data.reclaim();
reply.reclaim();
})
},
onDisconnect:function (elementName) {
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect onDisconnect");
},
onFailed:function (code) {
console.info("[ttt] [DataShareTest] <<Consumer>> seConnect onFailed");
}
};
let dseProxy = 0;
let dseUri = ("datashare:///com.samples.datasharetest.DataShare");
var dseConnect = {
onConnect:function (elementName, proxy) {
console.info("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect called.");
// console.info("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect elementName = " + elementName);
// console.info("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect proxy = " + proxy);
dseProxy = proxy;
},
onDisconnect:function (elementName) {
console.info("[ttt] [DataShareTest] <<Consumer>> dseConnect onDisconnect, elementName:" + elementName);
},
onFailed:function (code) {
console.info("[ttt] [DataShareTest] <<Consumer>> dseConnect onFailed, code:" + code);
}
};
let seConnectionId = -1;
let dseConnectionId = -1;
let seWant = {
"bundleName": "com.samples.datasharetest",
"abilityName": "ServiceExtAbility",
}
let dseWant = {
"bundleName": "com.samples.datasharetest",
"abilityName": "DataShareExtAbility",
}
export function onCallback() {
console.info("[ttt] [DataShareTest] <<Consumer>> **** Observer on callback ****");
}
export function offCallback() {
console.info("[ttt] [DataShareTest] <<Consumer>> **** Observer off callback ****");
}
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.info("[ttt] [DataShareTest] <<Consumer>> MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.info("[ttt] [DataShareTest] <<Consumer>> MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.info("[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context;
let context = this.context;
// console.info('[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageCreate this.context.stageMode:' + context.stageMode);
// console.info('[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageCreate this.context.bundleName:' + context.bundleName);
// console.info('[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageCreate this.context.name:' + context.name);
globalThis.connectServiceExtAbility = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> connectServiceExtAbility begin");
seConnectionId = await context.connectAbility(seWant, seConnect);
console.info("[ttt] [DataShareTest] <<Consumer>> connectServiceExtAbility end, seConnectionId:" + seConnectionId);
})
globalThis.disconnectServiceExtAbility = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> disconnectServiceExtAbility begin");
await context.disconnectAbility(seConnectionId).then((data) => {
console.info("[ttt] [DataShareTest] <<Consumer>> startAbility success:" + JSON.stringify(data));
}).catch((error) => {
console.error("[ttt] [DataShareTest] <<Consumer>> startAbility failed:" + JSON.stringify(error));
});
console.info("[ttt] [DataShareTest] <<Consumer>> disconnectServiceExtAbility end, seConnectionId:" + seConnectionId);
})
globalThis.connectDataShareExtAbility = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> connectDataShareExtAbility begin");
// globalThis.dsHelper = await dataShare.createDataShareHelper(this.context,dseUri);
await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{
globalThis.dsHelper = data;
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 1 -----, globalThis.dsHelper = " + globalThis.dsHelper);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 2 -----, data = " + data);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 3 -----, err = " + err);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err));
});
// await dataShare.createDataShareHelper(this.context,dseUri).then((data)=>{
// globalThis.dsHelper = data;
// console.info("[ttt] [DataShareTest] <<Consumer>> ----- 1 -----, globalThis.dsHelper = " + globalThis.dsHelper);
// console.info("[ttt] [DataShareTest] <<Consumer>> ----- 2 -----, data = " + data);
// }).catch((err)=>{
// console.info("[ttt] [DataShareTest] <<Consumer>> ----- 3 -----, err = " + err);
// console.info("[ttt] [DataShareTest] <<Consumer>> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err));
// })
dseConnectionId = await context.connectAbility(dseWant, dseConnect);
// console.info("[ttt] [DataShareTest] <<Consumer>> ----- 5 -----, globalThis.dsHelper = " + globalThis.dsHelper);
// console.info("[ttt] [DataShareTest] <<Consumer>> connectDataShareExtAbility end, dseConnectionId:" + dseConnectionId);
})
globalThis.disconnectDataShareExtAbility = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> disconnectDataShareExtAbility begin");
await context.disconnectAbility(dseConnectionId).then((data) => {
console.info("[ttt] [DataShareTest] <<Consumer>> disconnectDataShareExtAbility success:" + JSON.stringify(data));
}).catch((error) => {
console.error("[ttt] [DataShareTest] <<Consumer>> disconnectDataShareExtAbility failed:" + JSON.stringify(error));
});
globalThis.dsHelper = null;
console.info("[ttt] [DataShareTest] <<Consumer>> disconnectDataShareExtAbility end, dseConnectionId:" + dseConnectionId);
})
globalThis.on = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> on begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> on end, DSHelper is null");
return;
}
await globalThis.dsHelper.on("dataChange", dseUri, onCallback);
console.info("[ttt] [DataShareTest] <<Consumer>> on end");
})
globalThis.off = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> off begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> off end, DSHelper is null");
return;
}
await globalThis.dsHelper.off("dataChange", dseUri);
await globalThis.dsHelper.off("dataChange", dseUri, offCallback);
console.info("[ttt] [DataShareTest] <<Consumer>> off end");
})
// globalThis.openFile = (async () => {
// console.info("[ttt] [DataShareTest] <<Consumer>> openFile begin");
// if (globalThis.dsHelper == null) {
// console.info("[ttt] [DataShareTest] <<Consumer>> openFile end, DSHelper is null");
// return;
// }
// let result = await globalThis.dsHelper.openFile(dseUri, "rwt");
// console.info("[ttt] [DataShareTest] <<Consumer>> openFile end, result:" + result);
// return result;
// })
globalThis.query = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> query begin");
let da = new dataSharePredicates.DataSharePredicates();
if (da == null || da == undefined) {
console.info("[ttt] [DataShareTest] <<Consumer>> da is null or undefined");
return;
}
let count = 0;
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> query end, DSHelper is null");
return;
}
da.equalTo("name", "ZhangSan");
let result = await globalThis.dsHelper.query(dseUri, da, ["*"], (err,resultSet)=> {
if (err) {
console.error("[ttt] [DataShareTest] <<Consumer>> query err:" + JSON.stringify(err));
console.info("[ttt] [DataShareTest] <<Consumer>> query data:" + resultSet);
console.info("[ttt] [DataShareTest] <<Consumer>> query data.rowCount:" + resultSet.rowCount);
console.info("[ttt] [DataShareTest] <<Consumer>> query data.columnCount:" + resultSet.columnCount);
} else {
console.info("[ttt] [DataShareTest] <<Consumer>> query data:" + resultSet);
console.info("[ttt] [DataShareTest] <<Consumer>> query data.rowCount:" + resultSet.rowCount);
console.info("[ttt] [DataShareTest] <<Consumer>> query data.columnCount:" + resultSet.columnCount);
}
});
if (result != undefined) {
count = result.rowCount;
}
console.info("[ttt] [DataShareTest] <<Consumer>> query end, count:" + count);
return count;
})
globalThis.insert = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> insert begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> insert end, DSHelper is null");
return;
}
let vb = {"age": 21}
let v8Arr = [];
let ar = new Uint8Array([1,2,3,4,5,6]);
let arr = new Uint8Array([4,5,6,7]);
let vb1 = {"key":ar,"value":arr}
v8Arr.push(vb1);
console.info("[ttt] [DataShareTest] <<Consumer>> insert vb:" + JSON.stringify(vb));
console.info("[ttt] [DataShareTest] <<Consumer>> insert vb:" + JSON.stringify(vb));
let ret = await globalThis.dsHelper.insert(dseUri, vb, (err,ret)=>{
if(err){
console.error("[ttt] [DataShareTest] <<Consumer>> insert err:" + JSON.stringify(err));
console.info("[ttt] [DataShareTest] <<Consumer>> insert data:" + ret);
}else {
console.info("[ttt] [DataShareTest] <<Consumer>> insert data:" + ret);
}
});
await globalThis.notifyChange();
console.info("[ttt] [DataShareTest] <<Consumer>> insert end, ret:" + ret);
return ret;
})
globalThis.update = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> update begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> update end, DSHelper is null");
return;
}
console.info("[ttt] [DataShareTest] <<Consumer>> update begin RPF666");
let da = new dataSharePredicates.DataSharePredicates();
console.info("[ttt] [DataShareTest] <<Consumer>> update begin RPF777");
if (da == null || da == undefined) {
console.info("[ttt] [DataShareTest] <<Consumer>> da is null or u" +
"ndefined");
return;
}
// da.equalTo("name", "ZhangSan");
let ret = await globalThis.dsHelper.update(dseUri, da, {"age": 31}, (err,ret)=>{
if(err){
console.error("[ttt] [DataShareTest] <<Consumer>> update err:" + JSON.stringify(err));
console.info("[ttt] [DataShareTest] <<Consumer>> update data:" + ret);
}else {
console.info("[ttt] [DataShareTest] <<Consumer>> update data:" + ret);
}
});
await globalThis.notifyChange();
console.info("[ttt] [DataShareTest] <<Consumer>> update end, result:" + ret);
return ret;
})
globalThis.delete = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> delete begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> delete end, DSHelper is null");
return;
}
let da = new dataSharePredicates.DataSharePredicates();
if (da == null || da == undefined) {
console.info("[ttt] [DataShareTest] <<Consumer>> da is null or undefined");
return;
}
// da.equalTo("name", "ZhangSan");
let ret = globalThis.dsHelper.delete(dseUri, da, (err,ret)=>{
if(err){
console.error("[ttt] [DataShareTest] <<Consumer>> delete err:" + JSON.stringify(err));
console.info("[ttt] [DataShareTest] <<Consumer>> delete data:" + ret);
}else {
console.info("[ttt] [DataShareTest] <<Consumer>> delete data:" + ret);
}
});
await globalThis.notifyChange();
console.info("[ttt] [DataShareTest] <<Consumer>> delete end, result:" + ret);
return ret;
})
globalThis.batchInsert = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> batchInsert begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> batchInsert end, DSHelper is null");
return;
}
let ar = new Uint8Array([1,2,3,4,5,6]);
let arr = new Uint8Array([4,5,6,7]);
let people = new Array(
{"name": "LiSi", "age": 41, "Binary": ar},
{"name": "WangWu", "age": 21, "Binary": arr},
{"name": "ZhaoLiu", "age": 61, "Binary": arr});
// let ar = new Uint8Array([1,2,3,4,5,6]);
// let arr = new Uint8Array([4,5,6,7]);
// let v8Arr = [];
// let vb = {"key":ar,"jii":arr,"value":arr,"njj":arr};
// v8Arr.push(vb)
let ret = await globalThis.dsHelper.batchInsert(dseUri, people);
await globalThis.notifyChange();
console.info("[ttt] [DataShareTest] <<Consumer>> batchInsert end, result:" + ret);
return ret;
})
globalThis.notifyChange = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> notifyChange begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> notifyChange end, DSHelper is null");
return;
}
await globalThis.dsHelper.notifyChange(dseUri);
console.info("[ttt] [DataShareTest] <<Consumer>> notifyChange end");
})
globalThis.getType = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> getType begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> getType end, DSHelper is null");
return;
}
let result;
globalThis.dsHelper.getType(dseUri,(err,data)=>{
if(err){
console.info("[ttt] [DataShareTest] <<Consumer>> getType err, err:" + JSON.stringify(err));
console.info("[ttt] [DataShareTest] <<Consumer>> getType end, err:" + JSON.stringify(data));
result = data;
}else{
console.info("[ttt] [DataShareTest] <<Consumer>> getType end, err:" + JSON.stringify(data));
result = data;
}
});
console.info("[ttt] [DataShareTest] <<Consumer>> getType end, result:" + result);
return result;
})
globalThis.getFileTypes = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> getFileTypes begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> getFileTypes end, DSHelper is null");
return;
}
let result = await globalThis.dsHelper.getFileTypes(dseUri, "image/*",(err,data)=>{
if(err){
console.info("[ttt] [DataShareTest] <<Consumer>> getType err, err:" + JSON.stringify(err));
console.info("[ttt] [DataShareTest] <<Consumer>> getType end, err:" + JSON.stringify(data));
result = data;
}else{
console.info("[ttt] [DataShareTest] <<Consumer>> getType end, err:" + JSON.stringify(data));
result = data;
}
});
return result;
})
globalThis.normalizeUri = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> normalizeUri begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> normalizeUri end, DSHelper is null");
return;
}
let result = await globalThis.dsHelper.normalizeUri(dseUri,(err,data)=>{
if(err){
console.info("[ttt] [DataShareTest] <<Consumer>> normalizeUri err, err:" + JSON.stringify(err));
// console.info("[ttt] [DataShareTest] <<Consumer>> getType end, data:" + JSON.stringify(data));
// result = data;
}else{
console.info("[ttt] [DataShareTest] <<Consumer>> normalizeUri end, data:" + JSON.stringify(data));
result = data;
}
});
return result;
})
globalThis.denormalizeUri = (async () => {
console.info("[ttt] [DataShareTest] <<Consumer>> denormalizeUri begin");
if (globalThis.dsHelper == null) {
console.info("[ttt] [DataShareTest] <<Consumer>> denormalizeUri end, DSHelper is null");
return;
}
let result = await globalThis.dsHelper.denormalizeUri(dseUri,(err,data)=>{
if(err){
console.info("[ttt] [DataShareTest] <<Consumer>> denormalizeUri err, err:" + JSON.stringify(err));
// console.info("[ttt] [DataShareTest] <<Consumer>> getType end, err:" + JSON.stringify(data));
// result = data;
}else{
console.info("[ttt] [DataShareTest] <<Consumer>> denormalizeUri end, err:" + JSON.stringify(data));
result = data;
}
});
return result;
})
windowStage.setUIContent(this.context, "pages/index", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.info("[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.info("[ttt] [DataShareTest] <<Consumer>> MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.info("[ttt] [DataShareTest] <<Consumer>> MainAbility onBackground")
}
};
/*
* 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 dataShare from '@ohos.data.dataShare'
@Entry
@Component
struct Index {
@State message: string = "Main thread message filed"
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('DataShare Extension Ability Test')
.fontSize(40)
.fontWeight(FontWeight.Bold)
.onClick(async () => {
// console.info('[ttt] [DataShareTest] <<UI>> dataSharePredicates build begin');
// let da = new dataShare.DataSharePredicates();
// da.equalTo("name", "zhangsan");
// da.notEqualTo("name", "lisi");
// da.beginWrap();
// da.endWrap();
// da.or();
// da.and();
// da.contains("name", "zhang");
// da.beginsWith("name", "z");
// da.endsWith("name", "n");
// da.isNull("name");
// da.isNotNull("name");
// da.like("name", "zhang");
// da.unlike("name", "li");
// da.glob("name", "???");
// da.between("age", 18, 22);
// da.notBetween("age", 18, 22);
// da.greaterThan("age", 18);
// da.lessThan("age", 22);
// da.greaterThanOrEqualTo("age", 18);
// da.lessThanOrEqualTo("age", 22);
// da.orderByAsc("age");
// da.orderByDesc("age");
// da.distinct();
// da.limit(10, 5);
// da.groupBy(["name", "age"]);
// da.indexedBy("name");
// da.in("name", []);
// da.notIn("name", []);
// da.prefixKey("name");
// console.info('[ttt] [DataShareTest] <<UI>> dataSharePredicates = ' + JSON.stringify(da));
// console.info('[ttt] [DataShareTest] <<UI>> dataSharePredicates build end');
})
Text(`${this.message}`)
.fontSize(30)
.height('15%')
.width('100%')
.textAlign(TextAlign.Center)
// Row() {
// Button() {
// Text('ConnectServiceExtension')
// .fontSize(25)
// .fontWeight(FontWeight.Bold)
// }.type(ButtonType.Capsule)
// .margin({
// top: 20
// })
// .width('45%')
// .height('8%')
// .backgroundColor('#0ddffb')
// .onClick(async () => {
// console.info('[ttt] [DataShareTest] <<UI>> ConnectServiceExtension onclick enter')
// this.message = 'ConnectServiceExtension onclick'
// globalThis.connectServiceExtAbility()
// console.info('[ttt] [DataShareTest] <<UI>> ConnectServiceExtension onclick leave')
// })
//
// Button() {
// Text('DisconnectServiceExtension')
// .fontSize(25)
// .fontWeight(FontWeight.Bold)
// }.type(ButtonType.Capsule)
// .margin({
// top: 20
// })
// .width('45%')
// .height('8%')
// .backgroundColor('#0ddffb')
// .onClick(async () => {
// console.info('[ttt] [DataShareTest] <<UI>> DisconnectServiceExtension onclick enter')
// this.message = 'DisconnectServiceExtension onclick'
// globalThis.disconnectServiceExtAbility()
// console.info('[ttt] [DataShareTest] <<UI>> DisconnectServiceExtension onclick leave')
// })
// }
Row() {
Button() {
Text('Connect')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Connect onclick enter')
this.message = 'Connect onclick'
await globalThis.connectDataShareExtAbility()
console.info('[ttt] [DataShareTest] <<UI>> Connect onclick leave')
})
Button() {
Text('Disconnect')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Disconnect onclick enter')
this.message = 'Disconnect onclick'
await globalThis.disconnectDataShareExtAbility()
console.info('[ttt] [DataShareTest] <<UI>> Disconnect onclick leave')
})
}
Row() {
Button() {
Text('On')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> On onclick enter')
this.message = '~ On onclick'
try {
await globalThis.on();
} catch (err) {
console.error('[ttt] [DataAbilityTest] Observer on catch(err)====>:' + err);
}
console.info('[ttt] [DataShareTest] <<UI>> On onclick leave')
})
Button() {
Text('Off')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Off onclick enter')
this.message = '~ Off onclick'
try {
await globalThis.off();
} catch (err) {
console.error('[ttt] [DataAbilityTest] Observer Off catch(err)====>:' + err);
}
console.info('[ttt] [DataShareTest] <<UI>> Off onclick leave')
})
// Button() {
// Text('OpenFile')
// .fontSize(25)
// .fontWeight(FontWeight.Bold)
// }.type(ButtonType.Capsule)
// .margin({
// top: 20
// })
// .width('30%')
// .height('8%')
// .backgroundColor('#0ddffb')
// .onClick(async () => {
// console.info('[ttt] [DataShareTest] <<UI>> OpenFile onclick enter')
// this.message = 'OpenFile onclick'
// let ret = await globalThis.openFile()
// this.message += "\n\n Test Result: " + ret;
// console.info('[ttt] [DataShareTest] <<UI>> OpenFile onclick leave')
// })
}
Row() {
Button() {
Text('Query')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Query onclick enter')
this.message = 'Query onclick'
let ret = await globalThis.query()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> Query onclick leave')
})
Button() {
Text('Insert')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Insert onclick enter')
this.message = 'Insert onclick'
let ret = await globalThis.insert()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> Insert onclick leave')
})
}
Row() {
Button() {
Text('Update')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Update onclick enter')
this.message = 'Update onclick'
let ret = await globalThis.update()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> Update onclick leave')
})
Button() {
Text('Delete')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> Delete onclick enter')
this.message = 'Delete onclick'
let ret = await globalThis.delete()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> Delete onclick leave')
})
}
Row() {
Button() {
Text('BatchInsert')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> BatchInsert onclick enter')
this.message = 'BatchInsert onclick'
let ret = await globalThis.batchInsert()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> BatchInsert onclick leave')
})
Button() {
Text('NotifyChange')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> NotifyChange onclick enter')
this.message = 'NotifyChange onclick'
await globalThis.notifyChange()
console.info('[ttt] [DataShareTest] <<UI>> NotifyChange onclick leave')
})
}
Row() {
Button() {
Text('GetType')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> GetType onclick enter')
this.message = 'GetType onclick'
let ret = await globalThis.getType()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> GetType onclick leave')
})
Button() {
Text('GetFileTypes')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> GetFileTypes onclick enter')
this.message = 'GetFileTypes onclick'
let ret = await globalThis.getFileTypes()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> GetFileTypes onclick leave')
})
}
Row() {
Button() {
Text('NormalizeUri')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> NormalizeUri onclick enter')
this.message = 'NormalizeUri onclick'
let ret = await globalThis.normalizeUri()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> NormalizeUri onclick leave')
})
Button() {
Text('DenormalizeUri')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.width('45%')
.height('8%')
.backgroundColor('#0ddffb')
.onClick(async () => {
console.info('[ttt] [DataShareTest] <<UI>> DenormalizeUri onclick enter')
this.message = 'DenormalizeUri onclick'
let ret = await globalThis.denormalizeUri()
this.message += "\n\n Test Result: " + ret;
console.info('[ttt] [DataShareTest] <<UI>> DenormalizeUri onclick leave')
})
}
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
{
"module": {
"name": "entry",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:phone_entry_dsc",
"mainElement": "MainAbility",
"deviceTypes": [
"default"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:phone_entry_main",
"icon": "$media:icon",
"label": "$string:entry_label",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:color_1"
}
],
"extensionAbilities": [
{
"srcEntrance": "./ets/DataShareExtAbility/DataShareExtAbility.ts",
"name": "DataShareExtAbility",
"icon": "$media:icon",
"description": "$string:description_datashareextability",
"type": "dataShare",
"uri": "datashare://com.samples.datasharekvtest.DataShare",
"visible": true
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "phone_entry_dsc",
"value": "i am an entry for phone"
},
{
"name": "phone_entry_main",
"value": "the phone entry ability"
},
{
"name": "entry_label",
"value": "ActsKvServiceHap"
},
{
"name": "form_description",
"value": "my form"
},
{
"name": "serviceability_description",
"value": "my whether"
},
{
"name": "description_application",
"value": "ActsKvServiceHap"
},
{
"name": "app_name",
"value": "ActsKvServiceHap"
},
{
"name": "description_datashareextability",
"value": "description_datashareextability"
},
{
"name": "description_serviceability",
"value": "description_serviceability"
}
]
}
......@@ -13,13 +13,11 @@
import("//test/xts/tools/build/suite.gni")
ohos_hap("ActsRdbServiceHap") {
ohos_hap_assist_suite("ActsRdbServiceHap") {
hap_profile = "./entry/src/main/module.json"
hap_name = "ActsRdbServiceHap"
subsystem_name = XTS_SUITENAME
final_hap_path =
"${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/testcases/${hap_name}.hap"
subsystem_name = "distributeddatamgr"
part_name = "data_share"
js_build_mode = "debug"
deps = [
":rdbService_js_assets",
......
{
"color": [
{
"name": "color_1",
"value": "#ff0000"
}
]
}
\ No newline at end of file
{
"forms": [
{
"name": "Form_Js",
"description": "$string:form_description",
"src": "pages/card/index",
"window": {
"designWidth": 720,
"autoDesignWidth": true
},
"colorMode": "auto",
"formConfigAbility": "ability://xxxxx",
"formVisibleNotify": false,
"isDefault": true,
"updateEnabled": true,
"scheduledUpdateTime": "10:30",
"updateDuration": 1,
"defaultDimension": "2*2",
"supportDimensions": [
"2*2"
]
}
]
}
......@@ -13,19 +13,21 @@
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("distributeddatamgr_js_test") {
ohos_js_hap_suite("kvStore_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":distributeddatamgr_js_assets",
":distributeddatamgr_resources",
":kvStore_js_assets",
":kvStore_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsDistributedDatamgrJsTest"
hap_name = "ActKvStoreJsTest"
subsystem_name = "distributeddatamgr"
part_name = "distributeddatamgr"
}
ohos_js_assets("distributeddatamgr_js_assets") {
ohos_js_assets("kvStore_js_assets") {
source_dir = "./src/main/js/default"
}
ohos_resources("distributeddatamgr_resources") {
ohos_resources("kvStore_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
......@@ -3,13 +3,13 @@
"driver": {
"type": "JSUnitTest",
"test-timeout": "1200000",
"package": "ohos.acts.distributeddatamgr",
"package": "ohos.acts.kvStore",
"shell-timeout": "60000"
},
"kits": [
{
"test-file-name": [
"ActsDistributedDatamgrJsTest.hap"
"ActKvStoreJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
......
{
"app": {
"bundleName": "ohos.acts.distributeddatamgr",
"bundleName": "ohos.acts.kvStore",
"vendor": "example",
"version": {
"code": 1000000,
......@@ -13,9 +13,9 @@
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.distributeddatamgr",
"package": "ohos.acts.kvStore",
"name": ".MyApplication",
"mainAbility": "ohos.acts.distributeddatamgr.MainAbility",
"mainAbility": "ohos.acts.kvStore.MainAbility",
"deviceType": [
"phone"
],
......@@ -38,7 +38,7 @@
]
}
],
"name": "ohos.acts.distributeddatamgr.MainAbility",
"name": "ohos.acts.kvStore.MainAbility",
"icon": "$media:icon",
"description": "$string:mainability_description",
"label": "$string:app_name",
......
......@@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true;
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
......
......@@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true;
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
......
......@@ -15,7 +15,7 @@
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
const STORE_KEY = 'key_test_string';
const STORE_VALUE = 'value-test-string';
......
......@@ -15,7 +15,7 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
......
......@@ -15,7 +15,7 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import factory from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
......
......@@ -15,7 +15,7 @@
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import ddm from '@ohos.data.distributedData';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
......
......@@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true;
const VALUE_TEST_STRING_ELEMENT = 'value-string-002';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
......
......@@ -27,7 +27,7 @@ const VALUE_TEST_BOOLEAN_ELEMENT = true;
const VALUE_TEST_STRING_ELEMENT = 'value-string-001';
const VALUE_TEST_SYNC_ELEMENT = 'value-string-001';
const TEST_BUNDLE_NAME = 'ohos.acts.distributeddatamgr';
const TEST_BUNDLE_NAME = 'ohos.acts.kvStore';
const TEST_STORE_ID = 'storeId';
var kvManager = null;
var kvStore = null;
......@@ -2657,4 +2657,79 @@ describe('SingleKvStorePromiseTest', function () {
}
done();
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_CHANGENOTIFICATION_0100
* @tc.name [JS-API8]SingleKvStoreChangeNotification.
* @tc.desc Test Js Api SingleKvStoreChangeNotification testcase 001
*/
it('testSingleKvStoreChangeNotification101', 0, async function (done) {
var getInsertEntries = new Promise((resolve, reject) => {
kvStore.on('dataChange', 0, function(ChangeNotification){
resolve(ChangeNotification.insertEntries);
});
kvStore.put("getInsertEntries", "byPut").then(() => {
console.info('testSingleKvStoreChangeNotification101 put success');
});
});
await getInsertEntries.then(function(insertEntries){
console.info('testSingleKvStoreChangeNotification101 getInsertEntries' + JSON.stringify(insertEntries));
expect(insertEntries).assertNotNull();
}).catch((error) => {
console.info('testSingleKvStoreChangeNotification101 can NOT getInsertEntries, fail:' + error);
});
done();
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_CHANGENOTIFICATION_0200
* @tc.name [JS-API8]SingleKvStoreChangeNotification.
* @tc.desc Test Js Api SingleKvStoreChangeNotification testcase 002
*/
it('testSingleKvStoreChangeNotification102', 0, async function (done) {
await kvStore.put('getUpdateEntries', 'byPut').then(() => {
console.info('testSingleKvStoreChangeNotification102 put success');
});
var getUpdateEntries = new Promise((resolve, reject) => {
kvStore.on('dataChange', 0, function(ChangeNotification){
resolve(ChangeNotification.updateEntries);
});
kvStore.put("getUpdateEntries", "byPut").then(() => {
console.info('testSingleKvStoreChangeNotification102 update success');
});
});
await getUpdateEntries.then(function(updateEntries){
console.info('testSingleKvStoreChangeNotification102 getUpdateEntries' + JSON.stringify(updateEntries));
expect(updateEntries).assertNotNull();
}).catch((error) => {
console.info('testSingleKvStoreChangeNotification102 can NOT getUpdateEntries, fail:' + error);
});
done();
})
/**
* @tc.number SUB_DISTRIBUTEDDATAMGR_SINGLEKVSTORE_CHANGENOTIFICATION_0300
* @tc.name [JS-API8]SingleKvStoreChangeNotification.
* @tc.desc Test Js Api SingleKvStoreChangeNotification testcase 003
*/
it('testSingleKvStoreChangeNotification103', 0, async function (done) {
await kvStore.put('deleteEntries', 'byPut').then(() => {
console.info('testSingleKvStoreChangeNotification103 put success');
});
var getdeleteEntries = new Promise((resolve, reject) => {
kvStore.on('dataChange', 0, function(ChangeNotification){
resolve(ChangeNotification.deleteEntries);
});
kvStore.delete("deleteEntries").then(() => {
console.info('testSingleKvStoreChangeNotification103 delete success');
});
});
await getdeleteEntries.then(function(deleteEntries){
console.info('testSingleKvStoreChangeNotification103 deleteEntries' + JSON.stringify(getdeleteEntries));
expect(deleteEntries != null).assertNotNull();
}).catch((error) => {
console.info('testSingleKvStoreChangeNotification103 can NOT getdeleteEntries, fail:' + error);
});
done();
})
})
\ 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("preferences_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":preferences_js_assets",
":preferences_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsPreferencesJsTest"
subsystem_name = "distributeddatamgr"
part_name = "preferences"
}
ohos_js_assets("preferences_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("preferences_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "1000000",
"shell-timeout": "1000000",
"bundle-name": "ohos.acts.preferencesjstest",
"package-name": "ohos.acts.preferencesjstest"
},
"kits": [
{
"test-file-name": [
"ActsPreferencesJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.preferencesjstest",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.preferencesjstest",
"name": ".entry",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"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:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ 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.
*/
export default {
onCreate() {
console.info('TestApplication onCreate');
},
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
/*
* 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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{title}}
</text>
</div>
/*
* 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.
*/
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
},
}
\ No newline at end of file
/*
* 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);
})
}
};
/*
* 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 storageCallBackTest from './StorageCallBackJsunit.test.js'
import storageHelperTest from './StorageHelperJsunit.test.js'
import storagePromiseTest from './StoragePromiseJsunit.test.js'
import storageSyncTest from './StorageSyncJsunit.test.js'
import systemStorageTest from './SystemStorageJsunit.test.js'
export default function testsuite() {
storageCallBackTest()
storageHelperTest()
storagePromiseTest()
storageSyncTest()
systemStorageTest()
}
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"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"
}
]
}
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("relationalstore_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":relationalstore_js_assets",
":relationalstore_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsRelationalStoreJsTest"
subsystem_name = "distributeddatamgr"
part_name = "relational_store"
}
ohos_js_assets("relationalstore_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("relationalstore_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "1000000",
"shell-timeout": "1000000",
"bundle-name": "ohos.acts.relationalStorejstest",
"package-name": "ohos.acts.relationalStorejstest"
},
"kits": [
{
"test-file-name": [
"ActsRelationalStoreJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.relationalStorejstest",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.relationalStorejstest",
"name": ".entry",
"deviceType": [
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"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:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ 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.
*/
export default {
onCreate() {
console.info('TestApplication onCreate');
},
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
/*
* 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.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{title}}
</text>
</div>
/*
* 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.
*/
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
},
}
\ No newline at end of file
/*
* 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,10 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import dataAbilityPredicatesTest from './DataAbilityPredicatesJsunit.test.js'
import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js'
import rdbstoreChangeEncryptKeyTest from './RdbstoreChangeEncryptKeyJsunit.test.js'
import rdbStoreDataSharePredicatesTest from './RdbStoreDataShareJsunit.test.js'
import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js'
import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js'
import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js'
......@@ -26,16 +24,9 @@ import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js'
import rdbstoreStoreExcuteSqlTest from './RdbstoreStoreExcuteSqlJsunit.test.js'
import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js'
import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js'
import storageCallBackTest from './StorageCallBackJsunit.test.js'
import storageHelperTest from './StorageHelperJsunit.test.js'
import storagePromiseTest from './StoragePromiseJsunit.test.js'
import storageSyncTest from './StorageSyncJsunit.test.js'
import systemStorageTest from './SystemStorageJsunit.test.js'
export default function testsuite() {
dataAbilityPredicatesTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbstoreChangeEncryptKeyTest()
rdbStoreDataSharePredicatesTest()
rdbStoreDeleteTest()
rdbStoreDistributedTest()
rdbstoreInsertTest()
......@@ -46,9 +37,4 @@ rdbResultSetTest()
rdbstoreStoreExcuteSqlTest()
rdbstoreTransactionTest()
rdbStoreUpdateTest()
storageCallBackTest()
storageHelperTest()
storagePromiseTest()
storageSyncTest()
systemStorageTest()
}
......@@ -119,70 +119,70 @@ describe('rdbStoreBackupRestoreWithFAContextTest', function () {
console.info(TAG + "*************Unit Test Begin*************")
/**
* @tc.name RDB Backup Restore test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0010
* @tc.desc RDB backup and restore function test
*/
it('RdbBackupRestoreTest_0010', 0, async function (done) {
await console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RDB backup function test
let promiseBackup = RdbStore.backup(DATABASE_BACKUP_NAME)
promiseBackup.then(() => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
expect(false).assertTrue()
}
}).catch((err) => {
expect(false).assertTrue()
})
await promiseBackup
// RDB restore function test
let promiseRestore = RdbStore.restore(DATABASE_BACKUP_NAME)
promiseRestore.then(() => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue()
} catch (err) {
expect(true).assertTrue()
}
try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
expect(true).assertTrue()
} catch (err) {
expect(false).assertTrue()
}
}).catch((err) => {
expect(false).assertTrue()
})
await promiseRestore
// RDB after restored, data query test
let predicates = new dataRdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan")
let resultSet = await RdbStore.query(predicates)
try {
console.info(TAG + "After restore resultSet query done")
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(1).assertEqual(id)
expect("zhangsan").assertEqual(name)
expect(1).assertEqual(blobType[0])
} catch (err) {
expect(false).assertTrue()
}
resultSet = null
RdbStore = null
done()
await console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************")
})
// /**
// * @tc.name RDB Backup Restore test
// * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0010
// * @tc.desc RDB backup and restore function test
// */
// it('RdbBackupRestoreTest_0010', 0, async function (done) {
// await console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// // RDB backup function test
// let promiseBackup = RdbStore.backup(DATABASE_BACKUP_NAME)
// promiseBackup.then(() => {
// try {
// fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
// fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
// } catch (err) {
// expect(false).assertTrue()
// }
// }).catch((err) => {
// expect(false).assertTrue()
// })
// await promiseBackup
// // RDB restore function test
// let promiseRestore = RdbStore.restore(DATABASE_BACKUP_NAME)
// promiseRestore.then(() => {
// try {
// fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
// expect(false).assertTrue()
// } catch (err) {
// expect(true).assertTrue()
// }
// try {
// fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
// expect(true).assertTrue()
// } catch (err) {
// expect(false).assertTrue()
// }
// }).catch((err) => {
// expect(false).assertTrue()
// })
// await promiseRestore
// // RDB after restored, data query test
// let predicates = new dataRdb.RdbPredicates("test")
// predicates.equalTo("name", "zhangsan")
// let resultSet = await RdbStore.query(predicates)
// try {
// console.info(TAG + "After restore resultSet query done")
// expect(true).assertEqual(resultSet.goToFirstRow())
// const id = resultSet.getLong(resultSet.getColumnIndex("id"))
// const name = resultSet.getString(resultSet.getColumnIndex("name"))
// const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
// expect(1).assertEqual(id)
// expect("zhangsan").assertEqual(name)
// expect(1).assertEqual(blobType[0])
// } catch (err) {
// expect(false).assertTrue()
// }
// resultSet = null
// RdbStore = null
// done()
// await console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************")
// })
/**
* @tc.name RDB Backup test
......
......@@ -47,6 +47,7 @@ describe('rdbStoreDeleteTest', function () {
})
console.info(TAG + '*************Unit Test Begin*************');
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0010
......
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"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"
}
]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册