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

!9427 【Distributeddatamgr】【Master】接口用例补充

Merge pull request !9427 from yanglifeng/master
......@@ -23,8 +23,10 @@ group("distributeddatamgr") {
"dataSharejstest/hap:dataShare_js_test",
"distributedKVStoretest:distributedKVStoretest",
"kvStoretest:kvStoretest",
"preferencesdatagroupidtest:ActsPreferencesDataGroupIdTest",
"preferencesjstest/hap:preferences_js_test",
"relationalStoretest:relationalStoretest",
"relationalstoredatagroupidtest:ActsRelationalstoreDataGroupIdTest",
]
} else {
deps = [
......
{
"app": {
"bundleName": "ohos.acts.preferencesdatagroupidtest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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("ActsPreferencesDataGroupIdTest") {
hap_profile = "src/main/module.json"
deps = [
":preferencesDataGroupId_js_assets",
":preferencesDataGroupId_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsPreferencesDataGroupIdTest"
subsystem_name = "distributeddatamgr"
part_name = "preferences"
}
ohos_app_scope("preferencesDataGroupId_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("preferencesDataGroupId_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("preferencesDataGroupId_resources") {
sources = [ "src/main/resources" ]
deps = [ ":preferencesDataGroupId_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.preferencesdatagroupidtest",
"module-name": "preferencesDataGroupId"
},
"kits": [
{
"test-file-name": [
"ActsPreferencesDataGroupIdTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 UIAbility from "@ohos.app.ability.UIAbility";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
import hilog from "@ohos.hilog";
import { Hypium } from "@ohos/hypium";
import testsuite from "../test/List.test";
import window from "@ohos.window";
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onCreate");
hilog.info(0x0000, "testTag", "%{public}s", "want param:" + JSON.stringify(want) ?? "");
hilog.info(0x0000, "testTag", "%{public}s", "launchParam:" + JSON.stringify(launchParam) ?? "");
var abilityDelegator: any;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegatorArguments: any;
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!");
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
}
onDestroy() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onDestroy");
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageCreate");
globalThis.abilityContext = this.context;
windowStage.loadContent("TestAbility/pages/Index", (err, data) => {
if (err.code) {
hilog.error(0x0000, "testTag", "Failed to load the content. Cause: %{public}s", JSON.stringify(err) ?? "");
return;
}
hilog.info(0x0000, "testTag", "Succeeded in loading the content. Data: %{public}s", JSON.stringify(data) ?? "");
});
}
onWindowStageDestroy() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageDestroy");
}
onForeground() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onForeground");
}
onBackground() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onBackground");
}
}
/*
* Copyright (C) 2023 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', '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
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 preferencesDataGroupIdCallback from './preferencesDataGroupIdCallback.test'
import preferencesDataGroupIdPromise from './preferencesDataGroupIdPromise.test'
export default function testsuite() {
preferencesDataGroupIdCallback()
preferencesDataGroupIdPromise()
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 dataPreferences from '@ohos.data.preferences';
const TAG = "[ttt]"
export default function preferencesDataGroupIdCallback() {
describe('preferencesDataGroupIdCallback', function () {
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0100
* @tc.name preferencesgetPreferences dataGroupId null callback test
* @tc.desc preferences getPreferences dataGroupId null callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0100', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: null,
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) {
console.info(TAG, `deletePreferences successfully.`);
expect().assertFail();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0200
* @tc.name preferences dataGroupId undefined callback test
* @tc.desc preferences getPreferences dataGroupId undefined callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0200', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: undefined,
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) {
console.info(TAG, `deletePreferences successfully.`);
expect().assertFail();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0300
* @tc.name preferences dataGroupId callback test
* @tc.desc preferences getPreferences dataGroupId callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0300', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: '112233',
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) {
console.info(TAG, `deletePreferences successfully.`);
expect().assertFail();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('15501002');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0400
* @tc.name preferences dataGroupId callback test
* @tc.desc preferences deletePreferences dataGroupId callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0400', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: '123456',
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
if (err) {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
return false;
}
console.info(TAG, `getPreferences successfully.`);
dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) {
if (error) {
console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`);
return false;
}
console.info(TAG, `deletePreferences successfully.`);
expect(error === undefined).assertTrue();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo !== null).assertFail();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0500
* @tc.name preferences dataGroupId null callback test
* @tc.desc preferences getPreferences dataGroupId null callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0500', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: null,
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) {
console.info(TAG, `removePreferencesFromCache successfully.`);
expect().assertFail();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0600
* @tc.name preferences dataGroupId undefined callback test
* @tc.desc preferences removePreferencesFromCache dataGroupId undefined callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0600', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: undefined,
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) {
console.info(TAG, `removePreferencesFromCache successfully.`);
expect().assertFail();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0700
* @tc.name preferences dataGroupId callback test
* @tc.desc preferences removePreferencesFromCache dataGroupId callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0700', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: '112233',
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) {
console.info(TAG, `removePreferencesFromCache successfully.`);
expect().assertFail();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('15501002');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0800
* @tc.name preferences dataGroupId callback test
* @tc.desc preferences removePreferencesFromCache dataGroupId callback test
*/
it('SUB_DDM_Preferences_DataGroupId_Callback_0800', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: '123456',
};
try {
dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) {
if (err) {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
return false;
}
console.info(TAG, `getPreferences successfully.`);
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) {
if (error) {
console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`);
return false;
}
console.info(TAG, `removePreferencesFromCache successfully.`);
expect(error === undefined).assertTrue();
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo !== null).assertFail();
}
})
console.log(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 dataPreferences from '@ohos.data.preferences';
const TAG = "[ttt]"
export default function preferencesDataGroupIdPromise() {
describe('preferencesDataGroupIdPromise', function () {
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0100
* @tc.name preferences dataGroupId null promise test
* @tc.desc preferences getPreferences dataGroupId null promise test
*/
it('SUB_DDM_Preferences_DataGroupId_Promise_0100', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: null,
};
try{
dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.deletePreferences(globalThis.abilityContext, Options).then(async (val) => {
console.info(TAG, `deletePreferences successfully.`);
expect().assertFail();
done();
}).catch((error) => {
console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertFail();
done();
})
}catch(errInfo){
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0200
* @tc.name preferences dataGroupId undefined promise test
* @tc.desc preferences getPreferences dataGroupId undefined promise test
*/
it('SUB_DDM_Preferences_DataGroupId_Promise_0200', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: undefined,
};
try{
dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.deletePreferences(globalThis.abilityContext, Options).then(async (val) => {
console.info(TAG, `deletePreferences successfully.`);
expect().assertFail();
done();
}).catch((error) => {
console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertFail();
done();
})
}catch(errInfo){
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0300
* @tc.name preferences dataGroupId promise test
* @tc.desc preferences getPreferences dataGroupId promise test
*/
it('SUB_DDM_Preferences_DataGroupId_Promise_0300', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: '112233',
};
try{
dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.deletePreferences(globalThis.abilityContext, Options).then(async (val) => {
console.info(TAG, `deletePreferences successfully.`);
expect().assertFail();
done();
}).catch((error) => {
console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertFail();
done();
})
}catch(errInfo){
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('15501002');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0400
* @tc.name preferences dataGroupId null promise test
* @tc.desc preferences getPreferences dataGroupId null promise test
*/
it('SUB_DDM_Preferences_DataGroupId_Promise_0400', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: null,
};
try{
dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options).then(async (val) => {
console.info(TAG, `removePreferencesFromCache successfully.`);
expect().assertFail();
done();
}).catch((error) => {
console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertFail();
done();
})
}catch(errInfo){
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0500
* @tc.name preferences dataGroupId undefined promise test
* @tc.desc preferences removePreferencesFromCache dataGroupId undefined promise test
*/
it('SUB_DDM_Preferences_DataGroupId_Promise_0500', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: undefined,
};
try{
dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options).then(async (val) => {
console.info(TAG, `removePreferencesFromCache successfully.`);
expect().assertFail();
done();
}).catch((error) => {
console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertFail();
done();
})
}catch(errInfo){
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0600
* @tc.name preferences dataGroupId promise test
* @tc.desc preferences removePreferencesFromCache dataGroupId promise test
*/
it('SUB_DDM_Preferences_DataGroupId_Promise_0600', 0, async function (done) {
const Options = {
name: "test_preferences_callback",
dataGroupId: '112233',
};
try{
dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => {
console.info(TAG, `getPreferences successfully.`);
expect().assertFail();
done();
dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options).then(async (val) => {
console.info(TAG, `removePreferencesFromCache successfully.`);
expect().assertFail();
done();
}).catch((error) => {
console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`);
expect(err !== null).assertFail();
done();
})
}catch(errInfo){
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('15501002');
done();
}
})
console.log(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
{
"module": {
"name": "preferencesDataGroupId",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet",
"phone",
"2in1"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
......@@ -378,5 +378,31 @@ export default function PreferencesSyncTest() {
expect("default").assertEqual(mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "default"));
done();
})
/**
* @tc.number SUB_DDM_Preferences_removePreferencesFromCacheSync_0100
* @tc.name removePreferencesFromCacheSync interface test
* @tc.desc removePreferencesFromCacheSync interface test
*/
it('SUB_DDM_Preferences_removePreferencesFromCacheSync_0100', 0, async function (done) {
console.log("SUB_DDM_Preferences_removePreferencesFromCacheSync_0100 begin.");
mPreferences = await dataPreferences.getPreferences(context, NAME);
await mPreferences.clearSync();
await mPreferences.putSync(KEY_TEST_STRING_ELEMENT, 'test')
await mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")
mPreferences.flush(async function (err, val) {
if (err) {
console.log("flush err.");
expect().assertFail();
}
console.log("flush done.");
await dataPreferences.removePreferencesFromCacheSync(context, NAME);
let value = mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue")
console.log("SUB_DDM_Preferences_removePreferencesFromCacheSync_0100 end." + value);
expect('test').assertEqual(value);
done();
console.log("SUB_DDM_Preferences_removePreferencesFromCacheSync_0100 end.");
});
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2023 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
......@@ -16,8 +16,11 @@
import relationalStoreDistributedTest from './relationalStoreDistributedEtsunit.test.ets'
import relationalStoreTest from './relationalStoreEtsunit.test.ets'
import relationalStoreResultSetTest from './relationalStoreTestResultsetEtsunit.test.ets'
import relationalStoreEmitTest from './relationalStoreEmit.test'
export default function testsuite() {
relationalStoreDistributedTest(globalThis.abilityContext)
relationalStoreTest(globalThis.abilityContext)
relationalStoreResultSetTest(globalThis.abilityContext)
relationalStoreEmitTest()
}
/*
* Copyright (C) 2023 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 data_Rdb from '@ohos.data.relationalStore';
const TAG = "[RelationalStore_Emit_TEST]";
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "name TEXT NOT NULL, "
+ "age INTEGER, "
+ "salary REAL, "
+ "blobType BLOB)";
let rdbStore;
const STORE_CONFIG = {
name: "rdbstoreEmit.db",
securityLevel: data_Rdb.SecurityLevel.S1
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default function relationalStoreEmitTest() {
describe('relationalStoreEmitTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll');
})
beforeEach(async function () {
console.info(TAG + 'beforeEach');
rdbStore = await data_Rdb.getRdbStore(globalThis.abilityContext, STORE_CONFIG)
await rdbStore.executeSql(CREATE_TABLE_TEST);
})
afterEach(async function () {
console.info(TAG + 'afterAll');
data_Rdb.deleteRdbStore(globalThis.abilityContext, "rdbstoreEmit.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll');
})
console.info(TAG + "*************Unit Test Begin*************");
/**
* @tc.number SUB_DDM_RelationalStore_Emit_0100
* @tc.name relationalStore emit test
* @tc.desc relationalStore emit test
*/
it('testRdbStoreDistributed0012', 0, async function (done) {
async function subscribeInsert() {
console.info(TAG + "subscribeInsert start");
const valueBucket = {
"name": "zhangsan"
}
await rdbStore.insert("test", valueBucket)
console.info(TAG + "subscribeInsert end");
}
try {
await rdbStore.on('storeObserverInsert', false, subscribeInsert);
await rdbStore.emit('storeObserverInsert');
await sleep(2000);
let resultSet = await rdbStore.querySql("SELECT * FROM test");
console.info(TAG + "resultSet = " + resultSet.rowCount);
expect(1).assertEqual(resultSet.rowCount);
done();
} catch (err) {
console.error(`failed, code is ${err.code},message is ${err.message}`);
expect().assertFail()
done();
}
})
})
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.relationalstoredatagroupidtest",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"minAPIVersion": 10,
"targetAPIVersion": 10,
"car": {
"apiCompatibleVersion": 10,
"singleUser": false
}
}
}
# Copyright (C) 2023 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("ActsRelationalstoreDataGroupIdTest") {
hap_profile = "src/main/module.json"
deps = [
":relationalstoreDataGroupId_js_assets",
":relationalstoreDataGroupId_resources",
]
ets2abc = true
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsRelationalstoreDataGroupIdTest"
subsystem_name = "distributeddatamgr"
part_name = "relational_store"
}
ohos_app_scope("relationalstoreDataGroupId_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("relationalstoreDataGroupId_js_assets") {
source_dir = "src/main/ets"
}
ohos_resources("relationalstoreDataGroupId_resources") {
sources = [ "src/main/resources" ]
deps = [ ":relationalstoreDataGroupId_app_profile" ]
hap_profile = "src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "60000",
"shell-timeout": "60000",
"bundle-name": "ohos.acts.relationalstoredatagroupidtest",
"module-name": "relationalstoreDataGroupId"
},
"kits": [
{
"test-file-name": [
"ActsRelationalstoreDataGroupIdTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
/*
* Copyright (C) 2023 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 UIAbility from "@ohos.app.ability.UIAbility";
import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry";
import hilog from "@ohos.hilog";
import { Hypium } from "@ohos/hypium";
import testsuite from "../test/List.test";
import window from "@ohos.window";
export default class TestAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onCreate");
hilog.info(0x0000, "testTag", "%{public}s", "want param:" + JSON.stringify(want) ?? "");
hilog.info(0x0000, "testTag", "%{public}s", "launchParam:" + JSON.stringify(launchParam) ?? "");
var abilityDelegator: any;
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var abilityDelegatorArguments: any;
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments();
hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!");
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite);
}
onDestroy() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onDestroy");
}
onWindowStageCreate(windowStage: window.WindowStage) {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageCreate");
globalThis.abilityContext = this.context;
windowStage.loadContent("TestAbility/pages/Index", (err, data) => {
if (err.code) {
hilog.error(0x0000, "testTag", "Failed to load the content. Cause: %{public}s", JSON.stringify(err) ?? "");
return;
}
hilog.info(0x0000, "testTag", "Succeeded in loading the content. Data: %{public}s", JSON.stringify(data) ?? "");
});
}
onWindowStageDestroy() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageDestroy");
}
onForeground() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onForeground");
}
onBackground() {
hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onBackground");
}
}
/*
* Copyright (C) 2023 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 hilog from '@ohos.hilog';
@Entry
@Component
struct Index {
aboutToAppear() {
hilog.info(0x0000, 'testTag', '%{public}s', '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
import hilog from '@ohos.hilog';
import TestRunner from '@ohos.application.testRunner';
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
async function onAbilityCreateCallback() {
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
}
async function addAbilityMonitorCallback(err: any) {
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
}
async onRun() {
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
var debug = abilityDelegatorArguments.parameters['-D']
if (debug == 'true')
{
cmd += ' -D'
}
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
})
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
}
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 relationalStoreDataGroupIdCallback from './relationalStoreDataGroupIdCallback.test'
import relationalStoreDataGroupIdPromise from './relationalStoreDataGroupIdPromise.test'
export default function testsuite() {
relationalStoreDataGroupIdCallback()
relationalStoreDataGroupIdPromise()
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 relationalStore from '@ohos.data.relationalStore';
const TAG = "[ttt]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "name TEXT NOT NULL, "
+ "age INTEGER, "
+ "salary REAL, "
+ "blobType BLOB)";
let context = globalThis.abilityContext;
//let rdbStore;
export default function relationalStoreDataGroupIdCallback() {
describe('relationalStoreDataGroupIdCallback', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
beforeEach(function () {
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0100
* @tc.name relationalStore dataGroupId null callback test
* @tc.desc relationalStore getRdbStore dataGroupId null callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Callback_0100', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: null,
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) {
console.info(TAG, `Get RdbStore successfully.`);
expect().assertFail();
done();
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) {
expect(error).assertFail();
console.info(TAG, `Delete RdbStore successfully.`);
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0200
* @tc.name relationalStore dataGroupId undefined callback test
* @tc.desc relationalStore getRdbStore dataGroupId undefined callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Callback_0200', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: undefined,
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) {
console.info(TAG, `Get RdbStore successfully.`);
expect().assertFail();
done();
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) {
expect(error).assertFail();
console.info(TAG, `Delete RdbStore successfully.`);
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0300
* @tc.name relationalStore dataGroupId callback test
* @tc.desc relationalStore getRdbStore dataGroupId callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Callback_0300', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: '112233',
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) {
console.info(TAG, `Get RdbStore successfully.`);
expect().assertFail();
done();
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) {
expect(error).assertFail();
console.info(TAG, `Delete RdbStore successfully.`);
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('14801002')
done();
}
})
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0400
* @tc.name relationalStore dataGroupId callback test
* @tc.desc relationalStore deleteRdbStore dataGroupId callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Callback_0400', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: '123456'
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) {
if (err) {
console.error(TAG, `Get RdbStore failed, code is ${err.code},message is ${err.message}`);
return false;
}
console.info(TAG, `Get RdbStore successfully.` + ` rdbStore = ${rdbStore} , err = ${err}`);
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (err) {
if (err) {
console.error(TAG, `Delete RdbStore failed, code is ${err.code},message is ${err.message}`);
return false;
}
console.info(TAG, `Delete RdbStore successfully.` + ` rdbStore = ${rdbStore} , err = ${err}`);
expect(err === undefined).assertTrue()
done();
})
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo !== undefined).assertFail()
done();
}
})
console.log(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
/*
* Copyright (c) 2023 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 relationalStore from '@ohos.data.relationalStore';
const TAG = "[ttt]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "name TEXT NOT NULL, "
+ "age INTEGER, "
+ "salary REAL, "
+ "blobType BLOB)";
let rdbStore;
export default function relationalStoreDataGroupIdPromise() {
describe('relationalStoreDataGroupIdPromise', function () {
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0100
* @tc.name relationalStore dataGroupId null promise test
* @tc.desc relationalStore getRdbStore dataGroupId null promise test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Promise_0100', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: null,
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => {
console.info(TAG, `Get RdbStore successfully.`);
expect().assertFail();
done();
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async () => {
expect().assertFail();
console.info(TAG, `Delete RdbStore successfully.`);
done();
}).catch((error) => {
console.info(TAG, `Delete RdbStore fail, code is ${error.code},message is ${error.message}.`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`);
expect(err !== null).assertFail();
done();
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0200
* @tc.name relationalStore dataGroupId undefined callback test
* @tc.desc relationalStore getRdbStore dataGroupId undefined callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Promise_0200', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: undefined,
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => {
console.info(TAG, `Get RdbStore successfully.`);
expect().assertFail();
done();
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async () => {
expect().assertFail();
console.info(TAG, `Delete RdbStore successfully.`);
done();
}).catch((error) => {
console.info(TAG, `Delete RdbStore fail, code is ${error.code},message is ${error.message}.`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`);
expect(err !== null).assertFail();
done();
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('401');
done();
}
})
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0300
* @tc.name relationalStore dataGroupId callback test
* @tc.desc relationalStore getRdbStore dataGroupId callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Promise_0300', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: '112233',
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => {
console.info(TAG, `Get RdbStore successfully.`);
expect().assertFail();
done();
await rdbStore.executeSql(CREATE_TABLE_TEST);
relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async () => {
expect().assertFail();
console.info(TAG, `Delete RdbStore successfully.`);
done();
}).catch((error) => {
console.info(TAG, `Delete RdbStore fail, code is ${error.code},message is ${error.message}.`);
expect(error !== null).assertFail();
done();
})
}).catch((err) => {
console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`);
expect(err !== null).assertFail();
done();
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo.code).assertEqual('14801002');
done();
}
})
/**
* @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0400
* @tc.name relationalStore dataGroupId callback test
* @tc.desc relationalStore deleteRdbStore dataGroupId callback test
*/
it('SUB_DDM_RelationalStore_DataGroupId_Promise_0400', 0, async function (done) {
const STORE_CONFIG = {
name: "RdbTest.db",
securityLevel: relationalStore.SecurityLevel.S1,
dataGroupId: '123456',
};
try {
relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => {
console.info(TAG, `Get RdbStore successfully.`);
// await rdbStore.executeSql(CREATE_TABLE_TEST);
rdbStore.executeSql(CREATE_TABLE_TEST, [], async function (error) {
if (error) {
console.error(TAG, `ExecuteSql failed, code is ${error.code},message is ${error.message}`);
return;
}
console.info(TAG, `executeSql1 done.` + error);
expect(error === undefined).assertTrue();
await relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG)
done();
})
}).catch((err) => {
console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`);
expect(err !== null).assertFail();
done();
})
} catch (errInfo) {
console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`);
expect(errInfo !== null).assertFail();
done();
}
})
console.info(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
{
"module": {
"name": "relationalstoreDataGroupId",
"type": "feature",
"description": "$string:module_test_desc",
"mainElement": "TestAbility",
"deviceTypes": [
"default",
"tablet",
"phone",
"2in1"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:test_pages",
"abilities": [
{
"name": "TestAbility",
"srcEntry": "./ets/TestAbility/TestAbility.ets",
"description": "$string:TestAbility_desc",
"icon": "$media:icon",
"label": "$string:TestAbility_label",
"exported": true,
"startWindowIcon": "$media:icon",
"startWindowBackground": "$color:start_window_background",
"skills": [
{
"actions": [
"action.system.home"
],
"entities": [
"entity.system.home"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册