diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn index dfbe9f096a508a1a47bf1aa0690355f43a725efc..7d5950cf18d29afbc58b584b1104fd3cbbf1da94 100644 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -21,7 +21,7 @@ group("distributeddatamgr") { "distributedKVStoretest:distributedKVStoretest", "kvStoretest:kvStoretest", "preferencesjstest/hap:preferences_js_test", - "relationalStorejstest/hap:relationalstore_js_test", + "relationalStoretest:relationalStoretest", ] } else { deps = [ diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js index e8089a3215d03b75a9413aaef7fde787ca1b8844..ac1ff838326d0432430addb4579d73a26a026515 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/List.test.js @@ -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() } diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..7285535249eaa9faf926d2960831ef4bc4b6360e --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesCallBackJsunit.test.js @@ -0,0 +1,424 @@ +/* +* 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 diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..8aef1cc331ac4a03fd930edd373ada5fd48d7352 --- /dev/null +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/V9_PreferencesPromiseJsunit.test.js @@ -0,0 +1,410 @@ +/* +* 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 diff --git a/distributeddatamgr/relationalStoretest/BUILD.gn b/distributeddatamgr/relationalStoretest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..50227449221655df6c85166ab6c1ced1be1e71a9 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/BUILD.gn @@ -0,0 +1,24 @@ +# 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", + ] + } +} diff --git a/distributeddatamgr/relationalStorejstest/hap/BUILD.gn b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/BUILD.gn similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/BUILD.gn rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/BUILD.gn diff --git a/distributeddatamgr/relationalStorejstest/hap/Test.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/Test.json similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/Test.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/Test.json diff --git a/distributeddatamgr/relationalStorejstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/signature/openharmony_sx.p7b similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/signature/openharmony_sx.p7b rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/signature/openharmony_sx.p7b diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/config.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json similarity index 96% rename from distributeddatamgr/relationalStorejstest/hap/src/main/config.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json index 81053ee05cb265d4b0510e18f1538de0a1c5d3c4..fb0d2a61e2e525916b73c669fbcddcb5e12bf33c 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/config.json +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json @@ -16,7 +16,6 @@ "package": "ohos.acts.relationalStorejstest", "name": ".entry", "deviceType": [ - "tablet", "default", "phone" ], diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/app.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/app.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/app.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/app.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/i18n/en-US.json similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/en-US.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/i18n/en-US.json diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/i18n/zh-CN.json similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/i18n/zh-CN.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/i18n/zh-CN.json diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.css b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/pages/index/index.css similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.css rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/pages/index/index.css diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.hml b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/pages/index/index.hml similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.hml rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/pages/index/index.hml diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/pages/index/index.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/MainAbility/pages/index/index.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/MainAbility/pages/index/index.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/app.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/app.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/app.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/app.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/i18n/en-US.json similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/en-US.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/i18n/en-US.json diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/i18n/zh-CN.json similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/i18n/zh-CN.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/i18n/zh-CN.json diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.css b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/pages/index/index.css similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.css rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/pages/index/index.css diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/pages/index/index.hml similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.hml rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/pages/index/index.hml diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/pages/index/index.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestAbility/pages/index/index.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestAbility/pages/index/index.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js similarity index 73% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js index 61373f602c9eacc4eae87c1676dcd2853815cfca..84bcde52bf21fa6139556987a94939085268059f 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/List.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js @@ -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() } diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js similarity index 91% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js index f5fbdf19e02d5c73366f449a63f1ddbdb4f68c71..93869bd40cb409e938f041365dfb8f88d211c3f6 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js @@ -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(); }) diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js similarity index 96% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js index a2fb7c9ae923be1607f7dd60149312f2e44fb078..aa046d7d8f767c8db89b90e936c6c30005adfda6 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js @@ -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 *************'); + }) /** diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js similarity index 95% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js index b0fb0b1445b0606da2ebbe7e9f2870fb096c8801..cce17236f369a1e4d048d9201cb65dc84d0d5ffb 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js @@ -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 *************'); }) diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js similarity index 94% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js index 4ab5bfe4442bd7779630c4912f4f009b3f055820..440dab92cc93ead9dd569b0b36052d65d939572c 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js @@ -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 *************"); }) diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9c12d9912088aa982ecf17bc2a9bae639b33dd82 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js @@ -0,0 +1,116 @@ +/* + * 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 diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js similarity index 96% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js index 2fbd64d9eafb299e93d4835d49c83df7a1ad39df..e51ea56960a14913587fc4a115a63dd307d20223 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js @@ -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 *************"); }) diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreQuery.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreQuery.test.js similarity index 94% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreQuery.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreQuery.test.js index d1833a2cf6cb03cf63c872d4044fe42dbf98cdce..e009cee5901bc3db85edec5d663d19ec852e0506 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreQuery.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreQuery.test.js @@ -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") }) diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js similarity index 96% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js index 53c88719c4d5be8305618b3e38fe1d8ac39916d0..7237375d6c604b61384498ef4a2a962c8b34ca75 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js @@ -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(); }) diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js similarity index 90% rename from distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js index 039db4739df5a6f303e017b39f3a1c210915e026..07a2387339d39f4a7af0d73c356a4cba1879dad7 100644 --- a/distributeddatamgr/relationalStorejstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js @@ -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"); diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/resources/base/element/string.json similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/element/string.json rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/resources/base/element/string.json diff --git a/distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/resources/base/media/icon.png similarity index 100% rename from distributeddatamgr/relationalStorejstest/hap/src/main/resources/base/media/icon.png rename to distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/resources/base/media/icon.png diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/app.json b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..e15d878211ac47cafc47f8b7026f0c25bcdbff36 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "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 + } + } +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/resources/base/element/string.json b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..743eebb13dba6bf565857756006a7c13bd8e7299 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication2" + } + ] +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/BUILD.gn b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..33206b783d9213bca5e1f24c53951a253fda6adf --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/BUILD.gn @@ -0,0 +1,43 @@ +# 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" +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/Test.json b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..c223a653f4ba3876a47cdca728666687822c0b47 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/Test.json @@ -0,0 +1,18 @@ +{ + "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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..02ecba3c3e620207210edec3de91aa7191f6e8c7 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* +* 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..cc6fdc5ef88488efe7bb9715a0c385c4bc32ffd0 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,144 @@ +/* +* 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] <> seConnect onConnect called."); + console.log("[ttt] [DataShareTest] <> seConnect onConnect elementName = " + elementName); + console.log("[ttt] [DataShareTest] <> 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] <> 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] <> seConnect reply msg: " + msg); + } else { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest failed, errCode: " + result.errCode); + } + // callback没有返回值,默认返回undefined + }).catch(function (e) { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest got exception: " + e); + }).finally (async () => { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest ends, reclaim parcel"); + data.reclaim(); + reply.reclaim(); + }) + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> seConnect onDisconnect"); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> seConnect onFailed"); + } +}; + +let dseProxy = 0; +let dseUri = ("datashare:///com.samples.datasharekvtest.DataShare"); + +var dseConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> dseConnect onConnect called."); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect elementName = " + elementName); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect proxy = " + proxy); + dseProxy = proxy; + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> dseConnect onDisconnect, elementName:" + elementName); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> 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] <> **** Observer on callback ****"); +} + +export function offCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer off callback ****"); +} + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + let context = this.context; + dseConnectionId = context.connectAbility(dseWant, dseConnect); + globalThis.connectDataShareExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> connectDataShareExtAbility begin"); + await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{ + globalThis.helper = data; + globalThis.testhelper = data; + console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.helper = " + globalThis.helper); + console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); + console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); + console.info("[ttt] [DataShareTest] <> ----- 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] <> MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[ttt] [DataShareTest] <> MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[ttt] [DataShareTest] <> MainAbility onBackground") + } +}; diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/MainAbility/pages/index.ets b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..3ee1f46bd035e2a8b9f73a81190bbd1985284185 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,58 @@ +/* +* 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestAbility/TestAbility.ts b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestAbility/TestAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..89a84730505783ba229175ab4b55d37f91a16266 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestAbility/TestAbility.ts @@ -0,0 +1,50 @@ +/* + * 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestAbility/pages/index.ets b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..b93567f962921124b282f78c8ef123965d1460c9 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestAbility/pages/index.ets @@ -0,0 +1,48 @@ +/* + * 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..4da4f3e56057db2757c9d9f9d83e8cfbdaa0e9ae --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,78 @@ +/* + * 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/List.test.ets b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..150321d7dc6d9287b37f1b977faeaf642e406cca --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/List.test.ets @@ -0,0 +1,18 @@ +/* + * 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/RdbstoreRdbstoreV9.test.ets b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/RdbstoreRdbstoreV9.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..12dd79f40a917cf75e4f0f1e055b01cf65d88762 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/RdbstoreRdbstoreV9.test.ets @@ -0,0 +1,271 @@ +/* + * 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 diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/module.json b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..85be88d3637ebecf9c74766ea7ea7f49c6b837f6 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/module.json @@ -0,0 +1,39 @@ +{ + "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" + ] + } + ] + } + ] + } +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/element/string.json b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..4a8df98b26f68ba98dc7e84b6d16df2ef981dd1e --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ActsRelationalStoreStageTest" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..c1858c216308ad312862a877139a8ba6908ec3c6 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "MainAbility/pages/index" + ] +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/signature/openharmony_sx.p7b b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/signature/openharmony_sx.p7b differ