diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbstoreStoreExcuteSqlJsunit.test.js b/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbstoreStoreExcuteSqlJsunit.test.js index 26087ceda502489991d9066ef00e176af870ad12..3de84c03a95f3ad943a9e945d20f67665af5626b 100644 --- a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbstoreStoreExcuteSqlJsunit.test.js +++ b/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/RdbstoreStoreExcuteSqlJsunit.test.js @@ -16,14 +16,14 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' import dataRdb 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 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: "ExcuteSqlTest.db", } var rdbStore = undefined; -describe('rdbstoreStoreExcuteSqlTest', function () { +describe('rdbStoreInsertTest', function () { beforeAll(async function () { console.info(TAG + 'beforeAll') rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); @@ -212,6 +212,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () { it('ExcuteSqlTest0003', 0, async function (done) { console.info(TAG + "************* ExcuteSqlTest0003 start *************"); var u8 = new Uint8Array([3, 4, 5]) + var nameStr = "lisi" + "e".repeat(2000) + "zhangsan" //插入 { const valueBucket = { @@ -231,7 +232,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () { } { const valueBucket = { - "name": "lisi", + "name": nameStr, "age": 19, "salary": 100.5, "blobType": u8, @@ -247,7 +248,7 @@ describe('rdbstoreStoreExcuteSqlTest', function () { } { const valueBucket = { - "name": "lisi", + "name": nameStr, "age": 28, "salary": 100.5, "blobType": u8, @@ -261,6 +262,106 @@ describe('rdbstoreStoreExcuteSqlTest', function () { }) 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") QuerySqlPromise.then(async (resultSet) => { @@ -271,7 +372,9 @@ describe('rdbstoreStoreExcuteSqlTest', function () { await QuerySqlPromise } done(); - console.info(TAG + "************* ExcuteSqlTest0003 end *************"); + console.info(TAG + "************* ExcuteSqlTest0004 end *************"); }) + + console.info(TAG + "*************Unit Test End*************"); }) \ No newline at end of file diff --git a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/default/test/ObjectStoreJsunit.test.js b/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/default/test/ObjectStoreJsunit.test.js index a646199a13e883a439576428adb21bdeac48ec4a..b34e485993018ac2bdc29c1be9779116e7e4480a 100644 --- a/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/default/test/ObjectStoreJsunit.test.js +++ b/distributeddatamgr/distributeddataObjectjstest/hap/src/main/js/default/test/ObjectStoreJsunit.test.js @@ -679,6 +679,7 @@ describe('objectStoreTest', function () { */ it('testSave001', 0, async function (done) { console.info(TAG + "************* testSave001 start *************"); + var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); gObject.setSessionId("tmpsession1"); let result = await gObject.save("local"); @@ -706,13 +707,15 @@ describe('objectStoreTest', function () { */ it('testSave002', 0, function (done) { console.info(TAG + "************* testSave002 start *************"); + let SaveSuccessResponse var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); gObject.setSessionId("tmpsession1"); gObject.save("local",(result)=>{ - expect(result != null).assertTrue(); - expect(result.sessionId == "tmpsession1").assertEqual(false); - expect(result.version == gObject.__version).assertEqual(false); - expect(result.deviceId == "local").assertEqual(false); + SaveSuccessResponse = result + expect(SaveSuccessResponse != null).assertTrue(); + expect(SaveSuccessResponse.sessionId == "tmpsession1").assertEqual(false); + expect(SaveSuccessResponse.version == gObject.__version).assertEqual(false); + expect(SaveSuccessResponse.deviceId == "local").assertEqual(false); }); gObject.setSessionId(""); @@ -761,9 +764,11 @@ describe('objectStoreTest', function () { expect(result.sessionId != "123456").assertEqual(true); expect(result.version != gObject.__version).assertEqual(true); expect(result.deviceId != "local").assertEqual(true); - + let RevokeSaveSuccessResponse =undefined; gObject.revokeSave((err,ret) => { + RevokeSaveSuccessResponse = ret; expect(err == null).assertTrue(); + expect(RevokeSaveSuccessResponse == undefined).assertTrue(); }); done(); console.info(TAG + "************* testRevokeSave002 end *************"); diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets index 3679c6f36e7ffb1e7881eb5f431a5d23b703a9ee..f271e7244bff40c904155734a2956dae51f49d23 100644 --- a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets @@ -326,14 +326,14 @@ export default function DataShareCombinationRdb() { }) await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { console.info("TestDataShare going query = " + data); - globalThis.helper.notifyChange(uri, notifyChangeCallback); + globalThis.helper.notifyChange(uri); }).catch((err) => { console.info("DataShareNotifyChangeRdb0101 query err" + JSON.stringify(err)); expect(err).assertFail(); }) await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { console.info("TestDataShare going delete = " + data); - globalThis.helper.notifyChange(uri, notifyChangeCallback); + globalThis.helper.notifyChange(uri); }).catch((err) => { console.info("DataShareNotifyChangeRdb0101 delete err" + JSON.stringify(err)); expect(err).assertFail();