提交 daba6d2b 编写于 作者: L liangzhenyu123

liangzhenyu6@huawei.com

Signed-off-by: Nliangzhenyu123 <liangzhenyu6@huawei.com>
上级 71312c9f
......@@ -17,7 +17,7 @@ group("distributeddatamgr") {
if (is_standard_system) {
deps = [
"dataObjectjstest/hap:dataObject_js_test",
"dataShare:dataShare",
"dataSharejstest/hap:dataShare_js_test",
"kvStorejstest/hap:kvStore_js_test",
"preferencesjstest/hap:preferences_js_test",
"relationalStorejstest/hap:relationalstore_js_test",
......
# 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")
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
}
}
}
# 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 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
/*
* 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 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
/*
* 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
{
"app": {
"bundleName": "com.example.myapplication",
"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
}
}
}
# 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("ActsDataShareRdbTest") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":dataShareRdb_js_assets",
":dataShareRdb_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsDataShareRdbTest"
subsystem_name = "distributeddatamgr"
part_name = "data_share"
}
ohos_app_scope("dataShareRdb_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("dataShareRdb_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("dataShareRdb_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":dataShareRdb_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.myapplication",
"module-name": "entry",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [{
"test-file-name": [
"ActsDataShareRdbTest.hap",
"ActsRdbServiceHap.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 dataSharePredicates from '@ohos.data.dataSharePredicates'
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.datasharetest.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 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
/*
* 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.myapplication.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 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
/*
* 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 DataShareSingleRdb_Callback from "./DataShareSingleRdb_Callback"
import DataShareSingleRdb_Promise from "./DataShareSingleRdb_Promise"
import DataSharePredicatesRdb from "./DataSharePredicatesRdb"
import DataShareCombinationRdb from "./DataShareCombinationRdb"
export default function testsuite() {
DataShareSingleRdb_Callback()
DataShareSingleRdb_Promise()
DataSharePredicatesRdb()
DataShareCombinationRdb()
}
\ No newline at end of file
{
"module": {
"package": "com.example.myapplication",
"name": "entry",
"mainAbility": "com.example.myapplication.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.myapplication.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"
]
}
]
}
]
}
}
\ No newline at end of file
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "ActsDataShareRdbTest"
}
]
}
\ No newline at end of file
{
"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
}
}
}
# 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
{
"color": [
{
"name": "color_1",
"value": "#ff0000"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册