diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn index 3f1d2c265a7d9250e08c487d5b610bf7c3238659..d3196ef78cc0d3c93c6e8ad5f9a8bbe00914f611 100644 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -16,7 +16,8 @@ group("distributeddatamgr") { testonly = true if (is_standard_system) { deps = [ - "UDMFtest:UDMFtest", + "crossplatform/preferencesetstest:ActsCrossplatformPreferencesTest", + "crossplatform/relationalstoreetstest:ActsCrossplatformRelationalStoreTest", "dataObjectjstest/hap:dataObject_js_test", "dataSharejstest/hap:dataShare_js_test", "distributedKVStoretest:distributedKVStoretest", diff --git a/distributeddatamgr/crossplatform/preferencesetstest/AppScope/app.json b/distributeddatamgr/crossplatform/preferencesetstest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..9ce01470ef4f328005ea65b0f23112743d03c813 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "ohos.acts.distributeddatamgr.crossplatform.preferences.normal", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/AppScope/resources/base/element/string.json b/distributeddatamgr/crossplatform/preferencesetstest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/crossplatform/preferencesetstest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/crossplatform/preferencesetstest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/crossplatform/preferencesetstest/BUILD.gn b/distributeddatamgr/crossplatform/preferencesetstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..862e73dfc20d47d6fa32b692790adfd5d980e97a --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/BUILD.gn @@ -0,0 +1,50 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsCrossplatformPreferencesTest") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + # hap_name: HAP的名字,可选,默认为目标名 + hap_name = "ActsCrossplatformPreferencesTest" + subsystem_name = "distributeddatamgr" + part_name = "preferences" +} +ohos_app_scope("windowStage_app_profile") { + # app_profile: HAP的AppScope中的app.json,只在Stage模型下使用 + app_profile = "AppScope/app.json" + + # sources: 资源文件路径 + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + # source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录 + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + # sources: 资源文件路径 + sources = [ "src/main/resources" ] + + # deps: 当前目标的依赖 + deps = [ ":windowStage_app_profile" ] + + # hap_profile: HAP的config.json,Stage模型对应module.json + hap_profile = "src/main/module.json" +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/Test.json b/distributeddatamgr/crossplatform/preferencesetstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..fce2b2de3c5e7f346b92cfab10f0fcf8aa4bb0fc --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "ohos.acts.distributeddatamgr.crossplatform.preferences.normal", + "module-name": "preferences_test_normal_ets" + }, + "kits": [ + { + "test-file-name": [ + "ActsCrossplatformPreferencesTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/preferencesetstest/signature/openharmony_sx.p7b b/distributeddatamgr/crossplatform/preferencesetstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..b5dde73b2a23f9851dd72e27fea941911dc94a84 Binary files /dev/null and b/distributeddatamgr/crossplatform/preferencesetstest/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestAbility/TestAbility.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..2529db0904438a4d2889d93d29b847fd7e3de801 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,63 @@ +/* + * 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 UIAbility from "@ohos.app.ability.UIAbility"; +import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry"; +import hilog from "@ohos.hilog"; +import { Hypium } from "@ohos/hypium"; +import testsuite from "../test/List.test"; +import window from "@ohos.window"; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onCreate"); + hilog.info(0x0000, "testTag", "%{public}s", "want param:" + JSON.stringify(want) ?? ""); + hilog.info(0x0000, "testTag", "%{public}s", "launchParam:" + JSON.stringify(launchParam) ?? ""); + var abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!"); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onDestroy"); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageCreate"); + globalThis.abilityContext = this.context; + windowStage.loadContent("TestAbility/pages/Index", (err, data) => { + if (err.code) { + hilog.error(0x0000, "testTag", "Failed to load the content. Cause: %{public}s", JSON.stringify(err) ?? ""); + return; + } + hilog.info(0x0000, "testTag", "Succeeded in loading the content. Data: %{public}s", JSON.stringify(data) ?? ""); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageDestroy"); + } + + onForeground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onForeground"); + } + + onBackground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onBackground"); + } +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestAbility/pages/Index.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..81ee8a0ac420032fea16a51a23dd251308fabc8d --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * 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 hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', '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/crossplatform/preferencesetstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..957b1c28c8563e99ba4d5cf6d8f15588aeea4fe8 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/List.test.ets @@ -0,0 +1,32 @@ +/* + * 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 preferencescallback from './PreferencesCallBack.test' +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' + + + +export default function testsuite() { + preferencescallback() + preferenceshelper() + 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 new file mode 100644 index 0000000000000000000000000000000000000000..c35d9ab59b1aa9fa230322119ceefef50737d5f0 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBack.test.ets @@ -0,0 +1,881 @@ +/* + * 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"; +const KEY_TEST_INT_ELEMENT = "key_test_int"; +const KEY_TEST_LONG_ELEMENT = "key_test_long"; +const KEY_TEST_FLOAT_ELEMENT = "key_test_float"; +const KEY_TEST_BOOLEAN_ELEMENT = "key_test_boolean"; +const KEY_TEST_STRING_ELEMENT = "key_test_string"; +const KEY_TEST_NUMBER_ARRAY_ELEMENT = "key_test_number_array"; +const KEY_TEST_STRING_ARRAY_ELEMENT = "key_test_string_array"; +const KEY_TEST_BOOL_ARRAY_ELEMENT = "key_test_bool_array"; +let mPreferences; +let context; + +const TAG = "[PREFERENCES_CALLBACK_JSUNIT_TEST]"; +export default function preferencesCallBackTest() { + describe("preferencesCallBackTest", 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_0000 + * @tc.name : testPreferencesGetPreferences000 + * @tc.desc : GetPreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesGetPreferences000", 0, async function (done) { + dataPreferences.getPreferences(context, NAME1, async (err, preferences) => { + if (err) { + console.info(TAG + "Get preferences err: " + err); + expect(!err).assertTrue(); + } else { + console.info(TAG + "Get preferences success" + preferences); + await preferences.put(KEY_TEST_STRING_ELEMENT, "test"); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + }); + await dataPreferences.deletePreferences(context, NAME1); + done(); + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_PREFERENCES_0200 + * @tc.name : testPreferencesGetPreferences002 + * @tc.desc : GetPreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesGetPreferences002", 0, async function (done) { + try { + dataPreferences.getPreferences(context, null, (err, preferences) => { + if (err) { + console.info(TAG + "Get preferences err: " + JSON.stringify(err)); + expect(!err).assertTrue(); + done(); + } else { + console.info(TAG + "Get preferences success" + preferences); + done(); + } + }); + } catch (err) { + console.info("testPreferencesGetPreferences002 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_0000 + * @tc.name : testPreferencesDeletePreferences000 + * @tc.desc : DeletePreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeletePreferences000", 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(); + dataPreferences.deletePreferences(context, NAME1, (err) => { + console.info(TAG + "Delete preferences success"); + expect(!err).assertTrue(); + done(); + }); + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_PREFERENCES_0100 + * @tc.name : testPreferencesDeletePreferences001 + * @tc.desc : DeletePreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeletePreferences001", 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 { + dataPreferences.deletePreferences(context, null, (err) => { + if (err) { + console.info(TAG + "Delete preferences err: " + err); + expect(!err).assertTrue(); + done(); + } + }); + } catch (err) { + console.info("testPreferencesDeletePreferences001 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 + * @tc.desc : DeletePreferences callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeletePreferences003", 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 { + preferences.put(KEY_TEST_STRING_ELEMENT, "test"); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + }); + dataPreferences.deletePreferences(context, "getPreferencesTest1", (err) => { + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) { + expect("test").assertEqual(pre); + done(); + }); + }); + } catch (err) { + console.info("testPreferencesDeletePreferences003 fail: " + err.message + "code: " + err.code); + expect(!err).assertTrue(); + done(); + } + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_0000 + * @tc.name : testRemovePreferencesFromCache000 + * @tc.desc : RemovePreferencesFromCache callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCache000", 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(); + dataPreferences.removePreferencesFromCache(context, NAME, (err) => { + console.info(TAG + "Remove preferences from cache success"); + expect(!err).assertTrue(); + done(); + }); + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_0100 + * @tc.name : testRemovePreferencesFromCache001 + * @tc.desc : RemovePreferencesFromCache callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCache001", 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 { + dataPreferences.removePreferencesFromCache(context, null, (err) => { + if (err) { + console.info(TAG + "Remove preferences from cache error: " + err); + expect(!err).assertTrue(); + done(); + } + }); + } catch (err) { + console.info("testRemovePreferencesFromCache001 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 + * @tc.desc : RemovePreferencesFromCache callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCache003", 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 { + preferences.put(KEY_TEST_STRING_ELEMENT, "test"); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + }); + dataPreferences.removePreferencesFromCache(context, "getPreferencesTest1", (err) => { + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) { + expect("test").assertEqual(pre); + done(); + }); + }); + } catch (err) { + console.info("testRemovePreferencesFromCache003 fail: " + err.message + "code: " + err.code); + expect(!err).assertTrue(); + done(); + } + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_DEFAULT_VALUE_0000 + * @tc.name : testPreferencesGetDefaultValue0000 + * @tc.desc : Get defaultValue callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetDefaultValue0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultValue", function (err, ret) { + expect("defaultValue").assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_FLOAT_0000 + * @tc.name : testPreferencesGetFloat0000 + * @tc.desc : Get float callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetFloat0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); + await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0, function (err, ret) { + expect(3.0).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_INT_0000 + * @tc.name : testPreferencesGetInt0000 + * @tc.desc : Get int callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetInt0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_INT_ELEMENT, 3); + await mPreferences.get(KEY_TEST_INT_ELEMENT, 0.0, function (err, ret) { + expect(3).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_LONG_0000 + * @tc.name : testPreferencesGetLong0000 + * @tc.desc : Get long callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetLong0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 3); + await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0, function (err, ret) { + expect(3).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_STRING_0000 + * @tc.name : testPreferencesGetString0000 + * @tc.desc : Get String callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetString0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + await mPreferences.flush(); + await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_BOOLEAN_0000 + * @tc.name : testPreferencesGetBoolean0000 + * @tc.desc : Get Boolean callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetBoolean0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, true); + await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, true, function (err, ret) { + expect(true).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_STRING_ARRAY_0000 + * @tc.name : testPreferencesGetStringArray0000 + * @tc.desc : Get StringArray callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetStringArray0000", 0, async function (done) { + await mPreferences.clear(); + var stringArr = ["11", "22", "33"]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"], function (err, pre) { + for (let i = 0; i < stringArr.length; i++) { + expect(stringArr[i]).assertEqual(pre[i]); + } + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_NUM_ARRAY_0000 + * @tc.name : testPreferencesGetNumArray0000 + * @tc.desc : Get NumArray callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetNumArray0000", 0, async function (done) { + await mPreferences.clear(); + var doubleArr = [11, 22, 33]; + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321], function (err, pre) { + for (let i = 0; i < doubleArr.length; i++) { + expect(doubleArr[i]).assertEqual(pre[i]); + } + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_BOOL_ARRAY_0000 + * @tc.name : testPreferencesGetBoolArray0000 + * @tc.desc : Get BoolArray callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetBoolArray0000", 0, async function (done) { + await mPreferences.clear(); + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [true, false], function (err, pre) { + for (let i = 0; i < boolArr.length; i++) { + expect(boolArr[i]).assertEqual(pre[i]); + } + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_ALL_0000 + * @tc.name : testPreferencesGetAll0000 + * @tc.desc : GetAll callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetAll0000", 0, async function (done) { + await mPreferences.clear(); + let doubleArr = [11, 22, 33]; + let stringArr = ["11", "22", "33"]; + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123"); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1); + + await mPreferences.flush(); + + await mPreferences.getAll(function (err, obj) { + expect(false).assertEqual(obj.key_test_boolean); + expect("123").assertEqual(obj.key_test_string); + expect(123.1).assertEqual(obj.key_test_float); + let sArr = obj.key_test_string_array; + for (let i = 0; i < sArr.length; i++) { + expect(sArr[i]).assertEqual(stringArr[i]); + } + + let bArr = obj.key_test_bool_array; + for (let i = 0; i < bArr.length; i++) { + expect(bArr[i]).assertEqual(boolArr[i]); + } + + let nArr = obj.key_test_number_array; + for (let i = 0; i < nArr.length; i++) { + expect(nArr[i]).assertEqual(doubleArr[i]); + } + + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_FLOAT_0000 + * @tc.name : testPreferencesPutFloat0000 + * @tc.desc : Put float callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutFloat0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 4.0, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(4.0).assertEqual(pre); + await mPreferences.flush(); + let pre2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(4.0).assertEqual(pre2); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_INT_0000 + * @tc.name : testPreferencesPutInt0000 + * @tc.desc : Put int callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutInt0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_INT_ELEMENT, 4, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); + expect(4).assertEqual(pre); + await mPreferences.flush(); + let pre2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); + expect(4).assertEqual(pre2); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_LONG_0000 + * @tc.name : testPreferencesPutLong0000 + * @tc.desc : Put long callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutLong0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 4); + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 4, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); + expect(4).assertEqual(pre); + await mPreferences.flush(); + let pre2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); + expect(4).assertEqual(pre2); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_STRING_0000 + * @tc.name : testPreferencesPutString0000 + * @tc.desc : Put String callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutString0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "", async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(pre); + await mPreferences.flush(); + let pre2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(pre2); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_BOOLEAN_0000 + * @tc.name : testPreferencesPutBoolean0000 + * @tc.desc : Put Boolean callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutBoolean0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, true, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); + expect(true).assertEqual(pre); + await mPreferences.flush(); + let pre2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); + expect(true).assertEqual(pre2); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_STRING_ARRAY_0000 + * @tc.name : testPreferencesPutStringArray0000 + * @tc.desc : Put StringArray callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutStringArray0000", 0, async function (done) { + await mPreferences.clear(); + var stringArr = ["11", "22", "33"]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"]); + for (let i = 0; i < stringArr.length; i++) { + expect(stringArr[i]).assertEqual(pre[i]); + } + + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_NUM_ARRAY_0000 + * @tc.name : testPreferencesPutNumArray0000 + * @tc.desc : Put NumberArray callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutNumArray0000", 0, async function (done) { + await mPreferences.clear(); + var doubleArr = [11, 22, 33]; + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]); + for (let i = 0; i < doubleArr.length; i++) { + expect(doubleArr[i]).assertEqual(pre[i]); + } + + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_BOOL_ARRAY_0000 + * @tc.name : testPreferencesPutBoolArray0000 + * @tc.desc : Put BoolArray callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutBoolArray0000", 0, async function (done) { + await mPreferences.clear(); + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr, async function (err, ret) { + let pre = await mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [true, false]); + for (let i = 0; i < boolArr.length; i++) { + expect(boolArr[i]).assertEqual(pre[i]); + } + + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_0000 + * @tc.name : testPreferencesHasKey0000 + * @tc.desc : Has float callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKey0000", 0, async function (done) { + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 1.1); + await mPreferences.has(KEY_TEST_FLOAT_ELEMENT, function (err, ret) { + expect(true).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_0100 + * @tc.name : testPreferencesHasKey0001 + * @tc.desc : Has int callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKey0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_INT_ELEMENT, 1); + await mPreferences.has(KEY_TEST_INT_ELEMENT, function (err, ret) { + expect(true).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_0200 + * @tc.name : testPreferencesHasKey0002 + * @tc.desc : Has long callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKey0002", 0, async function (done) { + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0); + await mPreferences.has(KEY_TEST_LONG_ELEMENT, function (err, ret) { + expect(true).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_0300 + * @tc.name : testPreferencesHasKey0003 + * @tc.desc : Has string callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKey0003", 0, async function (done) { + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + await mPreferences.has(KEY_TEST_STRING_ELEMENT, function (err, ret) { + expect(true).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_0400 + * @tc.name : testPreferencesHasKey0004 + * @tc.desc : Has boolean callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKey0004", 0, async function (done) { + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.has(KEY_TEST_BOOLEAN_ELEMENT, function (err, ret) { + expect(true).assertEqual(ret); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_CLEAR_0000 + * @tc.name : testPreferencesClear0000 + * @tc.desc : Clear callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesClear0000", 0, async function (done) { + await mPreferences.clear(); + let doubleArr = [11, 22, 33]; + let stringArr = ["11", "22", "33"]; + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123"); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1); + + await mPreferences.flush(); + + let obj = mPreferences.getAllSync(); + expect(false).assertEqual(obj.key_test_boolean); + expect("123").assertEqual(obj.key_test_string); + expect(123.1).assertEqual(obj.key_test_float); + let sArr = obj.key_test_string_array; + for (let i = 0; i < sArr.length; i++) { + expect(sArr[i]).assertEqual(stringArr[i]); + } + + let bArr = obj.key_test_bool_array; + for (let i = 0; i < bArr.length; i++) { + expect(bArr[i]).assertEqual(boolArr[i]); + } + + let nArr = obj.key_test_number_array; + for (let i = 0; i < nArr.length; i++) { + expect(nArr[i]).assertEqual(doubleArr[i]); + } + + await mPreferences.clear(async function (err) { + let ret = mPreferences.getAllSync(); + console.log("testPreferencesClear0000 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); + expect(undefined).assertEqual(ret.key_test_string_array); + expect(undefined).assertEqual(ret.key_test_bool_array); + expect(undefined).assertEqual(ret.key_test_number_array); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_0000 + * @tc.name : testPreferencesDelete0000 + * @tc.desc : Delete callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesDelete0000", 0, async function (done) { + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); + let ret = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(3.0).assertEqual(ret); + await mPreferences.flush(); + mPreferences.delete(KEY_TEST_FLOAT_ELEMENT, async (err, ret) => { + if (err) { + console.info("Failed to delete the key KEY_TEST_STRING_ELEMENT. code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + console.info("Succeeded in deleting the key KEY_TEST_STRING_ELEMENT."); + let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(0.0).assertEqual(per); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_FLUSH_0000 + * @tc.name : testPreferencesFlush0000 + * @tc.desc : Flush callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesFlush0000", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + await mPreferences.flush(); + mPreferences.flush(async function (err, val) { + if (err) { + console.info("Failed to flush. code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + console.info("Succeeded in flushing."); + expect(err === undefined).assertTrue(); + let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("test").assertEqual(per); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_CALLBACK_0000 + * @tc.name : testPreferencesCallback0000 + * @tc.desc : Clear、Put、Get、Flush String callback interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesCallback0000", 0, function (done) { + console.log(TAG + "testPreferencesCallback0000 begin."); + mPreferences.clear(function (err, val) { + if (err) { + expect(!err).assertTrue(); + } + mPreferences.put(KEY_TEST_STRING_ELEMENT, "123", function (err) { + if (err) { + expect(!err).assertTrue(); + } + mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) { + if (err) { + expect(!err).assertTrue(); + } + expect("123").assertEqual(pre); + mPreferences.flush(function (err) { + if (err) { + expect(!err).assertTrue(); + } + mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre2) { + if (err) { + expect(!err).assertTrue(); + } + expect("123").assertEqual(pre2); + done(); + console.log(TAG + "testPreferencesCallback0000 end."); + }); + }); + }); + }); + }); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBackWithError.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBackWithError.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..fb31cabf1a3aa725e54904b37d6b2b4bb60183f0 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesCallBackWithError.test.ets @@ -0,0 +1,476 @@ +/* + * 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_preferences from "@ohos.data.preferences"; + +const NAME = "test_preferences_callback_with_error"; +const KEY_TEST_INT_ELEMENT = "key_test_int"; +const KEY_TEST_STRING_ELEMENT = "key_test_string"; +let mPreference = undefined; +let context; +export default function preferencesCallbackWithErrorTest() { + describe("preferencesCallbackWithErrorTest", async function () { + beforeAll(async function () { + console.info("beforeAll"); + context = globalThis.abilityContext; + mPreference = await data_preferences.getPreferences(context, NAME); + }); + + afterAll(async function () { + console.info("afterAll"); + await data_preferences.deletePreferences(context, NAME); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_CALLBACK_WITH_ERROR_0000 + * @tc.name : testPreferencesCallbackWithError0000 + * @tc.desc : Clear、Put、Has、Delete、Get、Flush String callback interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesCallbackWithError0000", 0, function (done) { + console.log("testPreferencesCallbackWithError0000 begin."); + try { + mPreference.clear(function (err, val) { + if (err) { + console.log("clear err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).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(!err).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(!err).assertTrue(); + } + expect("abc").assertEqual(pre); + mPreference.flush(function (err, val) { + if (err) { + console.log("flush err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + mPreference.delete(KEY_TEST_STRING_ELEMENT, function (err) { + expect(!err).assertTrue(); + console.log("Succeeded in deleting ."); + done(); + console.log("testPreferencesCallbackWithError0000 end."); + }); + }); + }); + }); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_0000 + * @tc.name : testMpreferencesGet0000 + * @tc.desc : mPreference.get callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGet0000", 0, function (done) { + console.log("testMpreferencesGet0000 begin."); + try { + mPreference.get(123, function (err, val) { + console.log("get err"); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + console.log("testMpreferencesGet0000 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_0100 + * @tc.name : testMpreferencesGet0001 + * @tc.desc : mPreference.get callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGet0001", 0, function (done) { + console.log("testMpreferencesGet0001 begin."); + try { + mPreference.get(-1, 123, function (err, val) { + if (err) { + console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + done(); + console.log("testMpreferencesGet0001 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_0200 + * @tc.name : testMpreferencesGet0002 + * @tc.desc : mPreference.get callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGet0002", 0, async function (done) { + console.log("testMpreferencesGet0002 begin."); + try { + await mPreference.put(KEY_TEST_INT_ELEMENT, 3); + mPreference.get(KEY_TEST_STRING_ELEMENT, 123, function (err, val) { + if (err) { + console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + expect(val !== 3).assertTrue(); + done(); + console.log("testMpreferencesGet0002 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_ALL_0000 + * @tc.name : testMpreferencesGetALL0000 + * @tc.desc : mPreference.getAll callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetALL0000", 0, function (done) { + console.log("testMpreferencesGetALL0000 begin."); + try { + mPreference.getAll(function (err, val) { + if (err) { + console.log("getAll err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesGetALL0000 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_HAS_0100 + * @tc.name : testMpreferencesHas0001 + * @tc.desc : mPreference.has callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesHas0001", 0, function (done) { + console.log("testMpreferencesHas0001 begin."); + try { + mPreference.has(123, function (err, val) { + console.log("has err"); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + console.log("testMpreferencesHas0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_HAS_0200 + * @tc.name : testMpreferencesHas0002 + * @tc.desc : mPreference.has callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesHas0002", 0, function (done) { + console.log("testMpreferencesHas0002 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(!err).assertTrue(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesHas0002 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_0100 + * @tc.name : testMpreferencesPut0001 + * @tc.desc : mPreference.put callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPut0001", 0, function (done) { + console.log("testMpreferencesPut0001 begin."); + try { + mPreference.put(123, function (err) { + console.log("put err"); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + console.log("testMpreferencesPut0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_0200 + * @tc.name : testMpreferencesPut0002 + * @tc.desc : mPreference.put callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPut0002", 0, function (done) { + console.log("testMpreferencesPut0002 begin."); + try { + mPreference.put(KEY_TEST_STRING_ELEMENT, "", async (err) => { + if (err) { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + let pre = await mPreference.get(KEY_TEST_STRING_ELEMENT, "123"); + expect(pre === "").assertTrue(); + done(); + console.log("testMpreferencesPut0002 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_0300 + * @tc.name : testMpreferencesPut0003 + * @tc.desc : mPreference.put callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPut0003", 0, function (done) { + console.log("testMpreferencesPut0003 begin."); + try { + mPreference.put(KEY_TEST_STRING_ELEMENT, " ", async (err) => { + if (err) { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + let pre = await mPreference.get(KEY_TEST_STRING_ELEMENT, "123"); + expect(pre === " ").assertTrue(); + done(); + console.log("testMpreferencesPut0003 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_0400 + * @tc.name : testMpreferencesPut0004 + * @tc.desc : mPreference.put callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPut0004", 0, function (done) { + console.log("testMpreferencesPut0004 begin."); + try { + mPreference.put(-1, 123, function (err) { + if (err) { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesPut0004 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_0500 + * @tc.name : testMpreferencesPut0005 + * @tc.desc : mPreference.put callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPut0005", 0, function (done) { + console.log("testMpreferencesPut0005 begin."); + try { + mPreference.put(KEY_TEST_STRING_ELEMENT, null, function (err) { + if (err) { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesPut0005 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be ValueType.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_DELETE_0100 + * @tc.name : testMpreferencesDelete0001 + * @tc.desc : mPreference.delete callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesDelete0001", 0, function (done) { + console.log("testMpreferencesDelete0001 begin."); + try { + mPreference.delete(1233, function (err) { + console.log("delete err"); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + console.log("testMpreferencesDelete0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_DELETE_0200 + * @tc.name : testMpreferencesDelete0002 + * @tc.desc : mPreference.delete callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesDelete0002", 0, function (done) { + console.log("testMpreferencesDelete0002 begin."); + try { + mPreference.delete(KEY_TEST_STRING_ELEMENT, function (err) { + if (err) { + console.log("delete err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesDelete0002 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_CLEAR_0100 + * @tc.name : testMpreferencesClear0001 + * @tc.desc : mPreference.clear callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesClear0001", 0, function (done) { + console.log("testMpreferencesClear0001 begin."); + try { + mPreference.clear(function (err) { + if (err) { + console.log("clear err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesClear0001 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_FLUSH_0100 + * @tc.name : testMpreferencesFlush0001 + * @tc.desc : mPreference.flush callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesFlush0001", 0, function (done) { + console.log("testMpreferencesFlush0001 begin."); + try { + mPreference.flush(function (err) { + if (err) { + console.log("flush err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + expect(!err).assertTrue(); + done(); + console.log("testMpreferencesFlush0001 end."); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + }); +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f74af00f990f18d567daaa9df89732ba454216a --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesHelper.test.ets @@ -0,0 +1,410 @@ +/* + * 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 KEY_TEST_STRING_ELEMENT = "key_test_string"; +const KEY_TEST_INT_ELEMENT = "key_test_int"; +let mPreferences; +let context; +export default function preferencesHelperTest() { + describe("preferencesHelperTest", 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); + }); + + function sleep(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); + } + + /** + * @tc.number : SUB_DDM_TEST_GET_PREFERENCES_HELPER_0100 + * @tc.name : testGetPreferencesHelper0001 + * @tc.desc : GetPreferencesSync interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetPreferencesHelper0001", 0, async function () { + mPreferences = await dataPreferences.getPreferences(context, NAME); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + await mPreferences.flush(); + var value = await mPreferences.get(KEY_TEST_STRING_ELEMENT, 0); + expect(value).assertEqual("test"); + }); + + /** + * @tc.number : SUB_DDM_TEST_GET_PREFERENCES_HELPER_0200 + * @tc.name : testGetPreferencesHelper0002 + * @tc.desc : GetPreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetPreferencesHelper0002", 0, async function (done) { + const promise = dataPreferences.getPreferences(context, NAME); + let preferences = null; + promise + .then(async (pref) => { + preferences = pref; + await preferences.put(KEY_TEST_STRING_ELEMENT, "test"); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + }); + await dataPreferences.deletePreferences(context, NAME); + console.info("Succeeded in getting preferences."); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0100 + * @tc.name : testRemovePreferencesFromCacheHelper0001 + * @tc.desc : RemovePreferencesFromCache interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCacheHelper0001", 0, async function (done) { + let preferences = null; + preferences = await dataPreferences.getPreferences(context, NAME); + const promise = dataPreferences.removePreferencesFromCache(context, NAME); + promise + .then(() => { + console.info("Succeeded in removing preferences."); + expect("{}").assertEqual(JSON.stringify(preferences)); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_REMOVE_PREFERENCES_FROM_CACHE_HELPER_0400 + * @tc.name : testRemovePreferencesFromCacheHelper0004 + * @tc.desc : RemovePreferencesFromCache interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRemovePreferencesFromCacheHelper0004", 0, async function (done) { + let preferences = null; + preferences = await dataPreferences.getPreferences(context, NAME); + await preferences.put(KEY_TEST_STRING_ELEMENT, "test"); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + }); + dataPreferences + .removePreferencesFromCache(context, "test_preferences1") + .then(() => { + console.info("Succeeded in removing preferences."); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) { + expect("test").assertEqual(pre); + done(); + }); + }) + .catch((err) => { + console.info("Remove preferences from cache error: " + err); + expect(!err).assertTrue(); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0100 + * @tc.name : testPreferencesDeleteHelper0001 + * @tc.desc : DeletePreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeleteHelper0001", 0, async function (done) { + let preferences = null; + preferences = await dataPreferences.getPreferences(context, NAME); + const promise = dataPreferences.deletePreferences(context, NAME); + promise + .then(() => { + console.info("Succeeded in deleting preferences."); + expect("{}").assertEqual(JSON.stringify(preferences)); + done(); + }) + .catch((err) => { + console.info("Delete preferences err: " + err); + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_HELPER_0400 + * @tc.name : testPreferencesDeleteHelper0004 + * @tc.desc : DeletePreferences interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesDeleteHelper0004", 0, async function (done) { + let preferences = null; + preferences = await dataPreferences.getPreferences(context, NAME); + await preferences.put(KEY_TEST_STRING_ELEMENT, "test"); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, ret) { + expect("test").assertEqual(ret); + }); + dataPreferences + .deletePreferences(context, "test_preferences1") + .then(() => { + console.info("Succeeded in deleting preferences."); + preferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue", function (err, pre) { + expect("test").assertEqual(pre); + done(); + }); + }) + .catch((err) => { + console.info("Delete preferences err: " + err); + expect(!err).assertTrue(); + done(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_MAX_KEY_LENGTH_0100 + * @tc.name : testMaxKeyLength001 + * @tc.desc : Test key length + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 0 + */ + it("testMaxKeyLength001", 0, function () { + expect(dataPreferences.MAX_KEY_LENGTH == 80).assertTrue(); + }); + + /** + * @tc.number : SUB_DDM_TEST_MAX_VALUE_LENGTH_0100 + * @tc.name : testMaxValueLength001 + * @tc.desc : Test value length + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 0 + */ + it("testMaxValueLength001", 0, function () { + expect(dataPreferences.MAX_VALUE_LENGTH == 8192).assertTrue(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_ON_0100 + * @tc.name : testPreferencesOn001 + * @tc.desc : Test on interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOn001", 0, async function () { + try { + await mPreferences.clear(); + var observer = function (key) { + console.info("testPreferencesOn001 key " + key); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); + }; + mPreferences.on("change", observer); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "abcd"); + await mPreferences.flush(); + } catch (err) { + console.info("Failed to testPreferencesOn001. code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_ON_0200 + * @tc.name : testPreferencesOn002 + * @tc.desc : Test on interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOn002", 0, async function () { + try { + await mPreferences.clear(); + var observer = function (key) { + console.info("testPreferencesOn002 key " + key); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); + }; + mPreferences.on("change"); + } catch (err) { + console.info("Failed to testPreferencesOn002. code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 parameters!").assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_ON_0300 + * @tc.name : testPreferencesOn003 + * @tc.desc : Test on interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOn003", 0, async function () { + try { + await mPreferences.clear(); + var observer = function (key) { + console.info("testPreferencesOn003 key " + key); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); + }; + mPreferences.on(null, observer); + } catch (err) { + console.info("Failed to testPreferencesOn003. code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'type' must be string 'change'.").assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_ON_0400 + * @tc.name : testPreferencesOn004 + * @tc.desc : Test on interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOn004", 0, async function () { + try { + await mPreferences.clear(); + var observer = function (key) { + console.info("testPreferencesOn004 key " + key); + expect(KEY_TEST_STRING_ELEMENT).assertEqual(key); + }; + mPreferences.on("", observer); + } catch (err) { + console.info("Failed to testPreferencesOn004. code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'type' must be string 'change'.").assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_OFF_0100 + * @tc.name : testPreferencesOff001 + * @tc.desc : Test off interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOff001", 0, async function () { + try { + await mPreferences.clear(); + let isTrigger = false; + var observer = function (key) { + console.info("testPreferencesOff001 key" + key); + isTrigger = true; + }; + mPreferences.on("change", observer); + mPreferences.off("change", observer); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "abc"); + await mPreferences.flush(); + await sleep(1000); + expect(isTrigger === false).assertTrue(); + } catch (err) { + console.info("Failed to testPreferencesOff001. code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_OFF_0200 + * @tc.name : testPreferencesOff002 + * @tc.desc : Test off interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOff002", 0, async function () { + try { + await mPreferences.clear(); + let isTrigger = false; + var observer = function (key) { + console.info("testPreferencesOff001 key" + key); + isTrigger = true; + }; + mPreferences.on("change", observer); + mPreferences.off("change"); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "abc"); + await mPreferences.flush(); + await sleep(1000); + expect(isTrigger === false).assertTrue(); + } catch (err) { + console.info("Failed to testPreferencesOff001. code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_OFF_0300 + * @tc.name : testPreferencesOff003 + * @tc.desc : Test off interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOff003", 0, async function () { + try { + await mPreferences.clear(); + let isTrigger = false; + var observer = function (key) { + console.info("testPreferencesOff003 key" + key); + isTrigger = true; + }; + mPreferences.on("change", observer); + mPreferences.off(null); + } catch (err) { + console.info("Failed to testPreferencesOff003. code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'type' must be string 'change'.").assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_OFF_0400 + * @tc.name : testPreferencesOff004 + * @tc.desc : Test off interface + * @tc.size : MediumTest + * @tc.type : Constant + * @tc.level : Level 2 + */ + it("testPreferencesOff004", 0, async function () { + try { + await mPreferences.clear(); + let isTrigger = false; + var observer = function (key) { + console.info("testPreferencesOff004 key" + key); + isTrigger = true; + }; + mPreferences.on("change", observer); + mPreferences.off(""); + } catch (err) { + console.info("Failed to testPreferencesOff004. code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'type' must be string 'change'.").assertTrue(); + } + }); + }); +} 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 0000000000000000000000000000000000000000..8747ca552a44128b3c98e9a3259a7deedd36291b --- /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 new file mode 100644 index 0000000000000000000000000000000000000000..59067d415c96785457ecf07fc534c48488750a76 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromise.test.ets @@ -0,0 +1,1191 @@ +/* + * 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 KEY_TEST_INT_ELEMENT = "key_test_int"; +const KEY_TEST_LONG_ELEMENT = "key_test_long"; +const KEY_TEST_FLOAT_ELEMENT = "key_test_float"; +const KEY_TEST_BOOLEAN_ELEMENT = "key_test_boolean"; +const KEY_TEST_STRING_ELEMENT = "key_test_string"; +const KEY_TEST_NUMBER_ARRAY_ELEMENT = "key_test_number_array"; +const KEY_TEST_STRING_ARRAY_ELEMENT = "key_test_string_array"; +const KEY_TEST_BOOL_ARRAY_ELEMENT = "key_test_bool_array"; +let mPreferences; +let context; + +export default function preferencesPromiseTest() { + describe("preferencesPromiseTest", 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_DEF_VALUE_PROMISE_0100 + * @tc.name : testPreferencesGetDefValuePromise0001 + * @tc.desc : Get defaultValue promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetDefValuePromise0001", 0, async function (done) { + await mPreferences.clear(); + const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultValue"); + promise + .then((ret) => { + expect("defaultValue").assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_FLOAT_PROMISE_0100 + * @tc.name : testPreferencesGetFloatPromise0001 + * @tc.desc : Get float promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetFloatPromise0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); + const promise = mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + promise + .then((ret) => { + expect(3.0).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_INT_PROMISE_0100 + * @tc.name : testPreferencesGetIntPromise0001 + * @tc.desc : Get int promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetIntPromise0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_INT_ELEMENT, 3); + const promise = mPreferences.get(KEY_TEST_INT_ELEMENT, 0); + promise + .then((ret) => { + expect(3).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_LONG_PROMISE_0100 + * @tc.name : testPreferencesGetLongPromise0001 + * @tc.desc : Get long promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetLongPromise0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 3); + const promise = mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); + promise + .then((ret) => { + expect(3).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_STRING_PROMISE_0100 + * @tc.name : testPreferencesGetStringPromise0001 + * @tc.desc : Get string promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetStringPromise0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + await mPreferences.flush(); + const promise = mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + promise + .then((ret) => { + expect("test").assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_BOOLEAN_PROMISE_0100 + * @tc.name : testPreferencesGetBooleanPromise0001 + * @tc.desc : Get boolean promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetBooleanPromise0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, true); + let promise = mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, true); + promise + .then((ret) => { + expect(true).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_STRING_ARRAY_PROMISE_0100 + * @tc.name : testPreferencesGetStringArrayPromise0001 + * @tc.desc : Get StringArray promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetStringArrayPromise0001", 0, async function (done) { + await mPreferences.clear(); + var stringArr = ["11", "22", "33"]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + let promise = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"]); + promise + .then((pre) => { + for (let i = 0; i < stringArr.length; i++) { + expect(stringArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_NUM_ARRAY_PROMISE_0100 + * @tc.name : testPreferencesGetNumArrayPromise0001 + * @tc.desc : Get NumArray promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetNumArrayPromise0001", 0, async function (done) { + await mPreferences.clear(); + var doubleArr = [11, 22, 33]; + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + let promise = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]); + promise + .then((pre) => { + for (let i = 0; i < doubleArr.length; i++) { + expect(doubleArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_BOOL_ARRAY_PROMISE_0100 + * @tc.name : testPreferencesGetBoolArrayPromise0001 + * @tc.desc : Get BoolArray promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetBoolArrayPromise0001", 0, async function (done) { + await mPreferences.clear(); + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + let promise = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [true, false]); + promise + .then((pre) => { + for (let i = 0; i < boolArr.length; i++) { + expect(boolArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_DEFAULT_VALUE_0100 + * @tc.name : testPreferencesGetSyncDefaultValue0001 + * @tc.desc : GetSync defaultValue interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncDefaultValue0001", 0, async function (done) { + await mPreferences.clear(); + let ret = mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "defaultValue"); + expect("defaultValue").assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_FLOAT_0100 + * @tc.name : testPreferencesGetSyncFloat0001 + * @tc.desc : GetSync float interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncFloat0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); + let ret = mPreferences.getSync(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(3.0).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_INT_0100 + * @tc.name : testPreferencesGetSyncInt0001 + * @tc.desc : GetSync int interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncInt0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_INT_ELEMENT, 3); + let ret = mPreferences.getSync(KEY_TEST_INT_ELEMENT, 0); + expect(3).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_LONG_0100 + * @tc.name : testPreferencesGetSyncLong0001 + * @tc.desc : GetSync long interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncLong0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 3); + let ret = mPreferences.getSync(KEY_TEST_LONG_ELEMENT, 0); + expect(3).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_STRING_0100 + * @tc.name : testPreferencesGetSyncString0001 + * @tc.desc : GetSync string interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncString0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + let ret = mPreferences.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("test").assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_BOOLEAN_0100 + * @tc.name : testPreferencesGetSyncBoolean0001 + * @tc.desc : GetSync string interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncBoolean0001", 0, async function (done) { + await mPreferences.clear(); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, true); + let ret = mPreferences.getSync(KEY_TEST_STRING_ELEMENT, true); + expect(true).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_STRING_ARRAY_0100 + * @tc.name : testPreferencesGetSyncStringArray0001 + * @tc.desc : GetSync stringArray interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncBoolean0001", 0, async function (done) { + await mPreferences.clear(); + var stringArr = ["11", "22", "33"]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + let ret = mPreferences.getSync(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"]); + for (let i = 0; i < stringArr.length; i++) { + expect(stringArr[i]).assertEqual(ret[i]); + } + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_NUM_ARRAY_0100 + * @tc.name : testPreferencesGetSyncNumArray0001 + * @tc.desc : GetSync numArray interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncBoolean0001", 0, async function (done) { + await mPreferences.clear(); + var doubleArr = [11, 22, 33]; + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + let ret = mPreferences.getSync(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]); + for (let i = 0; i < doubleArr.length; i++) { + expect(doubleArr[i]).assertEqual(ret[i]); + } + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_SYNC_BOOL_ARRAY_0100 + * @tc.name : testPreferencesGetSyncBoolArray0001 + * @tc.desc : GetSync boolArray interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetSyncBoolArray0001", 0, async function (done) { + await mPreferences.clear(); + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + let ret = mPreferences.getSync(KEY_TEST_BOOL_ARRAY_ELEMENT, [true, false]); + for (let i = 0; i < boolArr.length; i++) { + expect(boolArr[i]).assertEqual(ret[i]); + } + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_ALL_PROMISE_0100 + * @tc.name : testPreferencesGetAllPromise0001 + * @tc.desc : GetAll promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetAllPromise0001", 0, async function (done) { + await mPreferences.clear(); + let doubleArr = [11, 22, 33]; + let stringArr = ["11", "22", "33"]; + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123"); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1); + + await mPreferences.flush(); + + let promise = mPreferences.getAll(); + promise + .then((obj) => { + expect(false).assertEqual(obj.key_test_boolean); + expect("123").assertEqual(obj.key_test_string); + expect(123.1).assertEqual(obj.key_test_float); + let sArr = obj.key_test_string_array; + for (let i = 0; i < sArr.length; i++) { + expect(sArr[i]).assertEqual(stringArr[i]); + } + + let bArr = obj.key_test_bool_array; + for (let i = 0; i < bArr.length; i++) { + expect(bArr[i]).assertEqual(boolArr[i]); + } + + let nArr = obj.key_test_number_array; + for (let i = 0; i < nArr.length; i++) { + expect(nArr[i]).assertEqual(doubleArr[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_GET_ALL_SYNC_0100 + * @tc.name : testPreferencesGetAllSync0001 + * @tc.desc : GetAllSync interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesGetAllSync0001", 0, async function (done) { + await mPreferences.clear(); + let doubleArr = [11, 22, 33]; + let stringArr = ["11", "22", "33"]; + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123"); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1); + + await mPreferences.flush(); + + let obj = mPreferences.getAllSync(); + expect(false).assertEqual(obj.key_test_boolean); + expect("123").assertEqual(obj.key_test_string); + expect(123.1).assertEqual(obj.key_test_float); + let sArr = obj.key_test_string_array; + for (let i = 0; i < sArr.length; i++) { + expect(sArr[i]).assertEqual(stringArr[i]); + } + + let bArr = obj.key_test_bool_array; + for (let i = 0; i < bArr.length; i++) { + expect(bArr[i]).assertEqual(boolArr[i]); + } + + let nArr = obj.key_test_number_array; + for (let i = 0; i < nArr.length; i++) { + expect(nArr[i]).assertEqual(doubleArr[i]); + } + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_FLOAT_PROMISE_0100 + * @tc.name : testPreferencesPutFloatPromise0001 + * @tc.desc : Put float promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutFloatPromise0001", 0, async function (done) { + await mPreferences.clear(); + 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(); + let per2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(4.0).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_INT_PROMISE_0100 + * @tc.name : testPreferencesPutIntPromise0001 + * @tc.desc : Put int promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutIntPromise0001", 0, async function (done) { + await mPreferences.clear(); + 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(); + let per2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); + expect(4).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_LONG_PROMISE_0100 + * @tc.name : testPreferencesPutLongPromise0001 + * @tc.desc : Put long promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutLongPromise0001", 0, async function (done) { + 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(); + let per2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); + expect(4).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_STRING_PROMISE_0100 + * @tc.name : testPreferencesPutStringPromise0001 + * @tc.desc : Put string promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutStringPromise0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_STRING_ELEMENT, ""); + let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(per); + await mPreferences.flush(); + let per2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_BOOLEAN_PROMISE_0100 + * @tc.name : testPreferencesPutBooleanPromise0001 + * @tc.desc : Put boolean promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutBooleanPromise0001", 0, async function (done) { + await mPreferences.clear(); + 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(); + let per2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); + expect(true).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_STRING_ARRAY_PROMISE_0100 + * @tc.name : testPreferencesPutStringArrayPromise0001 + * @tc.desc : Put StringArray promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutStringArrayPromise0001", 0, async function (done) { + await mPreferences.clear(); + var stringArr = ["1", "2", "3"]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + let promise2 = mPreferences.get(KEY_TEST_STRING_ARRAY_ELEMENT, ["123", "321"]); + promise2 + .then((pre) => { + for (let i = 0; i < stringArr.length; i++) { + expect(stringArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_NUM_ARRAY_PROMISE_0100 + * @tc.name : testPreferencesPutNumArrayPromise0001 + * @tc.desc : Put NumberArray promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutNumArrayPromise0001", 0, async function (done) { + await mPreferences.clear(); + var numberArr = [11, 22, 33, 44, 55]; + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, numberArr); + let promise2 = mPreferences.get(KEY_TEST_NUMBER_ARRAY_ELEMENT, [123, 321]); + promise2 + .then((pre) => { + for (let i = 0; i < numberArr.length; i++) { + expect(numberArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_BOOL_ARRAY_PROMISE_0100 + * @tc.name : testPreferencesPutBoolArrayPromise0001 + * @tc.desc : Put BoolArray promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutBoolArrayPromise0001", 0, async function (done) { + await mPreferences.clear(); + var boolArr = [true, true, false]; + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + let promise2 = mPreferences.get(KEY_TEST_BOOL_ARRAY_ELEMENT, [false, true]); + promise2 + .then((pre) => { + for (let i = 0; i < boolArr.length; i++) { + expect(boolArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_FLOAT_0100 + * @tc.name : testPreferencesPutSyncFloat0001 + * @tc.desc : PutSync float interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncFloat0001", 0, async function (done) { + await mPreferences.clear(); + mPreferences.putSync(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(); + let per2 = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(4.0).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_INT_0100 + * @tc.name : testPreferencesPutSyncInt0001 + * @tc.desc : PutSync int interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncInt0001", 0, async function (done) { + await mPreferences.clear(); + mPreferences.putSync(KEY_TEST_INT_ELEMENT, 4); + let per = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); + expect(4).assertEqual(per); + await mPreferences.flush(); + let per2 = await mPreferences.get(KEY_TEST_INT_ELEMENT, 0); + expect(4).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_LONG_0100 + * @tc.name : testPreferencesPutSyncLong0001 + * @tc.desc : PutSync long interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncLong0001", 0, async function (done) { + mPreferences.putSync(KEY_TEST_LONG_ELEMENT, 4); + let per = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); + expect(4).assertEqual(per); + await mPreferences.flush(); + let per2 = await mPreferences.get(KEY_TEST_LONG_ELEMENT, 0); + expect(4).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_STRING_0100 + * @tc.name : testPreferencesPutSyncString0001 + * @tc.desc : PutSync string interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncString0001", 0, async function (done) { + mPreferences.putSync(KEY_TEST_STRING_ELEMENT, ""); + let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(per); + await mPreferences.flush(); + let per2 = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_BOOLEAN_0100 + * @tc.name : testPreferencesPutSyncBoolean0001 + * @tc.desc : PutSync boolean interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncBoolean0001", 0, async function (done) { + await mPreferences.clear(); + mPreferences.putSync(KEY_TEST_BOOLEAN_ELEMENT, true); + let per = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); + expect(true).assertEqual(per); + await mPreferences.flush(); + let per2 = await mPreferences.get(KEY_TEST_BOOLEAN_ELEMENT, false); + expect(true).assertEqual(per2); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_STRING_ARRAY_0100 + * @tc.name : testPreferencesPutSyncStringArray0001 + * @tc.desc : PutSync StringArray interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncStringArray0001", 0, async function (done) { + await mPreferences.clear(); + 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++) { + expect(stringArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_NUM_ARRAY_0100 + * @tc.name : testPreferencesPutSyncNumArray0001 + * @tc.desc : PutSync NumberArray interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncNumArray0001", 0, async function (done) { + await mPreferences.clear(); + 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++) { + expect(numberArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PUT_SYNC_BOOL_ARRAY_0100 + * @tc.name : testPreferencesPutSyncBoolArray0001 + * @tc.desc : PutSync BoolArray interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesPutSyncBoolArray0001", 0, async function (done) { + await mPreferences.clear(); + 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++) { + expect(boolArr[i]).assertEqual(pre[i]); + } + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_PROMISE_0100 + * @tc.name : testPreferencesHasKeyPromise0001 + * @tc.desc : Has float promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKeyPromise0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 2.0); + const promise = mPreferences.has(KEY_TEST_FLOAT_ELEMENT); + promise + .then((ret) => { + expect(true).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_PROMISE_0100 + * @tc.name : testPreferencesHasKeyPromise0002 + * @tc.desc : Has int promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKeyPromise0002", 0, async function (done) { + await mPreferences.put(KEY_TEST_INT_ELEMENT, 1); + const promise = mPreferences.has(KEY_TEST_INT_ELEMENT); + promise + .then((ret) => { + expect(true).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_PROMISE_0100 + * @tc.name : testPreferencesHasKeyPromise0003 + * @tc.desc : Has long promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKeyPromise0003", 0, async function (done) { + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0); + const promise = mPreferences.has(KEY_TEST_LONG_ELEMENT); + promise + .then((ret) => { + expect(true).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_PROMISE_0100 + * @tc.name : testPreferencesHasKeyPromise0004 + * @tc.desc : Has string promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKeyPromise0004", 0, async function (done) { + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + const promise = mPreferences.has(KEY_TEST_STRING_ELEMENT); + promise + .then((ret) => { + expect(true).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_KEY_PROMISE_0100 + * @tc.name : testPreferencesHasKeyPromise0005 + * @tc.desc : Has boolean promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasKeyPromise0005", 0, async function (done) { + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + const promise = mPreferences.has(KEY_TEST_BOOLEAN_ELEMENT); + promise + .then((ret) => { + expect(true).assertEqual(ret); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_SYNC_0100 + * @tc.name : testPreferencesHasSync0001 + * @tc.desc : HasSync float interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasSync0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 2.0); + let ret = mPreferences.hasSync(KEY_TEST_FLOAT_ELEMENT); + expect(true).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_SYNC_0200 + * @tc.name : testPreferencesHasSync0002 + * @tc.desc : HasSync int interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasSync0002", 0, async function (done) { + await mPreferences.put(KEY_TEST_INT_ELEMENT, 1); + let ret = mPreferences.hasSync(KEY_TEST_INT_ELEMENT); + expect(true).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_SYNC_0300 + * @tc.name : testPreferencesHasSync0003 + * @tc.desc : HasSync long interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasSync0003", 0, async function (done) { + await mPreferences.put(KEY_TEST_LONG_ELEMENT, 0); + let ret = mPreferences.hasSync(KEY_TEST_LONG_ELEMENT); + expect(true).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_SYNC_0400 + * @tc.name : testPreferencesHasSync0004 + * @tc.desc : HasSync string interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + 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); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_HAS_SYNC_0500 + * @tc.name : testPreferencesHasSync0005 + * @tc.desc : HasSync boolean interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesHasSync0005", 0, async function (done) { + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + let ret = mPreferences.hasSync(KEY_TEST_BOOLEAN_ELEMENT); + expect(true).assertEqual(ret); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_CLEAR_PROMISE_0100 + * @tc.name : testPreferencesClearPromise0001 + * @tc.desc : Clear promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesClearPromise0001", 0, async function (done) { + await mPreferences.clear(); + let doubleArr = [11, 22, 33]; + let stringArr = ["11", "22", "33"]; + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123"); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1); + + await mPreferences.flush(); + + let obj = mPreferences.getAllSync(); + expect(false).assertEqual(obj.key_test_boolean); + expect("123").assertEqual(obj.key_test_string); + expect(123.1).assertEqual(obj.key_test_float); + let sArr = obj.key_test_string_array; + for (let i = 0; i < sArr.length; i++) { + expect(sArr[i]).assertEqual(stringArr[i]); + } + + let bArr = obj.key_test_bool_array; + for (let i = 0; i < bArr.length; i++) { + expect(bArr[i]).assertEqual(boolArr[i]); + } + + let nArr = obj.key_test_number_array; + for (let i = 0; i < nArr.length; i++) { + expect(nArr[i]).assertEqual(doubleArr[i]); + } + + const promise = mPreferences.clear(); + promise + .then(async () => { + let ret = mPreferences.getAllSync(); + console.log("testPreferencesClearPromise0001 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); + expect(undefined).assertEqual(ret.key_test_string_array); + expect(undefined).assertEqual(ret.key_test_bool_array); + expect(undefined).assertEqual(ret.key_test_number_array); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_CLEAR_SYNC_0100 + * @tc.name : testPreferencesClearSync0001 + * @tc.desc : ClearSync interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesClearSync0001", 0, async function (done) { + await mPreferences.clear(); + let doubleArr = [11, 22, 33]; + let stringArr = ["11", "22", "33"]; + let boolArr = [true, false, false, true]; + await mPreferences.put(KEY_TEST_STRING_ARRAY_ELEMENT, stringArr); + await mPreferences.put(KEY_TEST_BOOL_ARRAY_ELEMENT, boolArr); + await mPreferences.put(KEY_TEST_NUMBER_ARRAY_ELEMENT, doubleArr); + await mPreferences.put(KEY_TEST_BOOLEAN_ELEMENT, false); + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "123"); + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 123.1); + + await mPreferences.flush(); + + let obj = mPreferences.getAllSync(); + expect(false).assertEqual(obj.key_test_boolean); + expect("123").assertEqual(obj.key_test_string); + expect(123.1).assertEqual(obj.key_test_float); + let sArr = obj.key_test_string_array; + for (let i = 0; i < sArr.length; i++) { + expect(sArr[i]).assertEqual(stringArr[i]); + } + + let bArr = obj.key_test_bool_array; + for (let i = 0; i < bArr.length; i++) { + expect(bArr[i]).assertEqual(boolArr[i]); + } + + let nArr = obj.key_test_number_array; + for (let i = 0; i < nArr.length; i++) { + expect(nArr[i]).assertEqual(doubleArr[i]); + } + + mPreferences.clearSync(); + let ret = mPreferences.getAllSync(); + 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); + expect(undefined).assertEqual(ret.key_test_string_array); + expect(undefined).assertEqual(ret.key_test_bool_array); + expect(undefined).assertEqual(ret.key_test_number_array); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_PROMISE_0100 + * @tc.name : testPreferencesDeletePromise0001 + * @tc.desc : Delete promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesDeletePromise0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); + let ret = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(3.0).assertEqual(ret); + await mPreferences.flush(); + const promise = mPreferences.delete(KEY_TEST_FLOAT_ELEMENT); + promise + .then(async () => { + let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(0.0).assertEqual(per); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_DELETE_SYNC_0100 + * @tc.name : testPreferencesDeleteSync0001 + * @tc.desc : DeleteSync interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesDeleteSync0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_FLOAT_ELEMENT, 3.0); + let ret = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(3.0).assertEqual(ret); + await mPreferences.flush(); + mPreferences.deleteSync(KEY_TEST_FLOAT_ELEMENT); + let per = await mPreferences.get(KEY_TEST_FLOAT_ELEMENT, 0.0); + expect(0.0).assertEqual(per); + done(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_FLUSH_PROMISE_0100 + * @tc.name : testPreferencesFlushPromise0001 + * @tc.desc : Flush promise interface test + * @tc.size : MediumTest + * @tc.type : Method + * @tc.level : Level 2 + */ + it("testPreferencesFlushPromise0001", 0, async function (done) { + await mPreferences.put(KEY_TEST_STRING_ELEMENT, "test"); + await mPreferences.flush(); + const promise = mPreferences.flush(); + promise.then(async () => { + let per = await mPreferences.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("test").assertEqual(per); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + }); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..b9951029f03d52728f1fc44ceb39437d2f573b1f --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/ets/test/PreferencesPromiseWithError.test.ets @@ -0,0 +1,701 @@ +/* + * 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_preferences from "@ohos.data.preferences"; + +const NAME = "test_preferences_promise_with_error"; +const KEY_TEST_INT_ELEMENT = "key_test_int"; +const KEY_TEST_STRING_ELEMENT = "key_test_string"; +let mPreference; +let context; +export default function preferencesPromiseWithErrorTest() { + describe("preferencesPromiseWithErrorTest", async function () { + beforeAll(async function () { + console.info("beforeAll"); + context = globalThis.abilityContext; + mPreference = await data_preferences.getPreferences(context, NAME); + }); + + afterAll(async function () { + console.info("afterAll"); + await data_preferences.deletePreferences(context, NAME); + }); + + beforeEach(async function () { + console.info("beforeEach"); + await mPreference.clear(); + await mPreference.flush(); + }); + + /** + * @tc.number : SUB_DDM_TEST_PREFERENCES_PROMISE_WITH_ERROR_0100 + * @tc.name : testPreferencesPromiseWithError0001 + * @tc.desc : Clear、Delete、Put、Get、Flush promise interface test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testPreferencesPromiseWithError0001", 0, async function (done) { + console.log("testPreferencesPromiseWithError0001 begin."); + try { + if (mPreference === undefined) { + console.log("mPreference undefined"); + } + mPreference + .clear() + .then(async () => { + mPreference + .put(KEY_TEST_INT_ELEMENT, 123) + .then(async (ret) => { + mPreference + .get(KEY_TEST_INT_ELEMENT, 123) + .then(async (pre) => { + expect(123).assertEqual(pre); + mPreference + .flush() + .then(async () => { + mPreference + .delete(KEY_TEST_INT_ELEMENT) + .then(async () => { + console.log("Succeeded in deleting ."); + let per = await mPreference.get(KEY_TEST_INT_ELEMENT, 0); + expect(0).assertEqual(per); + done(); + console.log("testPreferencesPromiseWithError0001 end."); + }) + .catch((err) => { + console.log("delete err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + }) + .catch((err) => { + console.log("flush err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + }) + .catch((err) => { + console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + }) + .catch((err) => { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + }) + .catch((err) => { + console.log("clear err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_PROMISE_0100 + * @tc.name : testMpreferencesGetPromise0001 + * @tc.desc : mPreference.get promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetPromise0001", 0, async function (done) { + console.log("testMpreferencesGetPromise0001 begin."); + try { + mPreference + .get(1233) + .then((ret) => { + console.log("get err"); + }) + .catch((err) => { + console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + console.log("testMpreferencesGetPromise0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_PROMISE_0200 + * @tc.name : testMpreferencesGetPromise0002 + * @tc.desc : mPreference.get promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetPromise0002", 0, async function (done) { + console.log("testMpreferencesPromise0002 begin."); + try { + await mPreference.put(KEY_TEST_STRING_ELEMENT, "123"); + mPreference + .get(-1, KEY_TEST_INT_ELEMENT) + .then((ret) => { + done(); + console.log("testMpreferencesGetPromise0002 end."); + }) + .catch((err) => { + console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_PROMISE_0300 + * @tc.name : testMpreferencesGetPromise0003 + * @tc.desc : mPreference.get promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetPromise0003", 0, async function (done) { + console.log("testMpreferencesGetPromise0003 begin."); + try { + await mPreference.put(KEY_TEST_STRING_ELEMENT, "123"); + mPreference + .get(KEY_TEST_INT_ELEMENT, "default") + .then((ret) => { + expect(ret !== "123").assertTrue(); + done(); + console.log("testMpreferencesGetPromise0003 end." + JSON.stringify(ret)); + }) + .catch((err) => { + console.log("get err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_SYNC_WITH_ERROR_0100 + * @tc.name : testMpreferencesGetSyncWithError0001 + * @tc.desc : mPreference.getSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetSyncWithError0001", 0, async function (done) { + console.log("testMpreferencesGetSyncWithError0001 begin."); + try { + mPreference.getSync(1233); + } catch (err) { + console.log("trycatch1 err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 parameters!").assertTrue(); + done(); + console.log("testMpreferencesGetSyncWithError0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_SYNC_WITH_ERROR_0200 + * @tc.name : testMpreferencesGetSyncWithError0002 + * @tc.desc : mPreference.getSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetSyncWithError0002", 0, async function (done) { + console.log("testMpreferencesGetSyncWithError0002 begin."); + try { + await mPreference.put(KEY_TEST_STRING_ELEMENT, "123"); + mPreference.getSync(-1, KEY_TEST_INT_ELEMENT); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_SYNC_WITH_ERROR_0300 + * @tc.name : testMpreferencesGetSyncWithError0003 + * @tc.desc : mPreference.getSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetSyncWithError0003", 0, async function (done) { + console.log("testMpreferencesGetSyncWithError0003 begin."); + try { + await mPreference.put(KEY_TEST_STRING_ELEMENT, "123"); + let ret = mPreference.getSync(KEY_TEST_INT_ELEMENT, "default"); + expect(ret !== "123").assertTrue(); + done(); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_GET_ALL_PROMISE_0100 + * @tc.name : testMpreferencesGetALLPromise0001 + * @tc.desc : mPreference.getAll promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesGetALLPromise0001", 0, async function (done) { + console.log("testMpreferencesGetALLPromise0001 begin."); + try { + mPreference + .getAll() + .then((ret) => { + console.log("getAll val = " + JSON.stringify(ret)); + done(); + console.log("testMpreferencesGetALLPromise0001 end."); + }) + .catch((err) => { + console.log("getAll err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_HAS_PROMISE_0100 + * @tc.name : testMpreferencesHasPromise0001 + * @tc.desc : mPreference.has promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesHasPromise0001", 0, async function (done) { + console.log("testMpreferencesHasPromise0001 begin."); + try { + mPreference + .has(123) + .then((val) => { + console.log("has err"); + }) + .catch((err) => { + console.log("has err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + console.log("testMpreferencesHasPromise0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_HAS_PROMISE_0200 + * @tc.name : testMpreferencesHasPromise0002 + * @tc.desc : mPreference.has promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesHasPromise0002", 0, async function (done) { + console.log("testMpreferencesHasPromise0002 begin."); + try { + mPreference + .has(KEY_TEST_STRING_ELEMENT) + .then((val) => { + done(); + console.log("testMpreferencesHasPromise0002 end."); + }) + .catch((err) => { + console.log("has err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_PROMISE_0100 + * @tc.name : testMpreferencesPutPromise0001 + * @tc.desc : mPreference.put promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutPromise0001", 0, async function (done) { + console.log("testMpreferencesPutPromise0001 begin."); + try { + mPreference + .put(1233) + .then(() => { + console.log("put err"); + }) + .catch((err) => { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 or 3 parameters!").assertTrue(); + done(); + console.log("testMpreferencesPutPromise0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_PROMISE_0200 + * @tc.name : testMpreferencesPutPromise0002 + * @tc.desc : mPreference.put promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutPromise0002", 0, async function (done) { + console.log("testMpreferencesPutPromise0002 begin."); + try { + mPreference + .put(KEY_TEST_STRING_ELEMENT, "") + .then(async () => { + let per = await mPreference.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(per); + done(); + console.log("testMpreferencesPutPromise0002 end."); + }) + .catch((err) => { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + }); + } catch (err) { + console.log("trycatch err =1" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_PROMISE_0300 + * @tc.name : testMpreferencesPutPromise0003 + * @tc.desc : mPreference.put promise test space + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutPromise0003", 0, async function (done) { + console.log("testMpreferencesPutPromise0003 begin."); + try { + mPreference + .put(KEY_TEST_STRING_ELEMENT, " ") + .then(async () => { + let per = await mPreference.get(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect(" ").assertEqual(per); + + done(); + console.log("testMpreferencesPutPromise0003 end."); + }) + .catch((err) => { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_PROMISE_0400 + * @tc.name : testMpreferencesPutPromise0004 + * @tc.desc : mPreference.put promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutPromise0004", 0, async function (done) { + console.log("testMpreferencesPutPromise0004 begin."); + try { + mPreference + .put(-1, 123) + .then(() => { + done(); + console.log("testMpreferencesPutPromise0004 end."); + }) + .catch((err) => { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_PROMISE_0500 + * @tc.name : testMpreferencesPutPromise0005 + * @tc.desc : mPreference.put promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutPromise0005", 0, async function (done) { + console.log("testMpreferencesPutPromise0005 begin."); + try { + mPreference + .put(KEY_TEST_STRING_ELEMENT, null) + .then(() => { + done(); + console.log("testMpreferencesPutPromise0005 end."); + }) + .catch((err) => { + console.log("put err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be ValueType.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_SYNC_WITH_ERROR_0100 + * @tc.name : testMpreferencesPutSyncWithError0001 + * @tc.desc : mPreference.putSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutSyncWithError0001", 0, async function (done) { + console.log("testMpreferencesPutSyncWithError0001 begin."); + try { + mPreference.putSync(1233); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. Need 2 parameters!").assertTrue(); + done(); + console.log("testMpreferencesPutSyncWithError0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_SYNC_WITH_ERROR_0200 + * @tc.name : testMpreferencesPutSyncWithError0002 + * @tc.desc : mPreference.putSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutSyncWithError0002", 0, async function (done) { + console.log("testMpreferencesPutSyncWithError0002 begin."); + try { + mPreference.putSync(KEY_TEST_STRING_ELEMENT, ""); + let per = mPreference.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect("").assertEqual(per); + done(); + console.log("testMpreferencesPutSyncWithError0002 end."); + } catch (err) { + console.log("trycatch err =1" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_SYNC_WITH_ERROR_0300 + * @tc.name : testMpreferencesPutSyncWithError0003 + * @tc.desc : mPreference.putSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutSyncWithError0003", 0, async function (done) { + console.log("testMpreferencesPutSyncWithError0003 begin."); + try { + mPreference.putSync(KEY_TEST_STRING_ELEMENT, " "); + let per = mPreference.getSync(KEY_TEST_STRING_ELEMENT, "defaultvalue"); + expect(" ").assertEqual(per); + done(); + console.log("testMpreferencesPutSyncWithError0003 end."); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_SYNC_WITH_ERROR_0400 + * @tc.name : testMpreferencesPutSyncWithError0004 + * @tc.desc : mPreference.putSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutSyncWithError0004", 0, async function (done) { + console.log("testMpreferencesPutSyncWithError0004 begin."); + try { + mPreference.putSync(-1, 123); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_PUT_SYNC_WITH_ERROR_0500 + * @tc.name : testMpreferencesPutSyncWithError0005 + * @tc.desc : mPreference.putSync test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesPutSyncWithError0005", 0, async function (done) { + console.log("testMpreferencesPutSyncWithError0005 begin."); + try { + mPreference.putSync(KEY_TEST_STRING_ELEMENT, null); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be ValueType.").assertTrue(); + done(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_DELETE_PROMISE_0100 + * @tc.name : testMpreferencesDeletePromise0001 + * @tc.desc : mPreference.delete promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesDeletePromise0001", 0, async function (done) { + console.log("testMpreferencesDeletePromise0001 begin."); + try { + mPreference + .delete(1233) + .then(() => { + console.log("delete err"); + }) + .catch((err) => { + console.log("delete err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(err.code === "401" && err.message === "Parameter error. The type of 'value' must be string.").assertTrue(); + done(); + console.log("testMpreferencesDeletePromise0001 end."); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_DELETE_PROMISE_0200 + * @tc.name : testMpreferencesDeletePromise0002 + * @tc.desc : mPreference.delete promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesDeletePromise0002", 0, async function (done) { + console.log("testMpreferencesDeletePromise0002 begin."); + try { + mPreference + .delete(KEY_TEST_STRING_ELEMENT) + .then(async () => { + done(); + console.log("testMpreferencesDeletePromise0002 end."); + }) + .catch((err) => { + console.log("delete err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_CLEAR_PROMISE_0100 + * @tc.name : testMpreferencesClearPromise0001 + * @tc.desc : mPreference.clear promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesClearPromise0001", 0, async function (done) { + console.log("testMpreferencesClearPromise0001 begin."); + try { + mPreference + .clear() + .then(() => { + done(); + console.log("testMpreferencesClearPromise0001 end."); + }) + .catch((err) => { + console.log("clear err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_MPREFERENCES_FLUSH_PROMISE_0100 + * @tc.name : testMpreferencesFlushPromise0001 + * @tc.desc : mPreference.flush promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testMpreferencesFlushPromise0001", 0, async function (done) { + console.log("testMpreferencesFlushPromise0001 begin."); + try { + mPreference + .flush() + .then(() => { + done(); + console.log("testMpreferencesFlushPromise0001 end."); + }) + .catch((err) => { + console.log("flush err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + }); + } catch (err) { + console.log("trycatch err =" + err + ", code =" + err.code + ", message =" + err.message); + expect(!err).assertTrue(); + } + }); + }); +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/module.json b/distributeddatamgr/crossplatform/preferencesetstest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..702793879a1a3c9dfa87f565708841c06a899d88 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/module.json @@ -0,0 +1,36 @@ +{ + "module": { + "name": "preferences_test_normal_ets", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/element/color.json b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/element/string.json b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/media/icon.png b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/profile/test_pages.json b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..77e90731b5a38d861663029b483df3d3ac9ec74b --- /dev/null +++ b/distributeddatamgr/crossplatform/preferencesetstest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/Index" + ] +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/app.json b/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..806b7760cd4f9a4d769e8fe8b379801d512f2c60 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/app.json @@ -0,0 +1,16 @@ +{ + "app": { + "bundleName": "ohos.acts.distributeddatamgr.crossplatform.relationalstore.normal", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "minAPIVersion": 10, + "targetAPIVersion": 10, + "car": { + "apiCompatibleVersion": 10, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/resources/base/element/string.json b/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..3811bc441fc0f128eb4d14c53ed463ffb8dc3811 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "xtsDemo1" + } + ] +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/crossplatform/relationalstoreetstest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/BUILD.gn b/distributeddatamgr/crossplatform/relationalstoreetstest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5c79ab7dfd1259c4a056b55f12c198a6b1d15fe5 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/BUILD.gn @@ -0,0 +1,50 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsCrossplatformRelationalStoreTest") { + hap_profile = "src/main/module.json" + deps = [ + ":windowStage_js_assets", + ":windowStage_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" + + # hap_name: HAP的名字,可选,默认为目标名 + hap_name = "ActsCrossplatformRelationalStoreTest" + subsystem_name = "distributeddatamgr" + part_name = "relational_store" +} +ohos_app_scope("windowStage_app_profile") { + # app_profile: HAP的AppScope中的app.json,只在Stage模型下使用 + app_profile = "AppScope/app.json" + + # sources: 资源文件路径 + sources = [ "AppScope/resources" ] +} +ohos_js_assets("windowStage_js_assets") { + # source_dir: js或ets代码路径,兼容FA模型的单ability配置到ability目录 + source_dir = "src/main/ets" +} +ohos_resources("windowStage_resources") { + # sources: 资源文件路径 + sources = [ "src/main/resources" ] + + # deps: 当前目标的依赖 + deps = [ ":windowStage_app_profile" ] + + # hap_profile: HAP的config.json,Stage模型对应module.json + hap_profile = "src/main/module.json" +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/Test.json b/distributeddatamgr/crossplatform/relationalstoreetstest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..0f899ac57fe8e697f79cc48941b10aa63e9fc053 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "60000", + "shell-timeout": "60000", + "bundle-name": "ohos.acts.distributeddatamgr.crossplatform.relationalstore.normal", + "module-name": "relationalstore_test_normal_ets" + }, + "kits": [ + { + "test-file-name": [ + "ActsCrossplatformRelationalStoreTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/signature/openharmony_sx.p7b b/distributeddatamgr/crossplatform/relationalstoreetstest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..4fcdbe6142dc6310dda6b28be116811a477d18fe Binary files /dev/null and b/distributeddatamgr/crossplatform/relationalstoreetstest/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestAbility/TestAbility.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestAbility/TestAbility.ets new file mode 100644 index 0000000000000000000000000000000000000000..dac63ae78615c5762d40e44e94c5be2d33a1b546 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestAbility/TestAbility.ets @@ -0,0 +1,63 @@ +/* + * 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 UIAbility from "@ohos.app.ability.UIAbility"; +import AbilityDelegatorRegistry from "@ohos.app.ability.abilityDelegatorRegistry"; +import hilog from "@ohos.hilog"; +import { Hypium } from "@ohos/hypium"; +import testsuite from "../test/List.test"; +import window from "@ohos.window"; + +export default class TestAbility extends UIAbility { + onCreate(want, launchParam) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onCreate"); + hilog.info(0x0000, "testTag", "%{public}s", "want param:" + JSON.stringify(want) ?? ""); + hilog.info(0x0000, "testTag", "%{public}s", "launchParam:" + JSON.stringify(launchParam) ?? ""); + var abilityDelegator: any; + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator(); + var abilityDelegatorArguments: any; + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments(); + hilog.info(0x0000, "testTag", "%{public}s", "start run testcase!!!"); + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite); + } + + onDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onDestroy"); + } + + onWindowStageCreate(windowStage: window.WindowStage) { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageCreate"); + globalThis.abilityContext = this.context; + windowStage.loadContent("TestAbility/pages/Index", (err, data) => { + if (err.code) { + hilog.error(0x0000, "testTag", "Failed to load the content. Cause: %{public}s", JSON.stringify(err) ?? ""); + return; + } + hilog.info(0x0000, "testTag", "Succeeded in loading the content. Data: %{public}s", JSON.stringify(data) ?? ""); + }); + } + + onWindowStageDestroy() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onWindowStageDestroy"); + } + + onForeground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onForeground"); + } + + onBackground() { + hilog.info(0x0000, "testTag", "%{public}s", "TestAbility onBackground"); + } +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestAbility/pages/Index.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestAbility/pages/Index.ets new file mode 100644 index 0000000000000000000000000000000000000000..7063c2427f471eb22dc9ea361188d2bbd6c24c57 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestAbility/pages/Index.ets @@ -0,0 +1,49 @@ +/* + * 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 hilog from '@ohos.hilog'; + +@Entry +@Component +struct Index { + aboutToAppear() { + hilog.info(0x0000, 'testTag', '%{public}s', '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/crossplatform/relationalstoreetstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts new file mode 100644 index 0000000000000000000000000000000000000000..92a16d84e8870da219c51d9f1342c79203c1f42d --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/TestRunner/OpenHarmonyTestRunner.ts @@ -0,0 +1,49 @@ +import hilog from '@ohos.hilog'; +import TestRunner from '@ohos.application.testRunner'; +import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry'; + +var abilityDelegator = undefined +var abilityDelegatorArguments = undefined + +async function onAbilityCreateCallback() { + hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback'); +} + +async function addAbilityMonitorCallback(err: any) { + hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? ''); +} + +export default class OpenHarmonyTestRunner implements TestRunner { + constructor() { + } + + onPrepare() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare '); + } + + async onRun() { + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run'); + abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility' + let lMonitor = { + abilityName: testAbilityName, + onAbilityCreate: onAbilityCreateCallback, + }; + abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback) + var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName + var debug = abilityDelegatorArguments.parameters['-D'] + if (debug == 'true') + { + cmd += ' -D' + } + hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd); + abilityDelegator.executeShellCommand(cmd, + (err: any, d: any) => { + hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? ''); + hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? ''); + }) + hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end'); + } +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/List.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e28b49c1628389bfde268c4c299e500158b5849b --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/List.test.ets @@ -0,0 +1,40 @@ +/* + * 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 RdbPredicates from './RdbPredicates.test' +import ResultSet from './ResultSet.test' +import RdbStoreInsert from './RdbStoreInsert.test' +import RdbStoreUpdate from './RdbStoreUpdate.test' +import RdbStoreDelete from './RdbStoreDelete.test' +import RdbStoreQuery from './RdbStoreQuery.test' +import RdbStoreQuerySql from './RdbStoreQuerySql.test' +import RdbStoreExecuteSql from './RdbStoreExecuteSql.test' +import RdbStoreTransaction from './RdbStoreTransaction.test' +import RdbStoreBackupRestore from './RdbStoreBackupRestore.test' +import RelationalStore from './RelationalStore.test' + +export default function testsuite() { + RdbPredicates() + ResultSet() + RdbStoreInsert() + RdbStoreUpdate() + RdbStoreDelete() + RdbStoreQuery() + RdbStoreQuerySql() + RdbStoreExecuteSql() + RdbStoreTransaction() + RdbStoreBackupRestore() + RelationalStore() +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbPredicates.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbPredicates.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c7f3d1cd0c4b6de5a622c9a01cda7b47213599e9 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbPredicates.test.ets @@ -0,0 +1,2607 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS _TEST]"; +const CREATE_TABLE_ALL_DATA_TYPE_SQL = + "CREATE TABLE IF NOT EXISTS AllDataType " + + "(id INTEGER PRIMARY KEY AUTOINCREMENT, " + + "integerValue INTEGER , longValue INTEGER , shortValue INTEGER , booleanValue INTEGER , " + + "doubleValue REAL , floatValue REAL , stringValue TEXT , blobValue BLOB , clobValue TEXT , " + + "byteValue INTEGER , dateValue INTEGER , timeValue INTEGER , timestampValue INTEGER , " + + "calendarValue INTEGER , characterValue TEXT , primIntValue INTEGER , primLongValue INTEGER , " + + "primShortValue INTEGER , primFloatValue REAL , primDoubleValue REAL , " + + "primBooleanValue INTEGER , primByteValue INTEGER , primCharValue TEXT, `order` INTEGER);"; + +const STORE_CONFIG = { + name: "Predicates.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; +let rdbStore = undefined; +let DOUBLE_MAX = 9223372036854775807; +export default function rdbPredicatesTest() { + describe("rdbPredicatesTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "beforeEach"); + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_ALL_DATA_TYPE_SQL, null); + await buildAllDataType1(); + await buildAllDataType2(); + await buildAllDataType3(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "Predicates.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function buildAllDataType1() { + console.info(TAG + "buildAllDataType1 start"); + { + var u8 = new Uint8Array([1, 2, 3]); + const valueBucket = { + integerValue: 2147483647, + doubleValue: DOUBLE_MAX, + booleanValue: true, + floatValue: -0.123, + longValue: 9223372036854775807, + shortValue: 32767, + characterValue: " ", + stringValue: "ABCDEFGHIJKLMN", + blobValue: u8, + byteValue: 127, + }; + await rdbStore.insert("AllDataType", valueBucket); + } + } + + async function buildAllDataType2() { + console.info(TAG + "buildAllDataType2 start"); + { + var u8 = new Uint8Array([1, 2, 3]); + const valueBucket = { + integerValue: 1, + doubleValue: 1.0, + booleanValue: false, + floatValue: 1.0, + longValue: 1, + shortValue: 1, + characterValue: "中", + stringValue: "ABCDEFGHIJKLMN", + blobValue: u8, + byteValue: 1, + }; + await rdbStore.insert("AllDataType", valueBucket); + } + } + + async function buildAllDataType3() { + console.info(TAG + "buildAllDataType3 start"); + { + var u8 = new Uint8Array([1, 2, 3]); + const valueBucket = { + integerValue: -2147483648, + doubleValue: Number.MIN_VALUE, + booleanValue: false, + floatValue: 0.1234567, + longValue: -9223372036854775808, + shortValue: -32768, + characterValue: "#", + stringValue: "ABCDEFGHIJKLMN", + blobValue: u8, + byteValue: -128, + }; + await rdbStore.insert("AllDataType", valueBucket); + } + } + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_CONSTRUCTOR_0100 + * @tc.name : testRdbPredicatesConstructor001 + * @tc.desc : Test the constructor method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesConstructor001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesConstructor001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesConstructor001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_CONSTRUCTOR_0200 + * @tc.name : testRdbPredicatesConstructor002 + * @tc.desc : Test the constructor() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesConstructor002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesConstructor002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesConstructor002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0100 + * @tc.name : testRdbPredicatesEqualTo001 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("booleanValue", true); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0200 + * @tc.name : testRdbPredicatesEqualTo002 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("byteValue", -128).or().equalTo("byteValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0300 + * @tc.name : testRdbPredicatesEqualTo003 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0400 + * @tc.name : testRdbPredicatesEqualTo004 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("doubleValue", DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0500 + * @tc.name : testRdbPredicatesEqualTo005 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("shortValue", -32768.0); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0600 + * @tc.name : testRdbPredicatesEqualTo006 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(true).assertEqual(result.goToFirstRow()); + expect(2).assertEqual(result.getLong(0)); + result.close(); + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0700 + * @tc.name : testRdbPredicatesEqualTo007 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo007", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo007 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(true).assertEqual(result.goToFirstRow()); + expect(2).assertEqual(result.getLong(0)); + result.close(); + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo007 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_EQUALTO_0800 + * @tc.name : testRdbPredicatesEqualTo008 + * @tc.desc : Test the equalTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEqualTo008", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEqualTo008 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("floatValue", -0.123); + let result = await rdbStore.query(predicates); + expect(true).assertEqual(result.goToFirstRow()); + expect(1).assertEqual(result.getLong(0)); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesEqualTo008 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0100 + * @tc.name : testRdbPredicatesNotEqualTo001 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("booleanValue", true); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0200 + * @tc.name : testRdbPredicatesNotEqualTo002 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("byteValue", -128); + predicates.notEqualTo("byteValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0300 + * @tc.name : testRdbPredicatesNotEqualTo003 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("stringValue", "ABCDEFGHIJKLMN"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0400 + * @tc.name : testRdbPredicatesNotEqualTo004 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("doubleValue", DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0500 + * @tc.name : testRdbPredicatesNotEqualTo005 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("shortValue", -32768); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0600 + * @tc.name : testRdbPredicatesNotEqualTo006 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0700 + * @tc.name : testRdbPredicatesNotEqualTo007 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo007", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo007 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo007 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_EQUALTO_0800 + * @tc.name : testRdbPredicatesNotEqualTo008 + * @tc.desc : Test the notEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotEqualTo008", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotEqualTo008 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notEqualTo("floatValue", -0.123); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotEqualTo008 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINWRAP_AND_ENDWRAP_0100 + * @tc.name : testRdbPredicatesBeginWrapAndEndWrap001 + * @tc.desc : Test the beginWrap() and endWrap() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginWrapAndEndWrap001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").beginWrap().equalTo("integerValue", 1).or().equalTo("integerValue", 2147483647).endWrap(); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINWRAP_AND_ENDWRAP_0200 + * @tc.name : testRdbPredicatesBeginWrapAndEndWrap002 + * @tc.desc : Test the beginWrap() and endWrap() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginWrapAndEndWrap002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").beginWrap().equalTo("characterValue", " ").endWrap(); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINWRAP_AND_ENDWRAP_0300 + * @tc.name : testRdbPredicatesBeginWrapAndEndWrap003 + * @tc.desc : Test the beginWrap() and endWrap() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginWrapAndEndWrap003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").beginWrap().equalTo("characterValue", "中").endWrap(); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINWRAP_AND_ENDWRAP_0400 + * @tc.name : testRdbPredicatesBeginWrapAndEndWrap004 + * @tc.desc : Test the beginWrap() and endWrap() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginWrapAndEndWrap004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").equalTo("characterValue", "中").endWrap(); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINWRAP_AND_ENDWRAP_0500 + * @tc.name : testRdbPredicatesBeginWrapAndEndWrap005 + * @tc.desc : Test the beginWrap() and endWrap() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginWrapAndEndWrap005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").beginWrap().equalTo("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBeginWrapAndEndWrap005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_OR_0100 + * @tc.name : testRdbPredicatesOr001 + * @tc.desc : Test the or() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOr001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOr001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").beginWrap().equalTo("integerValue", 1).or().equalTo("integerValue", 2147483647).endWrap(); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesOr001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_AND_0100 + * @tc.name : testRdbPredicatesAnd001 + * @tc.desc : Test the and() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesAnd001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesAnd001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").and().equalTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesAnd001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_CONTAINS_0100 + * @tc.name : testRdbPredicatesContains001 + * @tc.desc : Test the contains() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesContains001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesContains001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.contains("stringValue", "DEF"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesContains001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_CONTAINS_0200 + * @tc.name : testRdbPredicatesContains002 + * @tc.desc : Test the contains() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesContains002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesContains002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.contains("stringValue", "DEFX"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesContains002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_CONTAINS_0300 + * @tc.name : testRdbPredicatesContains003 + * @tc.desc : Test the contains() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesContains003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesContains003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.contains("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesContains003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_CONTAINS_0400 + * @tc.name : testRdbPredicatesContains004 + * @tc.desc : Test the contains() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesContains004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesContains004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.contains("characterValue", "#"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesContains004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINSWITH_0100 + * @tc.name : testRdbPredicatesBeginsWith001 + * @tc.desc : Test the beginsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginsWith001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginsWith001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.beginsWith("stringValue", "ABC"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesBeginsWith001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINSWITH_0200 + * @tc.name : testRdbPredicatesBeginsWith002 + * @tc.desc : Test the beginsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginsWith002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginsWith002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.beginsWith("stringValue", "ABCX"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesBeginsWith002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINSWITH_0300 + * @tc.name : testRdbPredicatesBeginsWith003 + * @tc.desc : Test the beginsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginsWith003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginsWith003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.beginsWith("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesBeginsWith003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BEGINSWITH_0400 + * @tc.name : testRdbPredicatesBeginsWith004 + * @tc.desc : Test the beginsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBeginsWith004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBeginsWith004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.beginsWith("characterValue", "#"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesBeginsWith004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ENDSWITH_0100 + * @tc.name : testRdbPredicatesEndsWith001 + * @tc.desc : Test the endsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEndsWith001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEndsWith001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.endsWith("stringValue", "LMN"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesEndsWith001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ENDSWITH_0200 + * @tc.name : testRdbPredicatesEndsWith002 + * @tc.desc : Test the endsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEndsWith002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEndsWith002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.endsWith("stringValue", "LMNX"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesEndsWith002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ENDSWITH_0300 + * @tc.name : testRdbPredicatesEndsWith003 + * @tc.desc : Test the endsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEndsWith003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEndsWith003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.endsWith("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesEndsWith003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ENDSWITH_0400 + * @tc.name : testRdbPredicatesEndsWith004 + * @tc.desc : Test the endsWith() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesEndsWith004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesEndsWith004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.endsWith("characterValue", "#"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesEndsWith004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NULL_0100 + * @tc.name : testRdbPredicatesIsNull001 + * @tc.desc : Test the isNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNull001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNull001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNull("primLongValue"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNull001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NULL_0200 + * @tc.name : testRdbPredicatesIsNull002 + * @tc.desc : Test the isNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNull002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNull002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNull("longValue"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNull002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NULL_0300 + * @tc.name : testRdbPredicatesIsNull003 + * @tc.desc : Test the isNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNull003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNull003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNull("stringValue"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNull003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NULL_0400 + * @tc.name : testRdbPredicatesIsNull004 + * @tc.desc : Test the isNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNull004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNull004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNull("stringValueX"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNull004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NOT_NULL_0100 + * @tc.name : testRdbPredicatesIsNotNull001 + * @tc.desc : Test the isNotNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNotNull001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNotNull001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNotNull("primLongValue"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNotNull001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NOT_NULL_0200 + * @tc.name : testRdbPredicatesIsNotNull002 + * @tc.desc : Test the isNotNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNotNull002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNotNull002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNotNull("longValue"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNotNull002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NOT_NULL_0300 + * @tc.name : testRdbPredicatesIsNotNull003 + * @tc.desc : Test the isNotNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNotNull003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNotNull003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNotNull("stringValue"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNotNull003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IS_NOT_NULL_0400 + * @tc.name : testRdbPredicatesIsNotNull004 + * @tc.desc : Test the isNotNull() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIsNotNull004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIsNotNull004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.isNotNull("stringValueX"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesIsNotNull004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIKE_0100 + * @tc.name : testRdbPredicatesLike001 + * @tc.desc : Test the like() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLike001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLike001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "%LMN%"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLike001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIKE_0200 + * @tc.name : testRdbPredicatesLike002 + * @tc.desc : Test the like() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLike002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLike002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "%LMNX%"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLike002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIKE_0300 + * @tc.name : testRdbPredicatesLike003 + * @tc.desc : Test the like() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLike003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLike003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("characterValue", "%中%"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLike003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIKE_0400 + * @tc.name : testRdbPredicatesLike004 + * @tc.desc : Test the like() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLike004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLike004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("characterValue", "%#%"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLike004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GLOB_0100 + * @tc.name : testRdbPredicatesGlob001 + * @tc.desc : Test the glob() method of class RdbPredicates. + * End with ? by glob. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGlob001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGlob001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.glob("stringValue", "ABCDEFGHIJKLM?"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGlob001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GLOB_0200 + * @tc.name : testRdbPredicatesGlob002 + * @tc.desc : Test the glob() method of class RdbPredicates. + * Begin with ? by glob. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGlob002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGlob002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.glob("stringValue", "?BCDEFGHIJKLMN"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGlob002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GLOB_0300 + * @tc.name : testRdbPredicatesGlob003 + * @tc.desc : Test the glob() method of class RdbPredicates. + * Begin and end with ? by glob. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGlob0006", 0, async function (done) { + console.info(TAG + "************* testGlob0006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.glob("stringValue", "?BCDEFGHIJKLM?"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testGlob0006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GLOB_0400 + * @tc.name : testRdbPredicatesGlob004 + * @tc.desc : Test the glob() method of class RdbPredicates. + * End with * by glob. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGlob004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGlob004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.glob("stringValue", "ABC*"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGlob004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GLOB_0500 + * @tc.name : testRdbPredicatesGlob005 + * @tc.desc : Test the glob() method of class RdbPredicates. + * Begin with * by glob. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGlob005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGlob005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.glob("stringValue", "*LMN"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGlob005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GLOB_0600 + * @tc.name : testRdbPredicatesGlob006 + * @tc.desc : Test the glob() method of class RdbPredicates. + * Begin and end with * by glob. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGlob006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGlob006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.glob("stringValue", "*FGHI*"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGlob006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0100 + * @tc.name : testRdbPredicatesBetween001 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("stringValue", "ABB", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0200 + * @tc.name : testRdbPredicatesBetween002 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("doubleValue", 0.0, DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0300 + * @tc.name : testRdbPredicatesBetween003 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("integerValue", 0, 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0400 + * @tc.name : testRdbPredicatesBetween004 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("longValue", 0, 2); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0500 + * @tc.name : testRdbPredicatesBetween005 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("stringValue", "ABB", "ABB"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0600 + * @tc.name : testRdbPredicatesBetween006 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("doubleValue", DOUBLE_MAX, DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0700 + * @tc.name : testRdbPredicatesBetween007 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween007", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween007 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("integerValue", 1, 0); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween007 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_BETWEEN_0800 + * @tc.name : testRdbPredicatesBetween008 + * @tc.desc : Test the between() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesBetween008", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesBetween008 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.between("longValue", 2, -1); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesBetween008 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_BETWEEN_0100 + * @tc.name : testRdbPredicatesNotBetween001 + * @tc.desc : Test the notBetween() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotBetween001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotBetween001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notBetween("stringValue", "ABB", "ABD"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotBetween001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_BETWEEN_0200 + * @tc.name : testRdbPredicatesNotBetween002 + * @tc.desc : Test the notBetween() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotBetween002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotBetween002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notBetween("doubleValue", 0.0, DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotBetween002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_BETWEEN_0300 + * @tc.name : testRdbPredicatesNotBetween003 + * @tc.desc : Test the notBetween() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotBetween003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotBetween003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notBetween("integerValue", 0, 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotBetween003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_BETWEEN_0400 + * @tc.name : testRdbPredicatesNotBetween004 + * @tc.desc : Test the notBetween() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotBetween004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotBetween004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notBetween("longValue", 0, 2); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesNotBetween004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0100 + * @tc.name : testRdbPredicatesGreaterThan001 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("stringValue", "ABC"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0200 + * @tc.name : testRdbPredicatesGreaterThan002 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0300 + * @tc.name : testRdbPredicatesGreaterThan003 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0400 + * @tc.name : testRdbPredicatesGreaterThan004 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("longValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0500 + * @tc.name : testRdbPredicatesGreaterThan005 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("stringValue", "ZZZ"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0600 + * @tc.name : testRdbPredicatesGreaterThan006 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("doubleValue", 999.0); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0700 + * @tc.name : testRdbPredicatesGreaterThan007 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan007", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan007 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("integerValue", -999); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan007 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_0800 + * @tc.name : testRdbPredicatesGreaterThan008 + * @tc.desc : Test the greaterThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThan008", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThan008 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThan("longValue", -999); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThan008 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0100 + * @tc.name : testRdbPredicatesLessThan001 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("stringValue", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0200 + * @tc.name : testRdbPredicatesLessThan002 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0300 + * @tc.name : testRdbPredicatesLessThan003 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0400 + * @tc.name : testRdbPredicatesLessThan004 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("longValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0500 + * @tc.name : testRdbPredicatesLessThan005 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("stringValue", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0600 + * @tc.name : testRdbPredicatesLessThan006 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("doubleValue", 1.0); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0700 + * @tc.name : testRdbPredicatesLessThan007 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan007", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan007 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("integerValue", -2147483648); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan007 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_0800 + * @tc.name : testRdbPredicatesLessThan008 + * @tc.desc : Test the lessThan() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThan008", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThan008 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThan("longValue", -9223372036854775808); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThan008 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_OR_EQUALT0_0100 + * @tc.name : testRdbPredicatesGreaterThanOrEqualTo001 + * @tc.desc : Test the greaterThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThanOrEqualTo001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("stringValue", "ABC"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_OR_EQUALT0_0200 + * @tc.name : testRdbPredicatesGreaterThanOrEqualTo002 + * @tc.desc : Test the greaterThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThanOrEqualTo002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_OR_EQUALT0_0300 + * @tc.name : testRdbPredicatesGreaterThanOrEqualTo003 + * @tc.desc : Test the greaterThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThanOrEqualTo003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GREATER_THAN_OR_EQUALT0_0400 + * @tc.name : testRdbPredicatesGreaterThanOrEqualTo004 + * @tc.desc : Test the greaterThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGreaterThanOrEqualTo004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesGreaterThanOrEqualTo004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_OR_EQUALT0_0100 + * @tc.name : testRdbPredicatesLessThanOrEqualTo001 + * @tc.desc : Test the lessThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThanOrEqualTo001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("stringValue", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_OR_EQUALT0_0200 + * @tc.name : testRdbPredicatesLessThanOrEqualTo002 + * @tc.desc : Test the lessThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThanOrEqualTo002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_OR_EQUALT0_0300 + * @tc.name : testRdbPredicatesLessThanOrEqualTo003 + * @tc.desc : Test the lessThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThanOrEqualTo003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LESS_THAN_OR_EQUALT0_0400 + * @tc.name : testRdbPredicatesLessThanOrEqualTo004 + * @tc.desc : Test the lessThanOrEqualTo() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLessThanOrEqualTo004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesLessThanOrEqualTo004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ORDER_BY_ASC_0100 + * @tc.name : testRdbPredicatesOrderByAsc001 + * @tc.desc : Test the orderByAsc() and distinct() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOrderByAsc001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOrderByAsc001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").orderByAsc("integerValue").distinct(); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + expect(true).assertEqual(result.goToFirstRow()); + expect(3).assertEqual(result.getLong(0)); + expect(true).assertEqual(result.goToNextRow()); + expect(2).assertEqual(result.getLong(0)); + expect(true).assertEqual(result.goToNextRow()); + expect(1).assertEqual(result.getLong(0)); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesOrderByAsc001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ORDER_BY_ASC_0200 + * @tc.name : testRdbPredicatesOrderByAsc002 + * @tc.desc : Test the orderByAsc() and distinct() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOrderByAsc002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOrderByAsc002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").orderByAsc("integerValueX").distinct(); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesOrderByAsc002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ORDER_BY_DESC_0100 + * @tc.name : testRdbPredicatesOrderByDesc001 + * @tc.desc : Test the orderByDesc() and distinct() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOrderByDesc001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOrderByDesc001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").orderByDesc("integerValue").distinct(); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + expect(true).assertEqual(result.goToFirstRow()); + expect(1).assertEqual(result.getLong(0)); + expect(true).assertEqual(result.goToNextRow()); + expect(2).assertEqual(result.getLong(0)); + expect(true).assertEqual(result.goToNextRow()); + expect(3).assertEqual(result.getLong(0)); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesOrderByDesc001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_ORDER_BY_DESC_0200 + * @tc.name : testRdbPredicatesOrderByDesc002 + * @tc.desc : Test the orderByDesc() and distinct() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOrderByDesc002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOrderByDesc002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").orderByDesc("integerValueX").distinct(); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + } + done(); + console.info(TAG + "************* testRdbPredicatesOrderByDesc002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIMIT_AS_0100 + * @tc.name : testRdbPredicatesLimitAs001 + * @tc.desc : Test the limitAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLimitAs001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLimitAs001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLimitAs001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIMIT_AS_0200 + * @tc.name : testRdbPredicatesLimitAs002 + * @tc.desc : Test the limitAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLimitAs002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLimitAs002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLimitAs002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIMIT_AS_0300 + * @tc.name : testRdbPredicatesLimitAs003 + * @tc.desc : Test the limitAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLimitAs003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLimitAs003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(100); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLimitAs003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIMIT_AS_0400 + * @tc.name : testRdbPredicatesLimitAs004 + * @tc.desc : Test the limitAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLimitAs004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLimitAs004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "中").limitAs(1); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLimitAs004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIMIT_AS_0500 + * @tc.name : testRdbPredicatesLimitAs005 + * @tc.desc : Test the limitAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLimitAs005", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLimitAs005 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLimitAs005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_LIMIT_AS_0600 + * @tc.name : testRdbPredicatesLimitAs006 + * @tc.desc : Test the limitAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesLimitAs006", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesLimitAs006 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(-1); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesLimitAs006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_OFFSET_AS_0100 + * @tc.name : testRdbPredicatesOffsetAs001 + * @tc.desc : Test the offsetAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOffsetAs001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOffsetAs001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesOffsetAs001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_OFFSET_AS_0200 + * @tc.name : testRdbPredicatesOffsetAs002 + * @tc.desc : Test the offsetAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOffsetAs002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOffsetAs002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesOffsetAs002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_OFFSET_AS_0300 + * @tc.name : testRdbPredicatesOffsetAs003 + * @tc.desc : Test the offsetAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOffsetAs003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOffsetAs003 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(5); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesOffsetAs003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_OFFSET_AS_0400 + * @tc.name : testRdbPredicatesOffsetAs004 + * @tc.desc : Test the offsetAs() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesOffsetAs004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesOffsetAs004 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(-1); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesOffsetAs004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GROUP_BY_0100 + * @tc.name : testRdbPredicatesGroupBy001 + * @tc.desc : Test the groupBy() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGroupBy001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGroupBy001 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").groupBy(["characterValue"]); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesGroupBy001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_GROUP_BY_0200 + * @tc.name : testRdbPredicatesGroupBy002 + * @tc.desc : Test the groupBy() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesGroupBy002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesGroupBy002 start *************"); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").groupBy(["characterValueX"]); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result.close(); + result = null; + done(); + console.info(TAG + "************* testRdbPredicatesGroupBy002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_INDEXED_BY_0100 + * @tc.name : testRdbPredicatesIndexedBy001 + * @tc.desc : Test the indexedBy() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + // + it("testIndexedBy0001", 0, async function (done) { + console.info(TAG + "************* testIndexedBy0001 start *************"); + await rdbStore.executeSql("CREATE INDEX index_name ON AllDataType (characterValue);", null); + try { + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.indexedBy("index_name"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + done(); + } catch (err) { + console.info(TAG + "err = " + err); + expect(err.code).assertEqual("401"); + } + console.info(TAG + "************* testIndexedBy0001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_INDEXED_BY_0200 + * @tc.name : testRdbPredicatesIndexedBy002 + * @tc.desc : Test the indexedBy() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIndexedBy002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIndexedBy002 start *************"); + try { + await rdbStore.executeSql("CREATE INDEX index_name ON AllDataType (characterValueX);", null); + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.indexedBy("index_name"); + expect().assertFail(); + } catch (errInfo) { + expect(errInfo != null).assertTrue(); + console.info(TAG + "testRdbPredicatesIndexedBy002 error: " + errInfo); + done(); + } + console.info(TAG + "************* testRdbPredicatesIndexedBy002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IN_0100 + * @tc.name : testRdbPredicatesIn001 + * @tc.desc : Test the in() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIn001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIn001 start *************"); + var values = [Number.MIN_VALUE.toString()]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesIn001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IN_0200 + * @tc.name : testRdbPredicatesIn002 + * @tc.desc : Test the in() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIn002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIn002 start *************"); + var values = ["1.0"]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesIn002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IN_0300 + * @tc.name : testRdbPredicatesIn003 + * @tc.desc : Test the in() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIn003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIn003 start *************"); + var values = [DOUBLE_MAX.toString()]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesIn003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_IN_0400 + * @tc.name : testRdbPredicatesIn004 + * @tc.desc : Test the in() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesIn004", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesIn004 start *************"); + var values = [Number.MIN_VALUE.toString(), "1.0", DOUBLE_MAX.toString()]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesIn004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_IN_0100 + * @tc.name : testRdbPredicatesNotIn001 + * @tc.desc : Test the notIn() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotIn001", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotIn001 start *************"); + var values = [1, -2147483648]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notIn("integerValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesNotIn001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_IN_0200 + * @tc.name : testRdbPredicatesNotIn002 + * @tc.desc : Test the notIn() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotIn002", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotIn002 start *************"); + let values = [1, 2147483647]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notIn("integerValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesNotIn002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_PREDICATES_NOT_IN_0300 + * @tc.name : testRdbPredicatesNotIn003 + * @tc.desc : Test the notIn() method of class RdbPredicates. + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbPredicatesNotIn003", 0, async function (done) { + console.info(TAG + "************* testRdbPredicatesNotIn003 start *************"); + var values = [-2147483648, 2147483647]; + let predicates = await new relationalStore.RdbPredicates("AllDataType"); + predicates.notIn("integerValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testRdbPredicatesNotIn003 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..c6f0591a42d88b279d6f4a3ba35ad274d5d8770a --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreBackupRestore.test.ets @@ -0,0 +1,392 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS_TEST]"; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS backupTest (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; +let RdbStore = undefined; +let context = null; +const STORE_CONFIG = { + name: "BackupResotreTest.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; +const DATABASE_BACKUP_NAME = "Backup.db"; + +async function CreatRdbStore(context, STORE_CONFIG) { + context = globalThis.abilityContext; + let RdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await RdbStore.executeSql(CREATE_TABLE_TEST, null); + let u8 = new Uint8Array([1, 2, 3]); + { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: u8, + }; + await RdbStore.insert("backupTest", valueBucket); + } + { + const valueBucket = { + name: "lisi", + age: 28, + salary: 100.5, + blobType: u8, + }; + await RdbStore.insert("backupTest", valueBucket); + } + { + const valueBucket = { + name: "wangwu", + age: 38, + salary: 90.0, + blobType: u8, + }; + await RdbStore.insert("backupTest", valueBucket); + } + return RdbStore; +} + +export default function RdbStoreBackupRestoreCallbackTest() { + describe("RdbStoreBackupRestoreCallbackTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + console.info(TAG + "beforeEach"); + RdbStore = await CreatRdbStore(context, STORE_CONFIG); + }); + + afterEach(async function () { + console.info(TAG + "afterEach"); + context = globalThis.abilityContext; + await relationalStore.deleteRdbStore(context, STORE_CONFIG.name); + await relationalStore.deleteRdbStore(context, DATABASE_BACKUP_NAME); + await relationalStore.deleteRdbStore(context, "BackupTest003.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BACKUP_RESTORE_0100 + * @tc.name : testRdbStoreBackupRestore001 + * @tc.desc : RdbStore backup and restore callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBackupRestore001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBackupRestore001 start *************"); + RdbStore.backup(DATABASE_BACKUP_NAME, async (err) => { + if (err) { + console.info(TAG + "backup err ttt: " + err); + 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) { + expect(!err).assertTrue(); + } else { + let predicates = new relationalStore.RdbPredicates("backupTest"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await RdbStore.query(predicates); + try { + console.info(TAG + "After restore resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(1).assertEqual(blobType[0]); + resultSet.close(); + done(); + } catch (err) { + expect(!err).assertTrue(); + } + resultSet = null; + RdbStore = null; + } + console.info(TAG + "************* testRdbStoreBackupRestore001 end *************"); + }); + } + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BACKUP_RESTORE_0200 + * @tc.name : testRdbStoreBackupRestore002 + * @tc.desc : RdbStore backup and restore promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBackupRestore002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBackupRestore002 start *************"); + let promiseBackup = RdbStore.backup(DATABASE_BACKUP_NAME); + promiseBackup + .then(async () => { + console.info(`Backup success.`); + let deleteData = new relationalStore.RdbPredicates("backupTest"); + deleteData.equalTo("name", "zhangsan"); + await RdbStore.delete(deleteData); + let promiseRestore = RdbStore.restore(DATABASE_BACKUP_NAME); + promiseRestore + .then(async () => { + console.info(`Restore success.`); + let predicates = new relationalStore.RdbPredicates("backupTest"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await RdbStore.query(predicates); + try { + console.info(TAG + "After restore resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(1).assertEqual(blobType[0]); + resultSet.close(); + done(); + } catch (err) { + console.info(TAG + "testRdbStoreBackupRestore002 error: " + err); + expect(!err).assertTrue(); + } + resultSet = null; + RdbStore = null; + console.info(TAG + "************* testRdbStoreBackupRestore002 end *************"); + }) + .catch((err) => { + console.info(TAG + "Restore error: " + err); + expect(!err).assertTrue(); + }); + }) + .catch((err) => { + console.info(TAG + "Backup error: " + err); + expect(!err).assertTrue(); + }); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BACKUP_0100 + * @tc.name : testRdbStoreBackup001 + * @tc.desc : RdbStore backup callback test: file name empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBackup001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBackup001 start *************"); + try { + RdbStore.backup("", async (err) => { + console.info(`Backup success.`); + expect(!err).assertTrue(); + done(); + }); + } catch (errInfo) { + console.info(TAG + "testRdbStoreBackup001 error: " + errInfo); + expect(errInfo == "Error: Parameter error. The table must be not empty").assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreBackup001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BACKUP_0200 + * @tc.name : testRdbStoreBackup002 + * @tc.desc : RdbStore backup callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBackup002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBackup002 start *************"); + try { + RdbStore.backup(STORE_CONFIG.name, async (err) => { + console.info(TAG + "backup err ttt: " + err.message + "code: " + err.code); + expect(err.code == 14800011 && err.message == "Failed to open database by database corrupted").assertTrue(); + done(); + }); + } catch (errInfo) { + console.info(TAG + "testRdbStoreBackup002 error: " + errInfo); + expect(!errInfo).assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreBackup002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BACKUP_0300 + * @tc.name : testRdbStoreBackup003 + * @tc.desc : RdbStore backup promise test: file name empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBackup003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBackup003 start *************"); + try { + await RdbStore.backup(""); + done(); + } catch (errInfo) { + console.info(TAG + "testRdbStoreBackup003 error: " + errInfo); + console.info(`Backup err: file name empty.`); + expect(errInfo == "Error: Parameter error. The table must be not empty").assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreBackup003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BACKUP_0400 + * @tc.name : testRdbStoreBackup004 + * @tc.desc : RdbStore backup promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBackup004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBackup004 start *************"); + try { + let promiseBackup = RdbStore.backup(STORE_CONFIG.name); + promiseBackup + .then(() => { + console.info(`Backup success.`); + done(); + }) + .catch((err) => { + console.info(TAG + "backup err ttt1: " + err.message + "code: " + err.code); + expect(err.code == 14800011 && err.message == "Failed to open database by database corrupted").assertTrue(); + done(); + }); + } catch (err) { + console.info(TAG + "testRdbStoreBackup004 error: " + err.message + "code: " + err.code); + expect(!err).assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreBackup004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_RESTORE_0100 + * @tc.name : testRdbStoreRestore001 + * @tc.desc : RdbStore retore callback test: file name empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreRestore001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreRestore001 start *************"); + let backupName = "BackupTest003.db"; + await RdbStore.backup(backupName); + try { + RdbStore.restore("", async (err) => { + console.info(`restore success.`); + expect(!err).assertTrue(); + done(); + }); + } catch (errInfo) { + console.info(TAG + "testRdbStoreRestore001 error: " + errInfo); + expect(errInfo == "Error: Parameter error. The srcName must be not empty").assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreRestore001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_RESTORE_0200 + * @tc.name : testRdbStoreRestore002 + * @tc.desc : RdbStore retore callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreRestore002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreRestore002 start *************"); + let backupName = "BackupTest003.db"; + await RdbStore.backup(backupName); + try { + RdbStore.restore(STORE_CONFIG.name, async (err) => { + 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 *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_RESTORE_0300 + * @tc.name : testRdbStoreRestore003 + * @tc.desc : RdbStore retore promise test: file name empty + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreRestore003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreRestore003 start *************"); + let backupName = "BackupTest003.db"; + await RdbStore.backup(backupName); + try { + await RdbStore.retore(""); + done(); + } catch (errInfo) { + console.info(TAG + "testRdbStoreRestore003 error: " + errInfo); + console.info(`retore err: file name empty.`); + expect(errInfo == "TypeError: is not callable").assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreRestore003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_RESTORE_0400 + * @tc.name : testRdbStoreRestore004 + * @tc.desc : RdbStore retore promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreRestore004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreRestore004 start *************"); + let backupName = "BackupTest003.db"; + await RdbStore.backup(backupName); + try { + await RdbStore.retore(STORE_CONFIG.name); + done(); + } catch (errInfo) { + console.info(TAG + "testRdbStoreRestore004 error: " + errInfo); + console.info(`Restore err: file name wrong.`); + expect(errInfo == "TypeError: is not callable").assertTrue(); + done(); + } + console.info(TAG + "************* testRdbStoreRestore004 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreDelete.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreDelete.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..cbf8e2cf340c43f81921ccd4e83edbf1a793bf5c --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreDelete.test.ets @@ -0,0 +1,261 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS_TEST]"; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT UNIQUE, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; +const STORE_CONFIG = { + name: "Delete.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; + +let rdbStore = undefined; + +export default function rdbStoreDeleteTest() { + describe("rdbStoreDeleteTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "beforeEach"); + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await createTest1(); + await createTest2(); + await createTest3(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "Delete.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function createTest1() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + async function createTest2() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "lisi", + age: 28, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + async function createTest3() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "lisi2", + age: 28, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_DELETE_0100 + * @tc.name : testRdbStoreDelete001 + * @tc.desc : RdbStore delete callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreDelete001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreDelete001 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 18); + let resultSet = await rdbStore.query(predicates); + expect(1).assertEqual(resultSet.rowCount); + resultSet.close(); + rdbStore.delete(predicates, async (err, rows) => { + if (err) { + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + } + console.info(`Delete rows: ${rows}`); + expect(1).assertEqual(rows); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 18); + let resultSet = await rdbStore.query(predicates); + expect(0).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreDelete001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_DELETE_0200 + * @tc.name : testRdbStoreDelete002 + * @tc.desc : RdbStore delete callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreDelete002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreDelete002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("aaa id", 1); + rdbStore.delete(predicates, async (err, rows) => { + if (err) { + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000).assertTrue(); + console.info(TAG + "delete with wrong conditions"); + done(); + } + }); + console.info(TAG + "************* testRdbStoreDelete002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_DELETE_0300 + * @tc.name : testRdbStoreDelete003 + * @tc.desc : RdbStore delete callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreDelete003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreDelete003 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 28); + rdbStore.delete(predicates, async (err, rows) => { + if (err) { + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + console.info(`Delete rows: ${rows}`); + expect(2).assertEqual(rows); + done(); + }); + console.info(TAG + "************* testRdbStoreDelete003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_DELETE_0400 + * @tc.name : testRdbStoreDelete004 + * @tc.desc : RdbStore delete promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreDelete004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreDelete004 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 18); + let resultSet = await rdbStore.query(predicates); + expect(1).assertEqual(resultSet.rowCount); + resultSet.close(); + rdbStore + .delete(predicates) + .then(async (ret) => { + expect(1).assertEqual(ret); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 18); + let resultSet = await rdbStore.query(predicates); + expect(0).assertEqual(resultSet.rowCount); + console.info(TAG + "Delete done: " + ret); + resultSet.close(); + done(); + }) + .catch((err) => { + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + }); + console.info(TAG + "************* testRdbStoreDelete004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_DELETE_0500 + * @tc.name : testRdbStoreDelete005 + * @tc.desc : RdbStore delete promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreDelete005", 0, async function (done) { + console.info(TAG + "************* testRdbStoreDelete005 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("aaa id", 1); + rdbStore + .delete(predicates) + .then(async (ret) => { + console.info(TAG + "Delete done: " + ret); + }) + .catch((err) => { + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000).assertTrue(); + console.info(TAG + "delete with wrong conditions"); + done(); + }); + console.info(TAG + "************* testRdbStoreDelete005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_DELETE_0600 + * @tc.name : testRdbStoreDelete006 + * @tc.desc : RdbStore delete promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreDelete006", 0, async function (done) { + console.info(TAG + "************* testRdbStoreDelete006 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", "28"); + rdbStore + .delete(predicates) + .then(async (ret) => { + expect(2).assertEqual(ret); + console.info(TAG + "Delete done: " + ret); + done(); + }) + .catch((err) => { + console.error(`Delete failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + }); + console.info(TAG + "************* testRdbStoreDelete006 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreExecuteSql.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreExecuteSql.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..e260c8c4eb2add45e933cb50926af0017857d8a4 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreExecuteSql.test.ets @@ -0,0 +1,197 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +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)"; + +const STORE_CONFIG = { + name: "ExcuteSqlTest.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; +let rdbStore = undefined; + +export default function rdbstoreStoreExcuteSqlTest() { + describe("rdbstoreStoreExcuteSqlTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await rdbStore.executeSql("DELETE FROM test"); + console.info(TAG + "beforeEach"); + await createTest1(); + await createTest2(); + await createTest3(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "ExcuteSqlTest.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function createTest1() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + async function createTest2() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "lisi", + age: 28, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + async function createTest3() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "lisi2", + age: 28, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_EXECUTE_SQL_0100 + * @tc.name : testRdbStoreExecuteSql001 + * @tc.desc : RdbStore executeSql callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreExecuteSql001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreExecuteSql001 start *************"); + rdbStore.executeSql("DELETE FROM test WHERE name = 'zhangsan'", async (err) => { + if (err) { + console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + console.info(`Delete table done.`); + let resultSet = await rdbStore.querySql("SELECT * FROM test"); + expect(2).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreExecuteSql001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_EXECUTE_SQL_0200 + * @tc.name : testRdbStoreExecuteSql002 + * @tc.desc : RdbStore executeSql callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreExecuteSql002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreExecuteSql002 start *************"); + rdbStore.executeSql("DELETE FROM test WHERE age = ? OR age = ?", ["18", "28"], async (err) => { + if (err) { + console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + console.info(`Delete table done.`); + let resultSet = await rdbStore.querySql("SELECT * FROM test"); + expect(0).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreExecuteSql002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_EXECUTE_SQL_0300 + * @tc.name : testRdbStoreExecuteSql003 + * @tc.desc : RdbStore executeSql promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreExecuteSql003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreExecuteSql003 start *************"); + let promise = rdbStore.executeSql("DELETE FROM test WHERE name = 'zhangsan'"); + promise + .then(async () => { + console.info(`Delete table done.`); + let resultSet = await rdbStore.querySql("SELECT * FROM test"); + expect(2).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }) + .catch((err) => { + console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + }); + console.info(TAG + "************* testRdbStoreExecuteSql003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_EXECUTE_SQL_0400 + * @tc.name : testRdbStoreExecuteSql004 + * @tc.desc : RdbStore executeSql promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreExecuteSql004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreExecuteSql004 start *************"); + let promise = rdbStore.executeSql("DELETE FROM test WHERE age = ? OR age = ?", ["18", "28"]); + promise + .then(async () => { + console.info(`Delete table done.`); + let resultSet = await rdbStore.querySql("SELECT * FROM test"); + expect(0).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }) + .catch((err) => { + console.error(`ExecuteSql failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + }); + console.info(TAG + "************* testRdbStoreExecuteSql004 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreInsert.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreInsert.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..4485018509e9ea64715e3ba883c60bc854bc3b16 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreInsert.test.ets @@ -0,0 +1,407 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +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)"; +const STORE_CONFIG = { + name: "InsertTest.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; + +let rdbStore = undefined; +let resultSet = undefined; +let context = null; + +function sleep(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +export default function InsertTest() { + describe("InsertTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + console.info(TAG + "beforeEach"); + context = globalThis.abilityContext; + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + console.log("InsertTestrdbStore" + rdbStore); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await rdbStore.executeSql("DELETE FROM test"); + }); + + afterEach(async function () { + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "InsertTest.db").then(() => { + sleep(2); + }); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_VERSION_0100 + * @tc.name : testRdbStoreVersion001 + * @tc.desc : RdbStore version test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it("testRdbStoreVersion001", 0, async function (done) { + console.log(TAG + "************* testRdbStoreVersion001 start *************"); + rdbStore.version = 3; + expect(3).assertEqual(rdbStore.version); + done(); + console.log(TAG + "************* testRdbStoreVersion001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_INSERT_0100 + * @tc.name : testRdbStoreInsert001 + * @tc.desc : RdbStore insert callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreInsert001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert001 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + rdbStore.insert("test", valueBucket, async (err, rowId) => { + if (err) { + console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + try { + console.info(`Insert is successful, rowId = ${rowId}`); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + }); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + + console.info(TAG + "************* testRdbStoreInsert001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_INSERT_0200 + * @tc.name : testRdbStoreInsert002 + * @tc.desc : RdbStore insert promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreInsert002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert002 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreInsert002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_INSERT_0300 + * @tc.name : testRdbStoreInsert003 + * @tc.desc : RdbStore insert callback with ConflictResolution test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreInsert003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert003 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + rdbStore.insert("test", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_ROLLBACK, async (err, rowId) => { + if (err) { + console.error(`Insert is failed, code is ${err.code},message is ${err.message}`); + done(); + } + try { + console.info(`Insert is successful, rowId = ${rowId}`); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + }); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + + console.info(TAG + "************* testRdbStoreInsert003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_INSERT_0400 + * @tc.name : testRdbStoreInsert004 + * @tc.desc : RdbStore insert promise with ConflictResolution test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreInsert004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert004 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket, relationalStore.ConflictResolution.ON_CONFLICT_IGNORE); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreInsert004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BATCH_INSERT_0100 + * @tc.name : testRdbStoreBatchInsert001 + * @tc.desc : RdbStore batchInsert callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBatchInsert001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBatchInsert001 start *************"); + try { + const valueBucket1 = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + const valueBucket2 = { + name: "lisi", + age: 23, + salary: 200, + blobType: new Uint8Array([1, 2, 3]), + }; + const valueBucket3 = { + name: "wangwu", + age: 20, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]; + rdbStore.batchInsert("test", valueBuckets, async (err, insertNum) => { + if (err) { + console.error(`batchInsert is failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + try { + console.info(`batchInsert is successful, the number of values that were inserted = ${insertNum}`); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("Insert error " + e); + expect(!e).assertTrue(); + } + }); + } catch (e) { + console.info("BatchInsert error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreBatchInsert001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_BATCH_INSERT_0200 + * @tc.name : testRdbStoreBatchInsert002 + * @tc.desc : RdbStore batchInsert promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreBatchInsert002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreBatchInsert002 start *************"); + try { + const valueBucket1 = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + const valueBucket2 = { + name: "lisi", + age: 23, + salary: 200, + blobType: new Uint8Array([1, 2, 3]), + }; + const valueBucket3 = { + name: "wangwu", + age: 20, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3]; + await rdbStore.batchInsert("test", valueBuckets); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "lisi"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name); + expect(23).assertEqual(age); + expect(200).assertEqual(salary); + resultSet.close(); + done(); + } catch (e) { + console.info("BatchInsert error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreBatchInsert002 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreQuery.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreQuery.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..3fa240c8eac46a7bd97ccddeaff7d284adbe520a --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreQuery.test.ets @@ -0,0 +1,191 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS_TEST]"; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT UNIQUE, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; +const STORE_CONFIG = { + name: "Query.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; + +let rdbStore = undefined; + +export default function rdbStoreQueryTest() { + describe("rdbStoreQueryTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "beforeEach"); + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await createTest1(); + await createTest2(); + await createTest3(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "Query.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function createTest1() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + async function createTest2() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "lisi", + age: 28, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + async function createTest3() { + console.info(TAG + "createTest start"); + { + const valueBucket = { + name: "lisi2", + age: 28, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + } + } + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_0100 + * @tc.name : testRdbStoreQuery001 + * @tc.desc : RdbStore query callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuery001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreQuery001 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + rdbStore.query(predicates, async (err, resultSet) => { + if (err) { + console.error(`Query failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + } + console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); + expect(3).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreQuery001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_0200 + * @tc.name : testRdbStoreQuery002 + * @tc.desc : RdbStore query callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuery002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreQuery002 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 18); + rdbStore.query(predicates, "salary", async (err, resultSet) => { + if (err) { + console.error(`Query failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + } + console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); + expect(true).assertEqual(resultSet.goToFirstRow()); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + expect(100.5).assertEqual(salary); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreQuery002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_0300 + * @tc.name : testRdbStoreQuery003 + * @tc.desc : RdbStore query promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuery003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreQuery003 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + let promise = rdbStore.query(predicates); + promise.then((resultSet) => { + console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); + expect(3).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreQuery003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_0400 + * @tc.name : testRdbStoreQuery004 + * @tc.desc : RdbStore query promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuery004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreQuery004 start *************"); + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("age", 18); + let promise = rdbStore.query(predicates, "salary"); + promise.then((resultSet) => { + console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); + expect(true).assertEqual(resultSet.goToFirstRow()); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + expect(100.5).assertEqual(salary); + resultSet.close(); + done(); + }); + console.info(TAG + "************* testRdbStoreQuery004 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreQuerySql.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreQuerySql.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..655c16a5e25f44fc2246c9fa988f06228e3571c5 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreQuerySql.test.ets @@ -0,0 +1,228 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const USER_TABLE = "CREATE TABLE IF NOT EXISTS user " + "(userId INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT , lastName TEXT ," + "age INTEGER , balance REAL NOT NULL)"; + +const BOOK_TABLE = "CREATE TABLE IF NOT EXISTS Book (id INTEGER PRIMARY KEY AUTOINCREMENT," + "name TEXT, userId INTEGER , " + "FOREIGN KEY (userId) REFERENCES user (userId) ON UPDATE NO ACTION ON DELETE CASCADE)"; + +const USER_BULK_INSERT_STATEMENT = "INSERT INTO user" + "(userId, firstName, lastName, age, balance) VALUES " + "(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?)"; + +const BOOK_BULK_INSERT_STATEMENT = "INSERT INTO Book (id, name, userId) " + "VALUES (?,?,?),(?,?,?),(?,?,?)"; + +const STORE_CONFIG = { + name: "QuerySqlTest.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; + +const CURRENT_STORE_VERSION = 1; + +const TAG = "RDB_TEST"; + +let rdbStore = undefined; + +export default function rdbStoreQuerySqlTest() { + describe("rdbStoreQuerySqlTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "beforeEach"); + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await generateUserTable(); + await generateBookTable(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "QuerySqlTest.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function generateUserTable() { + console.info(TAG + "generateUserTable"); + await rdbStore.executeSql(USER_TABLE); + + const users = [ + { userId: 1, firstName: "Zhang", lastName: "San", age: 29, balance: 100.51 }, + { userId: 2, firstName: "Li", lastName: "Si", age: 30, balance: 200.51 }, + { userId: 3, firstName: "wang", lastName: "wu", age: 30, balance: 300.51 }, + { userId: 4, firstName: "sun", lastName: "liu", age: 30, balance: 400.51 }, + { userId: 5, firstName: "ma", lastName: "qi", age: 32, balance: 500.51 }, + ]; + + var objects = new Array(); + users.forEach((user) => { + objects.push(user.userId); + objects.push(user.firstName); + objects.push(user.lastName); + objects.push(user.age); + objects.push(user.balance); + }); + + await rdbStore.executeSql(USER_BULK_INSERT_STATEMENT, objects); + console.info(TAG + "generateUserTable end"); + } + + async function generateBookTable() { + console.info(TAG + "generateBookTable"); + await rdbStore.executeSql(BOOK_TABLE); + + var books = [ + { id: 1, name: "sanguo", userId: 1 }, + { id: 2, name: "xiyouji", userId: 2 }, + { id: 3, name: "shuihuchuan", userId: 3 }, + ]; + + var objects = new Array(); + books.forEach((book) => { + objects.push(book.id); + objects.push(book.name); + objects.push(book.userId); + }); + + await rdbStore.executeSql(BOOK_BULK_INSERT_STATEMENT, objects); + console.info(TAG + "generateBookTable end"); + } + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_SQL_0100 + * @tc.name : testRdbStoreQuerySql001 + * @tc.desc : RdbStore querySql callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuerySql001", 0, async function (done) { + console.info(TAG + "testRdbStoreQuerySql001 begin."); + rdbStore.querySql("SELECT * FROM user INNER JOIN Book ON user.userId = Book.id WHERE Book.name = 'sanguo'", async (err, resultSet) => { + if (err) { + console.error(`Query failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); + expect(1).assertEqual(resultSet.rowCount); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getLong(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getLong(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getLong(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + expect(1).assertEqual(resultSet.getLong(7)); + resultSet.close(); + done(); + }); + console.info(TAG + "testRdbStoreQuerySql001 end."); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_SQL_0200 + * @tc.name : testRdbStoreQuerySql002 + * @tc.desc : RdbStore querySql callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuerySql002", 0, async function (done) { + console.info(TAG + "testRdbStoreQuerySql002 begin."); + rdbStore.querySql("SELECT * FROM user INNER JOIN Book ON user.userId = Book.id WHERE Book.name = ?", ["sanguo"], async (err, resultSet) => { + if (err) { + console.error(`Query failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + console.info(`ResultSet column names: ${resultSet.columnNames}, column count: ${resultSet.columnCount}`); + expect(1).assertEqual(resultSet.rowCount); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getLong(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getLong(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getLong(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + expect(1).assertEqual(resultSet.getLong(7)); + resultSet.close(); + done(); + }); + console.info(TAG + "testRdbStoreQuerySql002 end."); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_SQL_0300 + * @tc.name : testRdbStoreQuerySql003 + * @tc.desc : RdbStore querySql promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuerySql003", 0, async function (done) { + console.info(TAG + "testRdbStoreQuerySql003 begin."); + let resultSet = await rdbStore.querySql("SELECT * FROM user INNER JOIN Book ON user.userId = Book.id WHERE Book.name = 'sanguo'"); + expect(1).assertEqual(resultSet.rowCount); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getLong(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getLong(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getLong(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + expect(1).assertEqual(resultSet.getLong(7)); + resultSet.close(); + done(); + console.info(TAG + "testRdbStoreQuerySql003 end."); + }); + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_QUERY_SQL_0400 + * @tc.name : testRdbStoreQuerySql004 + * @tc.desc : RdbStore querySql promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreQuerySql004", 0, async function (done) { + console.info(TAG + "testRdbStoreQuerySql004 begin."); + let resultSet = await rdbStore.querySql("SELECT * FROM user INNER JOIN Book ON user.userId = Book.id WHERE Book.name = ?", ["sanguo"]); + expect(1).assertEqual(resultSet.rowCount); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getLong(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getLong(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getLong(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + expect(1).assertEqual(resultSet.getLong(7)); + resultSet.close(); + done(); + console.info(TAG + "testRdbStoreQuerySql004 end."); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreTransaction.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreTransaction.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..509d6093e6cbf4927444652b8a91471f4d0f68e6 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreTransaction.test.ets @@ -0,0 +1,274 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS_TEST]"; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; + +const STORE_CONFIG = { + name: "rdbstoreTransactionTest.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; + +let rdbStore = undefined; +let context = null; + +export default function rdbstoreTransactionTest() { + describe("rdbstoreTransactionTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + console.info(TAG + "beforeEach"); + context = globalThis.abilityContext; + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }); + + afterEach(async function () { + console.info(TAG + "afterEach"); + context = globalThis.abilityContext; + await rdbStore.executeSql("DELETE FROM test"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "rdbstoreTransactionTest.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_TRANSACTION_0100 + * @tc.name : testRdbStoreTransaction001 + * @tc.desc : RdbStore beginTransaction and commit test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreTransaction001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreTransaction001 start *************"); + await rdbStore.beginTransaction(); + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + await rdbStore.commit(); + let predicates = new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(1).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + console.info(TAG + "************* testRdbStoreTransaction001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_TRANSACTION_0200 + * @tc.name : testRdbStoreTransaction002 + * @tc.desc : RdbStore beginTransaction and commit test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreTransaction002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreTransaction002 start *************"); + await rdbStore.beginTransaction(); + const valueBucket1 = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket1); + + const valueBucket2 = { + name: "lisi", + age: 23, + salary: 200, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket2); + + const valueBucket3 = { + name: "wangwu", + age: 20, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket3); + + await rdbStore.commit(); + let predicates = new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(3).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + console.info(TAG + "************* testRdbStoreTransaction002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_TRANSACTION_0300 + * @tc.name : testRdbStoreTransaction003 + * @tc.desc : RdbStore beginTransaction and commit test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreTransaction003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreTransaction003 start *************"); + let predicates1 = new relationalStore.RdbPredicates("test"); + let resultSet1 = await rdbStore.query(predicates1); + expect(0).assertEqual(resultSet1.rowCount); + resultSet1.close(); + rdbStore.beginTransaction(); + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + + let predicates = new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(0).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + console.info(TAG + "************* testRdbStoreTransaction003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_TRANSACTION_0400 + * @tc.name : testRdbStoreTransaction004 + * @tc.desc : RdbStore beginTransaction and commit test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreTransaction004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreTransaction004 start *************"); + await rdbStore.beginTransaction(); + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + + await rdbStore.beginTransaction(); + const valueBucket2 = { + name: "lisi", + age: 23, + salary: 200, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket2); + + await rdbStore.commit(); + + await rdbStore.commit(); + + let predicates = new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(2).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + console.info(TAG + "************* testRdbStoreTransaction004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_ROLL_BACK_0100 + * @tc.name : testRdbStoreRollBack001 + * @tc.desc : RdbStore rollBack test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreRollBack001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreRollBack001 start *************"); + await rdbStore.beginTransaction(); + const valueBucket1 = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket1); + + await rdbStore.beginTransaction(); + const valueBucket2 = { + name: "lisi", + age: 23, + salary: 200, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket2); + + await rdbStore.rollBack(); + + await rdbStore.commit(); + + let predicates = new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(1).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + console.info(TAG + "************* testRdbStoreRollBack001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_ROLL_BACK_0200 + * @tc.name : testRdbStoreRollBack002 + * @tc.desc : RdbStore rollBack test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreRollBack002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreRollBack002 start *************"); + try { + await rdbStore.beginTransaction(); + const valueBucket = { + id: 1, + name: "lisi", + age: 18, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + await rdbStore.insert("test", valueBucket); + await rdbStore.insert("test", valueBucket); + + await rdbStore.commit(); + } catch (e) { + await rdbStore.rollBack(); + let predicates = new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "testRdbStoreRollBack002 result count " + resultSet.rowCount); + expect(0).assertEqual(resultSet.rowCount); + resultSet.close(); + done(); + } + console.info(TAG + "************* testRdbStoreRollBack002 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreUpdate.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreUpdate.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..40c065ec94b153e334f2ba9a7aa7cc729911f075 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RdbStoreUpdate.test.ets @@ -0,0 +1,564 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS_TEST]"; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT UNIQUE, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; +const STORE_CONFIG = { + name: "UpdataTest.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; + +let rdbStore = undefined; + +export default function rdbStoreUpdateTest() { + describe("rdbStoreUpdateTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "beforeEach"); + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await createTest(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "UpdataTest.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function createTest() { + console.info(TAG + "createTest start"); + { + var u8 = new Uint8Array([1, 2, 3]); + const valueBucket = { + name: "zhangsan", + age: 18, + salary: 100.5, + blobType: u8, + }; + await rdbStore.insert("test", valueBucket); + } + } + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0100 + * @tc.name : testRdbStoreUpdate001 + * @tc.desc : RdbStore update callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate001", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate001 start *************"); + try { + const valueBucket = { + name: "lisi", + age: 20, + salary: 200.5, + blobType: new Uint8Array([4, 5, 6]), + }; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + rdbStore.update(valueBucket, predicates, async (err, rows) => { + if (err) { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + return; + } + try { + console.info(`Updated row count: ${rows}`); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("lisi").assertEqual(name); + expect(20).assertEqual(age); + expect(200.5).assertEqual(salary); + expect(4).assertEqual(blobType[0]); + expect(5).assertEqual(blobType[1]); + expect(6).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0200 + * @tc.name : testRdbStoreUpdate002 + * @tc.desc : RdbStore update callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate002", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate002 start *************"); + try { + const emptyBucket = {}; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + rdbStore.update(emptyBucket, predicates, async (err, rows) => { + if (err) { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is 6").assertTrue(); + console.info(TAG + "update with wrong valueBucket"); + done(); + } + console.info(`Updated row count: ${rows}`); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0300 + * @tc.name : testRdbStoreUpdate003 + * @tc.desc : RdbStore update callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate003", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate003 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 23, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + + let predicates = new relationalStore.RdbPredicates("test"); + await predicates.equalTo("aaa", "null"); + rdbStore.update(valueBucket, predicates, async (err, rows) => { + if (err) { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is -1").assertTrue(); + console.info(TAG + "update with wrong condition"); + done(); + } + console.info(`Updated row count: ${rows}`); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0400 + * @tc.name : testRdbStoreUpdate004 + * @tc.desc : RdbStore update callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate004", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate004 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 23, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + wrongColumn: 100.5, + }; + + let predicates = new relationalStore.RdbPredicates("wrongTable"); + predicates.equalTo("id", "1"); + rdbStore.update(valueBucket, predicates, async (err, rows) => { + if (err) { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is -1").assertTrue(); + console.info(TAG + "update with wrong table name"); + done(); + } + console.info(`Updated row count: ${rows}`); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0500 + * @tc.name : testRdbStoreUpdate005 + * @tc.desc : RdbStore update callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate005", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate005 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 23, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + wrongColumn: 100.5, + }; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + rdbStore.update(valueBucket, predicates, async (err, rows) => { + if (err) { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is -1").assertTrue(); + console.info(TAG + "update with wrong column name"); + done(); + } + console.info(`Updated row count: ${rows}`); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + done(); + console.info(TAG + "************* testRdbStoreUpdate005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0600 + * @tc.name : testRdbStoreUpdate006 + * @tc.desc : RdbStore update promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate006", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate006 start *************"); + try { + const valueBucket = { + name: "lisi", + age: 20, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + await rdbStore.update(valueBucket, predicates); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("lisi").assertEqual(name); + expect(20).assertEqual(age); + expect(200.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate006 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0700 + * @tc.name : testRdbStoreUpdate007 + * @tc.desc : RdbStore update promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate007", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate007 start *************"); + try { + const emptyBucket = {}; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + let promise = rdbStore.update(emptyBucket, predicates); + promise + .then(async (rows) => { + console.info(`Updated row count: ${rows}`); + }) + .catch((err) => { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is 6").assertTrue(); + console.info(TAG + "update with wrong valueBucket"); + done(); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate007 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0800 + * @tc.name : testRdbStoreUpdate008 + * @tc.desc : RdbStore update promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate008", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate008 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 23, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + }; + + let predicates = new relationalStore.RdbPredicates("test"); + await predicates.equalTo("aaa", "null"); + let promise = rdbStore.update(valueBucket, predicates); + promise + .then(async (rows) => { + console.info(`Updated row count: ${rows}`); + }) + .catch((err) => { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is -1").assertTrue(); + console.info(TAG + "update with wrong condition"); + done(); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate008 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_0900 + * @tc.name : testRdbStoreUpdate009 + * @tc.desc : RdbStore update promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate009", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate009 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 23, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + wrongColumn: 100.5, + }; + + let predicates = new relationalStore.RdbPredicates("wrongTable"); + predicates.equalTo("id", "1"); + let promise = rdbStore.update(valueBucket, predicates); + promise + .then(async (rows) => { + console.info(`Updated row count: ${rows}`); + }) + .catch((err) => { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is -1").assertTrue(); + console.info(TAG + "update with null table name"); + done(); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate009 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_1000 + * @tc.name : testRdbStoreUpdate010 + * @tc.desc : RdbStore update promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate010", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate010 start *************"); + try { + const valueBucket = { + name: "zhangsan", + age: 23, + salary: 100.5, + blobType: new Uint8Array([1, 2, 3]), + wrongColumn: 100.5, + }; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + let promise = rdbStore.update(valueBucket, predicates); + promise + .then(async (rows) => { + console.info(`Updated row count: ${rows}`); + }) + .catch((err) => { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + expect(err.code === 14800000 && err.message === "Inner error. Inner code is -1").assertTrue(); + console.info(TAG + "update with wrong column name"); + done(); + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate010 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_1100 + * @tc.name : testRdbStoreUpdate011 + * @tc.desc : RdbStore update callback with ConflictResolution test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate011", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate011 start *************"); + try { + const valueBucket = { + name: "lisi", + age: 20, + salary: 200.5, + blobType: new Uint8Array([4, 5, 6]), + }; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + rdbStore.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_FAIL, async (err, rows) => { + if (err) { + console.error(`Updated failed, code is ${err.code},message is ${err.message}`); + return; + } + try { + console.info(`Updated row count: ${rows}`); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("lisi").assertEqual(name); + expect(20).assertEqual(age); + expect(200.5).assertEqual(salary); + expect(4).assertEqual(blobType[0]); + expect(5).assertEqual(blobType[1]); + expect(6).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + }); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate011 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RDB_STORE_UPDATE_1200 + * @tc.name : testRdbStoreUpdate012 + * @tc.desc : RdbStore update promise with ConflictResolution test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testRdbStoreUpdate012", 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate012 start *************"); + try { + const valueBucket = { + name: "lisi", + age: 20, + salary: 200.5, + blobType: new Uint8Array([1, 2, 3]), + }; + + let predicates = new relationalStore.RdbPredicates("test"); + predicates.equalTo("id", "1"); + await rdbStore.update(valueBucket, predicates, relationalStore.ConflictResolution.ON_CONFLICT_FAIL); + let resultSet = await rdbStore.query(predicates); + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const name = resultSet.getString(resultSet.getColumnIndex("name")); + const age = resultSet.getLong(resultSet.getColumnIndex("age")); + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")); + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("lisi").assertEqual(name); + expect(20).assertEqual(age); + expect(200.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + resultSet.close(); + done(); + } catch (e) { + console.info("update error " + e); + expect(!e).assertTrue(); + } + console.info(TAG + "************* testRdbStoreUpdate012 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RelationalStore.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RelationalStore.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..18e632bc74b8e0ed260e1609c2850ba3ec582bbd --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/RelationalStore.test.ets @@ -0,0 +1,312 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; +import curves from "@ohos.curves"; + +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)); +} + +let context; +let rdbStore; + +export default function relationalStoreTest() { + describe("relationalStoreTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + context = globalThis.abilityContext; + }); + + 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.number : SUB_DDM_TEST_GET_RDB_STORE_0100 + * @tc.name : testGetRdbStore001 + * @tc.desc : getRdbStore callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetRdbStore001", 0, async function (done) { + console.log(TAG + "************* testGetRdbStore001 start *************"); + let config = { + name: "secure.db", + securityLevel: relationalStore.SecurityLevel.S1, + }; + let getResult = false; + relationalStore.getRdbStore(context, config, async (err, rdbStore) => { + expect(!err).assertTrue(); + if (!err) { + getResult = true; + } else { + console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + try { + await rdbStore.executeSql(CREATE_TABLE_TEST); + } catch (err) { + expect(!err).assertTrue(); + done(); + } + await relationalStore.deleteRdbStore(context, "secure.db"); + expect(getResult).assertTrue(); + done(); + console.info(`Get RdbStore successfully.`); + }); + console.log(TAG + "************* testGetRdbStore001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_GET_RDB_STORE_0200 + * @tc.name : testGetRdbStore002 + * @tc.desc : getRdbStore promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testGetRdbStore002", 0, async function (done) { + console.log(TAG + "************* testGetRdbStore002 start *************"); + let config = { + name: "secure.db", + securityLevel: relationalStore.SecurityLevel.S1, + }; + let storePromise = relationalStore.getRdbStore(context, config); + let getResult = false; + storePromise + .then(async (rdbStore) => { + getResult = true; + try { + await rdbStore.executeSql(CREATE_TABLE_TEST); + } catch (err) { + expect(!err).assertTrue(); + } + await relationalStore.deleteRdbStore(context, "secure.db"); + expect(getResult).assertTrue(); + done(); + }) + .catch((err) => { + expect(!err).assertTrue(); + done(); + }); + console.log(TAG + "************* testGetRdbStore002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_DELETE_RDB_STORE_0100 + * @tc.name : testDeleteRdbStore001 + * @tc.desc : deleteRdbStore callback test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testDeleteRdbStore001", 0, async function (done) { + console.log(TAG + "************* testDeleteRdbStore001 start *************"); + let config = { + name: "secure.db", + securityLevel: relationalStore.SecurityLevel.S1, + }; + rdbStore = await relationalStore.getRdbStore(context, config); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + let deleteResult = false; + relationalStore.deleteRdbStore(context, "secure.db", async (err) => { + if (err) { + console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + } + if (err === undefined) { + deleteResult = true; + } + console.info(`Delete RdbStore successfully.`); + await sleep(1000); + expect(deleteResult).assertTrue(); + done(); + }); + console.log(TAG + "************* testDeleteRdbStore001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_DELETE_RDB_STORE_0200 + * @tc.name : testDeleteRdbStore002 + * @tc.desc : deleteRdbStore promise test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testDeleteRdbStore002", 0, async function (done) { + console.log(TAG + "************* testDeleteRdbStore002 start *************"); + let config = { + name: "secure.db", + securityLevel: relationalStore.SecurityLevel.S1, + }; + rdbStore = await relationalStore.getRdbStore(context, config); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + let deleteResult = false; + let promise = relationalStore.deleteRdbStore(context, "RdbTest.db"); + promise + .then(async () => { + console.info(`Delete RdbStore successfully.`); + deleteResult = true; + await sleep(1000); + expect(deleteResult).assertTrue(); + done(); + }) + .catch((err) => { + console.error(`Delete RdbStore failed, code is ${err.code},message is ${err.message}`); + expect(!err).assertTrue(); + done(); + }); + console.log(TAG + "************* testDeleteRdbStore002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_SYNC_MODE_0100 + * @tc.name : testSyncMode001 + * @tc.desc : SYNC_MODE_PUSH test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testSyncMode001", 0, async function (done) { + console.log(TAG + "************* testSyncMode001 start *************"); + expect(0).assertEqual(relationalStore.SyncMode.SYNC_MODE_PUSH); + done(); + console.log(TAG + "************* testSyncMode001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_SYNC_MODE_0100 + * @tc.name : testSyncMode002 + * @tc.desc : SYNC_MODE_PULL test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testSyncMode002", 0, async function (done) { + console.log(TAG + "************* testSyncMode002 start *************"); + expect(1).assertEqual(relationalStore.SyncMode.SYNC_MODE_PULL); + done(); + console.log(TAG + "************* testSyncMode002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_CONFLICT_RESOLUTION_0100 + * @tc.name : testConflictResolution001 + * @tc.desc : ON_CONFLICT_NONE test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testConflictResolution001", 0, async function (done) { + console.log(TAG + "************* testConflictResolution001 start *************"); + expect(0).assertEqual(relationalStore.ConflictResolution.ON_CONFLICT_NONE); + done(); + console.log(TAG + "************* testConflictResolution001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_CONFLICT_RESOLUTION_0200 + * @tc.name : testConflictResolution002 + * @tc.desc : ON_CONFLICT_ROLLBACK test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testConflictResolution002", 0, async function (done) { + console.log(TAG + "************* testConflictResolution002 start *************"); + expect(1).assertEqual(relationalStore.ConflictResolution.ON_CONFLICT_ROLLBACK); + done(); + console.log(TAG + "************* testConflictResolution002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_CONFLICT_RESOLUTION_0300 + * @tc.name : testConflictResolution003 + * @tc.desc : ON_CONFLICT_ABORT test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testConflictResolution003", 0, async function (done) { + console.log(TAG + "************* testConflictResolution003 start *************"); + expect(2).assertEqual(relationalStore.ConflictResolution.ON_CONFLICT_ABORT); + done(); + console.log(TAG + "************* testConflictResolution003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_CONFLICT_RESOLUTION_0400 + * @tc.name : testConflictResolution004 + * @tc.desc : ON_CONFLICT_FAIL test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testConflictResolution004", 0, async function (done) { + console.log(TAG + "************* testConflictResolution004 start *************"); + expect(3).assertEqual(relationalStore.ConflictResolution.ON_CONFLICT_FAIL); + done(); + console.log(TAG + "************* testConflictResolution004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_CONFLICT_RESOLUTION_0500 + * @tc.name : testConflictResolution005 + * @tc.desc : ON_CONFLICT_IGNORE test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testConflictResolution005", 0, async function (done) { + console.log(TAG + "************* testConflictResolution005 start *************"); + expect(4).assertEqual(relationalStore.ConflictResolution.ON_CONFLICT_IGNORE); + done(); + console.log(TAG + "************* testConflictResolution005 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_CONFLICT_RESOLUTION_0600 + * @tc.name : testConflictResolution006 + * @tc.desc : ON_CONFLICT_REPLACE test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it("testConflictResolution006", 0, async function (done) { + console.log(TAG + "************* testConflictResolution006 start *************"); + expect(5).assertEqual(relationalStore.ConflictResolution.ON_CONFLICT_REPLACE); + done(); + console.log(TAG + "************* testConflictResolution006 end *************"); + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/ResultSet.test.ets b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/ResultSet.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..5c6036888b947db197fc1f5fe8e2913298ef7a32 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/ets/test/ResultSet.test.ets @@ -0,0 +1,1868 @@ +/* + * 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 relationalStore from "@ohos.data.relationalStore"; + +const TAG = "[RDB_JSKITS_TEST]"; +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "data1 text," + "data2 long, " + "data3 double," + "data4 blob)"; + +const STORE_CONFIG = { + name: "Resultset.db", + securityLevel: relationalStore.SecurityLevel.S1, +}; +const COLOUNM_NAMES = ["id", "data1", "data2", "data3", "data4"]; +let rdbStore = undefined; + +export default function rdbResultSetTest() { + describe("rdbResultSetTest", function () { + beforeAll(async function () { + console.info(TAG + "beforeAll"); + }); + + beforeEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "beforeEach"); + rdbStore = await relationalStore.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await createTest(); + }); + + afterEach(async function () { + let context = globalThis.abilityContext; + console.info(TAG + "afterEach"); + rdbStore = null; + await relationalStore.deleteRdbStore(context, "Resultset.db"); + }); + + afterAll(async function () { + console.info(TAG + "afterAll"); + }); + + async function createTest() { + console.info(TAG + "createTest data start"); + { + var u8 = new Uint8Array([1, 2, 3]); + const valueBucket = { + data1: "hello", + data2: 10, + data3: 1.0, + data4: u8, + }; + await rdbStore.insert("test", valueBucket); + } + { + var u8 = new Uint8Array([3, 4, 5]); + const valueBucket = { + data1: "2", + data2: -5, + data3: 2.5, + data4: u8, + }; + await rdbStore.insert("test", valueBucket); + } + { + var u8 = new Uint8Array(0); + const valueBucket = { + data1: "hello world", + data2: 3, + data3: 1.8, + data4: u8, + }; + await rdbStore.insert("test", valueBucket); + } + console.info(TAG + "createTest data end"); + } + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_COLUMN_NAMES_0100 + * @tc.name : testResultSetColumnNames001 + * @tc.desc : ResultSet columnNames test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetColumnNames001", 0, async function (done) { + console.info(TAG + "************* testResultSetColumnNames001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(JSON.stringify(COLOUNM_NAMES)).assertEqual(JSON.stringify(resultSet.columnNames)); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetColumnNames001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_COLUMN_COUNT_0100 + * @tc.name : testResultSetColumnCount001 + * @tc.desc : ResultSet columnCount test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetColumnCount001", 0, async function (done) { + console.info(TAG + "************* testResultSetColumnCount001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(5).assertEqual(resultSet.columnCount); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetColumnCount001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_COLUMN_COUNT_0200 + * @tc.name : testResultSetColumnCount002 + * @tc.desc : ResultSet columnCount test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetColumnCount002", 0, async function (done) { + console.info(TAG + "************* testResultSetColumnCount002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(0).assertEqual(resultSet.columnCount); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetColumnCount002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_ROW_COUNT_0100 + * @tc.name : testResultSetRowCount001 + * @tc.desc : ResultSet rowCount test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetRowCount001", 0, async function (done) { + console.info(TAG + "************* testResultSetRowCount001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(3).assertEqual(resultSet.rowCount); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetRowCount001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_ROW_COUNT_0200 + * @tc.name : testResultSetRowCount002 + * @tc.desc : ResultSet rowCount test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetRowCount002", 0, async function (done) { + console.info(TAG + "************* testResultSetRowCount002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(-1).assertEqual(resultSet.rowCount); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetRowCount002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_ROW_COUNT_0300 + * @tc.name : testResultSetRowCount003 + * @tc.desc : ResultSet rowCount test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetRowCount003", 0, async function (done) { + console.info(TAG + "************* testResultSetRowCount003 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("data1", "hello"); + let resultSet = await rdbStore.query(predicates); + expect(1).assertEqual(resultSet.rowCount); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetRowCount003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_ROW_COUNT_0400 + * @tc.name : testResultSetRowCount004 + * @tc.desc : ResultSet rowCount test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetRowCount004", 0, async function (done) { + console.info(TAG + "************* testResultSetRowCount004 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("data1", "hello"); + predicates.equalTo("data2", 3); + let resultSet = await rdbStore.query(predicates); + expect(0).assertEqual(resultSet.rowCount); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetRowCount004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_ROW_INDEX_0100 + * @tc.name : testResultSetRowIndex001 + * @tc.desc : ResultSet rowIndex test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetRowIndex001", 0, async function (done) { + console.info(TAG + "************* testResultSetRowIndex001 *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(0).assertEqual(resultSet.rowIndex); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetRowIndex001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_ROW_INDEX_0200 + * @tc.name : testResultSetRowIndex002 + * @tc.desc : ResultSet rowIndex test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetRowIndex002", 0, async function (done) { + console.info(TAG + "************* testResultSetRowIndex002 *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(2).assertEqual(resultSet.rowIndex); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetRowIndex002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_FIRST_ROW_0100 + * @tc.name : testResultSetIsAtFirstRow001 + * @tc.desc : ResultSet isAtFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtFirstRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtFirstRow001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtFirstRow001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_FIRST_ROW_0200 + * @tc.name : testResultSetIsAtFirstRow002 + * @tc.desc : ResultSet isAtFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtFirstRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtFirstRow002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtFirstRow002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_FIRST_ROW_0300 + * @tc.name : testResultSetIsAtFirstRow003 + * @tc.desc : ResultSet isAtFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtFirstRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtFirstRow003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(false).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtFirstRow003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_FIRST_ROW_0400 + * @tc.name : testResultSetIsAtFirstRow004 + * @tc.desc : ResultSet isAtFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtFirstRow004", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtFirstRow004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(false).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtFirstRow004 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_FIRST_ROW_0500 + * @tc.name : testResultSetIsAtFirstRow005 + * @tc.desc : ResultSet isAtFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtFirstRow005", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtFirstRow005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goToRow(1); + resultSet.goToRow(0); + expect(true).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtFirstRow005 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_FIRST_ROW_0600 + * @tc.name : testResultSetIsAtFirstRow006 + * @tc.desc : ResultSet isAtFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtFirstRow006", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtFirstRow006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goToRow(1); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtFirstRow006 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_LAST_ROW_0100 + * @tc.name : testResultSetIsAtLastRow001 + * @tc.desc : ResultSet isAtLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtLastRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtLastRow001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(true).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtLastRow001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_LAST_ROW_0200 + * @tc.name : testResultSetIsAtLastRow002 + * @tc.desc : ResultSet isAtLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtLastRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtLastRow002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtLastRow002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_LAST_ROW_0300 + * @tc.name : testResultSetIsAtLastRow003 + * @tc.desc : ResultSet isAtLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtLastRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtLastRow003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(false).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtLastRow003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_LAST_ROW_0400 + * @tc.name : testResultSetIsAtLastRow004 + * @tc.desc : ResultSet isAtLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtLastRow004", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtLastRow004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(false).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtLastRow004 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_LAST_ROW_0500 + * @tc.name : testResultSetIsAtLastRow005 + * @tc.desc : ResultSet isAtLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtLastRow005", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtLastRow005 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goToRow(1); + resultSet.goToRow(2); + expect(true).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtLastRow005 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_AT_LAST_ROW_0600 + * @tc.name : testResultSetIsAtLastRow006 + * @tc.desc : ResultSet isAtLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsAtLastRow006", 0, async function (done) { + console.info(TAG + "************* testResultSetIsAtLastRow006 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goToRow(1); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(true).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsAtLastRow006 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_ENDED_0100 + * @tc.name : testResultSetIsEnded001 + * @tc.desc : ResultSet isEnded test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsEnded001", 0, async function (done) { + console.info(TAG + "************* testResultSetIsEnded001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(false).assertEqual(resultSet.isEnded); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsEnded001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_ENDED_0200 + * @tc.name : testResultSetIsEnded002 + * @tc.desc : ResultSet isEnded test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsEnded002", 0, async function (done) { + console.info(TAG + "************* testResultSetIsEnded002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(false).assertEqual(resultSet.isEnded); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsEnded002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_ENDED_0300 + * @tc.name : testResultSetIsEnded003 + * @tc.desc : ResultSet isEnded test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsEnded003", 0, async function (done) { + console.info(TAG + "************* testResultSetIsEnded003 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goToRow(3); + expect(true).assertEqual(resultSet.isEnded); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsEnded003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_STARTED_0100 + * @tc.name : testResultSetIsStarted001 + * @tc.desc : ResultSet isStarted test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsStarted001", 0, async function (done) { + console.info(TAG + "************* testResultSetIsStarted001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.isStarted); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsStarted001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_STARTED_0200 + * @tc.name : testResultSetIsStarted002 + * @tc.desc : ResultSet isStarted test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsStarted002", 0, async function (done) { + console.info(TAG + "************* testResultSetIsStarted002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goTo(1); + expect(true).assertEqual(resultSet.isStarted); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsStarted002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_STARTED_0300 + * @tc.name : testResultSetIsStarted003 + * @tc.desc : ResultSet isStarted test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsStarted003", 0, async function (done) { + console.info(TAG + "************* testResultSetIsStarted003 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.isStarted); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(true).assertEqual(resultSet.isStarted); + expect(true).assertEqual(resultSet.isStarted); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsStarted003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_CLOSED_0100 + * @tc.name : testResultSetIsClosed001 + * @tc.desc : ResultSet isClosed test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsClosed001", 0, async function (done) { + console.info(TAG + "************* testResultSetIsClosed001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + + expect(3).assertEqual(resultSet.rowCount); + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsClosed001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_CLOSED_0200 + * @tc.name : testResultSetIsClosed002 + * @tc.desc : ResultSet isClosed test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsClosed002", 0, async function (done) { + console.info(TAG + "************* testResultSetIsClosed002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.isClosed); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsClosed002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_CLOSED_0300 + * @tc.name : testResultSetIsClosed003 + * @tc.desc : ResultSet isClosed test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsClosed003", 0, async function (done) { + console.info(TAG + "************* testResultSetIsClosed003 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.isClosed); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsClosed003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_INDEX_0100 + * @tc.name : testResultSetGetColumnIndex001 + * @tc.desc : ResultSet getColumnIndex test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnIndex001", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnIndex001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getColumnIndex("data1")); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnIndex001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_INDEX_0200 + * @tc.name : testResultSetGetColumnIndex002 + * @tc.desc : ResultSet getColumnIndex test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnIndex002", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnIndex002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(-1).assertEqual(resultSet.getColumnIndex("data1")); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnIndex002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_INDEX_0300 + * @tc.name : testResultSetGetColumnIndex003 + * @tc.desc : ResultSet getColumnIndex test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnIndex003", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnIndex003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(-1).assertEqual(resultSet.getColumnIndex("dataX")); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnIndex003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_NAME_0100 + * @tc.name : testResultSetGetColumnName001 + * @tc.desc : ResultSet getColumnName test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnName001", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnName001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + + expect("data1").assertEqual(resultSet.getColumnName(1)); + expect("data4").assertEqual(resultSet.getColumnName(4)); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnName001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_NAME_0200 + * @tc.name : testResultSetGetColumnName002 + * @tc.desc : ResultSet getColumnName test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnName002", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnName002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + + expect("").assertEqual(resultSet.getColumnName(1)); + expect("").assertEqual(resultSet.getColumnName(4)); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnName002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_NAME_0300 + * @tc.name : testResultSetGetColumnName003 + * @tc.desc : ResultSet getColumnName test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnName003", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnName003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + + expect("").assertEqual(resultSet.getColumnName(10)); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnName003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_COLUMN_NAME_0400 + * @tc.name : testResultSetGetColumnName004 + * @tc.desc : ResultSet getColumnName test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetColumnName004", 0, async function (done) { + console.info(TAG + "************* testResultSetGetColumnName004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + + expect("").assertEqual(resultSet.getColumnName(10)); + resultSet.close(); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetColumnName004 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_0100 + * @tc.name : testResultSetGoTo001 + * @tc.desc : ResultSet goTo test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoTo001", 0, async function (done) { + console.info(TAG + "************* testResultSetGoTo001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToFirstRow()); + resultSet.goTo(1); + expect(1).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoTo001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_0200 + * @tc.name : testResultSetGoTo002 + * @tc.desc : ResultSet goTo test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoTo002", 0, async function (done) { + console.info(TAG + "************* testResultSetGoTo002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goTo(1); + expect(-1).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoTo002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_0300 + * @tc.name : testResultSetGoTo003 + * @tc.desc : ResultSet goTo test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoTo003", 0, async function (done) { + console.info(TAG + "************* testResultSetGoTo003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + resultSet.goTo(1); + expect(2).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoTo003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_0400 + * @tc.name : testResultSetGoTo004 + * @tc.desc : ResultSet goTo test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoTo004", 0, async function (done) { + console.info(TAG + "************* testResultSetGoTo004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToLastRow()); + resultSet.goTo(5); + expect(3).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoTo004 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_ROW_0100 + * @tc.name : testResultSetGoToRow001 + * @tc.desc : ResultSet goToRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToRow001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToFirstRow()); + resultSet.goToRow(1); + expect(1).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToRow001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_ROW_0200 + * @tc.name : testResultSetGoToRow002 + * @tc.desc : ResultSet goToRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToRow002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(1); + expect(-1).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToRow002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_ROW_0300 + * @tc.name : testResultSetGoToRow003 + * @tc.desc : ResultSet goToRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToRow003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + resultSet.goToRow(1); + expect(1).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToRow003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_ROW_0400 + * @tc.name : testResultSetGoToRow004 + * @tc.desc : ResultSet goToRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToRow004", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToRow004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToLastRow()); + resultSet.goToRow(5); + expect(3).assertEqual(resultSet.rowIndex); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToRow004 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_FIRST_ROW_0100 + * @tc.name : testResultSetGoToFirstRow001 + * @tc.desc : ResultSet goToFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToFirstRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToFirstRow001 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToFirstRow001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_FIRST_ROW_0200 + * @tc.name : testResultSetGoToFirstRow002 + * @tc.desc : ResultSet goToFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToFirstRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToFirstRow002 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.goToFirstRow()); + expect(false).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToFirstRow002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_FIRST_ROW_0300 + * @tc.name : testResultSetGoToFirstRow003 + * @tc.desc : ResultSet goToFirstRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToFirstRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToFirstRow003 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.isAtFirstRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToFirstRow003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_LAST_ROW_0100 + * @tc.name : testResultSetGoToLastRow001 + * @tc.desc : ResultSet goToLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToLastRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToLastRow001 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(true).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToLastRow001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_Last_ROW_0200 + * @tc.name : testResultSetGoToLastRow002 + * @tc.desc : ResultSet goToLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToLastRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToLastRow002 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.goToLastRow()); + expect(false).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToLastRow002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_Last_ROW_0300 + * @tc.name : testResultSetGoToLastRow003 + * @tc.desc : ResultSet goToLastRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToLastRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToLastRow003 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(true).assertEqual(resultSet.isAtLastRow); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToLastRow003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_NEXT_ROW_0100 + * @tc.name : testResultSetGoToNextRow001 + * @tc.desc : ResultSet goToNextRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToNextRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToNextRow001 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToNextRow()); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToNextRow001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_NEXT_ROW_0200 + * @tc.name : testResultSetGoToNextRow002 + * @tc.desc : ResultSet goToNextRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToNextRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToNextRow002 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.goToNextRow()); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToNextRow002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_NEXT_ROW_0300 + * @tc.name : testResultSetGoToNextRow003 + * @tc.desc : ResultSet goToNextRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToNextRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToNextRow003 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(2).assertEqual(resultSet.rowIndex); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToNextRow003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_NEXT_ROW_0400 + * @tc.name : testResultSetGoToNextRow004 + * @tc.desc : ResultSet goToNextRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToNextRow004", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToNextRow004 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(false).assertEqual(resultSet.goToNextRow()); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToNextRow004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_PREVIOUS_ROW_0100 + * @tc.name : testResultSetGoToPreviousRow001 + * @tc.desc : ResultSet goToPreviousRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToPreviousRow001", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToPreviousRow001 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.goToPreviousRow()); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToPreviousRow001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_PREVIOUS_ROW_0200 + * @tc.name : testResultSetGoToPreviousRow002 + * @tc.desc : ResultSet goToPreviousRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToPreviousRow002", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToPreviousRow002 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + expect(false).assertEqual(resultSet.goToPreviousRow()); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToPreviousRow002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_PREVIOUS_ROW_0300 + * @tc.name : testResultSetGoToPreviousRow003 + * @tc.desc : ResultSet goToPreviousRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToPreviousRow003", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToPreviousRow003 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + expect(true).assertEqual(resultSet.goToPreviousRow()); + expect(0).assertEqual(resultSet.rowIndex); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToPreviousRow003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GO_TO_PREVIOUS_ROW_0400 + * @tc.name : testResultSetGoToPreviousRow004 + * @tc.desc : ResultSet goToPreviousRow test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGoToPreviousRow004", 0, async function (done) { + console.info(TAG + "************* testResultSetGoToPreviousRow004 start *************"); + + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + expect(true).assertEqual(resultSet.goToLastRow()); + expect(true).assertEqual(resultSet.goToPreviousRow()); + expect(1).assertEqual(resultSet.rowIndex); + resultSet.close(); + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGoToPreviousRow004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_BLOB_0100 + * @tc.name : testResultSetGetBlob001 + * @tc.desc : ResultSet getBlob test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetBlob001", 0, async function (done) { + console.info(TAG + "************* testResultSetGetBlob001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + try { + { + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const data4 = resultSet.getBlob(resultSet.getColumnIndex("data4")); + console.info(TAG + "id=" + id + ", data4=" + data4); + expect(1).assertEqual(data4[0]); + expect(2).assertEqual(data4[1]); + expect(3).assertEqual(data4[2]); + } + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + } catch (e) { + expect(!e).assertTrue(); + } + resultSet = null; + done(); + console.info(TAG + "************* testGetBlob0001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_BLOB_0200 + * @tc.name : testResultSetGetBlob002 + * @tc.desc : ResultSet getBlob test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetBlob002", 0, async function (done) { + console.info(TAG + "************* testResultSetGetBlob002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + try { + { + resultSet.goToRow(1); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const data4 = resultSet.getBlob(resultSet.getColumnIndex("data4")); + console.info(TAG + "id=" + id + ", data4=" + data4); + expect(3).assertEqual(data4[0]); + expect(4).assertEqual(data4[1]); + expect(5).assertEqual(data4[2]); + } + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + } catch (e) { + expect(!e).assertTrue(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetBlob002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_STRING_0100 + * @tc.name : testResultSetGetString001 + * @tc.desc : ResultSet getString test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetString001", 0, async function (done) { + console.info(TAG + "************* testResultSetGetString001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToFirstRow()); + const data1 = resultSet.getString(resultSet.getColumnIndex("data1")); + expect("hello").assertEqual(data1); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetString001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_STRING_0200 + * @tc.name : testResultSetGetString002 + * @tc.desc : ResultSet getString test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetString002", 0, async function (done) { + console.info(TAG + "************* testResultSetGetString002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + expect(true).assertEqual(resultSet.goToFirstRow()); + const data2 = resultSet.getString(resultSet.getColumnIndex("data2")); + expect("10").assertEqual(data2); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetString002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_STRING_0300 + * @tc.name : testResultSetGetString003 + * @tc.desc : ResultSet getString test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetString003", 0, async function (done) { + console.info(TAG + "************* testResultSetGetString003 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(1); + const data3 = resultSet.getString(resultSet.getColumnIndex("data3")); + expect("2.5").assertEqual(data3); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetString003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_STRING_0400 + * @tc.name : testResultSetGetString004 + * @tc.desc : ResultSet getString test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetString004", 0, async function (done) { + console.info(TAG + "************* testResultSetGetString004 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(2); + const data1 = resultSet.getString(resultSet.getColumnIndex("data1")); + const data2 = resultSet.getString(resultSet.getColumnIndex("data2")); + const data3 = resultSet.getString(resultSet.getColumnIndex("data3")); + expect("hello world").assertEqual(data1); + expect("3").assertEqual(data2); + expect("1.8").assertEqual(data3); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetString004 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_LONG_0100 + * @tc.name : testResultSetGetLong001 + * @tc.desc : ResultSet getLong test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetLong001", 0, async function (done) { + console.info(TAG + "************* testResultSetGetLong001 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + try { + { + expect(true).assertEqual(resultSet.goToFirstRow()); + const id = resultSet.getLong(resultSet.getColumnIndex("id")); + const data2 = resultSet.getLong(resultSet.getColumnIndex("data2")); + console.info(TAG + "id=" + id + ", data2=" + data2); + expect(10).assertEqual(data2); + } + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + } catch (e) { + expect(!e).assertTrue(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetLong001 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_LONG_0200 + * @tc.name : testResultSetGetLong002 + * @tc.desc : ResultSet getLong test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetLong002", 0, async function (done) { + console.info(TAG + "************* testResultSetGetLong002 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + try { + { + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + const data1 = resultSet.getLong(resultSet.getColumnIndex("data1")); + expect(2).assertEqual(data1); + } + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + } catch (e) { + expect(!e).assertTrue(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetLong002 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_LONG_0300 + * @tc.name : testResultSetGetLong003 + * @tc.desc : ResultSet getLong test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetLong003", 0, async function (done) { + console.info(TAG + "************* testResultSetGetLong003 start *************"); + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + try { + { + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(true).assertEqual(resultSet.goToNextRow()); + const data2 = resultSet.getLong(resultSet.getColumnIndex("data2")); + expect(-5).assertEqual(data2); + } + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + } catch (e) { + expect(!e).assertTrue(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetLong003 end *************"); + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_DOUBLE_0100 + * @tc.name : testResultSetGetDouble001 + * @tc.desc : ResultSet getDouble test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetDouble001", 0, async function (done) { + console.info(TAG + "************* testResultSetGetDouble001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(0); + const data3 = resultSet.getDouble(resultSet.getColumnIndex("data3")); + expect(1.0).assertEqual(data3); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetDouble001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_DOUBLE_0200 + * @tc.name : testResultSetGetDouble002 + * @tc.desc : ResultSet getDouble test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetDouble002", 0, async function (done) { + console.info(TAG + "************* testResultSetGetDouble002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(1); + const data3 = resultSet.getDouble(resultSet.getColumnIndex("data3")); + expect(2.5).assertEqual(data3); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetDouble002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_DOUBLE_0300 + * @tc.name : testResultSetGetDouble003 + * @tc.desc : ResultSet getDouble test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetDouble003", 0, async function (done) { + console.info(TAG + "************* testResultSetGetDouble003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(2); + const data3 = resultSet.getDouble(resultSet.getColumnIndex("data3")); + expect(1.8).assertEqual(data3); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetDouble003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_GET_DOUBLE_0400 + * @tc.name : testResultSetGetDouble004 + * @tc.desc : ResultSet getDouble test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetGetDouble004", 0, async function (done) { + console.info(TAG + "************* testResultSetGetDouble004 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(0); + const data2 = resultSet.getDouble(resultSet.getColumnIndex("data2")); + expect(10).assertEqual(data2); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetGetDouble004 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_COLUMN_NULL_0100 + * @tc.name : testResultSetIsColumnNull001 + * @tc.desc : ResultSet isColumnNull test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsColumnNull001", 0, async function (done) { + console.info(TAG + "************* testResultSetIsColumnNull001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(2); + const isColumnNull1 = resultSet.isColumnNull(resultSet.getColumnIndex("data1")); + expect(false).assertEqual(isColumnNull1); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsColumnNull001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_COLUMN_NULL_0200 + * @tc.name : testResultSetIsColumnNull002 + * @tc.desc : ResultSet isColumnNull test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsColumnNull002", 0, async function (done) { + console.info(TAG + "************* testResultSetIsColumnNull002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(2); + const isColumnNull4 = resultSet.isColumnNull(resultSet.getColumnIndex("data4")); + expect(true).assertEqual(isColumnNull4); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsColumnNull002 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_IS_COLUMN_NULL_0300 + * @tc.name : testResultSetIsColumnNull003 + * @tc.desc : ResultSet isColumnNull test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetIsColumnNull003", 0, async function (done) { + console.info(TAG + "************* testResultSetIsColumnNull003 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + { + resultSet.goToRow(2); + expect(false).assertEqual(resultSet.isColumnNull(1)); + resultSet.close(); + } + resultSet = null; + done(); + console.info(TAG + "************* testResultSetIsColumnNull003 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_CLOSE_0100 + * @tc.name : testResultSetClose001 + * @tc.desc : ResultSet close test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetClose001", 0, async function (done) { + console.info(TAG + "************* testResultSetClose001 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates); + resultSet.goToRow(1); + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetClose001 end *************"); + } + }); + + /** + * @tc.number : SUB_DDM_TEST_RESULT_SET_CLOSE_0200 + * @tc.name : testResultSetClose002 + * @tc.desc : ResultSet close test + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it("testResultSetClose002", 0, async function (done) { + console.info(TAG + "************* testResultSetClose002 start *************"); + { + let predicates = await new relationalStore.RdbPredicates("test"); + predicates.equalTo("name", "wangwu"); + let resultSet = await rdbStore.query(predicates); + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed); + + resultSet = null; + done(); + console.info(TAG + "************* testResultSetClose002 end *************"); + } + }); + }); +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/module.json b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..d00ed1532da0830d9a234608870e0baa6ed92c6a --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/module.json @@ -0,0 +1,36 @@ +{ + "module": { + "name": "relationalstore_test_normal_ets", + "type": "feature", + "description": "$string:module_test_desc", + "mainElement": "TestAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:test_pages", + "abilities": [ + { + "name": "TestAbility", + "srcEntry": "./ets/TestAbility/TestAbility.ets", + "description": "$string:TestAbility_desc", + "icon": "$media:icon", + "label": "$string:TestAbility_label", + "exported": true, + "startWindowIcon": "$media:icon", + "startWindowBackground": "$color:start_window_background", + "skills": [ + { + "actions": [ + "action.system.home" + ], + "entities": [ + "entity.system.home" + ] + } + ] + } + ] + } +} diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/element/color.json b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/element/color.json new file mode 100644 index 0000000000000000000000000000000000000000..3c712962da3c2751c2b9ddb53559afcbd2b54a02 --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/element/color.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "start_window_background", + "value": "#FFFFFF" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/element/string.json b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..65d8fa5a7cf54aa3943dcd0214f58d1771bc1f6c --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "module_test_desc", + "value": "test ability description" + }, + { + "name": "TestAbility_desc", + "value": "the test ability" + }, + { + "name": "TestAbility_label", + "value": "test label" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/media/icon.png b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/profile/test_pages.json b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/profile/test_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..77e90731b5a38d861663029b483df3d3ac9ec74b --- /dev/null +++ b/distributeddatamgr/crossplatform/relationalstoreetstest/src/main/resources/base/profile/test_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "TestAbility/pages/Index" + ] +}