diff --git a/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js index 5ae040ad29c9d9fc79561dbaa55d020bbb25270b..b47b63c12674e27ad2acad620c2bf74940e3c8a8 100644 --- a/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js +++ b/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunit.test.js @@ -1,5 +1,5 @@ /* - * 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 @@ -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(""); }) /** @@ -711,12 +708,12 @@ export default function objectStoreTest() { console.log("testPerformance001 totalTime = " + totalTime); console.log("testPerformance001 baseLine = " + baseLine); expect(totalTime < baseLine).assertEqual(true); - + complexObject.setSessionId(""); done(); console.log(TAG + "************* testPerformance001 end *************"); - complexObject.setSessionId(""); + }) - /** + /** * @tc.name: testSave001 * @tc.desc: Save object * @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_001 diff --git a/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunitV9.test.js b/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunitV9.test.js index 02ce500ea07d20d6324b7bc7fcef5ae020ee1974..36e18189864d97291e204ce57f124e1a6dfa6efe 100644 --- a/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunitV9.test.js +++ b/distributeddatamgr/dataObjectjstest/hap/src/main/js/test/ObjectStoreJsunitV9.test.js @@ -1,5 +1,5 @@ /* - * 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 @@ -265,6 +265,7 @@ describe('objectStoreTest', function () { } console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_001 end *************"); + g_object.off("change"); g_object.setSessionId("", (error, data) => { console.info(TAG + error + "," + data); }); @@ -338,6 +339,7 @@ describe('objectStoreTest', function () { expect(error != undefined).assertEqual(true); } console.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_On_003 end *************"); + g_object.off("error"); g_object.setSessionId("", (error, data) => { console.info(TAG + error + "," + data); }); @@ -658,8 +660,87 @@ describe('objectStoreTest', function () { console.info(TAG + error + "," + data); }); done(); - }) - - 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.log(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.log(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.log(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.log(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.log(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.log(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.log(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.log(TAG + "************* SUB_DDM_AppDataFWK_Object_Api9_NumberAbnormal_0100 end *************"); + done(); + }) +console.log(TAG + "*************Unit Test End*************"); }) } \ No newline at end of file diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesCallBackJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesCallBackJsunit.test.js index 74274f0dc6a49079a7991ea22d95377c518c3040..dd60f1dad35a37b7f27375fab4472a40c6195da6 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesCallBackJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesCallBackJsunit.test.js @@ -1,5 +1,5 @@ /* -* 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 @@ -455,7 +455,7 @@ describe('preferencesCallBackTest', function () { expect(false).assertTrue(); }else{ console.info(TAG + "Delete preferences success") - expect(true).assertTrue(); + expect(data == null).assertTrue(); } }) done() @@ -482,7 +482,7 @@ describe('preferencesCallBackTest', function () { expect(false).assertTrue(); }else{ console.info(TAG + "Remove preferences from cache success") - expect(true).assertTrue(); + expect(data==null).assertTrue(); } }) done(); diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesHelperJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesHelperJsunit.test.js index cae9a79669e7ce456142a57d5e2269b9efed8a4b..dd895f0e346c3af640c581fc23662a0271ee8088 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesHelperJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesHelperJsunit.test.js @@ -1,5 +1,5 @@ /* -* 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 diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js index 31d5ac4505ad329bc2f5148fb0dfcd1cd080b59b..27dd9f343ed4a686a9c7515069def6cd00c71374 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesPromiseJsunit.test.js @@ -1,5 +1,5 @@ /* -* 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 @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import dataPreferences from '@ohos.data.preferences' import featureAbility from '@ohos.ability.featureAbility'; diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/SystemStorageJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/SystemStorageJsunit.test.js index a5ac65ae2a9122eb30531080bd6bc1338d94bda0..dba97def9775fdd34e68a2f7ef16c1c2591f92d2 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/SystemStorageJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/SystemStorageJsunit.test.js @@ -1,5 +1,5 @@ /* -* 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 @@ -30,11 +30,13 @@ describe('systemStorageTest', function () { afterEach(async function (done) { console.info(TAG + 'afterEach') let promise = storage.clear({ - success: function () { - expect(true).assertTrue(); + success: function (data) { + console.info("Succeeded in clearing."); + expect(data!=undefined).assertTrue(); done(); }, fail: function (data, errCode) { + console.info("Failed to clearr"); expect(false).assertTrue(); done(); } @@ -200,8 +202,9 @@ describe('systemStorageTest', function () { let promise1 = storage.set({ key: 'storageKey', value: 'storageVal', - success: async function () { - await expect(true).assertTrue(); + success:async function (data) { + console.info("Set is success."); + await expect(data != undefined).assertTrue(); }, fail: async function (data, err) { await expect(false).assertTrue(); @@ -340,8 +343,9 @@ describe('systemStorageTest', function () { let promise1 = storage.set({ key: 'storageKey', value: 'storageVal', - success: async function () { - await expect(true).assertTrue(); + success:async function (data) { + console.info("Set is success."); + await expect(data != undefined).assertTrue(); }, fail: async function (data, err) { await expect(false).assertTrue(); @@ -390,8 +394,9 @@ describe('systemStorageTest', function () { let promise1 = storage.set({ key: 'storageKey', value: 'storageVal', - success: async function () { - await expect(true).assertTrue(); + success:async function (data) { + console.info("Set is success."); + await expect(data != undefined).assertTrue(); }, fail: async function (data, err) { await expect(false).assertTrue(); @@ -435,8 +440,9 @@ describe('systemStorageTest', function () { let promise1 = storage.set({ key: 'storageKey', value: 'test', - success: async function () { - await expect(true).assertTrue(); + success:async function (data) { + console.info("Set is success."); + await expect(data != undefined).assertTrue(); }, fail: async function () { await expect(false).assertTrue(); @@ -445,8 +451,9 @@ describe('systemStorageTest', function () { await promise1; let promise2 = storage.delete({ key: '123', - success: async function () { - await expect(true).assertTrue(); + success: async function (data) { + console.info("delete is success."); + await expect(data != undefined).assertTrue(); }, fail: async function (data, err) { await expect(false).assertTrue(); @@ -486,8 +493,9 @@ describe('systemStorageTest', function () { let promise1 = storage.set({ key: 'storageKey1', value: 'storageVal1', - success:async function () { - await expect(true).assertTrue(); + success:async function (data) { + console.info("Set is success."); + await expect(data != undefined).assertTrue(); }, fail:async function () { await expect(false).assertTrue(); @@ -497,8 +505,9 @@ describe('systemStorageTest', function () { let promise2 = storage.set({ key: 'storageKey2', value: 'storageVal2', - success:async function () { - await expect(true).assertTrue(); + success:async function (data) { + console.info("Set is success.") + await expect(data != undefined).assertTrue(); }, fail:async function () { await expect(false).assertTrue();