提交 e215c5c1 编写于 作者: Y yanglifeng1217

<modified>

Signed-off-by: Nyanglifeng1217 <yanglifeng5@huawei.com>
上级 358dd58f
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* 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
......@@ -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 *************")
})
})
}
})
})
/**
......@@ -309,23 +304,17 @@ export default function rdbStoreBackupRestoreCallbackTest() {
// 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()
}
})
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup2 done")
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
})
})
})
/**
* @tc.name RDB BackupRestore test
......@@ -335,27 +324,23 @@ export default function rdbStoreBackupRestoreCallbackTest() {
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{
RdbStore.backup(DATABASE_BACKUP_TEST_NAME, async (err, data) => {
expect(err == null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 backup done")
dataRdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME, () => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME)
}catch(err){
expect(true).assertTrue();
} catch (err) {
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 deleteRdbStore done")
}
})
RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => {
if(err != null){
expect(true).assertTrue()
}
})
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 restore 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();
})
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************")
})
......@@ -411,9 +398,11 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){
expect(false).assertTrue()
}
})
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 *************")
})
......
......@@ -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,7 +132,7 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RDB backup function test
RdbStore.backup(DATABASE_BACKUP_NAME).then(async() => {
await RdbStore.backup(DATABASE_BACKUP_NAME)
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
......@@ -146,13 +146,12 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
await RdbStore.delete(deleteData)
// RDB restore function test
RdbStore.restore(DATABASE_BACKUP_NAME).then(async () => {
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 {
......@@ -164,7 +163,7 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
// RDB after restored, data query test
let predicates = new dataRdb.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,24 +182,13 @@ describe('rdbStoreBackupRestorePromiseTest', 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()
})
})
/**
* @tc.name RDB Backup test
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0020
......@@ -269,33 +257,32 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
// 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 *************")
})
......@@ -308,11 +295,11 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
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();
})
})
......@@ -325,14 +312,14 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
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 *************")
......@@ -370,7 +357,7 @@ describe('rdbStoreBackupRestorePromiseTest', 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 +370,7 @@ describe('rdbStoreBackupRestorePromiseTest', 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 +383,7 @@ describe('rdbStoreBackupRestorePromiseTest', 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 +397,7 @@ describe('rdbStoreBackupRestorePromiseTest', 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 *************")
})
......
......@@ -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()
......@@ -135,7 +135,8 @@ export default function relationalStoreBackupRestoreCallbackTest() {
// 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 {
......@@ -146,7 +147,6 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}
}
// RelationalStore before restored, delete data
let deleteData = new data_Rdb.RdbPredicates("backupTest")
deleteData.equalTo("name", "zhangsan")
......@@ -159,7 +159,7 @@ 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 {
......@@ -259,7 +259,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
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,13 +286,13 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}catch(err){
expect(false).assertTrue();
}
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
}
})
})
}
})
})
/**
......@@ -309,23 +305,17 @@ export default function relationalStoreBackupRestoreCallbackTest() {
// 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()
}
})
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup2 done")
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
})
})
})
/**
* @tc.name RelationalStore BackupRestore test
......@@ -335,27 +325,25 @@ export default function relationalStoreBackupRestoreCallbackTest() {
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()
} else {
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 backup done")
}
})
await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME).then(() => {
try{
data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME, () => {
try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME)
}catch(err){
expect(true).assertTrue();
} catch (err) {
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 deleteRdbStore done")
}
})
RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => {
if(err != null){
expect(true).assertTrue()
}
})
expect(err != null).assertTrue()
console.info(TAG + "RdbBackupRestoreCallbackTest_0700 restore err " + err.code)
done();
})
})
})
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 end *************")
})
......@@ -394,12 +382,11 @@ export default function relationalStoreBackupRestoreCallbackTest() {
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
......@@ -411,9 +398,9 @@ export default function relationalStoreBackupRestoreCallbackTest() {
if(err != null){
expect(false).assertTrue()
}
})
ReStoreCallbackTest()
done();
})
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************")
})
......@@ -428,9 +415,9 @@ export default function relationalStoreBackupRestoreCallbackTest() {
if(err != null){
expect(false).assertTrue()
}
})
BackupCallbackTest(DATABASE_BACKUP_NAME)
done();
})
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 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,24 +181,13 @@ 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()
})
})
/**
* @tc.name RelationalStore Backup test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0020
......@@ -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 *************")
})
......
/*
* Copyright (C) 2022-2023 Huawei Device Co., Ltd.
* 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
......@@ -149,13 +149,11 @@ describe('relationalStoreTest', function () {
} catch (err) {
expect(null).assertFail();
}
await dataRdb.deleteRdbStore(context,"secure.db");
done();
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 end *************");
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册