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

!7731 【Distributeddatamgr】【monthly_20221018】monthly_20221018用例修改,优化执行时序

Merge pull request !7731 from yanglifeng/monthly_20221018
......@@ -12,8 +12,7 @@
* 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'
......@@ -27,9 +26,9 @@ 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 rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js'
import rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js'
export default function testsuite() {
rdbStoreBackupRestoreCallbackTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreDeleteTest()
rdbStoreDistributedTest()
rdbstoreInsertTest()
......@@ -43,4 +42,6 @@ export default function testsuite() {
rdbstoreQueryTest()
rdbStoreEncryptionTest()
rdbStorePredicatesComplexFiledTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreBackupRestoreCallbackTest()
}
......@@ -146,7 +146,6 @@ export default function rdbStoreBackupRestoreCallbackTest() {
}
}
// RDB before restored, delete data
let deleteData = new dataRdb.RdbPredicates("backupTest")
deleteData.equalTo("name", "zhangsan")
......@@ -159,7 +158,7 @@ export default function rdbStoreBackupRestoreCallbackTest() {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue()
} catch (err) {
expect(true).assertTrue()
console.info(TAG + "rdb restore1 done")
}
try {
......@@ -275,14 +274,10 @@ export default function rdbStoreBackupRestoreCallbackTest() {
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 *************")
console.info(`${TAG} Backup database second failed`)
}else{
try{
console.info(TAG + 'Backup database second success')
......@@ -291,12 +286,12 @@ export default function rdbStoreBackupRestoreCallbackTest() {
expect(false).assertTrue();
}
}
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
})
})
}
})
})
/**
......@@ -304,27 +299,21 @@ export default function rdbStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0600
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreCallbackTest_0600', 0, async function (done) {
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()
}
})
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup1 done")
RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){
expect(true).assertTrue()
}else{
expect(false).assertTrue()
}
RdbStore.backup(STORE_CONFIG.name, (err, data) => {
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup2 done")
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
})
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
})
/**
......@@ -332,30 +321,26 @@ export default function rdbStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0700
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreCallbackTest_0700', 0, async function (done) {
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 dataRdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME).then(() => {
try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME)
}catch(err){
expect(true).assertTrue();
}
})
RdbStore.backup(DATABASE_BACKUP_TEST_NAME, async (err, data) => {
expect(err == null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 backup done")
RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => {
if(err != null){
expect(true).assertTrue()
}
dataRdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME, () => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME)
} catch (err) {
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 deleteRdbStore done")
}
RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => {
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 restore done")
done();
})
})
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 end *************")
})
......@@ -394,9 +379,11 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){
expect(false).assertTrue()
}
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
})
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************")
})
......@@ -411,9 +398,11 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){
expect(false).assertTrue()
}
ReStoreCallbackTest()
done();
})
ReStoreCallbackTest()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************")
})
......@@ -428,9 +417,10 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){
expect(false).assertTrue()
}
})
BackupCallbackTest(DATABASE_BACKUP_NAME)
done();
})
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************")
})
......@@ -453,9 +443,10 @@ export default function rdbStoreBackupRestoreCallbackTest() {
}
})
}
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 end *************")
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 end *************")
})
console.info(TAG + "*************Unit Test End*************")
})
......
......@@ -12,14 +12,14 @@
* 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 { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import dataRdb from '@ohos.data.rdb'
import abilityFeatureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio'
const TAG = "[RDB_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)"
+ "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"
const DATABASE_DIR = "/data/storage/el2/database/entry/rdb/"
var RdbStore
var context
......@@ -72,7 +72,7 @@ async function BackupTest(backupName) {
expect(true).assertTrue()
})
await promiseRestore
} catch(errInfo){
} catch (errInfo) {
console.info(TAG + "BackupTest error: " + errInfo)
expect(true).assertTrue()
}
......@@ -90,7 +90,7 @@ async function ReStoreTest(restoreName) {
expect(true).assertTrue()
})
await promiseRestore
} catch(errInfo) {
} catch (errInfo) {
console.info(TAG + "ReStoreTest error: " + errInfo)
expect(true).assertTrue()
}
......@@ -99,7 +99,7 @@ async function ReStoreTest(restoreName) {
}
export default function rdbStoreBackupRestorePromiseTest() {
describe('rdbStoreBackupRestorePromiseTest', function () {
describe('rdbStoreBackupRestorePromiseTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
......@@ -132,73 +132,61 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RDB 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()
}
// RDB before restored, delete data
let deleteData = new dataRdb.RdbPredicates("test")
deleteData.equalTo("name", "zhangsan")
await RdbStore.delete(deleteData)
await RdbStore.backup(DATABASE_BACKUP_NAME)
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()
}
// RDB before restored, delete data
let deleteData = new dataRdb.RdbPredicates("test")
deleteData.equalTo("name", "zhangsan")
await RdbStore.delete(deleteData)
// RDB 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()
}
await RdbStore.restore(DATABASE_BACKUP_NAME)
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue()
} catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success")
}
try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success2")
expect(false).assertTrue()
}
// RDB after restored, data query test
let predicates = new dataRdb.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) => {
try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success2")
expect(false).assertTrue()
})
}
// RDB after restored, data query test
let predicates = new dataRdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan")
let resultSet = await RdbStore.query(predicates)
try {
console.info(TAG + "After restore resultSet query done")
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.close()
RdbStore = null
done()
console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************")
})
/**
......@@ -264,38 +252,37 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0050
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0050', 0, async function (done) {
it('RdbBackupRestoreTest_0050', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0050 start *************")
// RDB restore function test, backup file
await RdbStore.backup(DATABASE_BACKUP_NAME).then(() => {
try{
try {
console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
} catch (err) {
expect(false).assertTrue();
}
}).then(() => {
dataRdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => {
try{
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
console.info(TAG + 'error2 ' + err)
expect(true).assertTrue();
} catch (err) {
console.info(TAG + 'RdbBackupRestoreTest_0050 deleteRdbStore done ')
}
})
}).then(() => {
RdbStore.backup(DATABASE_BACKUP_NAME).then(() => {
try{
try {
console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
} catch (err) {
console.info(TAG + 'error3 ' + err)
expect(false).assertTrue()
}
done()
})
})
done()
console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************")
})
......@@ -304,15 +291,15 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0060
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0060', 0, async function (done) {
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() ;
console.info(TAG + 'RdbBackupRestoreTest_0060 Backup database err');
expect(false).assertTrue();
}).catch((err) => {
console.info(TAG + "Backup database error");
expect(true).assertTrue() ;
console.info(TAG + "RdbBackupRestoreTest_0060 Backup database done");
expect(err != null).assertTrue();
done();
})
})
......@@ -321,18 +308,18 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0070
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0070', 0, async function (done) {
it('RdbBackupRestoreTest_0070', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0070 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
await dataRdb.deleteRdbStore(context, DATABASE_BACKUP_NAME)
try{
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
expect(true).assertTrue();
} catch (err) {
console.info(TAG + "RdbBackupRestoreTest_0070 deleteRdbStore done");
}
await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => {
console.info(TAG + 'Restore fail: ' + err)
expect(true).assertTrue();
console.info(TAG + 'Restore ')
expect(err != null).assertTrue();
})
done();
console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************")
......@@ -344,10 +331,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0080', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0080 start *************")
BackupTest()
done();
console.info(TAG + "************* RdbBackupRestoreTest_0080 end *************")
console.info(TAG + "************* RdbBackupRestoreTest_0080 start *************")
BackupTest()
done();
console.info(TAG + "************* RdbBackupRestoreTest_0080 end *************")
})
/**
......@@ -355,7 +342,7 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0090
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0090', 0, async function (done) {
it('RdbBackupRestoreTest_0090', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0090 start *************")
BackupTest([DATABASE_BACKUP_NAME])
done();
......@@ -367,10 +354,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0100
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0100', 0, async function (done) {
it('RdbBackupRestoreTest_0100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest([DATABASE_BACKUP_NAME])
await ReStoreTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************")
})
......@@ -380,10 +367,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0110
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0110', 0, async function (done) {
it('RdbBackupRestoreTest_0110', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest()
await ReStoreTest()
done();
console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************")
})
......@@ -393,10 +380,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0120
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0120', 0, async function (done) {
it('RdbBackupRestoreTest_0120', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
BackupTest(DATABASE_BACKUP_NAME)
await BackupTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************")
})
......@@ -406,11 +393,11 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0130
* @tc.desc RDB restore function test
*/
it('RdbBackupRestoreTest_0130', 0, async function (done) {
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)
await ReStoreTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************")
})
......
/*
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
......@@ -12,8 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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'
......@@ -27,9 +26,9 @@ import relationalStoreUpdateTest from './RelationalStoreUpdateJsunit.test.js'
import relationalStoreQueryTest from './RelationalStoreQuery.test.js'
import relationalStoreEncryptionTest from './RelationalStoreEncryptionJsunit.test.js'
import relationalStorePredicatesComplexFiledTest from './RelationalStorePredicatesComplexFiledJsunit.test.js'
import relationalStoreBackupRestoreWithFAContextTest from './RelationalStoreBackupRestoreWithFAContextJsunit.test.js'
import relationalStoreBackupRestoreCallbackTest from './RelationalStoreBackupRestoreCallbackJsunit.test.js'
export default function testsuite() {
relationalStoreBackupRestoreCallbackTest()
relationalStoreBackupRestoreWithFAContextTest()
relationalStoreDeleteTest()
relationalStoreDistributedTest()
relationalStoreInsertTest()
......@@ -43,4 +42,6 @@ export default function testsuite() {
relationalStoreQueryTest()
relationalStoreEncryptionTest()
relationalStorePredicatesComplexFiledTest()
relationalStoreBackupRestoreWithFAContextTest()
relationalStoreBackupRestoreCallbackTest()
}
......@@ -19,7 +19,7 @@ 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)"
+ "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()
......@@ -101,30 +101,30 @@ function ReStoreCallbackTest(restoreName) {
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
......@@ -132,10 +132,11 @@ export default function relationalStoreBackupRestoreCallbackTest() {
*/
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){
if (err != null) {
console.info(TAG + 'backup err ttt: ' + err)
expect(false).assertTrue()
}else{
try {
......@@ -145,8 +146,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
expect(false).assertTrue()
}
}
// RelationalStore before restored, delete data
let deleteData = new data_Rdb.RdbPredicates("backupTest")
deleteData.equalTo("name", "zhangsan")
......@@ -159,9 +159,9 @@ export default function relationalStoreBackupRestoreCallbackTest() {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue()
} catch (err) {
expect(true).assertTrue()
console.info(TAG + " restore1 done ")
}
try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) {
......@@ -189,10 +189,10 @@ export default function relationalStoreBackupRestoreCallbackTest() {
done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 end *************")
})
})
})
})
})
/**
* @tc.name RelationalStore Backup test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0200
......@@ -202,14 +202,14 @@ export default function relationalStoreBackupRestoreCallbackTest() {
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
......@@ -219,17 +219,17 @@ export default function relationalStoreBackupRestoreCallbackTest() {
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
......@@ -238,7 +238,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
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)
......@@ -246,20 +246,20 @@ export default function relationalStoreBackupRestoreCallbackTest() {
} 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) {
it('RdbBackupRestoreCallbackTest_0500', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 start *************")
// RelationalStore restore function test, backup file
// RDB restore function test, backup file
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
expect(false).assertTrue()
......@@ -270,19 +270,15 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}catch(err){
expect(false).assertTrue();
}
data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).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();
console.info(TAG + 'RdbBackupRestoreCallbackTest_0500 deleteRdbStore done')
}
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')
......@@ -290,130 +286,121 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}catch(err){
expect(false).assertTrue();
}
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
}
})
})
}
})
})
/**
* @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) {
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()
}
})
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup1 done")
RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){
expect(true).assertTrue()
}else{
expect(false).assertTrue()
}
RdbStore.backup(STORE_CONFIG.name, (err, data) => {
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup2 done")
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
})
})
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) {
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){
RdbStore.backup(DATABASE_BACKUP_TEST_NAME, async (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()
} else {
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 backup done")
}
data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME, () => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME)
} catch (err) {
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 deleteRdbStore done")
}
RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => {
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 restore err " + err.code)
done();
})
})
})
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 *************")
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) {
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) {
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();
})
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) {
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();
})
ReStoreCallbackTest()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************")
})
......@@ -422,15 +409,15 @@ export default function relationalStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1200
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_1200', 0, async function (done) {
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();
})
BackupCallbackTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************")
})
......@@ -439,7 +426,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1300
* @tc.desc RelationalStore restore function test
*/
it('RdbBackupRestoreCallbackTest_1300', 0, async function (done) {
it('RdbBackupRestoreCallbackTest_1300', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){
......@@ -453,9 +440,9 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}
})
}
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 end *************")
})
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 end *************")
})
console.info(TAG + "*************Unit Test End*************")
})
......
......@@ -131,8 +131,8 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0010', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RelationalStore backup function test
RdbStore.backup(DATABASE_BACKUP_NAME).then(async() => {
// RDB backup function test
await RdbStore.backup(DATABASE_BACKUP_NAME)
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
......@@ -140,31 +140,29 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info("RdbBackupRestoreTest_0010 backup success")
expect(false).assertTrue()
}
// RelationalStore before restored, delete data
// RDB 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 () => {
// RDB restore function test
await RdbStore.restore(DATABASE_BACKUP_NAME)
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
// RDB after restored, data query test
let predicates = new data_Rdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan")
RdbStore.query(predicates).then((resultSet)=>{
let resultSet = await RdbStore.query(predicates)
try {
console.info(TAG + "After restore resultSet query done")
resultSet.goToFirstRow();
......@@ -183,22 +181,11 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err)
expect(false).assertTrue()
}
resultSet = null
resultSet.close()
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()
})
})
/**
......@@ -281,7 +268,6 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
console.info(TAG + 'error2 ' + err)
expect(true).assertTrue();
}
})
}).then(() => {
......@@ -293,9 +279,9 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info(TAG + 'error3 ' + err)
expect(false).assertTrue()
}
done();
})
})
done()
console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************")
})
......@@ -312,7 +298,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
expect(false).assertTrue() ;
}).catch((err) => {
console.info(TAG + "Backup database error");
expect(true).assertTrue() ;
expect(err != null).assertTrue() ;
done();
})
})
......@@ -328,11 +314,11 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){
expect(true).assertTrue();
console.info(TAG + 'deleteRdbStore done')
}
await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => {
console.info(TAG + 'Restore fail: ' + err)
expect(true).assertTrue();
console.info(TAG + 'Restore fail: ' + err.code);
expect(err != null).assertTrue();
})
done();
console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************")
......@@ -370,7 +356,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest([DATABASE_BACKUP_NAME])
await ReStoreTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************")
})
......@@ -383,7 +369,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0110', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest()
await ReStoreTest()
done();
console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************")
})
......@@ -396,7 +382,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0120', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
BackupTest(DATABASE_BACKUP_NAME)
await BackupTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************")
})
......@@ -410,7 +396,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info(TAG + "************* RdbBackupRestoreTest_0130 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME)
await RdbStore.restore(DATABASE_BACKUP_NAME)
ReStoreTest(DATABASE_BACKUP_NAME)
await ReStoreTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************")
})
......
......@@ -137,27 +137,25 @@ describe('relationalStoreTest', function () {
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S4
}
let storePromise = dataRdb.getRdbStore(context, config);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (err) {
expect(null).assertFail();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S4
}
}).catch((err) => {
expect(null).assertFail();
let storePromise = dataRdb.getRdbStore(context, config);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (err) {
expect(null).assertFail();
}
await dataRdb.deleteRdbStore(context,"secure.db");
done();
}).catch((err) => {
expect(null).assertFail();
})
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 end *************");
})
await storePromise
storePromise = null
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 end *************");
})
/**
* @tc.name rdb store getRdbStore with securityLevel S1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册