提交 52087307 编写于 作者: O openharmony_ci 提交者: Gitee

!799 add rdb js test cases

Merge pull request !799 from smagicyun/OpenHarmony-3.0-LTS
......@@ -16,3 +16,11 @@ require('./StorageHelperJsunit.test.js')
require('./StorageSyncJsunit.test.js')
require('./StoragePromiseJsunit.test.js')
require('./StorageCallBackJsunit.test.js')
require('./RdbstoreInsertJsunit.test.js')
require('./RdbstoreDeleteJsunit.test.js')
require('./RdbstoreResultsetJsunit.test.js')
require('./RdbstorePredicatesJsunit.test.js')
require('./RdbstoreRdbstoreJsunit.test.js')
require('./RdbstoreStoreExcuteSqlJsunit.test.js')
require('./RdbstoreUpdateJsunit.test.js')
require('./DataAbilityPredicatesJsunit.test.js')
\ No newline at end of file
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb';
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)";
const STORE_CONFIG = {
name: "Delete.db",
}
var rdbStore = undefined;
describe('rdbStoreDeleteTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await rdbStore.executeSql("DELETE FROM test");
rdbStore = null
await ohos_data_rdb.deleteRdbStore("Delete.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0010
* @tc.desc rdb delete test
*/
it('testRdbStoreDelete0001', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 38,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
//删除
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
expect(3).assertEqual(ret)
console.log(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
})
await deletePromise
}
done()
console.log(TAG + "************* testRdbStoreDelete0001 end *************");
})
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0020
* @tc.desc rdb delete test
*/
it('testRdbStoreDelete0002', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 38,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
//删除
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
predicates.equalTo("name", "zhangsan")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
await expect(1).assertEqual(ret)
await console.log(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
})
await deletePromise
}
done()
console.log(TAG + "************* testRdbStoreDelete0002 end *************");
})
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0030
* @tc.desc rdb delete test
*/
it('testRdbStoreDelete0003', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0003 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
//删除前查询
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
predicates.equalTo("age", 28)
let resultSet = await rdbStore.query(predicates)
expect(1).assertEqual(resultSet.rowCount)
}
//删除
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
predicates.equalTo("age", 28)
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
})
await deletePromise
}
//删除后查询
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
predicates.equalTo("age", 28)
let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount)
}
done()
console.log(TAG + "************* testRdbStoreDelete0003 end *************");
})
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0040
* @tc.desc rdb delete test
*/
it('testRdbStoreDelete0004', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0004 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 38,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
//删除
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
predicates.equalTo("aaa id", 1)
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
console.log(TAG + "delete done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + "delete with wrong conditions")
})
}
done()
console.log(TAG + "************* testRdbStoreDelete0004 end *************");
})
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0050
* @tc.desc rdb delete test
*/
it('testRdbStoreDelete0005', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0005 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 38,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
//删除
{
let predicates = await new ohos_data_rdb.RdbPredicates("test")
predicates.equalTo("name", "lisi")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
expect(2).assertEqual(ret)
console.log(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
})
await deletePromise
}
done()
console.log(TAG + "************* testRdbStoreDelete0005 end *************");
})
/**
* @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0060
* @tc.desc rdb delete test
*/
it('testRdbStoreDelete0006', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0006 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 28,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 38,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
//删除
{
let predicates = await new ohos_data_rdb.RdbPredicates("")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
console.log(TAG + "delete done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + "delete with null")
})
}
done()
console.log(TAG + "************* testRdbStoreDelete0006 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb';
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)";
const STORE_CONFIG = {
name: "InsertTest.db",
}
var rdbStore = undefined;
describe('rdbStoreInsertTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
await rdbStore.executeSql("DELETE FROM test");
})
afterEach(async function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await ohos_data_rdb.deleteRdbStore("InsertTest.db");
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name rdb insert test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0010
* @tc.desc rdb insert test
*/
it('testRdbStoreInsert0001', 0, async function (done) {
console.log(TAG + "************* testRdbStoreInsert0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
{
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 100.5,
"blobType": u8,
}
await rdbStore.insert("test", valueBucket)
}
let predicates = new ohos_data_rdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
let resultSet = await rdbStore.query(predicates)
try {
console.log(TAG + "resultSet query done");
expect(true).assertEqual(resultSet.goToFirstRow())
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
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"))
console.log(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(1).assertEqual(id);
expect("zhangsan").assertEqual(name)
expect(18).assertEqual(age)
expect(100.5).assertEqual(salary)
expect(1).assertEqual(blobType[0])
expect(2).assertEqual(blobType[1])
expect(3).assertEqual(blobType[2])
expect(false).assertEqual(resultSet.goToNextRow())
} catch (e) {
console.log("insert1 error " + e);
}
resultSet = null
done()
console.log(TAG + "************* testRdbStoreInsert0001 end *************");
})
/**
* @tc.name rdb insert test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0020
* @tc.desc rdb insert test
*/
it('testRdbStoreInsert0002', 0, async function (done) {
console.log(TAG + "************* testRdbStoreInsert0002 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("wrong", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + "insert first done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + "insert with wrong table")
})
}
done()
console.log(TAG + "************* testRdbStoreInsert0002 end *************");
})
/**
* @tc.name rdb insert test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0030
* @tc.desc rdb insert test
*/
it('testRdbStoreInsert0003', 0, async function (done) {
console.log(TAG + "************* testRdbStoreInsert0003 start *************");
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert(null, valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.log(TAG + "insert first done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.log(TAG + "insert with null table")
})
}
done()
console.log(TAG + "************* testRdbStoreInsert0003 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb';
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)";
const STORE_CONFIG = {
name: "rdbstore.db",
}
describe('rdbStoreTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(function () {
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name rdb store getRdbStore test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0010
* @tc.desc rdb store getRdbStore test
*/
it('testRdbStore0001', 0, async function (done) {
console.log(TAG + "************* testRdbStore0001 start *************");
let storePromise = ohos_data_rdb.getRdbStore(STORE_CONFIG, 1);
storePromise.then(async (store) => {
try {
await console.log(TAG + "getRdbStore done: " + store);
} catch (e) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await ohos_data_rdb.deleteRdbStore("rdbstore.db");
done();
console.log(TAG + "************* testRdbStore0001 end *************");
})
/**
* @tc.name rdb store getRdbStore and create table
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0020
* @tc.desc rdb store getRdbStore and create table
*/
it('testRdbStore0002', 0, async function (done) {
console.log(TAG + "************* testRdbStore0002 start *************");
let storePromise = ohos_data_rdb.getRdbStore(STORE_CONFIG, 2);
storePromise.then(async (store) => {
try {
await console.log(TAG + "getRdbStore done: " + store);
await store.executeSql(CREATE_TABLE_TEST);
} catch (e) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await ohos_data_rdb.deleteRdbStore("rdbstore.db");
done();
console.log(TAG + "************* testRdbStore0002 end *************");
})
/**
* @tc.name rdb storegetRdbStore with wrong path
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0030
* @tc.desc rdb store getRdbStore with wrong path
*/
it('testRdbStore0003', 0, async function (done) {
console.log(TAG + "************* testRdbStore0003 start *************");
let storeConfig = {
name: "/wrong/rdbstore.db",
}
let storePromise = ohos_data_rdb.getRdbStore(storeConfig, 4);
storePromise.then(async (ret) => {
await console.log(TAG + "getRdbStore done" + ret);
expect(null).assertFail();
}).catch((err) => {
console.log(TAG + "getRdbStore with wrong path");
})
storePromise = null
done();
console.log(TAG + "************* testRdbStore0003 end *************");
})
/**
* @tc.name rdb store deleteRdbStore
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0040
* @tc.desc rdb store deleteRdbStore
*/
it('testRdbStore0004', 0, async function (done) {
console.log(TAG + "************* testRdbStore0004 start *************");
let storePromise = ohos_data_rdb.getRdbStore(STORE_CONFIG, 6);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (e) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await ohos_data_rdb.deleteRdbStore("rdbstore.db");
done();
console.log(TAG + "************* testRdbStore0004 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
/*
* Copyright (C) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb';
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 STORE_CONFIG = {
name: "ExcuteSqlTest.db",
}
var rdbStore = undefined;
describe('rdbStoreInsertTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
beforeEach(async function () {
await rdbStore.executeSql("DELETE FROM test");
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await ohos_data_rdb.deleteRdbStore("ExcuteSqlTest.db");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_ExcuteSql_0010
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0001', 0, async function (done) {
console.log(TAG + "************* ExcuteSqlTest0001 start *************");
var u8 = new Uint8Array([1, 2, 3])
//插入
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
await console.log(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(2).assertEqual(ret);
await console.log(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(3).assertEqual(ret);
await console.log(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
//sql删除
{
let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE age = ? OR age = ?", ["18", "20"])
executeSqlPromise.then(async (resultSet) => {
await console.log(TAG + "executeSql done: " + resultSet);
}).catch((err) => {
expect(null).assertFail();
})
await executeSqlPromise
}
{
let querySqlPromise = rdbStore.querySql("SELECT * FROM test")
querySqlPromise.then(async (resultSet) => {
await expect(0).assertEqual(resultSet.rowCount)
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
}
done();
console.log(TAG + "************* ExcuteSqlTest0001 end *************");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_ExcuteSql_0020
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0002', 0, async function (done) {
console.log(TAG + "************* ExcuteSqlTest0002 start *************");
var u8 = new Uint8Array([2, 3, 4])
//插入
{
const valueBucket = {
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(4).assertEqual(ret);
await console.log(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(5).assertEqual(ret);
await console.log(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(6).assertEqual(ret);
await console.log(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE name = 'lisi'")
executeSqlPromise.then(async () => {
await console.log(TAG + "executeSql done");
}).catch((err) => {
expect(null).assertFail();
})
await executeSqlPromise
}
{
let querySqlPromise = rdbStore.querySql("SELECT * FROM test")
querySqlPromise.then(async (resultSet) => {
await expect(1).assertEqual(resultSet.rowCount)
}).catch((err) => {
expect(null).assertFail();
})
await querySqlPromise
}
done();
console.log(TAG + "************* ExcuteSqlTest0002 end *************");
})
/**
* @tc.name resultSet ExcuteSql normal test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_ExcuteSql_0030
* @tc.desc resultSet ExcuteSql normal test
*/
it('ExcuteSqlTest0003', 0, async function (done) {
console.log(TAG + "************* ExcuteSqlTest0003 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(7).assertEqual(ret);
await console.log(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(8).assertEqual(ret);
await console.log(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(9).assertEqual(ret);
await console.log(TAG + "insert done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
{
let QuerySqlPromise = rdbStore.executeSql("DROP TABLE IF EXISTS test")
QuerySqlPromise.then(async (resultSet) => {
await console.log(TAG + "executeSql done: " + resultSet);
}).catch((err) => {
expect(null).assertFail();
})
await QuerySqlPromise
}
done();
console.log(TAG + "************* ExcuteSqlTest0003 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册