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

!7191 【xts_acts】【master】【distributeddatamgr】RelationalStoreJsunit.test.test.js 文件新增用例

Merge pull request !7191 from 于小雅/yu0111
......@@ -13,39 +13,40 @@
* 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 data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility';
var context = ability_featureAbility.getContext();
var contextApplication = context.getApplicationContext()
const TAG = "[RelationalStore_JSKITS_TEST]"
var contextApplication = context.getApplicationContext();
const TAG = "[RelationalStore_JSKITS_TEST]";
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {
name: "rdbstore.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
};
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default function relationalStoreTest() {
describe('relationalStoreTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
console.info(TAG + 'beforeAll');
})
beforeEach(function () {
console.info(TAG + 'beforeEach')
console.info(TAG + 'beforeEach');
})
afterEach(async function () {
console.info(TAG + 'afterAll')
console.info(TAG + 'afterAll');
await data_Rdb.deleteRdbStore(context,"rdbstore.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll')
console.info(TAG + 'afterAll');
})
console.info(TAG + "*************Unit Test Begin*************");
......@@ -88,8 +89,8 @@ describe('relationalStoreTest', function () {
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await storePromise;
storePromise = null;
done();
console.info(TAG + "************* testRdbStore0002 end *************");
})
......@@ -105,7 +106,7 @@ describe('relationalStoreTest', function () {
let storeConfig = {
name: "/wrong/rdbstore.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
};
try{
data_Rdb.getRdbStore(context, storeConfig).then(async (ret) => {
console.info(TAG + "getRdbStore done" + ret);
......@@ -115,8 +116,8 @@ describe('relationalStoreTest', function () {
})
expect(false).assertTrue();
}catch(error){
console.info(TAG + `catch err: failed: err: code= ${error.code}, message = ${error.message}`)
expect(error.code).assertEqual("401")
console.info(TAG + `catch err: failed: err: code= ${error.code}, message = ${error.message}`);
expect(error.code).assertEqual("401");
done();
console.info(TAG + "************* testRdbStore0003 end *************");
}
......@@ -130,9 +131,9 @@ describe('relationalStoreTest', function () {
it('testRdbStore0004', 0, async function (done) {
console.info(TAG + "************* testRdbStore0004 start *************");
try{
let store = await data_Rdb.getRdbStore(context, STORE_CONFIG)
let store = await data_Rdb.getRdbStore(context, STORE_CONFIG);
await store.executeSql(CREATE_TABLE_TEST);
await data_Rdb.deleteRdbStore(context, "rdbstore.db")
await data_Rdb.deleteRdbStore(context, "rdbstore.db");
}catch (e) {
expect(null).assertFail();
}
......@@ -149,9 +150,9 @@ describe('relationalStoreTest', function () {
console.info(TAG + "************* testRdbStore0005 start *************");
try {
let store = await data_Rdb.getRdbStore(context, STORE_CONFIG);
console.info(TAG + "Get rdbstore success")
console.info(TAG + "Get rdbstore success");
await store.executeSql(CREATE_TABLE_TEST);
await data_Rdb.deleteRdbStore(context, "rdbstore.db")
await data_Rdb.deleteRdbStore(context, "rdbstore.db");
} catch (e) {
expect(null).assertFail();
}
......@@ -171,14 +172,14 @@ describe('relationalStoreTest', function () {
const STORE_CONFIG= {
name: "rdbstorecontext.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
rdbstore = await data_Rdb.getRdbStore(context,STORE_CONFIG)
console.info(TAG + "Get rdbstore success")
};
rdbstore = await data_Rdb.getRdbStore(context,STORE_CONFIG);
console.info(TAG + "Get rdbstore success");
expect(rdbstore != null).assertTrue();
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
}catch(err){
console.info(TAG + "Get rdbstore fail catch err: " + err)
expect(null).assertFail()
console.info(TAG + "Get rdbstore fail catch err: " + err);
expect(null).assertFail();
}
rdbstore = null;
done();
......@@ -197,14 +198,14 @@ describe('relationalStoreTest', function () {
const STORE_CONFIG = {
name: "rdbstorecontext.db",
securityLevel: data_Rdb.SecurityLevel.S1
}
rdbstore = await data_Rdb.getRdbStore(contextApplication,STORE_CONFIG)
console.info(TAG + "Get rdbstore success")
};
rdbstore = await data_Rdb.getRdbStore(contextApplication,STORE_CONFIG);
console.info(TAG + "Get rdbstore success");
expect(rdbstore != null).assertTrue();
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
}catch(err){
console.info(TAG + "Get rdbstore fail catch err: " + err)
expect(null).assertFail()
console.info(TAG + "Get rdbstore fail catch err: " + err);
expect(null).assertFail();
}
rdbstore = null;
done();
......@@ -219,14 +220,14 @@ describe('relationalStoreTest', function () {
it('testRdbStore0008', 0, async function (done) {
console.info(TAG + "************* testRdbStore0008 start *************");
data_Rdb.getRdbStore(context, STORE_CONFIG, async (err,data) => {
console.info(TAG + "getRdbStore finish")
console.info(TAG + "getRdbStore success: " + data)
console.info(TAG + "getRdbStore finish");
console.info(TAG + "getRdbStore success: " + data);
expect(data != null).assertTrue();
await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name);
done();
console.info(TAG + "************* testRdbStore0008 end *************");
});
await sleep(1000)
await sleep(1000);
})
/**
......@@ -237,14 +238,243 @@ describe('relationalStoreTest', function () {
it('testRdbStore0009', 0, async function(done){
console.info(TAG + "************* testRdbStore0009 start *************");
data_Rdb.getRdbStore(contextApplication, STORE_CONFIG, async (err,data) => {
console.info(TAG + "getRdbStore finish")
console.info(TAG + "getRdbStore success: " + data)
console.info(TAG + "getRdbStore finish");
console.info(TAG + "getRdbStore success: " + data);
expect(data != null).assertTrue();
await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name)
await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name);
done();
console.info(TAG + "************* testRdbStore0009 end *************");
})
await sleep(1000);
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0010
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0010', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0010 start *************");
data_Rdb.getRdbStore(context, STORE_CONFIG, async (err, store) => {
if (err) {
expect(null).assertFail();
}
expect(store.openStatus == data_Rdb.OpenStatus.ON_CREATE).assertTrue();
data_Rdb.getRdbStore(context, STORE_CONFIG, async (err, store) => {
if (err) {
expect(null).assertFail();
}
expect(store.openStatus == data_Rdb.OpenStatus.ON_OPEN).assertTrue();
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
done();
})
})
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0010 end *************");
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0020
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0020', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0020 start *************");
try {
let rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG);
expect(rdbStore.openStatus == data_Rdb.OpenStatus.ON_CREATE).assertTrue();
await rdbStore.executeSql(CREATE_TABLE_TEST);
rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG);
expect(rdbStore.openStatus == data_Rdb.OpenStatus.ON_OPEN).assertTrue();
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
done();
} catch(e) {
console.log("catch err: failed, err: code=" + e.code + " message=" + e.message);
expect(null).assertFail();
done();
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0020 end *************");
}
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0030
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0030', 0, async function(done){
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0030 start *************");
await data_Rdb.getRdbStore(contextApplication, STORE_CONFIG, async function(err,rdbStore){
try {
if (err) {
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0030 failed, err: " + err);
expect().assertFail();
return;
}
expect(rdbStore.openStatus == data_Rdb.OpenStatus.ON_CREATE).assertTrue();
} catch (err) {
console.log("SUB_DDM_RelationalStore_OpenStatus_0030 status is " + rdbStore.OpenStatus);
}
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0030 successfully.");
})
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
done();
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0030 successfully end.");
await sleep(1000);
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0040
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0040', 0, async function(done){
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0040 start *************");
await data_Rdb.getRdbStore(contextApplication, STORE_CONFIG, async function(err,rdbStore){
try {
if (err) {
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0040 failed, err: " + err);
return;
}
expect(rdbStore.openStatus ==data_Rdb.OpenStatus.ON_CREATE).assertTrue();
} catch (err) {
console.log("SUB_DDM_RelationalStore_OpenStatus_0040 status1 is "+ rdbStore.OpenStatus);
}
});
await sleep(1000)
await sleep(1000);
await data_Rdb.getRdbStore(contextApplication, STORE_CONFIG, async function(err,rdbStore){
try {
if (err) {
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0040 failed, err: " + err);
expect().assertFail();
return;
}
expect(rdbStore.openStatus ==data_Rdb.OpenStatus.ON_OPEN).assertTrue();
} catch (err) {
console.log("SUB_DDM_RelationalStore_OpenStatus_0040 status is "+ rdbStore.OpenStatus);
}
});
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
done();
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0040 successfully end.");
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0050
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0050', 0, async function(done){
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0050 start *************");
try {
let promise = null;
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG);
promise =null;
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0050 promise.openStatus: " + promise.openStatus);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0050 data_Rdb.OpenStatus.ON_OPEN: " + data_Rdb.OpenStatus.ON_OPEN);
expect(promise.openStatus).assertEqual(data_Rdb.OpenStatus.ON_OPEN);
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
} catch (err) {
console.info(TAG + "Get rdbstore fail catch err: " + err);
expect(null).assertFail();
}
done();
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0050 successfully end.");
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0060
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0060', 0, async function(done){
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0060 start *************");
let STORE_CONFIG1 = {
name: "rdbnumber.db",
securityLevel: data_Rdb.SecurityLevel.S1
};
try {
let promise = null;
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0060 STORE_CONFIG promise.openStatus: " + promise.openStatus);
expect(promise.openStatus).assertEqual(data_Rdb.OpenStatus.ON_CREATE);
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG1);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0060 STORE_CONFIG1 promise.openStatus: " + promise.openStatus);
expect(promise.openStatus).assertEqual(data_Rdb.OpenStatus.ON_CREATE);
} catch (err) {
console.info(TAG + "Get SUB_DDM_RelationalStore_OpenStatus_0060 fail catch err: " + err);
expect(null).assertFail();
}
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
await data_Rdb.deleteRdbStore(context, STORE_CONFIG1.name);
done();
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0060 successfully end.");
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0070
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0070', 0, async function(done){
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0070 start *************");
let STORE_CONFIG1 = {
name: "rdbnumber.db",
securityLevel: data_Rdb.SecurityLevel.S1
};
try {
let promise = null;
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0070 STORE_CONFIG promise.openStatus: " + promise.openStatus);
expect(promise.openStatus).assertEqual(data_Rdb.OpenStatus.ON_CREATE);
let rdbResult = await data_Rdb.getRdbStore(context, STORE_CONFIG1);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0070 STORE_CONFIG1 rdbResult.openStatus: " + rdbResult.openStatus);
expect(rdbResult.openStatus).assertEqual(data_Rdb.OpenStatus.ON_CREATE);
} catch (err) {
console.info(TAG + "Get SUB_DDM_RelationalStore_OpenStatus_0070 fail catch err: " + err);
expect(null).assertFail();
}
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
await data_Rdb.deleteRdbStore(context, STORE_CONFIG1.name);
done();
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0070 successfully end.");
})
/**
* @tc.number SUB_DDM_RelationalStore_OpenStatus_0080
* @tc.name Get relational store status test
* @tc.desc relational OpenStatus
*/
it('SUB_DDM_RelationalStore_OpenStatus_0080', 0, async function(done){
console.info(TAG + "************* SUB_DDM_RelationalStore_OpenStatus_0050 start *************");
let STORE_CONFIG1 = {
name: "rdbnumber.db",
securityLevel: data_Rdb.SecurityLevel.S1
};
try {
let promise = null;
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0080 STORE_CONFIG promise.openStatus: " + promise.openStatus);
expect(promise.openStatus).assertEqual(data_Rdb.OpenStatus.ON_CREATE);
let rdbResult = await data_Rdb.getRdbStore(context, STORE_CONFIG1);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0080 STORE_CONFIG1 rdbResult.openStatus: " + rdbResult.openStatus);
expect(rdbResult.openStatus).assertEqual(data_Rdb.OpenStatus.ON_CREATE);
promise = null;
promise = await data_Rdb.getRdbStore(context, STORE_CONFIG);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0080 STORE_CONFIG promise.openStatus: " + promise.openStatus);
expect(promise.openStatus).assertEqual(data_Rdb.OpenStatus.ON_OPEN);
rdbResult = null;
rdbResult = await data_Rdb.getRdbStore(context, STORE_CONFIG1);
console.info("Get SUB_DDM_RelationalStore_OpenStatus_0080 STORE_CONFIG1 rdbResult.openStatus: " + rdbResult.openStatus);
expect(rdbResult.openStatus).assertEqual(data_Rdb.OpenStatus.ON_OPEN);
} catch (err) {
console.info(TAG + "Get SUB_DDM_RelationalStore_OpenStatus_0080 fail catch err: " + err);
expect(null).assertFail();
}
await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name);
await data_Rdb.deleteRdbStore(context, STORE_CONFIG1.name);
done();
console.log("Get SUB_DDM_RelationalStore_OpenStatus_0080 successfully end.");
})
console.info(TAG + "*************Unit Test End*************");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册