提交 e2f9138b 编写于 作者: L liangzhenyu123

<liangzhenyu6@huawei.com>

Signed-off-by: Nliangzhenyu123 <liangzhenyu6@huawei.com>
上级 fb916288
......@@ -169,63 +169,6 @@ describe('rdbStoreTest', function () {
done();
console.log(TAG + "************* testRdbStore0005 end *************");
})
/**
* @tc.name rdb store deleteRdbStore
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0060
* @tc.desc rdb store deleteRdbStore
*/
// it('testRdbStore0006', 0, async function (done) {
// console.log(TAG + "************* testRdbStore0006 start *************");
//
// let storePromise = dataRdb.getRdbStore(STORE_CONFIG, 4);
// storePromise.then(async (store) => {
// try {
// await store.executeSql(CREATE_TABLE_TEST);
// let deletePromise = dataRdb.deleteRdbStore("rdbstore.db")
// deletePromise.then(()=>{
// console.log(TAG + "deleteRdbStore promise done" + store);
// expect(true).assertTrue();
// })
// } catch (e) {
// expect(null).assertFail();
// }
// }).catch((err) => {
// expect(null).assertFail();
// })
// await storePromise
// storePromise = null
// done();
// console.log(TAG + "************* testRdbStore0006 end *************");
// })
/**
* @tc.name rdb store deleteRdbStore
* @tc.number SUB_DDM_AppDataFWK_JSRDB_RdbStore_0070
* @tc.desc rdb store deleteRdbStore
*/
it('testRdbStore0007', 0, async function (done) {
console.log(TAG + "************* testRdbStore0007 start *************");
let storePromise = dataRdb.getRdbStore(STORE_CONFIG, 6);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
let deletePromise = dataRdb.deleteRdbStore("rdbstore.db")
deletePromise.then(()=>{
console.log(TAG + "deleteRdbStore promise done" + store);
expect(true).assertTrue();
})
} catch (e) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
done();
console.log(TAG + "************* testRdbStore0007 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
......@@ -21,6 +21,8 @@ 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 MAX_KEY_LENGTH = 'X'.repeat(32)
const MAX_VALUE_LENGTH = 'y'.repeat(8191)
var mPref;
describe('storageTest', function () {
......@@ -380,7 +382,7 @@ describe('storageTest', function () {
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0200
* @tc.desc Maximum length of key test
*/
it('testMaxLengthofKety0200', 0, async function(done){
it('testMaxLengthofKey0200', 0, async function(done){
mPref.clearSync();
const promise = mPref.put(MAX_KEY_LENGTH,"value1")
promise.then((ret)=>{
......@@ -449,4 +451,43 @@ describe('storageTest', function () {
await promise;
done();
})
/**
* @tc.name Maximum length of key test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0240
* @tc.desc Maximum length of key test
*/
it('testMaxLengthofKey0240', 0, async function(done){
mPref.putSync(MAX_KEY_LENGTH, "value1");
expect("value1").assertEqual(mPref.getSync(MAX_KEY_LENGTH, "default"));
const promise = mPref.delete(MAX_KEY_LENGTH);
promise.then((ret)=>{
expect("default").assertEqual(mPref.getSync(MAX_KEY_LENGTH,"default"));
}).catch((err)=>{
expect(null).assertFail();
});
await promise;
done();
})
/**
* @tc.name Maximum length of value test
* @tc.number SUB_DDM_AppDataFWK_JSPreferences_Storage_0250
* @tc.desc Maximum length of value test
*/
it('testMaxLengthofValue0250', 0, async function (done) {
mPref.clearSync();
mPref.putSync("test",MAX_VALUE_LENGTH)
const promise = mPref.put("test", "y".repeat(8192));
promise.then((ret) => {
expect(MAX_VALUE_LENGTH).assertEqual(mPref.getSync("test", "defaultvalue"));
}).catch((err) => {
expect(null).assertFail();
});
await promise;
mPref.putSync("test",MAX_VALUE_LENGTH)
expect(MAX_VALUE_LENGTH).assertEqual(mPref.getSync("test", "defaultvalue"));
done();
})
})
......@@ -14,8 +14,11 @@
*/
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 gObject;
const TAG = "OBJECTSTORE_TEST";
function changeCallback(sessionId, changeData) {
......@@ -52,21 +55,43 @@ function statusCallback3(sessionId, networkId, status) {
console.info(TAG + "test init change333" + sessionId);
this.response += "\nstatus changed " + sessionId + " " + status + " " + networkId;
}
function sleep(delay) {
var start = (new Date()).getTime();
while((new Date()).getTime() - start >= delay) {
break;
}
}
var tokenID = undefined;
const TIMEOUT = 2000;
const PERMISSION_USER_SET = 1;
const PERMISSION_USER_NAME = "ohos.permission.DISTRIBUTED_DATASYNC";
describe('objectStoreTest', function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
beforeAll(async function (done) {
console.info("====>beforeAll start====");
var appInfo = await bundle.getApplicationInfo('ohos.acts.distributeddataObject', 0, 100);
tokenID = appInfo.accessTokenId;
console.info(" bundleName:" + appInfo.name);
var atManager = abilityAccessCtrl.createAtManager();
var result = await atManager.grantUserGrantedPermission(tokenID, PERMISSION_USER_NAME, PERMISSION_USER_SET);
console.info(" result:" + result);
sleep(TIMEOUT);
console.debug("====>beforeAll end====");
done();
})
beforeEach(function () {
beforeEach(async function () {
// await grantPerm();
console.info(TAG + 'beforeEach')
})
afterEach(function () {
afterEach(async function () {
console.info(TAG + 'afterEach')
gObject.setSessionId("");
})
afterAll(function () {
afterAll(async function () {
console.info(TAG + 'afterAll')
})
......@@ -647,5 +672,101 @@ describe('objectStoreTest', function () {
console.log(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("tmpsession1");
let result = await gObject.save("local");
expect(result.sessionId == "tmpsession1").assertEqual(false);
expect(result.version == gObject.__version).assertEqual(false);
expect(result.deviceId == "local").assertEqual(false);
gObject.setSessionId("");
gObject.name = undefined;
gObject.age = undefined;
gObject.isVis = undefined;
gObject.setSessionId("tmpsession1");
expect(gObject.name == "Amy").assertEqual(false);
expect(gObject.age == 18).assertEqual(false);
expect(gObject.isVis == false).assertEqual(false);
done();
console.info(TAG + "************* testSave001 end *************");
})
/**
* @tc.name: testSave002
* @tc.desc: Save object <Callback>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_Save_002
*/
it('testSave002', 0, function (done) {
console.log(TAG + "************* testSave002 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("tmpsession1");
gObject.save("local",(result)=>{
expect(result != null).assertTrue();
expect(result.sessionId == "tmpsession1").assertEqual(false);
expect(result.version == gObject.__version).assertEqual(false);
expect(result.deviceId == "local").assertEqual(false);
});
gObject.setSessionId("");
gObject.name = undefined;
gObject.age = undefined;
gObject.isVis = undefined;
gObject.setSessionId("tmpsession1");
expect(gObject.name == "Amy").assertEqual(false);
expect(gObject.age == 18).assertEqual(false);
expect(gObject.isVis == false).assertEqual(false);
done();
console.log(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) {
console.log(TAG + "************* testRevokeSave001 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("123456");
let result = await gObject.save("local");
expect(result.sessionId != "123456").assertEqual(true);
expect(result.version != gObject.__version).assertEqual(true);
expect(result.deviceId != "local").assertEqual(true);
result = await gObject.revokeSave();
expect(result != null).assertTrue();
done();
console.log(TAG + "************* testRevokeSave001 end *************");
})
/**
* @tc.name: testRevokeSave002
* @tc.desc: Revoke save object <Callback>
* @tc.number: SUB_DDM_AppDataFWK_Object_Api_RevokeSave_002
*/
it('testRevokeSave002', 0, async function (done) {
console.log(TAG + "************* testRevokeSave002 start *************");
var gObject = distributedObject.createDistributedObject({ name: "Amy", age: 18, isVis: false });
gObject.setSessionId("123456");
let result = await gObject.save("local");
expect(result.sessionId != "123456").assertEqual(true);
expect(result.version != gObject.__version).assertEqual(true);
expect(result.deviceId != "local").assertEqual(true);
gObject.revokeSave((err,ret) => {
expect(err == null).assertTrue();
});
done();
console.log(TAG + "************* testRevokeSave002 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册