提交 68ecafa9 编写于 作者: Y yanglifeng

<yanglifeng5@huawei.com>

Signed-off-by: Nyanglifeng <yanglifeng5@huawei.com>
上级 047e3194
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
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 TEXT 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: "Delete.db", name: 'Delete.db',
} }
var rdbStore = undefined; let rdbStore = undefined;
describe('rdbStoreDeleteTest', function () { describe('rdbStoreDeleteTest', function () {
beforeAll(function () { beforeAll(function () {
...@@ -36,65 +36,65 @@ describe('rdbStoreDeleteTest', function () { ...@@ -36,65 +36,65 @@ describe('rdbStoreDeleteTest', function () {
afterEach(async function () { afterEach(async function () {
console.info(TAG + 'afterEach') console.info(TAG + 'afterEach')
await rdbStore.executeSql("DELETE FROM test"); await rdbStore.executeSql('DELETE FROM test');
rdbStore = null rdbStore = null
await dataRdb.deleteRdbStore("Delete.db"); await dataRdb.deleteRdbStore('Delete.db');
}) })
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
}) })
console.log(TAG + "*************Unit Test Begin*************"); console.log(TAG + '*************Unit Test Begin*************');
/** /**
* @tc.name rdb delete test * @tc.name rdb delete test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0010 * @tc.number SUB_DDM_AppDataFWK_JSRDB_Delete_0010
* @tc.desc rdb delete test * @tc.desc rdb delete test
*/ */
it('testRdbStoreDelete0001', 0, async function (done) { it('testRdbStoreDelete0001', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0001 start *************"); console.log(TAG + '************* testRdbStoreDelete0001 start *************');
var u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3])
{ {
const valueBucket = { const valueBucket = {
"name": "zhangsan", 'name': 'zhangsan',
"age": 18, 'age': 18,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 28, 'age': 28,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 38, 'age': 38,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
//删除 //删除
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
let deletePromise = rdbStore.delete(predicates) let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => { deletePromise.then(async (ret) => {
expect(3).assertEqual(ret) expect(3).assertEqual(ret)
console.log(TAG + "Delete done: " + ret) console.log(TAG + 'Delete done: ' + ret)
}).catch((err) => { }).catch((err) => {
expect(null).assertFail() expect(null).assertFail()
}) })
await deletePromise await deletePromise
} }
done() done()
console.log(TAG + "************* testRdbStoreDelete0001 end *************"); console.log(TAG + '************* testRdbStoreDelete0001 end *************');
}) })
/** /**
...@@ -103,50 +103,50 @@ describe('rdbStoreDeleteTest', function () { ...@@ -103,50 +103,50 @@ describe('rdbStoreDeleteTest', function () {
* @tc.desc rdb delete test * @tc.desc rdb delete test
*/ */
it('testRdbStoreDelete0002', 0, async function (done) { it('testRdbStoreDelete0002', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0002 start *************"); console.log(TAG + '************* testRdbStoreDelete0002 start *************');
var u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3])
{ {
const valueBucket = { const valueBucket = {
"name": "zhangsan", 'name': 'zhangsan',
"age": 18, 'age': 18,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 28, 'age': 28,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 38, 'age': 38,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
//删除 //删除
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
predicates.equalTo("name", "zhangsan") predicates.equalTo('name', 'zhangsan')
let deletePromise = rdbStore.delete(predicates) let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => { deletePromise.then(async (ret) => {
await expect(1).assertEqual(ret) await expect(1).assertEqual(ret)
await console.log(TAG + "Delete done: " + ret) await console.log(TAG + 'Delete done: ' + ret)
}).catch((err) => { }).catch((err) => {
expect(null).assertFail() expect(null).assertFail()
}) })
await deletePromise await deletePromise
} }
done() done()
console.log(TAG + "************* testRdbStoreDelete0002 end *************"); console.log(TAG + '************* testRdbStoreDelete0002 end *************');
}) })
/** /**
...@@ -155,41 +155,41 @@ describe('rdbStoreDeleteTest', function () { ...@@ -155,41 +155,41 @@ describe('rdbStoreDeleteTest', function () {
* @tc.desc rdb delete test * @tc.desc rdb delete test
*/ */
it('testRdbStoreDelete0003', 0, async function (done) { it('testRdbStoreDelete0003', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0003 start *************"); console.log(TAG + '************* testRdbStoreDelete0003 start *************');
var u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3])
{ {
const valueBucket = { const valueBucket = {
"name": "zhangsan", 'name': 'zhangsan',
"age": 18, 'age': 18,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 28, 'age': 28,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
//删除前查询 //删除前查询
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
predicates.equalTo("age", 28) predicates.equalTo('age', 28)
let resultSet = await rdbStore.query(predicates) let resultSet = await rdbStore.query(predicates)
expect(1).assertEqual(resultSet.rowCount) expect(1).assertEqual(resultSet.rowCount)
} }
//删除 //删除
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
predicates.equalTo("age", 28) predicates.equalTo('age', 28)
let deletePromise = rdbStore.delete(predicates) let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => { deletePromise.then(async (ret) => {
expect(1).assertEqual(ret) expect(1).assertEqual(ret)
console.log(TAG + "Delete done: " + ret) console.log(TAG + 'Delete done: ' + ret)
}).catch((err) => { }).catch((err) => {
expect(null).assertFail() expect(null).assertFail()
}) })
...@@ -197,13 +197,13 @@ describe('rdbStoreDeleteTest', function () { ...@@ -197,13 +197,13 @@ describe('rdbStoreDeleteTest', function () {
} }
//删除后查询 //删除后查询
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
predicates.equalTo("age", 28) predicates.equalTo('age', 28)
let resultSet = await rdbStore.query(predicates) let resultSet = await rdbStore.query(predicates)
expect(0).assertEqual(resultSet.rowCount) expect(0).assertEqual(resultSet.rowCount)
} }
done() done()
console.log(TAG + "************* testRdbStoreDelete0003 end *************"); console.log(TAG + '************* testRdbStoreDelete0003 end *************');
}) })
/** /**
...@@ -212,49 +212,49 @@ describe('rdbStoreDeleteTest', function () { ...@@ -212,49 +212,49 @@ describe('rdbStoreDeleteTest', function () {
* @tc.desc rdb delete test * @tc.desc rdb delete test
*/ */
it('testRdbStoreDelete0004', 0, async function (done) { it('testRdbStoreDelete0004', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0004 start *************"); console.log(TAG + '************* testRdbStoreDelete0004 start *************');
var u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3])
{ {
const valueBucket = { const valueBucket = {
"name": "zhangsan", 'name': 'zhangsan',
"age": 18, 'age': 18,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 28, 'age': 28,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 38, 'age': 38,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
//删除 //删除
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
predicates.equalTo("aaa id", 1) predicates.equalTo('aaa id', 1)
let deletePromise = rdbStore.delete(predicates) let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => { deletePromise.then(async (ret) => {
console.log(TAG + "delete done: " + ret) console.log(TAG + 'delete done: ' + ret)
expect(null).assertFail() expect(null).assertFail()
}).catch((err) => { }).catch((err) => {
console.log(TAG + "delete with wrong conditions") console.log(TAG + 'delete with wrong conditions')
}) })
} }
done() done()
console.log(TAG + "************* testRdbStoreDelete0004 end *************"); console.log(TAG + '************* testRdbStoreDelete0004 end *************');
}) })
/** /**
...@@ -263,50 +263,50 @@ describe('rdbStoreDeleteTest', function () { ...@@ -263,50 +263,50 @@ describe('rdbStoreDeleteTest', function () {
* @tc.desc rdb delete test * @tc.desc rdb delete test
*/ */
it('testRdbStoreDelete0005', 0, async function (done) { it('testRdbStoreDelete0005', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0005 start *************"); console.log(TAG + '************* testRdbStoreDelete0005 start *************');
var u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3])
{ {
const valueBucket = { const valueBucket = {
"name": "zhangsan", 'name': 'zhangsan',
"age": 18, 'age': 18,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 28, 'age': 28,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 38, 'age': 38,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
//删除 //删除
{ {
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates('test')
predicates.equalTo("name", "lisi") predicates.equalTo('name', 'lisi')
let deletePromise = rdbStore.delete(predicates) let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => { deletePromise.then(async (ret) => {
expect(2).assertEqual(ret) expect(2).assertEqual(ret)
console.log(TAG + "Delete done: " + ret) console.log(TAG + 'Delete done: ' + ret)
}).catch((err) => { }).catch((err) => {
expect(null).assertFail() expect(null).assertFail()
}) })
await deletePromise await deletePromise
} }
done() done()
console.log(TAG + "************* testRdbStoreDelete0005 end *************"); console.log(TAG + '************* testRdbStoreDelete0005 end *************');
}) })
/** /**
...@@ -315,49 +315,49 @@ describe('rdbStoreDeleteTest', function () { ...@@ -315,49 +315,49 @@ describe('rdbStoreDeleteTest', function () {
* @tc.desc rdb delete test * @tc.desc rdb delete test
*/ */
it('testRdbStoreDelete0006', 0, async function (done) { it('testRdbStoreDelete0006', 0, async function (done) {
console.log(TAG + "************* testRdbStoreDelete0006 start *************"); console.log(TAG + '************* testRdbStoreDelete0006 start *************');
var u8 = new Uint8Array([1, 2, 3]) let u8 = new Uint8Array([1, 2, 3])
{ {
const valueBucket = { const valueBucket = {
"name": "zhangsan", 'name': 'zhangsan',
"age": 18, 'age': 18,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 28, 'age': 28,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
{ {
const valueBucket = { const valueBucket = {
"name": "lisi", 'name': 'lisi',
"age": 38, 'age': 38,
"salary": 100.5, 'salary': 100.5,
"blobType": u8, 'blobType': u8,
} }
await rdbStore.insert("test", valueBucket) await rdbStore.insert('test', valueBucket)
} }
//删除 //删除
{ {
let predicates = await new dataRdb.RdbPredicates("") let predicates = await new dataRdb.RdbPredicates('')
let deletePromise = rdbStore.delete(predicates) let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => { deletePromise.then(async (ret) => {
console.log(TAG + "delete done: " + ret) console.log(TAG + 'delete done: ' + ret)
expect(null).assertFail() expect(null).assertFail()
}).catch((err) => { }).catch((err) => {
console.log(TAG + "delete with null") console.log(TAG + 'delete with null')
}) })
} }
done() done()
console.log(TAG + "************* testRdbStoreDelete0006 end *************"); console.log(TAG + '************* testRdbStoreDelete0006 end *************');
}) })
console.log(TAG + "*************Unit Test 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.
先完成此消息的编辑!
想要评论请 注册