diff --git a/distributeddatamgr/relationalStoretest/BUILD.gn b/distributeddatamgr/relationalStoretest/BUILD.gn index 50227449221655df6c85166ab6c1ced1be1e71a9..a62aeb6da3838e560449af3eb6b839483389a5d5 100644 --- a/distributeddatamgr/relationalStoretest/BUILD.gn +++ b/distributeddatamgr/relationalStoretest/BUILD.gn @@ -17,6 +17,7 @@ group("relationalStoretest") { testonly = true if (is_standard_system) { deps = [ + "RdbJstest/hap:rdb_js_test", "relationalStoreJstest/hap:relationalstore_js_test", "relationalStoreStagetest:relationalstore_ets_test", ] diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/BUILD.gn b/distributeddatamgr/relationalStoretest/RdbJstest/hap/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8220ffd21b1d9634b2c63713e36ef35393230a98 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/BUILD.gn @@ -0,0 +1,35 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("rdb_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":rdb_js_assets", + ":rdb_resources", + ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ActsRdbJsTest" + subsystem_name = "distributeddatamgr" + part_name = "relational_store" +} +ohos_js_assets("rdb_js_assets") { + js2abc = true + hap_profile = "./src/main/config.json" + source_dir = "./src/main/js" +} +ohos_resources("rdb_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" +} diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/Test.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..8c3a9347b3e0177fb6632c4b4f4f42ce15603dd1 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/Test.json @@ -0,0 +1,19 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "OHJSUnitTest", + "test-timeout": "1000000", + "shell-timeout": "1000000", + "bundle-name": "ohos.acts.rdbjstest", + "package-name": "ohos.acts.rdbjstest" + }, + "kits": [ + { + "test-file-name": [ + "ActsRdbJsTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/relationalStoretest/RdbJstest/hap/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..2da86c3e3312e1152fcd3af78b41c3764b9251f5 Binary files /dev/null and b/distributeddatamgr/relationalStoretest/RdbJstest/hap/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/config.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..ce8e978ec4417ce08602410e886ed64b85a4d8cd --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/config.json @@ -0,0 +1,95 @@ +{ + "app": { + "bundleName": "ohos.acts.rdbjstest", + "vendor": "example", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 4, + "target": 5 + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.acts.rdbjstest", + "name": ".entry", + "deviceType": [ + "tablet", + "default", + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "formsEnabled": false, + "name": ".MainAbility", + "srcLanguage": "js", + "srcPath": "MainAbility", + "icon": "$media:icon", + "description": "$string:MainAbility_desc", + "label": "$string:MainAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + }, + { + "orientation": "unspecified", + "formsEnabled": false, + "name": ".TestAbility", + "srcLanguage": "js", + "srcPath": "TestAbility", + "icon": "$media:icon", + "description": "$string:TestAbility_desc", + "label": "$string:TestAbility_label", + "type": "page", + "visible": true, + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + }, + { + "pages": [ + "pages/index/index" + ], + "name": ".TestAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ], + "testRunner": { + "name": "OpenHarmonyTestRunner", + "srcPath": "TestRunner" + }, + "mainAbility": ".MainAbility", + "srcPath": "" + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/app.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..9b225d0cce79fd927c66e75cd35a88267a92431d --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/app.js @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +export default { + onCreate() { + console.info('TestApplication onCreate'); + }, + onDestroy() { + console.info('TestApplication onDestroy'); + } +}; diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/i18n/en-US.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/i18n/zh-CN.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.css b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..59e50f0bfb9ab1919501533a2b8b87771a4162e9 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.css @@ -0,0 +1,23 @@ +/* +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.hml b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..99a01341103ff63765e8163279d1e50a00e039d4 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{title}} + +
diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..aabb387ce9cfbc983eb0c62756fdd4c6607e778b --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/MainAbility/pages/index/index.js @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +const injectRef = Object.getPrototypeOf(global) || global +injectRef.regeneratorRuntime = require('@babel/runtime/regenerator') + +export default { + data: { + title: '' + }, + onInit() { + this.title = this.$t('strings.world'); + }, + onShow() { + console.info('onShow finish') + }, + onReady() { + }, +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/app.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/app.js new file mode 100644 index 0000000000000000000000000000000000000000..cdc31f3dcf031e2f6a7665d9653e53bb649e21c5 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/app.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' +import { Hypium } from '@ohos/hypium' +import testsuite from '../test/List.test' + +export default { + onCreate() { + console.info('TestApplication onCreate') + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + console.info('start run testcase!!!') + Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite) + }, + onDestroy() { + console.info("TestApplication onDestroy"); + } +}; diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/i18n/en-US.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..3cb24b374b1d919ca8eac0638f361692b603a900 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/i18n/en-US.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/i18n/zh-CN.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..c804e32c0c3103929baca5617cdac70be11fdba1 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/i18n/zh-CN.json @@ -0,0 +1,8 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + }, + "Files": { + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.css b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..b1bcd43387ba131cc1d30975ff7508a6f8084a4b --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.css @@ -0,0 +1,30 @@ +.container { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + left: 0px; + top: 0px; + width: 100%; + height: 100%; +} + +.title { + font-size: 60px; + text-align: center; + width: 100%; + height: 40%; + margin: 10px; +} + +@media screen and (device-type: phone) and (orientation: landscape) { + .title { + font-size: 60px; + } +} + +@media screen and (device-type: tablet) and (orientation: landscape) { + .title { + font-size: 100px; + } +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.hml b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f629c71a9be857db6cdf94149652a191b9b272ea --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..88b083a7f6b979019d6a2c5ad20b19c5fd43286b --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestAbility/pages/index/index.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + data: { + title: "" + }, + onInit() { + this.title = this.$t('strings.world'); + } +} + + + diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js new file mode 100644 index 0000000000000000000000000000000000000000..c5fa8620ca77d381f20b65a903b833e6e3378c97 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' + +function translateParamsToString(parameters) { + const keySet = new Set([ + '-s class', '-s notClass', '-s suite', '-s itName', + '-s level', '-s testType', '-s size', '-s timeout', + '-s package', '-s dryRun' + ]) + let targetParams = ''; + for (const key in parameters) { + if (keySet.has(key)) { + targetParams += ' ' + key + ' ' + parameters[key] + } + } + return targetParams.trim() +} + + export default { + onPrepare() { + console.info('OpenHarmonyTestRunner OnPrepare') + }, + onRun() { + console.log('OpenHarmonyTestRunner onRun run') + var abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments() + var abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator() + + var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' + + var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) + var debug = abilityDelegatorArguments.parameters["-D"] + console.info('debug value : '+debug) + if (debug == 'true') + { + cmd += ' -D' + } + console.info('cmd : '+cmd) + abilityDelegator.executeShellCommand(cmd, (err, data) => { + console.info('executeShellCommand : err : ' + JSON.stringify(err)); + console.info('executeShellCommand : data : ' + data.stdResult); + console.info('executeShellCommand : data : ' + data.exitCode); + }) + } +}; diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..84bcde52bf21fa6139556987a94939085268059f --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/List.test.js @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2021 Huawei Device Co., Ltd. +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js' +import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js' +import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js' +import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js' +import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js' +import rdbStorePredicatesJoinTest from './RdbstorePredicatesJoinJsunit.test.js' +import rdbPredicatesTest from './RdbstorePredicatesJsunit.test.js' +import rdbStoreTest from './RdbstoreRdbstoreJsunit.test.js' +import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js' +import rdbstoreStoreExcuteSqlTest from './RdbstoreStoreExcuteSqlJsunit.test.js' +import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js' +import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js' +import rdbstoreQueryTest from './RdbstoreQuery.test.js' +import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js' +import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js' +export default function testsuite() { + rdbStoreBackupRestoreCallbackTest() + rdbStoreBackupRestoreWithFAContextTest() + rdbStoreDeleteTest() + rdbStoreDistributedTest() + rdbstoreInsertTest() + rdbStorePredicatesJoinTest() + rdbPredicatesTest() + rdbStoreTest() + rdbResultSetTest() + rdbstoreStoreExcuteSqlTest() + rdbstoreTransactionTest() + rdbStoreUpdateTest() + rdbstoreQueryTest() + rdbStoreEncryptionTest() + rdbStorePredicatesComplexFiledTest() +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbStoreDistributedJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js similarity index 96% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js index 639e7266fab94e94d237fa09e35a93e04436bae4..e1968d31f3049e082dab5cab69fd8484ab0a33ab 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbStoreResultSetJsunit.test.js @@ -1649,22 +1649,17 @@ describe('rdbResultSetTest', function () { * @tc.number SUB_DDM_AppDataFWK_JSRDB_ResultSet_0203 * @tc.desc resultSet getColumnIndex test */ - it('testGetColumnIndex0004', 0, async function (done) { + it('testGetColumnIndex0004', 0, async function (done) { console.info(TAG + '************* testGetColumnIndex0004 start *************'); - let errInfo = undefined; - let predicates = await new dataRdb.RdbPredicates('test') - let resultSet = await rdbStore.query(predicates) - try{ - let resultSetresult = resultSet.getColumnIndex('') - expect(-1).assertEqual(resultSetresult) - }catch(err){ - errInfo = err - } - expect(errInfo.code).assertEqual("401") - resultSet = null; - done(); - console.info(TAG + '************* testGetColumnIndex0004 end *************'); - + { + let predicates = await new dataRdb.RdbPredicates('test'); + let resultSet = await rdbStore.query(predicates); + expect(-1).assertEqual(resultSet.getColumnIndex('')); + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnIndex0004 end *************'); + } }) /** diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreBackupRestoreCallbackJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreBackupRestoreWithFAContextJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreDeleteJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreEncryptionJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstorePredicatesComplexFiledJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstorePredicatesJoinJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstorePredicatesJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreQuery.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreQuery.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreQuery.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreQuery.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreRdbstoreJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreStoreExcuteSqlJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js similarity index 100% rename from distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js rename to distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/resources/base/element/string.json b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ccd87bb736f8b939f2a77131835e4da903dfed --- /dev/null +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/resources/base/element/string.json @@ -0,0 +1,28 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "label" + }, + { + "name": "TestAbility_desc", + "value": "description" + }, + { + "name": "TestAbility_label", + "value": "label" + } + ] +} diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/resources/base/media/icon.png b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/Test.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/Test.json index d4a01d80ac72f28e31b30bdca0c53beeb3a69d34..e2a3a1b0d7d9dc0744ba3b6f71fd1c6303d34e30 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/Test.json +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/Test.json @@ -4,8 +4,8 @@ "type": "OHJSUnitTest", "test-timeout": "1000000", "shell-timeout": "1000000", - "bundle-name": "ohos.acts.relationalStorejstest", - "package-name": "ohos.acts.relationalStorejstest" + "bundle-name": "ohos.acts.relationalstorejstest", + "package-name": "ohos.acts.relationalstorejstest" }, "kits": [ { diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/signature/openharmony_sx.p7b b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/signature/openharmony_sx.p7b index 4bb6d7690796dc26857e209e50b8ec06c50ae029..79c80900b7d77d8d84b4c2d8581ce37de628ba1a 100644 Binary files a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/signature/openharmony_sx.p7b and b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json index 81053ee05cb265d4b0510e18f1538de0a1c5d3c4..dfc5cc031dca5df1f30ef337c7e4a05f891e27c9 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "ohos.acts.relationalStorejstest", + "bundleName": "ohos.acts.relationalstorejstest", "vendor": "example", "version": { "code": 1, @@ -13,11 +13,11 @@ }, "deviceConfig": {}, "module": { - "package": "ohos.acts.relationalStorejstest", + "package": "ohos.acts.relationalstorejstest", "name": ".entry", "deviceType": [ - "tablet", - "default", + "tablet", + "default", "phone" ], "distro": { diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js index 84bcde52bf21fa6139556987a94939085268059f..52b584b16f6a3e5d9247859d5b89ca31200b9505 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/List.test.js @@ -1,5 +1,5 @@ /* -* Copyright (c) 2021 Huawei Device Co., Ltd. +* Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,35 +12,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import rdbStoreBackupRestoreCallbackTest from './RdbstoreBackupRestoreCallbackJsunit.test.js' -import rdbStoreBackupRestoreWithFAContextTest from './RdbstoreBackupRestoreWithFAContextJsunit.test.js' -import rdbStoreDeleteTest from './RdbstoreDeleteJsunit.test.js' -import rdbStoreDistributedTest from './RdbStoreDistributedJsunit.test.js' -import rdbstoreInsertTest from './RdbstoreInsertJsunit.test.js' -import rdbStorePredicatesJoinTest from './RdbstorePredicatesJoinJsunit.test.js' -import rdbPredicatesTest from './RdbstorePredicatesJsunit.test.js' -import rdbStoreTest from './RdbstoreRdbstoreJsunit.test.js' -import rdbResultSetTest from './RdbStoreResultSetJsunit.test.js' -import rdbstoreStoreExcuteSqlTest from './RdbstoreStoreExcuteSqlJsunit.test.js' -import rdbstoreTransactionTest from './RdbstoreTransactionJsunit.test.js' -import rdbStoreUpdateTest from './RdbstoreUpdateJsunit.test.js' -import rdbstoreQueryTest from './RdbstoreQuery.test.js' -import rdbStoreEncryptionTest from './RdbstoreEncryptionJsunit.test.js' -import rdbStorePredicatesComplexFiledTest from './RdbstorePredicatesComplexFiledJsunit.test.js' +import relationalStoreBackupRestoreCallbackTest from './RelationalStoreBackupRestoreCallbackJsunit.test.js' +import relationalStoreBackupRestoreWithFAContextTest from './RelationalStoreBackupRestoreWithFAContextJsunit.test.js' +import relationalStoreDeleteTest from './RelationalStoreDeleteJsunit.test.js' +import relationalStoreDistributedTest from './RelationalStoreDistributedJsunit.test.js' +import relationalStoreInsertTest from './RelationalStoreInsertJsunit.test.js' +import relationalStorePredicatesJoinTest from './RelationalStorePredicatesJoinJsunit.test.js' +import relationalStorePredicatesTest from './RelationalStorePredicatesJsunit.test.js' +import relationalStoreTest from './RelationalStoreJsunit.test.js' +import relationalStoreResultSetTest from './RelationalStoreResultSetJsunit.test.js' +import relationalStoreExcuteSqlTest from './RelationalStoreExcuteSqlJsunit.test.js' +import relationalStoreTransactionTest from './RelationalStoreTransactionJsunit.test.js' +import relationalStoreUpdateTest from './RelationalStoreUpdateJsunit.test.js' +import relationalStoreQueryTest from './RelationalStoreQuery.test.js' +import relationalStoreEncryptionTest from './RelationalStoreEncryptionJsunit.test.js' +import relationalStorePredicatesComplexFiledTest from './RelationalStorePredicatesComplexFiledJsunit.test.js' export default function testsuite() { - rdbStoreBackupRestoreCallbackTest() - rdbStoreBackupRestoreWithFAContextTest() - rdbStoreDeleteTest() - rdbStoreDistributedTest() - rdbstoreInsertTest() - rdbStorePredicatesJoinTest() - rdbPredicatesTest() - rdbStoreTest() - rdbResultSetTest() - rdbstoreStoreExcuteSqlTest() - rdbstoreTransactionTest() - rdbStoreUpdateTest() - rdbstoreQueryTest() - rdbStoreEncryptionTest() - rdbStorePredicatesComplexFiledTest() + relationalStoreBackupRestoreCallbackTest() + relationalStoreBackupRestoreWithFAContextTest() + relationalStoreDeleteTest() + relationalStoreDistributedTest() + relationalStoreInsertTest() + relationalStorePredicatesJoinTest() + relationalStorePredicatesTest() + relationalStoreTest() + relationalStoreResultSetTest() + relationalStoreExcuteSqlTest() + relationalStoreTransactionTest() + relationalStoreUpdateTest() + relationalStoreQueryTest() + relationalStoreEncryptionTest() + relationalStorePredicatesComplexFiledTest() } diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreBackupRestoreCallbackJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreBackupRestoreCallbackJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..86afb34c03d4775bb4343725b3731a87c192ff8d --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreBackupRestoreCallbackJsunit.test.js @@ -0,0 +1,462 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore' +import ability_featureAbility from '@ohos.ability.featureAbility' +import fileio from '@ohos.fileio' + +const TAG = "[RelationalStore_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)" +const DATABASE_DIR = "/data/storage/el2/database/entry/rdb/" +var RdbStore +var context = ability_featureAbility.getContext() +const STORE_CONFIG = { + name: "BackupResotreTest.db", + securityLevel: data_Rdb.SecurityLevel.S1 +} +const DATABASE_BACKUP_NAME = "Backup.db" + +async function CreatRdbStore(context, STORE_CONFIG) { + let RdbStore = await data_Rdb.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 +} + +function BackupCallbackTest(backupName) { + try { + RdbStore.backup(backupName, (err, data) => { + if(err != null){ + console.info(TAG + "Backup error: " + err) + expect(true).assertTrue() + }else{ + expect(false).assertTrue(); + } + }) + } catch(errInfo){ + console.info(TAG + "BackupCallbackTest error: " + errInfo) + expect(true).assertTrue() + } + + RdbStore = null +} + +function ReStoreCallbackTest(restoreName) { + try { + RdbStore.restore(restoreName, (err, data) => { + if(err != null){ + console.info(TAG + "Restore error: " + err) + expect(true).assertTrue() + }else{ + expect(false).assertTrue(); + } + }) + } catch(errInfo) { + console.info(TAG + "ReStoreCallbackTest error: " + errInfo) + expect(true).assertTrue() + } + + RdbStore = null +} + +export default function relationalStoreBackupRestoreCallbackTest() { + describe('relationalStoreBackupRestoreCallbackTest', 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') + await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name) + await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME) + await data_Rdb.deleteRdbStore(context, "BackupTest003.db") + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************") + + /** + * @tc.name RelationalStore Backup Restore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0100 + * @tc.desc RelationalStore backup and restore function test + */ + it('RdbBackupRestoreCallbackTest_0100', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 start *************") + + // RelationalStore backup function test + await RdbStore.backup(DATABASE_BACKUP_NAME,async (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + try { + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) + } catch (err) { + expect(false).assertTrue() + } + } + + + // RelationalStore before restored, delete data + let deleteData = new data_Rdb.RdbPredicates("backupTest") + deleteData.equalTo("name", "zhangsan") + RdbStore.delete(deleteData).then(()=> { + RdbStore.restore(DATABASE_BACKUP_NAME, async (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + try { + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + expect(false).assertTrue() + } catch (err) { + expect(true).assertTrue() + } + + try { + fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) + } catch (err) { + expect(false).assertTrue() + } + let predicates = new data_Rdb.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]) + } catch (err) { + console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err) + expect(false).assertTrue() + } + resultSet = null + RdbStore = null + } + done() + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0100 end *************") + }) + }) + }) + }) + + /** + * @tc.name RelationalStore Backup test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0200 + * @tc.desc RelationalStore backup function test + */ + it('RdbBackupRestoreCallbackTest_0200', 0, function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 start *************") + // RelationalStore backup function test, backup file name empty + BackupCallbackTest("") + + // RelationalStore backup function test, backup file name already exists + BackupCallbackTest(STORE_CONFIG.name) + + done() + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0200 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0300 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0300', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 start *************") + let backupName = "BackupTest003.db" + await RdbStore.backup(backupName) + + // RelationalStore restore function test, backup file name empty + ReStoreCallbackTest("") + + // RelationalStore restore function test, backup file is specified to database name + ReStoreCallbackTest(STORE_CONFIG.name) + + done() + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0300 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0400 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0400', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 start *************") + let dbName = "notExistName.db" + + // RelationalStore restore function test, backup file does not exists + try { + fileio.accessSync(DATABASE_DIR + dbName) + expect(false).assertTrue() + } catch { + ReStoreCallbackTest(dbName) + } + + done() + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0400 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0500 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0500', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 start *************") + + // RelationalStore restore function test, backup file + RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + try{ + console.info(TAG + 'Backup database success') + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + expect(false).assertTrue(); + } + data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => { + try{ + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + console.info(TAG + 'error2 ' + err) + expect(true).assertTrue(); + } + RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + console.info(`${TAG} Backup database second failed, error: message: ${err.message}`) + expect(true).assertTrue() + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0500 end *************") + }else{ + try{ + console.info(TAG + 'Backup database second success') + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + expect(false).assertTrue(); + } + } + }) + }) + } + }) + + + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0600 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0600', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 start *************") + + // Backup file is specified to database name + RdbStore.backup(STORE_CONFIG.name, (err, data) => { + if(err != null){ + expect(true).assertTrue() + }else{ + expect(false).assertTrue() + } + }) + + RdbStore.backup(STORE_CONFIG.name, (err, data) => { + if(err != null){ + expect(true).assertTrue() + }else{ + expect(false).assertTrue() + } + }) + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0600 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0700 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0700', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 start *************") + let DATABASE_BACKUP_TEST_NAME = "BackupTest.db" + RdbStore.backup(DATABASE_BACKUP_TEST_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + expect(true).assertTrue() + } + }) + await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_TEST_NAME).then(() => { + try{ + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_TEST_NAME) + }catch(err){ + expect(true).assertTrue(); + } + }) + + RdbStore.restore(DATABASE_BACKUP_TEST_NAME, (err, data) => { + if(err != null){ + expect(true).assertTrue() + } + }) + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0700 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0800 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0800', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 start *************") + BackupCallbackTest() + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0800 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_0900 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_0900', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 start *************") + BackupCallbackTest([DATABASE_BACKUP_NAME]) + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_0900 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1000 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_1000', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 start *************") + RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + } + }) + ReStoreCallbackTest([DATABASE_BACKUP_NAME]) + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1000 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1100 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_1100', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 start *************") + RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + } + }) + ReStoreCallbackTest() + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1100 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1200 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_1200', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 start *************") + RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + } + }) + BackupCallbackTest(DATABASE_BACKUP_NAME) + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1200 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreCallbackTest_1300 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreCallbackTest_1300', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 start *************") + RdbStore.backup(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + RdbStore.restore(DATABASE_BACKUP_NAME, (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + ReStoreCallbackTest(DATABASE_BACKUP_NAME) + } + }) + } + }) + done(); + console.info(TAG + "************* RdbBackupRestoreCallbackTest_1300 end *************") + }) + console.info(TAG + "*************Unit Test End*************") + }) +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreBackupRestoreWithFAContextJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreBackupRestoreWithFAContextJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..9a6ff85dbbe4986b45a26bda8309826b02347ef1 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreBackupRestoreWithFAContextJsunit.test.js @@ -0,0 +1,419 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore' +import ability_featureAbility from '@ohos.ability.featureAbility' +import fileio from '@ohos.fileio' + +const TAG = "[RelationalStore_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 DATABASE_DIR = "/data/storage/el2/database/entry/rdb/" +var RdbStore +var context = ability_featureAbility.getContext() +const STORE_CONFIG = { + name: "BackupResotreTest.db", + securityLevel: data_Rdb.SecurityLevel.S1 +} +const DATABASE_BACKUP_NAME = "Backup.db" + +async function CreatRdbStore(context, STORE_CONFIG) { + let RdbStore = await data_Rdb.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("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 28, + "salary": 100.5, + "blobType": u8, + } + await RdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "wangwu", + "age": 38, + "salary": 90.0, + "blobType": u8, + } + await RdbStore.insert("test", valueBucket) + } + return RdbStore +} + +async function BackupTest(backupName) { + try { + let promiseRestore = RdbStore.backup(backupName) + promiseRestore.then(() => { + expect(false).assertTrue() + }).catch((err) => { + console.info(TAG + "Backup error: " + err) + expect(true).assertTrue() + }) + await promiseRestore + } catch(errInfo){ + console.info(TAG + "BackupTest error: " + errInfo) + expect(true).assertTrue() + } + + RdbStore = null +} + +async function ReStoreTest(restoreName) { + try { + let promiseRestore = RdbStore.restore(restoreName) + promiseRestore.then(() => { + expect(false).assertTrue() + }).catch((err) => { + console.info(TAG + "Restore error: " + err) + expect(true).assertTrue() + }) + await promiseRestore + } catch(errInfo) { + console.info(TAG + "ReStoreTest error: " + errInfo) + expect(true).assertTrue() + } + + RdbStore = null +} + +export default function relationalStoreBackupRestorePromiseTest() { +describe('relationalStoreBackupRestorePromiseTest', 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') + await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name) + await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME) + await data_Rdb.deleteRdbStore(context, "BackupTest003.db") + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************") + + /** + * @tc.name RelationalStore Backup Restore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0010 + * @tc.desc RelationalStore backup and restore function test + */ + it('RdbBackupRestoreTest_0010', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0010 start *************") + + // RelationalStore backup function test + RdbStore.backup(DATABASE_BACKUP_NAME).then(async() => { + try { + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) + } catch (err) { + console.info("RdbBackupRestoreTest_0010 backup success") + expect(false).assertTrue() + } + // RelationalStore before restored, delete data + let deleteData = new data_Rdb.RdbPredicates("test") + deleteData.equalTo("name", "zhangsan") + await RdbStore.delete(deleteData) + + // RelationalStore restore function test + RdbStore.restore(DATABASE_BACKUP_NAME).then(async () => { + try { + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + expect(false).assertTrue() + } catch (err) { + console.info("RdbBackupRestoreTest_0010 restore success") + expect(true).assertTrue() + } + + try { + fileio.accessSync(DATABASE_DIR + STORE_CONFIG.name) + } catch (err) { + console.info("RdbBackupRestoreTest_0010 restore success2") + expect(false).assertTrue() + } + // RelationalStore after restored, data query test + let predicates = new data_Rdb.RdbPredicates("test") + predicates.equalTo("name", "zhangsan") + RdbStore.query(predicates).then((resultSet)=>{ + try { + console.info(TAG + "After restore resultSet query done") + resultSet.goToFirstRow(); + expect(true).assertEqual(resultSet.goToFirstRow()) + console.info("RdbBackupRestoreTest_0010 goto first row success") + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + console.info("RdbBackupRestoreTest_0010 get dolumnindex id success") + const name = resultSet.getString(resultSet.getColumnIndex("name")) + console.info("RdbBackupRestoreTest_0010 get dolumnindex name success") + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(`RdbBackupRestoreTest_0010 id is ${id},name id ${name},blobType is ${blobType[0]}`) + expect(1).assertEqual(id) + expect("zhangsan").assertEqual(name) + expect(1).assertEqual(blobType[0]) + } catch (err) { + console.info(TAG + 'RdbBackupRestoreTest_0010 accessSync err4: ' + err) + expect(false).assertTrue() + } + resultSet = null + RdbStore = null + + done() + console.info(TAG + "************* RdbBackupRestoreTest_0010 end *************") + }) + + }).catch((err) => { + console.info("RdbBackupRestoreTest_0010 restore error: " + err) + expect(false).assertTrue() + }) + }).catch((err) => { + expect(false).assertTrue() + }) + + + }) + + /** + * @tc.name RelationalStore Backup test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0020 + * @tc.desc RelationalStore backup function test + */ + it('RdbBackupRestoreTest_0020', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0020 start *************") + // RelationalStore backup function test, backup file name empty + BackupTest("") + + // RelationalStore backup function test, backup file name already exists + BackupTest(STORE_CONFIG.name) + + done() + console.info(TAG + "************* RdbBackupRestoreTest_0020 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0030 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0030', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0030 start *************") + let backupName = "BackupTest003.db" + await RdbStore.backup(backupName) + + // RelationalStore restore function test, backup file name empty + ReStoreTest("") + + // RelationalStore restore function test, backup file is specified to database name + ReStoreTest(STORE_CONFIG.name) + + done() + console.info(TAG + "************* RdbBackupRestoreTest_0030 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0040 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0040', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0040 start *************") + let dbName = "notExistName.db" + + // RelationalStore restore function test, backup file does not exists + try { + fileio.accessSync(DATABASE_DIR + dbName) + expect(false).assertTrue() + } catch { + ReStoreTest(dbName) + } + + done() + console.info(TAG + "************* RdbBackupRestoreTest_0040 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0050 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0050', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0050 start *************") + + // RelationalStore restore function test, backup file + await RdbStore.backup(DATABASE_BACKUP_NAME).then(() => { + try{ + console.info(TAG + 'Backup database success') + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + expect(false).assertTrue(); + } + }).then(() => { + data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME).then(() => { + try{ + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + console.info(TAG + 'error2 ' + err) + expect(true).assertTrue(); + } + }) + }).then(() => { + RdbStore.backup(DATABASE_BACKUP_NAME).then(() => { + try{ + console.info(TAG + 'Backup database success') + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + console.info(TAG + 'error3 ' + err) + expect(false).assertTrue() + } + }) + }) + done() + console.info(TAG + "************* RdbBackupRestoreTest_0050 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0060 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0060', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0060 start *************") + // Backup file is specified to database name + RdbStore.backup(STORE_CONFIG.name).then(() => { + console.info(TAG + 'Backup database finish'); + expect(false).assertTrue() ; + }).catch((err) => { + console.info(TAG + "Backup database error"); + expect(true).assertTrue() ; + done(); + }) + }) + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0070 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0070', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0070 start *************") + await RdbStore.backup(DATABASE_BACKUP_NAME) + await data_Rdb.deleteRdbStore(context, DATABASE_BACKUP_NAME) + try{ + fileio.accessSync(DATABASE_DIR + DATABASE_BACKUP_NAME) + }catch(err){ + expect(true).assertTrue(); + } + await RdbStore.restore(DATABASE_BACKUP_NAME).catch((err) => { + console.info(TAG + 'Restore fail: ' + err) + expect(true).assertTrue(); + }) + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0070 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0080 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0080', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0080 start *************") + BackupTest() + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0080 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0090 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0090', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0090 start *************") + BackupTest([DATABASE_BACKUP_NAME]) + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0090 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0100 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0100', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0100 start *************") + await RdbStore.backup(DATABASE_BACKUP_NAME) + ReStoreTest([DATABASE_BACKUP_NAME]) + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0100 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0110 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0110', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0110 start *************") + await RdbStore.backup(DATABASE_BACKUP_NAME) + ReStoreTest() + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0110 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0120 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0120', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0120 start *************") + await RdbStore.backup(DATABASE_BACKUP_NAME) + BackupTest(DATABASE_BACKUP_NAME) + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0120 end *************") + }) + + /** + * @tc.name RelationalStore BackupRestore test + * @tc.number SUB_DDM_RelationalStore_JS_RdbBackupRestoreTest_0130 + * @tc.desc RelationalStore restore function test + */ + it('RdbBackupRestoreTest_0130', 0, async function (done) { + console.info(TAG + "************* RdbBackupRestoreTest_0130 start *************") + await RdbStore.backup(DATABASE_BACKUP_NAME) + await RdbStore.restore(DATABASE_BACKUP_NAME) + ReStoreTest(DATABASE_BACKUP_NAME) + done(); + console.info(TAG + "************* RdbBackupRestoreTest_0130 end *************") + }) + console.info(TAG + "*************Unit Test End*************") + }) +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreDeleteJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreDeleteJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..a07a4e51d9a2d8081d12599628e419211bcf585b --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreDeleteJsunit.test.js @@ -0,0 +1,362 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility' + +const TAG = '[RelationalStore_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: 'Delete.db', + securityLevel: data_Rdb.SecurityLevel.S1 +} +let rdbStore = undefined; +var context = ability_featureAbility.getContext() + +export default function relationalStoreDeleteTest() { +describe('relationalStoreDeleteTest', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await rdbStore.executeSql('DELETE FROM test'); + rdbStore = null + await data_Rdb.deleteRdbStore(context, 'Delete.db'); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + '*************Unit Test Begin*************'); + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0010 + * @tc.desc RelationalStore delete test + */ + it('testRdbStoreDelete0001', 0, async function (done) { + console.info(TAG + '************* testRdbStoreDelete0001 start *************'); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + 'name': 'zhangsan', + 'age': 18, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 28, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 38, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + //删除 + { + let predicates = new data_Rdb.RdbPredicates('test') + rdbStore.delete(predicates).then(async (ret) => { + expect(3).assertEqual(ret) + console.info(TAG + 'Delete done: ' + ret) + done() + console.info(TAG + '************* testRdbStoreDelete0001 end *************'); + }).catch((err) => { + expect(null).assertFail() + }) + } + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0020 + * @tc.desc RelationalStore delete test + */ + it('testRdbStoreDelete0002', 0, async function (done) { + console.info(TAG + '************* testRdbStoreDelete0002 start *************'); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + 'name': 'zhangsan', + 'age': 18, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 28, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 38, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + //删除 + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'zhangsan') + rdbStore.delete(predicates).then(async (ret) => { + expect(1).assertEqual(ret) + console.info(TAG + 'Delete done: ' + ret) + done() + console.info(TAG + '************* testRdbStoreDelete0002 end *************'); + }).catch((err) => { + expect(null).assertFail() + }) + } + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0030 + * @tc.desc RelationalStore delete test + */ + it('testRdbStoreDelete0003', 0, async function (done) { + console.info(TAG + '************* testRdbStoreDelete0003 start *************'); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + 'name': 'zhangsan', + 'age': 18, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 28, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + //删除前查询 + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('age', 28) + let resultSet = await rdbStore.query(predicates) + expect(1).assertEqual(resultSet.rowCount) + } + //删除 + + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('age', 28) + rdbStore.delete(predicates).then(async (ret) => { + expect(1).assertEqual(ret) + console.info(TAG + 'Delete done: ' + ret) + //删除后查询 + + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('age', 28) + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + + done() + console.info(TAG + '************* testRdbStoreDelete0003 end *************'); + }).catch((err) => { + expect(null).assertFail() + }) + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0040 + * @tc.desc RelationalStore delete test + */ + it('testRdbStoreDelete0004', 0, async function (done) { + console.info(TAG + '************* testRdbStoreDelete0004 start *************'); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + 'name': 'zhangsan', + 'age': 18, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 28, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 38, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + //删除 + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('aaa id', 1) + rdbStore.delete(predicates).then(async (ret) => { + console.info(TAG + 'delete done: ' + ret) + expect(null).assertFail() + }).catch((err) => { + console.info(TAG + 'delete with wrong conditions') + done(); + console.info(TAG + '************* testRdbStoreDelete0004 end *************'); + }) + } + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0050 + * @tc.desc RelationalStore delete test + */ + it('testRdbStoreDelete0005', 0, async function (done) { + console.info(TAG + '************* testRdbStoreDelete0005 start *************'); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + 'name': 'zhangsan', + 'age': 18, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 28, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 38, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + //删除 + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'lisi') + rdbStore.delete(predicates).then(async (ret) => { + expect(2).assertEqual(ret) + console.info(TAG + 'Delete done: ' + ret) + + done() + console.info(TAG + '************* testRdbStoreDelete0005 end *************'); + }).catch((err) => { + expect(null).assertFail() + }) + } + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Delete_0060 + * @tc.desc RelationalStore delete test + */ + it('testRdbStoreDelete0006', 0, async function (done) { + console.info(TAG + '************* testRdbStoreDelete0006 start *************'); + let errInfo = undefined; + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + 'name': 'zhangsan', + 'age': 18, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 28, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + { + const valueBucket = { + 'name': 'lisi', + 'age': 38, + 'salary': 100.5, + 'blobType': u8, + } + await rdbStore.insert('test', valueBucket) + } + //删除 + try{ + let predicates = await new data_Rdb.RdbPredicates('') + rdbStore.delete(predicates).then(async (ret) => { + console.info(TAG + 'delete done: ' + ret) + expect(null).assertFail() + }).catch((err) => { + console.info(TAG + 'delete with null') + }) + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + '************* testRdbStoreDelete0006 end *************'); + }) + + console.info(TAG + '*************Unit Test End*************'); +})} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreDistributedJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreDistributedJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..e8dd3a7d33564f5868a746450fcbddd0eaeaf8c7 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreDistributedJsunit.test.js @@ -0,0 +1,415 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +var context = ability_featureAbility.getContext(); +var sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + +"id INTEGER PRIMARY KEY AUTOINCREMENT," + +"name TEXT NOT NULL," +"age INTEGER)" +sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + +"id INTEGER PRIMARY KEY AUTOINCREMENT," + +"name TEXT NOT NULL," +"price REAL," + +"vendor INTEGER," +"describe TEXT)" +const TAG = "[RelationalStore_JSKITS_TEST_Distributed]" +const STORE_NAME = "distributed_rdb.db" +var rdbStore = undefined; +const config = { + "name": STORE_NAME, + securityLevel: data_Rdb.SecurityLevel.S1 +} + +async function executeSql1() { + let sqlStatement = "CREATE TABLE IF NOT EXISTS employee (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "name TEXT NOT NULL," + + "age INTEGER)" +try { + await rdbStore.executeSql(sqlStatement, null) + console.info(TAG + "create table employee success") +} catch (err) { + console.info(TAG + "create table employee failed") + expect(null).assertFail() +} +} + +async function executeSql2() { + let sqlStatement = "CREATE TABLE IF NOT EXISTS product (" + + "id INTEGER PRIMARY KEY AUTOINCREMENT," + + "name TEXT NOT NULL," + + "price REAL," + + "vendor INTEGER," + + "describe TEXT)" +try { + await rdbStore.executeSql(sqlStatement, null) + console.info(TAG + "create table product success") +} catch (err) { + console.info(TAG + "create table product failed") + expect(null).assertFail() +} +} + +export default function relationalStoreDistributedTest() { +describe('relationalStoreDistributedTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await data_Rdb.getRdbStore(context, config); + console.info(TAG + "create RelationalStore store success") + await executeSql1() + await executeSql2() + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + await data_Rdb.deleteRdbStore(context, STORE_NAME); + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name set_distributed_table_none_table + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_002 + * @tc.desc RelationalStore set distributed table using none table as argment + */ + it('testRdbStoreDistributed0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed002 start *************"); + try { + await rdbStore.setDistributedTables([]) + console.info(TAG + "set none to be distributed table success"); + expect(rdbStore).assertEqual(rdbStore) + } catch (err) { + console.info(TAG + "set none to be distributed table failed"); + expect(null).assertFail(); + } + done() + console.info(TAG + "************* testRdbStoreDistributed002 end *************"); + }) + + /** + * @tc.name set distributed table using one table name + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_003 + * @tc.desc set distributed table using one table name + */ + it('testRdbStoreDistributed0003', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed003 start *************"); + try { + await rdbStore.setDistributedTables(['employee']) + console.info(TAG + "set employee to be distributed table success"); + expect(rdbStore).assertEqual(rdbStore) + } catch (err) { + console.info(TAG + "set employee to be distributed table failed"); + expect(null).assertFail(); + } + done() + console.info(TAG + "************* testRdbStoreDistributed003 end *************"); + }) + + /** + * @tc.name set distributed table using two table name + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_004 + * @tc.desc set distributed table using two table name + */ + it('testRdbStoreDistributed0004', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed004 start *************"); + try { + await rdbStore.setDistributedTables(['employee', 'product']) + console.info(TAG + "set employee and product to be distributed table success"); + expect(rdbStore).assertEqual(rdbStore) + } catch (err) { + console.info(TAG + "set employee and product to be distributed table failed"); + expect(null).assertFail(); + } + done() + console.info(TAG + "************* testRdbStoreDistributed004 end *************"); + }) + + /** + * @tc.name insert record after setting distributed table + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_005 + * @tc.desc insert record after setting distributed table + */ + it('testRdbStoreDistributed0005', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed005 start *************"); + const record = { + "name": "Jim", + "age": 20, + } + try { + let rowId = await rdbStore.insert("employee", record) + console.info(TAG + "insert one record success " + rowId) + expect(1).assertEqual(rowId) + } catch (err) { + console.info(TAG + "insert one record failed" + err); + expect(null).assertFail(); + } + done() + console.info(TAG + "************* testRdbStoreDistributed005 end *************"); + }) + + /** + * @tc.name update record after setting distributed table + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_006 + * @tc.desc update record after setting distributed table + */ + it('testRdbStoreDistributed0006', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed006 start *************"); + const record = { + "name": "Jim", + "age": 30, + } + try { + let predicate = new data_Rdb.RdbPredicates("employee"); + predicate.equalTo("id", 1); + try { + let rowId = await rdbStore.update(record, predicate); + console.info(TAG + "update one record success " + rowId) + expect(1).assertEqual(rowId) + } catch (err) { + console.info(TAG + "update one record failed" + err); + expect(null).assertFail(); + } + } catch (err) { + console.info(TAG + "construct predicate failed"); + expect(null).assertFail(); + } + done() + console.info(TAG + "************* testRdbStoreDistributed006 end *************"); + }) + + /** + * @tc.name query record after setting distributed table + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_007 + * @tc.desc query record after setting distributed table + */ + it('testRdbStoreDistributed0007', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0007 start *************"); + try { + let predicates = new data_Rdb.RdbPredicates("employee") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "product resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + + await expect(1).assertEqual(id); + await expect("Jim").assertEqual(name); + await expect(30).assertEqual(age); + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed) + } catch (e) { + console.info(TAG + "result get value failed") + expect(null).assertFail(); + } + } catch (err) { + console.info("query failed"); + expect(null).assertFail(); + } + done(); + console.info(TAG + "************* testRdbStoreDistributed0007 end *************"); + }) + + /** + * @tc.name delete record after setting distributed table + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_008 + * @tc.desc delete record after setting distributed table + */ + it('testRdbStoreDistributed0008', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0008 start *************"); + let predicates = new data_Rdb.RdbPredicates("employee") + try { + let number = await rdbStore.delete(predicates) + console.info(TAG + "employee Delete done: " + number) + expect(1).assertEqual(number) + } catch (err) { + console.info(TAG + "delete record failed"); + expect(null).assertFail() + } + done(); + console.info(TAG + "************* testRdbStoreDistributed0008 end *************"); + }) + + /** + * @tc.name predicates inDevice + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_009 + * @tc.desc predicates inDevice + */ + it('testRdbStoreDistributed0009', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0009 start *************"); + let predicates = new data_Rdb.RdbPredicates("employee") + try { + predicates = predicates.inDevices("1234567890"); + console.info(TAG + "inDevices success"); + expect(predicates).assertEqual(predicates); + } catch (err) { + console.info(TAG + "inDevices failed"); + expect(null).assertFail(); + } + done(); + console.info(TAG + "************* testRdbStoreDistributed0009 end *************"); + }) + + /** + * @tc.name predicates inAllDevices + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_010 + * @tc.desc predicates inAllDevices + */ + it('testRdbStoreDistributed0010', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0010 start *************"); + let predicates = new data_Rdb.RdbPredicates("employee") + try { + predicates = predicates.inAllDevices(); + console.info(TAG + "inAllDevices success"); + expect(predicates).assertEqual(predicates); + } catch (err) { + console.info(TAG + "inAllDevices failed"); + expect(null).assertFail(); + } + done(); + console.info(TAG + "************* testRdbStoreDistributed0010 end *************"); + }) + + /** + * @tc.name sync test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_011 + * @tc.desc sync test + */ + it('testRdbStoreDistributed0011', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0011 start *************"); + let predicates = new data_Rdb.RdbPredicates("employee") + predicates = predicates.inDevices("12345678abcd"); + rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates); + console.info(TAG + "sync push success"); + expect(rdbStore).assertEqual(rdbStore); + rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates); + console.info(TAG + "sync pull success"); + expect(rdbStore).assertEqual(rdbStore); + done(); + console.info(TAG + "************* testRdbStoreDistributed0011 end *************"); + }) + + /** + * @tc.name sync Callback test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_Callback_011 + * @tc.desc sync Callback test + */ + it('testRdbStoreDistributedCallback0011', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributedCallback0011 start *************"); + function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + let predicates = new data_Rdb.RdbPredicates("employee") + predicates = predicates.inDevices("12345678abcd"); + rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PUSH, predicates,(err,ret)=>{ + console.info(TAG + "sync push success"); + expect(rdbStore).assertEqual(rdbStore); + rdbStore.sync(data_Rdb.SyncMode.SYNC_MODE_PULL, predicates,(err,ret)=>{ + console.info(TAG + "sync push success"); + expect(rdbStore).assertEqual(rdbStore); + }); + done(); + }); + await sleep(2000) + done(); + console.info(TAG + "************* testRdbStoreDistributedCallback0011 end *************"); + }) + + /** + * @tc.name subscribe test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_012 + * @tc.desc subscribe test + */ + it('testRdbStoreDistributed0012', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0012 start *************"); + rdbStore.on("dataChange", (device) => { + console.info(TAG + device + " dataChange"); + }); + console.info(TAG + "on dataChange success"); + expect(rdbStore).assertEqual(rdbStore); + done() + console.info(TAG + "************* testRdbStoreDistributed0012 end *************"); + }) + + /** + * @tc.name subscribe test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_013 + * @tc.desc subscribe test + */ + it('testRdbStoreDistributed0013', 0, async function (done) { + console.info(TAG + "************* testRdbStoreDistributed0013 start *************"); + rdbStore.off("dataChange", (device) => { + console.info(TAG + device + " dataChange"); + }); + console.info(TAG + "off dataChange success"); + expect(rdbStore).assertEqual(rdbStore); + done() + console.info(TAG + "************* testRdbStoreDistributed0013 end *************"); + }) + + /** + * @tc.name obtainDistributedTableName Callback interface test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_014 + * @tc.desc obtainDistributedTableName test + */ + it('testRdbStoreDistributed0014', 0, async function (done){ + let errInfo = undefined; + try{ + rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE", function (err, tableName) { + expect(err != null).assertTrue(); + console.info('ObtainDistributedTableName failed, Unauthorized.' + err) + }) + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done(); + }) + + /** + * @tc.name obtainDistributedTableName Promise interface test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Distributed_015 + * @tc.desc obtainDistributedTableName test + */ + it('testRdbStoreDistributed0015',0,async function (done){ + await data_Rdb.deleteRdbStore(context, STORE_NAME); + const config = { + "name": STORE_NAME, + securityLevel: data_Rdb.SecurityLevel.S1 + } + rdbStore = await data_Rdb.getRdbStore(context, config); + let errInfo = undefined + try{ + rdbStore.obtainDistributedTableName(["deviceId"], "EMPLOYEE") + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done(); + }) + + console.info(TAG + "*************Unit Test End*************"); +}) +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreEncryptionJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreEncryptionJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1777b0ad3fa7f99de4ef4a5368ae96c0b11b8281 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreEncryptionJsunit.test.js @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_rdb from '@ohos.data.relationalStore' +import ability_featureAbility from '@ohos.ability.featureAbility' + + +const TAG = "[RelationalStore_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)" + +var rdbStore +var context = ability_featureAbility.getContext(); +const STORE_CONFIG_ENCRYPT = { + name: "Encrypt.db", + encrypt: true, + securityLevel: data_rdb.SecurityLevel.S1 +} +const STORE_CONFIG_UNENCRYPT = { + name: "Unencrypt.db", + encrypt: false, + securityLevel: data_rdb.SecurityLevel.S1 +} +const STORE_CONFIG_WRONG = { + name: "Encrypt.db", + encrypt: false, + securityLevel: data_rdb.SecurityLevel.S1 +} + +export default function relationalStoreEncryptTest() { +async function CreatRdbStore(context, STORE_CONFIG) { + let rdbStore = await data_rdb.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("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 28, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "wangwu", + "age": 38, + "salary": 90.0, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + return rdbStore +} + +describe('relationalStoreEncryptTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await data_rdb.deleteRdbStore(context, STORE_CONFIG_ENCRYPT.name) + await data_rdb.deleteRdbStore(context, STORE_CONFIG_UNENCRYPT.name) + await data_rdb.deleteRdbStore(context, STORE_CONFIG_WRONG.name) + rdbStore = null + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************") + + /** + * @tc.name RelationalStore encrypted test + * @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0010 + * @tc.desc RelationalStore create encrypt db test + */ + it('RdbEncryptTest_0010', 0, async function (done) { + console.info(TAG + "************* RdbEncryptTest_0010 start *************") + context = ability_featureAbility.getContext() + data_rdb.getRdbStore(context, STORE_CONFIG_ENCRYPT).then((store) => { + done() + expect(store != null).assertTrue(); + }).catch((err) => { + expect(null).assertFail(); + }) + console.info(TAG + "************* RdbEncryptTest_0010 end *************") + }) + + /** + * @tc.name RelationalStore unencrypted test + * @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0020 + * @tc.desc RelationalStore create unencrypted db test + */ + it('RdbEncryptTest_0020', 0, async function (done) { + console.info(TAG + "************* RdbEncryptTest_0020 start *************") + context = ability_featureAbility.getContext() + let storePromise = data_rdb.getRdbStore(context, STORE_CONFIG_UNENCRYPT); + storePromise.then((store) => { + expect(store != null).assertTrue(); + done() + }).catch((err) => { + expect(null).assertFail(); + }) + + console.info(TAG + "************* RdbEncryptTest_0020 end *************") + }) + + + /** + * @tc.name RelationalStore Encrypt test + * @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0030 + * @tc.desc RelationalStore Encrypt function test + */ + it('RdbEncryptTest_0030', 0, async function (done) { + console.info(TAG + "************* RdbEncryptTest_0030 start *************") + context = ability_featureAbility.getContext() + rdbStore = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT) + let predicates = new data_rdb.RdbPredicates("test") + 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]) + } catch (err) { + expect(false).assertTrue() + } + resultSet = null + rdbStore = null + done() + console.info(TAG + "************* RdbEncryptTest_0030 end *************") + }) + + /** + * @tc.name RelationalStore Encrypt test + * @tc.number SUB_DDM_RelationalStore_JS_RdbEncryptTest_0040 + * @tc.desc RelationalStore Encrypt function test + */ + it('RdbEncryptTest_0040', 0, async function (done) { + console.info(TAG + "************* RdbEncryptTest_0040 start *************") + context = ability_featureAbility.getContext() + rdbStore = await CreatRdbStore(context, STORE_CONFIG_ENCRYPT) + rdbStore = null + rdbStore = await CreatRdbStore(context, STORE_CONFIG_WRONG) + expect(rdbStore).assertNull + + done() + console.info(TAG + "************* RdbEncryptTest_0040 end *************") + }) + console.info(TAG + "*************Unit Test End*************") + } +) + +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreExcuteSqlJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreExcuteSqlJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..bde31f6589330df7be1055e42a712ee2f73c1ff5 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreExcuteSqlJsunit.test.js @@ -0,0 +1,370 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility'; +var context = ability_featureAbility.getContext(); + +const TAG = "[RelationalStore_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: data_Rdb.SecurityLevel.S1 +} +var rdbStore = undefined; + +export default function relationalStoreExcuteSqlTest() { + describe('relationalStoreExcuteSqlTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + beforeEach(async function () { + await rdbStore.executeSql("DELETE FROM test"); + console.info(TAG + 'beforeEach') + }) + + afterEach(function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await data_Rdb.deleteRdbStore(context, "ExcuteSqlTest.db"); + }) + + /** + * @tc.name resultSet ExcuteSql normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0010 + * @tc.desc resultSet ExcuteSql normal test + */ + it('ExcuteSqlTest0001', 0, async function (done) { + console.info(TAG + "************* ExcuteSqlTest0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + //插入 + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + { + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(2).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + { + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(3).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + //sql删除 + let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE age = ? OR age = ?", ["18", "20"]) + executeSqlPromise.then(async (resultSet) => { + await console.info(TAG + "executeSql done: " + resultSet); + }).catch((err) => { + expect(null).assertFail(); + }) + await executeSqlPromise + + + let querySqlPromise = rdbStore.querySql("SELECT * FROM test") + querySqlPromise.then(async (resultSet) => { + await expect(0).assertEqual(resultSet.rowCount) + }).catch((err) => { + expect(null).assertFail(); + }) + await querySqlPromise + + done(); + console.info(TAG + "************* ExcuteSqlTest0001 end *************"); + }) + + /** + * @tc.name resultSet ExcuteSql normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0020 + * @tc.desc resultSet ExcuteSql normal test + */ + it('ExcuteSqlTest0002', 0, async function (done) { + console.info(TAG + "************* ExcuteSqlTest0002 start *************"); + var u8 = new Uint8Array([2, 3, 4]) + //插入 + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(4).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + { + const valueBucket = { + "name": "lisi", + "age": 19, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(5).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + { + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(6).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE name = 'lisi'") + executeSqlPromise.then(async () => { + await console.info(TAG + "executeSql done"); + }).catch((err) => { + expect(null).assertFail(); + }) + await executeSqlPromise + + let querySqlPromise = rdbStore.querySql("SELECT * FROM test") + querySqlPromise.then(async (resultSet) => { + await expect(1).assertEqual(resultSet.rowCount) + }).catch((err) => { + expect(null).assertFail(); + }) + await querySqlPromise + + done(); + console.info(TAG + "************* ExcuteSqlTest0002 end *************"); + }) + + /** + * @tc.name resultSet ExcuteSql normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0030 + * @tc.desc resultSet ExcuteSql normal test + */ + it('ExcuteSqlTest0003', 0, async function (done) { + console.info(TAG + "************* ExcuteSqlTest0003 start *************"); + var u8 = new Uint8Array([3, 4, 5]) + var nameStr = "lisi" + "e".repeat(2000) + "zhangsan" + //插入 + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(7).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + { + const valueBucket = { + "name": nameStr, + "age": 19, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(8).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + { + const valueBucket = { + "name": nameStr, + "age": 28, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(9).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + let predicates = await new data_Rdb.RdbPredicates("test") + predicates.equalTo("name", nameStr) + let querySqlPromise = rdbStore.query(predicates) + querySqlPromise.then(async (resultSet) => { + await expect(2).assertEqual(resultSet.rowCount) + }).catch((err) => { + expect(null).assertFail(); + }) + await querySqlPromise + + let executeSqlPromise = rdbStore.executeSql("DELETE FROM test WHERE age = 19 AND name ='" + nameStr + "'") + executeSqlPromise.then(async () => { + await console.info(TAG + "executeSql done." ); + }).catch((err) => { + expect(null).assertFail(); + }) + await executeSqlPromise + { + let querySqlPromise = rdbStore.querySql("SELECT * FROM test WHERE name ='" + nameStr + "'") + querySqlPromise.then(async (resultSet) => { + await expect(1).assertEqual(resultSet.rowCount) + expect(true).assertEqual(resultSet.goToFirstRow()) + 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")) + expect(nameStr).assertEqual(name) + expect(2012).assertEqual(name.length) + expect(28).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(3).assertEqual(blobType[0]) + }).catch((err) => { + expect(null).assertFail(); + }) + await querySqlPromise + } + done(); + console.info(TAG + "************* ExcuteSqlTest0003 end *************"); + }) + + /** + * @tc.name resultSet ExcuteSql normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ExcuteSql_0040 + * @tc.desc resultSet ExcuteSql normal test + */ + it('ExcuteSqlTest0004', 0, async function (done) { + console.info(TAG + "************* ExcuteSqlTest0004 start *************"); + var u8 = new Uint8Array([3, 4, 5]) + //插入 + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(10).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + { + const valueBucket = { + "name": "lisi", + "age": 19, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(11).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + { + const valueBucket = { + "name": "lisi", + "age": 28, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(12).assertEqual(ret); + await console.info(TAG + "insert done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + let QuerySqlPromise = rdbStore.executeSql("DROP TABLE IF EXISTS test") + QuerySqlPromise.then(async (resultSet) => { + await console.info(TAG + "executeSql done: " + resultSet); + }).catch((err) => { + expect(null).assertFail(); + }) + await QuerySqlPromise + + done(); + console.info(TAG + "************* ExcuteSqlTest0004 end *************"); + }) + + + console.info(TAG + "*************Unit Test End*************"); + }) +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..131e02dae0a7bf5c9c61a86316634e787f082bd4 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js @@ -0,0 +1,1093 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility' +var context = ability_featureAbility.getContext(); + +const TAG = "[RelationalStore_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 CREATE_TABLE_NAME = "CREATE TABLE IF NOT EXISTS test" +const CREATE_TABLE = " (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; +const STORE_CONFIG = { + name: "InsertTest.db", + securityLevel: data_Rdb.SecurityLevel.S1 +} + +var rdbStore = undefined; +var resultSet = undefined; + +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} +export default function relationalStoreInsertTest() { +describe('relationalStoreInsertTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null) + await rdbStore.executeSql(CREATE_TABLE_BATCHINSERT_TEST, null); + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + await rdbStore.executeSql("DELETE FROM test"); + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await data_Rdb.deleteRdbStore(context, "InsertTest.db").then(() => { + sleep(2) + }); + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0010 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + 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]) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("insert1 error " + e); + } + resultSet = null + done() + console.info(TAG + "************* testRdbStoreInsert0001 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0020 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("wrong", valueBucket) + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret) + console.info(TAG + "insert first done: " + ret) + expect(null).assertFail() + }).catch((err) => { + console.info(TAG + "insert with wrong table") + }) + } + done() + console.info(TAG + "************* testRdbStoreInsert0002 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0030 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0003', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0003 start *************"); + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + try{ + rdbStore.insert(null, valueBucket) + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + } + done() + console.info(TAG + "************* testRdbStoreInsert0003 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0040 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0004', 0, async function (done) { + console.log(TAG + "************* testRdbStoreInsert0004 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": null, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret) + console.log(TAG + "insert first done: " + ret) + }).catch((err) => { + console.log(TAG + "insert with null table") + expect(null).assertFail() + }) + done(); + console.log(TAG + "************* testRdbStoreInsert0004 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0010 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0001', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0001 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "1" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test1", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) =>{ + expect(false).assertTrue(); + }) + + let predicates = new data_Rdb.RdbPredicates("test1"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + 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]) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + predicates = new data_Rdb.RdbPredicates("test1"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + 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(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet = null + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0020 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0002', 0, async function (done) { + await rdbStore.executeSql(CREATE_TABLE_NAME + "2" + CREATE_TABLE) + console.info(TAG + "************* testRdbStorebatchInsertPromise0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test2", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) =>{ + expect(false).assertTrue(); + }) + let predicates = new data_Rdb.RdbPredicates("test2"); + predicates.equalTo("name", "lisi") + let resultSet = await rdbStore.query(predicates) + try { + 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(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + await rdbStore.delete(predicates).then((number) => { + expect(1).assertEqual(number) + }).then(async () => { + resultSet = await rdbStore.query(predicates).catch((err) =>{ + expect(err != null).assertTrue(); + }) + }) + } catch (e) { + console.info("BatchInsert2 error " + e); + } + resultSet = null + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0030 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0003', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0003 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "3" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test3", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) =>{ + expect(false).assertTrue(); + }) + + let predicates = new data_Rdb.RdbPredicates("test3"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + 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]) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + predicates = new data_Rdb.RdbPredicates("test3"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + 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(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + const valueBucket4 = { + "name": "zhangmaowen", + "age": 25, + "salary": 500, + "blobType": u8, + } + await rdbStore.insert("test3",valueBucket4) + predicates = new data_Rdb.RdbPredicates("test3"); + predicates.equalTo("name", "zhangmaowen") + resultSet = await rdbStore.query(predicates) + try { + 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 + ", blobType=" + blobType); + expect(4).assertEqual(id); + expect("zhangmaowen").assertEqual(name) + expect(25).assertEqual(age) + expect(500).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet = null + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0003 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0040 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0004', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0004 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + var valueBuckets = new Array(100); + for(var i=0;i { + console.info(TAG + "Batch insert data end") + expect(100).assertEqual(number) + }).catch((err) =>{ + expect(false).assertTrue(); + }) + + let predicates = new data_Rdb.RdbPredicates("test4"); + predicates.equalTo("name", "zhangsan55") + let resultSet = await rdbStore.query(predicates) + try { + 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(56).assertEqual(id); + expect("zhangsan55").assertEqual(name) + expect(55).assertEqual(age) + expect(56).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet = null; + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0004 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0050 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0005', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0005 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "5" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket3 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test5", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) =>{ + expect(false).assertTrue(); + }) + + let predicates = new data_Rdb.RdbPredicates("test5"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + 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 + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + 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]) + expect(true).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet = null; + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0005 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0060 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0006', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0006 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "6" + CREATE_TABLE) + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + try{ + await rdbStore.batchInsert("test6","valueBuckets") + }catch(err){ + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0006 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0070 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0007', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************"); + let errInfo = undefined; + await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE) + try{ + await rdbStore.batchInsert("test7") + }catch(err){ + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0007 end *************"); + }) + + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0100 + * @tc.desc RelationalStore insert test + * zheg s + */ + it('testRdbStorebatchInsertCallback0001', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => { + console.info(TAG + "Batch insert data start") + await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => { + if(err != null){ + expect(false).assertTrue(); + }else{ + console.info(TAG + "Batch insert data end") + expect(3).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testcallback1"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + 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]) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + predicates = new data_Rdb.RdbPredicates("testcallback1"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + 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(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } + done(); + }) + resultSet = null + }) + await sleep(2000) + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0001 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0200 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0002', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => { + if(err != null){ + expect(false).assertTrue(); + }else{ + expect(3).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testCallback2"); + predicates.equalTo("name", "lisi") + let resultSet = await rdbStore.query(predicates) + try { + 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(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + await rdbStore.delete(predicates).then((number) => { + expect(1).assertEqual(number) + }).then(async () => { + resultSet = await rdbStore.query(predicates).catch((err) =>{ + expect(err != null).assertTrue(); + }) + }) + } catch (e) { + console.info("BatchInsert2 error " + e); + } + } + done(); + }) + }) + await sleep(2000) + resultSet = null + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0002 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0300 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0003', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () =>{ + await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => { + if(err != null){ + expect(false).assertTrue() + }else{ + expect(3).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + 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(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + predicates = new data_Rdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + 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) + const valueBucket4 = { + "name": "zhangmaowen", + "age": 25, + "salary": 500, + "blobType": u8, + } + await rdbStore.insert("testCallback3",valueBucket4) + predicates = new data_Rdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "zhangmaowen") + resultSet = await rdbStore.query(predicates) + try { + 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(4).assertEqual(id); + expect("zhangmaowen").assertEqual(name) + expect(25).assertEqual(age) + expect(500).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } + done(); + }) + }) + await sleep(2000) + resultSet = null + done(); + console.info(TAG + "************* testRdbStorebatchInsertCallback0003 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0400 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0004', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + var valueBuckets = new Array(100); + for(var i=0;i { + await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => { + if(err != null){ + expect(false).assertTrue(); + }else{ + console.info(TAG + "Batch insert data end") + expect(100).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testCallbak4"); + predicates.equalTo("name", "zhangsan55") + let resultSet = await rdbStore.query(predicates) + try { + 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(56).assertEqual(id); + expect("zhangsan55").assertEqual(name) + expect(55).assertEqual(age) + expect(56).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } + done(); + }) + }) + await sleep(2000) + resultSet = null; + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0004 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0500 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0005', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0005 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket3 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => { + if(err != null){ + expect(false).assertTrue(); + }else{ + expect(3).assertEqual(number) + let predicates = new data_Rdb.RdbPredicates("testCallback5"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + 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 + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + 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]) + expect(true).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } + done(); + }) + }) + await sleep(2000) + resultSet = null; + done(); + console.info(TAG + "************* testRdbStorebatchInsertCallback0005 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0600 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0006', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0006 start *************"); + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => { + try{ + rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => { + console.info(TAG + "Affect row is " + data) + if(err != null){ + expect(null).assertFail(); + }else{ + expect(data).assertEqual(-1) + } + }) + }catch(err){ + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + }) + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0006 end *************"); + }) + + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0700 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0007', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************"); + let errInfo = undefined; + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => { + try{ + await rdbStore.batchInsert("testCallback7", (err,data) => { + console.info(TAG + "Affect row is " + data) + if(err != null){ + expect(null).assertFail(); + }else{ + expect(data).assertEqual(-1) + } + }) + }catch(err){ + errInfo = err + } + }).catch((err) => { + expect(null).assertFail(); + }) + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************"); + }) + + console.info(TAG + " *************Unit Test End*************"); +}) +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..617ae34444938be175817eaa509d60654a0018bf --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreJsunit.test.js @@ -0,0 +1,252 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + + +var context = ability_featureAbility.getContext(); +var contextApplication = context.getApplicationContext(); +const TAG = "[RelationalStore_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: "rdbstore.db", + securityLevel: data_Rdb.SecurityLevel.S1 +}; +function sleep(ms) { + return new Promise(resolve => setTimeout(resolve, ms)); +} +export default function relationalStoreTest() { +describe('relationalStoreTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll'); + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach'); + }) + + afterEach(async function () { + console.info(TAG + 'afterAll'); + await data_Rdb.deleteRdbStore(context,"rdbstore.db"); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll'); + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name RelationalStore store getRdbStore test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0010 + * @tc.desc RelationalStore store getRdbStore test + */ + it('testRdbStore0001', 0, async function (done) { + console.info(TAG + "************* testRdbStore0001 start *************"); + await data_Rdb.getRdbStore(context, STORE_CONFIG).then(async (store) => { + try { + console.info(TAG + "getRdbStore done: " + store); + } catch (e) { + expect(null).assertFail(); + } + }).catch((err) => { + expect(null).assertFail(); + }) + done(); + console.info(TAG + "************* testRdbStore0001 end *************"); + }) + + /** + * @tc.name RelationalStore store getRdbStore and create table + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0020 + * @tc.desc RelationalStore store getRdbStore and create table + */ + it('testRdbStore0002', 0, async function (done) { + console.info(TAG + "************* testRdbStore0002 start *************"); + let storePromise = data_Rdb.getRdbStore(context, STORE_CONFIG); + storePromise.then(async (store) => { + try { + console.info(TAG + "getRdbStore done: " + store); + await store.executeSql(CREATE_TABLE_TEST); + } catch (e) { + expect(null).assertFail(); + } + }).catch((err) => { + expect(null).assertFail(); + }) + await storePromise; + storePromise = null; + done(); + console.info(TAG + "************* testRdbStore0002 end *************"); + }) + + /** + * @tc.name RelationalStore storegetRdbStore with wrong path + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0030 + * @tc.desc RelationalStore store getRdbStore with wrong path + */ + it('testRdbStore0003', 0, async function (done) { + console.info(TAG + "************* testRdbStore0003 start *************"); + + let storeConfig = { + name: "/wrong/rdbstore.db", + securityLevel: data_Rdb.SecurityLevel.S1 + }; + try{ + data_Rdb.getRdbStore(context, storeConfig).then(async (ret) => { + console.info(TAG + "getRdbStore done" + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "getRdbStore with wrong path"); + }) + expect(false).assertTrue(); + }catch(error){ + console.info(TAG + `catch err: failed: err: code= ${error.code}, message = ${error.message}`); + expect(error.code).assertEqual("401"); + done(); + console.info(TAG + "************* testRdbStore0003 end *************"); + } + }) + + /** + * @tc.name RelationalStore store deleteRdbStore + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0040 + * @tc.desc RelationalStore store deleteRdbStore + */ + it('testRdbStore0004', 0, async function (done) { + console.info(TAG + "************* testRdbStore0004 start *************"); + try{ + let store = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await store.executeSql(CREATE_TABLE_TEST); + await data_Rdb.deleteRdbStore(context, "rdbstore.db"); + }catch (e) { + expect(null).assertFail(); + } + done(); + console.info(TAG + "************* testRdbStore0004 end *************"); + }) + + /** + * @tc.name RelationalStore store deleteRdbStore + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0050 + * @tc.desc RelationalStore store deleteRdbStore + */ + it('testRdbStore0005', 0, async function (done) { + console.info(TAG + "************* testRdbStore0005 start *************"); + try { + let store = await data_Rdb.getRdbStore(context, STORE_CONFIG); + console.info(TAG + "Get rdbstore success"); + await store.executeSql(CREATE_TABLE_TEST); + await data_Rdb.deleteRdbStore(context, "rdbstore.db"); + } catch (e) { + expect(null).assertFail(); + } + done(); + console.info(TAG + "************* testRdbStore0005 end *************"); + }) + + /** + * @tc.name RelationalStore store getRdbStore test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0060 + * @tc.desc RelationalStore store getRdbStore test + */ + it('testRdbStore0006', 0, async function (done) { + console.info(TAG + "************* testRdbStore0006 start *************"); + let rdbstore = null; + try{ + const STORE_CONFIG= { + name: "rdbstorecontext.db", + securityLevel: data_Rdb.SecurityLevel.S1 + }; + rdbstore = await data_Rdb.getRdbStore(context,STORE_CONFIG); + console.info(TAG + "Get rdbstore success"); + expect(rdbstore != null).assertTrue(); + await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name); + }catch(err){ + console.info(TAG + "Get rdbstore fail catch err: " + err); + expect(null).assertFail(); + } + rdbstore = null; + done(); + console.info(TAG + "************* testRdbStore0006 end *************"); + }) + + /** + * @tc.name RelationalStore store getRdbStore test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0070 + * @tc.desc RelationalStore store getRdbStore test + */ + it('testRdbStore0007', 0, async function (done) { + console.info(TAG + "************* testRdbStore0007 start *************"); + let rdbstore = null; + try{ + const STORE_CONFIG = { + name: "rdbstorecontext.db", + securityLevel: data_Rdb.SecurityLevel.S1 + }; + rdbstore = await data_Rdb.getRdbStore(contextApplication,STORE_CONFIG); + console.info(TAG + "Get rdbstore success"); + expect(rdbstore != null).assertTrue(); + await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name); + }catch(err){ + console.info(TAG + "Get rdbstore fail catch err: " + err); + expect(null).assertFail(); + } + rdbstore = null; + done(); + console.info(TAG + "************* testRdbStore0007 end *************"); + }) + + /** + * @tc.name RelationalStore store deleteRdbStore test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0080 + * @tc.desc RelationalStore store deleteRdbStore test + */ + it('testRdbStore0008', 0, async function (done) { + console.info(TAG + "************* testRdbStore0008 start *************"); + data_Rdb.getRdbStore(context, STORE_CONFIG, async (err,data) => { + console.info(TAG + "getRdbStore finish"); + console.info(TAG + "getRdbStore success: " + data); + expect(data != null).assertTrue(); + await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name); + done(); + console.info(TAG + "************* testRdbStore0008 end *************"); + }); + await sleep(1000); + }) + + /** + * @tc.name RelationalStore store deleteRdbStore test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RdbStore_0090 + * @tc.desc RelationalStore store deleteRdbStore test + */ + it('testRdbStore0009', 0, async function(done){ + console.info(TAG + "************* testRdbStore0009 start *************"); + data_Rdb.getRdbStore(contextApplication, STORE_CONFIG, async (err,data) => { + console.info(TAG + "getRdbStore finish"); + console.info(TAG + "getRdbStore success: " + data); + expect(data != null).assertTrue(); + await data_Rdb.deleteRdbStore(contextApplication, STORE_CONFIG.name); + done(); + console.info(TAG + "************* testRdbStore0009 end *************"); + }) + await sleep(1000); + }) + + console.info(TAG + "*************Unit Test End*************"); +})} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesComplexFiledJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesComplexFiledJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..793429ff721e24127b233a38f38220eaaf81eb85 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesComplexFiledJsunit.test.js @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility' +var context = ability_featureAbility.getContext(); + +const TAG = "[RelationalStore_JSKITS_TEST]" +const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT, " + "age INTEGER, " + "salary REAL, " + "adddate DATE)"; +const STORE_CONFIG = { + name: "PredicatesComplexFiledJsunit.db", + securityLevel: data_Rdb.SecurityLevel.S1 +} +var rdbStore = undefined; +export default function relationalStorePredicatesComplexFiledTest(){ +describe('relationalStorePredicatesComplexFiledTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await generateTable(); + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await data_Rdb.deleteRdbStore(context, "PredicatesComplexFiledJsunit.db"); + }) + + async function generateTable() { + console.info(TAG + 'generateTable') + await rdbStore.executeSql(CREATE_TABLE_TEST); + const valueBucket1 = { id: 1, name: "ZhangSan", age: 20, salary: 100.51, adddate: '2022-09-01' } + await rdbStore.insert("test", valueBucket1) + const valueBucket2 = { id: 2, name: "LiSi", age: 21, salary: 120.61, adddate: '2022-09-01' } + await rdbStore.insert("test", valueBucket2) + const valueBucket3 = { id: 3, name: "WangWu", age: 22, salary: 130.71, adddate: '2022-09-02' } + await rdbStore.insert("test", valueBucket3) + const valueBucket4 = { id: 4, name: "SunLiu", age: 23, salary: 160.81, adddate: '2022-09-02' } + await rdbStore.insert("test", valueBucket4) + const valueBucket5 = { id: 5, name: "MaQi", age: 24, salary: 170.91, adddate: '2022-09-02' } + await rdbStore.insert("test", valueBucket5) + console.info(TAG + 'generateTable end') + } + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001 + * @tc.desc resultSet Update test + */ + it('SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001 start *************"); + + let predicates = await new data_Rdb.RdbPredicates("test") + predicates.groupBy(["DATE(test.adddate)"]).orderByAsc("COUNT(*)") + let resultSet = await rdbStore.query(predicates, ["COUNT(*) AS 'num Count'", "DATE(test.adddate) as birthday"]) + expect(true).assertEqual(resultSet.goToFirstRow()) + let count = await resultSet.getLong(resultSet.getColumnIndex("num Count")) + let birthday = await resultSet.getString(resultSet.getColumnIndex("birthday")) + expect(2).assertEqual(count); + await expect("2022-09-01").assertEqual(birthday) + expect(true).assertEqual(resultSet.goToNextRow()) + count = await resultSet.getLong(resultSet.getColumnIndex("num Count")) + birthday = await resultSet.getString(resultSet.getColumnIndex("birthday")) + expect(3).assertEqual(count); + await expect("2022-09-02").assertEqual(birthday) + expect(false).assertEqual(resultSet.goToNextRow()) + done(); + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0001 end *************"); + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002 + * @tc.desc resultSet Update test + */ + it('SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002', 0, async function (done) { + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002 start *************"); + + let predicates = await new data_Rdb.RdbPredicates("test") + predicates.groupBy(["DATE(test.adddate)"]).orderByDesc("COUNT(*)") + let resultSet = await rdbStore.query(predicates, ["COUNT(*) AS numCount", "DATE(test.adddate) as birthday"]) + expect(true).assertEqual(resultSet.goToFirstRow()) + let count = await resultSet.getLong(resultSet.getColumnIndex("numCount")) + let birthday = await resultSet.getString(resultSet.getColumnIndex("birthday")) + expect(3).assertEqual(count); + await expect("2022-09-02").assertEqual(birthday) + expect(true).assertEqual(resultSet.goToNextRow()) + count = await resultSet.getLong(resultSet.getColumnIndex("numCount")) + birthday = await resultSet.getString(resultSet.getColumnIndex("birthday")) + expect(2).assertEqual(count); + await expect("2022-09-01").assertEqual(birthday) + expect(false).assertEqual(resultSet.goToNextRow()) + done(); + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_ComplexFiled_0002 end *************"); + }) + + console.log(TAG + "*************Unit Test End*************"); +}) +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesJoinJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesJoinJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..aae7cf5ada176742800e6ec23023a473e94fa46e --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesJoinJsunit.test.js @@ -0,0 +1,192 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility' +var context = ability_featureAbility.getContext(); + +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: "RdbJoinTest.db", + securityLevel: data_Rdb.SecurityLevel.S1 +} + +const CURRENT_STORE_VERSION = 1; + +const TAG = 'RelationalStore_TEST'; + +var rdbStore = undefined; + +export default function relationalStorePredicatesJoinTest() { +describe('relationalStorePredicatesJoinTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll end') + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await generateUserTable(); + await generateBookTable(); + console.info(TAG + 'beforeEach end') + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await data_Rdb.deleteRdbStore(context, "InsertTest.db"); + rdbStore = null + console.info(TAG + 'afterEach end') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll end') + }) + + 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.name: testRdbJoin001 + * @tc.number: SUB_DDM_AppDataFWK_Rdb_Inner_Join + * @tc.desc: sql query inner join test + */ + it('testRdbJoin001', 0, async function (done) { + console.info(TAG + "testRdbJoin001 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.getInt(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getInt(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getInt(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + expect(1).assertEqual(resultSet.getInt(7)); + done(); + }) + + /** + * @tc.name: testRdbJoin002 + * @tc.number: SUB_DDM_AppDataFWK_Rdb_Cross_Join + * @tc.desc: sql query cross join test + */ + it('testRdbJoin002', 0, async function (done) { + console.info(TAG + "testRdbJoin002 begin."); + let resultSet = await rdbStore.querySql("" + + "SELECT * FROM user CROSS JOIN Book USING(userId) WHERE Book.name = 'sanguo'"); + + expect(1).assertEqual(resultSet.rowCount); + + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getInt(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getInt(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getInt(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + done(); + + done(); + }) + + /** + * @tc.name: testRdbJoin003 + * @tc.number: SUB_DDM_AppDataFWK_Rdb_Left_Outer_Join + * @tc.desc: sql query left outer join test + */ + it('testRdbJoin003', 0, async function (done) { + console.info(TAG + "testRdbJoin003 begin."); + let resultSet = await rdbStore.querySql("" + + "SELECT * FROM user LEFT OUTER JOIN Book USING(userId) WHERE Book.name = 'sanguo'"); + + expect(1).assertEqual(resultSet.rowCount); + + expect(true).assertEqual(resultSet.goToFirstRow()); + expect(1).assertEqual(resultSet.getInt(0)); + expect("Zhang").assertEqual(resultSet.getString(1)); + expect("San").assertEqual(resultSet.getString(2)); + expect(29).assertEqual(resultSet.getInt(3)); + expect(100.51).assertEqual(resultSet.getDouble(4)); + expect(1).assertEqual(resultSet.getInt(5)); + expect("sanguo").assertEqual(resultSet.getString(6)); + done(); + }) + + console.info(TAG + "*************Unit Test End*************"); +})} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..915f76b35f71c8a882f7c26b109f6e3da5319b1b --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStorePredicatesJsunit.test.js @@ -0,0 +1,2221 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility' +var context = ability_featureAbility.getContext(); + +const TAG = "[RelationalStore_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: data_Rdb.SecurityLevel.S1 +} +var rdbStore = undefined; +var DOUBLE_MAX = 9223372036854775807; +export default function relationalStorePredicatesTest() { +describe('relationalStorePredicatesTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_ALL_DATA_TYPE_SQL, null); + await buildAllDataType1(); + await buildAllDataType2(); + await buildAllDataType3(); + }) + + beforeEach(function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await data_Rdb.deleteRdbStore(context, "Predicates.db"); + }) + + function resultSize(resultSet) { + if (!resultSet.goToFirstRow()) { + return 0; + } + let count = 1; + while (resultSet.goToNextRow()) { + count++; + } + return count; + } + + 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.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0010 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0001', 0, async function (done) { + console.info(TAG + "************* testEqualTo0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + { + predicates.equalTo("booleanValue", true); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testEqualTo0001 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0011 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0002', 0, async function (done) { + console.info(TAG + "************* testEqualTo0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("byteValue", -128).or().equalTo("byteValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testEqualTo0002 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0012 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0003', 0, async function (done) { + console.info(TAG + "************* testEqualTo0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testEqualTo0003 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0013 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0004', 0, async function (done) { + console.info(TAG + "************* testEqualTo0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("doubleValue", DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testEqualTo0004 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0014 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0005', 0, async function (done) { + console.info(TAG + "************* testEqualTo0005 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("shortValue", -32768.0); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testEqualTo0005 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0015 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0006', 0, async function (done) { + console.info(TAG + "************* testEqualTo0006 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(true).assertEqual(result.goToFirstRow()); + expect(2).assertEqual(result.getLong(0)); + } + done(); + console.info(TAG + "************* testEqualTo0006 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0016 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0007', 0, async function (done) { + console.info(TAG + "************* testEqualTo0007 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(true).assertEqual(result.goToFirstRow()); + expect(2).assertEqual(result.getLong(0)) + } + done(); + console.info(TAG + "************* testEqualTo0007 end *************"); + }) + + /** + * @tc.name predicates equalTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0017 + * @tc.desc predicates equalTo normal test + */ + it('testEqualTo0008', 0, async function (done) { + console.info(TAG + "************* testEqualTo0008 start *************"); + { + let predicates = await new data_Rdb.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 = null + } + done(); + console.info(TAG + "************* testEqualTo0008 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0020 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0001', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("booleanValue", true); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0001 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0021 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0002', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("byteValue", -128); + predicates.notEqualTo("byteValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0002 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0022 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0003', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("stringValue", "ABCDEFGHIJKLMN"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0003 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0023 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0004', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("doubleValue", DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0004 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0024 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0005', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0005 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("shortValue", -32768); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0005 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0025 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0006', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0006 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0006 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0026 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0007', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0007 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0007 end *************"); + }) + + /** + * @tc.name predicates notEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0027 + * @tc.desc predicates notEqualTo normal test + */ + it('testNotEqualTo0008', 0, async function (done) { + console.info(TAG + "************* testNotEqualTo0008 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notEqualTo("floatValue", -0.123); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testNotEqualTo0008 end *************"); + }) + + /** + * @tc.name predicates isNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0030 + * @tc.desc predicates isNull normal test + */ + it('testIsNull0001', 0, async function (done) { + console.info(TAG + "************* testIsNull001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNull("primLongValue"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNull0001 end *************"); + }) + + /** + * @tc.name predicates isNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0031 + * @tc.desc predicates isNull normal test + */ + it('testIsNull0002', 0, async function (done) { + console.info(TAG + "************* testIsNull0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNull("longValue"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNull0002 end *************"); + }) + + /** + * @tc.name predicates isNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0032 + * @tc.desc predicates isNull normal test + */ + it('testIsNull0003', 0, async function (done) { + console.info(TAG + "************* testIsNull0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNull("stringValue"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNull0003 end *************"); + }) + + /** + * @tc.name predicates isNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0033 + * @tc.desc predicates isNull normal test + */ + it('testIsNull0004', 0, async function (done) { + console.info(TAG + "************* testIsNull0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNull("stringValueX"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNull0004 end *************"); + }) + + /** + * @tc.name predicates isNotNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0040 + * @tc.desc predicates isNotNull normal test + */ + it('testIsNotNull0001', 0, async function (done) { + console.info(TAG + "************* testIsNotNull0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNotNull("primLongValue"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNotNull0001 end *************"); + }) + + /** + * @tc.name predicates isNotNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0041 + * @tc.desc predicates isNotNull normal test + */ + it('testIsNotNull0002', 0, async function (done) { + console.info(TAG + "************* testIsNotNull0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNotNull("longValue"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNotNull0002 end *************"); + }) + + /** + * @tc.name predicates isNotNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0042 + * @tc.desc predicates isNotNull normal test + */ + it('testIsNotNull0003', 0, async function (done) { + console.info(TAG + "************* testIsNotNull0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNotNull("stringValue"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNotNull0003 end *************"); + }) + + /** + * @tc.name predicates isNotNull normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0043 + * @tc.desc predicates isNotNull normal test + */ + it('testIsNotNull0004', 0, async function (done) { + console.info(TAG + "************* testIsNotNull0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.isNotNull("stringValueX"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testIsNotNull0004 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0050 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0001', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("stringValue", "ABC"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0001 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0051 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0002', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0002 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0052 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0003', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0003 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0053 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0004', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("longValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0004 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0054 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0005', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0005 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("stringValue", "ZZZ"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0005 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0055 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0006', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0006 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("doubleValue", 999.0); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0006 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0056 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0007', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0007 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("integerValue", -999); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0007 end *************"); + }) + + /** + * @tc.name predicates greaterThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0057 + * @tc.desc predicates greaterThan normal test + */ + it('testGreaterThan0008', 0, async function (done) { + console.info(TAG + "************* testGreaterThan0008 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThan("longValue", -999); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThan0008 end *************"); + }) + + /** + * @tc.name predicates greaterThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0060 + * @tc.desc predicates greaterThanOrEqualTo normal test + */ + it('testGreaterThanOrEqualTo0001', 0, async function (done) { + console.info(TAG + "************* testGreaterThanOrEqualTo0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("stringValue", "ABC"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThanOrEqualTo0001 end *************"); + }) + + /** + * @tc.name predicates greaterThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0061 + * @tc.desc predicates greaterThanOrEqualTo normal test + */ + it('testGreaterThanOrEqualTo0002', 0, async function (done) { + console.info(TAG + "************* testGreaterThanOrEqualTo0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThanOrEqualTo0002 end *************"); + }) + + /** + * @tc.name predicates greaterThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0062 + * @tc.desc predicates greaterThanOrEqualTo normal test + */ + it('testGreaterThanOrEqualTo0003', 0, async function (done) { + console.info(TAG + "************* testGreaterThanOrEqualTo0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThanOrEqualTo0003 end *************"); + }) + + /** + * @tc.name predicates greaterThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0063 + * @tc.desc predicates greaterThanOrEqualTo normal test + */ + it('testGreaterThanOrEqualTo0004', 0, async function (done) { + console.info(TAG + "************* testGreaterThanOrEqualTo0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.greaterThanOrEqualTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testGreaterThanOrEqualTo0004 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0070 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0001', 0, async function (done) { + console.info(TAG + "************* testLessThan0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("stringValue", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0001 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0071 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0002', 0, async function (done) { + console.info(TAG + "************* testLessThan0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0002 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0072 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0003', 0, async function (done) { + console.info(TAG + "************* testLessThan0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0003 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0073 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0004', 0, async function (done) { + console.info(TAG + "************* testLessThan0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("longValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0004 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0074 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0005', 0, async function (done) { + console.info(TAG + "************* testLessThan0005 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("stringValue", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0005 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0075 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0006', 0, async function (done) { + console.info(TAG + "************* testLessThan0006 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("doubleValue", 1.0); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0006 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0076 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0007', 0, async function (done) { + console.info(TAG + "************* testLessThan0007 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("integerValue", -2147483648); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0007 end *************"); + }) + + /** + * @tc.name predicates lessThan normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0077 + * @tc.desc predicates lessThan normal test + */ + it('testLessThan0008', 0, async function (done) { + console.info(TAG + "************* testLessThan0008 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThan("longValue", -9223372036854775808); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThan0008 end *************"); + }) + + /** + * @tc.name predicates lessThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0080 + * @tc.desc predicates lessThanOrEqualTo normal test + */ + it('testLessThanOrEqualTo0001', 0, async function (done) { + console.info(TAG + "************* testLessThanOrEqualTo0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("stringValue", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThanOrEqualTo0001 end *************"); + }) + + /** + * @tc.name predicates lessThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0081 + * @tc.desc predicates lessThanOrEqualTo normal test + */ + it('testLessThanOrEqualTo0002', 0, async function (done) { + console.info(TAG + "************* testLessThanOrEqualTo0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("doubleValue", 0.0); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThanOrEqualTo0002 end *************"); + }) + + /** + * @tc.name predicates lessThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0082 + * @tc.desc predicates lessThanOrEqualTo normal test + */ + it('testLessThanOrEqualTo0003', 0, async function (done) { + console.info(TAG + "************* testLessThanOrEqualTo0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThanOrEqualTo0003 end *************"); + }) + + /** + * @tc.name predicates lessThanOrEqualTo normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0083 + * @tc.desc predicates lessThanOrEqualTo normal test + */ + it('testLessThanOrEqualTo0004', 0, async function (done) { + console.info(TAG + "************* testLessThanOrEqualTo0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.lessThanOrEqualTo("longValue", 1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testLessThanOrEqualTo0004 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0090 + * @tc.desc predicates between normal test + */ + it('testBetween0001', 0, async function (done) { + console.info(TAG + "************* testBetween0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("stringValue", "ABB", "ABD"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0001 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0091 + * @tc.desc predicates between normal test + */ + it('testBetween0002', 0, async function (done) { + console.info(TAG + "************* testBetween0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("doubleValue", 0.0, DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0002 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0092 + * @tc.desc predicates between normal test + */ + it('testBetween0003', 0, async function (done) { + console.info(TAG + "************* testBetween0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("integerValue", 0, 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0003 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0093 + * @tc.desc predicates between normal test + */ + it('testBetween0004', 0, async function (done) { + console.info(TAG + "************* testBetween0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("longValue", 0, 2); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0004 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0094 + * @tc.desc predicates between normal test + */ + it('testBetween0005', 0, async function (done) { + console.info(TAG + "************* testBetween0005 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("stringValue", "ABB", "ABB"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0005 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0095 + * @tc.desc predicates between normal test + */ + it('testBetween0006', 0, async function (done) { + console.info(TAG + "************* testBetween0006 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("doubleValue", DOUBLE_MAX, DOUBLE_MAX); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0006 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0096 + * @tc.desc predicates between normal test + */ + it('testBetween0007', 0, async function (done) { + console.info(TAG + "************* testBetween0007 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("integerValue", 1, 0); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0007 end *************"); + }) + + /** + * @tc.name predicates between normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0097 + * @tc.desc predicates between normal test + */ + it('testBetween0008', 0, async function (done) { + console.info(TAG + "************* testBetween0008 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.between("longValue", 2, -1); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBetween0008 end *************"); + }) + + /** + * @tc.name testNotBetween0001 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0230 + * @tc.desc test string value with notBetween. + */ + it('testNotBetween0001', 0, async function (done) { + console.info(TAG + "************* testNotBetween0001 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testNotBetween0001 end *************"); + }) + + /** + * @tc.name testNotBetween0002 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0231 + * @tc.desc test double value with notBetween. + */ + it('testNotBetween0002', 0, async function (done) { + console.info(TAG + "************* testNotBetween0002 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testNotBetween0002 end *************"); + }) + + /** + * @tc.name testNotBetween0003 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0232 + * @tc.desc test integer value with notBetween. + */ + it('testNotBetween0003', 0, async function (done) { + console.info(TAG + "************* testNotBetween0003 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testNotBetween0003 end *************"); + }) + + /** + * @tc.name testNotBetween0004 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0233 + * @tc.desc test long value with notBetween. + */ + it('testNotBetween0004', 0, async function (done) { + console.info(TAG + "************* testNotBetween0004 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testNotBetween0004 end *************"); + }) + + /** + * @tc.name testGlob0001 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0240 + * @tc.desc end with ? by glob. + */ + it('testGlob0001', 0, async function (done) { + console.info(TAG + "************* testGlob0001 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testGlob0001 end *************"); + }) + + /** + * @tc.name testGlob0002 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0241 + * @tc.desc begin with * by glob. + */ + it('testGlob0002', 0, async function (done) { + console.info(TAG + "************* testGlob0002 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testGlob0002 end *************"); + }) + + /** + * @tc.name testGlob0003 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0242 + * @tc.desc end with ? by glob. + */ + it('testGlob0003', 0, async function (done) { + console.info(TAG + "************* testGlob0003 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testGlob0003 end *************"); + }) + + /** + * @tc.name testGlob0004 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0243 + * @tc.desc begin with ? by glob. + */ + it('testGlob0004', 0, async function (done) { + console.info(TAG + "************* testGlob0004 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testGlob0004 end *************"); + }) + + /** + * @tc.name testGlob0005 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0244 + * @tc.desc begin and end with * by glob. + */ + it('testGlob0005', 0, async function (done) { + console.info(TAG + "************* testGlob0005 start *************"); + { + let predicates = await new data_Rdb.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 + "************* testGlob0005 end *************"); + }) + + /** + * @tc.name testGlob0006 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0245 + * @tc.desc begin and end with ? by glob. + */ + it('testGlob0006', 0, async function (done) { + console.info(TAG + "************* testGlob0006 start *************"); + { + let predicates = await new data_Rdb.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.name predicates contains normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0100 + * @tc.desc predicates contains normal test + */ + it('testContains0001', 0, async function (done) { + console.info(TAG + "************* testContains0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.contains("stringValue", "DEF"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testContains0001 end *************"); + }) + + /** + * @tc.name predicates contains normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0101 + * @tc.desc predicates contains normal test + */ + it('testContains0002', 0, async function (done) { + console.info(TAG + "************* testContains0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.contains("stringValue", "DEFX"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testContains0002 end *************"); + }) + + /** + * @tc.name predicates contains normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0102 + * @tc.desc predicates contains normal test + */ + it('testContains0003', 0, async function (done) { + console.info(TAG + "************* testContains0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.contains("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testContains0003 end *************"); + }) + + /** + * @tc.name predicates contains normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0103 + * @tc.desc predicates contains normal test + */ + it('testContains0004', 0, async function (done) { + console.info(TAG + "************* testContains0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.contains("characterValue", "#"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testContains0004 end *************"); + }) + + /** + * @tc.name predicates beginsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0110 + * @tc.desc predicates beginsWith normal test + */ + it('testBeginsWith0001', 0, async function (done) { + console.info(TAG + "************* testBeginsWith0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.beginsWith("stringValue", "ABC"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testBeginsWith0001 end *************"); + }) + + /** + * @tc.name predicates beginsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0111 + * @tc.desc predicates beginsWith normal test + */ + it('testBeginsWith0002', 0, async function (done) { + console.info(TAG + "************* testBeginsWith0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.beginsWith("stringValue", "ABCX"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testBeginsWith0002 end *************"); + }) + + /** + * @tc.name predicates beginsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0112 + * @tc.desc predicates beginsWith normal test + */ + it('testBeginsWith0003', 0, async function (done) { + console.info(TAG + "************* testBeginsWith0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.beginsWith("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testBeginsWith0003 end *************"); + }) + + /** + * @tc.name predicates beginsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0113 + * @tc.desc predicates beginsWith normal test + */ + it('testBeginsWith0004', 0, async function (done) { + console.info(TAG + "************* testBeginsWith0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.beginsWith("characterValue", "#"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testBeginsWith0004 end *************"); + }) + + /** + * @tc.name predicates endsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0120 + * @tc.desc predicates endsWith normal test + */ + it('testEndsWith0001', 0, async function (done) { + console.info(TAG + "************* testEndsWith0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.endsWith("stringValue", "LMN"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testEndsWith0001 end *************"); + }) + + /** + * @tc.name predicates endsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0121 + * @tc.desc predicates endsWith normal test + */ + it('testEndsWith0002', 0, async function (done) { + console.info(TAG + "************* testEndsWith0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.endsWith("stringValue", "LMNX"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testEndsWith0002 end *************"); + }) + + /** + * @tc.name predicates endsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0122 + * @tc.desc predicates endsWith normal test + */ + it('testEndsWith0003', 0, async function (done) { + console.info(TAG + "************* testEndsWith0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.endsWith("characterValue", "中"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testEndsWith0003 end *************"); + }) + + /** + * @tc.name predicates endsWith normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0123 + * @tc.desc predicates endsWith normal test + */ + it('testEndsWith0004', 0, async function (done) { + console.info(TAG + "************* testEndsWith0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.endsWith("characterValue", "#"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testEndsWith0004 end *************"); + }) + + /** + * @tc.name predicates like normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0130 + * @tc.desc predicates like normal test + */ + it('testLike0001', 0, async function (done) { + console.info(TAG + "************* testLike0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "%LMN%"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLike0001 end *************"); + }) + + /** + * @tc.name predicates like normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0131 + * @tc.desc predicates like normal test + */ + it('testLike0002', 0, async function (done) { + console.info(TAG + "************* testLike0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "%LMNX%"); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLike0002 end *************"); + }) + + /** + * @tc.name predicates like normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0132 + * @tc.desc predicates like normal test + */ + it('testLike0003', 0, async function (done) { + console.info(TAG + "************* testLike0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("characterValue", "%中%"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLike0003 end *************"); + }) + + /** + * @tc.name predicates like normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0133 + * @tc.desc predicates like normal test + */ + it('testLike0004', 0, async function (done) { + console.info(TAG + "************* testLike0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("characterValue", "%#%"); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLike0004 end *************"); + }) + + /** + * @tc.name predicates beginWrap normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0140 + * @tc.desc predicates beginWrap normal test + */ + it('testBeginWrap0001', 0, async function (done) { + console.info(TAG + "************* testBeginWrap0001 start *************"); + { + let predicates = await new data_Rdb.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 = null + } + done(); + console.info(TAG + "************* testBeginWrap0001 end *************"); + }) + + /** + * @tc.name predicates beginWrap normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0141 + * @tc.desc predicates beginWrap normal test + */ + it('testBeginWrap0002', 0, async function (done) { + console.info(TAG + "************* testBeginWrap0002 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN") + .beginWrap() + .equalTo("characterValue", ' ') + .endWrap(); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBeginWrap0002 end *************"); + }) + + /** + * @tc.name predicates beginWrap normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0142 + * @tc.desc predicates beginWrap normal test + */ + it('testBeginWrap0003', 0, async function (done) { + console.info(TAG + "************* testBeginWrap0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN") + .beginWrap() + .equalTo("characterValue", '中') + .endWrap(); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBeginWrap0003 end *************"); + }) + + /** + * @tc.name predicates beginWrap normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0143 + * @tc.desc predicates beginWrap normal test + */ + it('testBeginWrap0004', 0, async function (done) { + console.info(TAG + "************* testBeginWrap0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN") + .equalTo("characterValue", '中') + .endWrap(); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBeginWrap0004 end *************"); + }) + + /** + * @tc.name predicates beginWrap normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0144 + * @tc.desc predicates beginWrap normal test + */ + it('testBeginWrap0005', 0, async function (done) { + console.info(TAG + "************* testBeginWrap0005 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN") + .beginWrap() + .equalTo("characterValue", '中'); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testBeginWrap0005 end *************"); + }) + + /** + * @tc.name predicates and normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0150 + * @tc.desc predicates and normal test + */ + it('testAnd0001', 0, async function (done) { + console.info(TAG + "************* testAnd0001 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN") + .and() + .equalTo("integerValue", 1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testAnd0001 end *************"); + }) + + /** + * @tc.name predicates or normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0151 + * @tc.desc predicates or normal test + */ + it('testAnd0002', 0, async function (done) { + console.info(TAG + "************* testAnd0002 start *************"); + { + let predicates = await new data_Rdb.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 = null + } + done(); + console.info(TAG + "************* testAnd0002 end *************"); + }) + + /** + * @tc.name predicates and normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0152 + * @tc.desc predicates and normal test + */ + it('testAnd0003', 0, async function (done) { + console.info(TAG + "************* testAnd0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + var predicatesInit = predicates + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").or().and().equalTo("integerValue", 1); + expect(predicates == predicatesInit).assertTrue(); + console.info(TAG + "you should not start a request" + " with \"and\" or use or() before this function"); + } + done(); + console.info(TAG + "************* testAnd0003 end *************"); + }) + + /** + * @tc.name predicates and normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0153 + * @tc.desc predicates and normal test + */ + it('testAnd0004', 0, async function (done) { + console.info(TAG + "************* testAnd0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + var predicatesInit = predicates + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").or().or().equalTo("integerValue", 1); + expect(predicates == predicatesInit).assertTrue(); + console.info(TAG + "you are starting a sql request with predicate or or," + + "using function or() immediately after another or(). that is ridiculous."); + } + done(); + console.info(TAG + "************* testAnd0004 end *************"); + }) + + /** + * @tc.name predicates order normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0160 + * @tc.desc predicates order normal test + */ + it('testOrder0001', 0, async function (done) { + console.info(TAG + "************* testOrder0001 start *************"); + { + let predicates = await new data_Rdb.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 = null + } + done(); + console.info(TAG + "************* testOrder0001 end *************"); + }) + + /** + * @tc.name predicates order normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0161 + * @tc.desc predicates order normal test + */ + it('testOrder0002', 0, async function (done) { + console.info(TAG + "************* testOrder0002 start *************"); + { + let predicates = await new data_Rdb.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 = null + } + done(); + console.info(TAG + "************* testOrder0002 end *************"); + }) + + /** + * @tc.name predicates order normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0162 + * @tc.desc predicates order normal test + */ + it('testOrder0003', 0, async function (done) { + console.info(TAG + "************* testOrder0003 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").orderByDesc("integerValueX").distinct(); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testOrder0003 end *************"); + }) + + /** + * @tc.name predicates order normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0163 + * @tc.desc predicates order normal test + */ + it('testOrder0004', 0, async function (done) { + console.info(TAG + "************* testOrder0004 start *************"); + { + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.equalTo("stringValue", "ABCDEFGHIJKLMN").orderByAsc("integerValueX").distinct(); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + } + done(); + console.info(TAG + "************* testOrder0004 end *************"); + }) + + /** + * @tc.name predicates limit normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0170 + * @tc.desc predicates limit normal test + */ + it('testLimit0001', 0, async function (done) { + console.info(TAG + "************* testLimit0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(1); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLimit0001 end *************"); + }) + + /** + * @tc.name predicates limit normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0171 + * @tc.desc predicates limit normal test + */ + it('testLimit0002', 0, async function (done) { + console.info(TAG + "************* testLimit0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLimit0002 end *************"); + }) + + /** + * @tc.name predicates limit normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0172 + * @tc.desc predicates limit normal test + */ + it('testLimit0003', 0, async function (done) { + console.info(TAG + "************* testLimit0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(100); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLimit0003 end *************"); + }) + + /** + * @tc.name predicates limit normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0173 + * @tc.desc predicates limit normal test + */ + it('testLimit0004', 0, async function (done) { + console.info(TAG + "************* testLimit0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "中").limitAs(1); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLimit0004 end *************"); + }) + + /** + * @tc.name predicates limit normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0174 + * @tc.desc predicates limit normal test + */ + it('testLimit0005', 0, async function (done) { + console.info(TAG + "************* testLimit0005 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLimit0005 end *************"); + }) + + /** + * @tc.name predicates limit normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0175 + * @tc.desc predicates limit normal test + */ + it('testLimit0006', 0, async function (done) { + console.info(TAG + "************* testLimit0006 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(-1); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testLimit0006 end *************"); + }) + + /** + * @tc.name predicates offset normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0180 + * @tc.desc predicates offset normal test + */ + it('testOffset0001', 0, async function (done) { + console.info(TAG + "************* testOffset0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(1); + let result = await rdbStore.query(predicates); + expect(2).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testOffset0001 end *************"); + }) + + /** + * @tc.name predicates offset normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0181 + * @tc.desc predicates offset normal test + */ + it('testOffset0002', 0, async function (done) { + console.info(TAG + "************* testOffset0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(0); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testOffset0002 end *************"); + }) + + /** + * @tc.name predicates offset normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0182 + * @tc.desc predicates offset normal test + */ + it('testOffset0003', 0, async function (done) { + console.info(TAG + "************* testOffset0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(5); + let result = await rdbStore.query(predicates); + expect(0).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testOffset0003 end *************"); + }) + + /** + * @tc.name predicates offset normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0183 + * @tc.desc predicates offset normal test + */ + it('testOffset0004', 0, async function (done) { + console.info(TAG + "************* testOffset0004 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").limitAs(3).offsetAs(-1); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testOffset0004 end *************"); + }) + + /** + * @tc.name predicates in normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0190 + * @tc.desc predicates in normal test + */ + it('testIn0001', 0, async function (done) { + console.info(TAG + "************* testIn0001 start *************"); + var values = [Number.MIN_VALUE.toString()]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + done(); + console.info(TAG + "************* testIn0001 end *************"); + }) + + /** + * @tc.name predicates in normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0191 + * @tc.desc predicates in normal test + */ + it('testIn0002', 0, async function (done) { + console.info(TAG + "************* testIn0002 start *************"); + var values = ["1.0"]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + done(); + console.info(TAG + "************* testIn0002 end *************"); + }) + + /** + * @tc.name predicates in normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0192 + * @tc.desc predicates in normal test + */ + it('testIn0003', 0, async function (done) { + console.info(TAG + "************* testIn0003 start *************"); + var values = [DOUBLE_MAX.toString()]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + done(); + console.info(TAG + "************* testIn0003 end *************"); + }) + + /** + * @tc.name predicates in normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0193 + * @tc.desc predicates in normal test + */ + it('testIn0004', 0, async function (done) { + console.info(TAG + "************* testIn0004 start *************"); + var values = [Number.MIN_VALUE.toString(), "1.0", DOUBLE_MAX.toString()]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.in("doubleValue", values); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + done(); + console.info(TAG + "************* testIn0004 end *************"); + }) + + /** + * @tc.name testNotIn0001 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0250 + * @tc.desc the common and min value test with notin. + */ + it('testNotIn0001', 0, async function (done) { + console.info(TAG + "************* testNotIn0001 start *************"); + var values = [1, -2147483648]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notIn("integerValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testNotIn0001 end *************"); + }) + + /** + * @tc.name testNotIn0002 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0251 + * @tc.desc the common and max value test with notin. + */ + it('testNotIn0002', 0, async function (done) { + console.info(TAG + "************* testNotIn0002 start *************"); + let values = [1, 2147483647]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notIn("integerValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testNotIn0002 end *************"); + }) + + /** + * @tc.name testNotIn0003 + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0252 + * @tc.desc the min and max value test with notin. + */ + it('testNotIn0003', 0, async function (done) { + console.info(TAG + "************* testNotIn0003 start *************"); + var values = [-2147483648, 2147483647]; + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.notIn("integerValue", values); + let result = await rdbStore.query(predicates); + expect(1).assertEqual(result.rowCount); + result.close(); + done(); + console.info(TAG + "************* testNotIn0003 end *************"); + }) + + /** + * @tc.name predicates constructor test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0200 + * @tc.desc predicates constructor test + */ + it('testCreate0001', 0, async function (done) { + console.info(TAG + "************* testCreate0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + done(); + console.info(TAG + "************* testCreate0001 end *************"); + }) + + /** + * @tc.name predicates constructor test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0201 + * @tc.desc predicates constructor test + */ + it('testCreate0002', 0, async function (done) { + console.info(TAG + "************* testCreate0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("test"); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + done(); + console.info(TAG + "************* testCreate0002 end *************"); + }) + + /** + * @tc.name predicates groupBy test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0210 + * @tc.desc predicates groupBy test + */ + it('testGroupBy0001', 0, async function (done) { + console.info(TAG + "************* testGroupBy0001 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").groupBy(["characterValue"]); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testGroupBy0001 end *************"); + }) + + /** + * @tc.name predicates groupBy test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0211 + * @tc.desc predicates groupBy test + */ + it('testGroupBy0002', 0, async function (done) { + console.info(TAG + "************* testGroupBy0002 start *************"); + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").groupBy(["characterValueX"]); + let result = await rdbStore.query(predicates); + expect(-1).assertEqual(result.rowCount); + result = null + done(); + console.info(TAG + "************* testGroupBy0002 end *************"); + }) + + /** + * @tc.name predicates indexedBy test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0220 + * @tc.desc predicates indexedBy test + */ + it('testIndexedBy0001', 0, async function (done) { + console.info(TAG + "************* testIndexedBy0001 start *************"); + let errInfo = undefined + try{ + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").indexedBy(["characterValue"]); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done(); + console.info(TAG + "************* testIndexedBy0001 end *************"); + }) + + /** + * @tc.name predicates indexedBy test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Predicates_0221 + * @tc.desc predicates indexedBy test + */ + it('testIndexedBy0002', 0, async function (done) { + console.info(TAG + "************* testIndexedBy0002 start *************"); + let errInfo = undefined + try{ + let predicates = await new data_Rdb.RdbPredicates("AllDataType"); + predicates.like("stringValue", "ABCDEFGHIJKLMN").indexedBy(["characterValueX"]); + let result = await rdbStore.query(predicates); + expect(3).assertEqual(result.rowCount); + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done(); + console.info(TAG + "************* testIndexedBy0002 end *************"); + }) + + console.info(TAG + "*************Unit Test End*************"); +})} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreQuery.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreQuery.test.js new file mode 100644 index 0000000000000000000000000000000000000000..d4e5cd50e012ba9220514f5f12703999c01c0019 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreQuery.test.js @@ -0,0 +1,348 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium'; +import data_Rdb from '@ohos.data.relationalStore'; +import factory from '@ohos.data.distributedData'; +import ability_featureAbility from '@ohos.ability.featureAbility'; + +const TAG = "[RelationalStore_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: "Query.db", + securityLevel: data_Rdb.SecurityLevel.S1 +} +const TEST_BUNDLE_NAME="ohos.acts.relationalstorejstest" + +var kvManager = null +var kvStore = null +var localDeviceId = null +var rdbStore +var context = ability_featureAbility.getContext() + +async function CreatRdbStore(context, STORE_CONFIG) { + let RdbStore = await data_Rdb.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("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 28, + "salary": 100.5, + "blobType": u8, + } + await RdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "wangwu", + "age": 38, + "salary": 90.0, + "blobType": u8, + } + await RdbStore.insert("test", valueBucket) + } + return RdbStore +} + +async function getLocalDeviceId(){ + +} +export default function relationalStoreQueryTest(){ + describe("relationalStoreQueryTest", function() { + beforeAll(async function (done){ + const config = { + bundleName : TEST_BUNDLE_NAME, + userInfo : { + userId : '0', + userType : factory.UserType.SAME_USER_ID, + context:context + } + } + + const options = { + createIfMissing : true, + encrypt : false, + backup : false, + autoSync : true, + kvStoreType : factory.KVStoreType.DEVICE_COLLABORATION, + schema : '', + securityLevel : factory.SecurityLevel.S2, + } + + console.info('getLocalDeviceId config:'+ JSON.stringify(config)); + await factory.createKVManager(config).then((manager) => { + kvManager = manager; + console.info('getLocalDeviceId createKVManager success'); + }).catch((err) => { + console.info('getLocalDeviceId createKVManager err ' + err); + }); + await kvManager.getKVStore(TEST_STORE_ID, options).then((store) => { + kvStore = store; + console.info('getLocalDeviceId getKVStore for getDeviceId success'); + }).catch((err) => { + console.info('getLocalDeviceId getKVStore err ' + err); + }); + var getDeviceId = new Promise((resolve, reject) => { + kvStore.on('dataChange', 0, function (data) { + console.info('getLocalDeviceId on data change: ' + JSON.stringify(data)); + resolve(data.deviceId); + }); + kvStore.put("getDeviceId", "byPut").then((data) => { + console.info('getLocalDeviceId put success'); + expect(data == undefined).assertTrue(); + }); + setTimeout(() => { + reject(new Error('not resolved in 2 second, reject it.')) + }, 2000); + }); + await getDeviceId.then(function(deviceId) { + console.info('getLocalDeviceId getDeviceId ' + JSON.stringify(deviceId)); + localDeviceId = deviceId; + }).catch((error) => { + console.info('getLocalDeviceId can NOT getDeviceId, fail: ' + error); + expect(null).assertFail(); + }); + await kvManager.closeKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID, kvStore); + await kvManager.deleteKVStore(TEST_BUNDLE_NAME, TEST_STORE_ID); + kvStore = null; + console.info('getLocalDeviceId end'); + getLocalDeviceId() + console.info(TAG + 'beforeAll') + done(); + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + + rdbStore = await CreatRdbStore(context, STORE_CONFIG) + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await data_Rdb.deleteRdbStore(context, STORE_CONFIG.name) + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0010 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryPromiseTest0010', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryPromiseTest0010 start") + let errInfo = undefined + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + rdbStore.remoteQuery(localDeviceId,"test",predicates,["name","age","salary"]) + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done(); + console.info(TAG + "RdbRemoteQueryPromiseTest0010 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0020 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryPromiseTest0020', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryPromiseTest0020 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery([localDeviceId],"test",predicates,["name","age","salary"]).then((resultSet) => { + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + }).catch((err) => { + console.info(TAG + "Remote query error" + err) + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryPromiseTest0020 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryPromiseTest0020 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0030 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryPromiseTest0030', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryPromiseTest0030 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery(localDeviceId,["test"],predicates,["name","age","salary"]).then((resultSet) => { + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + }).catch((err) => { + console.info(TAG + "Remote query error" + err) + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryPromiseTest0030 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryPromiseTest0030 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Promise_0040 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryPromiseTest0040', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryPromiseTest0040 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery(localDeviceId,"test",predicates,"age").then((resultSet) => { + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + }).catch((err) => { + console.info(TAG + "Remote query error" + err) + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryPromiseTest0040 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryPromiseTest0040 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0010 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryCallbackTest0010', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryCallbackTest0010 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery(localDeviceId, "test", predicates,["name","age","salary"], (err, data) => { + if(err != null){ + console.info(TAG + "Remote query error" + err) + }else{ + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + } + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryCallbackTest0010 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryCallbackTest0010 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0020 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryCallbackTest0020', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryCallbackTest0020 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery([localDeviceId], "test", predicates,["name","age","salary"], (err, data) => { + if(err != null){ + console.info(TAG + "Remote query error" + err) + }else{ + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + } + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryCallbackTest0020 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryCallbackTest0020 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0030 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryCallbackTest0030', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryCallbackTest0020 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery(localDeviceId, ["test"], predicates,["name","age","salary"], (err, data) => { + if(err != null){ + console.info(TAG + "Remote query error" + err) + }else{ + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + } + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryCallbackTest0030 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryCallbackTest0030 end") + }) + + /** + * @tc.name RelationalStore remotequery test + * @tc.number SUB_DDM_RelationalStore_JS_RemoteQueryTest_Callback_0040 + * @tc.desc RelationalStore remotequery function test + */ + it('RdbRemoteQueryCallbackTest0040', 0, async function (done){ + console.info(TAG + "RdbRemoteQueryCallbackTest0040 start") + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + try{ + await rdbStore.remoteQuery(localDeviceId, "test", predicates,"name", (err, data) => { + if(err != null){ + console.info(TAG + "Remote query error" + err) + }else{ + console.info(TAG + "Remote query success") + expect(false).assertTrue(); + } + }) + }catch(err){ + console.info(TAG + "RdbRemoteQueryCallbackTest0040 error:" + err) + } + + done(); + console.info(TAG + "RdbRemoteQueryCallbackTest0040 end") + }) + + }) +} \ No newline at end of file diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreResultSetJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreResultSetJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..6a5069fe87f73f0f42583c93927379a78b314d01 --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreResultSetJsunit.test.js @@ -0,0 +1,1848 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore' +import ability_featureAbility from '@ohos.ability.featureAbility'; +var context = ability_featureAbility.getContext(); + +const TAG = '[RelationalStore_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: data_Rdb.SecurityLevel.S1 +} +const COLOUNM_NAMES = ["id","data1","data2","data3","data4"]; +var rdbStore = undefined; + +function createUint8Array(length) { + let i = 0 + let index = 0 + let temp = null + let u8 = new Uint8Array(length) + length = typeof (length) === 'undefined' ? 9 : length + for (i = 1; i <= length; i++) { + u8[i - 1] = i + } + for (i = 1; i <= length; i++) { + index = parseInt(Math.random() * (length - i)) + i + if (index != i) { + temp = u8[i - 1] + u8[i - 1] = u8[index - 1] + u8[index - 1] = temp + } + } + return u8; +} + +async function createBigData(size) { + await rdbStore.executeSql("DELETE FROM test"); + let u8 = createUint8Array(32768); + let valueBucketArray = new Array(); + for (let i = 0; i < size; i++) { + valueBucketArray.push({ + "data1": "test" + i, + "data2": 18, + "data3": 100.5, + "data4": u8, + }); + } + await rdbStore.batchInsert("test", valueBucketArray); +} + +export default function relationalStoreResultSetTest() { +describe('relationalStoreResultSetTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + await createTest(); + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + }) + + afterEach(function () { + console.info(TAG + 'afterEach') + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + rdbStore = null + await data_Rdb.deleteRdbStore(context, 'Resultset.db'); + }) + //插入数据 + 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.name resultSet getBlob normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0010 + * @tc.desc resultSet getBlob normal test + */ + it('testGetBlob0001', 0, async function (done) { + console.info(TAG + '************* testGetBlob0001 start *************'); + let predicates = await new data_Rdb.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(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGetBlob0001 end *************'); + }) + + /** + * @tc.name resultSet getBlob normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0011 + * @tc.desc resultSet getBlob normal test + */ + it('testGetBlob0002', 0, async function (done) { + console.info(TAG + '************* testGetBlob0002 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + 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(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGetBlob0002 end *************'); + }) + + /** + * @tc.name resultSet getBlob normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0012 + * @tc.desc resultSet getBlob normal test + */ + it('testGetBlob0003', 0, async function (done) { + console.info(TAG + '************* testGetBlob0003 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + const id = resultSet.getLong(resultSet.getColumnIndex('id')) + const data4 = resultSet.getBlob(resultSet.getColumnIndex('data4')) + console.info(TAG + 'id=' + id); + } + resultSet.close(); + expect(true).assertEqual(resultSet.isClosed) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGetBlob0003 end *************'); + }) + + /** + * @tc.name resultSet isStarted normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0020 + * @tc.desc resultSet isStarted normal test + */ + it('testIsStarted0001', 0, async function (done) { + console.info(TAG + '************* testIsStarted0001 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(false).assertEqual(resultSet.isStarted) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsStarted0001 end *************'); + }) + + /** + * @tc.name resultSet isStarted normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0021 + * @tc.desc resultSet isStarted normal test + */ + it('testIsStarted0002', 0, async function (done) { + console.info(TAG + '************* testIsStarted0002 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + resultSet.goTo(1) + expect(true).assertEqual(resultSet.isStarted) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsStarted0002 end *************'); + }) + + /** + * @tc.name resultSet isStarted normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0022 + * @tc.desc resultSet isStarted normal test + */ + it('testIsStarted0003', 0, async function (done) { + console.info(TAG + "************* testIsStarted0003 start *************"); + let predicates = await new data_Rdb.RdbPredicates("test") + let resultSet = await rdbStore.query(predicates) + try { + expect(false).assertEqual(resultSet.isStarted) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.isStarted) + expect(false).assertEqual(resultSet.goToPreviousRow()) + expect(true).assertEqual(resultSet.isStarted) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + "************* testIsStarted0003 end *************"); + }) + + /** + * @tc.name resultSet isStarted with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0023 + * @tc.desc resultSet isStarted with no result test + */ + it('testIsStarted0004', 0, async function (done) { + console.info(TAG + '************* testIsStarted0004 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.isStarted) + expect(true).assertEqual(resultSet.isStarted) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsStarted0004 end *************'); + }) + + + /** + * @tc.name resultSet isEnded normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0030 + * @tc.desc resultSet isEnded normal test + */ + it('testIsEnded0001', 0, async function (done) { + console.info(TAG + '************* testIsEnded0001 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(false).assertEqual(resultSet.isEnded) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsEnded0001 end *************'); + }) + + /** + * @tc.name resultSet isEnded normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0031 + * @tc.desc resultSet isEnded normal test + */ + it('testIsEnded0002', 0, async function (done) { + console.info(TAG + '************* testIsEnded0002 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(false).assertEqual(resultSet.isEnded) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsEnded0002 end *************'); + }) + + /** + * @tc.name resultSet isEnded normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0032 + * @tc.desc resultSet isEnded normal test + */ + it('testIsEnded0003', 0, async function (done) { + console.info(TAG + '************* testIsEnded0003 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + resultSet.goToRow(3) + expect(true).assertEqual(resultSet.isEnded) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsEnded0003 end *************'); + }) + + /** + * @tc.name resultSet isEnded normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0033 + * @tc.desc resultSet isEnded normal test + */ + it('testIsEnded0004', 0, async function (done) { + console.info(TAG + '************* testIsEnded0004 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + resultSet.goToRow(3) + expect(true).assertEqual(resultSet.isEnded) + expect(true).assertEqual(resultSet.isEnded) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testIsEnded0004 end *************'); + }) + + /** + * @tc.name resultSet rowCount normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0040 + * @tc.desc resultSet rowCount normal test + */ + it('testRowCount0001', 0, async function (done) { + console.info(TAG + '************* testRowCount0001 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(3).assertEqual(resultSet.rowCount) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testRowCount0001 end *************'); + }) + + /** + * @tc.name resultSet rowCount with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0041 + * @tc.desc resultSet rowCount with no result test + */ + it('testRowCount0002', 0, async function (done) { + console.info(TAG + '************* testRowCount0002 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + try { + expect(-1).assertEqual(resultSet.rowCount) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testRowCount0002 end *************'); + }) + + /** + * @tc.name resultSet rowCount test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0042 + * @tc.desc resultSet rowCount test + */ + it('testRowCount0003', 0, async function (done) { + console.info(TAG + '************* testRowCount0003 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('data1', 'hello'); + let resultSet = await rdbStore.query(predicates) + try { + expect(1).assertEqual(resultSet.rowCount) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testRowCount0003 end *************'); + }) + + /** + * @tc.name resultSet rowCount test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0043 + * @tc.desc resultSet rowCount test + */ + it('testRowCount0004', 0, async function (done) { + console.info(TAG + '************* testRowCount0004 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('data1', 'hello'); + predicates.equalTo('data2', 3); + let resultSet = await rdbStore.query(predicates) + try { + expect(0).assertEqual(resultSet.rowCount) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testRowCount0003 end *************'); + }) + + /** + * @tc.name resultSet getLong test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0050 + * @tc.desc resultSet getLong test + */ + it('testGetLong0001', 0, async function (done) { + console.info(TAG + '************* testGetLong0001 start *************'); + let predicates = await new data_Rdb.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(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGetLong0001 end *************'); + }) + + /** + * @tc.name resultSet getLong test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0051 + * @tc.desc resultSet getLong test + */ + it('testGetLong0002', 0, async function (done) { + console.info(TAG + '************* testGetLong0002 start *************'); + let predicates = await new data_Rdb.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(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGetLong0002 end *************'); + }) + + /** + * @tc.name resultSet getLong test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0052 + * @tc.desc resultSet getLong test + */ + it('testGetLong0003', 0, async function (done) { + console.info(TAG + '************* testGetLong0003 start *************'); + let predicates = await new data_Rdb.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(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGetLong0003 end *************'); + }) + + /** + * @tc.name resultSet getString test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0060 + * @tc.desc resultSet getString test + */ + it('testGetString0001', 0, async function (done) { + console.info(TAG + '************* testGetString0001 start *************'); + let predicates = await new data_Rdb.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 = null + done(); + console.info(TAG + '************* testGetString0001 end *************'); + }) + + /** + * @tc.name resultSet getString test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0061 + * @tc.desc resultSet getString test + */ + it('testGetString0002', 0, async function (done) { + console.info(TAG + '************* testGetString0002 start *************'); + let predicates = await new data_Rdb.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 = null + done(); + console.info(TAG + '************* testGetString0002 end *************'); + }) + + /** + * @tc.name resultSet getString test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0062 + * @tc.desc resultSet getString test + */ + it('testGetString0003', 0, async function (done) { + console.info(TAG + '************* testGetString0003 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + const data3 = resultSet.getString(resultSet.getColumnIndex('data3')) + expect('2.5').assertEqual(data3); + } + resultSet = null + done(); + console.info(TAG + '************* testGetString0003 end *************'); + }) + + /** + * @tc.name resultSet getString test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0063 + * @tc.desc resultSet getString test + */ + it('testGetString0004', 0, async function (done) { + console.info(TAG + '************* testGetString0004 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + 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 = null + done(); + console.info(TAG + '************* testGetString0004 end *************'); + }) + + /** + * @tc.name resultSet isClosed test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0070 + * @tc.desc resultSet isClosed test + */ + it('testIsClosed0001', 0, async function (done) { + console.info(TAG + '************* testIsClosed0001 start *************'); + let predicates = await new data_Rdb.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 + '************* testIsClosed0001 end *************'); + }) + + /** + * @tc.name resultSet isClosed with not close test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0071 + * @tc.desc resultSet isClosed with not close test + */ + it('testIsClosed0002', 0, async function (done) { + console.info(TAG + '************* testIsClosed0002 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + expect(false).assertEqual(resultSet.isClosed) + + resultSet = null + done(); + console.info(TAG + '************* testIsClosed0002 end *************'); + }) + + /** + * @tc.name resultSet isClosed with not close test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0072 + * @tc.desc resultSet isClosed with not close test + */ + it('testIsClosed0003', 0, async function (done) { + console.info(TAG + '************* testIsClosed0003 start *************'); + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + expect(false).assertEqual(resultSet.isClosed) + + resultSet = null + done(); + console.info(TAG + '************* testIsClosed0003 end *************'); + }) + + /** + * @tc.name resultSet columnCount test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0080 + * @tc.desc resultSet columnCount test + */ + it('testColumnCount0001', 0, async function (done) { + console.info(TAG + '************* testColumnCount0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + expect(5).assertEqual(resultSet.columnCount); + resultSet = null; + done(); + console.info(TAG + '************* testColumnCount0001 end *************'); + } + }) + + /** + * @tc.name resultSet columnCount test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0081 + * @tc.desc resultSet columnCount test + */ + it('testColumnCount0002', 0, async function (done) { + console.info(TAG + '************* testColumnCount0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.columnCount); + resultSet = null; + done(); + console.info(TAG + '************* testColumnCount0002 end *************'); + } + }) + + /** + * @tc.name resultSet rowIndex test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0090 + * @tc.desc resultSet rowIndex test + */ + it('testRowIndex0001', 0, async function (done) { + console.info(TAG + '************* testRowIndex0001 *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(0).assertEqual(resultSet.rowIndex) + } + + resultSet = null; + done(); + console.info(TAG + '************* testRowIndex0001 end *************'); + } + }) + + /** + * @tc.name resultSet rowIndex at last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0091 + * @tc.desc resultSet rowIndex at last row test + */ + it('testRowIndex0002', 0, async function (done) { + console.info(TAG + '************* testRowIndex0002 *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(2).assertEqual(resultSet.rowIndex) + } + + resultSet = null; + done(); + console.info(TAG + '************* testRowIndex0002 end *************'); + } + }) + + /** + * @tc.name resultSet goToFirstRow normal test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0100 + * @tc.desc resultSet goToFirstRow normal test + */ + it('testGoToFirstRow0001', 0, async function (done) { + console.info(TAG + '************* testGoToFirstRow0001 start *************'); + + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(true).assertEqual(resultSet.goToFirstRow()) + resultSet.close(); + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGoToFirstRow0001 end *************'); + }) + + /** + * @tc.name resultSet goToFirstRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0101 + * @tc.desc resultSet goToFirstRow with no result test + */ + it('testGoToFirstRow0002', 0, async function (done) { + console.info(TAG + '************* testGoToFirstRow0002 start *************'); + + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + try { + expect(false).assertEqual(resultSet.goToFirstRow()) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGoToFirstRow0002 end *************'); + }) + + /** + * @tc.name resultSet goToFirstRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0102 + * @tc.desc resultSet goToFirstRow test + */ + it('testGoToFirstRow0003', 0, async function (done) { + console.info(TAG + '************* testGoToFirstRow0003 start *************'); + + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToFirstRow()) + } catch (e) { + expect(null).assertFail(); + } + resultSet = null + done(); + console.info(TAG + '************* testGoToFirstRow0003 end *************'); + }) + + /** + * @tc.name resultSet goToLastRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0110 + * @tc.desc resultSet goToFirstRow test + */ + it('testGoToLastRow0001', 0, async function (done) { + console.info(TAG + '************* testGoToLastRow0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToLastRow0001 end *************'); + } + }) + + /** + * @tc.name resultSet goToLastRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0111 + * @tc.desc resultSet goToLastRow with no result test + */ + it('testGoToLastRow0002', 0, async function (done) { + console.info(TAG + '************* testGoToLastRow0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + expect(false).assertEqual(resultSet.goToLastRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToLastRow0002 end *************'); + } + }) + + /** + * @tc.name resultSet goToLastRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0112 + * @tc.desc resultSet goToLastRow test + */ + it('testGoToLastRow0003', 0, async function (done) { + console.info(TAG + '************* testGoToLastRow0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(true).assertEqual(resultSet.goToPreviousRow()) + expect(true).assertEqual(resultSet.goToLastRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToLastRow0003 end *************'); + } + }) + + /** + * @tc.name resultSet goToNextRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0120 + * @tc.desc resultSet goToNextRow test + */ + it('testGoToNextRow0001', 0, async function (done) { + console.info(TAG + '************* testGoToNextRow0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToNextRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToNextRow0001 end *************'); + } + }) + + /** + * @tc.name resultSet goToNextRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0121 + * @tc.desc resultSet goToNextRow with no result test + */ + it('testGoToNextRow0002', 0, async function (done) { + console.info(TAG + '************* testGoToNextRow0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + expect(false).assertEqual(resultSet.goToNextRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToNextRow0002 end *************'); + } + }) + + /** + * @tc.name resultSet goToNextRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0122 + * @tc.desc resultSet goToNextRow test + */ + it('testGoToNextRow0003', 0, async function (done) { + console.info(TAG + '************* testGoToNextRow0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToPreviousRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToNextRow0003 end *************'); + } + }) + + /** + * @tc.name resultSet goToNextRow after last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0123 + * @tc.desc resultSet goToNextRow after last row test + */ + it('testGoToNextRow0004', 0, async function (done) { + console.info(TAG + '************* testGoToNextRow0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(false).assertEqual(resultSet.goToNextRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToNextRow0004 end *************'); + } + }) + + /** + * @tc.name resultSet goToPreviousRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0130 + * @tc.desc resultSet goToPreviousRow test + */ + it('testGoToPreviousRow0001', 0, async function (done) { + console.info(TAG + '************* testGoToPreviousRow0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(false).assertEqual(resultSet.goToPreviousRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToPreviousRow0001 end *************'); + } + }) + + /** + * @tc.name resultSet goToPreviousRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0131 + * @tc.desc resultSet goToPreviousRow with no result test + */ + it('testGoToPreviousRow0002', 0, async function (done) { + console.info(TAG + '************* testGoToPreviousRow0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + expect(false).assertEqual(resultSet.goToPreviousRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToPreviousRow0002 end *************'); + } + }) + + /** + * @tc.name resultSet goToPreviousRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0132 + * @tc.desc resultSet goToPreviousRow test + */ + it('testGoToPreviousRow0003', 0, async function (done) { + console.info(TAG + '************* testGoToPreviousRow0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToPreviousRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToPreviousRow0003 end *************'); + } + }) + + /** + * @tc.name resultSet goToPreviousRow after last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0133 + * @tc.desc resultSet goToPreviousRow after last row test + */ + it('testGoToPreviousRow0004', 0, async function (done) { + console.info(TAG + '************* testGoToPreviousRow0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(true).assertEqual(resultSet.goToPreviousRow()) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToPreviousRow0004 end *************'); + } + }) + + /** + * @tc.name resultSet goTo test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0140 + * @tc.desc resultSet goTo test + */ + it('testGoTo0001', 0, async function (done) { + console.info(TAG + '************* testGoTo0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + resultSet.goTo(1) + expect(1).assertEqual(resultSet.rowIndex) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoTo0001 end *************'); + } + }) + + /** + * @tc.name resultSet goTo with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0141 + * @tc.desc resultSet goTo with no result test + */ + it('testGoTo0002', 0, async function (done) { + console.info(TAG + '************* testGoTo0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(1) + expect(-1).assertEqual(resultSet.rowIndex) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoTo0002 end *************'); + } + }) + + /** + * @tc.name resultSet goTo test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0142 + * @tc.desc resultSet goTo test + */ + it('testGoTo0003', 0, async function (done) { + console.info(TAG + '************* testGoTo0003 start *************'); + { + let predicates = await new data_Rdb.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 = null; + done(); + console.info(TAG + '************* testGoTo0003 end *************'); + } + }) + + /** + * @tc.name resultSet goTo after last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0143 + * @tc.desc resultSet goTo after last row test + */ + it('testGoTo0004', 0, async function (done) { + console.info(TAG + '************* testGoTo0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + resultSet.goTo(5) + expect(3).assertEqual(resultSet.rowIndex) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoTo0004 end *************'); + } + }) + + /** + * @tc.name resultSet goToRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0150 + * @tc.desc resultSet goToRow test + */ + it('testGoToRow0001', 0, async function (done) { + console.info(TAG + '************* testGoToRow0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + resultSet.goToRow(1) + expect(1).assertEqual(resultSet.rowIndex) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToRow0001 end *************'); + } + }) + + /** + * @tc.name resultSet goToRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0151 + * @tc.desc resultSet goToRow with no result test + */ + it('testGoToRow0002', 0, async function (done) { + console.info(TAG + '************* testGoToRow0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + resultSet.goToRow(1) + expect(-1).assertEqual(resultSet.rowIndex) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToRow0002 end *************'); + } + }) + + /** + * @tc.name resultSet goToRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0152 + * @tc.desc resultSet goToRow test + */ + it('testGoToRow0003', 0, async function (done) { + console.info(TAG + '************* testGoToRow0003 start *************'); + { + let predicates = await new data_Rdb.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 = null; + done(); + console.info(TAG + '************* testGoToRow0003 end *************'); + } + }) + + /** + * @tc.name resultSet goToRow after last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0153 + * @tc.desc resultSet goToRow after last row test + */ + it('testGoToRow0004', 0, async function (done) { + console.info(TAG + '************* testGoToRow0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + resultSet.goToRow(5) + expect(3).assertEqual(resultSet.rowIndex) + } + resultSet = null; + done(); + console.info(TAG + '************* testGoToRow0004 end *************'); + } + }) + + /** + * @tc.name resultSet isAtFirstRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0160 + * @tc.desc resultSet isAtFirstRow test + */ + it('testIsAtFirstRow0001', 0, async function (done) { + console.info(TAG + '************* testIsAtFirstRow0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.isAtFirstRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtFirstRow0001 end *************'); + } + }) + + /** + * @tc.name resultSet isAtFirstRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0161 + * @tc.desc resultSet isAtFirstRow with no result test + */ + it('testIsAtFirstRow0002', 0, async function (done) { + console.info(TAG + '************* testIsAtFirstRow0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + expect(false).assertEqual(resultSet.isAtFirstRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtFirstRow0002 end *************'); + } + }) + + /** + * @tc.name resultSet isAtFirstRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0162 + * @tc.desc resultSet isAtFirstRow test + */ + it('testIsAtFirstRow0003', 0, async function (done) { + console.info(TAG + '************* testIsAtFirstRow0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(false).assertEqual(resultSet.isAtFirstRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtFirstRow0003 end *************'); + } + }) + + /** + * @tc.name resultSet isAtFirstRow after last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0163 + * @tc.desc resultSet isAtFirstRow after last row test + */ + it('testIsAtFirstRow0004', 0, async function (done) { + console.info(TAG + '************* testIsAtFirstRow0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(false).assertEqual(resultSet.isAtFirstRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtFirstRow0004 end *************'); + } + }) + + /** + * @tc.name resultSet isAtFirstRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0165 + * @tc.descresultSet isAtFirstRow test + */ + it('testIsAtFirstRow0005', 0, async function (done) { + console.info(TAG + '************* testIsAtFirstRow0005 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(1) + resultSet.goTo(0) + expect(true).assertEqual(resultSet.isAtFirstRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtFirstRow0005 end *************'); + } + }) + + /** + * @tc.name resultSet isAtFirstRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0166 + * @tc.descresultSet isAtFirstRow test + */ + it('testIsAtFirstRow0006', 0, async function (done) { + console.info(TAG + '************* testIsAtFirstRow0006 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(1) + expect(true).assertEqual(resultSet.isAtFirstRow) + expect(true).assertEqual(resultSet.isAtFirstRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtFirstRow0006 end *************'); + } + }) + + /** + * @tc.name resultSet isAtLastRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0170 + * @tc.desc resultSet isAtLastRow test + */ + it('testIsAtLastRow0001', 0, async function (done) { + console.info(TAG + '************* testIsAtLastRow0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(false).assertEqual(resultSet.isAtLastRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtLastRow0001 end *************'); + } + }) + + /** + * @tc.name resultSet isAtLastRow with no result test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0171 + * @tc.desc resultSet isAtLastRow with no result test + */ + it('testIsAtLastRow0002', 0, async function (done) { + console.info(TAG + '************* testIsAtLastRow0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + { + expect(false).assertEqual(resultSet.isAtLastRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtLastRow0002 end *************'); + } + }) + + /** + * @tc.name resultSet isAtLastRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0172 + * @tc.desc resultSet isAtLastRow test + */ + it('testIsAtLastRow0003', 0, async function (done) { + console.info(TAG + '************* testIsAtLastRow0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(false).assertEqual(resultSet.isAtLastRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtLastRow0003 end *************'); + } + }) + + /** + * @tc.name resultSet isAtLastRow after last row test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0173 + * @tc.desc resultSet isAtLastRow after last row test + */ + it('testIsAtLastRow0004', 0, async function (done) { + console.info(TAG + '************* testIsAtLastRow0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToLastRow()) + expect(true).assertEqual(resultSet.isAtLastRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtLastRow0004 end *************'); + } + }) + + /** + * @tc.name resultSet isAtLastRow test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0174 + * @tc.desc resultSet isAtLastRow test + */ + it('testIsAtLastRow0005', 0, async function (done) { + console.info(TAG + '************* testIsAtLastRow0005 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goToRow(2) + expect(true).assertEqual(resultSet.isAtLastRow) + expect(true).assertEqual(resultSet.isAtLastRow) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsAtLastRow0005 end *************'); + } + }) + + /** + * @tc.name resultSet getDouble test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0180 + * @tc.desc resultSet getDouble test + */ + it('testGetDouble0001', 0, async function (done) { + console.info(TAG + '************* testGetDouble0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(1) + const data3 = resultSet.getDouble(resultSet.getColumnIndex('data3')) + expect(1.0).assertEqual(data3) + } + resultSet = null; + done(); + console.info(TAG + '************* testGetDouble0001 end *************'); + } + }) + + /** + * @tc.name resultSet getDouble test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0181 + * @tc.desc resultSet getDouble test + */ + it('testGetDouble0002', 0, async function (done) { + console.info(TAG + '************* testGetDouble0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(2) + const data3 = resultSet.getDouble(resultSet.getColumnIndex('data3')) + expect(2.5).assertEqual(data3) + } + resultSet = null; + done(); + console.info(TAG + '************* testGetDouble0002 end *************'); + } + }) + + /** + * @tc.name resultSet getDouble test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0182 + * @tc.desc resultSet getDouble test + */ + it('testGetDouble0003', 0, async function (done) { + console.info(TAG + '************* testGetDouble0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(3) + const data3 = resultSet.getDouble(resultSet.getColumnIndex('data3')) + expect(1.8).assertEqual(data3) + } + resultSet = null; + done(); + console.info(TAG + '************* testGetDouble0003 end *************'); + } + }) + + /** + * @tc.name resultSet getDouble test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0183 + * @tc.desc resultSet getDouble test + */ + it('testGetDouble0004', 0, async function (done) { + console.info(TAG + '************* testGetDouble0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goTo(1) + const data2 = resultSet.getDouble(resultSet.getColumnIndex('data2')) + expect(10).assertEqual(data2) + } + resultSet = null; + done(); + console.info(TAG + '************* testGetDouble0004 end *************'); + } + }) + + /** + * @tc.name resultSet isColumnNull test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0190 + * @tc.desc resultSet isColumnNull test + */ + it('testIsColumnNull0001', 0, async function (done) { + console.info(TAG + '************* testIsColumnNull0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + const isColumnNull1 = resultSet.isColumnNull(resultSet.getColumnIndex('data1')) + expect(false).assertEqual(isColumnNull1) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsColumnNull0001 end *************'); + } + }) + + /** + * @tc.name resultSet isColumnNull test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0191 + * @tc.desc resultSet isColumnNull test + */ + it('testIsColumnNull0002', 0, async function (done) { + console.info(TAG + '************* testIsColumnNull0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToNextRow()) + const isColumnNull4 = resultSet.isColumnNull(resultSet.getColumnIndex('data4')) + expect(true).assertEqual(isColumnNull4) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsColumnNull0002 end *************'); + } + }) + + /** + * @tc.name resultSet isColumnNull test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0192 + * @tc.desc resultSet isColumnNull test + */ + it('testIsColumnNull0003', 0, async function (done) { + console.info(TAG + '************* testIsColumnNull0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + resultSet.goToRow(5) + try{ + expect(false).assertEqual(resultSet.isColumnNull(2)) + }catch(e){ + expect(e.code).assertEqual("14800013") + } + resultSet = null; + done(); + console.info(TAG + '************* testIsColumnNull0003 end *************'); + } + }) + /** + * @tc.name resultSet isColumnNull test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0193 + * @tc.desc resultSet isColumnNull test + */ + it('testIsColumnNull0004', 0, async function (done) { + console.info(TAG + '************* testIsColumnNull0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + { + resultSet.goToRow(2) + expect(false).assertEqual(resultSet.isColumnNull(1)) + } + resultSet = null; + done(); + console.info(TAG + '************* testIsColumnNull0004 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnIndex test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0200 + * @tc.desc resultSet getColumnIndex test + */ + it('testGetColumnIndex0001', 0, async function (done) { + console.info(TAG + '************* testGetColumnIndex0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + expect(true).assertEqual(resultSet.goToFirstRow()) + expect(1).assertEqual(resultSet.getColumnIndex('data1')) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnIndex0001 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnIndex test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0201 + * @tc.desc resultSet getColumnIndex test + */ + it('testGetColumnIndex0002', 0, async function (done) { + console.info(TAG + '************* testGetColumnIndex0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + expect(-1).assertEqual(resultSet.getColumnIndex('data1')) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnIndex0002 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnIndex test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0202 + * @tc.desc resultSet getColumnIndex test + */ + it('testGetColumnIndex0003', 0, async function (done) { + console.info(TAG + '************* testGetColumnIndex0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + expect(-1).assertEqual(resultSet.getColumnIndex('dataX')) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnIndex0003 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnIndex test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0203 + * @tc.desc resultSet getColumnIndex test + */ + it('testGetColumnIndex0004', 0, async function (done) { + console.info(TAG + '************* testGetColumnIndex0004 start *************'); + let errInfo = undefined; + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + try{ + let resultSetresult = resultSet.getColumnIndex('') + expect(-1).assertEqual(resultSetresult) + }catch(err){ + errInfo = err + } + expect(errInfo.code).assertEqual("401") + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnIndex0004 end *************'); + + }) + + /** + * @tc.name resultSet getColumnName test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0210 + * @tc.desc resultSet getColumnName test + */ + it('testGetColumnName0001', 0, async function (done) { + console.info(TAG + '************* testGetColumnIndex0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + + expect('data1').assertEqual(resultSet.getColumnName(1)) + expect('data4').assertEqual(resultSet.getColumnName(4)) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnName0001 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnName test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0211 + * @tc.desc resultSet getColumnName test + */ + it('testGetColumnName0002', 0, async function (done) { + console.info(TAG + '************* testGetColumnName0002 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + + expect('').assertEqual(resultSet.getColumnName(1)) + expect('').assertEqual(resultSet.getColumnName(4)) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnName0002 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnName test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0212 + * @tc.desc resultSet getColumnName test + */ + it('testGetColumnName0003', 0, async function (done) { + console.info(TAG + '************* testGetColumnName0003 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + + expect('').assertEqual(resultSet.getColumnName(10)) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnName0003 end *************'); + } + }) + + /** + * @tc.name resultSet getColumnName test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0213 + * @tc.desc resultSet getColumnName test + */ + it('testGetColumnName0004', 0, async function (done) { + console.info(TAG + '************* testGetColumnName0004 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + predicates.equalTo('name', 'wangwu'); + let resultSet = await rdbStore.query(predicates) + + expect('').assertEqual(resultSet.getColumnName(10)) + + resultSet = null; + done(); + console.info(TAG + '************* testGetColumnName0004 end *************'); + } + }) + + /** + * @tc.name resultSet close test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0220 + * @tc.desc resultSet close test + */ + it('testClose0001', 0, async function (done) { + console.info(TAG + '************* testClose0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + resultSet.goToRow(1) + resultSet.close() + expect(true).assertEqual(resultSet.isClosed) + + resultSet = null; + done(); + console.info(TAG + '************* testClose0001 end *************'); + } + }) + + /** + * @tc.name resultSet close test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0221 + * @tc.desc resultSet close test + */ + it('testClose0002', 0, async function (done) { + console.info(TAG + '************* testClose0002 start *************'); + { + let predicates = await new data_Rdb.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 + '************* testClose0002 end *************'); + } + }) + + /** + * @tc.name resultSet columnNames test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0240 + * @tc.desc resultSet columnNames test + */ + it('testcolumnNames0001', 0, async function (done) { + console.info(TAG + '************* testcolumnNames0001 start *************'); + { + let predicates = await new data_Rdb.RdbPredicates('test') + let resultSet = await rdbStore.query(predicates) + if (COLOUNM_NAMES == resultSet.columnNames){ + expect(1).assertEqual(0); + }else{ + expect(0).assertEqual(0); + } + resultSet = null; + done(); + console.info(TAG + '************* testcolumnNames0001 end *************'); + } + }) + + /** + * @tc.name big resultSet data test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_ResultSet_0250 + * @tc.desc big resultSet data test + */ + it('testBigData0001', 0, async function (done) { + console.log(TAG + "************* testBigData0001 start *************"); + { + await createBigData(500); + let resultSet = await rdbStore.querySql("SELECT * FROM test"); + let count = resultSet.rowCount; + expect(500).assertEqual(count); + + resultSet.goToFirstRow(); + let i = 0; + while (resultSet.isEnded == false) { + expect("test" + i++).assertEqual(resultSet.getString(1)) + resultSet.goToNextRow(); + } + + resultSet.close() + expect(true).assertEqual(resultSet.isClosed) + resultSet = null; + done(); + console.log(TAG + "************* testBigData0001 end *************"); + } + }) + + console.info(TAG + '*************Unit Test End*************'); +}) +} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..fe98c636c4eef892975f4492431cb90ade072aad --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js @@ -0,0 +1,442 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility'; +var context = ability_featureAbility.getContext(); + +const TAG = "[RelationalStore_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: data_Rdb.SecurityLevel.S1 +} + +var rdbStore = undefined; + +export default function relationalStoreTransactionTest() { +describe('relationalStoreTransactionTest', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await rdbStore.executeSql("DELETE FROM test"); + rdbStore = null + await data_Rdb.deleteRdbStore(context, "rdbstoreTransactionTest.db"); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name RelationalStore transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0001 + * @tc.desc RelationalStore transaction insert & commit, the result comes out is 3 items; + */ + it('testRdbTransactionInsert0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount) + expect(1).assertEqual(resultSet.rowCount) + resultSet.close() +// resultSet == null; + } catch (e) { + console.info(TAG + e); + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0001 failed"); + } + done() + console.info(TAG + "************* testRdbTransactionInsert0001 end *************"); + }) + + /** + * @tc.name RelationalStore transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0002 + * @tc.desc RelationalStore transaction insert & commit, the result comes out is 3 items; + */ + it('testRdbTransactionInsert0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(3).assertEqual(resultSet.rowCount) + resultSet.close() +// resultSet == null; + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0002 failed"); + } + done() + console.info(TAG + "************* testRdbTransactionInsert0002 end *************"); + }) + + + /** + * @tc.name RelationalStore transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0003 + * @tc.desc while using transaction to insert values, querying the db, + * the result comes out is 0; + */ + it('testRdbTransactionInsert0003', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionInsert0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() +// resultSet == null; + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0003 failed"); + } + done() + console.info(TAG + "************* testRdbTransactionInsert0003 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RollBack_0001 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionRollBack0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionRollBack0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + await rdbStore.insert("test", valueBucket) + + await rdbStore.commit() + } catch (e) { + await rdbStore.rollBack() + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount); + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() +// resultSet == null; + } + done() + console.info(TAG + "************* testRdbTransactionRollBack0001 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0001 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + let num = rdbStore.insert("test", valueBucket1) + num.then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0001 * insert result " + ret); + expect(2).assertEqual(ret) + }) + + await rdbStore.commit() + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + num = rdbStore.query(predicates) + num.then(async (ret) => { + expect(2).assertEqual(ret.rowCount) + ret.close() + }) + } catch (e) { + console.info(TAG + "testRdbTransactionMulti0001 fail ***** "); + } + done() + console.info(TAG + "************* testRdbTransactionMulti0001 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0002 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0002', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, function (err, ret){ + + }); + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + let num = rdbStore.insert("test", valueBucket1) + num.then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret); + expect(2).assertEqual(ret) + ret.close() + }) + + await rdbStore.rollBack() + + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + num = rdbStore.query(predicates) + num.then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret.rowCount); + expect(1).assertEqual(ret.rowCount) + ret.close() + }) + } catch (e) { + console.info(TAG + "testRdbTransactionMulti0002 fail ***** "); + } + done() + console.info(TAG + "************* testRdbTransactionMulti0002 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0003 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0003', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, function (err, ret){ + + }); + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + let num = await rdbStore.insert("test", valueBucket1) + + await rdbStore.rollBack() + + await rdbStore.insert("test", valueBucket) + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + num = rdbStore.query(predicates) + num.then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount); + expect(1).assertEqual(ret.rowCount) + ret.close() + }) + } catch (e) { + await rdbStore.rollBack() + console.info(TAG + "testRdbTransactionMulti0003 rollback ***** "); + } + done() + console.info(TAG + "************* testRdbTransactionMulti0003 end *************"); + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Transaction_Delete_0010 + * @tc.desc the classical transaction scenario, when we delete or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionDelete0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionDelete0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() +// resultSet == null; + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0003 failed"); + } + //删除 + { + let predicates = await new data_Rdb.RdbPredicates("test") + let deletePromise = rdbStore.delete(predicates) + deletePromise.then(async (ret) => { + expect(3).assertEqual(ret) + console.info(TAG + "Delete done: " + ret) + }).catch((err) => { + expect(null).assertFail() + }) + await deletePromise + } + done() + console.info(TAG + "************* testRdbTransactionDelete0001 end *************"); + }) + + console.info(TAG + "*************Unit Test End*************"); +})} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js new file mode 100644 index 0000000000000000000000000000000000000000..de43eb656b3ffdb537e8ad23c176b1deb389888b --- /dev/null +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js @@ -0,0 +1,270 @@ +/* + * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import data_Rdb from '@ohos.data.relationalStore'; +import ability_featureAbility from '@ohos.ability.featureAbility'; +var context = ability_featureAbility.getContext(); + +const TAG = "[RelationalStore_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: data_Rdb.SecurityLevel.S1 +} +var rdbStore = undefined; + +export default function relationalStoreUpdateTest() { +describe('relationalStoreUpdateTest', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await rdbStore.executeSql("DELETE FROM test"); + rdbStore = null + await data_Rdb.deleteRdbStore(context, "UpdataTest.db"); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Update_0010 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + //插入 + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret); + console.info(TAG + "update done: " + ret); + }).catch((err) => { + expect(null).assertFail(); + }) + await insertPromise + } + //更新 + { + var u8 = new Uint8Array([4, 5, 6]) + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 200.5, + "blobType": u8, + } + let predicates = await new data_Rdb.RdbPredicates("test") + predicates.equalTo("id", "1") + let updatePromise = rdbStore.update(valueBucket, predicates) + await updatePromise.then(async (ret) => { + expect(1).assertEqual(ret); + console.info(TAG + "update done: " + ret); + let resultSet = await rdbStore.query(predicates) + + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = await resultSet.getBlob(resultSet.getColumnIndex("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]); + console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(false).assertEqual(resultSet.goToNextRow()) + resultSet = null + }).catch((err) => { + console.info(TAG + "update error"); + expect(null).assertFail(); + }) + //await updatePromise + } + done(); + console.info(TAG + "************* testRdbStoreUpdate0001 end *************"); + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Update_0020 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0002 start *************"); + //更新 + { + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + try{ + let predicates = new data_Rdb.RdbPredicates("") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with null table name"); + }) + }catch(err){ + errInfo = err + } + { + const emptyBucket = {}; + let predicates = await new data_Rdb.RdbPredicates("test") + let updatePromise = rdbStore.update(emptyBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong valueBucket"); + }) + } + { + let predicates = await new data_Rdb.RdbPredicates("test") + await predicates.equalTo("aaa", "null") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong condition"); + }) + } + expect(errInfo.code).assertEqual("401") + } + done(); + console.info(TAG + "************* testRdbStoreUpdate0002 end *************"); + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Update_0030 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0003', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0003 start *************"); + //更新 + { + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + "wrongColumn": 100.5, + } + { + let predicates = new data_Rdb.RdbPredicates("wrongTable") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong table name"); + }) + //await updatePromise + } + { + let predicates = await new data_Rdb.RdbPredicates("test") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong column name"); + }) + //await updatePromise + } + } + done(); + console.info(TAG + "************* testRdbStoreUpdate0003 end *************"); + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Update_0040 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0004', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0004 start *************"); + //更新 + { + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + { + let predicates = await new data_Rdb.RdbPredicates("test") + await predicates.equalTo("aaa", "null") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong condition"); + }) + //await updatePromise + } + { + const emptyBucket = {}; + let predicates = await new data_Rdb.RdbPredicates("test") + await predicates.equalTo("name", "zhangsan") + await predicates.equalTo("age", 18) + await predicates.equalTo("null", 100.5) + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong condition"); + }) + } + } + done(); + console.info(TAG + "************* testRdbStoreUpdate0004 end *************"); + }) + console.info(TAG + "*************Unit Test End*************"); +}) + +}