From 6cf2aa9d872231209827d9ab7dd88fc3ce9a37cb Mon Sep 17 00:00:00 2001 From: yanglifeng1217 Date: Mon, 24 Jul 2023 17:20:32 +0800 Subject: [PATCH] Signed-off-by: yanglifeng1217 --- .../preferencesDataGroupIdCallback.test.ets | 149 ++++++++++++++++++ .../preferencesDataGroupIdPromise.test.ets | 108 +++++++++++++ ...elationalStoreDataGroupIdCallback.test.ets | 65 ++++---- ...relationalStoreDataGroupIdPromise.test.ets | 37 +++++ 4 files changed, 326 insertions(+), 33 deletions(-) diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets index 0d508dadd..7df725d55 100644 --- a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdCallback.test.ets @@ -107,6 +107,155 @@ export default function preferencesDataGroupIdCallback() { } }) + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0400 + * @tc.name preferences dataGroupId callback test + * @tc.desc preferences dataGroupId callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0400', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: '123456', + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + if (err) { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + return false; + } + console.info(TAG, `getPreferences successfully.`); + dataPreferences.deletePreferences(globalThis.abilityContext, Options, function (error) { + if (error) { + console.error(TAG, `deletePreferences failed, code is ${error.code},message is ${error.message}`); + return false; + } + console.info(TAG, `deletePreferences successfully.`); + expect(error === undefined).assertTrue(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo !== null).assertFail(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0500 + * @tc.name preferences dataGroupId null callback test + * @tc.desc preferences dataGroupId null callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0500', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: null, + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) { + console.info(TAG, `removePreferencesFromCache successfully.`); + expect().assertFail(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0600 + * @tc.name preferences dataGroupId undefined callback test + * @tc.desc preferences dataGroupId undefined callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0600', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: undefined, + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) { + console.info(TAG, `removePreferencesFromCache successfully.`); + expect().assertFail(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0700 + * @tc.name preferences dataGroupId callback test + * @tc.desc preferences dataGroupId callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0700', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: '112233', + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) { + console.info(TAG, `removePreferencesFromCache successfully.`); + expect().assertFail(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('14801002'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Callback_0800 + * @tc.name preferences dataGroupId callback test + * @tc.desc preferences dataGroupId callback test + */ + it('SUB_DDM_Preferences_DataGroupId_Callback_0800', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: '123456', + }; + try { + dataPreferences.getPreferences(globalThis.abilityContext, Options, async function (err) { + if (err) { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + return false; + } + console.info(TAG, `getPreferences successfully.`); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options, function (error) { + if (error) { + console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`); + return false; + } + console.info(TAG, `removePreferencesFromCache successfully.`); + expect(error === undefined).assertTrue(); + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo !== null).assertFail(); + } + }) + console.log(TAG + "*************Unit Test End*************"); }) } \ No newline at end of file diff --git a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets index b24afbfa9..676be2461 100644 --- a/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets +++ b/distributeddatamgr/preferencesdatagroupidtest/src/main/ets/test/preferencesDataGroupIdPromise.test.ets @@ -132,6 +132,114 @@ 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 + */ + it('SUB_DDM_Preferences_DataGroupId_Promise_0400', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: null, + }; + try{ + dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options).then(async (val) => { + console.info(TAG, `removePreferencesFromCache successfully.`); + expect().assertFail(); + done(); + }).catch((error) => { + console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertFail(); + done(); + }) + }catch(errInfo){ + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0500 + * @tc.name preferences dataGroupId undefined promise test + * @tc.desc preferences dataGroupId undefined promise test + */ + it('SUB_DDM_Preferences_DataGroupId_Promise_0500', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: undefined, + }; + try{ + dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options).then(async (val) => { + console.info(TAG, `removePreferencesFromCache successfully.`); + expect().assertFail(); + done(); + }).catch((error) => { + console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertFail(); + done(); + }) + }catch(errInfo){ + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('401'); + done(); + } + }) + + /** + * @tc.number SUB_DDM_Preferences_DataGroupId_Promise_0600 + * @tc.name preferences dataGroupId promise test + * @tc.desc preferences dataGroupId promise test + */ + it('SUB_DDM_Preferences_DataGroupId_Promise_0600', 0, async function (done) { + const Options = { + name: "test_preferences_callback", + dataGroupId: '112233', + }; + try{ + dataPreferences.getPreferences(globalThis.abilityContext, Options).then(async (data) => { + console.info(TAG, `getPreferences successfully.`); + expect().assertFail(); + done(); + dataPreferences.removePreferencesFromCache(globalThis.abilityContext, Options).then(async (val) => { + console.info(TAG, `removePreferencesFromCache successfully.`); + expect().assertFail(); + done(); + }).catch((error) => { + console.error(TAG, `removePreferencesFromCache failed, code is ${error.code},message is ${error.message}`); + expect(error !== null).assertFail(); + done(); + }) + }).catch((err) => { + console.error(TAG, `getPreferences failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertFail(); + done(); + }) + }catch(errInfo){ + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo.code).assertEqual('14801002'); + done(); + } + }) + console.log(TAG + "*************Unit Test End*************"); }) } \ 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 95efef0ab..358e54746 100644 --- a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdCallback.test.ets @@ -143,42 +143,41 @@ export default function relationalStoreDataGroupIdCallback() { }) /** - * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0100 + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Callback_0400 * @tc.name relationalStore dataGroupId callback test * @tc.desc relationalStore dataGroupId callback test */ - // it('SUB_DDM_RelationalStore_DataGroupId_Callback_0100', 0, async function (done) { - // const STORE_CONFIG = { - // name: "RdbTest.db", - // securityLevel: relationalStore.SecurityLevel.S1, - // dataGroupId: '123456' - // }; - // try { - // relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, store) { - // rdbStore = store; - // if (err) { - // console.error(TAG, `Get RdbStore failed, code is ${err.code},message is ${err.message}`); - // return false; - // } - // console.info(TAG, `Get RdbStore successfully.`); - // await rdbStore.executeSql(CREATE_TABLE_TEST); - // relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (err) { - // if (err) { - // console.error(TAG, `Delete RdbStore failed, code is ${err.code},message is ${err.message}`); - // return false; - // } - // console.info(TAG, `Delete RdbStore successfully.`); - // expect(err === null).assertTrue() - // done(); - // }) - // }) - // } catch (errInfo) { - // console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); - // expect(errInfo !== null).assertFail() - // done(); - // } - // - // }) + it('SUB_DDM_RelationalStore_DataGroupId_Callback_0400', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: '123456' + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG, async function (err, rdbStore) { + if (err) { + console.error(TAG, `Get RdbStore failed, code is ${err.code},message is ${err.message}`); + return false; + } + console.info(TAG, `Get RdbStore successfully.` + ` rdbStore = ${rdbStore} , err = ${err}`); + await rdbStore.executeSql(CREATE_TABLE_TEST); + relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG, function (err) { + if (err) { + console.error(TAG, `Delete RdbStore failed, code is ${err.code},message is ${err.message}`); + return false; + } + console.info(TAG, `Delete RdbStore successfully.` + ` rdbStore = ${rdbStore} , err = ${err}`); + expect(err === undefined).assertTrue() + done(); + }) + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo !== undefined).assertFail() + done(); + } + }) + console.log(TAG + "*************Unit Test End*************"); diff --git a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets index 4f6246500..c66064772 100644 --- a/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets +++ b/distributeddatamgr/relationalstoredatagroupidtest/src/main/ets/test/relationalStoreDataGroupIdPromise.test.ets @@ -149,6 +149,43 @@ export default function relationalStoreDataGroupIdPromise() { } }) + /** + * @tc.number SUB_DDM_RelationalStore_DataGroupId_Promise_0400 + * @tc.name relationalStore dataGroupId callback test + * @tc.desc relationalStore dataGroupId callback test + */ + it('SUB_DDM_RelationalStore_DataGroupId_Promise_0400', 0, async function (done) { + const STORE_CONFIG = { + name: "RdbTest.db", + securityLevel: relationalStore.SecurityLevel.S1, + dataGroupId: '123456', + }; + try { + relationalStore.getRdbStore(globalThis.abilityContext, STORE_CONFIG).then(async (rdbStore) => { + console.info(TAG, `Get RdbStore successfully.`); + // await rdbStore.executeSql(CREATE_TABLE_TEST); + rdbStore.executeSql(CREATE_TABLE_TEST, [], async function (error) { + if (error) { + console.error(TAG, `ExecuteSql failed, code is ${error.code},message is ${error.message}`); + return; + } + console.info(TAG, `executeSql1 done.` + error); + expect(error === undefined).assertTrue(); + await relationalStore.deleteRdbStore(globalThis.abilityContext, STORE_CONFIG) + done(); + }) + }).catch((err) => { + console.info(TAG, `Get RdbStore fail, code is ${err.code},message is ${err.message}.`); + expect(err !== null).assertFail(); + done(); + }) + } catch (errInfo) { + console.error(TAG, `failed, code is ${errInfo.code},message is ${errInfo.message}`); + expect(errInfo !== null).assertFail(); + done(); + } + }) + console.info(TAG + "*************Unit Test End*************"); }) } \ No newline at end of file -- GitLab