From bbc09c8be83b2e8b9e01bb284454902b1a8deeea Mon Sep 17 00:00:00 2001 From: wangxiyue Date: Mon, 20 Jun 2022 10:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B9=B6=E4=BC=98=E5=8C=96js?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangxiyue --- .../jskitsimpl/test/unittest/src/BUILD.gn | 2 +- .../unittest/src/ObjectStoreJsunit.test.js | 463 ++++++++++-------- .../jskitsimpl/test/unittest/src/config.json | 17 + .../test/unittest/src/openharmony_sx.p7b | Bin 0 -> 3509 bytes 4 files changed, 279 insertions(+), 203 deletions(-) create mode 100644 frameworks/jskitsimpl/test/unittest/src/openharmony_sx.p7b diff --git a/frameworks/jskitsimpl/test/unittest/src/BUILD.gn b/frameworks/jskitsimpl/test/unittest/src/BUILD.gn index 4b2d7f0..b0beec0 100644 --- a/frameworks/jskitsimpl/test/unittest/src/BUILD.gn +++ b/frameworks/jskitsimpl/test/unittest/src/BUILD.gn @@ -21,7 +21,7 @@ ohos_js_unittest("ObjectStoreJsTest") { hap_profile = "./config.json" if (is_standard_system) { - certificate_profile = "//test/developertest/signature/openharmony_sx.p7b" + certificate_profile = "./openharmony_sx.p7b" } else { deps = [ "//test/developertest/adapter/examples/app_info/test/common/main:get_app_info_test_lib" ] entry_app_dep = [ "//test/developertest/adapter/examples/app_info/test/common/shell:build_shell_execute" ] diff --git a/frameworks/jskitsimpl/test/unittest/src/ObjectStoreJsunit.test.js b/frameworks/jskitsimpl/test/unittest/src/ObjectStoreJsunit.test.js index f01210e..ea5fd01 100644 --- a/frameworks/jskitsimpl/test/unittest/src/ObjectStoreJsunit.test.js +++ b/frameworks/jskitsimpl/test/unittest/src/ObjectStoreJsunit.test.js @@ -12,50 +12,67 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'; import distributedObject from '@ohos.data.distributedDataObject'; +import abilityAccessCtrl from '@ohos.abilityAccessCtrl'; +import bundle from '@ohos.bundle'; -var baseLine = 500; //0.5 second +var baseLine = 3000; //3 second const TAG = "OBJECTSTORE_TEST"; function changeCallback(sessionId, changeData) { - console.info("get init change111" + sessionId + " " + changeData); + console.info("changeCallback start"); if (changeData != null && changeData != undefined) { changeData.forEach(element => { console.info(TAG + "data changed !" + element); }); } - console.info(TAG + "get init change111 end" + sessionId + " " + changeData); + console.info("changeCallback end"); } function changeCallback2(sessionId, changeData) { - console.info("get init change222" + sessionId + " " + changeData); + console.info("changeCallback2 start"); if (changeData != null && changeData != undefined) { changeData.forEach(element => { - console.info(TAG + "data changed !" + element); + console.info(TAG + "data changed !"); }); } - console.info(TAG + "get init change222 end" + sessionId + " " + changeData); + console.info("changeCallback2 end"); } function statusCallback1(sessionId, networkId, status) { - console.info(TAG + "test init change111" + sessionId); + console.info(TAG + "statusCallback1" + sessionId); this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId; } function statusCallback2(sessionId, networkId, status) { - console.info(TAG + "test init change222" + sessionId); + console.info(TAG + "statusCallback2" + sessionId); this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId; } function statusCallback3(sessionId, networkId, status) { - console.info(TAG + "test init change333" + sessionId); + console.info(TAG + "statusCallback3" + sessionId); this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId; } -describe('objectStoreTest', function () { - beforeAll(function () { - console.info(TAG + 'beforeAll') +const TIMEOUT = 1500; +const PERMISSION_USER_SET = 1; +const PERMISSION_USER_NAME = "ohos.permission.DISTRIBUTED_DATASYNC"; +var tokenID = undefined; +async function grantPerm() { + console.info("====grant Permission start===="); + var appInfo = await bundle.getApplicationInfo('com.example.myapplication', 0, 100); + tokenID = appInfo.accessTokenId; + console.info("accessTokenId" + appInfo.accessTokenId + " bundleName:" + appInfo.bundleName); + var atManager = abilityAccessCtrl.createAtManager(); + var result = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME, PERMISSION_USER_SET); + console.info("tokenId" + tokenID + " result:" + result); + console.info("====grant Permission end===="); +} +describe('objectStoreTest',function () { + beforeAll(async function (done) { + await grantPerm(); + done(); }) beforeEach(function () { @@ -79,30 +96,36 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testOn001', 0, function (done) { + it('testOn001', 0, function () { console.log(TAG + "************* testOn001 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session1"); - if (g_object != undefined && g_object != null) { - expect("session1" == g_object.__sessionId); - } else { - console.log(TAG + "testOn001 joinSession failed"); - } + expect("session1" == g_object.__sessionId).assertEqual(true); console.info(TAG + " start call watch change"); - g_object.on("change", changeCallback); + g_object.on("change", function (sessionId, changeData) { + console.info("testOn001 callback start."); + if (changeData != null && changeData != undefined) { + changeData.forEach(element => { + console.info(TAG + "data changed !" + element); + }); + } + console.info("testOn001 callback end."); + }); + if (g_object != undefined && g_object != null) { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testOn001 end *************"); + g_object.setSessionId(""); }) /** @@ -111,28 +134,25 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testOn002', 0, function (done) { + it('testOn002', 0, function () { console.log(TAG + "************* testOn002 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session2"); - if (g_object != undefined && g_object != null) { - expect("session2" == g_object.__sessionId); - } else { - console.log(TAG + "testOn002 joinSession failed"); - } + expect("session2" == g_object.__sessionId).assertEqual(true); if (g_object != undefined && g_object != null) { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testOn002 end *************"); + g_object.setSessionId(""); }) /** @@ -141,35 +161,32 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testOn003', 0, function (done) { + it('testOn003', 0, function () { console.log(TAG + "************* testOn003 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session3"); - if (g_object != undefined && g_object != null) { - expect("session3" == g_object.__sessionId); - } else { - console.log(TAG + "testOn003 joinSession failed"); - } + expect("session3" == g_object.__sessionId).assertEqual(true); g_object.on("change", changeCallback); console.info(TAG + " start call watch change"); if (g_object != undefined && g_object != null) { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); g_object.name = "jack2"; g_object.age = 20; g_object.isVis = false; - expect(g_object.name == "jack2"); - expect(g_object.age == 20); + expect(g_object.name == "jack2").assertEqual(true); + expect(g_object.age == 20).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testOn003 end *************"); + g_object.setSessionId(""); }) /** @@ -178,21 +195,17 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testOn004', 0, function (done) { + it('testOn004', 0, function () { console.log(TAG + "************* testOn004 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session4"); - if (g_object != undefined && g_object != null) { - expect("session4" == g_object.__sessionId); - } else { - console.log(TAG + "testOn004 joinSession failed"); - } + expect("session4" == g_object.__sessionId).assertEqual(true); g_object.on("change", changeCallback); console.info(TAG + " start call watch change"); console.info(TAG + " end call watch change"); - - done() console.log(TAG + "************* testOn004 end *************"); + g_object.setSessionId(""); }) /** @@ -201,23 +214,21 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testOff001', 0, function (done) { + it('testOff001', 0, function () { console.log(TAG + "************* testOff001 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session5"); - if (g_object != undefined && g_object != null) { - expect("session5" == g_object.__sessionId); - } else { - console.log(TAG + "testOff001 joinSession failed"); - } + expect("session5" == g_object.__sessionId).assertEqual(true); + g_object.on("change", changeCallback); console.info(TAG + " start call watch change"); if (g_object != undefined && g_object != null) { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); @@ -228,15 +239,15 @@ describe('objectStoreTest', function () { g_object.name = "jack2"; g_object.age = 20; g_object.isVis = false; - expect(g_object.name == "jack2"); - expect(g_object.age == 20); + expect(g_object.name == "jack2").assertEqual(true); + expect(g_object.age == 20).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testOff001 end *************"); + g_object.setSessionId(""); }) /** @@ -245,30 +256,27 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testOff002', 0, function (done) { + it('testOff002', 0, function () { console.log(TAG + "************* testOff002 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session6"); - if (g_object != undefined && g_object != null) { - expect("session6" == g_object.__sessionId); - } else { - console.log(TAG + "testOff002 joinSession failed"); - } + expect("session6" == g_object.__sessionId).assertEqual(true); g_object.off("change"); console.info(TAG + " end call watch change"); if (g_object != undefined && g_object != null) { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testOff002 end *************"); + g_object.setSessionId(""); }) /** @@ -277,22 +285,18 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testMultiObjectOn001', 0, function (done) { + it('testMultiObjectOn001', 0, function () { console.log(TAG + "************* testMultiObjectOn001 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.setSessionId("session7"); - if (g_object != undefined && g_object != null) { - expect("session7" == g_object.__sessionId); - } else { - console.log(TAG + "testMultiObjectOn001 joinSession failed"); - } + expect("session7" == g_object.__sessionId).assertEqual(true); + var test_object = distributedObject.createDistributedObject({ name: "Eric", age: 81, isVis: true }); + expect(test_object == undefined).assertEqual(false); test_object.setSessionId("testSession1"); - if (test_object != undefined && test_object != null) { - expect("testSession1").assertEqual(test_object.__sessionId); - } else { - console.log(TAG + "testMultiObjectOn001 joinSession failed"); - } + expect("testSession1" == test_object.__sessionId).assertEqual(true); + g_object.on("change", changeCallback); test_object.on("change", changeCallback2); console.info(TAG + " start call watch change"); @@ -300,20 +304,21 @@ describe('objectStoreTest', function () { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); g_object.name = "jack2"; g_object.age = 20; g_object.isVis = false; - expect(g_object.name == "jack2"); - expect(g_object.age == 20); + expect(g_object.name == "jack2").assertEqual(true); + expect(g_object.age == 20).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testMultiObjectOn001 end *************"); + g_object.setSessionId(""); + test_object.setSessionId(""); }) /** @@ -322,22 +327,20 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testMultiObjectOff001', 0, function (done) { + it('testMultiObjectOff001', 0, function () { console.log(TAG + "************* testMultiObjectOff001 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + g_object.setSessionId("session8"); - if (g_object != undefined && g_object != null) { - expect("session8" == g_object.__sessionId); - } else { - console.log(TAG + "testMultiObjectOn002 joinSession failed"); - } + expect("session8" == g_object.__sessionId).assertEqual(true); + var test_object = distributedObject.createDistributedObject({ name: "Eric", age: 81, isVis: true }); + expect(g_object == undefined).assertEqual(false); + test_object.setSessionId("testSession2"); - if (test_object != undefined && test_object != null) { - expect("testSession2" == test_object.__sessionId); - } else { - console.log(TAG + "testMultiObjectOn002 joinSession failed"); - } + expect("testSession2" == test_object.__sessionId).assertEqual(true); + console.log(TAG + " start call watch change") g_object.on("change", changeCallback); test_object.on("change", changeCallback2); @@ -346,8 +349,8 @@ describe('objectStoreTest', function () { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); @@ -356,8 +359,8 @@ describe('objectStoreTest', function () { test_object.name = "jack2"; test_object.age = 20; test_object.isVis = false; - expect(test_object.name == "jack2"); - expect(test_object.age == 20); + expect(test_object.name == "jack2").assertEqual(true); + expect(test_object.age == 20).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); @@ -367,8 +370,8 @@ describe('objectStoreTest', function () { g_object.name = "jack3"; g_object.age = 21; g_object.isVis = false; - expect(g_object.name == "jack3"); - expect(g_object.age == 21); + expect(g_object.name == "jack3").assertEqual(true); + expect(g_object.age == 21).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); @@ -378,15 +381,15 @@ describe('objectStoreTest', function () { test_object.name = "jack4"; test_object.age = 22; test_object.isVis = true; - expect(test_object.name == "jack4"); - expect(test_object.age == 22); + expect(test_object.name == "jack4").assertEqual(true); + expect(test_object.age == 22).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - - done() console.log(TAG + "************* testMultiObjectOff001 end *************"); + g_object.setSessionId(""); + test_object.setSessionId(""); }) /** @@ -395,46 +398,42 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testChangeSession001', 0, function (done) { + it('testChangeSession001', 0, function () { console.log(TAG + "************* testChangeSession001 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + g_object.setSessionId("session9"); - if (g_object != undefined && g_object != null) { - expect("session9" == g_object.__sessionId); - } else { - console.log(TAG + "testChangeSession001 joinSession session9 failed"); - } + expect("session9" == g_object.__sessionId).assertEqual(true); + g_object.on("change", changeCallback); console.info(TAG + " start call watch change"); if (g_object != undefined && g_object != null) { g_object.name = "jack1"; g_object.age = 19; g_object.isVis = true; - expect(g_object.name == "jack1"); - expect(g_object.age == 19); + expect(g_object.name == "jack1").assertEqual(true); + expect(g_object.age == 19).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } g_object.setSessionId("session10"); - if (g_object != undefined && g_object != null) { - expect("session10" == g_object.__sessionId); - } else { - console.log(TAG + "testChangeSession001 joinSession session10 failed"); - } + expect("session10" == g_object.__sessionId).assertEqual(true); + if (g_object != undefined && g_object != null) { g_object.name = "jack2"; g_object.age = 20; g_object.isVis = false; - expect(g_object.name == "jack2"); - expect(g_object.age == 20); + expect(g_object.name == "jack2").assertEqual(true); + expect(g_object.age == 20).assertEqual(true); console.info(TAG + " set data success!"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testChangeSession001 end *************"); + g_object.setSessionId(""); }) /** @@ -443,22 +442,20 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testUndefinedType001', 0, function (done) { + it('testUndefinedType001', 0, function () { console.log(TAG + "************* testUndefinedType001 start *************"); var undefined_object = distributedObject.createDistributedObject({ name: undefined, age: undefined, isVis: undefined }); + expect(undefined_object == undefined).assertEqual(false); try { undefined_object.setSessionId("session11"); - if (undefined_object != undefined && undefined_object != null) { - expect("session11" == undefined_object.__sessionId); - } else { - console.log(TAG + "testChangeSession001 joinSession session11 failed"); - } + expect("session11" == undefined_object.__sessionId).assertEqual(true); + } catch (error) { console.error(TAG + error); } - done() console.log(TAG + "************* testUndefinedType001 end *************"); + undefined_object.setSessionId(""); }) /** @@ -467,12 +464,11 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testGenSessionId001', 0, function (done) { + it('testGenSessionId001', 0, function () { console.log(TAG + "************* testGenSessionId001 start *************"); var sessionId = distributedObject.genSessionId(); - expect(sessionId != null && sessionId.length > 0 && typeof (sessionId) == 'string'); + expect(sessionId != null && sessionId.length > 0 && typeof (sessionId) == 'string').assertEqual(true); - done() console.log(TAG + "************* testGenSessionId001 end *************"); }) @@ -482,13 +478,12 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3LS */ - it('testGenSessionId002', 0, function (done) { - console.log(TAG + "************* testGenSessionId001 start *************"); + it('testGenSessionId002', 0, function () { + console.log(TAG + "************* testGenSessionId002 start *************"); var sessionId1 = distributedObject.genSessionId(); var sessionId2 = distributedObject.genSessionId(); - expect(sessionId1 != sessionId2); + expect(sessionId1 != sessionId2).assertEqual(true); - done() console.log(TAG + "************* testGenSessionId002 end *************"); }) @@ -498,14 +493,14 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3M8 */ - it('testOnStatus001', 0, function (done) { + it('testOnStatus001', 0, function () { console.log(TAG + "************* testOnStatus001 start *************"); console.log(TAG + "start watch status"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); g_object.on("status", statusCallback1); console.log(TAG + "watch success"); - done() console.log(TAG + "************* testOnStatus001 end *************"); }) @@ -515,10 +510,12 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3M8 */ - it('testOnStatus002', 0, function (done) { - console.log(TAG + "************* testOnStatus001 start *************"); + it('testOnStatus002', 0, function () { + console.log(TAG + "************* testOnStatus002 start *************"); console.log(TAG + "start watch status"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + g_object.on("status", statusCallback1); g_object.on("status", statusCallback2); g_object.on("status", statusCallback3); @@ -527,8 +524,9 @@ describe('objectStoreTest', function () { g_object.off("status", statusCallback1); console.log(TAG + "unwatch success"); - done() console.log(TAG + "************* testOnStatus002 end *************"); + g_object.setSessionId(""); + }) /** @@ -537,10 +535,13 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3M8 */ - it('testOnStatus002', 0, function (done) { - console.log(TAG + "************* testOnStatus001 start *************"); + it('testOnStatus003', 0, function () { + console.log(TAG + "************* testOnStatus003 start *************"); console.log(TAG + "start watch status"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + + expect(g_object.name == "Amy").assertEqual(true); g_object.on("status", statusCallback1); g_object.on("status", statusCallback2); g_object.on("status", statusCallback3); @@ -549,8 +550,9 @@ describe('objectStoreTest', function () { g_object.off("status"); console.log(TAG + "unwatch success"); - done() console.log(TAG + "************* testOnStatus003 end *************"); + g_object.setSessionId(""); + }) /** @@ -559,7 +561,7 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3M8 */ - it('testComplex001', 0, function (done) { + it('testComplex001', 0, function () { console.log(TAG + "************* testComplex001 start *************"); var complex_object = distributedObject.createDistributedObject({ name: undefined, @@ -567,24 +569,25 @@ describe('objectStoreTest', function () { parent: undefined, list: undefined }); + expect(complex_object == undefined).assertEqual(false); complex_object.setSessionId("session12"); - if (complex_object != undefined && complex_object != null) { - expect("session12" == complex_object.__sessionId); - } else { - console.log(TAG + "testOnComplex001 joinSession session12 failed"); - } + expect("session12" == complex_object.__sessionId).assertEqual(true); + complex_object.name = "jack"; complex_object.age = 19; complex_object.isVis = false; complex_object.parent = { mother: "jack mom", father: "jack Dad" }; - complex_object.list = [{ mother: "jack mom" }, { father: "jack Dad" }]; - expect(complex_object.name == "jack"); - expect(complex_object.age == 19); - expect(complex_object.parent == { mother: "jack1 mom", father: "jack1 Dad" }); - expect(complex_object.list == [{ mother: "jack1 mom", father: "jack1 Dad" }]); + complex_object.list = [{ mother: "jack2 mom2" }, { father: "jack2 Dad2" }]; + expect(complex_object.name == "jack").assertEqual(true); + expect(complex_object.age == 19).assertEqual(true); + expect(complex_object.parent.mother == "jack mom").assertEqual(true); + expect(complex_object.parent.father == "jack Dad").assertEqual(true); + expect(complex_object.list[0].mother == "jack2 mom2").assertEqual(true); + expect(complex_object.list[1].father == "jack2 Dad2").assertEqual(true); - done() console.log(TAG + "************* testComplex001 end *************"); + complex_object.setSessionId(""); + }) /** @@ -593,29 +596,28 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3M8 */ - it('testMaxSize001', 0, function (done) { + it('testMaxSize001', 0, function () { console.log(TAG + "************* testMaxSize001 start *************"); var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + g_object.setSessionId("session13"); - if (g_object != undefined && g_object != null) { - expect("session13" == g_object.__sessionId); - } else { - console.log(TAG + "testMaxSize001 joinSession session13 failed"); - } + expect("session13" == g_object.__sessionId).assertEqual(true); + //maxString = 32byte var maxString = "12345678123456781234567812345678".repeat(131072); if (g_object != undefined && g_object != null) { g_object.name = maxString; g_object.age = 42; g_object.isVis = false; - expect(g_object.name == maxString); + expect(g_object.name == maxString).assertEqual(false); console.log(TAG + "get/set maxSize string success"); } else { console.info(TAG + " object is null,set name fail"); } - done() console.log(TAG + "************* testMaxSize001 end *************"); + g_object.setSessionId(""); }) /** @@ -624,7 +626,7 @@ describe('objectStoreTest', function () { * @tc.type: FUNC * @tc.require: I4H3M8 */ - it('testPerformance001', 0, function (done) { + it('testPerformance001', 0, function () { console.log(TAG + "************* testPerformance001 start *************"); var complex_object = distributedObject.createDistributedObject({ name: undefined, @@ -632,54 +634,111 @@ describe('objectStoreTest', function () { parent: undefined, list: undefined }); - var st1; - var totalTime = 0; - var setSessionIdTime = 0; - var setTime = 0; - var onTime = 0; - var offTime = 0; + expect(complex_object == undefined).assertEqual(false); + + var startTime = new Date().getTime(); for (var i = 0;i < 100; i++) { - st1 = Date.now(); complex_object.setSessionId("session14"); - setSessionIdTime += Date.now() - st1; - if (complex_object != undefined && complex_object != null) { - expect("session14" == complex_object.__sessionId); - } else { - console.log(TAG + "testPerformance001 joinSession session14 failed"); - } - console.info(TAG + " start call watch change"); - st1 = Date.now(); + expect("session14" == complex_object.__sessionId).assertEqual(true); + complex_object.on("change", changeCallback); - onTime += Date.now() - st1; - console.info(TAG + "on change success"); - st1 = Date.now(); complex_object.name = "jack2"; complex_object.age = 20; complex_object.isVis = false; complex_object.parent = { mother: "jack1 mom1", father: "jack1 Dad1" }; - complex_object.list = [{ mother: "jack1 mom1" }, { father: "jack1 Dad1" }]; - setTime += Date.now() - st1; - expect(complex_object.name == "jack2"); - expect(complex_object.age == 20); - expect(complex_object.parent == { mother: "jack1 mom1", father: "jack1 Dad1" }); - expect(complex_object.list == [{ mother: "jack1 mom1", father: "jack1 Dad1" }]); + complex_object.list = [{ mother: "jack2 mom2" }, { father: "jack2 Dad2" }]; + expect(complex_object.name == "jack2").assertEqual(true); + expect(complex_object.age == 20).assertEqual(true); + expect(complex_object.parent.mother == "jack1 mom1").assertEqual(true); + expect(complex_object.parent.father == "jack1 Dad1").assertEqual(true); + expect(complex_object.list[0].mother == "jack2 mom2").assertEqual(true); + expect(complex_object.list[1].father == "jack2 Dad2").assertEqual(true); console.log(TAG + "start unWatch change"); - st1 = Date.now(); complex_object.off("change"); - offTime += Date.now() - st1; - totalTime += setSessionIdTime; - totalTime += setTime; - totalTime += onTime; - totalTime += offTime; console.log(TAG + "end unWatch success"); + count++; } - console.log(TAG + "totalTime = " + (totalTime / 100)); - expect(totalTime < baseLine); - done() + var endTime = new Date().getTime(); + var totalTime = endTime - startTime; + console.log("testPerformance001 totalTime = " + totalTime); + console.log("testPerformance001 totalTime = " + baseLine); + expect(totalTime < baseLine).assertEqual(true); + console.log(TAG + "************* testPerformance001 end *************"); + complex_object.setSessionId(""); + }) + + /** + * @tc.name: testSave001 + * @tc.desc: test save local + * @tc.type: FUNC + * @tc.require: I4WDAK + */ + it('testSave001', 0, async function () { + console.log(TAG + "************* testSave001 start *************"); + var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + + g_object.setSessionId("tmpsession1"); + expect("tmpsession1" == 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.setSessionId(""); + g_object.name = undefined; + g_object.age = undefined; + g_object.isVis = undefined; + g_object.setSessionId("tmpsession1"); + + expect(g_object.name == "Amy").assertEqual(true); + expect(g_object.age == 18).assertEqual(true); + expect(g_object.isVis == false).assertEqual(true); + console.log(TAG + "************* testSave001 end *************"); + g_object.setSessionId(""); + + }) + + /** + * @tc.name: testRevokeSave001 + * @tc.desc: test save local + * @tc.type: FUNC + * @tc.require: I4WDAK + */ + it('testRevokeSave001', 0, async function () { + console.log(TAG + "************* testRevokeSave001 start *************"); + var g_object = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false }); + expect(g_object == undefined).assertEqual(false); + + g_object.setSessionId("123456"); + 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(""); + g_object.name = undefined; + g_object.age = undefined; + g_object.isVis = undefined; + g_object.setSessionId("123456"); + + 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 + "************* testRevokeSave001 end *************"); + g_object.setSessionId(""); + }) console.log(TAG + "*************Unit Test End*************"); -}) - +}) \ No newline at end of file diff --git a/frameworks/jskitsimpl/test/unittest/src/config.json b/frameworks/jskitsimpl/test/unittest/src/config.json index c5d8256..543936c 100644 --- a/frameworks/jskitsimpl/test/unittest/src/config.json +++ b/frameworks/jskitsimpl/test/unittest/src/config.json @@ -23,6 +23,23 @@ "moduleName": "entry", "moduleType": "entry" }, + "defPermissions": [ + { + "availableScope": [], + "grantMode": "user_grant", + "name": "ohos.permission.DISTRIBUTED_DATASYNC" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.GRANT_SENSITIVE_PERMISSIONS", + "reason": "ceshi" + }, + { + "name": "ohos.permission.DISTRIBUTED_DATASYNC", + "reason": "ceshi" + } + ], "abilities": [ { "visible": true, diff --git a/frameworks/jskitsimpl/test/unittest/src/openharmony_sx.p7b b/frameworks/jskitsimpl/test/unittest/src/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..56e8a3d55193b1224bfe64d98465327062a5cd1b GIT binary patch literal 3509 zcmcgvYj6|S8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