提交 63c5ad95 编写于 作者: L liangzhenyu123

<liangzhenyu6@huawei.com>

Signed-off-by: Nliangzhenyu123 <liangzhenyu6@huawei.com>
上级 09130093
......@@ -21,7 +21,7 @@ group("distributeddatamgr") {
"distributedKVStoretest:distributedKVStoretest",
"kvStoretest:kvStoretest",
"preferencesjstest/hap:preferences_js_test",
"relationalStorejstest/hap:relationalstore_js_test",
"relationalStoretest:relationalStoretest",
]
} else {
deps = [
......
......@@ -21,13 +21,18 @@ import storageHelperTest from './StorageHelperJsunit.test.js'
import storagePromiseTest from './StoragePromiseJsunit.test.js'
import storageSyncTest from './StorageSyncJsunit.test.js'
import systemStorageTest from './SystemStorageJsunit.test.js'
import preferencesV9CallbackTest from './V9_PreferencesCallBackJsunit.test.js'
import preferencesV9PromiseTest from './V9_PreferencesPromiseJsunit.test.js'
export default function testsuite() {
storageCallBackTest()
storageHelperTest()
storagePromiseTest()
storageSyncTest()
systemStorageTest()
preferencesCallBackTest()
preferencesHelperTest()
preferencesPromiseTest()
storageCallBackTest()
storageHelperTest()
storagePromiseTest()
storageSyncTest()
systemStorageTest()
preferencesCallBackTest()
preferencesHelperTest()
preferencesPromiseTest()
preferencesV9CallbackTest()
preferencesV9PromiseTest()
}
/*
* Copyright (c) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 data_preferences from '@ohos.data.preferences'
import featureAbility from '@ohos.ability.featureAbility'
const NAME = 'v9_test_preferences_callback'
const KEY_TEST_INT_ELEMENT = 'key_test_int'
const KEY_TEST_STRING_ELEMENT = 'key_test_string'
var mPreference = undefined
var context
export default function preferencesV9CallbackTest(){
describe('preferencesV9CallbackTest', async function () {
beforeAll(async function () {
console.info('beforeAll')
context = featureAbility.getContext()
mPreference = await data_preferences.getPreferences(context, NAME)
})
afterAll(async function () {
console.info('afterAll')
await data_preferences.deletePreferences(context, NAME)
})
/**
* @tc.name has、delete、get、flush String callback interface test
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0100
* @tc.desc flush String callback interface test
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0100', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0100 begin.")
try{
mPreference.clear(function (err, val) {
if(err){
console.log("clear err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
mPreference.put(KEY_TEST_STRING_ELEMENT, 'abc', function (err, ret) {
if(err){
console.log("put err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
mPreference.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) {
if(err){
console.log("get err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
expect('abc').assertEqual(pre)
mPreference.flush(function (err, val) {
if(err){
console.log("flush err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
data_preferences.removePreferencesFromCache(context, NAME,(err)=>{
if(err){
console.log("removePreferencesFromCache err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
mPreference.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre2) {
if(err){
console.log("get err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
expect('abc').assertEqual(pre2)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0100 end.")
})
})
})
})
})
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.get()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0200
* @tc.desc mPreference.get()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0200', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0200 begin.")
try {
mPreference.get(123, function (err, val) {
if (err) {
console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
expect(true).assertEqual(val)
})
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0200 end.")
}
})
/**
* @tc.name mPreference.get()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0300
* @tc.desc mPreference.get()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0300', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0300 begin.")
try {
mPreference.get(KEY_TEST_STRING_ELEMENT, KEY_TEST_INT_ELEMENT, function (err, val) {
if (err) {
console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
expect('abc').assertEqual(val)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0300 end.")
})
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.getAll()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0400
* @tc.desc mPreference.getAll()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0400', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0400 begin.")
try {
mPreference.getAll(function (err, val) {
if (err) {
console.log("getAll err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
console.log("getAll val = " + JSON.stringify(val))
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0400 end.")
})
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
done()
})
/**
* @tc.name mPreference.has()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0500
* @tc.desc mPreference.has()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0500', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0500 begin.")
try{
mPreference.has(123,function (err, val) {
console.log("has err")
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0500 end.")
}
})
/**
* @tc.name mPreference.has()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0600
* @tc.desc mPreference.has()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0600', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0600 begin.")
try{
mPreference.has(KEY_TEST_STRING_ELEMENT, function (err, val) {
if (err) {
console.log("has err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
expect(true).assertEqual(val)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0600 end.")
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.put()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0700
* @tc.desc mPreference.put()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0700', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0700 begin.")
try{
mPreference.put(123, function (err) {
console.log("put err")
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0700 end.")
}
})
/**
* @tc.name mPreference.put()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0800
* @tc.desc mPreference.put()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0800', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0800 begin.")
try{
mPreference.put(KEY_TEST_STRING_ELEMENT, KEY_TEST_INT_ELEMENT, function (err) {
if (err) {
console.log("put err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0800 end.")
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.delete()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_0900
* @tc.desc mPreference.delete()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_0900', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0900 begin.")
try{
mPreference.delete(1233, function(err) {
if (err) {
console.log("delete err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
console.log("delete err")
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_0900 end.")
}
})
/**
* @tc.name mPreference.delete()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1000
* @tc.desc mPreference.delete()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1000', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1000 begin.")
try{
mPreference.delete(KEY_TEST_STRING_ELEMENT, function(err) {
if (err) {
console.log("delete err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1000 end.")
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.clear()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1100
* @tc.desc mPreference.clear()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1100', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1100 begin.")
try{
mPreference.clear(function (err) {
if (err) {
console.log("clear err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1100 end.")
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.flush()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1200
* @tc.desc mPreference.flush()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1200', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1200 begin.")
try{
mPreference.flush(function (err) {
if (err) {
console.log("flush err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
done()
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1200 end.")
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.clear()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1300
* @tc.desc mPreference.clear()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1300', 0, async function () {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1300 begin.")
try {
mPreference.clear();
var observer = function (key) {
if (key) {
console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1300 key' + key);
expect(false).assertTrue()
}
expect("abcd").assertEqual(key);
};
await mPreference.on('change', observer);
await mPreference.put(KEY_TEST_STRING_ELEMENT, "abcd");
} catch (error) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.clear()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1400
* @tc.desc mPreference.clear()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1400', 0, async function () {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1400 begin.")
try {
var observer = function (key) {
if (key) {
console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1400 key' + key);
expect(false).assertTrue()
}
expect("abcd").assertEqual(key);
};
mPreference.clear();
await mPreference.on('sschange', observer);
await mPreference.put(KEY_TEST_STRING_ELEMENT, "abcd");
} catch (error) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
done()
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.on()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1500
* @tc.desc mPreference.on()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1500', 0, async function () {
try {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1500 begin.")
var observer = function (key) {
console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1500 key' + key);
expect('').assertEqual(key);
};
await mPreference.on('change', observer);
await mPreference.off('change', observer);
await mPreference.put(KEY_TEST_STRING_ELEMENT, "abc");
} catch (error) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.off()
* @tc.number SUB_DDM_JSPREFERENCEV9_CALLBACK_1600
* @tc.desc mPreference.off()
*/
it('SUB_DDM_JSPREFERENCEV9_CALLBACK_1600', 0, async function () {
try {
console.log("SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 begin.")
var observer = function (key) {
console.info('SUB_DDM_JSPREFERENCEV9_CALLBACK_1600 key' + key);
expect('').assertEqual(key);
};
await mPreference.on('change', observer);
await mPreference.off('123change', observer);
await mPreference.put(KEY_TEST_STRING_ELEMENT, "abc");
} catch (error) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
done()
expect(false).assertTrue()
}
})
})
}
\ No newline at end of file
/*
* Copyright (c) 2021 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 data_preferences from '@ohos.data.preferences'
import featureAbility from '@ohos.ability.featureAbility'
const NAME = 'v9_test_preferences_promise'
const KEY_TEST_INT_ELEMENT = 'key_test_int'
const KEY_TEST_STRING_ELEMENT = 'key_test_string'
var mPreference
var context
export default function preferencesV9PromiseTest(){
describe('preferencesV9PromiseTest', async function () {
beforeAll(async function () {
console.info('beforeAll')
context = featureAbility.getContext()
mPreference = await data_preferences.getPreferences(context, NAME)
})
afterAll(async function () {
console.info('afterAll')
await data_preferences.deletePreferences(context, NAME)
})
/**
* @tc.name has、delete、get、flush String callback interface test
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0100
* @tc.desc flush String callback interface test
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0100', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0100 begin.")
try{
if(mPreference== undefined) {
console.log("mPreference undefined")
expect(false).assertTrue()
}
mPreference.clear().then(()=>{
mPreference.put(KEY_TEST_STRING_ELEMENT, '123').then((ret)=>{
mPreference.get(KEY_TEST_STRING_ELEMENT, "defaultvalue").then((pre)=>{
expect('123').assertEqual(pre)
mPreference.flush().then(()=>{
data_preferences.removePreferencesFromCache(context, NAME).then(()=>{
mPreference.get(KEY_TEST_STRING_ELEMENT, "defaultvalue").then((pre2)=>{
expect('123').assertEqual(pre2)
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0100 end.")
}).catch((err) => {
console.log("get err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
}).catch((err) => {
console.log("removePreferencesFromCache err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
}).catch((err) => {
console.log("flush err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
}).catch((err) => {
console.log("get err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
}).catch((err) => {
console.log("put err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
}).catch((err) => {
console.log("clear err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.get()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0200
* @tc.desc mPreference.get()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0200', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0200 begin.")
try{
mPreference.get(1233).then((ret)=>{
console.log("get err")
expect(false).assertTrue()
}).catch((err) => {
console.log("get err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0200 end.")
}
})
/**
* @tc.name mPreference.get()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0300
* @tc.desc mPreference.get()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0300', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0300 begin.")
try{
mPreference.get(KEY_TEST_STRING_ELEMENT, KEY_TEST_INT_ELEMENT).then((ret)=>{
expect('123').assertEqual(ret)
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0300 end.")
}).catch((err) => {
console.log("get err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.getAll()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0400
* @tc.desc mPreference.getAll()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0400', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0400 begin.")
try {
mPreference.getAll().then((ret) => {
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0400 end.")
}).catch((err) => {
console.log("getAll err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
})
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.has()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0500
* @tc.desc mPreference.has()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0500', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0500 begin.")
try{
mPreference.has(123).then((val)=>{
console.log("has err")
expect(false).assertTrue()
}).catch((err) => {
console.log("has err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0500 end.")
}
})
/**
* @tc.name mPreference.has()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0600
* @tc.desc mPreference.has()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0600', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0600 begin.")
try{
mPreference.has(KEY_TEST_STRING_ELEMENT).then((val)=>{
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0600 end.")
}).catch((err) => {
console.log("has err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.put()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0700
* @tc.desc mPreference.put()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0700', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0700 begin.")
try{
mPreference.put(1233).then(()=>{
console.log("put err")
expect(false).assertTrue()
}).catch((err) => {
console.log("put err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0700 end.")
}
})
/**
* @tc.name mPreference.put()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0800
* @tc.desc mPreference.put()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0800', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0800 begin.")
try{
mPreference.put(KEY_TEST_STRING_ELEMENT, KEY_TEST_INT_ELEMENT).then(()=>{
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0800 end.")
}).catch((err) => {
console.log("put err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.delete()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0900
* @tc.desc fmPreference.delete()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_0900', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0900 begin.")
try{
mPreference.delete(1233).then(()=>{
console.log("delete err")
expect(false).assertTrue()
}).catch((err) => {
console.log("delete err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0900 end.")
}
})
/**
* @tc.name mPreference.delete()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_0100
* @tc.desc mPreference.delete()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1000', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1000 begin.")
try{
mPreference.delete(KEY_TEST_STRING_ELEMENT).then(()=>{
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_0500 end.")
}).catch((err) => {
console.log("delete err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.flush()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1100
* @tc.desc mPreference.flush()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1100', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1100 begin.")
try{
mPreference.clear().then(()=>{
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1100 end.")
}).catch((err) => {
console.log("clear err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
})
} catch(err) {
console.log("trycatch err =" + err + ", code =" + err.code +", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.flush()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1200
* @tc.desc mPreference.flush()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1200', 0, function (done) {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1200 begin.")
try {
mPreference.flush().then(() => {
done()
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1200 end.")
}).catch((err) => {
console.log("flush err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
})
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.on()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1300
* @tc.desc mPreference.on()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1300', 0, async function () {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1300 begin.")
await mPreference.clear();
try {
var observer = function (key) {
console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1300 key' + key);
expect('abc').assertEqual(key);
};
mPreference.on('change', observer);
mPreference.put(KEY_TEST_STRING_ELEMENT, "abc");
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.on()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1400
* @tc.desc mPreference.on()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1400', 0, async function () {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1400 begin.")
await mPreference.clear();
try {
var observer = function (key) {
console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1400 key' + key);
expect('abc').assertEqual(key);
};
mPreference.on('sschange', observer);
mPreference.put(KEY_TEST_STRING_ELEMENT, "abc");
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
done()
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.off()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1500
* @tc.desc mPreference.off()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1500', 0, async function () {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1500 begin.")
try {
var observer = function (key) {
console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1500 key' + key);
expect('').assertEqual(key);
};
mPreference.on('change', observer);
mPreference.off('change', observer);
mPreference.put(KEY_TEST_STRING_ELEMENT, "abc");
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
expect(false).assertTrue()
}
})
/**
* @tc.name mPreference.off()
* @tc.number SUB_DDM_JSPREFERENCEV9_PROMISE_1600
* @tc.desc mPreference.off()
*/
it('SUB_DDM_JSPREFERENCEV9_PROMISE_1600', 0, async function () {
console.log("SUB_DDM_JSPREFERENCEV9_PROMISE_1600 begin.")
try {
var observer = function (key) {
console.info('SUB_DDM_JSPREFERENCEV9_PROMISE_1600 key' + key);
expect('').assertEqual(key);
};
mPreference.on('change', observer);
mPreference.off('sschange', observer);
mPreference.put(KEY_TEST_STRING_ELEMENT, "abc");
} catch (err) {
console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message)
done()
expect(false).assertTrue()
}
})
})
}
\ No newline at end of file
# Copyright (c) 2022 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
group("relationalStoretest") {
testonly = true
if (is_standard_system) {
deps = [
"relationalStoreJstest/hap:relationalstore_js_test",
"relationalStoreStagetest:relationalstore_ets_test",
]
}
}
......@@ -16,7 +16,6 @@
"package": "ohos.acts.relationalStorejstest",
"name": ".entry",
"deviceType": [
"tablet",
"default",
"phone"
],
......
......@@ -26,19 +26,21 @@ import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js'
import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js'
import rdbstoreQueryTest from './RdbstoreQuery.test.js'
import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js'
import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js'
export default function testsuite() {
rdbStoreBackupRestoreCallbackTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreDeleteTest()
rdbStoreDistributedTest()
rdbstoreInsertTest()
rdbStorePredicatesJoinTest()
rdbPredicatesTest()
rdbStoreTest()
rdbResultSetTest()
rdbstoreStoreExcuteSqlTest()
rdbstoreTransactionTest()
rdbStoreUpdateTest()
rdbstoreQueryTest()
rdbStoreEncryptionTest()
rdbStoreBackupRestoreCallbackTest()
rdbStoreBackupRestoreWithFAContextTest()
rdbStoreDeleteTest()
rdbStoreDistributedTest()
rdbstoreInsertTest()
rdbStorePredicatesJoinTest()
rdbPredicatesTest()
rdbStoreTest()
rdbResultSetTest()
rdbstoreStoreExcuteSqlTest()
rdbstoreTransactionTest()
rdbStoreUpdateTest()
rdbstoreQueryTest()
rdbStoreEncryptionTest()
rdbStorePredicatesComplexFiledTest()
}
......@@ -318,16 +318,21 @@ describe('rdbStoreDistributedTest', function () {
*/
it('testRdbStoreDistributedCallback0011', 0, async function (done) {
console.info(TAG + "************* testRdbStoreDistributedCallback0011 start *************");
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
let predicates = new dataRdb.RdbPredicates("employee")
predicates = predicates.inDevices("12345678abcd");
rdbStore.sync(dataRdb.SyncMode.SYNC_MODE_PUSH, predicates,(err,ret)=>{
console.info(TAG + "sync push success");
expect(rdbStore).assertEqual(rdbStore);
rdbStore.sync(dataRdb.SyncMode.SYNC_MODE_PULL, predicates,(err,ret)=>{
console.info(TAG + "sync push success");
expect(rdbStore).assertEqual(rdbStore);
});
done();
});
rdbStore.sync(dataRdb.SyncMode.SYNC_MODE_PULL, predicates,(err,ret)=>{
console.info(TAG + "sync push success");
expect(rdbStore).assertEqual(rdbStore);
});
await sleep(2000)
done();
console.info(TAG + "************* testRdbStoreDistributedCallback0011 end *************");
})
......@@ -370,10 +375,16 @@ describe('rdbStoreDistributedTest', function () {
* @tc.desc obtainDistributedTableName test
*/
it('testRdbStoreDistributed0014', 0, async function (done){
await rdbStore.obtainDistributedTableName("deviceId", "EMPLOYEE", function (err, tableName) {
expect(err != null).assertTrue();
console.info('ObtainDistributedTableName failed, Unauthorized.' + err)
})
let errInfo = undefined;
try{
rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE", function (err, tableName) {
expect(err != null).assertTrue();
console.info('ObtainDistributedTableName failed, Unauthorized.' + err)
})
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
})
......@@ -388,14 +399,13 @@ describe('rdbStoreDistributedTest', function () {
"name": STORE_NAME,
}
rdbStore = await dataRdb.getRdbStore(config, 1);
let promise = rdbStore.obtainDistributedTableName("deviceId", "EMPLOYEE")
promise.then((tableName)=>{
expect(tableName != "EMPLOYEE").assertTrue();
console.info('ObtainDistributedTableName')
}).catch((err)=>{
expect(null).assertFail();
console.info('ObtainDistributedTableName failed, Unauthorized.' + err)
})
let errInfo = undefined
try{
rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE")
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
})
......
......@@ -1559,12 +1559,16 @@ describe('rdbResultSetTest', function () {
it('testIsColumnNull0003', 0, async function (done) {
console.info(TAG + '************* testIsColumnNull0003 start *************');
{
let errInfo = undefined;
let predicates = await new dataRdb.RdbPredicates('test')
let resultSet = await rdbStore.query(predicates)
{
try{
resultSet.goToRow(5)
expect(false).assertEqual(resultSet.isColumnNull(2))
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("14800012")
resultSet = null;
done();
console.info(TAG + '************* testIsColumnNull0003 end *************');
......@@ -1653,15 +1657,20 @@ describe('rdbResultSetTest', function () {
*/
it('testGetColumnIndex0004', 0, async function (done) {
console.info(TAG + '************* testGetColumnIndex0004 start *************');
{
let predicates = await new dataRdb.RdbPredicates('test')
let resultSet = await rdbStore.query(predicates)
expect(-1).assertEqual(resultSet.getColumnIndex(''))
resultSet = null;
done();
console.info(TAG + '************* testGetColumnIndex0004 end *************');
}
let errInfo = undefined;
let predicates = await new dataRdb.RdbPredicates('test')
let resultSet = await rdbStore.query(predicates)
try{
let resultSetresult = resultSet.getColumnIndex('')
expect(-1).assertEqual(resultSetresult)
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
resultSet = null;
done();
console.info(TAG + '************* testGetColumnIndex0004 end *************');
})
/**
......
......@@ -318,6 +318,7 @@ describe('rdbStoreDeleteTest', function () {
*/
it('testRdbStoreDelete0006', 0, async function (done) {
console.info(TAG + '************* testRdbStoreDelete0006 start *************');
let errInfo = undefined;
let u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
......@@ -347,7 +348,7 @@ describe('rdbStoreDeleteTest', function () {
await rdbStore.insert('test', valueBucket)
}
//删除
{
try{
let predicates = await new dataRdb.RdbPredicates('')
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
......@@ -356,7 +357,10 @@ describe('rdbStoreDeleteTest', function () {
}).catch((err) => {
console.info(TAG + 'delete with null')
})
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done()
console.info(TAG + '************* testRdbStoreDelete0006 end *************');
})
......
......@@ -157,6 +157,7 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStoreInsert0003', 0, async function (done) {
console.info(TAG + "************* testRdbStoreInsert0003 start *************");
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
{
const valueBucket = {
......@@ -165,14 +166,12 @@ describe('rdbstoreInsertTest', function () {
"salary": 100.5,
"blobType": u8,
}
let insertPromise = rdbStore.insert(null, valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret)
console.info(TAG + "insert first done: " + ret)
expect(null).assertFail()
}).catch((err) => {
console.info(TAG + "insert with null table")
})
try{
rdbStore.insert(null, valueBucket)
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
}
done()
console.info(TAG + "************* testRdbStoreInsert0003 end *************");
......@@ -576,6 +575,7 @@ describe('rdbstoreInsertTest', function () {
it('testRdbStorebatchInsertPromise0006', 0, async function (done) {
console.info(TAG + "************* testRdbStorebatchInsertPromise0006 start *************");
await rdbStore.executeSql(CREATE_TABLE_NAME + "6" + CREATE_TABLE)
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
const valueBucket1 = {
"name": "zhangsan",
......@@ -597,16 +597,12 @@ describe('rdbstoreInsertTest', function () {
}
const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]
try{
await rdbStore.batchInsert("test6","valueBuckets").then((number) => {
console.info(TAG + "Affect row is " + number)
expect(number).assertEqual(-1)
}).catch((err) =>{
expect(err == null).assertTrue();
})
await rdbStore.batchInsert("test6","valueBuckets")
}catch(err){
console.info(TAG + "Batch insert data error: " + err)
expect(null).assertFail();;
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done()
console.info(TAG + "************* testRdbStorebatchInsertPromise0006 end *************");
})
......@@ -618,18 +614,15 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStorebatchInsertPromise0007', 0, async function (done) {
console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************");
let errInfo = undefined;
await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE)
try{
await rdbStore.batchInsert("test7").then((number) => {
console.info(TAG + "BatchInsert without data,affect row number is " + number)
expect(number).assertEqual(0)
}).catch((err) =>{
expect(err == null).assertTrue();
})
await rdbStore.batchInsert("test7")
}catch(err){
console.info(TAG + "Batch insert data error: " + err)
expect(null).assertFail();
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done()
console.info(TAG + "************* testRdbStorebatchInsertPromise0007 end *************");
})
......@@ -1021,7 +1014,7 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStorebatchInsertCallback0006', 0, async function (done) {
console.info(TAG + "************* testRdbStorebatchInsertCallback0006 start *************");
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
const valueBucket1 = {
"name": "zhangsan",
......@@ -1054,10 +1047,10 @@ describe('rdbstoreInsertTest', function () {
})
}catch(err){
console.info(TAG + "Batch insert data error: " + err)
expect(null).assertFail();
errInfo = err
}
})
await sleep(2000)
expect(errInfo.code).assertEqual("401")
done()
console.info(TAG + "************* testRdbStorebatchInsertCallback0006 end *************");
})
......@@ -1070,22 +1063,24 @@ describe('rdbstoreInsertTest', function () {
*/
it('testRdbStorebatchInsertCallback0007', 0, async function (done) {
console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************");
let errInfo = undefined;
await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => {
await rdbStore.batchInsert("testCallback7", (err,data) => {
console.info(TAG + "Affect row is " + data)
if(err != null){
expect(null).assertFail();
}else{
expect(data).assertEqual(-1)
}
}).then((data) => {
console.info(TAG + "Batch insert fail ,affect row number is: " + data)
expect(data).assertEqual(-1)
})
try{
await rdbStore.batchInsert("testCallback7", (err,data) => {
console.info(TAG + "Affect row is " + data)
if(err != null){
expect(null).assertFail();
}else{
expect(data).assertEqual(-1)
}
})
}catch(err){
errInfo = err
}
}).catch((err) => {
expect(null).assertFail();
})
await sleep(2000)
expect(errInfo.code).assertEqual("401")
done()
console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************");
})
......
/*
* Copyright (C) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 dataRdb from '@ohos.data.rdb';
const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, " + "age INTEGER, " + "salary REAL, " + "adddate DATE)";
const STORE_CONFIG = {
name: "PredicatesComplexFiledJsunit.db",
}
var rdbStore = undefined;
export default function rdbStorePredicatesComplexFiledTest(){
describe('rdbStorePredicatesComplexFiledTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await generateTable();
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await dataRdb.deleteRdbStore("PredicatesComplexFiledJsunit.db");
})
async function generateTable() {
console.info(TAG + 'generateTable')
await rdbStore.executeSql(CREATE_TABLE_TEST);
const valueBucket1 = { id: 1, name: "ZhangSan", age: 20, salary: 100.51, adddate: '2022-09-01' }
await rdbStore.insert("test", valueBucket1)
const valueBucket2 = { id: 2, name: "LiSi", age: 21, salary: 120.61, adddate: '2022-09-01' }
await rdbStore.insert("test", valueBucket2)
const valueBucket3 = { id: 3, name: "WangWu", age: 22, salary: 130.71, adddate: '2022-09-02' }
await rdbStore.insert("test", valueBucket3)
const valueBucket4 = { id: 4, name: "SunLiu", age: 23, salary: 160.81, adddate: '2022-09-02' }
await rdbStore.insert("test", valueBucket4)
const valueBucket5 = { id: 5, name: "MaQi", age: 24, salary: 170.91, adddate: '2022-09-02' }
await rdbStore.insert("test", valueBucket5)
console.info(TAG + 'generateTable end')
}
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0001
* @tc.desc resultSet Update test
*/
it('SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0001', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0001 start *************");
let predicates = await new dataRdb.RdbPredicates("test")
predicates.groupBy(["DATE(test.adddate,'utc')"]).orderByAsc("COUNT(*)")
let resultSet = await rdbStore.query(predicates, ["COUNT(*) AS 'num Count'", "DATE(test.adddate,'utc') as birthday"])
expect(true).assertEqual(resultSet.goToFirstRow())
let count = await resultSet.getLong(resultSet.getColumnIndex("num Count"))
let birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(2).assertEqual(count);
await expect("2022-09-01").assertEqual(birthday)
expect(true).assertEqual(resultSet.goToNextRow())
count = await resultSet.getLong(resultSet.getColumnIndex("num Count"))
birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(3).assertEqual(count);
await expect("2022-09-02").assertEqual(birthday)
expect(false).assertEqual(resultSet.goToNextRow())
done();
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0001 end *************");
})
/**
* @tc.name resultSet Update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0002
* @tc.desc resultSet Update test
*/
it('SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0002', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0002 start *************");
let predicates = await new dataRdb.RdbPredicates("test")
predicates.groupBy(["DATE(test.adddate,'utc')"]).orderByDesc("COUNT(*)")
let resultSet = await rdbStore.query(predicates, ["COUNT(*) AS numCount", "DATE(test.adddate,'utc') as birthday"])
expect(true).assertEqual(resultSet.goToFirstRow())
let count = await resultSet.getLong(resultSet.getColumnIndex("numCount"))
let birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(3).assertEqual(count);
await expect("2022-09-02").assertEqual(birthday)
expect(true).assertEqual(resultSet.goToNextRow())
count = await resultSet.getLong(resultSet.getColumnIndex("numCount"))
birthday = await resultSet.getString(resultSet.getColumnIndex("birthday"))
expect(2).assertEqual(count);
await expect("2022-09-01").assertEqual(birthday)
expect(false).assertEqual(resultSet.goToNextRow())
done();
console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Predicates_ComplexFiled_0002 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
......@@ -2179,11 +2179,16 @@ describe('rdbPredicatesTest', function () {
*/
it('testIndexedBy0001', 0, async function (done) {
console.info(TAG + "************* testIndexedBy0001 start *************");
let predicates = await new dataRdb.RdbPredicates("AllDataType");
predicates.like("stringValue", "ABCDEFGHIJKLMN").indexedBy(["characterValue"]);
let result = await rdbStore.query(predicates);
expect(3).assertEqual(result.rowCount);
result = null
let errInfo = undefined
try{
let predicates = await new dataRdb.RdbPredicates("AllDataType");
predicates.like("stringValue", "ABCDEFGHIJKLMN").indexedBy(["characterValue"]);
let result = await rdbStore.query(predicates);
expect(3).assertEqual(result.rowCount);
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
console.info(TAG + "************* testIndexedBy0001 end *************");
})
......@@ -2195,11 +2200,16 @@ describe('rdbPredicatesTest', function () {
*/
it('testIndexedBy0002', 0, async function (done) {
console.info(TAG + "************* testIndexedBy0002 start *************");
let predicates = await new dataRdb.RdbPredicates("AllDataType");
predicates.like("stringValue", "ABCDEFGHIJKLMN").indexedBy(["characterValueX"]);
let result = await rdbStore.query(predicates);
expect(3).assertEqual(result.rowCount);
result = null
let errInfo = undefined
try{
let predicates = await new dataRdb.RdbPredicates("AllDataType");
predicates.like("stringValue", "ABCDEFGHIJKLMN").indexedBy(["characterValueX"]);
let result = await rdbStore.query(predicates);
expect(3).assertEqual(result.rowCount);
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
console.info(TAG + "************* testIndexedBy0002 end *************");
})
......
......@@ -155,16 +155,15 @@ export default function rdbstoreQueryTest(){
*/
it('RdbRemoteQueryPromiseTest0010', 0, async function (done){
console.info(TAG + "RdbRemoteQueryPromiseTest0010 start")
let errInfo = undefined
let predicates = new dataRdb.RdbPredicates("test");
predicates.equalTo("name", "zhangsan")
await rdbStore.remoteQuery(localDeviceId,"test",predicates,["name","age","salary"]).then( (resultSet) => {
console.info(TAG + "Remote query success")
expect(false).assertTrue();
}).catch((err) => {
console.info(TAG + "Remote query error: " + err)
expect(true).assertTrue();
})
try{
rdbStore.remoteQuery(localDeviceId,"test",predicates,["name","age","salary"])
}catch(err){
errInfo = err
}
expect(errInfo.code).assertEqual("401")
done();
console.info(TAG + "RdbRemoteQueryPromiseTest0010 end")
})
......
......@@ -128,8 +128,7 @@ describe('rdbStoreTest', function () {
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
let deletePromise = dataRdb.deleteRdbStore("rdbstore.db")
deletePromise.then(()=>{
await dataRdb.deleteRdbStore("rdbstore.db").then(()=>{
console.info(TAG + "deleteRdbStore promise done" + store);
expect(true).assertTrue();
})
......
......@@ -64,7 +64,7 @@ describe('rdbStoreUpdateTest', function () {
let insertPromise = rdbStore.insert("test", valueBucket)
insertPromise.then(async (ret) => {
expect(1).assertEqual(ret);
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
}).catch((err) => {
expect(null).assertFail();
})
......@@ -83,8 +83,8 @@ describe('rdbStoreUpdateTest', function () {
predicates.equalTo("id", "1")
let updatePromise = rdbStore.update(valueBucket, predicates)
await updatePromise.then(async (ret) => {
await expect(1).assertEqual(ret);
await console.info(TAG + "update done: " + ret);
expect(1).assertEqual(ret);
console.info(TAG + "update done: " + ret);
let resultSet = await rdbStore.query(predicates)
expect(true).assertEqual(resultSet.goToFirstRow())
......@@ -122,7 +122,8 @@ describe('rdbStoreUpdateTest', function () {
it('testRdbStoreUpdate0002', 0, async function (done) {
console.info(TAG + "************* testRdbStoreUpdate0002 start *************");
//更新
{
{
let errInfo = undefined;
var u8 = new Uint8Array([1, 2, 3])
const valueBucket = {
"name": "zhangsan",
......@@ -130,22 +131,24 @@ describe('rdbStoreUpdateTest', function () {
"salary": 100.5,
"blobType": u8,
}
{
try{
let predicates = new dataRdb.RdbPredicates("")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with null table name");
})
}catch(err){
errInfo = err
}
{
const emptyBucket = {};
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(emptyBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong valueBucket");
......@@ -156,12 +159,13 @@ describe('rdbStoreUpdateTest', function () {
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
})
}
expect(errInfo.code).assertEqual("401")
}
done();
console.info(TAG + "************* testRdbStoreUpdate0002 end *************");
......@@ -188,7 +192,7 @@ describe('rdbStoreUpdateTest', function () {
let predicates = new dataRdb.RdbPredicates("wrongTable")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong table name");
......@@ -199,7 +203,7 @@ describe('rdbStoreUpdateTest', function () {
let predicates = await new dataRdb.RdbPredicates("test")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong column name");
......@@ -232,7 +236,7 @@ describe('rdbStoreUpdateTest', function () {
await predicates.equalTo("aaa", "null")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
......@@ -247,7 +251,7 @@ describe('rdbStoreUpdateTest', function () {
await predicates.equalTo("null", 100.5)
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await console.info(TAG + "update done: " + ret);
console.info(TAG + "update done: " + ret);
expect(null).assertFail();
}).catch((err) => {
console.info(TAG + "update with wrong condition");
......
{
"app": {
"bundleName": "ohos.acts.RelationalStoreStage",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name",
"debug": false,
"distributedNotificationEnabled": true,
"keepAlive": true,
"singleUser": true,
"minAPIVersion": 9,
"targetAPIVersion": 9,
"car": {
"apiCompatibleVersion": 9,
"singleUser": false
}
}
}
# Copyright (c) 2022 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("relationalstore_ets_test") {
hap_profile = "entry/src/main/module.json"
js_build_mode = "debug"
deps = [
":relationalStoreStage_js_assets",
":relationalStoreStage_resources",
]
ets2abc = true
certificate_profile = "signature/openharmony_sx.p7b"
hap_name = "ActsRelationalStoreStageTest"
subsystem_name = "distributeddatamgr"
part_name = "relational_store"
}
ohos_app_scope("relationalStoreStage_app_profile") {
app_profile = "AppScope/app.json"
sources = [ "AppScope/resources" ]
}
ohos_js_assets("relationalStoreStage_js_assets") {
source_dir = "entry/src/main/ets"
}
ohos_resources("relationalStoreStage_resources") {
sources = [ "entry/src/main/resources" ]
deps = [ ":relationalStoreStage_app_profile" ]
hap_profile = "entry/src/main/module.json"
}
{
"description": "Configuration for hjunit demo Tests",
"driver": {
"type": "OHJSUnitTest",
"test-timeout": "180000",
"bundle-name": "ohos.acts.RelationalStoreStage",
"module-name": "entry",
"shell-timeout": "600000",
"testcase-timeout": 70000
},
"kits": [{
"test-file-name": [
"ActsRelationalStoreStageTest.hap"
],
"type": "AppInstallKit",
"cleanup-apps": true
}]
}
\ No newline at end of file
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import AbilityStage from "@ohos.application.AbilityStage"
export default class MyAbilityStage extends AbilityStage {
onCreate() {
console.log("[Demo] MyAbilityStage onCreate")
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
import dataShare from '@ohos.data.dataShare'
import rpc from "@ohos.rpc";
var seConnect = {
onConnect:function (elementName, proxy) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect called.");
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect elementName = " + elementName);
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect proxy = " + proxy);
let data = rpc.MessageParcel.create();
let reply = rpc.MessageParcel.create();
let option = new rpc.MessageOption();
data.writeInterfaceToken("connect-test");
data.writeInt(111);
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onConnect sendRequest.");
proxy.sendRequest(1, data, reply, option)
.then(function (result) {
if (result.errCode === 0) {
// let msg = reply.readString();
let msg = result.reply.readInt();
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect reply msg: " + msg);
} else {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest failed, errCode: " + result.errCode);
}
// callback没有返回值,默认返回undefined
}).catch(function (e) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest got exception: " + e);
}).finally (async () => {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect sendRequest ends, reclaim parcel");
data.reclaim();
reply.reclaim();
})
},
onDisconnect:function (elementName) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onDisconnect");
},
onFailed:function (code) {
console.log("[ttt] [DataShareTest] <<Consumer>> seConnect onFailed");
}
};
let dseProxy = 0;
let dseUri = ("datashare:///com.samples.datasharekvtest.DataShare");
var dseConnect = {
onConnect:function (elementName, proxy) {
console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect called.");
// console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect elementName = " + elementName);
// console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onConnect proxy = " + proxy);
dseProxy = proxy;
},
onDisconnect:function (elementName) {
console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onDisconnect, elementName:" + elementName);
},
onFailed:function (code) {
console.log("[ttt] [DataShareTest] <<Consumer>> dseConnect onFailed, code:" + code);
}
};
let seConnectionId = -1;
let dseConnectionId = -1;
let seWant = {
"bundleName": "com.samples.datasharetest",
"abilityName": "ServiceExtAbility",
}
let dseWant = {
"bundleName": "com.samples.datasharetest",
"abilityName": "DataShareExtAbility",
}
export function onCallback() {
console.info("[ttt] [DataShareTest] <<Consumer>> **** Observer on callback ****");
}
export function offCallback() {
console.info("[ttt] [DataShareTest] <<Consumer>> **** Observer off callback ****");
}
export default class MainAbility extends Ability {
onCreate(want, launchParam) {
// Ability is creating, initialize resources for this ability
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onCreate")
globalThis.abilityWant = want;
}
onDestroy() {
// Ability is destroying, release resources for this ability
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onDestroy")
}
onWindowStageCreate(windowStage) {
// Main window is created, set main page for this ability
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageCreate")
globalThis.abilityContext = this.context;
let context = this.context;
dseConnectionId = context.connectAbility(dseWant, dseConnect);
globalThis.connectDataShareExtAbility = (async () => {
console.log("[ttt] [DataShareTest] <<Consumer>> connectDataShareExtAbility begin");
await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{
globalThis.helper = data;
globalThis.testhelper = data;
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 1 -----, globalThis.helper = " + globalThis.helper);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 2 -----, data = " + data);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 3 -----, err = " + err);
console.info("[ttt] [DataShareTest] <<Consumer>> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err));
});
dseConnectionId = await context.connectAbility(dseWant, dseConnect);
})
windowStage.setUIContent(this.context, "MainAbility/pages/index", null)
}
onWindowStageDestroy() {
// Main window is destroyed, release UI related resources
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onWindowStageDestroy")
}
onForeground() {
// Ability has brought to foreground
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onForeground")
}
onBackground() {
// Ability has back to background
console.log("[ttt] [DataShareTest] <<Consumer>> MainAbility onBackground")
}
};
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import file from '@system.file';
import router from '@ohos.router';
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
import { Hypium } from '@ohos/hypium'
import testsuite from '../../test/List.test'
//InstrumentLog, ReportExtend
@Entry
@Component
struct Index {
aboutToAppear(){
console.info("start run testcase!!!!")
var abilityDelegator: any
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var abilityDelegatorArguments: any
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
console.info('start run testcase!!!')
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
}
build() {
Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Text('Hello World')
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(25)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.onClick(() => {
})
}
.width('100%')
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import Ability from '@ohos.application.Ability'
export default class TestAbility extends Ability {
onCreate(want, launchParam) {
console.log('TestAbility onCreate')
}
onDestroy() {
console.log('TestAbility onDestroy')
}
onWindowStageCreate(windowStage) {
console.log('TestAbility onWindowStageCreate')
windowStage.loadContent("TestAbility/pages/index", (err, data) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content. Data: ' + JSON.stringify(data))
});
globalThis.abilityContext = this.context;
}
onWindowStageDestroy() {
console.log('TestAbility onWindowStageDestroy')
}
onForeground() {
console.log('TestAbility onForeground')
}
onBackground() {
console.log('TestAbility onBackground')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import router from '@ohos.router';
@Entry
@Component
struct Index {
aboutToAppear() {
console.info('TestAbility index aboutToAppear')
}
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
.onClick(()=>{
})
}
.width('100%')
}
.height('100%')
}
}
\ No newline at end of file
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import TestRunner from '@ohos.application.testRunner'
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'
var abilityDelegator = undefined
var abilityDelegatorArguments = undefined
function translateParamsToString(parameters) {
const keySet = new Set([
'-s class', '-s notClass', '-s suite', '-s it',
'-s level', '-s testType', '-s size', '-s timeout',
'-s dryRun'
])
let targetParams = '';
for (const key in parameters) {
if (keySet.has(key)) {
targetParams = `${targetParams} ${key} ${parameters[key]}`
}
}
return targetParams.trim()
}
async function onAbilityCreateCallback() {
console.log("onAbilityCreateCallback");
}
async function addAbilityMonitorCallback(err: any) {
console.info("addAbilityMonitorCallback : " + JSON.stringify(err))
}
export default class OpenHarmonyTestRunner implements TestRunner {
constructor() {
}
onPrepare() {
console.info("OpenHarmonyTestRunner OnPrepare ")
}
async onRun() {
console.log('OpenHarmonyTestRunner onRun run')
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
var testAbilityName = abilityDelegatorArguments.bundleName + '.MainAbility'
let lMonitor = {
abilityName: testAbilityName,
onAbilityCreate: onAbilityCreateCallback,
};
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
var cmd = 'aa start -d 0 -a ohos.acts.RelationalStoreStage.MainAbility' + ' -b ' + abilityDelegatorArguments.bundleName
cmd += ' '+translateParamsToString(abilityDelegatorArguments.parameters)
var debug = abilityDelegatorArguments.parameters["-D"]
if (debug == 'true')
{
cmd += ' -D'
}
console.info('cmd : '+cmd)
abilityDelegator.executeShellCommand(cmd,
(err: any, d: any) => {
console.info('executeShellCommand : err : ' + JSON.stringify(err));
console.info('executeShellCommand : data : ' + d.stdResult);
console.info('executeShellCommand : data : ' + d.exitCode);
})
console.info('OpenHarmonyTestRunner onRun end')
}
};
\ No newline at end of file
/*
* Copyright (c) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import rdbStoreV9Test from './RdbstoreRdbstoreV9.test.ets'
export default function testsuite() {
rdbStoreV9Test(globalThis.abilityContext);
}
\ No newline at end of file
/*
* Copyright (C) 2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 dataRdb from '@ohos.data.rdb';
const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
export default function rdbStoreV9Test(context){
describe('rdbStoreV9Test', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll')
})
beforeEach(function () {
console.info(TAG + 'beforeEach')
})
afterEach(function () {
console.info(TAG + 'afterEach')
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S1
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0100
* @tc.desc rdb store getRdbStoreV9 with securityLevel S1
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0100 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S1
}
let storePromise = dataRdb.getRdbStoreV9(context, config, 1);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (err) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0100 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S2
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0200
* @tc.desc rdb store getRdbStoreV9 with securityLevel S2
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0200', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0200 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S2
}
let storePromise = dataRdb.getRdbStoreV9(context, config, 1);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (err) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0200 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S3
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0300
* @tc.desc rdb store getRdbStoreV9 with securityLevel S3
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0300', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0300 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S3
}
let storePromise = dataRdb.getRdbStoreV9(context, config, 1);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (err) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0300 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S4
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0400
* @tc.desc rdb store getRdbStoreV9 with securityLevel S4
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0400', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0400 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S4
}
let storePromise = dataRdb.getRdbStoreV9(context, config, 1);
storePromise.then(async (store) => {
try {
await store.executeSql(CREATE_TABLE_TEST);
} catch (err) {
expect(null).assertFail();
}
}).catch((err) => {
expect(null).assertFail();
})
await storePromise
storePromise = null
await dataRdb.deleteRdbStore(context,"secure.db");
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_PROMISE_0400 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S1
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0100
* @tc.desc rdb store getRdbStoreV9 with securityLevel S1
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0100', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0100 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S1
}
dataRdb.getRdbStoreV9(context, config, 1, async (err,data) => {
if(err != null){
console.info(TAG + "get rdb store error" + err.message)
expect(null).assertFail();
}else{
console.info(TAG + "create table success")
}
done();
});
await dataRdb.deleteRdbStore(context,"secure.db");
await sleep(1000)
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0100 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S2
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0200
* @tc.desc rdb store getRdbStoreV9 with securityLevel S2
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0200', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0200 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S2
}
dataRdb.getRdbStoreV9(context, config, 1,async (err,data) => {
if(err != null){
console.info(TAG + "get rdb store error")
expect(null).assertFail();
}else{
console.info(TAG + "create table success")
}
done();
});
await dataRdb.deleteRdbStore(context,"secure.db");
await sleep(1000)
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0200 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S3
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0300
* @tc.desc rdb store getRdbStoreV9 with securityLevel S3
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0300', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0300 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S3
}
dataRdb.getRdbStoreV9(context, config, 1,async (err,data) => {
if(err != null){
console.info(TAG + "get rdb store error")
expect(null).assertFail();
}else{
console.info(TAG + "create table success")
}
done();
});
await dataRdb.deleteRdbStore(context,"secure.db");
await sleep(1000)
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0300 end *************");
})
/**
* @tc.name rdb store getRdbStoreV9 with securityLevel S4
* @tc.number SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0400
* @tc.desc rdb store getRdbStoreV9 with securityLevel S4
* @tc.require: I5PIL6
*/
it('SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0400', 0, async function (done) {
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0400 start *************");
let config = {
name: "secure.db",
securityLevel: dataRdb.SecurityLevel.S4
}
dataRdb.getRdbStoreV9(context, config, 1,async (err,data) => {
if(err != null){
console.info(TAG + "get rdb store error")
expect(null).assertFail();
}else{
console.info(TAG + "create table success")
}
done();
});
await dataRdb.deleteRdbStore(context,"secure.db");
await sleep(1000)
done();
console.log(TAG + "************* SUB_DDM_RELATIONALETS_GETRDBSTOREV9_CALLBACK_0400 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
}
\ No newline at end of file
{
"module": {
"package": "ohos.acts.RelationalStoreStage",
"name": "entry",
"mainAbility": "ohos.acts.RelationalStoreStage.MainAbility",
"type": "entry",
"srcEntrance": "./ets/Application/AbilityStage.ts",
"description": "$string:entry_desc",
"mainElement": "MainAbility",
"deviceTypes": [
"default",
"phone"
],
"deliveryWithInstall": true,
"installationFree": false,
"pages": "$profile:main_pages",
"uiSyntax": "ets",
"abilities": [
{
"name": "ohos.acts.RelationalStoreStage.MainAbility",
"srcEntrance": "./ets/MainAbility/MainAbility.ts",
"description": "$string:MainAbility_desc",
"icon": "$media:icon",
"label": "$string:MainAbility_label",
"visible": true,
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"action.system.home"
]
}
]
}
]
}
}
{
"string": [
{
"name": "entry_desc",
"value": "description"
},
{
"name": "MainAbility_desc",
"value": "description"
},
{
"name": "MainAbility_label",
"value": "ActsRelationalStoreStageTest"
}
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册