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

!7116 【Distributeddatamgr】【master】Object以及preference测试用例优化整改

Merge pull request !7116 from wangxiaomeng/master
/*
* 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 <Promise>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_001
......
/*
* 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
/*
* 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();
......
/*
* 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,8 +12,8 @@
* 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 dataPreferences from '@ohos.data.preferences'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import dataPreferences from '@ohos.data.preferences';
import featureAbility from '@ohos.ability.featureAbility';
const NAME = 'test_preferences';
......@@ -22,22 +22,22 @@ const KEY_TEST_LONG_ELEMENT = 'key_test_long';
const KEY_TEST_FLOAT_ELEMENT = 'key_test_float';
const KEY_TEST_BOOLEAN_ELEMENT = 'key_test_boolean';
const KEY_TEST_STRING_ELEMENT = 'key_test_string';
const KEY_TEST_NUMBER_ARRAY_ELEMENT = 'key_test_number_array'
const KEY_TEST_STRING_ARRAY_ELEMENT = 'key_test_string_array'
const KEY_TEST_BOOL_ARRAY_ELEMENT = 'key_test_bool_array'
const KEY_TEST_NUMBER_ARRAY_ELEMENT = 'key_test_number_array';
const KEY_TEST_STRING_ARRAY_ELEMENT = 'key_test_string_array';
const KEY_TEST_BOOL_ARRAY_ELEMENT = 'key_test_bool_array';
var mPreferences;
var context;
export default function preferencesPromiseTest(){
describe('preferencesPromiseTest', function () {
beforeAll(async function () {
console.info('beforeAll')
context = featureAbility.getContext()
console.info('beforeAll');
context = featureAbility.getContext();
mPreferences = await dataPreferences.getPreferences(context, NAME);
})
afterAll(async function () {
console.info('afterAll')
console.info('afterAll');
await dataPreferences.deletePreferences(context, NAME);
})
......@@ -48,10 +48,10 @@ export default function preferencesPromiseTest(){
*/
it('testPreferencesPutStringArray0131', 0, async function (done) {
await mPreferences.clear();
var stringArr = ['1', '2', '3']
let promise1 = mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr)
await promise1
let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ['123', '321'])
var stringArr = ['1', '2', '3'];
let promise1 = mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr);
await promise1;
let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ['123', '321']);
promise2.then((pre) => {
for (let i = 0; i < stringArr.length; i++) {
expect(stringArr[i]).assertEqual(pre[i]);
......@@ -60,7 +60,7 @@ export default function preferencesPromiseTest(){
}).catch((err) => {
expect(null).assertFail();
})
await promise2
await promise2;
done();
});
......@@ -72,10 +72,10 @@ export default function preferencesPromiseTest(){
*/
it('testPreferencesPutNumberArray0132', 0, async function (done) {
await mPreferences.clear();
var numberArr = [11, 22, 33, 44, 55]
let promise1 = mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr)
await promise1
let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321])
var numberArr = [11, 22, 33, 44, 55];
let promise1 = mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr);
await promise1;
let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]);
promise2.then((pre) => {
for (let i = 0; i < numberArr.length; i++) {
expect(numberArr[i]).assertEqual(pre[i]);
......@@ -83,7 +83,7 @@ export default function preferencesPromiseTest(){
}).catch((err) => {
expect(null).assertFail();
})
await promise2
await promise2;
done();
});
......@@ -95,10 +95,10 @@ export default function preferencesPromiseTest(){
*/
it('testPreferencesPutBoolArray0133', 0, async function (done) {
await mPreferences.clear();
var boolArr = [true, true, false]
let promise1 = mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr)
await promise1
let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true])
var boolArr = [true, true, false];
let promise1 = mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr);
await promise1;
let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true]);
promise2.then((pre) => {
for (let i = 0; i < boolArr.length; i++) {
expect(boolArr[i]).assertEqual(pre[i]);
......@@ -106,7 +106,7 @@ export default function preferencesPromiseTest(){
}).catch((err) => {
expect(null).assertFail();
})
await promise2
await promise2;
done();
});
......@@ -118,29 +118,29 @@ export default function preferencesPromiseTest(){
*/
it('testPreferencesGetAll0001', 0, async function (done) {
await mPreferences.clear();
let doubleArr = [11, 22, 33]
let stringArr = ['11', '22', '33']
let boolArr = [true, false, false, true]
await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr)
await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr)
await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr)
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false)
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123")
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1)
await mPreferences.flush()
let promise = mPreferences.getAll()
let doubleArr = [11, 22, 33];
let stringArr = ['11', '22', '33'];
let boolArr = [true, false, false, true];
await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr);
await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr);
await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr);
await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false);
await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123");
await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1);
await mPreferences.flush();
let promise = mPreferences.getAll();
promise.then((obj) => {
expect(false).assertEqual(obj.key_test_boolean)
expect("123").assertEqual(obj.key_test_string)
expect(123.1).assertEqual(obj.key_test_float)
let sArr = obj.key_test_string_array
expect(false).assertEqual(obj.key_test_boolean);
expect("123").assertEqual(obj.key_test_string);
expect(123.1).assertEqual(obj.key_test_float);
let sArr = obj.key_test_string_array;
for (let i = 0; i < sArr.length; i++) {
expect(sArr[i]).assertEqual(stringArr[i]);
}
let bArr = obj.key_test_bool_array
let bArr = obj.key_test_bool_array;
for (let i = 0; i < bArr.length; i++) {
expect(bArr[i]).assertEqual(boolArr[i]);
}
......@@ -152,7 +152,7 @@ export default function preferencesPromiseTest(){
}).catch((err) => {
expect(null).assertFail();
})
await promise
await promise;
done();
})
......
/*
* 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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册