From 4783e082846e6b6f1fb037c28ea3eabba13b30ce Mon Sep 17 00:00:00 2001 From: yanglifeng1217 Date: Tue, 25 Jul 2023 12:09:03 +0800 Subject: [PATCH] Signed-off-by: yanglifeng1217 --- distributeddatamgr/BUILD.gn | 2 +- .../preferencesDataGroupIdCallback.test.ets | 18 ++-- .../preferencesDataGroupIdPromise.test.ets | 12 +-- .../js/test/PreferencesSyncJsunit.test.js | 26 ++++++ .../entry/src/main/ets/test/List.test.ets | 5 +- .../ets/test/relationalStoreEmit.test.ets | 92 +++++++++++++++++++ ...elationalStoreDataGroupIdCallback.test.ets | 12 +-- ...relationalStoreDataGroupIdPromise.test.ets | 8 +- 8 files changed, 148 insertions(+), 27 deletions(-) create mode 100644 distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEmit.test.ets diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn index 5fd17ee49..3ee5e3909 100644 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -23,10 +23,10 @@ group("distributeddatamgr") { "dataSharejstest/hap:dataShare_js_test", "distributedKVStoretest:distributedKVStoretest", "kvStoretest:kvStoretest", + "preferencesdatagroupidtest:ActsPreferencesDataGroupIdTest", "preferencesjstest/hap:preferences_js_test", "relationalStoretest:relationalStoretest", "relationalstoredatagroupidtest:ActsRelationalstoreDataGroupIdTest", - "preferencesdatagroupidtest:ActsPreferencesDataGroupIdTest", ] } else { deps = [ diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets index 34b7d3219..a1adf32cc 100644 --- a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets @@ -26,8 +26,8 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0100 - * @tc.name preferences dataGroupId null callback test - * @tc.desc preferences dataGroupId null callback test + * @tc.name preferencesgetPreferences dataGroupId null callback test + * @tc.desc preferences getPreferences dataGroupId null callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0100', 0, async function (done) { const Options = { @@ -55,7 +55,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0200 * @tc.name preferences dataGroupId undefined callback test - * @tc.desc preferences dataGroupId undefined callback test + * @tc.desc preferences getPreferences dataGroupId undefined callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0200', 0, async function (done) { const Options = { @@ -82,7 +82,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0300 * @tc.name preferences dataGroupId callback test - * @tc.desc preferences dataGroupId callback test + * @tc.desc preferences getPreferences dataGroupId callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0300', 0, async function (done) { const Options = { @@ -110,7 +110,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0400 * @tc.name preferences dataGroupId callback test - * @tc.desc preferences dataGroupId callback test + * @tc.desc preferences deletePreferences dataGroupId callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0400', 0, async function (done) { const Options = { @@ -143,7 +143,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0500 * @tc.name preferences dataGroupId null callback test - * @tc.desc preferences dataGroupId null callback test + * @tc.desc preferences getPreferences dataGroupId null callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0500', 0, async function (done) { const Options = { @@ -171,7 +171,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0600 * @tc.name preferences dataGroupId undefined callback test - * @tc.desc preferences dataGroupId undefined callback test + * @tc.desc preferences removePreferencesFromCache dataGroupId undefined callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0600', 0, async function (done) { const Options = { @@ -198,7 +198,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0700 * @tc.name preferences dataGroupId callback test - * @tc.desc preferences dataGroupId callback test + * @tc.desc preferences removePreferencesFromCache dataGroupId callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0700', 0, async function (done) { const Options = { @@ -226,7 +226,7 @@ export default function preferencesDataGroupIdCallback() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0800 * @tc.name preferences dataGroupId callback test - * @tc.desc preferences dataGroupId callback test + * @tc.desc preferences removePreferencesFromCache dataGroupId callback test */ it('SUB_DDM_Preferences_DataGroupId_Callback_0800', 0, async function (done) { const Options = { diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets index 205a833b0..afe7aa35d 100644 --- a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets @@ -27,7 +27,7 @@ export default function preferencesDataGroupIdPromise() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0100 * @tc.name preferences dataGroupId null promise test - * @tc.desc preferences dataGroupId null promise test + * @tc.desc preferences getPreferences dataGroupId null promise test */ it('SUB_DDM_Preferences_DataGroupId_Promise_0100', 0, async function (done) { const Options = { @@ -63,7 +63,7 @@ export default function preferencesDataGroupIdPromise() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0200 * @tc.name preferences dataGroupId undefined promise test - * @tc.desc preferences dataGroupId undefined promise test + * @tc.desc preferences getPreferences dataGroupId undefined promise test */ it('SUB_DDM_Preferences_DataGroupId_Promise_0200', 0, async function (done) { const Options = { @@ -99,7 +99,7 @@ export default function preferencesDataGroupIdPromise() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0300 * @tc.name preferences dataGroupId promise test - * @tc.desc preferences dataGroupId promise test + * @tc.desc preferences getPreferences dataGroupId promise test */ it('SUB_DDM_Preferences_DataGroupId_Promise_0300', 0, async function (done) { const Options = { @@ -135,7 +135,7 @@ export default function preferencesDataGroupIdPromise() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0400 * @tc.name preferences dataGroupId null promise test - * @tc.desc preferences dataGroupId null promise test + * @tc.desc preferences getPreferences dataGroupId null promise test */ it('SUB_DDM_Preferences_DataGroupId_Promise_0400', 0, async function (done) { const Options = { @@ -171,7 +171,7 @@ export default function preferencesDataGroupIdPromise() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0500 * @tc.name preferences dataGroupId undefined promise test - * @tc.desc preferences dataGroupId undefined promise test + * @tc.desc preferences removePreferencesFromCache dataGroupId undefined promise test */ it('SUB_DDM_Preferences_DataGroupId_Promise_0500', 0, async function (done) { const Options = { @@ -207,7 +207,7 @@ export default function preferencesDataGroupIdPromise() { /** * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0600 * @tc.name preferences dataGroupId promise test - * @tc.desc preferences dataGroupId promise test + * @tc.desc preferences removePreferencesFromCache dataGroupId promise test */ it('SUB_DDM_Preferences_DataGroupId_Promise_0600', 0, async function (done) { const Options = { diff --git a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js index a84a65c82..9270b8e9f 100644 --- a/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js +++ b/distributeddatamgr/preferencesjstest/hap/src/main/js/test/PreferencesSyncJsunit.test.js @@ -378,5 +378,31 @@ export default function PreferencesSyncTest() { expect("default").assertEqual(mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "default")); done(); }) + + /** + * @tc.number SUB_DDM_Preferences_removePreferencesFromCacheSync_0100 + * @tc.name removePreferencesFromCacheSync interface test + * @tc.desc removePreferencesFromCacheSync interface test + */ + it('testPreferencesCallback0172', 0, async function (done) { + console.log(TAG + "testPreferencesCallback0172 begin."); + mPreferences = await dataPreferences.getPreferences(context, NAME); + await mPreferences.clearSync(); + await mPreferences.putSync(KEY_TEST_STRING_ELEMENT, 'test') + await mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue") + mPreferences.flush(async function (err, val) { + if (err) { + console.log(TAG + "flush err."); + expect().assertFail(); + } + console.log(TAG + "flush done."); + await dataPreferences.removePreferencesFromCacheSync(context, NAME); + let value = mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue") + console.log(TAG + "testPreferencesCallback0172 end." + value); + expect('test').assertEqual(value); + done(); + console.log(TAG + "testPreferencesCallback0172 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 index 26e665417..3a224a768 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/List.test.ets +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/List.test.ets @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,8 +16,11 @@ import relationalStoreDistributedTest from './relationalStoreDistributedEtsunit.test.ets' import relationalStoreTest from './relationalStoreEtsunit.test.ets' import relationalStoreResultSetTest from './relationalStoreTestResultsetEtsunit.test.ets' +import relationalStoreEmitTest from './relationalStoreEmit.test' + export default function testsuite() { relationalStoreDistributedTest(globalThis.abilityContext) relationalStoreTest(globalThis.abilityContext) relationalStoreResultSetTest(globalThis.abilityContext) + relationalStoreEmitTest() } diff --git a/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEmit.test.ets b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEmit.test.ets new file mode 100644 index 000000000..5aaa5c2c2 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreStagetest/entry/src/main/ets/test/relationalStoreEmit.test.ets @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * 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_Rdb from '@ohos.data.relationalStore'; + +const TAG = "[RelationalStore_Emit_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)"; + +let rdbStore; +const STORE_CONFIG = { + name: "rdbstoreEmit.db", + securityLevel: data_Rdb.SecurityLevel.S1 +}; + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} + +export default function relationalStoreEmitTest() { + describe('relationalStoreEmitTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll'); + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach'); + rdbStore = await data_Rdb.getRdbStore(globalThis.abilityContext, STORE_CONFIG) + await rdbStore.executeSql(CREATE_TABLE_TEST); + }) + + afterEach(async function () { + console.info(TAG + 'afterAll'); + data_Rdb.deleteRdbStore(globalThis.abilityContext, "rdbstoreEmit.db"); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll'); + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number SUB_DDM_RelationalStore_Emit_0100 + * @tc.name relationalStore emit test + * @tc.desc relationalStore emit test + */ + it('testRdbStoreDistributed0012', 0, async function (done) { + async function subscribeInsert() { + console.info(TAG + "subscribeInsert start"); + const valueBucket = { + "name": "zhangsan" + } + await rdbStore.insert("test", valueBucket) + console.info(TAG + "subscribeInsert end"); + } + + try { + await rdbStore.on('storeObserverInsert', false, subscribeInsert); + await rdbStore.emit('storeObserverInsert'); + await sleep(2000); + let resultSet = await rdbStore.querySql("SELECT * FROM test"); + console.info(TAG + "resultSet = " + resultSet.rowCount); + expect(1).assertEqual(resultSet.rowCount); + + done(); + } catch (err) { + console.error(`failed, code is ${err.code},message is ${err.message}`); + expect().assertFail() + done(); + } + }) + + }) +} \ No newline at end of file diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets index 1368ed203..105608401 100644 --- a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets @@ -54,7 +54,7 @@ export default function relationalStoreDataGroupIdCallback() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0100 * @tc.name relationalStore dataGroupId null callback test - * @tc.desc relationalStore dataGroupId null callback test + * @tc.desc relationalStore getRdbStore dataGroupId null callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Callback_0100', 0, async function (done) { const STORE_CONFIG = { @@ -84,7 +84,7 @@ export default function relationalStoreDataGroupIdCallback() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0200 * @tc.name relationalStore dataGroupId undefined callback test - * @tc.desc relationalStore dataGroupId undefined callback test + * @tc.desc relationalStore getRdbStore dataGroupId undefined callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Callback_0200', 0, async function (done) { const STORE_CONFIG = { @@ -95,7 +95,7 @@ export default function relationalStoreDataGroupIdCallback() { try { relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) { console.info(TAG, `Get RdbStore successfully.`); - expect(err !== null && rdbStore !== null).assertFail(); + expect().assertFail(); done(); await rdbStore.executeSql(CREATE_TABLE_TEST); relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) { @@ -115,7 +115,7 @@ export default function relationalStoreDataGroupIdCallback() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0300 * @tc.name relationalStore dataGroupId callback test - * @tc.desc relationalStore dataGroupId callback test + * @tc.desc relationalStore getRdbStore dataGroupId callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Callback_0300', 0, async function (done) { const STORE_CONFIG = { @@ -126,7 +126,7 @@ export default function relationalStoreDataGroupIdCallback() { try { relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) { console.info(TAG, `Get RdbStore successfully.`); - expect(err !== null && rdbStore !== null).assertFail(); + expect().assertFail(); done(); await rdbStore.executeSql(CREATE_TABLE_TEST); relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (error) { @@ -145,7 +145,7 @@ export default function relationalStoreDataGroupIdCallback() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0400 * @tc.name relationalStore dataGroupId callback test - * @tc.desc relationalStore dataGroupId callback test + * @tc.desc relationalStore deleteRdbStore dataGroupId callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Callback_0400', 0, async function (done) { const STORE_CONFIG = { diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets index c66064772..fc0b403c3 100644 --- a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets @@ -37,7 +37,7 @@ export default function relationalStoreDataGroupIdPromise() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0100 * @tc.name relationalStore dataGroupId null promise test - * @tc.desc relationalStore dataGroupId null promise test + * @tc.desc relationalStore getRdbStore dataGroupId null promise test */ it('SUB_DDM_RelationalStore_DataGroupId_Promise_0100', 0, async function (done) { const STORE_CONFIG = { @@ -75,7 +75,7 @@ export default function relationalStoreDataGroupIdPromise() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0200 * @tc.name relationalStore dataGroupId undefined callback test - * @tc.desc relationalStore dataGroupId undefined callback test + * @tc.desc relationalStore getRdbStore dataGroupId undefined callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Promise_0200', 0, async function (done) { const STORE_CONFIG = { @@ -114,7 +114,7 @@ export default function relationalStoreDataGroupIdPromise() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0300 * @tc.name relationalStore dataGroupId callback test - * @tc.desc relationalStore dataGroupId callback test + * @tc.desc relationalStore getRdbStore dataGroupId callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Promise_0300', 0, async function (done) { const STORE_CONFIG = { @@ -152,7 +152,7 @@ export default function relationalStoreDataGroupIdPromise() { /** * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0400 * @tc.name relationalStore dataGroupId callback test - * @tc.desc relationalStore dataGroupId callback test + * @tc.desc relationalStore deleteRdbStore dataGroupId callback test */ it('SUB_DDM_RelationalStore_DataGroupId_Promise_0400', 0, async function (done) { const STORE_CONFIG = { -- GitLab