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

!8104 【Distributeddatamgr】【OpenHarmony-3.2-Release】用例优化add 801

Merge pull request !8104 from yanglifeng/OpenHarmony-3.2-Release
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-2023 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
......@@ -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) {
......@@ -130,9 +130,10 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
objectTest.off("change");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOn001 end *************");
objectTest.setSessionId("");
})
/**
......@@ -160,9 +161,9 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOn002 end *************");
objectTest.setSessionId("");
})
/**
......@@ -198,10 +199,10 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
objectTest.off("change");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOn003 end *************");
objectTest.setSessionId("");
})
/**
......@@ -221,11 +222,11 @@ export default function objectStoreTest() {
}
objectTest.on("change", changeCallback);
console.info(TAG + " start call watch change");
objectTest.off("change");
console.info(TAG + " end call watch change");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOn004 end *************");
objectTest.setSessionId("");
})
/**
......@@ -267,10 +268,9 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
objectTest.setSessionId("");
done()
console.info(TAG + "************* testOff001 end *************");
objectTest.setSessionId("");
})
/**
......@@ -336,6 +336,7 @@ 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 {
......@@ -351,10 +352,12 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " testObject is null,set name fail");
}
done();
console.info(TAG + "************* testMultiObjectOn001 end *************");
objectTest.off("change");
testObject.off("change");
objectTest.setSessionId("");
testObject.setSessionId("");
done();
console.info(TAG + "************* testMultiObjectOn001 end *************");
})
/**
......@@ -427,11 +430,10 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
done();
console.info(TAG + "************* testMultiObjectOff001 end *************");
objectTest.setSessionId("");
testObject.setSessionId("");
done();
console.info(TAG + "************* testMultiObjectOff001 end *************");
})
/**
......@@ -480,9 +482,10 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
objectTest.off("change");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testChangeSession001 end *************");
objectTest.setSessionId("");
})
/**
......@@ -501,7 +504,6 @@ export default function objectStoreTest() {
} catch (error) {
console.error(TAG + error);
}
done();
console.info(TAG + "************* testUndefinedType001 end *************");
})
......@@ -515,7 +517,6 @@ export default function objectStoreTest() {
console.info(TAG + "************* testGenSessionId001 start *************");
var sessionId = distributedObject.genSessionId();
expect(sessionId != null && sessionId.length > 0 && typeof (sessionId) == 'string').assertEqual(true);
done();
console.info(TAG + "************* testGenSessionId001 end *************");
})
......@@ -546,10 +547,10 @@ export default function objectStoreTest() {
var objectTest = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
objectTest.on("status", statusCallback1);
console.info(TAG + "watch success");
objectTest.off("status");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOnStatus001 end *************");
objectTest.setSessionId("");
})
/**
......@@ -570,10 +571,9 @@ export default function objectStoreTest() {
console.info(TAG + "start call unwatch status");
objectTest.off("status", statusCallback1);
console.info(TAG + "unwatch success");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOnStatus002 end *************");
objectTest.setSessionId("");
})
/**
......@@ -592,12 +592,11 @@ export default function objectStoreTest() {
objectTest.on("status", statusCallback3);
console.info(TAG + "watch success");
console.info(TAG + "start call unwatch status");
objectTest.off("status");
objectTest.off("status", statusCallback1);
console.info(TAG + "unwatch success");
objectTest.setSessionId("");
done();
console.info(TAG + "************* testOnStatus003 end *************");
objectTest.setSessionId("");
})
/**
......@@ -631,10 +630,9 @@ export default function objectStoreTest() {
expect(complexObject.parent.father == "jack Dad").assertEqual(true);
expect(complexObject.list[0].mother == "jack2 mom2").assertEqual(true);
expect(complexObject.list[1].father == "jack2 Dad2").assertEqual(true);
complexObject.setSessionId("");
done();
console.info(TAG + "************* testComplex001 end *************");
complexObject.setSessionId("");
})
/**
......@@ -663,10 +661,9 @@ export default function objectStoreTest() {
} else {
console.info(TAG + " object is null,set name fail");
}
objectTest.setSessionId("");
done()
console.info(TAG + "************* testMaxSize001 end *************");
objectTest.setSessionId("");
})
/**
......@@ -702,47 +699,53 @@ 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);
done();
console.log(TAG + "************* testPerformance001 end *************");
complexObject.setSessionId("");
done();
console.info(TAG + "************* testPerformance001 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 *************");
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 *************");
})
......@@ -751,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 *************");
})
......@@ -820,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
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2022-2023 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
......@@ -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,8 @@ 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);
});
......@@ -278,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");
......@@ -300,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);
});
......@@ -314,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(() => {
......@@ -337,7 +339,8 @@ 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);
});
......@@ -351,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(() => {
......@@ -385,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);
});
......@@ -399,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(() => {
......@@ -415,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");
......@@ -432,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 {
......@@ -442,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");
......@@ -460,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) => {
......@@ -486,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
......@@ -533,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
......@@ -582,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);
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("mySession4");
expect("mySession4" == g_object.__sessionId).assertEqual(true);
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
......@@ -628,38 +618,128 @@ 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 *************");
})
console.log(TAG + "*************Unit Test End*************");
/**
* @tc.name: testNumberMax
* @tc.desc: test NumberMax
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100 start *************");
try {
let g_object;
let maxValue = Number.MAX_VALUE;
g_object= distributedObject.create(context, {name: "Amy", age: maxValue, isVis: false});
console.info(TAG + "_age = "+g_object.age);
expect(g_object == undefined).assertEqual(false);
} catch (error) {
console.info(error.code + error.message);
}
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMax_0100 end *************");
done();
})
/**
* @tc.name: testNumberMin
* @tc.desc: test NumberMin
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100 start *************");
try {
let g_object;
let minValue = Number.MIN_VALUE;
g_object= distributedObject.create(context, {name: "Amy", age: minValue, isVis: false});
console.info(TAG + "_age = "+g_object.age);
expect(g_object == undefined).assertEqual(false);
} catch (error) {
console.info(error.code + error.message);
}
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberMin_0100 end *************");
done();
})
/**
* @tc.name: testNumberAbnormal
* @tc.desc: test NumberAbnormal
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 start *************");
try {
let g_object;
let abnValue = -1;
g_object= distributedObject.create(context, {name: "Amy", age: abnValue, isVis: false});
console.info(TAG + "_age = "+g_object.age);
expect(g_object == undefined).assertEqual(false);
} catch (error) {
console.info(error.code + error.message);
}
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************");
done();
})
/**
* @tc.name: testNumberAbnormal
* @tc.desc: test NumberAbnormal
* @tc.type: FUNC
* @tc.number: SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0200
*/
it('SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100', 0, async function (done) {
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 start *************");
try {
let g_object;
let abnValue = 0.02;
g_object= distributedObject.create(context, {name: "Amy", age: abnValue, isVis: false});
console.info(TAG + "_age = "+g_object.age);
expect(g_object == undefined).assertEqual(false);
} catch (error) {
console.info(error.code + error.message);
}
console.info(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************");
done();
})
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.
先完成此消息的编辑!
想要评论请 注册