提交 d69fbac8 编写于 作者: Y yanglifeng1217

<modified>

Signed-off-by: Nyanglifeng1217 <yanglifeng5@huawei.com>
上级 77cbc38c
...@@ -23,245 +23,243 @@ const STORE_CONFIG = { ...@@ -23,245 +23,243 @@ const STORE_CONFIG = {
var rdbStore = undefined; var rdbStore = undefined;
export default function rdbStoreUpdateTest() { export default function rdbStoreUpdateTest() {
describe('rdbStoreUpdateTest', function () { describe('rdbStoreUpdateTest', function () {
beforeAll(function () { beforeAll(function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
}) })
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await dataRdb.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 dataRdb.deleteRdbStore("UpdataTest.db");
})
afterAll(async function () { beforeEach(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'beforeEach')
}) rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
/** afterEach(async function () {
* @tc.name resultSet Update test console.info(TAG + 'afterEach')
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0010 await rdbStore.executeSql("DELETE FROM test");
* @tc.desc resultSet Update test rdbStore = null
*/ await dataRdb.deleteRdbStore("UpdataTest.db");
it('testRdbStoreUpdate0001', 0, async function (done) { })
console.info(TAG + "************* testRdbStoreUpdate0001 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);
console.info(TAG + "update done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
await insertPromise
}
//更新
{
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 200.5,
"blobType": u8,
}
let predicates = await new dataRdb.RdbPredicates("test")
predicates.equalTo("id", "1")
let updatePromise = rdbStore.update(valueBucket, predicates)
await updatePromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret);
let resultSet = await rdbStore.query(predicates)
expect(true).assertEqual(resultSet.goToFirstRow()) afterAll(async function () {
const id = await resultSet.getLong(resultSet.getColumnIndex("id")) console.info(TAG + 'afterAll')
const name = await resultSet.getString(resultSet.getColumnIndex("name")) })
const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
expect(1).assertEqual(id); /**
expect("lisi").assertEqual(name); * @tc.name resultSet Update test
expect(20).assertEqual(age); * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0010
expect(200.5).assertEqual(salary); * @tc.desc resultSet Update test
expect(4).assertEqual(blobType[0]); */
expect(5).assertEqual(blobType[1]); it('testRdbStoreUpdate0001', 0, async function (done) {
expect(6).assertEqual(blobType[2]); console.info(TAG + "************* testRdbStoreUpdate0001 start *************");
console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
expect(false).assertEqual(resultSet.goToNextRow())
resultSet = null
}).catch((err) => {
console.info(TAG + "update error");
expect(null).assertFail();
})
//await updatePromise
}
done();
console.info(TAG + "************* testRdbStoreUpdate0001 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0020
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0002 start *************");
//更新
{
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3]) var u8 = new Uint8Array([1, 2, 3])
const valueBucket = { //插入
"name": "zhangsan",
"age": 18,
"salary": 100.5,
"blobType": u8,
}
try{
let predicates = new dataRdb.RdbPredicates("")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with null table name");
})
}catch(err){
errInfo = err
}
{ {
const emptyBucket = {}; const valueBucket = {
let predicates = await new dataRdb.RdbPredicates("test") "name": "zhangsan",
let updatePromise = rdbStore.update(emptyBucket, predicates) "age": 18,
updatePromise.then(async (ret) => { "salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret); console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => { }).catch((err) => {
console.info(TAG + "update with wrong valueBucket"); expect(null).assertFail();
}) })
await insertPromise
} }
//更新
{ {
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"name": "lisi",
"age": 20,
"salary": 200.5,
"blobType": u8,
}
let predicates = await new dataRdb.RdbPredicates("test") let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null") predicates.equalTo("id", "1")
let updatePromise = rdbStore.update(valueBucket, predicates) let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => { await updatePromise.then(async (ret) => {
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret); console.info(TAG + "update done: " + ret);
expect(null).assertFail(); let resultSet = await rdbStore.query(predicates)
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
}
expect(errInfo.code).assertEqual("401")
}
done();
console.info(TAG + "************* testRdbStoreUpdate0002 end *************");
})
/** expect(true).assertEqual(resultSet.goToFirstRow())
* @tc.name resultSet Update test const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0030 const name = await resultSet.getString(resultSet.getColumnIndex("name"))
* @tc.desc resultSet Update test const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
*/ const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
it('testRdbStoreUpdate0003', 0, async function (done) { const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
console.info(TAG + "************* testRdbStoreUpdate0003 start *************");
//更新 expect(1).assertEqual(id);
{ expect("lisi").assertEqual(name);
var u8 = new Uint8Array([1, 2, 3]) expect(20).assertEqual(age);
const valueBucket = { expect(200.5).assertEqual(salary);
"name": "zhangsan", expect(4).assertEqual(blobType[0]);
"age": 18, expect(5).assertEqual(blobType[1]);
"salary": 100.5, expect(6).assertEqual(blobType[2]);
"blobType": u8, console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType);
"wrongColumn": 100.5, expect(false).assertEqual(resultSet.goToNextRow())
} resultSet = null
{
let predicates = new dataRdb.RdbPredicates("wrongTable")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => { }).catch((err) => {
console.info(TAG + "update with wrong table name"); console.info(TAG + "update error");
})
//await updatePromise
}
{
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail(); expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong column name");
}) })
//await updatePromise //await updatePromise
} }
} done();
done(); console.info(TAG + "************* testRdbStoreUpdate0001 end *************");
console.info(TAG + "************* testRdbStoreUpdate0003 end *************"); })
})
/** /**
* @tc.name resultSet Update test * @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0040 * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0020
* @tc.desc resultSet Update test * @tc.desc resultSet Update test
*/ */
it('testRdbStoreUpdate0004', 0, async function (done) { it('testRdbStoreUpdate0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0004 start *************"); console.info(TAG + "************* testRdbStoreUpdate0002 start *************");
//更新 //更新
{ {
var u8 = new Uint8Array([1, 2, 3]) let errInfo = undefined;
const valueBucket = { var u8 = new Uint8Array([1, 2, 3])
"name": "zhangsan", const valueBucket = {
"age": 18, "name": "zhangsan",
"salary": 100.5, "age": 18,
"blobType": u8, "salary": 100.5,
"blobType": u8,
}
try{
let predicates = new dataRdb.RdbPredicates("")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with null table name");
})
}catch(err){
errInfo = err
}
{
const emptyBucket = {};
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(emptyBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong valueBucket");
})
}
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
}
expect(errInfo.code).assertEqual("401")
} }
done();
console.info(TAG + "************* testRdbStoreUpdate0002 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0030
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0003 start *************");
//更新
{ {
let predicates = await new dataRdb.RdbPredicates("test") var u8 = new Uint8Array([1, 2, 3])
await predicates.equalTo("aaa", "null") const valueBucket = {
let updatePromise = rdbStore.update(valueBucket, predicates) "name": "zhangsan",
updatePromise.then(async (ret) => { "age": 18,
console.info(TAG + "update done: " + ret); "salary": 100.5,
expect(null).assertFail(); "blobType": u8,
}).catch((err) => { "wrongColumn": 100.5,
console.info(TAG + "update with wrong condition"); }
}) {
//await updatePromise let predicates = new dataRdb.RdbPredicates("wrongTable")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong table name");
})
//await updatePromise
}
{
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong column name");
})
//await updatePromise
}
} }
done();
console.info(TAG + "************* testRdbStoreUpdate0003 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0040
* @tc.desc resultSet Update test
*/
it('testRdbStoreUpdate0004', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0004 start *************");
//更新
{ {
const emptyBucket = {}; var u8 = new Uint8Array([1, 2, 3])
let predicates = await new dataRdb.RdbPredicates("test") const valueBucket = {
await predicates.equalTo("name", "zhangsan") "name": "zhangsan",
await predicates.equalTo("age", 18) "age": 18,
await predicates.equalTo("null", 100.5) "salary": 100.5,
let updatePromise = rdbStore.update(valueBucket, predicates) "blobType": u8,
updatePromise.then(async (ret) => { }
console.info(TAG + "update done: " + ret); {
expect(null).assertFail(); let predicates = await new dataRdb.RdbPredicates("test")
}).catch((err) => { await predicates.equalTo("aaa", "null")
console.info(TAG + "update with wrong condition"); await rdbStore.update(valueBucket, predicates).then(async (ret) => {
}) console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
expect(err !== null).assertTrue();
})
}
{
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("name", "zhangsan")
await predicates.equalTo("age", 18)
await predicates.equalTo("null", 100.5)
await rdbStore.update(valueBucket, predicates).then(async (ret) => {
console.info(TAG + "update done: " + ret);
expect(ret).assertEqual(0);
}).catch((err) => {
console.info(TAG + "update with wrong condition");
expect(null).assertFail();
})
}
} }
} done();
done(); console.info(TAG + "************* testRdbStoreUpdate0004 end *************");
console.info(TAG + "************* testRdbStoreUpdate0004 end *************"); })
console.info(TAG + "*************Unit Test End*************");
}) })
console.info(TAG + "*************Unit Test End*************");
})
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册