未验证 提交 05a9c1bf 编写于 作者: O openharmony_ci 提交者: Gitee

!4318 【Distributeddatamgr】【OpenHarmony-3.2-Bata2】文件修改,补齐API覆盖率

Merge pull request !4318 from yanglifeng/cherry-pick-1657782912
...@@ -16,14 +16,14 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -16,14 +16,14 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import dataRdb from '@ohos.data.rdb'; import dataRdb from '@ohos.data.rdb';
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, " + "name NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; 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 = { const STORE_CONFIG = {
name: "ExcuteSqlTest.db", name: "ExcuteSqlTest.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
describe('rdbstoreStoreExcuteSqlTest', function () { describe('rdbStoreInsertTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
...@@ -212,6 +212,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () { ...@@ -212,6 +212,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () {
it('ExcuteSqlTest0003', 0, async function (done) { it('ExcuteSqlTest0003', 0, async function (done) {
console.info(TAG + "************* ExcuteSqlTest0003 start *************"); console.info(TAG + "************* ExcuteSqlTest0003 start *************");
var u8 = new Uint8Array([3, 4, 5]) var u8 = new Uint8Array([3, 4, 5])
var nameStr = "lisi" + "e".repeat(2000) + "zhangsan"
//插入 //插入
{ {
const valueBucket = { const valueBucket = {
...@@ -231,7 +232,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () { ...@@ -231,7 +232,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () {
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", "name": nameStr,
"age": 19, "age": 19,
"salary": 100.5, "salary": 100.5,
"blobType": u8, "blobType": u8,
...@@ -247,7 +248,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () { ...@@ -247,7 +248,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () {
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", "name": nameStr,
"age": 28, "age": 28,
"salary": 100.5, "salary": 100.5,
"blobType": u8, "blobType": u8,
...@@ -261,6 +262,106 @@ describe('rdbstoreStoreExcuteSqlTest', function () { ...@@ -261,6 +262,106 @@ describe('rdbstoreStoreExcuteSqlTest', function () {
}) })
await insertPromise await insertPromise
} }
{
let predicates = await new dataRdb.RdbPredicates("test")
predicates.equalTo("name", nameStr)
let querySqlPromise = rdbStore.query(predicates)
querySqlPromise.then(async (resultSet) => {
await expect(2).assertEqual(resultSet.rowCount)
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
}
{
let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE age = 19 AND name ='" + nameStr + "'")
executeSqlPromise.then(async () => {
await console.info(TAG + "executeSql done." );
}).catch((err) => {
expect(null).assertFail();
})
await executeSqlPromise
}
{
let querySqlPromise = rdbStore.querySql("SELECT * FROM test WHERE name ='" + nameStr + "'")
querySqlPromise.then(async (resultSet) => {
await expect(1).assertEqual(resultSet.rowCount)
expect(true).assertEqual(resultSet.goToFirstRow())
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(nameStr).assertEqual(name)
expect(2012).assertEqual(name.length)
expect(28).assertEqual(age)
expect(100.5).assertEqual(salary)
expect(3).assertEqual(blobType[0])
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
}
done();
console.info(TAG + "************* ExcuteSqlTest0003 end *************");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_ExcuteSql_0040
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0004', 0, async function (done) {
console.info(TAG + "************* ExcuteSqlTest0004 start *************");
var u8 = new Uint8Array([3, 4, 5])
//插入
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(10).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 19,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(11).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(12).assertEqual(ret);
await console.info(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{ {
let QuerySqlPromise = rdbStore.executeSql("DROP TABLE IF EXISTS test") let QuerySqlPromise = rdbStore.executeSql("DROP TABLE IF EXISTS test")
QuerySqlPromise.then(async (resultSet) => { QuerySqlPromise.then(async (resultSet) => {
...@@ -271,7 +372,9 @@ describe('rdbstoreStoreExcuteSqlTest', function () { ...@@ -271,7 +372,9 @@ describe('rdbstoreStoreExcuteSqlTest', function () {
await QuerySqlPromise await QuerySqlPromise
} }
done(); done();
console.info(TAG + "************* ExcuteSqlTest0003 end *************"); console.info(TAG + "************* ExcuteSqlTest0004 end *************");
}) })
console.info(TAG + "*************Unit Test End*************"); console.info(TAG + "*************Unit Test End*************");
}) })
\ No newline at end of file
...@@ -679,6 +679,7 @@ describe('objectStoreTest', function () { ...@@ -679,6 +679,7 @@ describe('objectStoreTest', function () {
*/ */
it('testSave001', 0, async function (done) { it('testSave001', 0, async function (done) {
console.info(TAG + "************* testSave001 start *************"); console.info(TAG + "************* testSave001 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession1"); gObject.setSessionId("tmpsession1");
let result = await gObject.save("local"); let result = await gObject.save("local");
...@@ -706,13 +707,15 @@ describe('objectStoreTest', function () { ...@@ -706,13 +707,15 @@ describe('objectStoreTest', function () {
*/ */
it('testSave002', 0, function (done) { it('testSave002', 0, function (done) {
console.info(TAG + "************* testSave002 start *************"); console.info(TAG + "************* testSave002 start *************");
let SaveSuccessResponse
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession1"); gObject.setSessionId("tmpsession1");
gObject.save("local",(result)=>{ gObject.save("local",(result)=>{
expect(result != null).assertTrue(); SaveSuccessResponse = result
expect(result.sessionId == "tmpsession1").assertEqual(false); expect(SaveSuccessResponse != null).assertTrue();
expect(result.version == gObject.__version).assertEqual(false); expect(SaveSuccessResponse.sessionId == "tmpsession1").assertEqual(false);
expect(result.deviceId == "local").assertEqual(false); expect(SaveSuccessResponse.version == gObject.__version).assertEqual(false);
expect(SaveSuccessResponse.deviceId == "local").assertEqual(false);
}); });
gObject.setSessionId(""); gObject.setSessionId("");
...@@ -761,9 +764,11 @@ describe('objectStoreTest', function () { ...@@ -761,9 +764,11 @@ describe('objectStoreTest', function () {
expect(result.sessionId != "123456").assertEqual(true); expect(result.sessionId != "123456").assertEqual(true);
expect(result.version != gObject.__version).assertEqual(true); expect(result.version != gObject.__version).assertEqual(true);
expect(result.deviceId != "local").assertEqual(true); expect(result.deviceId != "local").assertEqual(true);
let RevokeSaveSuccessResponse =undefined;
gObject.revokeSave((err,ret) => { gObject.revokeSave((err,ret) => {
RevokeSaveSuccessResponse = ret;
expect(err == null).assertTrue(); expect(err == null).assertTrue();
expect(RevokeSaveSuccessResponse == undefined).assertTrue();
}); });
done(); done();
console.info(TAG + "************* testRevokeSave002 end *************"); console.info(TAG + "************* testRevokeSave002 end *************");
......
...@@ -326,14 +326,14 @@ export default function DataShareCombinationRdb() { ...@@ -326,14 +326,14 @@ export default function DataShareCombinationRdb() {
}) })
await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => {
console.info("TestDataShare going query = " + data); console.info("TestDataShare going query = " + data);
globalThis.helper.notifyChange(uri, notifyChangeCallback); globalThis.helper.notifyChange(uri);
}).catch((err) => { }).catch((err) => {
console.info("DataShareNotifyChangeRdb0101 query err" + JSON.stringify(err)); console.info("DataShareNotifyChangeRdb0101 query err" + JSON.stringify(err));
expect(err).assertFail(); expect(err).assertFail();
}) })
await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => {
console.info("TestDataShare going delete = " + data); console.info("TestDataShare going delete = " + data);
globalThis.helper.notifyChange(uri, notifyChangeCallback); globalThis.helper.notifyChange(uri);
}).catch((err) => { }).catch((err) => {
console.info("DataShareNotifyChangeRdb0101 delete err" + JSON.stringify(err)); console.info("DataShareNotifyChangeRdb0101 delete err" + JSON.stringify(err));
expect(err).assertFail(); expect(err).assertFail();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册