提交 881cd7a0 编写于 作者: P PaDaBoo

add relationalStoreJstest, update rdbStoreJstest and relationalStoreStagetest

Signed-off-by: NPaDaBoo <xuejianwu@huawei.com>
上级 e94d1422
......@@ -17,6 +17,7 @@ group("relationalStoretest") {
testonly = true
if (is_standard_system) {
deps = [
"RdbJstest/hap:rdb_js_test",
"relationalStoreJstest/hap:relationalstore_js_test",
"relationalStoreStagetest:relationalstore_ets_test",
]
......
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("rdb_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":rdb_js_assets",
":rdb_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsRdbJsTest"
subsystem_name = "distributeddatamgr"
part_name = "relational_store"
}
ohos_js_assets("rdb_js_assets") {
js2abc = true
hap_profile = "./src/main/config.json"
source_dir = "./src/main/js"
}
ohos_resources("rdb_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "1000000",
"shell-timeout": "1000000",
"bundle-name": "ohos.acts.rdbjstest",
"package-name": "ohos.acts.rdbjstest"
},
"kits": [
{
"test-file-name": [
"ActsRdbJsTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}
]
}
\ No newline at end of file
{
"app": {
"bundleName": "ohos.acts.rdbjstest",
"vendor": "example",
"version": {
"code": 1,
"name": "1.0"
},
"apiVersion": {
"compatible": 4,
"target": 5
}
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.rdbjstest",
"name": ".entry",
"deviceType": [
"tablet",
"default",
"phone"
],
"distro": {
"deliveryWithInstall": true,
"moduleName": "entry",
"moduleType": "entry"
},
"abilities": [
{
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
],
"orientation": "unspecified",
"formsEnabled": false,
"name": ".MainAbility",
"srcLanguage": "js",
"srcPath": "MainAbility",
"icon": "$media:icon",
"description": "$string:MainAbility_desc",
"label": "$string:MainAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
},
{
"orientation": "unspecified",
"formsEnabled": false,
"name": ".TestAbility",
"srcLanguage": "js",
"srcPath": "TestAbility",
"icon": "$media:icon",
"description": "$string:TestAbility_desc",
"label": "$string:TestAbility_label",
"type": "page",
"visible": true,
"launchType": "standard"
}
],
"js": [
{
"pages": [
"pages/index/index"
],
"name": "default",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
},
{
"pages": [
"pages/index/index"
],
"name": ".TestAbility",
"window": {
"designWidth": 720,
"autoDesignWidth": false
}
}
],
"testRunner": {
"name": "OpenHarmonyTestRunner",
"srcPath": "TestRunner"
},
"mainAbility": ".MainAbility",
"srcPath": ""
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
onCreate() {
console.info('TestApplication onCreate');
},
onDestroy() {
console.info('TestApplication onDestroy');
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.container {
flex-direction: column;
justify-content: center;
align-items: center;
}
.title {
font-size: 100px;
}
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{title}}
</text>
</div>
/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const injectRef = Object.getPrototypeOf(global) || global
injectRef.regeneratorRuntime = require('@babel/runtime/regenerator')
export default {
data: {
title: ''
},
onInit() {
this.title = this.$t('strings.world');
},
onShow() {
console.info('onShow finish')
},
onReady() {
},
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../test/List.test'
export default {
onCreate() {
console.info('TestApplication onCreate')
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
},
onDestroy() {
console.info("TestApplication onDestroy");
}
};
{
"strings": {
"hello": "Hello",
"world": "World"
},
"Files": {
}
}
\ No newline at end of file
{
"strings": {
"hello": "您好",
"world": "世界"
},
"Files": {
}
}
\ No newline at end of file
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
}
.title {
font-size: 60px;
text-align: center;
width: 100%;
height: 40%;
margin: 10px;
}
@media screen and (device-type: phone) and (orientation: landscape) {
.title {
font-size: 60px;
}
}
@media screen and (device-type: tablet) and (orientation: landscape) {
.title {
font-size: 100px;
}
}
\ No newline at end of file
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
data: {
title: ""
},
onInit() {
this.title = this.$t('strings.world');
}
}
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s itName',
'-s level', '-s testType', '-s size', '-s timeout',
'-s package', '-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams += ' ' + key + ' ' + parameters[key]
}
}
return targetParams.trim()
}
export default {
onPrepare() {
console.info('OpenHarmonyTestRunner OnPrepare')
},
onRun() {
console.log('OpenHarmonyTestRunner onRun run')
var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility'
var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
console.info('debug value : '+debug)
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd, (err, data) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + data.stdResult);
console.info('executeShellCommand : data : ' + data.exitCode);
})
}
};
/*
* Copyright (c) 2021-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 rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js'
import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js'
import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js'
import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js'
import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js'
import rdbStorePredicatesJoinTest from './RdbstorePredicatesJoinJsunit.test.js'
import rdbPredicatesTest from './RdbstorePredicatesJsunit.test.js'
import rdbStoreTest from './RdbstoreRdbstoreJsunit.test.js'
import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js'
import rdbstoreStoreExcuteSqlTest from './RdbstoreStoreExcuteSqlJsunit.test.js'
import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js'
import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js'
import rdbstoreQueryTest from './RdbstoreQuery.test.js'
import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js'
import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js'
export default function testsuite() {
rdbStoreBackupRestoreCallbackTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreDeleteTest()
rdbStoreDistributedTest()
rdbstoreInsertTest()
rdbStorePredicatesJoinTest()
rdbPredicatesTest()
rdbStoreTest()
rdbResultSetTest()
rdbstoreStoreExcuteSqlTest()
rdbstoreTransactionTest()
rdbStoreUpdateTest()
rdbstoreQueryTest()
rdbStoreEncryptionTest()
rdbStorePredicatesComplexFiledTest()
}
......@@ -309,34 +309,6 @@ describe('rdbStoreDistributedTest', function () {
done();
console.info(TAG + "************* testRdbStoreDistributed0011 end *************");
})
/**
* @tc.name sync test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Distributed_syncV9_0100
* @tc.desc sync test
*/
it('SUB_DDM_AppDataFWK_JSRDB_Distributed_syncV9_0100', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Distributed_syncV9_0100 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S1
}
await dataRdb.getRdbStoreV9(context, config, 1).then(async (store) => {
let predicates = new dataRdb.RdbPredicatesV9("employee")
predicates = predicates.inDevices("12345678abcd");
try {
store.sync(dataRdb.SyncMode.SYNC_MODE_PUSH, predicates);
} catch (err) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.info(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Distributed_syncV9_0100 end *************");
})
/**
* @tc.name sync Callback test
......
......@@ -23,7 +23,7 @@ const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIM
const STORE_CONFIG = {
name: "Query.db",
}
const TEST_BUNDLE_NAME="ohos.acts.relationalStorejstest"
const TEST_BUNDLE_NAME="ohos.acts.rdbjstest"
var kvManager = null
var kvStore = null
......
{
"string": [
{
"name": "app_name",
"value": "MyApplication"
},
{
"name": "mainability_description",
"value": "hap sample empty page"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "label"
},
{
"name": "TestAbility_desc",
"value": "description"
},
{
"name": "TestAbility_label",
"value": "label"
}
]
}
......@@ -4,8 +4,8 @@
"type": "OHJSUnitTest",
"test-timeout": "1000000",
"shell-timeout": "1000000",
"bundle-name": "ohos.acts.relationalStorejstest",
"package-name": "ohos.acts.relationalStorejstest"
"bundle-name": "ohos.acts.relationalstorejstest",
"package-name": "ohos.acts.relationalstorejstest"
},
"kits": [
{
......
{
"app": {
"bundleName": "ohos.acts.relationalStorejstest",
"bundleName": "ohos.acts.relationalstorejstest",
"vendor": "example",
"version": {
"code": 1,
......@@ -13,11 +13,11 @@
},
"deviceConfig": {},
"module": {
"package": "ohos.acts.relationalStorejstest",
"package": "ohos.acts.relationalstorejstest",
"name": ".entry",
"deviceType": [
"tablet",
"default",
"tablet",
"default",
"phone"
],
"distro": {
......
......@@ -12,35 +12,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js'
import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js'
import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js'
import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js'
import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js'
import rdbStorePredicatesJoinTest from './RdbstorePredicatesJoinJsunit.test.js'
import rdbPredicatesTest from './RdbstorePredicatesJsunit.test.js'
import rdbStoreTest from './RdbstoreRdbstoreJsunit.test.js'
import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js'
import rdbstoreStoreExcuteSqlTest from './RdbstoreStoreExcuteSqlJsunit.test.js'
import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js'
import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js'
import rdbstoreQueryTest from './RdbstoreQuery.test.js'
import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js'
import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js'
import relationalStoreBackupRestoreCallbackTest from './RelationalStoreBackupRestoreCallbackJsunit.test.js'
import relationalStoreBackupRestoreWithFAContextTest from './RelationalStoreBackupRestoreWithFAContextJsunit.test.js'
import relationalStoreDeleteTest from './RelationalStoreDeleteJsunit.test.js'
import relationalStoreDistributedTest from './RelationalStoreDistributedJsunit.test.js'
import relationalStoreInsertTest from './RelationalStoreInsertJsunit.test.js'
import relationalStorePredicatesJoinTest from './RelationalStorePredicatesJoinJsunit.test.js'
import relationalStorePredicatesTest from './RelationalStorePredicatesJsunit.test.js'
import relationalStoreTest from './RelationalStoreJsunit.test.js'
import relationalStoreResultSetTest from './RelationalStoreResultSetJsunit.test.js'
import relationalStoreExcuteSqlTest from './RelationalStoreExcuteSqlJsunit.test.js'
import relationalStoreTransactionTest from './RelationalStoreTransactionJsunit.test.js'
import relationalStoreUpdateTest from './RelationalStoreUpdateJsunit.test.js'
import relationalStoreQueryTest from './RelationalStoreQuery.test.js'
import relationalStoreEncryptionTest from './RelationalStoreEncryptionJsunit.test.js'
import relationalStorePredicatesComplexFiledTest from './RelationalStorePredicatesComplexFiledJsunit.test.js'
export default function testsuite() {
rdbStoreBackupRestoreCallbackTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreDeleteTest()
rdbStoreDistributedTest()
rdbstoreInsertTest()
rdbStorePredicatesJoinTest()
rdbPredicatesTest()
rdbStoreTest()
rdbResultSetTest()
rdbstoreStoreExcuteSqlTest()
rdbstoreTransactionTest()
rdbStoreUpdateTest()
rdbstoreQueryTest()
rdbStoreEncryptionTest()
rdbStorePredicatesComplexFiledTest()
relationalStoreBackupRestoreCallbackTest()
relationalStoreBackupRestoreWithFAContextTest()
relationalStoreDeleteTest()
relationalStoreDistributedTest()
relationalStoreInsertTest()
relationalStorePredicatesJoinTest()
relationalStorePredicatesTest()
relationalStoreTest()
relationalStoreResultSetTest()
relationalStoreExcuteSqlTest()
relationalStoreTransactionTest()
relationalStoreUpdateTest()
relationalStoreQueryTest()
relationalStoreEncryptionTest()
relationalStorePredicatesComplexFiledTest()
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore'
import ability_featureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio'
const TAG = "[RelationalStore_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS backupTest (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"
const DATABASE_DIR = "/data/storage/el2/database/entry/rdb/"
var RdbStore
var context = ability_featureAbility.getContext()
const STORE_CONFIG = {
name: "BackupResotreTest.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
const DATABASE_BACKUP_NAME = "Backup.db"
async function CreatRdbStore(context, STORE_CONFIG) {
let RdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1)
await RdbStore.executeSql(CREATE_TABLE_TEST, null)
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await RdbStore.insert("backupTest", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await RdbStore.insert("backupTest", valueBucket)
}
{
const valueBucket = {
"name": "wangwu",
"age": 38,
"salary": 90.0,
"blobType": u8,
}
await RdbStore.insert("backupTest", valueBucket)
}
return RdbStore
}
function BackupCallbackTest(backupName) {
try {
RdbStore.backup(backupName, (err, data) => {
if(err != null){
console.info(TAG + "Backup error: " + err)
expect(true).assertTrue()
}else{
expect(false).assertTrue();
}
})
} catch(errInfo){
console.info(TAG + "BackupCallbackTest error: " + errInfo)
expect(true).assertTrue()
}
RdbStore = null
}
function ReStoreCallbackTest(restoreName) {
try {
RdbStore.restore(restoreName, (err, data) => {
if(err != null){
console.info(TAG + "Restore error: " + err)
expect(true).assertTrue()
}else{
expect(false).assertTrue();
}
})
} catch(errInfo) {
console.info(TAG + "ReStoreCallbackTest error: " + errInfo)
expect(true).assertTrue()
}
RdbStore = null
}
export default function relationalStoreBackupRestoreCallbackTest() {
describe('relationalStoreBackupRestoreCallbackTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
RdbStore = await CreatRdbStore(context, STORE_CONFIG)
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME)
await data_Rdb.deleteRdbStore(context, "BackupTest003.db")
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.info(TAG + "*************Unit Test Begin*************")
/**
* @tc.name RelationalStore Backup Restore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0100
* @tc.desc RelationalStore backup and restore function test
*/
it('RdbBackupRestoreCallbackTest_0100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 start *************")
// RelationalStore backup function test
await RdbStore.backup(DATABASE_BACKUP_NAME,async (err, data) => {
if(err != null){
expect(false).assertTrue()
}else{
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
expect(false).assertTrue()
}
}
// RelationalStore before restored, delete data
let deleteData = new data_Rdb.RdbPredicates("backupTest")
deleteData.equalTo("name", "zhangsan")
RdbStore.delete(deleteData).then(()=> {
RdbStore.restore(DATABASE_BACKUP_NAME, async (err, data) => {
if(err != null){
expect(false).assertTrue()
}else{
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue()
} catch (err) {
expect(true).assertTrue()
}
try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
expect(false).assertTrue()
}
let predicates = new data_Rdb.RdbPredicates("backupTest")
predicates.equalTo("name", "zhangsan")
let resultSet = await RdbStore.query(predicates)
try {
console.info(TAG + "After restore resultSet query done")
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(1).assertEqual(id)
expect("zhangsan").assertEqual(name)
expect(1).assertEqual(blobType[0])
} catch (err) {
console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err)
expect(false).assertTrue()
}
resultSet = null
RdbStore = null
}
done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 end *************")
})
})
})
})
/**
* @tc.name RelationalStore Backup test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0200
* @tc.desc RelationalStore backup function test
*/
it('RdbBackupRestoreCallbackTest_0200', 0, function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 start *************")
// RelationalStore backup function test, backup file name empty
BackupCallbackTest("")
// RelationalStore backup function test, backup file name already exists
BackupCallbackTest(STORE_CONFIG.name)
done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0300
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0300', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 start *************")
let backupName = "BackupTest003.db"
await RdbStore.backup(backupName)
// RelationalStore restore function test, backup file name empty
ReStoreCallbackTest("")
// RelationalStore restore function test, backup file is specified to database name
ReStoreCallbackTest(STORE_CONFIG.name)
done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0400
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0400', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 start *************")
let dbName = "notExistName.db"
// RelationalStore restore function test, backup file does not exists
try {
fileio.accessSync(DATABASE_DIR + dbName)
expect(false).assertTrue()
} catch {
ReStoreCallbackTest(dbName)
}
done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0500
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0500', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 start *************")
// RelationalStore restore function test, backup file
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}else{
try{
console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
expect(false).assertTrue();
}
data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => {
try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
console.info(TAG + 'error2 ' + err)
expect(true).assertTrue();
}
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
console.info(`${TAG} Backup database second failed, error: message: ${err.message}`)
expect(true).assertTrue()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
}else{
try{
console.info(TAG + 'Backup database second success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
expect(false).assertTrue();
}
}
})
})
}
})
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0600
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0600', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 start *************")
// Backup file is specified to database name
RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){
expect(true).assertTrue()
}else{
expect(false).assertTrue()
}
})
RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){
expect(true).assertTrue()
}else{
expect(false).assertTrue()
}
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0700
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0700', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 start *************")
let DATABASE_BACKUP_TEST_NAME = "BackupTest.db"
RdbStore.backup(DATABASE_BACKUP_TEST_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}else{
expect(true).assertTrue()
}
})
await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME).then(() => {
try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME)
}catch(err){
expect(true).assertTrue();
}
})
RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => {
if(err != null){
expect(true).assertTrue()
}
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0800
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0800', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 start *************")
BackupCallbackTest()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0900
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_0900', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 start *************")
BackupCallbackTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1000
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_1000', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}
})
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1100
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_1100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}
})
ReStoreCallbackTest()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1200
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_1200', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}
})
BackupCallbackTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1300
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_1300', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}else{
RdbStore.restore(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
}else{
ReStoreCallbackTest(DATABASE_BACKUP_NAME)
}
})
}
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 end *************")
})
console.info(TAG + "*************Unit Test End*************")
})
}
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore'
import ability_featureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio'
const TAG = "[RelationalStore_JSKITS_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)"
const DATABASE_DIR = "/data/storage/el2/database/entry/rdb/"
var RdbStore
var context = ability_featureAbility.getContext()
const STORE_CONFIG = {
name: "BackupResotreTest.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
const DATABASE_BACKUP_NAME = "Backup.db"
async function CreatRdbStore(context, STORE_CONFIG) {
let RdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1)
await RdbStore.executeSql(CREATE_TABLE_TEST, null)
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await RdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await RdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "wangwu",
"age": 38,
"salary": 90.0,
"blobType": u8,
}
await RdbStore.insert("test", valueBucket)
}
return RdbStore
}
async function BackupTest(backupName) {
try {
let promiseRestore = RdbStore.backup(backupName)
promiseRestore.then(() => {
expect(false).assertTrue()
}).catch((err) => {
console.info(TAG + "Backup error: " + err)
expect(true).assertTrue()
})
await promiseRestore
} catch(errInfo){
console.info(TAG + "BackupTest error: " + errInfo)
expect(true).assertTrue()
}
RdbStore = null
}
async function ReStoreTest(restoreName) {
try {
let promiseRestore = RdbStore.restore(restoreName)
promiseRestore.then(() => {
expect(false).assertTrue()
}).catch((err) => {
console.info(TAG + "Restore error: " + err)
expect(true).assertTrue()
})
await promiseRestore
} catch(errInfo) {
console.info(TAG + "ReStoreTest error: " + errInfo)
expect(true).assertTrue()
}
RdbStore = null
}
export default function relationalStoreBackupRestorePromiseTest() {
describe('relationalStoreBackupRestorePromiseTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
RdbStore = await CreatRdbStore(context, STORE_CONFIG)
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME)
await data_Rdb.deleteRdbStore(context, "BackupTest003.db")
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.info(TAG + "*************Unit Test Begin*************")
/**
* @tc.name RelationalStore Backup Restore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0010
* @tc.desc RelationalStore backup and restore function test
*/
it('RdbBackupRestoreTest_0010', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RelationalStore backup function test
RdbStore.backup(DATABASE_BACKUP_NAME).then(async() => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
console.info("RdbBackupRestoreTest_0010 backup success")
expect(false).assertTrue()
}
// RelationalStore before restored, delete data
let deleteData = new data_Rdb.RdbPredicates("test")
deleteData.equalTo("name", "zhangsan")
await RdbStore.delete(deleteData)
// RelationalStore restore function test
RdbStore.restore(DATABASE_BACKUP_NAME).then(async () => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue()
} catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success")
expect(true).assertTrue()
}
try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success2")
expect(false).assertTrue()
}
// RelationalStore after restored, data query test
let predicates = new data_Rdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan")
RdbStore.query(predicates).then((resultSet)=>{
try {
console.info(TAG + "After restore resultSet query done")
resultSet.goToFirstRow();
expect(true).assertEqual(resultSet.goToFirstRow())
console.info("RdbBackupRestoreTest_0010 goto first row success")
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
console.info("RdbBackupRestoreTest_0010 get dolumnindex id success")
const name = resultSet.getString(resultSet.getColumnIndex("name"))
console.info("RdbBackupRestoreTest_0010 get dolumnindex name success")
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
console.info(`RdbBackupRestoreTest_0010 id is ${id},name id ${name},blobType is ${blobType[0]}`)
expect(1).assertEqual(id)
expect("zhangsan").assertEqual(name)
expect(1).assertEqual(blobType[0])
} catch (err) {
console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err)
expect(false).assertTrue()
}
resultSet = null
RdbStore = null
done()
console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************")
})
}).catch((err) => {
console.info("RdbBackupRestoreTest_0010 restore error: " + err)
expect(false).assertTrue()
})
}).catch((err) => {
expect(false).assertTrue()
})
})
/**
* @tc.name RelationalStore Backup test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0020
* @tc.desc RelationalStore backup function test
*/
it('RdbBackupRestoreTest_0020', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0020 start *************")
// RelationalStore backup function test, backup file name empty
BackupTest("")
// RelationalStore backup function test, backup file name already exists
BackupTest(STORE_CONFIG.name)
done()
console.info(TAG + "************* RdbBackupRestoreTest_0020 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0030
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0030', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0030 start *************")
let backupName = "BackupTest003.db"
await RdbStore.backup(backupName)
// RelationalStore restore function test, backup file name empty
ReStoreTest("")
// RelationalStore restore function test, backup file is specified to database name
ReStoreTest(STORE_CONFIG.name)
done()
console.info(TAG + "************* RdbBackupRestoreTest_0030 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0040
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0040', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0040 start *************")
let dbName = "notExistName.db"
// RelationalStore restore function test, backup file does not exists
try {
fileio.accessSync(DATABASE_DIR + dbName)
expect(false).assertTrue()
} catch {
ReStoreTest(dbName)
}
done()
console.info(TAG + "************* RdbBackupRestoreTest_0040 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0050
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0050', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0050 start *************")
// RelationalStore restore function test, backup file
await RdbStore.backup(DATABASE_BACKUP_NAME).then(() => {
try{
console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
expect(false).assertTrue();
}
}).then(() => {
data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => {
try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
console.info(TAG + 'error2 ' + err)
expect(true).assertTrue();
}
})
}).then(() => {
RdbStore.backup(DATABASE_BACKUP_NAME).then(() => {
try{
console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
console.info(TAG + 'error3 ' + err)
expect(false).assertTrue()
}
})
})
done()
console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0060
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0060', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0060 start *************")
// Backup file is specified to database name
RdbStore.backup(STORE_CONFIG.name).then(() => {
console.info(TAG + 'Backup database finish');
expect(false).assertTrue() ;
}).catch((err) => {
console.info(TAG + "Backup database error");
expect(true).assertTrue() ;
done();
})
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0070
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0070', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0070 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME)
try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
expect(true).assertTrue();
}
await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => {
console.info(TAG + 'Restore fail: ' + err)
expect(true).assertTrue();
})
done();
console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0080
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0080', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0080 start *************")
BackupTest()
done();
console.info(TAG + "************* RdbBackupRestoreTest_0080 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0090
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0090', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0090 start *************")
BackupTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreTest_0090 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0100
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0110
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0110', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest()
done();
console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0120
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0120', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
BackupTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************")
})
/**
* @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0130
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreTest_0130', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0130 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
await RdbStore.restore(DATABASE_BACKUP_NAME)
ReStoreTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************")
})
console.info(TAG + "*************Unit Test End*************")
})
}
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility'
const TAG = '[RelationalStore_JSKITS_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)';
const STORE_CONFIG = {
name: 'Delete.db',
securityLevel: data_Rdb.SecurityLevel.S1
}
let rdbStore = undefined;
var context = ability_featureAbility.getContext()
export default function relationalStoreDeleteTest() {
describe('relationalStoreDeleteTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await rdbStore.executeSql('DELETE FROM test');
rdbStore = null
await data_Rdb.deleteRdbStore(context, 'Delete.db');
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.info(TAG + '*************Unit Test Begin*************');
/**
* @tc.name RelationalStore delete test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0010
* @tc.desc RelationalStore delete test
*/
it('testRdbStoreDelete0001', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0001 start *************');
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
'name': 'zhangsan',
'age': 18,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 28,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 38,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
//删除
{
let predicates = new data_Rdb.RdbPredicates('test')
rdbStore.delete(predicates).then(async (ret) => {
expect(3).assertEqual(ret)
console.info(TAG + 'Delete done: ' + ret)
done()
console.info(TAG + '************* testRdbStoreDelete0001 end *************');
}).catch((err) => {
expect(null).assertFail()
})
}
})
/**
* @tc.name RelationalStore delete test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0020
* @tc.desc RelationalStore delete test
*/
it('testRdbStoreDelete0002', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0002 start *************');
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
'name': 'zhangsan',
'age': 18,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 28,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 38,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
//删除
{
let predicates = await new data_Rdb.RdbPredicates('test')
predicates.equalTo('name', 'zhangsan')
rdbStore.delete(predicates).then(async (ret) => {
expect(1).assertEqual(ret)
console.info(TAG + 'Delete done: ' + ret)
done()
console.info(TAG + '************* testRdbStoreDelete0002 end *************');
}).catch((err) => {
expect(null).assertFail()
})
}
})
/**
* @tc.name RelationalStore delete test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0030
* @tc.desc RelationalStore delete test
*/
it('testRdbStoreDelete0003', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0003 start *************');
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
'name': 'zhangsan',
'age': 18,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 28,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
//删除前查询
{
let predicates = await new data_Rdb.RdbPredicates('test')
predicates.equalTo('age', 28)
let resultSet = await rdbStore.query(predicates)
expect(1).assertEqual(resultSet.rowCount)
}
//删除
let predicates = await new data_Rdb.RdbPredicates('test')
predicates.equalTo('age', 28)
rdbStore.delete(predicates).then(async (ret) => {
expect(1).assertEqual(ret)
console.info(TAG + 'Delete done: ' + ret)
//删除后查询
let predicates = await new data_Rdb.RdbPredicates('test')
predicates.equalTo('age', 28)
let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount)
done()
console.info(TAG + '************* testRdbStoreDelete0003 end *************');
}).catch((err) => {
expect(null).assertFail()
})
})
/**
* @tc.name RelationalStore delete test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0040
* @tc.desc RelationalStore delete test
*/
it('testRdbStoreDelete0004', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0004 start *************');
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
'name': 'zhangsan',
'age': 18,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 28,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 38,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
//删除
{
let predicates = await new data_Rdb.RdbPredicates('test')
predicates.equalTo('aaa id', 1)
rdbStore.delete(predicates).then(async (ret) => {
console.info(TAG + 'delete done: ' + ret)
expect(null).assertFail()
}).catch((err) => {
console.info(TAG + 'delete with wrong conditions')
done();
console.info(TAG + '************* testRdbStoreDelete0004 end *************');
})
}
})
/**
* @tc.name RelationalStore delete test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0050
* @tc.desc RelationalStore delete test
*/
it('testRdbStoreDelete0005', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0005 start *************');
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
'name': 'zhangsan',
'age': 18,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 28,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 38,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
//删除
{
let predicates = await new data_Rdb.RdbPredicates('test')
predicates.equalTo('name', 'lisi')
rdbStore.delete(predicates).then(async (ret) => {
expect(2).assertEqual(ret)
console.info(TAG + 'Delete done: ' + ret)
done()
console.info(TAG + '************* testRdbStoreDelete0005 end *************');
}).catch((err) => {
expect(null).assertFail()
})
}
})
/**
* @tc.name RelationalStore delete test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0060
* @tc.desc RelationalStore delete test
*/
it('testRdbStoreDelete0006', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0006 start *************');
let errInfo = undefined;
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
'name': 'zhangsan',
'age': 18,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 28,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
{
const valueBucket = {
'name': 'lisi',
'age': 38,
'salary': 100.5,
'blobType': u8,
}
await rdbStore.insert('test', valueBucket)
}
//删除
try{
let predicates = await new data_Rdb.RdbPredicates('')
rdbStore.delete(predicates).then(async (ret) => {
console.info(TAG + 'delete done: ' + ret)
expect(null).assertFail()
}).catch((err) => {
console.info(TAG + 'delete with null')
})
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done()
console.info(TAG + '************* testRdbStoreDelete0006 end *************');
})
console.info(TAG + '*************Unit Test End*************');
})}
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium';
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility';
var context = ability_featureAbility.getContext();
var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT NOT NULL," +"age INTEGER)"
sqlStatement = "CREATE TABLE IF NOT EXISTS product (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT NOT NULL," +"price REAL," +
"vendor INTEGER," +"describe TEXT)"
const TAG = "[RelationalStore_JSKITS_TEST_Distributed]"
const STORE_NAME = "distributed_rdb.db"
var rdbStore = undefined;
const config = {
"name": STORE_NAME,
securityLevel: data_Rdb.SecurityLevel.S1
}
async function executeSql1() {
let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT NOT NULL," +
"age INTEGER)"
try {
await rdbStore.executeSql(sqlStatement, null)
console.info(TAG + "create table employee success")
} catch (err) {
console.info(TAG + "create table employee failed")
expect(null).assertFail()
}
}
async function executeSql2() {
let sqlStatement = "CREATE TABLE IF NOT EXISTS product (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT NOT NULL," +
"price REAL," +
"vendor INTEGER," +
"describe TEXT)"
try {
await rdbStore.executeSql(sqlStatement, null)
console.info(TAG + "create table product success")
} catch (err) {
console.info(TAG + "create table product failed")
expect(null).assertFail()
}
}
export default function relationalStoreDistributedTest() {
describe('relationalStoreDistributedTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await data_Rdb.getRdbStore(context, config, 1);
console.info(TAG + "create RelationalStore store success")
await executeSql1()
await executeSql2()
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
})
afterEach(async function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
await data_Rdb.deleteRdbStore(context, STORE_NAME);
})
console.info(TAG + "*************Unit Test Begin*************");
/**
* @tc.name set_distributed_table_none_table
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_002
* @tc.desc RelationalStore set distributed table using none table as argment
*/
it('testRdbStoreDistributed0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed002 start *************");
try {
await rdbStore.setDistributedTables([])
console.info(TAG + "set none to be distributed table success");
expect(rdbStore).assertEqual(rdbStore)
} catch (err) {
console.info(TAG + "set none to be distributed table failed");
expect(null).assertFail();
}
done()
console.info(TAG + "************* testRdbStoreDistributed002 end *************");
})
/**
* @tc.name set distributed table using one table name
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_003
* @tc.desc set distributed table using one table name
*/
it('testRdbStoreDistributed0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed003 start *************");
try {
await rdbStore.setDistributedTables(['employee'])
console.info(TAG + "set employee to be distributed table success");
expect(rdbStore).assertEqual(rdbStore)
} catch (err) {
console.info(TAG + "set employee to be distributed table failed");
expect(null).assertFail();
}
done()
console.info(TAG + "************* testRdbStoreDistributed003 end *************");
})
/**
* @tc.name set distributed table using two table name
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_004
* @tc.desc set distributed table using two table name
*/
it('testRdbStoreDistributed0004', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed004 start *************");
try {
await rdbStore.setDistributedTables(['employee', 'product'])
console.info(TAG + "set employee and product to be distributed table success");
expect(rdbStore).assertEqual(rdbStore)
} catch (err) {
console.info(TAG + "set employee and product to be distributed table failed");
expect(null).assertFail();
}
done()
console.info(TAG + "************* testRdbStoreDistributed004 end *************");
})
/**
* @tc.name insert record after setting distributed table
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_005
* @tc.desc insert record after setting distributed table
*/
it('testRdbStoreDistributed0005', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed005 start *************");
const record = {
"name": "Jim",
"age": 20,
}
try {
let rowId = await rdbStore.insert("employee", record)
console.info(TAG + "insert one record success " + rowId)
expect(1).assertEqual(rowId)
} catch (err) {
console.info(TAG + "insert one record failed" + err);
expect(null).assertFail();
}
done()
console.info(TAG + "************* testRdbStoreDistributed005 end *************");
})
/**
* @tc.name update record after setting distributed table
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_006
* @tc.desc update record after setting distributed table
*/
it('testRdbStoreDistributed0006', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed006 start *************");
const record = {
"name": "Jim",
"age": 30,
}
try {
let predicate = new data_Rdb.RdbPredicates("employee");
predicate.equalTo("id", 1);
try {
let rowId = await rdbStore.update(record, predicate);
console.info(TAG + "update one record success " + rowId)
expect(1).assertEqual(rowId)
} catch (err) {
console.info(TAG + "update one record failed" + err);
expect(null).assertFail();
}
} catch (err) {
console.info(TAG + "construct predicate failed");
expect(null).assertFail();
}
done()
console.info(TAG + "************* testRdbStoreDistributed006 end *************");
})
/**
* @tc.name query record after setting distributed table
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_007
* @tc.desc query record after setting distributed table
*/
it('testRdbStoreDistributed0007', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0007 start *************");
try {
let predicates = new data_Rdb.RdbPredicates("employee")
let resultSet = await rdbStore.query(predicates)
try {
console.info(TAG + "product resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
await expect(1).assertEqual(id);
await expect("Jim").assertEqual(name);
await expect(30).assertEqual(age);
resultSet.close();
expect(true).assertEqual(resultSet.isClosed)
} catch (e) {
console.info(TAG + "result get value failed")
expect(null).assertFail();
}
} catch (err) {
console.info("query failed");
expect(null).assertFail();
}
done();
console.info(TAG + "************* testRdbStoreDistributed0007 end *************");
})
/**
* @tc.name delete record after setting distributed table
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_008
* @tc.desc delete record after setting distributed table
*/
it('testRdbStoreDistributed0008', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0008 start *************");
let predicates = new data_Rdb.RdbPredicates("employee")
try {
let number = await rdbStore.delete(predicates)
console.info(TAG + "employee Delete done: " + number)
expect(1).assertEqual(number)
} catch (err) {
console.info(TAG + "delete record failed");
expect(null).assertFail()
}
done();
console.info(TAG + "************* testRdbStoreDistributed0008 end *************");
})
/**
* @tc.name predicates inDevice
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_009
* @tc.desc predicates inDevice
*/
it('testRdbStoreDistributed0009', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0009 start *************");
let predicates = new data_Rdb.RdbPredicates("employee")
try {
predicates = predicates.inDevices("1234567890");
console.info(TAG + "inDevices success");
expect(predicates).assertEqual(predicates);
} catch (err) {
console.info(TAG + "inDevices failed");
expect(null).assertFail();
}
done();
console.info(TAG + "************* testRdbStoreDistributed0009 end *************");
})
/**
* @tc.name predicates inAllDevices
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_010
* @tc.desc predicates inAllDevices
*/
it('testRdbStoreDistributed0010', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0010 start *************");
let predicates = new data_Rdb.RdbPredicates("employee")
try {
predicates = predicates.inAllDevices();
console.info(TAG + "inAllDevices success");
expect(predicates).assertEqual(predicates);
} catch (err) {
console.info(TAG + "inAllDevices failed");
expect(null).assertFail();
}
done();
console.info(TAG + "************* testRdbStoreDistributed0010 end *************");
})
/**
* @tc.name sync test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_011
* @tc.desc sync test
*/
it('testRdbStoreDistributed0011', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0011 start *************");
let predicates = new data_Rdb.RdbPredicates("employee")
predicates = predicates.inDevices("12345678abcd");
rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates);
console.info(TAG + "sync push success");
expect(rdbStore).assertEqual(rdbStore);
rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates);
console.info(TAG + "sync pull success");
expect(rdbStore).assertEqual(rdbStore);
done();
console.info(TAG + "************* testRdbStoreDistributed0011 end *************");
})
/**
* @tc.name sync Callback test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_Callback_011
* @tc.desc sync Callback test
*/
it('testRdbStoreDistributedCallback0011', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributedCallback0011 start *************");
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let predicates = new data_Rdb.RdbPredicates("employee")
predicates = predicates.inDevices("12345678abcd");
rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates,(err,ret)=>{
console.info(TAG + "sync push success");
expect(rdbStore).assertEqual(rdbStore);
rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates,(err,ret)=>{
console.info(TAG + "sync push success");
expect(rdbStore).assertEqual(rdbStore);
});
done();
});
await sleep(2000)
done();
console.info(TAG + "************* testRdbStoreDistributedCallback0011 end *************");
})
/**
* @tc.name subscribe test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_012
* @tc.desc subscribe test
*/
it('testRdbStoreDistributed0012', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0012 start *************");
rdbStore.on("dataChange", (device) => {
console.info(TAG + device + " dataChange");
});
console.info(TAG + "on dataChange success");
expect(rdbStore).assertEqual(rdbStore);
done()
console.info(TAG + "************* testRdbStoreDistributed0012 end *************");
})
/**
* @tc.name subscribe test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_013
* @tc.desc subscribe test
*/
it('testRdbStoreDistributed0013', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributed0013 start *************");
rdbStore.off("dataChange", (device) => {
console.info(TAG + device + " dataChange");
});
console.info(TAG + "off dataChange success");
expect(rdbStore).assertEqual(rdbStore);
done()
console.info(TAG + "************* testRdbStoreDistributed0013 end *************");
})
/**
* @tc.name obtainDistributedTableName Callback interface test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_014
* @tc.desc obtainDistributedTableName test
*/
it('testRdbStoreDistributed0014', 0, async function (done){
let errInfo = undefined;
try{
rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE", function (err, tableName) {
expect(err != null).assertTrue();
console.info('ObtainDistributedTableName failed, Unauthorized.' + err)
})
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
})
/**
* @tc.name obtainDistributedTableName Promise interface test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_015
* @tc.desc obtainDistributedTableName test
*/
it('testRdbStoreDistributed0015',0,async function (done){
await data_Rdb.deleteRdbStore(context, STORE_NAME);
const config = {
"name": STORE_NAME,
securityLevel: data_Rdb.SecurityLevel.S1
}
rdbStore = await data_Rdb.getRdbStore(context, config, 1);
let errInfo = undefined
try{
rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE")
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
})
console.info(TAG + "*************Unit Test End*************");
})
}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_rdb from '@ohos.data.relationalStore'
import ability_featureAbility from '@ohos.ability.featureAbility'
const TAG = "[RelationalStore_JSKITS_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)"
var rdbStore
var context = ability_featureAbility.getContext();
const STORE_CONFIG_ENCRYPT = {
name: "Encrypt.db",
encrypt: true,
securityLevel: data_rdb.SecurityLevel.S1
}
const STORE_CONFIG_UNENCRYPT = {
name: "Unencrypt.db",
encrypt: false,
securityLevel: data_rdb.SecurityLevel.S1
}
const STORE_CONFIG_WRONG = {
name: "Encrypt.db",
encrypt: false,
securityLevel: data_rdb.SecurityLevel.S1
}
export default function relationalStoreEncryptTest() {
async function CreatRdbStore(context, STORE_CONFIG) {
let rdbStore = await data_rdb.getRdbStore(context, STORE_CONFIG, 1)
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "wangwu",
"age": 38,
"salary": 90.0,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
return rdbStore
}
describe('relationalStoreEncryptTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await data_rdb.deleteRdbStore(context, STORE_CONFIG_ENCRYPT.name)
await data_rdb.deleteRdbStore(context, STORE_CONFIG_UNENCRYPT.name)
await data_rdb.deleteRdbStore(context, STORE_CONFIG_WRONG.name)
rdbStore = null
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.info(TAG + "*************Unit Test Begin*************")
/**
* @tc.name RelationalStore encrypted test
* @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0010
* @tc.desc RelationalStore create encrypt db test
*/
it('RdbEncryptTest_0010', 0, async function (done) {
console.info(TAG + "************* RdbEncryptTest_0010 start *************")
context = ability_featureAbility.getContext()
data_rdb.getRdbStore(context, STORE_CONFIG_ENCRYPT, 1).then((store) => {
done()
expect(store != null).assertTrue();
}).catch((err) => {
expect(null).assertFail();
})
console.info(TAG + "************* RdbEncryptTest_0010 end *************")
})
/**
* @tc.name RelationalStore unencrypted test
* @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0020
* @tc.desc RelationalStore create unencrypted db test
*/
it('RdbEncryptTest_0020', 0, async function (done) {
console.info(TAG + "************* RdbEncryptTest_0020 start *************")
context = ability_featureAbility.getContext()
let storePromise = data_rdb.getRdbStore(context, STORE_CONFIG_UNENCRYPT, 1);
storePromise.then((store) => {
expect(store != null).assertTrue();
done()
}).catch((err) => {
expect(null).assertFail();
})
console.info(TAG + "************* RdbEncryptTest_0020 end *************")
})
/**
* @tc.name RelationalStore Encrypt test
* @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0030
* @tc.desc RelationalStore Encrypt function test
*/
it('RdbEncryptTest_0030', 0, async function (done) {
console.info(TAG + "************* RdbEncryptTest_0030 start *************")
context = ability_featureAbility.getContext()
rdbStore = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT)
let predicates = new data_rdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
console.info(TAG + "After restore resultSet query done")
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(1).assertEqual(id)
expect("zhangsan").assertEqual(name)
expect(1).assertEqual(blobType[0])
} catch (err) {
expect(false).assertTrue()
}
resultSet = null
rdbStore = null
done()
console.info(TAG + "************* RdbEncryptTest_0030 end *************")
})
/**
* @tc.name RelationalStore Encrypt test
* @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0040
* @tc.desc RelationalStore Encrypt function test
*/
it('RdbEncryptTest_0040', 0, async function (done) {
console.info(TAG + "************* RdbEncryptTest_0040 start *************")
context = ability_featureAbility.getContext()
rdbStore = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT)
rdbStore = null
rdbStore = await CreatRdbStore(context, STORE_CONFIG_WRONG)
expect(rdbStore).assertNull
done()
console.info(TAG + "************* RdbEncryptTest_0040 end *************")
})
console.info(TAG + "*************Unit Test End*************")
}
)
}
\ No newline at end of file
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility';
var context = ability_featureAbility.getContext();
const TAG = "[RelationalStore_JSKITS_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)";
const STORE_CONFIG = {
name: "ExcuteSqlTest.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
var rdbStore = undefined;
export default function relationalStoreExcuteSqlTest() {
describe('relationalStoreExcuteSqlTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
beforeEach(async function () {
await rdbStore.executeSql("DELETE FROM test");
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await data_Rdb.deleteRdbStore(context, "ExcuteSqlTest.db");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0010
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0001', 0, async function (done) {
console.info(TAG + "************* ExcuteSqlTest0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
//插入
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
{
const valueBucket = {
"name": "lisi",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(2).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(3).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
//sql删除
let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE age = ? OR age = ?", ["18", "20"])
executeSqlPromise.then(async (resultSet) => {
await console.info(TAG + "executeSql done: " + resultSet);
}).catch((err) => {
expect(null).assertFail();
})
await executeSqlPromise
let querySqlPromise = rdbStore.querySql("SELECT * FROM test")
querySqlPromise.then(async (resultSet) => {
await expect(0).assertEqual(resultSet.rowCount)
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
done();
console.info(TAG + "************* ExcuteSqlTest0001 end *************");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0020
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0002', 0, async function (done) {
console.info(TAG + "************* ExcuteSqlTest0002 start *************");
var u8 = new Uint8Array([2, 3, 4])
//插入
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(4).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
{
const valueBucket = {
"name": "lisi",
"age": 19,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(5).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(6).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE name = 'lisi'")
executeSqlPromise.then(async () => {
await console.info(TAG + "executeSql done");
}).catch((err) => {
expect(null).assertFail();
})
await executeSqlPromise
let querySqlPromise = rdbStore.querySql("SELECT * FROM test")
querySqlPromise.then(async (resultSet) => {
await expect(1).assertEqual(resultSet.rowCount)
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
done();
console.info(TAG + "************* ExcuteSqlTest0002 end *************");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0030
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0003', 0, async function (done) {
console.info(TAG + "************* ExcuteSqlTest0003 start *************");
var u8 = new Uint8Array([3, 4, 5])
var nameStr = "lisi" + "e".repeat(2000) + "zhangsan"
//插入
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(7).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
{
const valueBucket = {
"name": nameStr,
"age": 19,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(8).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": nameStr,
"age": 28,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(9).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
let predicates = await new data_Rdb.RdbPredicates("test")
predicates.equalTo("name", nameStr)
let querySqlPromise = rdbStore.query(predicates)
querySqlPromise.then(async (resultSet) => {
await expect(2).assertEqual(resultSet.rowCount)
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE age = 19 AND name ='" + nameStr + "'")
executeSqlPromise.then(async () => {
await console.info(TAG + "executeSql done." );
}).catch((err) => {
expect(null).assertFail();
})
await executeSqlPromise
{
let querySqlPromise = rdbStore.querySql("SELECT * FROM test WHERE name ='" + nameStr + "'")
querySqlPromise.then(async (resultSet) => {
await expect(1).assertEqual(resultSet.rowCount)
expect(true).assertEqual(resultSet.goToFirstRow())
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(nameStr).assertEqual(name)
expect(2012).assertEqual(name.length)
expect(28).assertEqual(age)
expect(100.5).assertEqual(salary)
expect(3).assertEqual(blobType[0])
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
}
done();
console.info(TAG + "************* ExcuteSqlTest0003 end *************");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0040
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0004', 0, async function (done) {
console.info(TAG + "************* ExcuteSqlTest0004 start *************");
var u8 = new Uint8Array([3, 4, 5])
//插入
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(10).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
{
const valueBucket = {
"name": "lisi",
"age": 19,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(11).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(12).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
let QuerySqlPromise = rdbStore.executeSql("DROP TABLE IF EXISTS test")
QuerySqlPromise.then(async (resultSet) => {
await console.info(TAG + "executeSql done: " + resultSet);
}).catch((err) => {
expect(null).assertFail();
})
await QuerySqlPromise
done();
console.info(TAG + "************* ExcuteSqlTest0004 end *************");
})
console.info(TAG + "*************Unit Test End*************");
})
}
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility';
var context = ability_featureAbility.getContext();
var contextApplication = context.getApplicationContext()
const TAG = "[RelationalStore_JSKITS_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)";
const STORE_CONFIG = {
name: "rdbstore.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default function relationalStoreTest() {
describe('relationalStoreTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(function () {
console.info(TAG + 'beforeEach')
})
afterEach(async function () {
console.info(TAG + 'afterAll')
await data_Rdb.deleteRdbStore(context,"rdbstore.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.info(TAG + "*************Unit Test Begin*************");
/**
* @tc.name RelationalStore store getRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0010
* @tc.desc RelationalStore store getRdbStore test
*/
it('testRdbStore0001', 0, async function (done) {
console.info(TAG + "************* testRdbStore0001 start *************");
await data_Rdb.getRdbStore(context, STORE_CONFIG, 1).then(async (store) => {
try {
console.info(TAG + "getRdbStore done: " + store);
} catch (e) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
done();
console.info(TAG + "************* testRdbStore0001 end *************");
})
/**
* @tc.name RelationalStore store getRdbStore and create table
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0020
* @tc.desc RelationalStore store getRdbStore and create table
*/
it('testRdbStore0002', 0, async function (done) {
console.info(TAG + "************* testRdbStore0002 start *************");
let storePromise = data_Rdb.getRdbStore(context, STORE_CONFIG, 2);
storePromise.then(async (store) => {
try {
console.info(TAG + "getRdbStore done: " + store);
await store.executeSql(CREATE_TABLE_TEST);
} catch (e) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
done();
console.info(TAG + "************* testRdbStore0002 end *************");
})
/**
* @tc.name RelationalStore storegetRdbStore with wrong path
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0030
* @tc.desc RelationalStore store getRdbStore with wrong path
*/
it('testRdbStore0003', 0, async function (done) {
console.info(TAG + "************* testRdbStore0003 start *************");
let storeConfig = {
name: "/wrong/rdbstore.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
try{
data_Rdb.getRdbStore(context, storeConfig, 4).then(async (ret) => {
console.info(TAG + "getRdbStore done" + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "getRdbStore with wrong path");
})
expect(false).assertTrue();
}catch(error){
console.info(TAG + `catch err: failed: err: code= ${error.code}, message = ${error.message}`)
expect(error.code).assertEqual("401")
done();
console.info(TAG + "************* testRdbStore0003 end *************");
}
})
/**
* @tc.name RelationalStore store deleteRdbStore
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0040
* @tc.desc RelationalStore store deleteRdbStore
*/
it('testRdbStore0004', 0, async function (done) {
console.info(TAG + "************* testRdbStore0004 start *************");
try{
let store = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1)
await store.executeSql(CREATE_TABLE_TEST);
await data_Rdb.deleteRdbStore(context, "rdbstore.db")
}catch (e) {
expect(null).assertFail();
}
done();
console.info(TAG + "************* testRdbStore0004 end *************");
})
/**
* @tc.name RelationalStore store deleteRdbStore
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0050
* @tc.desc RelationalStore store deleteRdbStore
*/
it('testRdbStore0005', 0, async function (done) {
console.info(TAG + "************* testRdbStore0005 start *************");
try {
let store = await data_Rdb.getRdbStore(context, STORE_CONFIG, 2);
console.info(TAG + "Get rdbstore success")
await store.executeSql(CREATE_TABLE_TEST);
await data_Rdb.deleteRdbStore(context, "rdbstore.db")
} catch (e) {
expect(null).assertFail();
}
done();
console.info(TAG + "************* testRdbStore0005 end *************");
})
/**
* @tc.name RelationalStore store getRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0060
* @tc.desc RelationalStore store getRdbStore test
*/
it('testRdbStore0006', 0, async function (done) {
console.info(TAG + "************* testRdbStore0006 start *************");
let rdbstore = null;
try{
const STORE_CONFIG= {
name: "rdbstorecontext.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
rdbstore = await data_Rdb.getRdbStore(context,STORE_CONFIG, 1)
console.info(TAG + "Get rdbstore success")
expect(rdbstore != null).assertTrue();
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
}catch(err){
console.info(TAG + "Get rdbstore fail catch err: " + err)
expect(null).assertFail()
}
rdbstore = null;
done();
console.info(TAG + "************* testRdbStore0006 end *************");
})
/**
* @tc.name RelationalStore store getRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0070
* @tc.desc RelationalStore store getRdbStore test
*/
it('testRdbStore0007', 0, async function (done) {
console.info(TAG + "************* testRdbStore0007 start *************");
let rdbstore = null;
try{
const STORE_CONFIG = {
name: "rdbstorecontext.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
rdbstore = await data_Rdb.getRdbStore(contextApplication,STORE_CONFIG, 1)
console.info(TAG + "Get rdbstore success")
expect(rdbstore != null).assertTrue();
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
}catch(err){
console.info(TAG + "Get rdbstore fail catch err: " + err)
expect(null).assertFail()
}
rdbstore = null;
done();
console.info(TAG + "************* testRdbStore0007 end *************");
})
/**
* @tc.name RelationalStore store deleteRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0080
* @tc.desc RelationalStore store deleteRdbStore test
*/
it('testRdbStore0008', 0, async function (done) {
console.info(TAG + "************* testRdbStore0008 start *************");
data_Rdb.getRdbStore(context, STORE_CONFIG, 1, async (err,data) => {
console.info(TAG + "getRdbStore finish")
console.info(TAG + "getRdbStore success: " + data)
expect(data != null).assertTrue();
await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name)
done();
console.info(TAG + "************* testRdbStore0008 end *************");
});
await sleep(1000)
})
/**
* @tc.name RelationalStore store deleteRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0090
* @tc.desc RelationalStore store deleteRdbStore test
*/
it('testRdbStore0009', 0, async function(done){
console.info(TAG + "************* testRdbStore0009 start *************");
data_Rdb.getRdbStore(contextApplication, STORE_CONFIG, 1, async (err,data) => {
console.info(TAG + "getRdbStore finish")
console.info(TAG + "getRdbStore success: " + data)
expect(data != null).assertTrue();
await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name)
done();
console.info(TAG + "************* testRdbStore0009 end *************");
});
await sleep(1000)
})
console.info(TAG + "*************Unit Test End*************");
})}
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility'
var context = ability_featureAbility.getContext();
const TAG = "[RelationalStore_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, " + "age INTEGER, " + "salary REAL, " + "adddate DATE)";
const STORE_CONFIG = {
name: "PredicatesComplexFiledJsunit.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
var rdbStore = undefined;
export default function relationalStorePredicatesComplexFiledTest(){
describe('relationalStorePredicatesComplexFiledTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1);
await generateTable();
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await data_Rdb.deleteRdbStore(context, "PredicatesComplexFiledJsunit.db");
})
async function generateTable() {
console.info(TAG + 'generateTable')
await rdbStore.executeSql(CREATE_TABLE_TEST);
const valueBucket1 = { id: 1, name: "ZhangSan", age: 20, salary: 100.51, adddate: '2022-09-01' }
await rdbStore.insert("test", valueBucket1)
const valueBucket2 = { id: 2, name: "LiSi", age: 21, salary: 120.61, adddate: '2022-09-01' }
await rdbStore.insert("test", valueBucket2)
const valueBucket3 = { id: 3, name: "WangWu", age: 22, salary: 130.71, adddate: '2022-09-02' }
await rdbStore.insert("test", valueBucket3)
const valueBucket4 = { id: 4, name: "SunLiu", age: 23, salary: 160.81, adddate: '2022-09-02' }
await rdbStore.insert("test", valueBucket4)
const valueBucket5 = { id: 5, name: "MaQi", age: 24, salary: 170.91, adddate: '2022-09-02' }
await rdbStore.insert("test", valueBucket5)
console.info(TAG + 'generateTable end')
}
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001
* @tc.desc resultSet Update test
*/
it('SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001 start *************");
let predicates = await new data_Rdb.RdbPredicates("test")
predicates.groupBy(["DATE(test.adddate)"]).orderByAsc("COUNT(*)")
let resultSet = await rdbStore.query(predicates, ["COUNT(*) AS 'num Count'", "DATE(test.adddate) as birthday"])
expect(true).assertEqual(resultSet.goToFirstRow())
let count = await resultSet.getLong(resultSet.getColumnIndex("num Count"))
let birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(2).assertEqual(count);
await expect("2022-09-01").assertEqual(birthday)
expect(true).assertEqual(resultSet.goToNextRow())
count = await resultSet.getLong(resultSet.getColumnIndex("num Count"))
birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(3).assertEqual(count);
await expect("2022-09-02").assertEqual(birthday)
expect(false).assertEqual(resultSet.goToNextRow())
done();
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002
* @tc.desc resultSet Update test
*/
it('SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002 start *************");
let predicates = await new data_Rdb.RdbPredicates("test")
predicates.groupBy(["DATE(test.adddate)"]).orderByDesc("COUNT(*)")
let resultSet = await rdbStore.query(predicates, ["COUNT(*) AS numCount", "DATE(test.adddate) as birthday"])
expect(true).assertEqual(resultSet.goToFirstRow())
let count = await resultSet.getLong(resultSet.getColumnIndex("numCount"))
let birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(3).assertEqual(count);
await expect("2022-09-02").assertEqual(birthday)
expect(true).assertEqual(resultSet.goToNextRow())
count = await resultSet.getLong(resultSet.getColumnIndex("numCount"))
birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(2).assertEqual(count);
await expect("2022-09-01").assertEqual(birthday)
expect(false).assertEqual(resultSet.goToNextRow())
done();
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility'
var context = ability_featureAbility.getContext();
const USER_TABLE = "CREATE TABLE IF NOT EXISTS user "
+ "(userId INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT , lastName TEXT ,"
+ "age INTEGER , balance REAL NOT NULL)";
const BOOK_TABLE = "CREATE TABLE IF NOT EXISTS Book (id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "name TEXT, userId INTEGER , "
+ "FOREIGN KEY (userId) REFERENCES user (userId) ON UPDATE NO ACTION ON DELETE CASCADE)";
const USER_BULK_INSERT_STATEMENT = "INSERT INTO user"
+ "(userId, firstName, lastName, age, balance) VALUES "
+ "(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?)";
const BOOK_BULK_INSERT_STATEMENT = "INSERT INTO Book (id, name, userId) "
+ "VALUES (?,?,?),(?,?,?),(?,?,?)";
const STORE_CONFIG = {
name: "RdbJoinTest.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
const CURRENT_STORE_VERSION = 1;
const TAG = 'RelationalStore_TEST';
var rdbStore = undefined;
export default function relationalStorePredicatesJoinTest() {
describe('relationalStorePredicatesJoinTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll end')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, CURRENT_STORE_VERSION);
await generateUserTable();
await generateBookTable();
console.info(TAG + 'beforeEach end')
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await data_Rdb.deleteRdbStore(context, "InsertTest.db");
rdbStore = null
console.info(TAG + 'afterEach end')
})
afterAll(async function () {
console.info(TAG + 'afterAll end')
})
async function generateUserTable() {
console.info(TAG + 'generateUserTable')
await rdbStore.executeSql(USER_TABLE);
const users = [
{userId:1, firstName:"Zhang", lastName:"San", age:29, balance:100.51},
{userId:2, firstName:"Li", lastName:"Si", age:30, balance:200.51},
{userId:3, firstName:"wang", lastName:"wu", age:30, balance:300.51},
{userId:4, firstName:"sun", lastName:"liu", age:30, balance:400.51},
{userId:5, firstName:"ma", lastName:"qi", age:32, balance:500.51},
];
var objects = new Array();
users.forEach((user) => {
objects.push(user.userId);
objects.push(user.firstName);
objects.push(user.lastName);
objects.push(user.age);
objects.push(user.balance);
});
await rdbStore.executeSql(USER_BULK_INSERT_STATEMENT, objects);
console.info(TAG + 'generateUserTable end')
}
async function generateBookTable() {
console.info(TAG + 'generateBookTable')
await rdbStore.executeSql(BOOK_TABLE);
var books = [
{id:1, name:"sanguo", userId:1},
{id:2, name:"xiyouji", userId:2},
{id:3, name:"shuihuchuan", userId:3},
]
var objects = new Array();
books.forEach(book => {
objects.push(book.id);
objects.push(book.name);
objects.push(book.userId);
});
await rdbStore.executeSql(BOOK_BULK_INSERT_STATEMENT, objects);
console.info(TAG + 'generateBookTable end')
}
console.info(TAG + "*************Unit Test Begin*************");
/**
* @tc.name: testRdbJoin001
* @tc.number: SUB_DDM_AppDataFWK_Rdb_Inner_Join
* @tc.desc: sql query inner join test
*/
it('testRdbJoin001', 0, async function (done) {
console.info(TAG + "testRdbJoin001 begin.");
let resultSet = await rdbStore.querySql(
"SELECT * FROM user INNER JOIN Book ON user.userId = Book.id WHERE Book.name = 'sanguo'")
expect(1).assertEqual(resultSet.rowCount);
expect(true).assertEqual(resultSet.goToFirstRow());
expect(1).assertEqual(resultSet.getInt(0));
expect("Zhang").assertEqual(resultSet.getString(1));
expect("San").assertEqual(resultSet.getString(2));
expect(29).assertEqual(resultSet.getInt(3));
expect(100.51).assertEqual(resultSet.getDouble(4));
expect(1).assertEqual(resultSet.getInt(5));
expect("sanguo").assertEqual(resultSet.getString(6));
expect(1).assertEqual(resultSet.getInt(7));
done();
})
/**
* @tc.name: testRdbJoin002
* @tc.number: SUB_DDM_AppDataFWK_Rdb_Cross_Join
* @tc.desc: sql query cross join test
*/
it('testRdbJoin002', 0, async function (done) {
console.info(TAG + "testRdbJoin002 begin.");
let resultSet = await rdbStore.querySql("" +
"SELECT * FROM user CROSS JOIN Book USING(userId) WHERE Book.name = 'sanguo'");
expect(1).assertEqual(resultSet.rowCount);
expect(true).assertEqual(resultSet.goToFirstRow());
expect(1).assertEqual(resultSet.getInt(0));
expect("Zhang").assertEqual(resultSet.getString(1));
expect("San").assertEqual(resultSet.getString(2));
expect(29).assertEqual(resultSet.getInt(3));
expect(100.51).assertEqual(resultSet.getDouble(4));
expect(1).assertEqual(resultSet.getInt(5));
expect("sanguo").assertEqual(resultSet.getString(6));
done();
done();
})
/**
* @tc.name: testRdbJoin003
* @tc.number: SUB_DDM_AppDataFWK_Rdb_Left_Outer_Join
* @tc.desc: sql query left outer join test
*/
it('testRdbJoin003', 0, async function (done) {
console.info(TAG + "testRdbJoin003 begin.");
let resultSet = await rdbStore.querySql("" +
"SELECT * FROM user LEFT OUTER JOIN Book USING(userId) WHERE Book.name = 'sanguo'");
expect(1).assertEqual(resultSet.rowCount);
expect(true).assertEqual(resultSet.goToFirstRow());
expect(1).assertEqual(resultSet.getInt(0));
expect("Zhang").assertEqual(resultSet.getString(1));
expect("San").assertEqual(resultSet.getString(2));
expect(29).assertEqual(resultSet.getInt(3));
expect(100.51).assertEqual(resultSet.getDouble(4));
expect(1).assertEqual(resultSet.getInt(5));
expect("sanguo").assertEqual(resultSet.getString(6));
done();
})
console.info(TAG + "*************Unit Test End*************");
})}
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium';
import data_Rdb from '@ohos.data.relationalStore';
import factory from '@ohos.data.distributedData';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RelationalStore_JSKITS_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)"
const STORE_CONFIG = {
name: "Query.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
const TEST_BUNDLE_NAME="ohos.acts.relationalstorejstest"
var kvManager = null
var kvStore = null
var localDeviceId = null
var rdbStore
var context = ability_featureAbility.getContext()
async function CreatRdbStore(context, STORE_CONFIG) {
let RdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG, 1)
await RdbStore.executeSql(CREATE_TABLE_TEST, null)
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await RdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await RdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "wangwu",
"age": 38,
"salary": 90.0,
"blobType": u8,
}
await RdbStore.insert("test", valueBucket)
}
return RdbStore
}
async function getLocalDeviceId(){
}
export default function relationalStoreQueryTest(){
describe("relationalStoreQueryTest", function() {
beforeAll(async function (done){
const config = {
bundleName : TEST_BUNDLE_NAME,
userInfo : {
userId : '0',
userType : factory.UserType.SAME_USER_ID,
context:context
}
}
const options = {
createIfMissing : true,
encrypt : false,
backup : false,
autoSync : true,
kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION,
schema : '',
securityLevel : factory.SecurityLevel.S2,
}
console.info('getLocalDeviceId config:'+ JSON.stringify(config));
await factory.createKVManager(config).then((manager) => {
kvManager = manager;
console.info('getLocalDeviceId createKVManager success');
}).catch((err) => {
console.info('getLocalDeviceId createKVManager err ' + err);
});
await kvManager.getKVStore(TEST_STORE_ID, options).then((store) => {
kvStore = store;
console.info('getLocalDeviceId getKVStore for getDeviceId success');
}).catch((err) => {
console.info('getLocalDeviceId getKVStore err ' + err);
});
var getDeviceId = new Promise((resolve, reject) => {
kvStore.on('dataChange', 0, function (data) {
console.info('getLocalDeviceId on data change: ' + JSON.stringify(data));
resolve(data.deviceId);
});
kvStore.put("getDeviceId", "byPut").then((data) => {
console.info('getLocalDeviceId put success');
expect(data == undefined).assertTrue();
});
setTimeout(() => {
reject(new Error('not resolved in 2 second, reject it.'))
}, 2000);
});
await getDeviceId.then(function(deviceId) {
console.info('getLocalDeviceId getDeviceId ' + JSON.stringify(deviceId));
localDeviceId = deviceId;
}).catch((error) => {
console.info('getLocalDeviceId can NOT getDeviceId, fail: ' + error);
expect(null).assertFail();
});
await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore);
await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID);
kvStore = null;
console.info('getLocalDeviceId end');
getLocalDeviceId()
console.info(TAG + 'beforeAll')
done();
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await CreatRdbStore(context, STORE_CONFIG)
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0010
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryPromiseTest0010', 0, async function (done){
console.info(TAG + "RdbRemoteQueryPromiseTest0010 start")
let errInfo = undefined
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
rdbStore.remoteQuery(localDeviceId,"test",predicates,["name","age","salary"])
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
console.info(TAG + "RdbRemoteQueryPromiseTest0010 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0020
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryPromiseTest0020', 0, async function (done){
console.info(TAG + "RdbRemoteQueryPromiseTest0020 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery([localDeviceId],"test",predicates,["name","age","salary"]).then((resultSet) => {
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}).catch((err) => {
console.info(TAG + "Remote query error" + err)
})
}catch(err){
console.info(TAG + "RdbRemoteQueryPromiseTest0020 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryPromiseTest0020 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0030
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryPromiseTest0030', 0, async function (done){
console.info(TAG + "RdbRemoteQueryPromiseTest0030 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery(localDeviceId,["test"],predicates,["name","age","salary"]).then((resultSet) => {
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}).catch((err) => {
console.info(TAG + "Remote query error" + err)
})
}catch(err){
console.info(TAG + "RdbRemoteQueryPromiseTest0030 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryPromiseTest0030 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0040
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryPromiseTest0040', 0, async function (done){
console.info(TAG + "RdbRemoteQueryPromiseTest0040 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery(localDeviceId,"test",predicates,"age").then((resultSet) => {
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}).catch((err) => {
console.info(TAG + "Remote query error" + err)
})
}catch(err){
console.info(TAG + "RdbRemoteQueryPromiseTest0040 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryPromiseTest0040 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0010
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryCallbackTest0010', 0, async function (done){
console.info(TAG + "RdbRemoteQueryCallbackTest0010 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery(localDeviceId, "test", predicates,["name","age","salary"], (err, data) => {
if(err != null){
console.info(TAG + "Remote query error" + err)
}else{
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}
})
}catch(err){
console.info(TAG + "RdbRemoteQueryCallbackTest0010 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryCallbackTest0010 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0020
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryCallbackTest0020', 0, async function (done){
console.info(TAG + "RdbRemoteQueryCallbackTest0020 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery([localDeviceId], "test", predicates,["name","age","salary"], (err, data) => {
if(err != null){
console.info(TAG + "Remote query error" + err)
}else{
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}
})
}catch(err){
console.info(TAG + "RdbRemoteQueryCallbackTest0020 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryCallbackTest0020 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0030
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryCallbackTest0030', 0, async function (done){
console.info(TAG + "RdbRemoteQueryCallbackTest0020 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery(localDeviceId, ["test"], predicates,["name","age","salary"], (err, data) => {
if(err != null){
console.info(TAG + "Remote query error" + err)
}else{
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}
})
}catch(err){
console.info(TAG + "RdbRemoteQueryCallbackTest0030 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryCallbackTest0030 end")
})
/**
* @tc.name RelationalStore remotequery test
* @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0040
* @tc.desc RelationalStore remotequery function test
*/
it('RdbRemoteQueryCallbackTest0040', 0, async function (done){
console.info(TAG + "RdbRemoteQueryCallbackTest0040 start")
let predicates = new data_Rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
try{
await rdbStore.remoteQuery(localDeviceId, "test", predicates,"name", (err, data) => {
if(err != null){
console.info(TAG + "Remote query error" + err)
}else{
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}
})
}catch(err){
console.info(TAG + "RdbRemoteQueryCallbackTest0040 error:" + err)
}
done();
console.info(TAG + "RdbRemoteQueryCallbackTest0040 end")
})
})
}
\ No newline at end of file
......@@ -12,11 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import rdbStoreV9Test from './RdbstoreRdbstoreV9.test.ets'
import rdbStoreDistributedTest from './RdbstoreDistributedEtsunit.test.ets'
import rdbResultSetTest from './RdbstoreResultsetV9Etsunit.test.ets'
import relationalStoreDistributedTest from './relationalStoreDistributedEtsunit.test.ets'
import relationalStoreTest from './relationalStoreEtsunit.test.ets'
import relationalStoreResultSetTest from './relationalStoreTestResultsetEtsunit.test.ets'
export default function testsuite() {
rdbStoreDistributedTest(globalThis.abilityContext)
rdbStoreV9Test(globalThis.abilityContext);
rdbResultSetTest(globalThis.abilityContext)
relationalStoreDistributedTest(globalThis.abilityContext)
relationalStoreTest(globalThis.abilityContext)
relationalStoreResultSetTest(globalThis.abilityContext)
}
......@@ -15,7 +15,7 @@
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import dataRdb from '@ohos.data.rdb';
import dataRdb from '@ohos.data.relationalStore';
const TAG = "[RDB_JSKITS_TEST_Distributed]"
const STORE_NAME = "distributed_rdb.db"
......@@ -27,20 +27,20 @@ const config = {
}
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)"
export default function rdbStoreDistributedTest(context) {
describe('rdbStoreDistributedTest', function () {
export default function relationalStoreDistributedTest(context) {
describe('relationalStoreDistributedTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
rdbStore = await dataRdb.getRdbStoreV9(context, config, 1);
rdbStore = await dataRdb.getRdbStore(context, config, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null)
console.info(TAG + 'beforeEach')
})
afterEach(async function () {
await dataRdb.deleteRdbStoreV9(context, STORE_NAME);
await dataRdb.deleteRdbStore(context, STORE_NAME);
console.info(TAG + 'afterEach')
})
......
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'
import dataRdb from '@ohos.data.rdb'
import dataRdb from '@ohos.data.relationalStore'
const TAG = '[RDB_JSKITS_TEST]'
const CREATE_TABLE_TEST = 'CREATE TABLE IF NOT EXISTS test (' + 'id INTEGER PRIMARY KEY AUTOINCREMENT, ' + 'data1 text,' + 'data2 long, ' + 'data3 double,' + 'data4 blob)';
......@@ -25,11 +25,11 @@ const STORE_CONFIG = {
const COLOUNM_NAMES = ["id","data1","data2","data3","data4"];
var rdbStore = undefined;
export default function rdbResultSetTestV9(context) {
describe('rdbResultSetTestV9', function () {
export default function relationalStoreResultSetTest(context) {
describe('relationalStoreResultSetTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await dataRdb.getRdbStoreV9(context, STORE_CONFIG, 1);
rdbStore = await dataRdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
await createTest();
})
......@@ -45,7 +45,7 @@ describe('rdbResultSetTestV9', function () {
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await dataRdb.deleteRdbStoreV9(context, 'Resultset.db');
await dataRdb.deleteRdbStore(context, 'Resultset.db');
})
//插入数据
async function createTest() {
......@@ -84,32 +84,32 @@ describe('rdbResultSetTestV9', function () {
}
/**
* @tc.name resultSetV9 getBlob normal test
* @tc.number SUB_DDM_RELATIONALETS_RESULTSETV9_0010
* @tc.desc resultSetV9 getBlob normal test
* @tc.name resultSet getBlob normal test
* @tc.number SUB_DDM_RELATIONALETS_RESULTSET_0010
* @tc.desc resultSet getBlob normal test
*/
it('SUB_DDM_RELATIONALETS_RESULTSETV9_0010', 0, async function (done) {
console.info(TAG + '************* SUB_DDM_RELATIONALETS_RESULTSETV9_0010 start *************');
let predicates = await new dataRdb.RdbPredicatesV9('test')
let resultSetV9 = await rdbStore.query(predicates)
it('SUB_DDM_RELATIONALETS_RESULTSET_0010', 0, async function (done) {
console.info(TAG + '************* SUB_DDM_RELATIONALETS_RESULTSET_0010 start *************');
let predicates = await new dataRdb.RdbPredicates('test')
let resultSet = await rdbStore.query(predicates)
try {
{
expect(true).assertEqual(resultSetV9.goToFirstRow())
const id = resultSetV9.getLong(resultSetV9.getColumnIndex('id'))
const data4 = resultSetV9.getBlob(resultSetV9.getColumnIndex('data4'))
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex('id'))
const data4 = resultSet.getBlob(resultSet.getColumnIndex('data4'))
console.info(TAG + 'id=' + id + ', data4=' + data4);
expect(1).assertEqual(data4[0]);
expect(2).assertEqual(data4[1]);
expect(3).assertEqual(data4[2]);
}
resultSetV9.close();
expect(true).assertEqual(resultSetV9.isClosed)
resultSet.close();
expect(true).assertEqual(resultSet.isClosed)
} catch (e) {
expect(null).assertFail();
}
resultSetV9 = null
resultSet = null
done();
console.info(TAG + '************* SUB_DDM_RELATIONALETS_RESULTSETV9_0010 end *************');
console.info(TAG + '************* SUB_DDM_RELATIONALETS_RESULTSET_0010 end *************');
})
console.info(TAG + '*************Unit Test End*************');
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册