提交 69f24145 编写于 作者: Y yanglifeng1217

<modified>

Signed-off-by: Nyanglifeng1217 <yanglifeng5@huawei.com>
上级 66bce73b
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js'
import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js'
import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js' import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js'
import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js' import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js'
import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js' import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js'
...@@ -27,9 +26,9 @@ import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js' ...@@ -27,9 +26,9 @@ import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js'
import rdbstoreQueryTest from './RdbstoreQuery.test.js' import rdbstoreQueryTest from './RdbstoreQuery.test.js'
import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js' import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js'
import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js' import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js'
import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js'
import rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js'
export default function testsuite() { export default function testsuite() {
rdbStoreBackupRestoreCallbackTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreDeleteTest() rdbStoreDeleteTest()
rdbStoreDistributedTest() rdbStoreDistributedTest()
rdbstoreInsertTest() rdbstoreInsertTest()
...@@ -43,4 +42,6 @@ export default function testsuite() { ...@@ -43,4 +42,6 @@ export default function testsuite() {
rdbstoreQueryTest() rdbstoreQueryTest()
rdbStoreEncryptionTest() rdbStoreEncryptionTest()
rdbStorePredicatesComplexFiledTest() rdbStorePredicatesComplexFiledTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreBackupRestoreCallbackTest()
} }
...@@ -146,7 +146,6 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -146,7 +146,6 @@ export default function rdbStoreBackupRestoreCallbackTest() {
} }
} }
// RDB before restored, delete data // RDB before restored, delete data
let deleteData = new dataRdb.RdbPredicates("backupTest") let deleteData = new dataRdb.RdbPredicates("backupTest")
deleteData.equalTo("name", "zhangsan") deleteData.equalTo("name", "zhangsan")
...@@ -159,7 +158,7 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -159,7 +158,7 @@ export default function rdbStoreBackupRestoreCallbackTest() {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue() expect(false).assertTrue()
} catch (err) { } catch (err) {
expect(true).assertTrue() console.info(TAG + "rdb restore1 done")
} }
try { try {
...@@ -275,14 +274,10 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -275,14 +274,10 @@ export default function rdbStoreBackupRestoreCallbackTest() {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ }catch(err){
console.info(TAG + 'error2 ' + err) console.info(TAG + 'error2 ' + err)
expect(true).assertTrue();
} }
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
console.info(`${TAG} Backup database second failed, error: message: ${err.message}`) console.info(`${TAG} Backup database second failed`)
expect(true).assertTrue()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
}else{ }else{
try{ try{
console.info(TAG + 'Backup database second success') console.info(TAG + 'Backup database second success')
...@@ -291,12 +286,12 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -291,12 +286,12 @@ export default function rdbStoreBackupRestoreCallbackTest() {
expect(false).assertTrue(); expect(false).assertTrue();
} }
} }
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
}) })
}) })
} }
}) })
}) })
/** /**
...@@ -304,27 +299,21 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -304,27 +299,21 @@ export default function rdbStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0600 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0600
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 start *************")
// Backup file is specified to database name // Backup file is specified to database name
RdbStore.backup(STORE_CONFIG.name, (err, data) => { RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){ expect(err != null).assertTrue()
expect(true).assertTrue() console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup1 done")
}else{
expect(false).assertTrue()
}
})
RdbStore.backup(STORE_CONFIG.name, (err, data) => { RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){ expect(err != null).assertTrue()
expect(true).assertTrue() console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup2 done")
}else{ done();
expect(false).assertTrue() console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
} })
}) })
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
}) })
/** /**
...@@ -332,30 +321,26 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -332,30 +321,26 @@ export default function rdbStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0700 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreCallbackTest_0700
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 start *************")
let DATABASE_BACKUP_TEST_NAME = "BackupTest.db" let DATABASE_BACKUP_TEST_NAME = "BackupTest.db"
RdbStore.backup(DATABASE_BACKUP_TEST_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_TEST_NAME, async (err, data) => {
if(err != null){ expect(err == null).assertTrue()
expect(false).assertTrue() console.info(TAG + "RdbBackupRestoreCallbackTest_0700 backup done")
}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.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => { dataRdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME, () => {
if(err != null){ try {
expect(true).assertTrue() 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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 end *************")
}) })
...@@ -394,9 +379,11 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -394,9 +379,11 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
} }
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
}) })
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************")
}) })
...@@ -411,9 +398,11 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -411,9 +398,11 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
} }
ReStoreCallbackTest()
done();
}) })
ReStoreCallbackTest()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************")
}) })
...@@ -428,9 +417,10 @@ export default function rdbStoreBackupRestoreCallbackTest() { ...@@ -428,9 +417,10 @@ export default function rdbStoreBackupRestoreCallbackTest() {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
} }
})
BackupCallbackTest(DATABASE_BACKUP_NAME) BackupCallbackTest(DATABASE_BACKUP_NAME)
done(); done();
})
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************")
}) })
......
...@@ -12,14 +12,14 @@ ...@@ -12,14 +12,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * 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 dataRdb from '@ohos.data.rdb'
import abilityFeatureAbility from '@ohos.ability.featureAbility' import abilityFeatureAbility from '@ohos.ability.featureAbility'
import fileio from '@ohos.fileio' import fileio from '@ohos.fileio'
const TAG = "[RDB_JSKITS_TEST]" const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " 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/" const DATABASE_DIR = "/data/storage/el2/database/entry/rdb/"
var RdbStore var RdbStore
var context var context
...@@ -72,7 +72,7 @@ async function BackupTest(backupName) { ...@@ -72,7 +72,7 @@ async function BackupTest(backupName) {
expect(true).assertTrue() expect(true).assertTrue()
}) })
await promiseRestore await promiseRestore
} catch(errInfo){ } catch (errInfo) {
console.info(TAG + "BackupTest error: " + errInfo) console.info(TAG + "BackupTest error: " + errInfo)
expect(true).assertTrue() expect(true).assertTrue()
} }
...@@ -90,7 +90,7 @@ async function ReStoreTest(restoreName) { ...@@ -90,7 +90,7 @@ async function ReStoreTest(restoreName) {
expect(true).assertTrue() expect(true).assertTrue()
}) })
await promiseRestore await promiseRestore
} catch(errInfo) { } catch (errInfo) {
console.info(TAG + "ReStoreTest error: " + errInfo) console.info(TAG + "ReStoreTest error: " + errInfo)
expect(true).assertTrue() expect(true).assertTrue()
} }
...@@ -99,7 +99,7 @@ async function ReStoreTest(restoreName) { ...@@ -99,7 +99,7 @@ async function ReStoreTest(restoreName) {
} }
export default function rdbStoreBackupRestorePromiseTest() { export default function rdbStoreBackupRestorePromiseTest() {
describe('rdbStoreBackupRestorePromiseTest', function () { describe('rdbStoreBackupRestorePromiseTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
}) })
...@@ -132,73 +132,61 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -132,73 +132,61 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RDB backup function test // RDB backup function test
RdbStore.backup(DATABASE_BACKUP_NAME).then(async() => { await RdbStore.backup(DATABASE_BACKUP_NAME)
try { try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) { } catch (err) {
console.info("RdbBackupRestoreTest_0010 backup success") console.info("RdbBackupRestoreTest_0010 backup success")
expect(false).assertTrue() expect(false).assertTrue()
} }
// RDB before restored, delete data // RDB before restored, delete data
let deleteData = new dataRdb.RdbPredicates("test") let deleteData = new dataRdb.RdbPredicates("test")
deleteData.equalTo("name", "zhangsan") deleteData.equalTo("name", "zhangsan")
await RdbStore.delete(deleteData) await RdbStore.delete(deleteData)
// RDB restore function test // RDB restore function test
RdbStore.restore(DATABASE_BACKUP_NAME).then(async () => { await RdbStore.restore(DATABASE_BACKUP_NAME)
try { try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue() expect(false).assertTrue()
} catch (err) { } catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success") console.info("RdbBackupRestoreTest_0010 restore success")
expect(true).assertTrue() }
}
try { try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) { } catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success2") 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) => {
expect(false).assertTrue() 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 () { ...@@ -264,38 +252,37 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0050 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0050
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0050 start *************")
// RDB restore function test, backup file // RDB restore function test, backup file
await RdbStore.backup(DATABASE_BACKUP_NAME).then(() => { await RdbStore.backup(DATABASE_BACKUP_NAME).then(() => {
try{ try {
console.info(TAG + 'Backup database success') console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ } catch (err) {
expect(false).assertTrue(); expect(false).assertTrue();
} }
}).then(() => { }).then(() => {
dataRdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => { dataRdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => {
try{ try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ } catch (err) {
console.info(TAG + 'error2 ' + err) console.info(TAG + 'RdbBackupRestoreTest_0050 deleteRdbStore done ')
expect(true).assertTrue();
} }
}) })
}).then(() => { }).then(() => {
RdbStore.backup(DATABASE_BACKUP_NAME).then(() => { RdbStore.backup(DATABASE_BACKUP_NAME).then(() => {
try{ try {
console.info(TAG + 'Backup database success') console.info(TAG + 'Backup database success')
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ } catch (err) {
console.info(TAG + 'error3 ' + err) console.info(TAG + 'error3 ' + err)
expect(false).assertTrue() expect(false).assertTrue()
} }
done()
}) })
}) })
done()
console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************")
}) })
...@@ -304,15 +291,15 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -304,15 +291,15 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0060 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0060
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0060 start *************")
// Backup file is specified to database name // Backup file is specified to database name
RdbStore.backup(STORE_CONFIG.name).then(() => { RdbStore.backup(STORE_CONFIG.name).then(() => {
console.info(TAG + 'Backup database finish'); console.info(TAG + 'RdbBackupRestoreTest_0060 Backup database err');
expect(false).assertTrue() ; expect(false).assertTrue();
}).catch((err) => { }).catch((err) => {
console.info(TAG + "Backup database error"); console.info(TAG + "RdbBackupRestoreTest_0060 Backup database done");
expect(true).assertTrue() ; expect(err != null).assertTrue();
done(); done();
}) })
}) })
...@@ -321,18 +308,18 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -321,18 +308,18 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0070 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0070
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0070 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
await dataRdb.deleteRdbStore(context, DATABASE_BACKUP_NAME) await dataRdb.deleteRdbStore(context, DATABASE_BACKUP_NAME)
try{ try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ } catch (err) {
expect(true).assertTrue(); console.info(TAG + "RdbBackupRestoreTest_0070 deleteRdbStore done");
} }
await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => { await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => {
console.info(TAG + 'Restore fail: ' + err) console.info(TAG + 'Restore ')
expect(true).assertTrue(); expect(err != null).assertTrue();
}) })
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************")
...@@ -344,10 +331,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -344,10 +331,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.desc RDB restore function test * @tc.desc RDB restore function test
*/ */
it('RdbBackupRestoreTest_0080', 0, async function (done) { it('RdbBackupRestoreTest_0080', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0080 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0080 start *************")
BackupTest() BackupTest()
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0080 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0080 end *************")
}) })
/** /**
...@@ -355,7 +342,7 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -355,7 +342,7 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0090 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0090
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0090 start *************")
BackupTest([DATABASE_BACKUP_NAME]) BackupTest([DATABASE_BACKUP_NAME])
done(); done();
...@@ -367,10 +354,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -367,10 +354,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0100 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0100
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest([DATABASE_BACKUP_NAME]) await ReStoreTest([DATABASE_BACKUP_NAME])
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************")
}) })
...@@ -380,10 +367,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -380,10 +367,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0110 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0110
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest() await ReStoreTest()
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************")
}) })
...@@ -393,10 +380,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -393,10 +380,10 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0120 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0120
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
BackupTest(DATABASE_BACKUP_NAME) await BackupTest(DATABASE_BACKUP_NAME)
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************")
}) })
...@@ -406,11 +393,11 @@ describe('rdbStoreBackupRestorePromiseTest', function () { ...@@ -406,11 +393,11 @@ describe('rdbStoreBackupRestorePromiseTest', function () {
* @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0130 * @tc.number SUB_DDM_RDB_JS_RdbBackupRestoreTest_0130
* @tc.desc RDB restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreTest_0130 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
await RdbStore.restore(DATABASE_BACKUP_NAME) await RdbStore.restore(DATABASE_BACKUP_NAME)
ReStoreTest(DATABASE_BACKUP_NAME) await ReStoreTest(DATABASE_BACKUP_NAME)
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************")
}) })
......
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import relationalStoreBackupRestoreCallbackTest from './RelationalStoreBackupRestoreCallbackJsunit.test.js'
import relationalStoreBackupRestoreWithFAContextTest from './RelationalStoreBackupRestoreWithFAContextJsunit.test.js'
import relationalStoreDeleteTest from './RelationalStoreDeleteJsunit.test.js' import relationalStoreDeleteTest from './RelationalStoreDeleteJsunit.test.js'
import relationalStoreDistributedTest from './RelationalStoreDistributedJsunit.test.js' import relationalStoreDistributedTest from './RelationalStoreDistributedJsunit.test.js'
import relationalStoreInsertTest from './RelationalStoreInsertJsunit.test.js' import relationalStoreInsertTest from './RelationalStoreInsertJsunit.test.js'
...@@ -27,9 +26,9 @@ import relationalStoreUpdateTest from './RelationalStoreUpdateJsunit.test.js' ...@@ -27,9 +26,9 @@ import relationalStoreUpdateTest from './RelationalStoreUpdateJsunit.test.js'
import relationalStoreQueryTest from './RelationalStoreQuery.test.js' import relationalStoreQueryTest from './RelationalStoreQuery.test.js'
import relationalStoreEncryptionTest from './RelationalStoreEncryptionJsunit.test.js' import relationalStoreEncryptionTest from './RelationalStoreEncryptionJsunit.test.js'
import relationalStorePredicatesComplexFiledTest from './RelationalStorePredicatesComplexFiledJsunit.test.js' import relationalStorePredicatesComplexFiledTest from './RelationalStorePredicatesComplexFiledJsunit.test.js'
import relationalStoreBackupRestoreWithFAContextTest from './RelationalStoreBackupRestoreWithFAContextJsunit.test.js'
import relationalStoreBackupRestoreCallbackTest from './RelationalStoreBackupRestoreCallbackJsunit.test.js'
export default function testsuite() { export default function testsuite() {
relationalStoreBackupRestoreCallbackTest()
relationalStoreBackupRestoreWithFAContextTest()
relationalStoreDeleteTest() relationalStoreDeleteTest()
relationalStoreDistributedTest() relationalStoreDistributedTest()
relationalStoreInsertTest() relationalStoreInsertTest()
...@@ -43,4 +42,6 @@ export default function testsuite() { ...@@ -43,4 +42,6 @@ export default function testsuite() {
relationalStoreQueryTest() relationalStoreQueryTest()
relationalStoreEncryptionTest() relationalStoreEncryptionTest()
relationalStorePredicatesComplexFiledTest() relationalStorePredicatesComplexFiledTest()
relationalStoreBackupRestoreWithFAContextTest()
relationalStoreBackupRestoreCallbackTest()
} }
...@@ -19,7 +19,7 @@ import fileio from '@ohos.fileio' ...@@ -19,7 +19,7 @@ import fileio from '@ohos.fileio'
const TAG = "[RelationalStore_JSKITS_TEST]" const TAG = "[RelationalStore_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS backupTest (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " 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/" const DATABASE_DIR = "/data/storage/el2/database/entry/rdb/"
var RdbStore var RdbStore
var context = ability_featureAbility.getContext() var context = ability_featureAbility.getContext()
...@@ -101,30 +101,30 @@ function ReStoreCallbackTest(restoreName) { ...@@ -101,30 +101,30 @@ function ReStoreCallbackTest(restoreName) {
export default function relationalStoreBackupRestoreCallbackTest() { export default function relationalStoreBackupRestoreCallbackTest() {
describe('relationalStoreBackupRestoreCallbackTest', function () { describe('relationalStoreBackupRestoreCallbackTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
}) })
beforeEach(async function () { beforeEach(async function () {
console.info(TAG + 'beforeEach') console.info(TAG + 'beforeEach')
RdbStore = await CreatRdbStore(context, STORE_CONFIG) RdbStore = await CreatRdbStore(context, STORE_CONFIG)
}) })
afterEach(async function () { afterEach(async function () {
console.info(TAG + 'afterEach') console.info(TAG + 'afterEach')
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name) await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME) await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME)
await data_Rdb.deleteRdbStore(context, "BackupTest003.db") await data_Rdb.deleteRdbStore(context, "BackupTest003.db")
}) })
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
}) })
console.info(TAG + "*************Unit Test Begin*************") console.info(TAG + "*************Unit Test Begin*************")
/** /**
* @tc.name RelationalStore Backup Restore test * @tc.name RelationalStore Backup Restore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0100 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0100
...@@ -132,10 +132,11 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -132,10 +132,11 @@ export default function relationalStoreBackupRestoreCallbackTest() {
*/ */
it('RdbBackupRestoreCallbackTest_0100', 0, async function (done) { it('RdbBackupRestoreCallbackTest_0100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 start *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 start *************")
// RelationalStore backup function test // RelationalStore backup function test
await RdbStore.backup(DATABASE_BACKUP_NAME,async (err, data) => { 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() expect(false).assertTrue()
}else{ }else{
try { try {
...@@ -145,8 +146,7 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -145,8 +146,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
expect(false).assertTrue() expect(false).assertTrue()
} }
} }
// RelationalStore before restored, delete data // RelationalStore before restored, delete data
let deleteData = new data_Rdb.RdbPredicates("backupTest") let deleteData = new data_Rdb.RdbPredicates("backupTest")
deleteData.equalTo("name", "zhangsan") deleteData.equalTo("name", "zhangsan")
...@@ -159,9 +159,9 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -159,9 +159,9 @@ export default function relationalStoreBackupRestoreCallbackTest() {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue() expect(false).assertTrue()
} catch (err) { } catch (err) {
expect(true).assertTrue() console.info(TAG + " restore1 done ")
} }
try { try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) { } catch (err) {
...@@ -189,10 +189,10 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -189,10 +189,10 @@ export default function relationalStoreBackupRestoreCallbackTest() {
done() done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 end *************")
}) })
}) })
}) })
}) })
/** /**
* @tc.name RelationalStore Backup test * @tc.name RelationalStore Backup test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0200 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0200
...@@ -202,14 +202,14 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -202,14 +202,14 @@ export default function relationalStoreBackupRestoreCallbackTest() {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 start *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 start *************")
// RelationalStore backup function test, backup file name empty // RelationalStore backup function test, backup file name empty
BackupCallbackTest("") BackupCallbackTest("")
// RelationalStore backup function test, backup file name already exists // RelationalStore backup function test, backup file name already exists
BackupCallbackTest(STORE_CONFIG.name) BackupCallbackTest(STORE_CONFIG.name)
done() done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0300 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0300
...@@ -219,17 +219,17 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -219,17 +219,17 @@ export default function relationalStoreBackupRestoreCallbackTest() {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 start *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 start *************")
let backupName = "BackupTest003.db" let backupName = "BackupTest003.db"
await RdbStore.backup(backupName) await RdbStore.backup(backupName)
// RelationalStore restore function test, backup file name empty // RelationalStore restore function test, backup file name empty
ReStoreCallbackTest("") ReStoreCallbackTest("")
// RelationalStore restore function test, backup file is specified to database name // RelationalStore restore function test, backup file is specified to database name
ReStoreCallbackTest(STORE_CONFIG.name) ReStoreCallbackTest(STORE_CONFIG.name)
done() done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0400 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0400
...@@ -238,7 +238,7 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -238,7 +238,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
it('RdbBackupRestoreCallbackTest_0400', 0, async function (done) { it('RdbBackupRestoreCallbackTest_0400', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 start *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 start *************")
let dbName = "notExistName.db" let dbName = "notExistName.db"
// RelationalStore restore function test, backup file does not exists // RelationalStore restore function test, backup file does not exists
try { try {
fileio.accessSync(DATABASE_DIR + dbName) fileio.accessSync(DATABASE_DIR + dbName)
...@@ -246,20 +246,20 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -246,20 +246,20 @@ export default function relationalStoreBackupRestoreCallbackTest() {
} catch { } catch {
ReStoreCallbackTest(dbName) ReStoreCallbackTest(dbName)
} }
done() done()
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0500 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0500
* @tc.desc RelationalStore restore function test * @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 *************") 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) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
...@@ -270,19 +270,15 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -270,19 +270,15 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}catch(err){ }catch(err){
expect(false).assertTrue(); expect(false).assertTrue();
} }
data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => { data_Rdb .deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => {
try{ try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ }catch(err){
console.info(TAG + 'error2 ' + err) console.info(TAG + 'RdbBackupRestoreCallbackTest_0500 deleteRdbStore done')
expect(true).assertTrue();
} }
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
console.info(`${TAG} Backup database second failed, error: message: ${err.message}`) console.info(`${TAG} Backup database second failed, error: message: ${err.message}`)
expect(true).assertTrue()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
}else{ }else{
try{ try{
console.info(TAG + 'Backup database second success') console.info(TAG + 'Backup database second success')
...@@ -290,130 +286,121 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -290,130 +286,121 @@ export default function relationalStoreBackupRestoreCallbackTest() {
}catch(err){ }catch(err){
expect(false).assertTrue(); expect(false).assertTrue();
} }
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************")
} }
}) })
}) })
} }
}) })
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0600 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0600
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 start *************")
// Backup file is specified to database name // Backup file is specified to database name
RdbStore.backup(STORE_CONFIG.name, (err, data) => { RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){ expect(err != null).assertTrue()
expect(true).assertTrue() console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup1 done")
}else{
expect(false).assertTrue()
}
})
RdbStore.backup(STORE_CONFIG.name, (err, data) => { RdbStore.backup(STORE_CONFIG.name, (err, data) => {
if(err != null){ expect(err != null).assertTrue()
expect(true).assertTrue() console.info(TAG + "RdbBackupRestoreCallbackTest_0600 backup2 done")
}else{ done();
expect(false).assertTrue() console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
} })
}) })
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0700 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0700
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 start *************")
let DATABASE_BACKUP_TEST_NAME = "BackupTest.db" let DATABASE_BACKUP_TEST_NAME = "BackupTest.db"
RdbStore.backup(DATABASE_BACKUP_TEST_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_TEST_NAME, async (err, data) => {
if(err != null){ if (err != null) {
expect(false).assertTrue() expect(false).assertTrue()
}else{ } else {
expect(true).assertTrue() console.info(TAG + "RdbBackupRestoreCallbackTest_0700 backup done")
}
})
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()
} }
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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0800 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0800
* @tc.desc RelationalStore restore function test * @tc.desc RelationalStore restore function test
*/ */
it('RdbBackupRestoreCallbackTest_0800', 0, async function (done) { it('RdbBackupRestoreCallbackTest_0800', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 start *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 start *************")
BackupCallbackTest() BackupCallbackTest()
done(); done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0900 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0900
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 start *************")
BackupCallbackTest([DATABASE_BACKUP_NAME]) BackupCallbackTest([DATABASE_BACKUP_NAME])
done(); done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1000 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1000
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
} }
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
}) })
ReStoreCallbackTest([DATABASE_BACKUP_NAME])
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************")
}) })
/** /**
* @tc.name RelationalStore BackupRestore test * @tc.name RelationalStore BackupRestore test
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1100 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1100
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
} }
ReStoreCallbackTest()
done();
}) })
ReStoreCallbackTest()
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************")
}) })
...@@ -422,15 +409,15 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -422,15 +409,15 @@ export default function relationalStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1200 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1200
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
expect(false).assertTrue() expect(false).assertTrue()
} }
BackupCallbackTest(DATABASE_BACKUP_NAME)
done();
}) })
BackupCallbackTest(DATABASE_BACKUP_NAME)
done();
console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************")
}) })
...@@ -439,7 +426,7 @@ export default function relationalStoreBackupRestoreCallbackTest() { ...@@ -439,7 +426,7 @@ export default function relationalStoreBackupRestoreCallbackTest() {
* @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1300 * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1300
* @tc.desc RelationalStore restore function test * @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 *************") console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 start *************")
RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => {
if(err != null){ if(err != null){
......
...@@ -131,8 +131,8 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -131,8 +131,8 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0010', 0, async function (done) { it('RdbBackupRestoreTest_0010', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************")
// RelationalStore backup function test // RDB backup function test
RdbStore.backup(DATABASE_BACKUP_NAME).then(async() => { await RdbStore.backup(DATABASE_BACKUP_NAME)
try { try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
...@@ -140,31 +140,29 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -140,31 +140,29 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info("RdbBackupRestoreTest_0010 backup success") console.info("RdbBackupRestoreTest_0010 backup success")
expect(false).assertTrue() expect(false).assertTrue()
} }
// RelationalStore before restored, delete data // RDB before restored, delete data
let deleteData = new data_Rdb.RdbPredicates("test") let deleteData = new data_Rdb.RdbPredicates("test")
deleteData.equalTo("name", "zhangsan") deleteData.equalTo("name", "zhangsan")
await RdbStore.delete(deleteData) await RdbStore.delete(deleteData)
// RelationalStore restore function test // RDB restore function test
RdbStore.restore(DATABASE_BACKUP_NAME).then(async () => { await RdbStore.restore(DATABASE_BACKUP_NAME)
try { try {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
expect(false).assertTrue() expect(false).assertTrue()
} catch (err) { } catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success") console.info("RdbBackupRestoreTest_0010 restore success")
expect(true).assertTrue()
} }
try { try {
fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name)
} catch (err) { } catch (err) {
console.info("RdbBackupRestoreTest_0010 restore success2")
expect(false).assertTrue() expect(false).assertTrue()
} }
// RelationalStore after restored, data query test // RDB after restored, data query test
let predicates = new data_Rdb.RdbPredicates("test") let predicates = new data_Rdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan") predicates.equalTo("name", "zhangsan")
RdbStore.query(predicates).then((resultSet)=>{ let resultSet = await RdbStore.query(predicates)
try { try {
console.info(TAG + "After restore resultSet query done") console.info(TAG + "After restore resultSet query done")
resultSet.goToFirstRow(); resultSet.goToFirstRow();
...@@ -183,22 +181,11 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -183,22 +181,11 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err) console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err)
expect(false).assertTrue() expect(false).assertTrue()
} }
resultSet = null resultSet.close()
RdbStore = null RdbStore = null
done() done()
console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************") 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 () { ...@@ -281,7 +268,6 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ }catch(err){
console.info(TAG + 'error2 ' + err) console.info(TAG + 'error2 ' + err)
expect(true).assertTrue();
} }
}) })
}).then(() => { }).then(() => {
...@@ -293,9 +279,9 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -293,9 +279,9 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info(TAG + 'error3 ' + err) console.info(TAG + 'error3 ' + err)
expect(false).assertTrue() expect(false).assertTrue()
} }
done();
}) })
}) })
done()
console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************")
}) })
...@@ -312,7 +298,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -312,7 +298,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
expect(false).assertTrue() ; expect(false).assertTrue() ;
}).catch((err) => { }).catch((err) => {
console.info(TAG + "Backup database error"); console.info(TAG + "Backup database error");
expect(true).assertTrue() ; expect(err != null).assertTrue() ;
done(); done();
}) })
}) })
...@@ -328,11 +314,11 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -328,11 +314,11 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
try{ try{
fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME)
}catch(err){ }catch(err){
expect(true).assertTrue(); console.info(TAG + 'deleteRdbStore done')
} }
await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => { await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => {
console.info(TAG + 'Restore fail: ' + err) console.info(TAG + 'Restore fail: ' + err.code);
expect(true).assertTrue(); expect(err != null).assertTrue();
}) })
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************")
...@@ -370,7 +356,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -370,7 +356,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0100', 0, async function (done) { it('RdbBackupRestoreTest_0100', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest([DATABASE_BACKUP_NAME]) await ReStoreTest([DATABASE_BACKUP_NAME])
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************")
}) })
...@@ -383,7 +369,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -383,7 +369,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0110', 0, async function (done) { it('RdbBackupRestoreTest_0110', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
ReStoreTest() await ReStoreTest()
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************")
}) })
...@@ -396,7 +382,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -396,7 +382,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
it('RdbBackupRestoreTest_0120', 0, async function (done) { it('RdbBackupRestoreTest_0120', 0, async function (done) {
console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
BackupTest(DATABASE_BACKUP_NAME) await BackupTest(DATABASE_BACKUP_NAME)
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************")
}) })
...@@ -410,7 +396,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () { ...@@ -410,7 +396,7 @@ describe('relationalStoreBackupRestorePromiseTest', function () {
console.info(TAG + "************* RdbBackupRestoreTest_0130 start *************") console.info(TAG + "************* RdbBackupRestoreTest_0130 start *************")
await RdbStore.backup(DATABASE_BACKUP_NAME) await RdbStore.backup(DATABASE_BACKUP_NAME)
await RdbStore.restore(DATABASE_BACKUP_NAME) await RdbStore.restore(DATABASE_BACKUP_NAME)
ReStoreTest(DATABASE_BACKUP_NAME) await ReStoreTest(DATABASE_BACKUP_NAME)
done(); done();
console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************") console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************")
}) })
......
...@@ -137,27 +137,25 @@ describe('relationalStoreTest', function () { ...@@ -137,27 +137,25 @@ describe('relationalStoreTest', function () {
* @tc.require: I5PIL6 * @tc.require: I5PIL6
*/ */
it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400', 0, async function (done) { it('SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 start *************"); console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTORE_PROMISE_0400 start *************");
let config = { let config = {
name: "secure.db", name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S4 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();
} }
}).catch((err) => { let storePromise = dataRdb.getRdbStore(context, config);
expect(null).assertFail(); 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 * @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.
先完成此消息的编辑!
想要评论请 注册