From f1b8c2b4326d3d8c5e4dad10adc5d13f6b08d39f Mon Sep 17 00:00:00 2001 From: hu0475 Date: Sat, 15 Jul 2023 18:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9distributeddatamgr=E5=AD=90?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F[preferences=E3=80=81relationalStore]?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hu0475 --- .../src/main/ets/test/List.test.ets | 2 + .../ets/test/PreferencesCallBack.test.ets | 96 ------- .../main/ets/test/PreferencesHelper.test.ets | 118 -------- .../main/ets/test/PreferencesIgnore.test.ets | 252 ++++++++++++++++++ .../main/ets/test/PreferencesPromise.test.ets | 47 ++-- .../test/PreferencesPromiseWithError.test.ets | 54 ++-- .../ets/test/RdbStoreBackupRestore.test.ets | 35 +-- 7 files changed, 321 insertions(+), 283 deletions(-) create mode 100644 distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesIgnore.test.ets diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets index a402804b3..957b1c28c 100644 --- a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets @@ -18,6 +18,7 @@ import preferenceshelper from './PreferencesHelper.test' import preferencespromise from './PreferencesPromise.test' import preferencescallbackwitherror from './PreferencesCallBackWithError.test' import preferencespromisewitherror from './PreferencesPromiseWithError.test' +import preferencesIgnoreTest from './PreferencesIgnore.test' @@ -27,4 +28,5 @@ export default function testsuite() { preferencespromise() preferencescallbackwitherror() preferencespromisewitherror() + preferencesIgnoreTest() } \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBack.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBack.test.ets index 074fa713e..c35d9ab59 100644 --- a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBack.test.ets +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBack.test.ets @@ -67,34 +67,6 @@ export default function preferencesCallBackTest() { }); }); - /** - * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_PREFERENCES_0100 - * @tc.name : testPreferencesGetPreferences001 - * @tc.desc : GetPreferences callback interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testPreferencesGetPreferences001", 0, async function (done) { - try { - // @ts-ignore - await dataPreferences.getPreferences(context, -1, (err, preferences) => { - if (err) { - console.info(TAG + "Get preferences err: " + err); - expect(!err).assertTrue(); - done(); - } else { - console.info(TAG + "Get preferences success" + preferences); - done(); - } - }); - } catch (err) { - console.info("testPreferencesGetPreferences001 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message == "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); - done(); - } - }); - /** * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_PREFERENCES_0200 * @tc.name : testPreferencesGetPreferences002 @@ -180,40 +152,6 @@ export default function preferencesCallBackTest() { }); }); - /** - * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_PREFERENCES_0200 - * @tc.name : testPreferencesDeletePreferences002 - * @tc.desc : DeletePreferences callback interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testPreferencesDeletePreferences002", 0, async function (done) { - dataPreferences.getPreferences(context, NAME1, (err, preferences) => { - if (err) { - console.info(TAG + "Get preferences err: " + err); - expect(!err).assertTrue(); - } else { - console.info(TAG + "Get preferences success"); - expect(preferences !== null).assertTrue(); - try { - // @ts-ignore - dataPreferences.deletePreferences(context, -1, (err) => { - if (err) { - console.info(TAG + "Delete preferences err: " + err); - expect(!err).assertTrue(); - done(); - } - }); - } catch (err) { - console.info("testPreferencesDeletePreferences002 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); - done(); - } - } - }); - }); - /** * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_PREFERENCES_0300 * @tc.name : testPreferencesDeletePreferences003 @@ -308,40 +246,6 @@ export default function preferencesCallBackTest() { }); }); - /** - * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_0200 - * @tc.name : testRemovePreferencesFromCache002 - * @tc.desc : RemovePreferencesFromCache callback interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testRemovePreferencesFromCache002", 0, async function (done) { - dataPreferences.getPreferences(context, NAME, (err, preferences) => { - if (err) { - console.info(TAG + "Get preferences err: " + err); - expect(!err).assertTrue(); - } else { - console.info(TAG + "Get preferences success"); - expect(preferences !== null).assertTrue(); - try { - // @ts-ignore - dataPreferences.removePreferencesFromCache(context, -1, (err) => { - if (err) { - console.info(TAG + "Remove preferences from cache error: " + err); - expect(!err).assertTrue(); - done(); - } - }); - } catch (err) { - console.info("testRemovePreferencesFromCache002 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); - done(); - } - } - }); - }); - /** * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_0300 * @tc.name : testRemovePreferencesFromCache003 diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets index 3c5735d22..5f74af00f 100644 --- a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets @@ -80,44 +80,6 @@ export default function preferencesHelperTest() { }); }); - /** - * @tc.number : SUB_DDM_TEST_GET_PREFERENCES_HELPER_0300 - * @tc.name : testGetPreferencesHelper0003 - * @tc.desc : GetPreferences interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testGetPreferencesHelper0003", 0, async function (done) { - try { - // @ts-ignore - await dataPreferences.getPreferences(context, -1); - } catch (err) { - console.info("testGetPreferencesHelper0003 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_DDM_TEST_GET_PREFERENCES_HELPER_0400 - * @tc.name : testGetPreferencesHelper0004 - * @tc.desc : GetPreferences interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testGetPreferencesHelper0004", 0, async function (done) { - try { - // @ts-ignore - await dataPreferences.getPreferences(context); - } catch (err) { - console.info("testGetPreferencesHelper0004 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); - done(); - } - }); - /** * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0100 * @tc.name : testRemovePreferencesFromCacheHelper0001 @@ -141,46 +103,6 @@ export default function preferencesHelperTest() { }); }); - /** - * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0200 - * @tc.name : testRemovePreferencesFromCacheHelper0002 - * @tc.desc : RemovePreferencesFromCache interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testRemovePreferencesFromCacheHelper0002", 0, async function (done) { - try { - await dataPreferences.getPreferences(context, NAME); - // @ts-ignore - await dataPreferences.removePreferencesFromCache(context); - } catch (err) { - console.info("testRemovePreferencesFromCacheHelper0002 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0300 - * @tc.name : testRemovePreferencesFromCacheHelper0003 - * @tc.desc : RemovePreferencesFromCache interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testRemovePreferencesFromCacheHelper0003", 0, async function (done) { - try { - await dataPreferences.getPreferences(context, NAME); - // @ts-ignore - await dataPreferences.removePreferencesFromCache(context, -1); - } catch (err) { - console.info("testRemovePreferencesFromCacheHelper0003 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); - done(); - } - }); - /** * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0400 * @tc.name : testRemovePreferencesFromCacheHelper0004 @@ -236,46 +158,6 @@ export default function preferencesHelperTest() { }); }); - /** - * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0200 - * @tc.name : testPreferencesDeleteHelper0002 - * @tc.desc : DeletePreferences interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testPreferencesDeleteHelper0002", 0, async function (done) { - try { - await dataPreferences.getPreferences(context, NAME); - // @ts-ignore - await dataPreferences.deletePreferences(context); - } catch (err) { - console.info("testPreferencesDeleteHelper0002 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); - done(); - } - }); - - /** - * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0300 - * @tc.name : testPreferencesDeleteHelper0003 - * @tc.desc : DeletePreferences interface test - * @tc.size : MediumTest - * @tc.type : Function - * @tc.level : Level 2 - */ - it("testPreferencesDeleteHelper0003", 0, async function (done) { - try { - await dataPreferences.getPreferences(context, NAME); - // @ts-ignore - await dataPreferences.deletePreferences(context, -1); - } catch (err) { - console.info("testPreferencesDeleteHelper0003 fail: " + err.message + "code: " + err.code); - expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); - done(); - } - }); - /** * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0400 * @tc.name : testPreferencesDeleteHelper0004 diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesIgnore.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesIgnore.test.ets new file mode 100644 index 000000000..8747ca552 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesIgnore.test.ets @@ -0,0 +1,252 @@ +/* + * 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 dataPreferences from "@ohos.data.preferences"; + +const NAME = "test_preferences"; +const NAME1 = "getPreferencesTest"; +let mPreferences; +let context; + +const TAG = "[PREFERENCES_IGNORE_TEST]"; +export default function preferencesIgnoreTest() { + describe("preferencesIgnoreTest", function () { + beforeAll(async function () { + console.info("beforeAll"); + context = globalThis.abilityContext; + mPreferences = await dataPreferences.getPreferences(context, NAME); + }); + + afterAll(async function () { + console.info("afterAll"); + await dataPreferences.deletePreferences(context, NAME); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_PREFERENCES_0100 + * @tc.name : testPreferencesGetPreferences001 + * @tc.desc : GetPreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesGetPreferences001", 0, async function (done) { + try { + // @ts-ignore + await dataPreferences.getPreferences(context, -1, (err, preferences) => { + if (err) { + console.info(TAG + "Get preferences err: " + err); + expect(!err).assertTrue(); + done(); + } else { + console.info(TAG + "Get preferences success" + preferences); + done(); + } + }); + } catch (err) { + console.info("testPreferencesGetPreferences001 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message == "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_PREFERENCES_0200 + * @tc.name : testPreferencesDeletePreferences002 + * @tc.desc : DeletePreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeletePreferences002", 0, async function (done) { + dataPreferences.getPreferences(context, NAME1, (err, preferences) => { + if (err) { + console.info(TAG + "Get preferences err: " + err); + expect(!err).assertTrue(); + } else { + console.info(TAG + "Get preferences success"); + expect(preferences !== null).assertTrue(); + try { + // @ts-ignore + dataPreferences.deletePreferences(context, -1, (err) => { + if (err) { + console.info(TAG + "Delete preferences err: " + err); + expect(!err).assertTrue(); + done(); + } + }); + } catch (err) { + console.info("testPreferencesDeletePreferences002 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); + done(); + } + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_0200 + * @tc.name : testRemovePreferencesFromCache002 + * @tc.desc : RemovePreferencesFromCache callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCache002", 0, async function (done) { + dataPreferences.getPreferences(context, NAME, (err, preferences) => { + if (err) { + console.info(TAG + "Get preferences err: " + err); + expect(!err).assertTrue(); + } else { + console.info(TAG + "Get preferences success"); + expect(preferences !== null).assertTrue(); + try { + // @ts-ignore + dataPreferences.removePreferencesFromCache(context, -1, (err) => { + if (err) { + console.info(TAG + "Remove preferences from cache error: " + err); + expect(!err).assertTrue(); + done(); + } + }); + } catch (err) { + console.info("testRemovePreferencesFromCache002 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); + done(); + } + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_GET_PREFERENCES_HELPER_0300 + * @tc.name : testGetPreferencesHelper0003 + * @tc.desc : GetPreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetPreferencesHelper0003", 0, async function (done) { + try { + // @ts-ignore + await dataPreferences.getPreferences(context, -1); + } catch (err) { + console.info("testGetPreferencesHelper0003 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_GET_PREFERENCES_HELPER_0400 + * @tc.name : testGetPreferencesHelper0004 + * @tc.desc : GetPreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetPreferencesHelper0004", 0, async function (done) { + try { + // @ts-ignore + await dataPreferences.getPreferences(context); + } catch (err) { + console.info("testGetPreferencesHelper0004 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0200 + * @tc.name : testRemovePreferencesFromCacheHelper0002 + * @tc.desc : RemovePreferencesFromCache interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCacheHelper0002", 0, async function (done) { + try { + await dataPreferences.getPreferences(context, NAME); + // @ts-ignore + await dataPreferences.removePreferencesFromCache(context); + } catch (err) { + console.info("testRemovePreferencesFromCacheHelper0002 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0300 + * @tc.name : testRemovePreferencesFromCacheHelper0003 + * @tc.desc : RemovePreferencesFromCache interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCacheHelper0003", 0, async function (done) { + try { + await dataPreferences.getPreferences(context, NAME); + // @ts-ignore + await dataPreferences.removePreferencesFromCache(context, -1); + } catch (err) { + console.info("testRemovePreferencesFromCacheHelper0003 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0200 + * @tc.name : testPreferencesDeleteHelper0002 + * @tc.desc : DeletePreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeleteHelper0002", 0, async function (done) { + try { + await dataPreferences.getPreferences(context, NAME); + // @ts-ignore + await dataPreferences.deletePreferences(context); + } catch (err) { + console.info("testPreferencesDeleteHelper0002 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0300 + * @tc.name : testPreferencesDeleteHelper0003 + * @tc.desc : DeletePreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeleteHelper0003", 0, async function (done) { + try { + await dataPreferences.getPreferences(context, NAME); + // @ts-ignore + await dataPreferences.deletePreferences(context, -1); + } catch (err) { + console.info("testPreferencesDeleteHelper0003 fail: " + err.message + "code: " + err.code); + expect(err.code === "401" && err.message === "Parameter error. The type of 'name' must be a without path non empty string.").assertTrue(); + done(); + } + }); + }); +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromise.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromise.test.ets index fcfa0c5f0..59067d415 100644 --- a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromise.test.ets +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromise.test.ets @@ -501,8 +501,7 @@ export default function preferencesPromiseTest() { */ it("testPreferencesPutFloatPromise0001", 0, async function (done) { await mPreferences.clear(); - const promise = mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0); - await promise; + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0); let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); expect(4.0).assertEqual(per); await mPreferences.flush(); @@ -521,8 +520,7 @@ export default function preferencesPromiseTest() { */ it("testPreferencesPutIntPromise0001", 0, async function (done) { await mPreferences.clear(); - let promise = mPreferences.put(KEY_TEST_INT_ELEMENT, 4); - await promise; + await mPreferences.put(KEY_TEST_INT_ELEMENT, 4); let per = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); expect(4).assertEqual(per); await mPreferences.flush(); @@ -540,8 +538,7 @@ export default function preferencesPromiseTest() { * @tc.level : Level 2 */ it("testPreferencesPutLongPromise0001", 0, async function (done) { - let promise = mPreferences.put(KEY_TEST_LONG_ELEMENT, 4); - await promise; + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 4); let per = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); expect(4).assertEqual(per); await mPreferences.flush(); @@ -559,8 +556,7 @@ export default function preferencesPromiseTest() { * @tc.level : Level 2 */ it("testPreferencesPutStringPromise0001", 0, async function (done) { - let promise = mPreferences.put(KEY_TEST_STRING_ELEMENT, ""); - await promise; + await mPreferences.put(KEY_TEST_STRING_ELEMENT, ""); let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); expect("").assertEqual(per); await mPreferences.flush(); @@ -579,8 +575,7 @@ export default function preferencesPromiseTest() { */ it("testPreferencesPutBooleanPromise0001", 0, async function (done) { await mPreferences.clear(); - let promise = mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true); - await promise; + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true); let per = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); expect(true).assertEqual(per); await mPreferences.flush(); @@ -600,8 +595,7 @@ export default function preferencesPromiseTest() { it("testPreferencesPutStringArrayPromise0001", 0, async function (done) { await mPreferences.clear(); var stringArr = ["1", "2", "3"]; - let promise1 = mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); - await promise1; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"]); promise2 .then((pre) => { @@ -626,8 +620,7 @@ export default function preferencesPromiseTest() { it("testPreferencesPutNumArrayPromise0001", 0, async function (done) { await mPreferences.clear(); var numberArr = [11, 22, 33, 44, 55]; - let promise1 = mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr); - await promise1; + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr); let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]); promise2 .then((pre) => { @@ -652,8 +645,7 @@ export default function preferencesPromiseTest() { it("testPreferencesPutBoolArrayPromise0001", 0, async function (done) { await mPreferences.clear(); var boolArr = [true, true, false]; - let promise1 = mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); - await promise1; + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true]); promise2 .then((pre) => { @@ -670,7 +662,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_FLOAT_0100 * @tc.name : testPreferencesPutSyncFloat0001 - * @tc.desc : PutSync float promise interface test + * @tc.desc : PutSync float interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -689,7 +681,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_INT_0100 * @tc.name : testPreferencesPutSyncInt0001 - * @tc.desc : PutSync int promise interface test + * @tc.desc : PutSync int interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -708,7 +700,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_LONG_0100 * @tc.name : testPreferencesPutSyncLong0001 - * @tc.desc : PutSync long promise interface test + * @tc.desc : PutSync long interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -726,7 +718,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_STRING_0100 * @tc.name : testPreferencesPutSyncString0001 - * @tc.desc : PutSync string promise interface test + * @tc.desc : PutSync string interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -744,7 +736,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_BOOLEAN_0100 * @tc.name : testPreferencesPutSyncBoolean0001 - * @tc.desc : PutSync boolean promise interface test + * @tc.desc : PutSync boolean interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -763,7 +755,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_STRING_ARRAY_0100 * @tc.name : testPreferencesPutSyncStringArray0001 - * @tc.desc : PutSync StringArray promise interface test + * @tc.desc : PutSync StringArray interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -773,6 +765,7 @@ export default function preferencesPromiseTest() { var stringArr = ["1", "2", "3"]; mPreferences.putSync(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"]); + await promise2; promise2 .then((pre) => { for (let i = 0; i < stringArr.length; i++) { @@ -788,7 +781,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_NUM_ARRAY_0100 * @tc.name : testPreferencesPutSyncNumArray0001 - * @tc.desc : PutSync NumberArray promise interface test + * @tc.desc : PutSync NumberArray interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -798,6 +791,7 @@ export default function preferencesPromiseTest() { var numberArr = [11, 22, 33, 44, 55]; mPreferences.putSync(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr); let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]); + await promise2; promise2 .then((pre) => { for (let i = 0; i < numberArr.length; i++) { @@ -813,7 +807,7 @@ export default function preferencesPromiseTest() { /** * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_BOOL_ARRAY_0100 * @tc.name : testPreferencesPutSyncBoolArray0001 - * @tc.desc : PutSync BoolArray promise interface test + * @tc.desc : PutSync BoolArray interface test * @tc.size : MediumTest * @tc.type : Method * @tc.level : Level 2 @@ -823,6 +817,7 @@ export default function preferencesPromiseTest() { var boolArr = [true, true, false]; mPreferences.putSync(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true]); + await promise2; promise2 .then((pre) => { for (let i = 0; i < boolArr.length; i++) { @@ -993,7 +988,7 @@ export default function preferencesPromiseTest() { * @tc.type : Method * @tc.level : Level 2 */ - it("testPreferencesHasKeyPromise0004", 0, async function (done) { + it("testPreferencesHasSync0004", 0, async function (done) { await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); let ret = mPreferences.hasSync(KEY_TEST_STRING_ELEMENT); expect(true).assertEqual(ret); @@ -1117,7 +1112,7 @@ export default function preferencesPromiseTest() { mPreferences.clearSync(); let ret = mPreferences.getAllSync(); - console.log("testPreferencesClearPromise0001 end." + JSON.stringify(ret.key_test_string)); + console.log("testPreferencesClearSync0001 end." + JSON.stringify(ret.key_test_string)); expect(undefined).assertEqual(ret.key_test_boolean); expect(undefined).assertEqual(ret.key_test_string); expect(undefined).assertEqual(ret.key_test_float); diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets index d2dd2b138..b9951029f 100644 --- a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets @@ -47,7 +47,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testPreferencesPromiseWithError0001", 0, function (done) { + it("testPreferencesPromiseWithError0001", 0, async function (done) { console.log("testPreferencesPromiseWithError0001 begin."); try { if (mPreference === undefined) { @@ -55,17 +55,17 @@ export default function preferencesPromiseWithErrorTest() { } mPreference .clear() - .then(() => { + .then(async () => { mPreference .put(KEY_TEST_INT_ELEMENT, 123) - .then((ret) => { - mPreference + .then(async (ret) => { + mPreference .get(KEY_TEST_INT_ELEMENT, 123) - .then((pre) => { + .then(async (pre) => { expect(123).assertEqual(pre); - mPreference + mPreference .flush() - .then(() => { + .then(async () => { mPreference .delete(KEY_TEST_INT_ELEMENT) .then(async () => { @@ -113,7 +113,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesGetPromise0001", 0, function (done) { + it("testMpreferencesGetPromise0001", 0, async function (done) { console.log("testMpreferencesGetPromise0001 begin."); try { mPreference @@ -199,7 +199,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesGetSyncWithError0001", 0, function (done) { + it("testMpreferencesGetSyncWithError0001", 0, async function (done) { console.log("testMpreferencesGetSyncWithError0001 begin."); try { mPreference.getSync(1233); @@ -261,7 +261,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesGetALLPromise0001", 0, function (done) { + it("testMpreferencesGetALLPromise0001", 0, async function (done) { console.log("testMpreferencesGetALLPromise0001 begin."); try { mPreference @@ -289,7 +289,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesHasPromise0001", 0, function (done) { + it("testMpreferencesHasPromise0001", 0, async function (done) { console.log("testMpreferencesHasPromise0001 begin."); try { mPreference @@ -317,7 +317,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesHasPromise0002", 0, function (done) { + it("testMpreferencesHasPromise0002", 0, async function (done) { console.log("testMpreferencesHasPromise0002 begin."); try { mPreference @@ -344,7 +344,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutPromise0001", 0, function (done) { + it("testMpreferencesPutPromise0001", 0, async function (done) { console.log("testMpreferencesPutPromise0001 begin."); try { mPreference @@ -372,7 +372,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutPromise0002", 0, function (done) { + it("testMpreferencesPutPromise0002", 0, async function (done) { console.log("testMpreferencesPutPromise0002 begin."); try { mPreference @@ -403,7 +403,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutPromise0003", 0, function (done) { + it("testMpreferencesPutPromise0003", 0, async function (done) { console.log("testMpreferencesPutPromise0003 begin."); try { mPreference @@ -435,7 +435,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutPromise0004", 0, function (done) { + it("testMpreferencesPutPromise0004", 0, async function (done) { console.log("testMpreferencesPutPromise0004 begin."); try { mPreference @@ -464,7 +464,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutPromise0005", 0, function (done) { + it("testMpreferencesPutPromise0005", 0, async function (done) { console.log("testMpreferencesPutPromise0005 begin."); try { mPreference @@ -493,7 +493,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutSyncWithError0001", 0, function (done) { + it("testMpreferencesPutSyncWithError0001", 0, async function (done) { console.log("testMpreferencesPutSyncWithError0001 begin."); try { mPreference.putSync(1233); @@ -513,7 +513,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutSyncWithError0002", 0, function (done) { + it("testMpreferencesPutSyncWithError0002", 0, async function (done) { console.log("testMpreferencesPutSyncWithError0002 begin."); try { mPreference.putSync(KEY_TEST_STRING_ELEMENT, ""); @@ -536,7 +536,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutSyncWithError0003", 0, function (done) { + it("testMpreferencesPutSyncWithError0003", 0, async function (done) { console.log("testMpreferencesPutSyncWithError0003 begin."); try { mPreference.putSync(KEY_TEST_STRING_ELEMENT, " "); @@ -559,7 +559,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutSyncWithError0004", 0, function (done) { + it("testMpreferencesPutSyncWithError0004", 0, async function (done) { console.log("testMpreferencesPutSyncWithError0004 begin."); try { mPreference.putSync(-1, 123); @@ -578,7 +578,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesPutSyncWithError0005", 0, function (done) { + it("testMpreferencesPutSyncWithError0005", 0, async function (done) { console.log("testMpreferencesPutSyncWithError0005 begin."); try { mPreference.putSync(KEY_TEST_STRING_ELEMENT, null); @@ -597,7 +597,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesDeletePromise0001", 0, function (done) { + it("testMpreferencesDeletePromise0001", 0, async function (done) { console.log("testMpreferencesDeletePromise0001 begin."); try { mPreference @@ -625,12 +625,12 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesDeletePromise0002", 0, function (done) { + it("testMpreferencesDeletePromise0002", 0, async function (done) { console.log("testMpreferencesDeletePromise0002 begin."); try { mPreference .delete(KEY_TEST_STRING_ELEMENT) - .then(() => { + .then(async () => { done(); console.log("testMpreferencesDeletePromise0002 end."); }) @@ -652,7 +652,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesClearPromise0001", 0, function (done) { + it("testMpreferencesClearPromise0001", 0, async function (done) { console.log("testMpreferencesClearPromise0001 begin."); try { mPreference @@ -679,7 +679,7 @@ export default function preferencesPromiseWithErrorTest() { * @tc.type : Function * @tc.level : Level 2 */ - it("testMpreferencesFlushPromise0001", 0, function (done) { + it("testMpreferencesFlushPromise0001", 0, async function (done) { console.log("testMpreferencesFlushPromise0001 begin."); try { mPreference diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets index a4bb5f171..c6f0591a4 100644 --- a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets @@ -97,17 +97,17 @@ export default function RdbStoreBackupRestoreCallbackTest() { it("testRdbStoreBackupRestore001", 0, async function (done) { console.info(TAG + "************* testRdbStoreBackupRestore001 start *************"); RdbStore.backup(DATABASE_BACKUP_NAME, async (err) => { - if (err != null) { + if (err) { console.info(TAG + "backup err ttt: " + err); - expect(false).assertTrue(); + expect(!err).assertTrue(); } else { console.info(`Backup success.`); let deleteData = new relationalStore.RdbPredicates("backupTest"); deleteData.equalTo("name", "zhangsan"); await RdbStore.delete(deleteData); RdbStore.restore(DATABASE_BACKUP_NAME, async (err) => { - if (err != null) { - expect(false).assertTrue(); + if (err) { + expect(!err).assertTrue(); } else { let predicates = new relationalStore.RdbPredicates("backupTest"); predicates.equalTo("name", "zhangsan"); @@ -124,7 +124,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { resultSet.close(); done(); } catch (err) { - expect(false).assertTrue(); + expect(!err).assertTrue(); } resultSet = null; RdbStore = null; @@ -172,6 +172,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { done(); } catch (err) { console.info(TAG + "testRdbStoreBackupRestore002 error: " + err); + expect(!err).assertTrue(); } resultSet = null; RdbStore = null; @@ -179,10 +180,12 @@ export default function RdbStoreBackupRestoreCallbackTest() { }) .catch((err) => { console.info(TAG + "Restore error: " + err); + expect(!err).assertTrue(); }); }) .catch((err) => { console.info(TAG + "Backup error: " + err); + expect(!err).assertTrue(); }); }); @@ -199,7 +202,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { try { RdbStore.backup("", async (err) => { console.info(`Backup success.`); - expect().assertFail(); + expect(!err).assertTrue(); done(); }); } catch (errInfo) { @@ -228,7 +231,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { }); } catch (errInfo) { console.info(TAG + "testRdbStoreBackup002 error: " + errInfo); - expect().assertFail(); + expect(!errInfo).assertTrue(); done(); } console.info(TAG + "************* testRdbStoreBackup002 end *************"); @@ -246,7 +249,6 @@ export default function RdbStoreBackupRestoreCallbackTest() { console.info(TAG + "************* testRdbStoreBackup003 start *************"); try { await RdbStore.backup(""); - expect().assertFail(); done(); } catch (errInfo) { console.info(TAG + "testRdbStoreBackup003 error: " + errInfo); @@ -279,8 +281,10 @@ export default function RdbStoreBackupRestoreCallbackTest() { expect(err.code == 14800011 && err.message == "Failed to open database by database corrupted").assertTrue(); done(); }); - } catch (errInfo) { - console.info(TAG + "testRdbStoreBackup004 error: " + errInfo); + } catch (err) { + console.info(TAG + "testRdbStoreBackup004 error: " + err.message + "code: " + err.code); + expect(!err).assertTrue(); + done(); } console.info(TAG + "************* testRdbStoreBackup004 end *************"); }); @@ -300,7 +304,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { try { RdbStore.restore("", async (err) => { console.info(`restore success.`); - expect().assertFail(); + expect(!err).assertTrue(); done(); }); } catch (errInfo) { @@ -325,13 +329,14 @@ export default function RdbStoreBackupRestoreCallbackTest() { await RdbStore.backup(backupName); try { RdbStore.restore(STORE_CONFIG.name, async (err) => { - expect(err != null).assertTrue(); + expect(err !== null).assertTrue(); console.info(TAG + "restore err ttt: " + err); console.info(`Restore err: file name wrong.`); done(); }); } catch (errInfo) { console.info(TAG + "testRdbStoreRestore002 error: " + errInfo); + expect(!errInfo).assertTrue(); } console.info(TAG + "************* testRdbStoreRestore002 end *************"); }); @@ -349,8 +354,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { let backupName = "BackupTest003.db"; await RdbStore.backup(backupName); try { - RdbStore.retore(""); - expect().assertFail(); + await RdbStore.retore(""); done(); } catch (errInfo) { console.info(TAG + "testRdbStoreRestore003 error: " + errInfo); @@ -374,8 +378,7 @@ export default function RdbStoreBackupRestoreCallbackTest() { let backupName = "BackupTest003.db"; await RdbStore.backup(backupName); try { - RdbStore.retore(STORE_CONFIG.name); - expect().assertFail(); + await RdbStore.retore(STORE_CONFIG.name); done(); } catch (errInfo) { console.info(TAG + "testRdbStoreRestore004 error: " + errInfo); -- GitLab