未验证 提交 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'
import bundle from '@ohos.bundle'
var baseLine = 3000; //3 second
var gObject;
const CATCH_ERR = -1;
const TAG = "OBJECTSTORE_TEST";
function changeCallback(sessionId, changeData) {
......@@ -699,18 +699,18 @@ export default function objectStoreTest() {
expect(complexObject.list[0].mother == "jack2 mom2").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");
console.log(TAG + "end unWatch success");
console.info(TAG + "end unWatch success");
}
var endTime = new Date().getTime();
var totalTime = endTime - startTime;
console.log("testPerformance001 totalTime = " + totalTime);
console.log("testPerformance001 baseLine = " + baseLine);
console.info("testPerformance001 totalTime = " + totalTime);
console.info("testPerformance001 baseLine = " + baseLine);
expect(totalTime < baseLine).assertEqual(true);
complexObject.setSessionId("");
done();
console.log(TAG + "************* testPerformance001 end *************");
console.info(TAG + "************* testPerformance001 end *************");
})
/**
......@@ -720,26 +720,32 @@ export default function objectStoreTest() {
*/
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);
gObject.setSessionId("");
done();
var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
expect(g_object == undefined).assertEqual(false);
g_object.setSessionId("testSession001");
expect("testSession001" == g_object.__sessionId).assertEqual(true);
g_object.save("local").then((ret) => {
expect(ret.sessionId == "testSession001").assertEqual(true);
expect(ret.version == g_object.__version).assertEqual(true);
expect(ret.deviceId == "local").assertEqual(true);
done();
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("testSession001");
expect(g_object.name == "Amy").assertEqual(true);
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 *************");
})
......@@ -748,67 +754,81 @@ export default function objectStoreTest() {
* @tc.desc: Save object
* @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 *************");
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);
var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
expect(g_object == undefined).assertEqual(false);
g_object.setSessionId("testSession002");
expect("testSession002" == g_object.__sessionId).assertEqual(true);
g_object.save("local", (err, result) => {
if (err) {
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);
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);
done();
gObject.setSessionId("");
});
done();
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
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 *************");
})
/**
* @tc.name: testRevokeSave001
* @tc.desc: Revoke save object <Promise>
* @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 *************");
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();
var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
expect(g_object == undefined).assertEqual(false);
g_object.setSessionId("testSession003");
expect("testSession003" == g_object.__sessionId).assertEqual(true);
g_object.save("local", (err, result) => {
if (err) {
console.info('testRevokeSave001 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
done();
return;
}
expect(result.sessionId == "testSession003").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
g_object.revokeSave((err, result) => {
if (err) {
expect("801").assertEqual(err.code.toString());
done();
return;
}
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 *************");
})
......@@ -817,31 +837,49 @@ export default function objectStoreTest() {
* @tc.desc: Revoke save object <Callback>
* @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 *************");
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("");
var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
expect(g_object == undefined).assertEqual(false);
g_object.setSessionId("testSession004");
expect("testSession004" == g_object.__sessionId).assertEqual(true);
let result = await g_object.save("local").catch((err)=> {
expect("801").assertEqual(err.code.toString());
return CATCH_ERR;
});
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 + "*************Unit Test End*************");
})
}
\ No newline at end of file
......@@ -17,6 +17,7 @@ import distributedObject from '@ohos.data.distributedDataObject';
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import featureAbility from '@ohos.ability.featureAbility';
import bundle from '@ohos.bundle';
const CATCH_ERR = -1;
let context;
const TAG = "OBJECTSTORE_TEST";
function changeCallback(sessionId, changeData) {
......@@ -74,7 +75,7 @@ describe('objectStoreTest', function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
console.info(TAG + "*************Unit Test Begin*************");
/**
......@@ -84,7 +85,7 @@ describe('objectStoreTest', function () {
* @tc.type: FUNC
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001 start *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001 start *************");
var g_object;
try {
g_object = distributedObject.create(123, {name: "Amy", age: 18, isVis: false});
......@@ -108,7 +109,7 @@ describe('objectStoreTest', function () {
}).catch((error) => {
console.info(TAG + error);
});
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_001 end *************");
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -122,7 +123,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002 start *************");
console.info(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);
try {
......@@ -136,7 +137,7 @@ describe('objectStoreTest', function () {
expect(error.code == 401).assertEqual(true);
expect(error.message == "Parameter error. The type of 'sessionId' must be 'string'.").assertEqual(true);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_002 end *************");
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -150,7 +151,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003 start *************");
console.info(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);
g_object.setSessionId("session1");
......@@ -161,7 +162,7 @@ describe('objectStoreTest', function () {
expect(error.code == 15400001).assertEqual(true);
expect(error.message == "create table failed").assertEqual(true);
});
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_003 end *************");
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -175,7 +176,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004 start *************");
console.info(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);
g_object.setSessionId("123456").then((data) => {
......@@ -184,7 +185,7 @@ describe('objectStoreTest', function () {
}).catch((err) => {
console.info(TAG + err.code + err.message);
});
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_004 end *************");
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -198,7 +199,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005
*/
it('SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005 start *************");
console.info(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);
g_object.setSessionId("123456", (error, data) => {
......@@ -214,11 +215,11 @@ describe('objectStoreTest', function () {
console.info(TAG + "setSessionId test");
});
} catch (error) {
console.log(error.code + error.message);
console.info(error.code + error.message);
expect(error.code == 401).assertEqual(true);
expect(error.message == "Parameter error. The type of 'sessionId' must be 'string'.").assertEqual(true);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_SetSessionId_005 end *************");
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -233,7 +234,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_On_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_On_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_001 start *************");
console.info(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);
g_object.setSessionId("session1").then(() => {
......@@ -264,7 +265,7 @@ describe('objectStoreTest', function () {
console.info(TAG + " object is null,set name fail");
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_001 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_001 end *************");
g_object.off("change");
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
......@@ -279,7 +280,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_On_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_On_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_002 start *************");
console.info(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);
g_object.setSessionId("session1");
......@@ -301,7 +302,7 @@ describe('objectStoreTest', function () {
expect(error.code == 401).assertEqual(true);
expect(error.message == "Parameter error. The type of 'type' must be 'string'.").assertEqual(true);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_002 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_002 end *************");
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -315,7 +316,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_On_003
*/
it('SUB_DDM_AppDataFWK_Object_Api9_On_003', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_003 start *************");
console.info(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);
g_object.setSessionId("session1").then(() => {
......@@ -338,7 +339,7 @@ describe('objectStoreTest', function () {
} catch (error) {
expect(error != undefined).assertEqual(true);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_003 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_003 end *************");
g_object.off("error");
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
......@@ -353,7 +354,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Off_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Off_001', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_001 start *************");
console.info(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);
g_object.setSessionId("session5").then(() => {
......@@ -387,7 +388,7 @@ describe('objectStoreTest', function () {
} else {
console.info(TAG + " object is null,set name fail");
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_001 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_001 end *************");
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
......@@ -401,7 +402,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Off_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Off_002', 0, function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_002 start *************");
console.info(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);
g_object.setSessionId("session6").then(() => {
......@@ -417,7 +418,7 @@ describe('objectStoreTest', function () {
expect(error.message == "Parameter error. The type of 'type' must be 'string'.").assertEqual(true);
}
console.info(TAG + " end call watch change");
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_002 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Off_002 end *************");
g_object.setSessionId().then((data) => {
console.info(TAG + data);
console.info(TAG + "setSessionId test");
......@@ -434,8 +435,8 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001
*/
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");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001 start *************");
console.info(TAG + "start watch status");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
try {
......@@ -444,8 +445,8 @@ describe('objectStoreTest', function () {
expect(error.code == 401).assertEqual(true);
expect(error.message == "Parameter error. The type of 'callback' must be 'function'.").assertEqual(true);
}
console.log(TAG + "watch success");
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001 end *************");
console.info(TAG + "watch success");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_001 end *************");
g_object.setSessionId("").then((data) => {
console.info(TAG + data);
console.info(TAG + "setSessionId test");
......@@ -462,17 +463,17 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002
*/
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");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002 start *************");
console.info(TAG + "start watch status");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
expect(g_object.name == "Amy").assertEqual(true);
g_object.on("status", statusCallback1);
console.log(TAG + "watch success");
console.log(TAG + "start call unwatch status");
console.info(TAG + "watch success");
console.info(TAG + "start call unwatch status");
g_object.off("status");
console.log(TAG + "unwatch success");
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002 end *************");
console.info(TAG + "unwatch success");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_OnStatus_002 end *************");
g_object.setSessionId().then(() => {
console.info("leave session");
}).catch((error) => {
......@@ -488,46 +489,41 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Save_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Save_001', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_001 start *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_001 start *************");
console.info(TAG + "************* V9testSave001 start *************");
var g_object = distributedObject.create(context, {name: "Amy", age: 18, isVis: false});
expect(g_object == undefined).assertEqual(false);
g_object.setSessionId("tmpsession1").then(() => {
g_object.setSessionId("mySession1").then(() => {
console.info("join session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
expect("tmpsession1" == g_object.__sessionId).assertEqual(true);
expect("mySession1" == g_object.__sessionId).assertEqual(true);
let result = await g_object.save("local");
expect(result.sessionId == "tmpsession1").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
g_object.save("local").then((ret) => {
expect(ret.sessionId == "mySession1").assertEqual(true);
expect(ret.version == g_object.__version).assertEqual(true);
expect(ret.deviceId == "local").assertEqual(true);
done();
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("tmpsession1").then(() => {
console.info("join session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("mySession1");
expect(g_object.name == "Amy").assertEqual(true);
expect(g_object.age == 18).assertEqual(true);
expect(g_object.isVis == false).assertEqual(true);
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_001 end *************");
g_object.setSessionId().then(() => {
console.info("leave session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
expect(g_object.name == "Amy").assertEqual(true);
expect(g_object.age == 18).assertEqual(true);
expect(g_object.isVis == false).assertEqual(true);
}).catch((err) => {
console.info('testV9Save001 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
done();
});
done();
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_001 end *************");
})
/**
* @tc.name: V9testSave002
* @tc.desc: test save local
......@@ -535,47 +531,38 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_Save_002
*/
it('SUB_DDM_AppDataFWK_Object_Api9_Save_002', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_002 start *************");
console.info(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);
g_object.setSessionId("tmpsession1").then(() => {
console.info("join session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
expect("tmpsession1" == g_object.__sessionId).assertEqual(true);
try {
g_object.save(1234).then((result) => {
expect(result.sessionId == "tmpsession1").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
})
} catch (error) {
expect(error.message == "Parameter error. The type of 'deviceId' must be 'string'.").assertEqual(true);
}
g_object.save("errorDeviceId").then((result) => {
expect(result.sessionId == "tmpsession1").assertEqual(true);
g_object.setSessionId("mySession2");
expect("mySession2" == g_object.__sessionId).assertEqual(true);
g_object.save("local", (err, result) => {
if (err) {
console.info('testV9Save002 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
done();
return;
}
expect(result.sessionId == "mySession2").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
}).catch((error) => {
expect(error != undefined).assertEqual(true);
});
try {
g_object.save("local", 123);
} catch (error) {
expect(error.code == 401).assertEqual(true);
expect(error.message == "Parameter error. The type of 'callback' must be 'function'.").assertEqual(true);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_002 end *************");
g_object.setSessionId().then(() => {
console.info("leave session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("mySession2");
expect(g_object.name == "Amy").assertEqual(true);
expect(g_object.age == 18).assertEqual(true);
expect(g_object.isVis == false).assertEqual(true);
done();
});
done();
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_Save_002 end *************");
})
/**
* @tc.name: V9testRevokeSave001
......@@ -584,45 +571,46 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001
*/
it('SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001 start *************");
console.info(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);
g_object.setSessionId("123456").then(() => {
console.info("join session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
expect("123456" == g_object.__sessionId).assertEqual(true);
g_object.setSessionId("mySession4");
expect("mySession4" == g_object.__sessionId).assertEqual(true);
let result = await g_object.save("local");
expect(result.sessionId == "123456").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
result = await g_object.revokeSave();
g_object.setSessionId((error, data) => {
console.info(TAG + error + "," + data);
});
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("123456").then(() => {
console.info("join session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
});
expect(g_object.name == undefined).assertEqual(true);
expect(g_object.age == undefined).assertEqual(true);
expect(g_object.isVis == undefined).assertEqual(true);
expect(result.sessionId == "123456").assertEqual(true);
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001 end *************");
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
g_object.save("local", (err, result) => {
if (err) {
console.info('testV9RevokeSave001 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
done();
return;
}
expect(result.sessionId == "mySession4").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
g_object.revokeSave((err, result) => {
if (err) {
expect("801").assertEqual(err.code.toString());
done();
return;
}
expect("mySession4" == result.sessionId).assertEqual(true);
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("mySession4");
expect(g_object.name == undefined).assertEqual(true);
expect(g_object.age == undefined).assertEqual(true);
expect(g_object.isVis == undefined).assertEqual(true);
done();
})
});
done();
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_001 end *************");
})
/**
* @tc.name: V9testRevokeSave002
......@@ -630,37 +618,48 @@ 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 (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002 start *************");
it('SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002', 0, async function () {
console.info(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);
g_object.setSessionId("123456").then(() => {
console.info("join session");
}).catch((error) => {
console.info(TAG + error.code + error.message);
expect(g_object != undefined).assertEqual(true);
g_object.setSessionId("mySession5");
expect("mySession5" == g_object.__sessionId.toString()).assertEqual(true);
let result = await g_object.save("local").catch((err) => {
console.info('testV9Save001 err ' + `, error code is ${err.code}, message is ${err.message}`);
expect("801").assertEqual(err.code.toString());
return CATCH_ERR;
});
expect("123456" == g_object.__sessionId).assertEqual(true);
let result = await g_object.save("local");
expect(result.sessionId == "123456").assertEqual(true);
expect(result.version == g_object.__version).assertEqual(true);
expect(result.deviceId == "local").assertEqual(true);
try {
g_object.revokeSave(123).then((result) => {
expect(result.sessionId == "tmpsession1").assertEqual(true)
}).catch((err) => {
console.log(err.code + err.message);
});
} catch (error) {
console.info(error.code + error.message);
expect(error.code == 401).assertEqual(true);
expect(error.message == "Parameter error. The type of 'callback' must be 'function'.").assertEqual(true);
if (result === CATCH_ERR) {
return;
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002 end *************");
g_object.setSessionId("", (error, data) => {
console.info(TAG + error + "," + data);
expect(result.sessionId.toString() == "mySession5").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)=> {
expect("801").assertEqual(err.code.toString());
return CATCH_ERR;
});
done();
})
if (result === CATCH_ERR) {
return;
}
g_object.setSessionId("");
g_object.name = undefined;
g_object.age = undefined;
g_object.isVis = undefined;
g_object.setSessionId("mySession5");
expect(g_object.name == undefined).assertEqual(true);
expect(g_object.age == undefined).assertEqual(true);
expect(g_object.isVis == undefined).assertEqual(true);
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_RevokeSave_002 end *************");
})
/**
* @tc.name: testNumberMax
* @tc.desc: test NumberMax
......@@ -668,7 +667,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100 start *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100 start *************");
try {
let g_object;
let maxValue = Number.MAX_VALUE;
......@@ -678,7 +677,7 @@ describe('objectStoreTest', function () {
} catch (error) {
console.info(error.code + error.message);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100 end *************");
done();
})
/**
......@@ -688,7 +687,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100 start *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100 start *************");
try {
let g_object;
let minValue = Number.MIN_VALUE;
......@@ -698,7 +697,7 @@ describe('objectStoreTest', function () {
} catch (error) {
console.info(error.code + error.message);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100 end *************");
done();
})
/**
......@@ -708,7 +707,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 start *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 start *************");
try {
let g_object;
let abnValue = -1;
......@@ -718,7 +717,7 @@ describe('objectStoreTest', function () {
} catch (error) {
console.info(error.code + error.message);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************");
done();
})
/**
......@@ -728,7 +727,7 @@ describe('objectStoreTest', function () {
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0200
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 start *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 start *************");
try {
let g_object;
let abnValue = 0.02;
......@@ -738,9 +737,9 @@ describe('objectStoreTest', function () {
} catch (error) {
console.info(error.code + error.message);
}
console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************");
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************");
done();
})
console.log(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 '
import data_Rdb from '@ohos.data.relationalStore';
import ability_featureAbility from '@ohos.ability.featureAbility';
const ERRCODE = 801;
var context = ability_featureAbility.getContext();
var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" +
"id INTEGER PRIMARY KEY AUTOINCREMENT," +
......@@ -100,8 +101,8 @@ describe('relationalStoreDistributedTest', function () {
console.info(TAG + "set none to be distributed table success");
expect(rdbStore).assertEqual(rdbStore)
} catch (err) {
console.info(TAG + "set none to be distributed table failed");
expect(null).assertFail();
console.info(TAG + "setDistributed002 failed"+ `, error code is ${err.code}, message is ${err.message}`);
expect(err.code).assertEqual(ERRCODE);
}
done()
console.info(TAG + "************* testRdbStoreDistributed002 end *************");
......@@ -119,8 +120,8 @@ describe('relationalStoreDistributedTest', function () {
console.info(TAG + "set employee to be distributed table success");
expect(rdbStore).assertEqual(rdbStore)
} catch (err) {
console.info(TAG + "set employee to be distributed table failed");
expect(null).assertFail();
console.info(TAG + "setDistributed003 failed"+ `, error code is ${err.code}, message is ${err.message}`);
expect(err.code).assertEqual(ERRCODE);
}
done()
console.info(TAG + "************* testRdbStoreDistributed003 end *************");
......@@ -138,8 +139,8 @@ describe('relationalStoreDistributedTest', function () {
console.info(TAG + "set employee and product to be distributed table success");
expect(rdbStore).assertEqual(rdbStore)
} catch (err) {
console.info(TAG + "set employee and product to be distributed table failed");
expect(null).assertFail();
console.info(TAG + "setDistributed004 failed"+ `, error code is ${err.code}, message is ${err.message}`);
expect(err.code).assertEqual(ERRCODE);
}
done()
console.info(TAG + "************* testRdbStoreDistributed004 end *************");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册