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

!6977 【Distributeddatamgr】【master】分布式对象save以及revokeSave用例优化修改

Merge pull request !6977 from wangxiaomeng/master
/*
* Copyright (C) 2021-2022 Huawei Device Co., Ltd.
* Copyright (C) 2022 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
......@@ -336,7 +336,6 @@ export default function objectStoreTest() {
objectTest.name = "jack1";
objectTest.age = 19;
objectTest.isVis = true;
expect(objectTest.name == "jack1").assertEqual(true);
expect(objectTest.age == 19).assertEqual(true);
console.info(TAG + " set data success!");
} else {
......@@ -717,74 +716,135 @@ export default function objectStoreTest() {
console.log(TAG + "************* testPerformance001 end *************");
complexObject.setSessionId("");
})
/**
* @tc.name: testSave001
* @tc.desc: Save object <Promise>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_001
*/
it('testSave001', 0, async function (done) {
console.info(TAG + "************* testSave001 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession01");
let result = await gObject.save("local");
done();
expect(result.sessionId == "tmpsession01").assertEqual(true);
expect(result.version == gObject.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
gObject.setSessionId("");
gObject.name = undefined;
gObject.age = undefined;
gObject.isVis = undefined;
gObject.setSessionId("tmpsession01");
expect(gObject.name == "Amy").assertEqual(true);
expect(gObject.age == 18).assertEqual(true);
expect(gObject.isVis == false).assertEqual(true);
done();
console.info(TAG + "************* testSave001 end *************");
})
/**
* @tc.name: testSave001
* @tc.desc: Save object <Promise>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_001
*/
it('testSave001', 0, async function (done) {
console.info(TAG + "************* testSave001 start *************");
/**
* @tc.name: testSave002
* @tc.desc: Save object
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_002
*/
it('testSave002', 0, function (done) {
console.info(TAG + "************* testSave002 start *************");
var objectTest = distributedObject.createDistributedObject({ name: "Eva", age: 20, isVis: false });
objectTest.setSessionId("tmpsession02");
done();
console.info(TAG + "************* testSave002 end *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession01");
let result = await gObject.save("local");
done();
expect(result.sessionId == "tmpsession01").assertEqual(true);
expect(result.version == gObject.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
gObject.setSessionId("");
gObject.name = undefined;
gObject.age = undefined;
gObject.isVis = undefined;
gObject.setSessionId("tmpsession01");
expect(gObject.name == "Amy").assertEqual(true);
expect(gObject.age == 18).assertEqual(true);
expect(gObject.isVis == false).assertEqual(true);
gObject.setSessionId("");
done();
console.info(TAG + "************* testSave001 end *************");
})
/**
* @tc.name: testSave002
* @tc.desc: Save object
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_002
*/
it('testSave002', 0, function (done) {
console.info(TAG + "************* testSave002 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
if (gObject != undefined && gObject != null) {
gObject.setSessionId("tmpsession02");
console.info(TAG + "testSave002 joinSession tmpsession02 success:"+ gObject.__sessionId);
}
gObject.save("local", (result) => {
console.info("save callback");
expect(result.sessionId == "tmpsession02").assertEqual(true);
expect(result.version == gObject.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
console.info("save end");
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);
})
/**
* @tc.name: testRevokeSave001
* @tc.desc: Revoke save object <Promise>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_001
*/
it('testRevokeSave001', 0, async function (done) {
console.info(TAG + "************* testRevokeSave001 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession03");
done();
console.info(TAG + "************* testRevokeSave001 end *************");
})
gObject.setSessionId("");
});
done();
console.info(TAG + "************* testSave002 end *************");
})
/**
* @tc.name: testRevokeSave001
* @tc.desc: Revoke save object <Promise>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_001
*/
it('testRevokeSave001', 0, async function (done) {
console.info(TAG + "************* testRevokeSave001 start *************");
var RObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
RObject.setSessionId("tmpsession03");
expect("tmpsession03" == RObject.__sessionId).assertEqual(true);
let result = await RObject.save("local");
done();
expect(result.sessionId == "tmpsession03").assertEqual(true);
expect(result.version == RObject.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
result = await RObject.revokeSave();
RObject.setSessionId("");
RObject.name = undefined;
RObject.age = undefined;
RObject.isVis = undefined;
RObject.setSessionId("tmpsession03");
expect(RObject.name == "Amy").assertEqual(false);
expect(RObject.age == 18).assertEqual(false);
expect(RObject.isVis == false).assertEqual(false);
RObject.setSessionId("");
done();
console.info(TAG + "************* testRevokeSave001 end *************");
})
/**
* @tc.name: testRevokeSave002
* @tc.desc: Revoke save object <Callback>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_002
*/
it('testRevokeSave002', 0, async function (done) {
console.info(TAG + "************* testRevokeSave002 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession04");
done();
console.info(TAG + "************* testRevokeSave002 end *************");
})
/**
* @tc.name: testRevokeSave002
* @tc.desc: Revoke save object <Callback>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_002
*/
it('testRevokeSave002', 0, async function (done) {
console.info(TAG + "************* testRevokeSave002 start *************");
var RObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
RObject.setSessionId("tmpsession04");
expect("tmpsession04" == RObject.__sessionId).assertEqual(true);
let result = await RObject.save("local");
done();
RObject.revokeSave((response)=>{
console.info(TAG +"revokeSave callback");
console.info("revokeSave sessionId: " + response.sessionId);
console.info(TAG +"revokeSave end");
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();
console.info(TAG + "************* testRevokeSave002 end *************");
})
console.info(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
......@@ -12,12 +12,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from 'deccjsunit/index';
import {afterAll, afterEach, beforeAll, beforeEach, describe, expect, it} from '@ohos/hypium';
import distributedObject from '@ohos.data.distributedDataObject';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle';
var context;
let context;
const TAG = "OBJECTSTORE_TEST";
function changeCallback(sessionId, changeData) {
console.info("changeCallback start");
......@@ -83,7 +83,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001
* @tc.type: FUNC
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001 start *************");
var g_object;
try {
......@@ -112,6 +112,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -120,7 +121,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -139,6 +140,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -147,7 +149,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -163,6 +165,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -171,7 +174,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -185,6 +188,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -193,7 +197,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -218,6 +222,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
......@@ -227,7 +232,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_On_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_On_001', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_On_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_001 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -263,6 +268,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -271,7 +277,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_On_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_On_002', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_On_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_002 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -298,6 +304,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -306,7 +313,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_On_003
*/
it('SUB_DDM_AppDataFWK_Object_Api9_On_003', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_On_003', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_003 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -334,6 +341,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -342,7 +350,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Off_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Off_001', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_Off_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_001 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -381,6 +389,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -389,7 +398,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Off_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Off_002', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_Off_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_002 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -413,6 +422,7 @@ describe('objectStoreTest', function () {
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
done();
})
/**
......@@ -421,7 +431,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001 start *************");
console.log(TAG + "start watch status");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
......@@ -440,6 +450,7 @@ describe('objectStoreTest', function () {
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
done();
})
/**
......@@ -448,7 +459,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002', 0, function () {
it('SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002 start *************");
console.log(TAG + "start watch status");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
......@@ -465,6 +476,7 @@ describe('objectStoreTest', function () {
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
done();
})
/**
......@@ -473,7 +485,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Save_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Save_001', 0, async function () {
it('SUB_DDM_AppDataFWK_Object_Api9_Save_001', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_001 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -511,6 +523,7 @@ describe('objectStoreTest', function () {
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
done();
})
/**
......@@ -519,7 +532,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Save_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Save_002', 0, async function () {
it('SUB_DDM_AppDataFWK_Object_Api9_Save_002', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_002 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -559,6 +572,7 @@ describe('objectStoreTest', function () {
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
done();
})
/**
......@@ -567,7 +581,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001', 0, async function () {
it('SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -605,6 +619,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
/**
......@@ -613,7 +628,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002', 0, async function () {
it('SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
......@@ -642,6 +657,7 @@ describe('objectStoreTest', function () {
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
done();
})
console.log(TAG + "*************Unit Test End*************");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册