未验证 提交 4089a949 编写于 作者: O openharmony_ci 提交者: Gitee

!8103 【Distributeddatamgr】【Master】用例优化add 801

Merge pull request !8103 from yanglifeng/master
...@@ -18,7 +18,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl' ...@@ -18,7 +18,7 @@ import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle' import bundle from '@ohos.bundle'
var baseLine = 3000; //3 second var baseLine = 3000; //3 second
var gObject; const CATCH_ERR = -1;
const TAG = "OBJECTSTORE_TEST"; const TAG = "OBJECTSTORE_TEST";
function changeCallback(sessionId, changeData) { function changeCallback(sessionId, changeData) {
...@@ -699,18 +699,18 @@ export default function objectStoreTest() { ...@@ -699,18 +699,18 @@ export default function objectStoreTest() {
expect(complexObject.list[0].mother == "jack2 mom2").assertEqual(true); expect(complexObject.list[0].mother == "jack2 mom2").assertEqual(true);
expect(complexObject.list[1].father == "jack2 Dad2").assertEqual(true); expect(complexObject.list[1].father == "jack2 Dad2").assertEqual(true);
console.log(TAG + "start unWatch change"); console.info(TAG + "start unWatch change");
complexObject.off("change"); complexObject.off("change");
console.log(TAG + "end unWatch success"); console.info(TAG + "end unWatch success");
} }
var endTime = new Date().getTime(); var endTime = new Date().getTime();
var totalTime = endTime - startTime; var totalTime = endTime - startTime;
console.log("testPerformance001 totalTime = " + totalTime); console.info("testPerformance001 totalTime = " + totalTime);
console.log("testPerformance001 baseLine = " + baseLine); console.info("testPerformance001 baseLine = " + baseLine);
expect(totalTime < baseLine).assertEqual(true); expect(totalTime < baseLine).assertEqual(true);
complexObject.setSessionId(""); complexObject.setSessionId("");
done(); done();
console.log(TAG + "************* testPerformance001 end *************"); console.info(TAG + "************* testPerformance001 end *************");
}) })
/** /**
...@@ -720,26 +720,32 @@ export default function objectStoreTest() { ...@@ -720,26 +720,32 @@ export default function objectStoreTest() {
*/ */
it('testSave001', 0, async function (done) { it('testSave001', 0, async function (done) {
console.info(TAG + "************* testSave001 start *************"); console.info(TAG + "************* testSave001 start *************");
var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); expect(g_object == undefined).assertEqual(false);
gObject.setSessionId("tmpsession01");
let result = await gObject.save("local"); g_object.setSessionId("testSession001");
done(); expect("testSession001" == g_object.__sessionId).assertEqual(true);
expect(result.sessionId == "tmpsession01").assertEqual(true);
expect(result.version == gObject.__version).assertEqual(true); g_object.save("local").then((ret) => {
expect(result.deviceId == "local").assertEqual(true); expect(ret.sessionId == "testSession001").assertEqual(true);
expect(ret.version == g_object.__version).assertEqual(true);
gObject.setSessionId(""); expect(ret.deviceId == "local").assertEqual(true);
gObject.name = undefined; done();
gObject.age = undefined;
gObject.isVis = undefined; g_object.setSessionId("");
g_object.name = undefined;
gObject.setSessionId("tmpsession01"); g_object.age = undefined;
expect(gObject.name == "Amy").assertEqual(true); g_object.isVis = undefined;
expect(gObject.age == 18).assertEqual(true); g_object.setSessionId("testSession001");
expect(gObject.isVis == false).assertEqual(true);
gObject.setSessionId(""); expect(g_object.name == "Amy").assertEqual(true);
done(); expect(g_object.age == 18).assertEqual(true);
expect(g_object.isVis == false).assertEqual(true);
}).catch((err) => {
console.info('testSave001 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
done();
});
console.info(TAG + "************* testSave001 end *************"); console.info(TAG + "************* testSave001 end *************");
}) })
...@@ -748,67 +754,81 @@ export default function objectStoreTest() { ...@@ -748,67 +754,81 @@ export default function objectStoreTest() {
* @tc.desc: Save object * @tc.desc: Save object
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_002 * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_002
*/ */
it('testSave002', 0, function (done) { it('testSave002', 0, async function (done) {
console.info(TAG + "************* testSave002 start *************"); console.info(TAG + "************* testSave002 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
if (gObject != undefined && gObject != null) { expect(g_object == undefined).assertEqual(false);
gObject.setSessionId("tmpsession02");
console.info(TAG + "testSave002 joinSession tmpsession02 success:"+ gObject.__sessionId); g_object.setSessionId("testSession002");
} expect("testSession002" == g_object.__sessionId).assertEqual(true);
gObject.save("local", (result) => {
console.info("save callback"); g_object.save("local", (err, result) => {
expect(result.sessionId == "tmpsession02").assertEqual(true); if (err) {
expect(result.version == gObject.__version).assertEqual(true); console.info('testSave002 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
done();
return;
}
expect(result.sessionId == "testSession002").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true); expect(result.deviceId == "local").assertEqual(true);
console.info("save end"); done();
console.info("save success");
gObject.setSessionId("");
gObject.name = undefined;
gObject.age = undefined;
gObject.isVis = undefined;
console.info("save setSessionId");
gObject.setSessionId("tmpsession02");
expect(gObject.name == "Amy").assertEqual(true);
expect(gObject.age == 18).assertEqual(true);
expect(gObject.isVis == false).assertEqual(true);
gObject.setSessionId(""); g_object.setSessionId("");
g_object.name = undefined;
}); g_object.age = undefined;
done(); g_object.isVis = undefined;
g_object.setSessionId("testSession002");
expect(g_object.name == "Amy").assertEqual(true);
expect(g_object.age == 18).assertEqual(true);
expect(g_object.isVis == false).assertEqual(true);
})
console.info(TAG + "************* testSave002 end *************"); console.info(TAG + "************* testSave002 end *************");
}) })
/** /**
* @tc.name: testRevokeSave001 * @tc.name: testRevokeSave001
* @tc.desc: Revoke save object <Promise> * @tc.desc: Revoke save object <Promise>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_001 * @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_001
*/ */
it('testRevokeSave001', 0, async function (done) { it('testRevokeSave001', 0, async function (done) {
console.info(TAG + "************* testRevokeSave001 start *************"); console.info(TAG + "************* testRevokeSave001 start *************");
var RObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
RObject.setSessionId("tmpsession03"); expect(g_object == undefined).assertEqual(false);
expect("tmpsession03" == RObject.__sessionId).assertEqual(true);
let result = await RObject.save("local"); g_object.setSessionId("testSession003");
done(); expect("testSession003" == g_object.__sessionId).assertEqual(true);
expect(result.sessionId == "tmpsession03").assertEqual(true);
expect(result.version == RObject.__version).assertEqual(true); g_object.save("local", (err, result) => {
expect(result.deviceId == "local").assertEqual(true); if (err) {
console.info('testRevokeSave001 err ' + `, error code is ${err.code}, message is ${err.message}`);
result = await RObject.revokeSave(); expect("801").assertEqual(err.code.toString());
done();
RObject.setSessionId(""); return;
RObject.name = undefined; }
RObject.age = undefined; expect(result.sessionId == "testSession003").assertEqual(true);
RObject.isVis = undefined; expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
RObject.setSessionId("tmpsession03"); g_object.revokeSave((err, result) => {
expect(RObject.name == "Amy").assertEqual(false); if (err) {
expect(RObject.age == 18).assertEqual(false); expect("801").assertEqual(err.code.toString());
expect(RObject.isVis == false).assertEqual(false); done();
RObject.setSessionId(""); return;
done(); }
expect("testSession003" == result.sessionId).assertEqual(true);
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("testSession003");
expect(g_object.name == undefined).assertEqual(true);
expect(g_object.age == undefined).assertEqual(true);
expect(g_object.isVis == undefined).assertEqual(true);
done();
})
});
console.info(TAG + "************* testRevokeSave001 end *************"); console.info(TAG + "************* testRevokeSave001 end *************");
}) })
...@@ -817,31 +837,49 @@ export default function objectStoreTest() { ...@@ -817,31 +837,49 @@ export default function objectStoreTest() {
* @tc.desc: Revoke save object <Callback> * @tc.desc: Revoke save object <Callback>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_002 * @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_002
*/ */
it('testRevokeSave002', 0, async function (done) { it('testRevokeSave002', 0, async function () {
console.info(TAG + "************* testRevokeSave002 start *************"); console.info(TAG + "************* testRevokeSave002 start *************");
var RObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
RObject.setSessionId("tmpsession04"); expect(g_object == undefined).assertEqual(false);
expect("tmpsession04" == RObject.__sessionId).assertEqual(true);
let result = await RObject.save("local"); g_object.setSessionId("testSession004");
done(); expect("testSession004" == g_object.__sessionId).assertEqual(true);
RObject.revokeSave((response)=>{
console.info(TAG +"revokeSave callback"); let result = await g_object.save("local").catch((err)=> {
console.info("revokeSave sessionId: " + response.sessionId); expect("801").assertEqual(err.code.toString());
console.info(TAG +"revokeSave end"); return CATCH_ERR;
RObject.setSessionId("");
RObject.name = undefined;
RObject.age = undefined;
RObject.isVis = undefined;
RObject.setSessionId("tmpsession04");
expect(RObject.name == "Amy").assertEqual(false);
expect(RObject.age == 18).assertEqual(false);
expect(RObject.isVis == false).assertEqual(false);
RObject.setSessionId("");
}); });
done(); if (result === CATCH_ERR) {
return;
}
expect(result.sessionId.toString() == "testSession004").assertEqual(true);
expect(result.version.toString() == g_object.__version.toString()).assertEqual(true);
expect(result.deviceId.toString() == "local").assertEqual(true);
result = await g_object.revokeSave().catch((err) => {
console.info('testRevokeSave002 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
return CATCH_ERR;
});
if (result === CATCH_ERR) {
return;
}
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("testSession004");
expect(g_object.name == undefined).assertEqual(true);
expect(g_object.age == undefined).assertEqual(true);
expect(g_object.isVis == undefined).assertEqual(true);
console.info(TAG + "************* testRevokeSave002 end *************"); console.info(TAG + "************* testRevokeSave002 end *************");
}) })
console.info(TAG + "*************Unit Test End*************"); console.info(TAG + "*************Unit Test End*************");
}) })
} }
\ No newline at end of file
...@@ -17,6 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from ' ...@@ -17,6 +17,7 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import data_Rdb from '@ohos.data.relationalStore'; import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility'; import ability_featureAbility from '@ohos.ability.featureAbility';
const ERRCODE = 801;
var context = ability_featureAbility.getContext(); var context = ability_featureAbility.getContext();
var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," + "id INTEGER PRIMARY KEY AUTOINCREMENT," +
...@@ -100,8 +101,8 @@ describe('relationalStoreDistributedTest', function () { ...@@ -100,8 +101,8 @@ describe('relationalStoreDistributedTest', function () {
console.info(TAG + "set none to be distributed table success"); console.info(TAG + "set none to be distributed table success");
expect(rdbStore).assertEqual(rdbStore) expect(rdbStore).assertEqual(rdbStore)
} catch (err) { } catch (err) {
console.info(TAG + "set none to be distributed table failed"); console.info(TAG + "setDistributed002 failed"+ `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail(); expect(err.code).assertEqual(ERRCODE);
} }
done() done()
console.info(TAG + "************* testRdbStoreDistributed002 end *************"); console.info(TAG + "************* testRdbStoreDistributed002 end *************");
...@@ -119,8 +120,8 @@ describe('relationalStoreDistributedTest', function () { ...@@ -119,8 +120,8 @@ describe('relationalStoreDistributedTest', function () {
console.info(TAG + "set employee to be distributed table success"); console.info(TAG + "set employee to be distributed table success");
expect(rdbStore).assertEqual(rdbStore) expect(rdbStore).assertEqual(rdbStore)
} catch (err) { } catch (err) {
console.info(TAG + "set employee to be distributed table failed"); console.info(TAG + "setDistributed003 failed"+ `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail(); expect(err.code).assertEqual(ERRCODE);
} }
done() done()
console.info(TAG + "************* testRdbStoreDistributed003 end *************"); console.info(TAG + "************* testRdbStoreDistributed003 end *************");
...@@ -138,8 +139,8 @@ describe('relationalStoreDistributedTest', function () { ...@@ -138,8 +139,8 @@ describe('relationalStoreDistributedTest', function () {
console.info(TAG + "set employee and product to be distributed table success"); console.info(TAG + "set employee and product to be distributed table success");
expect(rdbStore).assertEqual(rdbStore) expect(rdbStore).assertEqual(rdbStore)
} catch (err) { } catch (err) {
console.info(TAG + "set employee and product to be distributed table failed"); console.info(TAG + "setDistributed004 failed"+ `, error code is ${err.code}, message is ${err.message}`);
expect(null).assertFail(); expect(err.code).assertEqual(ERRCODE);
} }
done() done()
console.info(TAG + "************* testRdbStoreDistributed004 end *************"); console.info(TAG + "************* testRdbStoreDistributed004 end *************");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册