diff --git a/distributeddatamgr/BUILD.gn b/distributeddatamgr/BUILD.gn old mode 100755 new mode 100644 index 076d6369f267ea23abf563534f452a5b24a8123e..13262e64259d525ae46649ec45f21e60517c8c17 --- a/distributeddatamgr/BUILD.gn +++ b/distributeddatamgr/BUILD.gn @@ -19,6 +19,7 @@ group("distributeddatamgr") { "appdatamgrjstest/hap:appdatamgr_js_test", "distributeddataObjectjstest/hap:distributeddataObject_js_test", "distributeddatamgrjstest/hap:distributeddatamgr_js_test", + "windowStage:windowStage", ] } else { deps = [ diff --git a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/DataShareJsunit.test.js b/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/DataShareJsunit.test.js deleted file mode 100644 index f99f9ea044c3388998b6dd62c4cc927434988953..0000000000000000000000000000000000000000 --- a/distributeddatamgr/appdatamgrjstest/hap/src/main/js/default/test/DataShareJsunit.test.js +++ /dev/null @@ -1,1081 +0,0 @@ -/* - * 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 'deccjsunit/index' -import dataShare from '@ohos.data.dataShare'; -import dataAbility from '@ohos.data.dataAbility'; - -const TAG = "[DATASHARE_JSKITS_TEST]" -const URI = ("datashare:///com.samples.datasharetest.DataShare"); -let dseWant = { - "bundleName": "com.examples.datasharetest.service", - "abilityName": "DataShareExtAbility", -} - -describe('dataShareTest', function () { - beforeAll(async function () { - console.info(TAG + 'beforeAll') - }) - - beforeEach(function () { - console.info(TAG + 'beforeEach') - }) - - afterEach(function () { - console.info(TAG + 'afterEach') - }) - - afterAll(async function () { - console.info(TAG + 'afterAll') - }) - - console.info(TAG + "*************Unit Test Begin*************"); - - function onChangeNotify() { - console.info("==========================>onChangeNotify=======================>"); - } - - /** - * @tc.name data share createDataShareHelper test - * @tc.number SUB_DDM_DataShare_JS_createDataShareHelper_0000 - * @tc.desc data share createDataShareHelper test - */ - it('createDataShareHelper_0000', 0, async function (done) { - console.info(TAG + ":createDataShareHelper_0000 start"); - try { - let helper = dataShare.createDataShareHelper(this.context, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":createDataShareHelper_0000 end"); - }) - - /** - * @tc.name data share createDataShareHelper test - * @tc.number SUB_DDM_DataShare_JS_createDataShareHelper_0010 - * @tc.desc data share createDataShareHelper test - */ - it('createDataShareHelper_0010', 0, async function (done) { - console.info(TAG + ":createDataShareHelper_0010 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":createDataShareHelper_0010 end"); - }) - - /** - * @tc.name data share createDataShareHelper test - * @tc.number SUB_DDM_DataShare_JS_createDataShareHelper_0011 - * @tc.desc data share createDataShareHelper test - */ - it('createDataShareHelper_0011', 0, async function (done) { - console.info(TAG + ":createDataShareHelper_0011 start"); - try { - let helper = dataShare.createDataShareHelper(this.context, null, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":createDataShareHelper_0011 end"); - }) - - /** - * @tc.name data share createDataShareHelper test - * @tc.number SUB_DDM_DataShare_JS_createDataShareHelper_0012 - * @tc.desc data share createDataShareHelper test - */ - it('createDataShareHelper_0012', 0, async function (done) { - console.info(TAG + ":createDataShareHelper_0012 start"); - try { - let helper = dataShare.createDataShareHelper(this.context, dseWant, null); - console.info(TAG + ":DataShareHelper helper:" + helper); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":createDataShareHelper_0012 end"); - }) - - /** - * @tc.name data share onEvent test - * @tc.number SUB_DDM_DataShare_JS_on_0020 - * @tc.desc data share onEvent test - */ - it('on_0020', 0, async function (done) { - console.info(TAG + ":on_0020 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.on( - "dataChange", - URI, - onChangeNotify - ) - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":on_0020 end"); - }) - - /** - * @tc.name data share onEvent test - * @tc.number SUB_DDM_DataShare_JS_on_0021 - * @tc.desc data share onEvent test - */ - it('on_0021', 0, async function (done) { - console.info(TAG + ":on_0021 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.on( - "dataChange", - null, - onChangeNotify - ) - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":on_0021 end"); - }) - - /** - * @tc.name data share offEvent test - * @tc.number SUB_DDM_DataShare_JS_off_0030 - * @tc.desc data share offEvent test - */ - it('off_0030', 0, async function (done) { - console.info(TAG + ":off_0030 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.off( - "dataChange", - URI, - ) - helper.off( - "dataChange", - URI, - onChangeNotify - ) - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":off_0030 end"); - }) - - /** - * @tc.name data share offEvent test - * @tc.number SUB_DDM_DataShare_JS_off_0031 - * @tc.desc data share offEvent test - */ - it('off_0031', 0, async function (done) { - console.info(TAG + ":off_0031 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.off( - "dataChange", - null, - onChangeNotify - ) - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":off_0031 end"); - }) - - /** - * @tc.name data share getType_callback test - * @tc.number SUB_DDM_DataShare_getType_0040 - * @tc.desc data share getType_callback test - */ - it('getType_callback_0040', 0, async function (done) { - console.info(TAG + ":getType_callback_0040 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.getType( - URI, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":getType_callback_0040 end"); - }) - - /** - * @tc.name data share getType_promise test - * @tc.number SUB_DDM_DataShare_JS_getType_promise_0041 - * @tc.desc data share getType_promise test - */ - it('getType_promise_0041', 0, async function (done) { - console.info(TAG + ":getType_promise_0041 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.getType( - URI - ).then((data) => { - console.info("==========================>getTypeCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":getType_promise_0041 end"); - }) - - /** - * @tc.name data share getFileType_callback test - * @tc.number SUB_DDM_DataShare_JS_getFileType_callback_0050 - * @tc.desc data share getFileType_callback test - */ - it('getFileType_callback_0050', 0, async function (done) { - console.info(TAG + ":getFileType_callback_0050 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.getFileTypes( - URI, - "image/*", - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":getFileType_callback_0050 end"); - }) - - /** - * @tc.name data share getFileType_promise test - * @tc.number SUB_DDM_DataShare_JS_getFileType_promise_0051 - * @tc.desc data share getFileType_promise test - */ - it('getFileType_promise_0051', 0, async function (done) { - console.info(TAG + ":getFileType_promise_0051 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.getFileTypes( - URI, - "image/*" - ).then((data) => { - console.info("==========================>getFileTypesCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":getFileType_promise_0051 end"); - }) - - /** - * @tc.name data share getFileType_callback test - * @tc.number SUB_DDM_DataShare_JS_getFileType_callback_0052 - * @tc.desc data share getFileType_callback test - */ - it('getFileType_callback_0052', 0, async function (done) { - console.info(TAG + ":getFileType_callback_0052 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.getFileTypes( - null, - "image/*", - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":getFileType_callback_0052 end"); - }) - - /** - * @tc.name data share normalizeUri_callback test - * @tc.number SUB_DDM_DataShare_JS_normalizeUri_0060 - * @tc.desc data share normalizeUri_callback test - */ - it('normalizeUri_callback_0060', 0, async function (done) { - console.info(TAG + ":normalizeUri_callback_0060 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.normalizeUri( - URI, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":normalizeUri_callback_0060 end"); - }) - - /** - * @tc.name data share normalizeUri_promise test - * @tc.number SUB_DDM_DataShare_JS_normalizeUri_promise_0061 - * @tc.desc data share normalizeUri_promise test - */ - it('normalizeUri_promise_0061', 0, async function (done) { - console.info(TAG + ":normalizeUri_promise_0061 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.normalizeUri( - URI, - ).then((data) => { - console.info("==========================>normalizeUriCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":normalizeUri_promise_0061 end"); - }) - - /** - * @tc.name data share normalizeUri_callback test - * @tc.number SUB_DDM_DataShare_JS_normalizeUri_0062 - * @tc.desc data share normalizeUri_callback test - */ - it('normalizeUri_callback_0062', 0, async function (done) { - console.info(TAG + ":normalizeUri_callback_0062 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.normalizeUri( - null, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":normalizeUri_callback_0062 end"); - }) - - /** - * @tc.name data share denormalizeUri_callback test - * @tc.number SUB_DDM_DataShare_JS_denormalizeUri_callback_0060 - * @tc.desc data share denormalizeUri_callback test - */ - it('denormalizeUri_callback_0070', 0, async function (done) { - console.info(TAG + ":denormalizeUri_callback_0070 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.denormalizeUri( - URI, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":denormalizeUri_callback_0070 end"); - }) - - /** - * @tc.name data share denormalizeUri_promise test - * @tc.number SUB_DDM_DataShare_JS_denormalizeUri_promise_0061 - * @tc.desc data share denormalizeUri_promise test - */ - it('denormalizeUri_promise_0071', 0, async function (done) { - console.info(TAG + ":denormalizeUri_promise_0071 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.denormalizeUri( - URI, - ).then((data) => { - console.info("==========================>denormalizeUriCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":denormalizeUri_promise_0071 end"); - }) - - /** - * @tc.name data share denormalizeUri_callback test - * @tc.number SUB_DDM_DataShare_JS_denormalizeUri_callback_0072 - * @tc.desc data share denormalizeUri_callback test - */ - it('denormalizeUri_callback_0072', 0, async function (done) { - console.info(TAG + ":denormalizeUri_callback_0072 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.denormalizeUri( - null, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":denormalizeUri_callback_0072 end"); - }) - - /** - * @tc.name data share notifyChange_callback test - * @tc.number SUB_DDM_DataShare_JS_notifyChange_callback_0080 - * @tc.desc data share notifyChange_callback test - */ - it('notifyChange_callback_0080', 0, async function (done) { - console.info(TAG + ":notifyChange_callback_0080 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.notifyChange( - URI, - (err) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":notifyChange_callback_0080 end"); - }) - - /** - * @tc.name data share notifyChange_promise test - * @tc.number SUB_DDM_DataShare_JS_notifyChange_promise_0081 - * @tc.desc data share notifyChange_promise test - */ - it('notifyChange_promise_0081', 0, async function (done) { - console.info(TAG + ":notifyChange_promise_0081 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.notifyChange( - URI, - ).then(() => { - console.info("==========================>notifyChangeCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":notifyChange_promise_0081 end"); - }) - - /** - * @tc.name data share notifyChange_callback test - * @tc.number SUB_DDM_DataShare_JS_notifyChange_callback_0082 - * @tc.desc data share notifyChange_callback test - */ - it('notifyChange_callback_0082', 0, async function (done) { - console.info(TAG + ":notifyChange_callback_0082 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - helper.notifyChange( - null, - (err) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":notifyChange_callback_0082 end"); - }) - - /** - * @tc.name data share insert_callback test - * @tc.number SUB_DDM_DataShare_JS_insert_callback_0090 - * @tc.desc data share insert_callback test - */ - it('insert_callback_0090', 0, async function (done) { - console.info(TAG + ":insert_callback_0090 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - const valueBucket = { - "name": "rose", - "age": 22, - "salary": 200.5, - "blobType": u8, - } - helper.insert( - URI, - valueBucket, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":insert_callback_0090 end"); - }) - - /** - * @tc.name data share insert_promise test - * @tc.number SUB_DDM_DataShare_JS_insert_promise_0091 - * @tc.desc data share insert_promise test - */ - it('insert_promise_0091', 0, async function (done) { - console.info(TAG + ":insert_promise_0081 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - const valueBucket = { - "name": "rose1", - "age": 221, - "salary": 20.5, - "blobType": u8, - } - helper.insert( - URI, - valueBucket - ).then((data) => { - console.info("==========================>insertCallback=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":insert_promise_0091 end"); - }) - - /** - * @tc.name data share insert_callback test - * @tc.number SUB_DDM_DataShare_JS_insert_callback_0092 - * @tc.desc data share insert_callback test - */ - it('insert_callback_0092', 0, async function (done) { - console.info(TAG + ":insert_callback_0092 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - const valueBucket = { - "name": "rose", - "age": 22, - "salary": 200.5, - "blobType": u8, - } - helper.insert( - null, - valueBucket, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":insert_callback_0092 end"); - }) - - /** - * @tc.name data share batchInsert_callback test - * @tc.number SUB_DDM_DataShare_JS_batchInsert_callback_0090 - * @tc.desc data share batchInsert_callback test - */ - it('batchInsert_callback_0100', 0, async function (done) { - console.info(TAG + ":batchInsert_callback_0100 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) - helper.batchInsert( - URI, - cars, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":batchInsert_callback_0100 end"); - }) - - /** - * @tc.name data share batchInsert_promise test - * @tc.number SUB_DDM_DataShare_JS_batchInsert_promise_0101 - * @tc.desc data share createDataShareHelper test - */ - it('batchInsert_promise_0101', 0, async function (done) { - console.info(TAG + ":batchInsert_promise_0101 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) - helper.batchInsert( - URI, - cars - ).then((data) => { - console.info("==========================>batchInsertCallback=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":batchInsert_promise_0101 end"); - }) - - /** - * @tc.name data share batchInsert_callback test - * @tc.number SUB_DDM_DataShare_JS_batchInsert_callback_0102 - * @tc.desc data share batchInsert_callback test - */ - it('batchInsert_callback_0102', 0, async function (done) { - console.info(TAG + ":batchInsert_callback_0102 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - var cars = new Array({"name": "roe11", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe12", "age": 21, "salary": 20.5, "blobType": u8,}, - {"name": "roe13", "age": 21, "salary": 20.5, "blobType": u8,}) - helper.batchInsert( - null, - cars, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":batchInsert_callback_0102 end"); - }) - - /** - * @tc.name data share delete_callback test - * @tc.number SUB_DDM_DataShare_JS_delete_callback_0110 - * @tc.desc data share delete_callback test - */ - it('delete_callback_0110', 0, async function (done) { - console.info(TAG + ":delete_callback_0110 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.delete( - URI, - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":delete_callback_0110 end"); - }) - - /** - * @tc.name data share delete_promise test - * @tc.number SUB_DDM_DataShare_JS_delete_promise_0111 - * @tc.desc data share delete_promise test - */ - it('delete_promise_0111', 0, async function (done) { - console.info(TAG + ":delete_promise_0111 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.delete( - URI, - da - ).then((data) => { - console.info("==========================>deleteCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":delete_promise_0111 end"); - }) - - /** - * @tc.name data share delete_callback test - * @tc.number SUB_DDM_DataShare_JS_delete_callback_0112 - * @tc.desc data share delete_callback test - */ - it('delete_callback_0112', 0, async function (done) { - console.info(TAG + ":delete_callback_0112 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.delete( - null, - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":delete_callback_0112 end"); - }) - - /** - * @tc.name data share delete_callback test - * @tc.number SUB_DDM_DataShare_JS_delete_callback_0113 - * @tc.desc data share delete_callback test - */ - it('delete_callback_0113', 0, async function (done) { - console.info(TAG + ":delete_callback_0113 start"); - try { - let helper = dataShare.createDataShareHelper(this.context, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.delete( - URI, - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":delete_callback_0113 end"); - }) - - /** - * @tc.name data share update_callback test - * @tc.number SUB_DDM_DataShare_JS_update_callback_0120 - * @tc.desc data share update_callback test - */ - it('update_callback_0120', 0, async function (done) { - console.info(TAG + ":update_callback_0120 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - const va = { - "name": "roe1", - "age": 21, - "salary": 20.5, - "blobType": u8, - } - let da = new dataAbility.DataAbilityPredicates() - helper.update( - URI, - va, - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":update_callback_0120 end"); - }) - - /** - * @tc.name data share update_promise test - * @tc.number SUB_DDM_DataShare_JS_update_promise_0121 - * @tc.desc data share update_promise test - */ - it('update_promise_0121', 0, async function (done) { - console.info(TAG + ":update_promise_0121 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - const va = { - "name": "roe1", - "age": 21, - "salary": 20.5, - "blobType": u8, - } - let da = new dataAbility.DataAbilityPredicates() - helper.update( - URI, - va, - da - ).then((data) => { - console.info("==========================>updateCallback=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":update_promise_0121 end"); - }) - - /** - * @tc.name data share update_callback test - * @tc.number SUB_DDM_DataShare_JS_update_callback_0122 - * @tc.desc data share update_callback test - */ - it('update_callback_0122', 0, async function (done) { - console.info(TAG + ":update_callback_0122 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - const va = { - "name": "roe1", - "age": 21, - "salary": 20.5, - "blobType": u8, - } - let da = new dataAbility.DataAbilityPredicates() - helper.update( - null, - va, - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(false).assertTrue(); - } catch (err) { - expect(true).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":update_callback_0122 end"); - }) - - /** - * @tc.name data share update_callback test - * @tc.number SUB_DDM_DataShare_JS_update_callback_0123 - * @tc.desc data share update_callback test - */ - it('update_callback_0123', 0, async function (done) { - console.info(TAG + ":update_callback_0123 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.update( - URI, - null, - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":update_callback_0123 end"); - }) - - /** - * @tc.name data share query_callback test - * @tc.number SUB_DDM_DataShare_JS_query_callback_0130 - * @tc.desc data share query_callback test - */ - it('query_callback_0130', 0, async function (done) { - console.info(TAG + ":query_callback_0130 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.query( - URI, - ["*"], - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":query_callback_0130 end"); - }) - - /** - * @tc.name data share query_promise test - * @tc.number SUB_DDM_DataShare_JS_query_promise_0131 - * @tc.desc data share query_promise test - */ - it('query_promise_0131', 0, async function (done) { - console.info(TAG + ":query_promise_0131 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.query( - URI, - ["*"], - da - ).then((data) => { - console.info("==========================>queryCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":query_promise_0131 end"); - }) - - /** - * @tc.name data share query_callback test - * @tc.number SUB_DDM_DataShare_JS_query_callback_0132 - * @tc.desc data share query_callback test - */ - it('query_callback_0132', 0, async function (done) { - console.info(TAG + ":query_callback_0132 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.query( - null, - ["*"], - da, - (err, data) => { - console.info("==========================>Called=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":query_callback_0130 end"); - }) - - /** - * @tc.name data share query_promise test - * @tc.number SUB_DDM_DataShare_JS_query_promise_0133 - * @tc.desc data share query_promise test - */ - it('query_promise_0133', 0, async function (done) { - console.info(TAG + ":query_promise_0133 start"); - try { - let helper = dataShare.createDataShareHelper(null, dseWant, URI); - console.info(TAG + ":DataShareHelper helper:" + helper); - let da = new dataAbility.DataAbilityPredicates() - helper.query( - URI, - null, - da - ).then((data) => { - console.info("==========================>queryCallback=======================>"); - }); - expect(true).assertTrue(); - } catch (err) { - expect(false).assertTrue(); - console.info(TAG + ":DataShareHelper catch err:" + err); - } - done(); - console.info(TAG + ":query_promise_0133 end"); - }) - - console.info(TAG + "*************Unit Test End*************"); -}) \ No newline at end of file diff --git a/distributeddatamgr/windowStage/BUILD.gn b/distributeddatamgr/windowStage/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2f42d4434f17ebdd6608095cd7bbdff37aeccaa9 --- /dev/null +++ b/distributeddatamgr/windowStage/BUILD.gn @@ -0,0 +1,24 @@ +# 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("//test/xts/tools/build/suite.gni") + +group("windowStage") { + testonly = true + if (is_standard_system) { + deps = [ + "dataShareRdbtest:ActsDataShareRdbTest", + "server/rdbService:ActsRdbServiceHap", + ] + } +} diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/app.json b/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..f6f30ff973163b335f7cde7eecb23bbaf4595388 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "app": { + "bundleName": "com.example.myapplication", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "debug": false, + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/element/string.json b/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..d71e5ead1ce20b4ac3384d18e6d104f1ea4d83b4 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "MyApplication" + } + ] +} diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/windowStage/dataShareRdbtest/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/BUILD.gn b/distributeddatamgr/windowStage/dataShareRdbtest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..271042a33ebe477b6f4907e1c65f70b1ca350fdf --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/BUILD.gn @@ -0,0 +1,41 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_js_hap_suite("ActsDataShareRdbTest") { + hap_profile = "entry/src/main/module.json" + js_build_mode = "debug" + deps = [ + ":dataShareRdb_js_assets", + ":dataShareRdb_resources", + ] + ets2abc = true + certificate_profile = "signature/openharmony_sx.p7b" + hap_name = "ActsDataShareRdbTest" +} + +ohos_app_scope("dataShareRdb_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("dataShareRdb_js_assets") { + source_dir = "entry/src/main/ets" +} + +ohos_resources("dataShareRdb_resources") { + sources = [ "entry/src/main/resources" ] + deps = [ ":dataShareRdb_app_profile" ] + hap_profile = "entry/src/main/module.json" +} diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/Test.json b/distributeddatamgr/windowStage/dataShareRdbtest/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..8244a2b1e9f4f1385d1edd889c672ec29169c5e8 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/Test.json @@ -0,0 +1,17 @@ +{ + "description": "Configuration for hjunit demo Tests", + "driver": { + "type": "JSUnitTest", + "test-timeout": "180000", + "package": "com.example.myapplication", + "shell-timeout": "600000" + }, + "kits": [{ + "test-file-name": [ + "ActsDataShareRdbTest.hap", + "ActsRdbServiceHap.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + }] +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..ab2682985f2ed3ade10aefeecb9501a67eb05fbc --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[Demo] MyAbilityStage onCreate") + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..e9cf4fd08b1983e61c91558121799596cec3370a --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,145 @@ +/* + * 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 Ability from '@ohos.application.Ability' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import dataShare from '@ohos.data.dataShare' +import rpc from "@ohos.rpc"; + +var seConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> seConnect onConnect called."); + console.log("[ttt] [DataShareTest] <> seConnect onConnect elementName = " + elementName); + console.log("[ttt] [DataShareTest] <> seConnect onConnect proxy = " + proxy); + let data = rpc.MessageParcel.create(); + let reply = rpc.MessageParcel.create(); + let option = new rpc.MessageOption(); + data.writeInterfaceToken("connect-test"); + data.writeInt(111); + + console.log("[ttt] [DataShareTest] <> seConnect onConnect sendRequest."); + proxy.sendRequest(1, data, reply, option) + .then(function (result) { + if (result.errCode === 0) { + // let msg = reply.readString(); + let msg = result.reply.readInt(); + console.log("[ttt] [DataShareTest] <> seConnect reply msg: " + msg); + } else { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest failed, errCode: " + result.errCode); + } + // callback没有返回值,默认返回undefined + }).catch(function (e) { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest got exception: " + e); + }).finally (async () => { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest ends, reclaim parcel"); + data.reclaim(); + reply.reclaim(); + }) + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> seConnect onDisconnect"); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> seConnect onFailed"); + } +}; + +let dseProxy = 0; +let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); + +var dseConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> dseConnect onConnect called."); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect elementName = " + elementName); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect proxy = " + proxy); + dseProxy = proxy; + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> dseConnect onDisconnect, elementName:" + elementName); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> dseConnect onFailed, code:" + code); + } +}; + +let seConnectionId = -1; +let dseConnectionId = -1; + +let seWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "ServiceExtAbility", +} + +let dseWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "DataShareExtAbility", +} + +export function onCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer on callback ****"); +} + +export function offCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer off callback ****"); +} + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + let context = this.context; + dseConnectionId = context.connectAbility(dseWant, dseConnect); + globalThis.connectDataShareExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> connectDataShareExtAbility begin"); + await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{ + globalThis.helper = data; + globalThis.testhelper = data; + console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.helper = " + globalThis.helper); + console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); + console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); + console.info("[ttt] [DataShareTest] <> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err)); + }); + dseConnectionId = await context.connectAbility(dseWant, dseConnect); + }) + windowStage.setUIContent(this.context, "pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[ttt] [DataShareTest] <> MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[ttt] [DataShareTest] <> MainAbility onBackground") + } +}; diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets new file mode 100644 index 0000000000000000000000000000000000000000..93ddbbe319d7325acc6bb3881ef35f0c5c94a98e --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareCombinationRdb.ets @@ -0,0 +1,677 @@ +/* + * 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 'hypium/index' +import dataShare from '@ohos.data.dataShare' +import * as pubfun from './DataSharePublicfunction_Promise' +import dataSharePredicates from '@ohos.data.dataSharePredicates' + +//CreateDataShareHelper +let uri = "datashare:///com.samples.datasharetest.DataShare"; + +//InsertValuesBucket +let InsertNumber = { "age": 1 }; +let BatchInsert = new Array( + { "age": 1 }, + { "name": "sun" }, + { "isStudent": true }, + { "Binary": new Uint8Array([1, 2, 3]) }); +let ErrBatchInsert = new Array( + { "age": 1 }, + { "age": true }, + { "name": "sun" }); +let Insert100 = new Array(); +for (let i = 0; i < 100; i++) { + Insert100.push({ "name": "sun", "age": i + 1 }); +} + +let InsertString = { "name": "sun" }; +let InsertLong = { "age": 1234 }; +let InsertDouble = { "phoneNumber": 1.0 }; +let InsertBlob = { "Binary": new Uint8Array([1, 2, 3]) }; + +//UpdateValuesBucket +let UpdateNumber = { "age": 11 }; +let Update100 = { "name": "suns", "age": 1 }; + +//Predicates +let PredicatesNumber = new dataSharePredicates.DataSharePredicates(); +PredicatesNumber.equalTo("age", 1); +let PredicatesAll = new dataSharePredicates.DataSharePredicates(); + +//getColumnIndex +const IndexNumber = "age"; +const IndexString = "name"; +const IndexUint8Array = "Binary"; + +//Return Expect +const ResultSetNumber = 11; +const ResultSetDouble = "phoneNumber"; +const ResultSetUpdate100 = "suns"; +const DataProcessResultZero = 0; +const DataProcessResultOne = 1; +const DataProcessResultTwo = 2; +const DataProcessResultThree = 3; +const DataProcessResultFour = 4; +const DataProcessResultOnehundred = 100; +const DataProcessResultString = "sun"; +const DataProcessResultLong = 1234; +const DataProcessResultBlob = new Uint8Array([1, 2, 3]); +const DataProcessResultDouble = 1.0; +const column = 1; + +let Column; + +function onChangeNotify() { + console.info("===>onChangeNotify===>"); +}; + +function notifyChangeCallback() { + console.info("===>notifyChangeCallback===>"); +}; + +export default function DataShareCombinationRdb() { + describe('DataShareCombinationRdb', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert Update Query Delete in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationRdb0101', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareCombinationRdb0101 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesNumber, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationRdb0101 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexNumber); + expect(JSON.stringify(ResultSetNumber)).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataShareCombinationRdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareCombinationRdb0101 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareCombinationRdb0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert Update Query Delete in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationRdb0102', 1, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultFour).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationRdb0102 batchInsert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesAll, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultFour).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationRdb0102 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToLastRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexNumber) + expect(JSON.stringify(ResultSetNumber)).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataShareCombinationRdb0102 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareCombinationRdb0102 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareCombinationRdb0102 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : On on + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationRdb0104', 1, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going On 1"); + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going On 2"); + } catch (err) { + console.info("DataShareCombinationRdb0104 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationRdb005 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Off off + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareCombinationRdb0105', 1, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going On 1"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going Off 1"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going Off 2"); + } catch (err) { + console.info("DataShareCombinationRdb0105 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareCombinationRdb0106 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert Update Query Delete in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('DataShareCombinationRdb0106', 2, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, Insert100).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + expect(DataProcessResultOnehundred).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationRdb0106 batchInsert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesAll, Update100).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOnehundred).assertEqual(data); + }).catch((err) => { + console.info("DataShareCombinationRdb0106 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToLastRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexString); + expect(ResultSetUpdate100).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataShareCombinationRdb0106 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOnehundred).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareCombinationRdb0106 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareCombinationRdb0106 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareNotifyChangeRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : NotifyChange + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareNotifyChangeRdb0101', 1, async function (done) { + try { + let Count = 1; + globalThis.helper.on("dataChange", uri, function (data) { + if (Count < 4) { + console.info("TestDataShare notifyChange = " + data); + expect(true).assertEqual(data != null); + Count = Count + 1; + } else { + console.info("TestDataShare notifyChange = " + data); + expect(true).assertEqual(data != null); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare off"); + done(); + } + }) + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeRdb0101 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesAll, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeRdb0101 update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeRdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + globalThis.helper.notifyChange(uri, notifyChangeCallback); + }).catch((err) => { + console.info("DataShareNotifyChangeRdb0101 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + } catch (err) { + console.info("DataShareNotifyChangeRdb0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetRdb0101', 1, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb0101 batchInsert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + expect(true).assertEqual(globalThis.ResultSet.goToFirstRow()); + expect(true).assertEqual(globalThis.ResultSet.goToNextRow()); + expect(true).assertEqual(globalThis.ResultSet.goToLastRow()); + expect(true).assertEqual(globalThis.ResultSet.goToPreviousRow()); + expect(true).assertEqual(globalThis.ResultSet.goTo(column)); + expect(true).assertEqual(globalThis.ResultSet.goToRow(column)); + globalThis.ResultSet.close() + }).catch((err) => { + console.info("DataShareResultSetRdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0101 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb001 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetRdb0102', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + expect(false).assertEqual(globalThis.ResultSet.goToFirstRow()); + expect(false).assertEqual(globalThis.ResultSet.goToNextRow()); + expect(false).assertEqual(globalThis.ResultSet.goToLastRow()); + expect(false).assertEqual(globalThis.ResultSet.goToPreviousRow()); + expect(false).assertEqual(globalThis.ResultSet.goTo(column)); + expect(false).assertEqual(globalThis.ResultSet.goToRow(column)); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0102 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0102 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetRdb0103', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb0103 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexString); + expect(DataProcessResultString).assertEqual(globalThis.ResultSet.getString(Column)); + expect(DataProcessResultThree).assertEqual(globalThis.ResultSet.getDataType(Column)); + }).catch((err) => { + console.info("DataShareResultSetRdb0103 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0103 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0103 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetRdb0104', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertLong).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb0104 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexNumber); + expect(DataProcessResultLong).assertEqual(globalThis.ResultSet.getLong(Column)); + expect(DataProcessResultOne).assertEqual(globalThis.ResultSet.getDataType(Column)); + }).catch((err) => { + console.info("DataShareResultSetRdb0104 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0104 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0104 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + + it('DataShareResultSetRdb0105', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertDouble).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb005 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(ResultSetDouble) + expect(DataProcessResultDouble).assertEqual(globalThis.ResultSet.getDouble(Column)); + expect(DataProcessResultTwo).assertEqual(globalThis.ResultSet.getDataType(Column)); + }).catch((err) => { + console.info("DataShareResultSetRdb0105 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0105 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0105 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0106 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetRdb0106', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBlob).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb0106 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexUint8Array) + expect(JSON.stringify(DataProcessResultBlob)) + .assertEqual(JSON.stringify(globalThis.ResultSet.getBlob(Column))); + expect(DataProcessResultFour).assertEqual(globalThis.ResultSet.getDataType(Column)); + }).catch((err) => { + console.info("DataShareResultSetRdb0106 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0106 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0106 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0107 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataShareResultSetRdb0107', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb0107 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexNumber) + expect(DataProcessResultZero).assertEqual(globalThis.ResultSet.getDataType(Column)); + }).catch((err) => { + console.info("DataShareResultSetRdb0107 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0107 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0107 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareResultSetRdb0108 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports ResultSet + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 +*/ + it('DataShareResultSetRdb0108', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + }).catch((err) => { + console.info("DataShareResultSetRdb0108 insert err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(IndexNumber); + expect(DataProcessResultTwo).assertEqual(Column); + expect(IndexNumber).assertEqual(globalThis.ResultSet.getColumnName(Column)); + }).catch((err) => { + console.info("DataShareResultSetRdb0108 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareResultSetRdb0108 deleteall err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareResultSetRdb0108 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePredicatesRdb.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePredicatesRdb.ets new file mode 100644 index 0000000000000000000000000000000000000000..61396e9ea91b27e007fb1198cd084696f58328e3 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePredicatesRdb.ets @@ -0,0 +1,1102 @@ +/* + * 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 'hypium/index' +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import * as pubfun from './DataSharePublicfunction_Promise' + +//CreateDataShareHelper +let uri = "datashare:///com.samples.datasharetest.DataShare"; + +//InsertValuesBucket +let BatchInsert = new Array( + { "name": "LiSi", "age": 18 }, + { "name": "WangWu", "age": 20 }, + { "name": "ZhaoLiu"}); +let Insert = { "Name": "LiSi", "age": 18 }; + +//UpdateValuesBucket +let UpdateLiSi = { "name": "LiSii" }; +let UpdateWangWu = { "name": "WangWuu" }; +let UpdateZhaoLiu = { "name": "ZhaoLiuu" }; + +//Predicates +let EqualTo = new dataSharePredicates.DataSharePredicates(); +EqualTo.equalTo("age", 18); +let NotEqualTo = new dataSharePredicates.DataSharePredicates(); +NotEqualTo.notEqualTo("age", 18); +let GreaterThan = new dataSharePredicates.DataSharePredicates(); +GreaterThan.greaterThan("age", 18); +let LessThan = new dataSharePredicates.DataSharePredicates(); +LessThan.lessThan("age", 20); +let GreaterThanOrEqualTo = new dataSharePredicates.DataSharePredicates(); +GreaterThanOrEqualTo.greaterThanOrEqualTo("age", 20); +let LessThanOrEqualTo = new dataSharePredicates.DataSharePredicates(); +LessThanOrEqualTo.lessThanOrEqualTo("age", 18); +let IsNull = new dataSharePredicates.DataSharePredicates(); +IsNull.isNull("age"); +let IsNotNull = new dataSharePredicates.DataSharePredicates(); +IsNotNull.isNotNull("age"); +let In = new dataSharePredicates.DataSharePredicates(); +In.in("age", [18]); +let NotIn = new dataSharePredicates.DataSharePredicates(); +NotIn.notIn("age", [20]); +let Like = new dataSharePredicates.DataSharePredicates(); +Like.like("name", "%iS%"); +let And = new dataSharePredicates.DataSharePredicates(); +And.beginsWith("name", "Li").and().equalTo("age", 18); +let Or = new dataSharePredicates.DataSharePredicates(); +Or.beginsWith("name", "Li").or().equalTo("age", 18); +let OrderByAsc = new dataSharePredicates.DataSharePredicates(); +OrderByAsc.orderByAsc("age"); +let OrderByDesc = new dataSharePredicates.DataSharePredicates(); +OrderByDesc.orderByDesc("age"); +let Wrap = new dataSharePredicates.DataSharePredicates(); +Wrap.beginsWith("name", "Li").beginWrap().equalTo("age", 18).endWrap(); +let Contains = new dataSharePredicates.DataSharePredicates(); +Contains.contains("name", "LiSi"); +let BeginsWith = new dataSharePredicates.DataSharePredicates(); +BeginsWith.beginsWith("name", "Li"); +let EndsWith = new dataSharePredicates.DataSharePredicates(); +EndsWith.endsWith("name", "i"); +let Glob = new dataSharePredicates.DataSharePredicates(); +Glob.glob("name", "*i"); +let Between = new dataSharePredicates.DataSharePredicates(); +Between.between("age", 18, 19) +let NotBetween = new dataSharePredicates.DataSharePredicates(); +NotBetween.notBetween("age", 19, 20); +let Distinct = new dataSharePredicates.DataSharePredicates(); +Distinct.equalTo("age", 18).distinct("age"); +let GroupBy = new dataSharePredicates.DataSharePredicates(); +GroupBy.groupBy(["name"]); +let IndexedBy = new dataSharePredicates.DataSharePredicates(); +let PredicatesAll = new dataSharePredicates.DataSharePredicates(); + +//Return Expect +const DataProcessResultOne = 1; +const DataProcessResultTwo = 2; +const RetLiSii = "LiSii"; +const RetLiSi = "LiSi"; +const RetWangWuu = "WangWuu"; +const RetWangWu = "WangWu"; +const RetZhaoLiuu = "ZhaoLiuu"; +const RetZhaoLiu = "ZhaoLiu"; + +const Name = "name"; + +let Column; + +export default function DataSharePredicatesRdb() { + describe('DataSharePredicatesRdb', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + }) + + beforeEach(async function () { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + }) + }) + afterEach(async function () { + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going deleteall = " + data); + }) + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0101', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, EqualTo, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0101 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0101 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, EqualTo).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0101 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0102', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, NotEqualTo, UpdateWangWu).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0102 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, NotEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetWangWuu).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0102 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, NotEqualTo).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0102 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0102 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0103', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, GreaterThan, UpdateWangWu).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0103 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, GreaterThan, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetWangWuu).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0103 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, GreaterThan).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0103 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0103 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0104', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, LessThan, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0104 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, LessThan, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0104 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, LessThan).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0104 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0104 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0105', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, GreaterThanOrEqualTo, UpdateWangWu).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0105 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, GreaterThanOrEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetWangWuu).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0105 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, GreaterThanOrEqualTo).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0105 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0105 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0106 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0106', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, LessThanOrEqualTo, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0106 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, LessThanOrEqualTo, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0106 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, LessThanOrEqualTo).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0106 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb006 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0107 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0107', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, IsNull, UpdateZhaoLiu).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0107 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, IsNull, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToLastRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetZhaoLiuu).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0107 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, IsNull).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0107 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0107 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0108 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0108', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, IsNotNull, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultTwo).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0108 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, IsNotNull, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0108 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, IsNotNull).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultTwo).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0108 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0108 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0109 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0109', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, In, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0109 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, In, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0109 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, In).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0109 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0109 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0110 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0110', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, NotIn, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0110 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, NotIn, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0110 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, NotIn).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0110 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0110 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0111 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0111', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Like, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0111 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Like, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0111 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, Like).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0111 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0111 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0112 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0112', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, And, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0112 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, And, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0112 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, And).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0112 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0112 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0113 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0113', 0, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Or, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0113 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Or, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0113 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, Or).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0113 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0113 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0114 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0114', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, OrderByAsc, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetZhaoLiu).assertEqual(globalThis.ResultSet.getString(Column)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0114 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0114 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0115 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0115', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, OrderByDesc, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetWangWu).assertEqual(globalThis.ResultSet.getString(Column)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0115 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0115 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0116 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0116', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, Wrap, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSi).assertEqual(globalThis.ResultSet.getString(Column)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0116 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0116 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0117 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0117', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Contains, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0117 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Contains, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0117 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, Contains).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0117 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0117 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0118 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0118', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, BeginsWith, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0118 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, BeginsWith, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0118 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, BeginsWith).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0118 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0118 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0119 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0119', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, EndsWith, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0119 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, EndsWith, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0119 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, EndsWith).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0119 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0119 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0120 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0120', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Glob, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0120 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Glob, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0120 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, Glob).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0120 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0120 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0121 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0121', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, Between, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0121 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, Between, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0121 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, Between).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0121 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0121 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0122 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0122', 1, async function (done) { + try { + await pubfun.publicupdate(globalThis.helper, uri, NotBetween, UpdateLiSi).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataSharePredicatesRdb0122 Update err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicquery(globalThis.helper, uri, NotBetween, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSii).assertEqual(globalThis.ResultSet.getString(Column)); + }).catch((err) => { + console.info("DataSharePredicatesRdb0122 query err" + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, NotBetween).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0122 delete err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0122 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0123 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0123', 1, async function (done) { + try { + await pubfun.publicquery(globalThis.helper, uri, Distinct, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSi).assertEqual(globalThis.ResultSet.getString(Column)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0123 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0123 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0124 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0124', 1, async function (done) { + try { + pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + }) + await pubfun.publicquery(globalThis.helper, uri, GroupBy, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSi).assertEqual(globalThis.ResultSet.getString(Column)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0124 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0124 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataSharePredicatesRdb0125 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : DataShare Supports Predicates + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 1 + */ + it('DataSharePredicatesRdb0125', 1, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, Insert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + IndexedBy.indexedBy(data); + }) + await pubfun.publicquery(globalThis.helper, uri, IndexedBy, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToLastRow(); + Column = globalThis.ResultSet.getColumnIndex(Name); + expect(RetLiSi).assertEqual(globalThis.ResultSet.getString(Column)); + done(); + }).catch((err) => { + console.info("DataSharePredicatesRdb0125 query err" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataSharePredicatesRdb0125 fail" + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Callback.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Callback.ets new file mode 100644 index 0000000000000000000000000000000000000000..ff4ee98593fc5da7509d35826181877e3e1e8ea9 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Callback.ets @@ -0,0 +1,177 @@ +/* + * 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 file from '@system.file'; + +import { describe, it, expect } from 'hypium/index' +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import DataShareResultSet from '@ohos.data.DataShareResultSet' + +//insert公共方法 +function publicinsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.insert(uri, DataShareValuesBucket, (err, data) => { + console.info("TestDataShare publicinsert Callback=" + JSON.stringify(data)); + if (err) { + console.info("test insert err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//delete公共方法 +async function publicdelete(helper, uri, DataSharePredicates) { + return new Promise(function (resolve, reject) { + console.info("[ttt] [DataShareTest] <> 12345648564185645314"); + helper.delete(uri, DataSharePredicates, (err, data) => { + console.info("[ttt] [TestDataShare] publicdelete Callback=" + JSON.stringify(data)); + if (err) { + console.info("test delete err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//query公共方法 +function publicquery(helper, uri, DataSharePredicates, columns) { + return new Promise(function (resolve, reject) { + helper.query(uri, DataSharePredicates, columns, (err, data) => { + console.info("TestDataShare publicquery Callback=" + JSON.stringify(data)); + globalThis.ResultSet = data; + if (err) { + console.info("test query err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//update公共方法 +function publicupdate(helper, uri, DataSharePredicates, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.update(uri, DataSharePredicates, DataShareValuesBucket, (err, data) => { + console.info("TestDataShare publicupdate Callback=" + JSON.stringify(data)); + if (err) { + console.info("test update err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//batchInsert公共方法 +function publicbatchInsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.batchInsert(uri, DataShareValuesBucket, (err, data) => { + console.info("TestDataShare publicbatchInsert Callback=" + JSON.stringify(data)); + if (err) { + console.info("test batchInsert err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//getType公共方法 +function publicgetType(helper, uri) { + return new Promise(function (resolve, reject) { + helper.getType(uri, (err, data) => { + console.info("TestDataShare publicgetType Callback=" + JSON.stringify(data)); + if (err) { + console.info("test getType err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//getFileTypes公共方法 +function publicgetFileTypes(helper, uri, mimeTypeFilter) { + return new Promise(function (resolve, reject) { + helper.getFileTypes(uri, mimeTypeFilter, (err, data) => { + console.info("TestDataShare publicgetFileTypes Callback=" + JSON.stringify(data)); + if (err) { + console.info("test getFileTypes err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//normalizeUri公共方法 +function publicnormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.normalizeUri(uri, (err, data) => { + console.info("TestDataShare publicnormalizeUri Callback=" + JSON.stringify(data)); + if (err) { + console.info("test normalizeUri err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//denormalizeUri公共方法 +function publicdenormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.denormalizeUri(uri, (err, data) => { + console.info("TestDataShare publicdenormalizeUri Callback=" + JSON.stringify(data)); + if (err) { + console.info("test denormalizeUri err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +//denormalizeUri公共方法 +function publicopenFile(helper, uri, mode) { + return new Promise(function (resolve, reject) { + helper.denormalizeUri(uri, mode, (err, data) => { + console.info("TestDataShare publicopenFile Callback=" + JSON.stringify(data)); + if (err) { + console.info("test openFile err information: " + JSON.stringify(err)); + reject(err); + } else { + resolve(data); + } + }) + }) +} + +export { publicinsert, publicdelete, publicquery, publicupdate, publicbatchInsert, publicgetType, publicgetFileTypes, + publicnormalizeUri, publicdenormalizeUri, publicopenFile +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Promise.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Promise.ets new file mode 100644 index 0000000000000000000000000000000000000000..0cba17215286696b67508033f047a0509ffc5e85 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataSharePublicfunction_Promise.ets @@ -0,0 +1,154 @@ +/* + * 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, it, expect } from 'hypium/index' +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import DataShareResultSet from '@ohos.data.DataShareResultSet' + +//insert公共方法 +function publicinsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.insert(uri, DataShareValuesBucket).then((data) => { + console.info("TestDataShare publicinsert Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test insert err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//delete公共方法 +function publicdelete(helper, uri, DataSharePredicates) { + return new Promise(function (resolve, reject) { + helper.delete(uri, DataSharePredicates).then((data) => { + console.info("TestDataShare publicdelete Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test delete err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//query公共方法 +function publicquery(helper, uri, columns, DataSharePredicates) { + return new Promise(function (resolve, reject) { + helper.query(uri, columns, DataSharePredicates).then((data) => { + console.info("TestDataShare publicquery Callback=" + JSON.stringify(data)); + globalThis.ResultSet = data; + resolve(data); + }).catch((err) => { + console.info("test query err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//update公共方法 +function publicupdate(helper, uri, DataShareValuesBucket, DataSharePredicates) { + return new Promise(function (resolve, reject) { + helper.update(uri, DataShareValuesBucket, DataSharePredicates).then((data) => { + console.info("TestDataShare publicupdate Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test update err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//batchInsert公共方法 +function publicbatchInsert(helper, uri, DataShareValuesBucket) { + return new Promise(function (resolve, reject) { + helper.batchInsert(uri, DataShareValuesBucket).then((data) => { + console.info("TestDataShare publicbatchInsert Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test batchInsert err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//getType公共方法 +function publicgetType(helper, uri) { + return new Promise(function (resolve, reject) { + helper.getType(uri).then((data) => { + console.info("TestDataShare publicgetType Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test getType err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//getFileTypes公共方法 +function publicgetFileTypes(helper, uri, mimeTypeFilter) { + return new Promise(function (resolve, reject) { + helper.getFileTypes(uri, mimeTypeFilter).then((data) => { + console.info("TestDataShare publicgetFileTypes Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test getFileTypes err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//normalizeUri公共方法 +function publicnormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.normalizeUri(uri).then((data) => { + console.info("TestDataShare publicnormalizeUri Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test normalizeUri err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//denormalizeUri公共方法 +function publicdenormalizeUri(helper, uri) { + return new Promise(function (resolve, reject) { + helper.denormalizeUri(uri).then((data) => { + console.info("TestDataShare publicdenormalizeUri Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test denormalizeUri err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +//denormalizeUri公共方法 +function publicopenFile(helper, uri, mode) { + return new Promise(function (resolve, reject) { + helper.openFile(uri, mode).then((data) => { + console.info("TestDataShare publicopenFile Callback=" + JSON.stringify(data)); + resolve(data); + }).catch((err) => { + console.info("test openFile err information: " + JSON.stringify(err)); + reject(err); + }) + }) +} + +export { publicinsert, publicdelete, publicquery, publicupdate, publicbatchInsert, publicgetType, publicgetFileTypes, + publicnormalizeUri, publicdenormalizeUri, publicopenFile +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Callback.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Callback.ets new file mode 100644 index 0000000000000000000000000000000000000000..dfccde40363ad92f3e4803422c8eaf3f8386d15e --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Callback.ets @@ -0,0 +1,1109 @@ +/* + * 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 'hypium/index' +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import * as pubfun from './DataSharePublicfunction_Callback' + +//CreateDataShareHelper +let uri = ("datashare:///com.samples.datasharetest.DataShare"); + +//InsertValuesBucket +let InsertNumber = { "age": 1 }; +let InsertString = { "name": "sun" }; +let InsertBoolean = { "isStudent": true }; +let InsertUint8Array = { "Binary": new Uint8Array([1, 2, 3]) }; +let InsertNull = { "name": "" }; +let BatchInsert = new Array( + { "age": 1 }, + { "name": "sun" }, + { "isStudent": true }, + { "Binary": new Uint8Array([1, 2, 3]) }); + +//UpdateValuesBucket +let UpdateNumber = { "age": 11 }; +let UpdateString = { "name": "suns" }; +let UpdateBoolean = { "isStudent": false }; +let UpdateUint8Array = { "Binary": new Uint8Array([1, 2, 3, 4]) }; +let UpdateNull = { "name": "1" }; + +//Predicates +let PredicatesNumber = new dataSharePredicates.DataSharePredicates(); +PredicatesNumber.equalTo("age", 1); +let PredicatesString = new dataSharePredicates.DataSharePredicates(); +PredicatesString.equalTo("name", "sun"); +let PredicatesBoolean = new dataSharePredicates.DataSharePredicates(); +PredicatesBoolean.equalTo("isStudent", true); +let PredicatesUint8Array = new dataSharePredicates.DataSharePredicates(); +PredicatesUint8Array.equalTo("Binary", new Uint8Array([1, 2, 3])); +let PredicatesNull = new dataSharePredicates.DataSharePredicates(); +PredicatesNull.equalTo("name", ""); +let PredicatesAll = new dataSharePredicates.DataSharePredicates(); + +//getColumnIndex +const IndexNumber = "age"; +const IndexString = "name"; +const IndexBoolean = "isStudent"; +const IndexUint8Array = "Binary"; +const IndexNull = "name"; + +//Return Expect +const DataProcessResultOne = 1; +const DataProcessResultFour = 4; +const GetType = "image"; +const GetFileTypes = new Array("type01", "type02", "type03"); +const Normalize = "normalize+" + uri; +const Denormalize = "denormalize+" + uri; +const ResultSetNumber = 1; +const ResultSetString = "sun"; +const ResultSetBoolean = 1; +const ResultSetUint8Array = new Uint8Array([1, 2, 3]); +const ResultSetNull = ""; +const Mode = "rwt"; + +function onChangeNotify() { + console.info("===>onChangeNotify===>"); +}; + +export default function DataShareSingleRdb_Callback() { + describe('DataShareSingleRdb_Callback', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count = data; + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + }) + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0101 fail err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert null type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesNumber, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesString, UpdateString).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesBoolean, UpdateBoolean).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesUint8Array, UpdateUint8Array).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update null type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesNull, UpdateNull).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesNumber, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetNumber)) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexNumber))); + }).catch((err) => { + console.info("DataShareQueryRdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesString, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(ResultSetString) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexString))); + }).catch((err) => { + console.info("DataShareQueryRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesBoolean, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetBoolean)) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexBoolean))); + }).catch((err) => { + console.info("DataShareQueryRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesUint8Array, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUint8Array)) + .assertEqual( + JSON.stringify(globalThis.ResultSet.getBlob(globalThis.ResultSet.getColumnIndex(IndexUint8Array)))); + }).catch((err) => { + console.info("DataShareQueryRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query null type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesNull, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(ResultSetNull) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexNull))); + }).catch((err) => { + console.info("DataShareQueryRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesNumber).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesString).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesBoolean).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesUint8Array).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete nul type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesNull).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0101', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }).catch((err) => { + console.info("DataSharebatchRdb001 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataSharebatchRdb001 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0102', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesAll, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultFour).assertEqual(data); + }).catch((err) => { + console.info("DataShareBatchRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0103', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToLastRow(); + expect(JSON.stringify(ResultSetUint8Array)) + .assertEqual( + JSON.stringify(globalThis.ResultSet.getBlob(globalThis.ResultSet.getColumnIndex(IndexUint8Array)))); + }).catch((err) => { + console.info("DataShareBatchRdb003 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchRdb003 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0104', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareBatchRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareBatchRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetType0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetType function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetType0101', 0, async function (done) { + try { + await pubfun.publicgetType(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going getType = " + data); + expect(GetType).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareGetType0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetType0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetFileTypes0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetFileTypes function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetFileTypes0101', 0, async function (done) { + try { + await pubfun.publicgetFileTypes(globalThis.helper, uri, "image/*").then((data) => { + console.info("TestDataShare going getFileTypes = " + data); + expect(JSON.stringify(GetFileTypes)).assertEqual(JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("DataShareGetFileTypes0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetFileTypes0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareNormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support NormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareNormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicnormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going NormalizeUri = " + data); + expect(Normalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareNormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareNormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDenormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support DenormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDenormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicdenormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going denormalizeUri = " + data); + expect(Denormalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDenormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDenormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOnRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support On function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOnRdb0101', 0, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOnRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOffRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support Off function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOffRdb0101', 0, function () { + try { + globalThis.helper.off("dataChange", uri, onChangeNotify); + console.info("TestDataShare going off"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOffRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareTypeErr0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Cannot on off operate + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('DataShareTypeErr0101', 2, function () { + try { + globalThis.helper.on(null, uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off(null, uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareTypeErr0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_CreateDataSharePromise0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : CreateDataShareHelperPromise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('CreateDataSharePromise0101', 0, async function (done) { + try { + await dataShare.createDataShareHelper(globalThis.abilityContext, uri).then((data) => { + console.info("TestDataShare CreateDataShareHelper = " + data); + expect(true).assertEqual(data != undefined); + done(); + }).catch((err) => { + console.info("CreateDataSharePromise0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("CreateDataSharePromise0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOpenFile0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support OpenFile function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOpenFile0101', 0, async function (done) { + try { + await pubfun.publicopenFile(globalThis.helper, uri, Mode).then((data) => { + console.info("TestDataShare going openFile = " + data); + expect(true).assertEqual(data != null); + done(); + }).catch((err) => { + console.info("DataShareOpenFile0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareOpenFile0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Promise.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Promise.ets new file mode 100644 index 0000000000000000000000000000000000000000..d3f2b860ae6d2c890f1454d2dd3d991c94891b08 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/DataShareSingleRdb_Promise.ets @@ -0,0 +1,1109 @@ +/* + * 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 'hypium/index' +import dataShare from '@ohos.data.dataShare' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import * as pubfun from './DataSharePublicfunction_Promise' + +//CreateDataShareHelper +let uri = ("datashare:///com.samples.datasharetest.DataShare"); + +//InsertValuesBucket +let InsertNumber = { "age": 1 }; +let InsertString = { "name": "sun" }; +let InsertBoolean = { "isStudent": true }; +let InsertUint8Array = { "Binary": new Uint8Array([1, 2, 3]) }; +let InsertNull = { "name": "" }; +let BatchInsert = new Array( + { "age": 1 }, + { "name": "sun" }, + { "isStudent": true }, + { "Binary": new Uint8Array([1, 2, 3]) }); + +//UpdateValuesBucket +let UpdateNumber = { "age": 11 }; +let UpdateString = { "name": "suns" }; +let UpdateBoolean = { "isStudent": false }; +let UpdateUint8Array = { "Binary": new Uint8Array([1, 2, 3, 4]) }; +let UpdateNull = { "name": "1" }; + +//Predicates +let PredicatesNumber = new dataSharePredicates.DataSharePredicates(); +PredicatesNumber.equalTo("age", 1); +let PredicatesString = new dataSharePredicates.DataSharePredicates(); +PredicatesString.equalTo("name", "sun"); +let PredicatesBoolean = new dataSharePredicates.DataSharePredicates(); +PredicatesBoolean.equalTo("isStudent", true); +let PredicatesUint8Array = new dataSharePredicates.DataSharePredicates(); +PredicatesUint8Array.equalTo("Binary", new Uint8Array([1, 2, 3])); +let PredicatesNull = new dataSharePredicates.DataSharePredicates(); +PredicatesNull.equalTo("name", ""); +let PredicatesAll = new dataSharePredicates.DataSharePredicates(); + +//getColumnIndex +const IndexNumber = "age"; +const IndexString = "name"; +const IndexBoolean = "isStudent"; +const IndexUint8Array = "Binary"; +const IndexNull = "name"; + +//Return Expect +const DataProcessResultOne = 1; +const DataProcessResultFour = 4; +const GetType = "image"; +const GetFileTypes = new Array("type01", "type02", "type03"); +const Normalize = "normalize+" + uri; +const Denormalize = "denormalize+" + uri; +const ResultSetNumber = 1; +const ResultSetString = "sun"; +const ResultSetBoolean = 1; +const ResultSetUint8Array = new Uint8Array([1, 2, 3]); +const ResultSetNull = ""; +const Mode = "rwt"; + +function onChangeNotify() { + console.info("===>onChangeNotify===>"); +}; + +export default function DataShareSingleRdb_Promise() { + describe('DataShareSingleRdb_Promise', function () { + function sleep(time) { + return new Promise(resolve => { + setTimeout(() => { + resolve('sleep finished'); + }, time); + }) + } + + + beforeAll(async () => { + await globalThis.connectDataShareExtAbility(); + await sleep(2000); + console.info("[ttt] helper = " + globalThis.helper + "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count = data; + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + }) + }) + + /* + * @tc.number : SUB_DDM_DataShare_JS_DataShareInsertRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0101 fail err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareInsertRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Insert null type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareInsertRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }).catch((err) => { + console.info("DataShareInsertRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareInsertRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesNumber, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesString, UpdateString).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesBoolean, UpdateBoolean).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesUint8Array, UpdateUint8Array).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareUpdateRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update null type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareUpdateRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesNull, UpdateNull).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultOne).assertEqual(data); + }).catch((err) => { + console.info("DataShareUpdateRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareUpdateRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesNumber, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetNumber)) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexNumber))); + }).catch((err) => { + console.info("DataShareQueryRdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesString, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(ResultSetString) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexString))); + }).catch((err) => { + console.info("DataShareQueryRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesBoolean, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetBoolean)) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexBoolean))); + }).catch((err) => { + console.info("DataShareQueryRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesUint8Array, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(JSON.stringify(ResultSetUint8Array)) + .assertEqual( + JSON.stringify(globalThis.ResultSet.getBlob(globalThis.ResultSet.getColumnIndex(IndexUint8Array)))); + }).catch((err) => { + console.info("DataShareQueryRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareQueryRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query null type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareQueryRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesNull, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToFirstRow(); + expect(ResultSetNull) + .assertEqual(globalThis.ResultSet.getString(globalThis.ResultSet.getColumnIndex(IndexNull))); + }).catch((err) => { + console.info("DataShareQueryRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareQueryRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete number type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0101', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNumber).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesNumber).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete string type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0102', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertString).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesString).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete boolean type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0103', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertBoolean).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesBoolean).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0103 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0103 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete Uint8Array type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0104', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertUint8Array).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesUint8Array).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDeleteRdb0105 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete nul type data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDeleteRdb0105', 0, async function (done) { + try { + await pubfun.publicinsert(globalThis.helper, uri, InsertNull).then((data) => { + console.info("TestDataShare going insert = " + data); + globalThis.Count += 1; + expect(globalThis.Count).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesNull).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultOne).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDeleteRdb0105 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDeleteRdb0105 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : BatchInsert data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0101', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }).catch((err) => { + console.info("DataSharebatchRdb001 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataSharebatchRdb001 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0102 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Update data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0102', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }) + await pubfun.publicupdate(globalThis.helper, uri, PredicatesAll, UpdateNumber).then((data) => { + console.info("TestDataShare going update = " + data); + expect(DataProcessResultFour).assertEqual(data); + }).catch((err) => { + console.info("DataShareBatchRdb0102 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchRdb0102 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0103 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Query data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0103', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }) + await pubfun.publicquery(globalThis.helper, uri, PredicatesAll, ["*"]).then((data) => { + console.info("TestDataShare going query = " + data); + globalThis.ResultSet.goToLastRow(); + expect(JSON.stringify(ResultSetUint8Array)) + .assertEqual( + JSON.stringify(globalThis.ResultSet.getBlob(globalThis.ResultSet.getColumnIndex(IndexUint8Array)))); + }).catch((err) => { + console.info("DataShareBatchRdb003 err " + JSON.stringify(err)); + expect(err).assertFail(); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }) + } catch (err) { + console.info("DataShareBatchRdb003 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareBatchRdb0104 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Delete data in Rdb + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareBatchRdb0104', 0, async function (done) { + try { + await pubfun.publicbatchInsert(globalThis.helper, uri, BatchInsert).then((data) => { + console.info("TestDataShare going batchInsert = " + data); + globalThis.Count += DataProcessResultFour; + expect(DataProcessResultFour).assertEqual(data); + }) + await pubfun.publicdelete(globalThis.helper, uri, PredicatesAll).then((data) => { + console.info("TestDataShare going delete = " + data); + expect(DataProcessResultFour).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareBatchRdb0104 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareBatchRdb0104 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetType0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetType function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetType0101', 0, async function (done) { + try { + await pubfun.publicgetType(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going getType = " + data); + expect(GetType).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareGetType0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetType0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareGetFileTypes0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support GetFileTypes function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareGetFileTypes0101', 0, async function (done) { + try { + await pubfun.publicgetFileTypes(globalThis.helper, uri, "image/*").then((data) => { + console.info("TestDataShare going getFileTypes = " + data); + expect(JSON.stringify(GetFileTypes)).assertEqual(JSON.stringify(data)); + done(); + }).catch((err) => { + console.info("DataShareGetFileTypes0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareGetFileTypes0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareNormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support NormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareNormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicnormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going NormalizeUri = " + data); + expect(Normalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareNormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareNormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareDenormalizeUri0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support DenormalizeUri function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareDenormalizeUri0101', 0, async function (done) { + try { + await pubfun.publicdenormalizeUri(globalThis.helper, uri).then((data) => { + console.info("TestDataShare going denormalizeUri = " + data); + expect(Denormalize).assertEqual(data); + done(); + }).catch((err) => { + console.info("DataShareDenormalizeUri0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareDenormalizeUri0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOnRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support On function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOnRdb0101', 0, function () { + try { + globalThis.helper.on("dataChange", uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOnRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOffRdb0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support Off function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOffRdb0101', 0, function () { + try { + globalThis.helper.off("dataChange", uri, onChangeNotify); + console.info("TestDataShare going off"); + globalThis.helper.off("dataChange", uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareOffRdb0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareTypeErr0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Cannot on off operate + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 2 + */ + it('DataShareTypeErr0101', 2, function () { + try { + globalThis.helper.on(null, uri, onChangeNotify); + console.info("TestDataShare going on"); + globalThis.helper.off(null, uri); + console.info("TestDataShare going off"); + } catch (err) { + console.info("DataShareTypeErr0101 fail" + JSON.stringify(err)); + expect(err).assertFail(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_CreateDataSharePromise0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : CreateDataShareHelperPromise + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('CreateDataSharePromise0101', 0, async function (done) { + try { + await dataShare.createDataShareHelper(globalThis.abilityContext, uri).then((data) => { + console.info("TestDataShare CreateDataShareHelper = " + data); + expect(true).assertEqual(data != undefined); + done(); + }).catch((err) => { + console.info("CreateDataSharePromise0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("CreateDataSharePromise0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + + /* + * @tc.number : SUB_DDM_DataShare_ETS_DataShareOpenFile0101 + * @tc.name : Use getEntries get the value by mixing the string key + * @tc.desc : Support OpenFile function + * @tc.size : MediumTest + * @tc.type : Function + * @tc.level : Level 0 + */ + it('DataShareOpenFile0101', 0, async function (done) { + try { + await pubfun.publicopenFile(globalThis.helper, uri, Mode).then((data) => { + console.info("TestDataShare going openFile = " + data); + expect(true).assertEqual(data != null); + done(); + }).catch((err) => { + console.info("DataShareOpenFile0101 err " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + }) + } catch (err) { + console.info("DataShareOpenFile0101 fail " + JSON.stringify(err)); + expect(err).assertFail(); + done(); + } + }) + }) +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/List.test.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/List.test.ets new file mode 100644 index 0000000000000000000000000000000000000000..6d5482791782ba649c6ae8a9ae56f56de514af6c --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/Test/List.test.ets @@ -0,0 +1,27 @@ +/* + * 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 DataShareSingleRdb_Callback from "./DataShareSingleRdb_Callback" +import DataShareSingleRdb_Promise from "./DataShareSingleRdb_Promise" +import DataSharePredicatesRdb from "./DataSharePredicatesRdb" +import DataShareCombinationRdb from "./DataShareCombinationRdb" + +export default function testsuite() { + + DataShareSingleRdb_Callback() + DataShareSingleRdb_Promise() + DataSharePredicatesRdb() + DataShareCombinationRdb() +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/pages/index.ets b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..022c5e3aab6e41b72d84eb1f21be43abf1ee5dbf --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/ets/pages/index.ets @@ -0,0 +1,67 @@ +/* + * 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 file from '@system.file'; + +import {Core, ExpectExtend} from "hypium/index" +import testsuite from "../Test/List.test" + +//InstrumentLog, ReportExtend + +@Entry +@Component +struct Index { + + aboutToAppear(){ + console.info("start run testcase!!!!") + const core = Core.getInstance() + const expectExtend = new ExpectExtend({ + 'id': 'extend' + }) + core.addService('expect', expectExtend) + //const reportExtend = new ReportExtend(file) + + //core.addService('report', reportExtend) + core.init() + //core.subscribeEvent('task', reportExtend) + const configService = core.getDefaultService('config') + console.info('parameters---->' + JSON.stringify(globalThis.abilityWant.parameters)) + globalThis.abilityWant.parameters.timeout = 70000; + configService.setConfig(globalThis.abilityWant.parameters) + testsuite() + core.execute() + } + + build() { + Flex({ direction:FlexDirection.Column, alignItems:ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('Hello World') + .fontSize(50) + .fontWeight(FontWeight.Bold) + Button() { + Text('next page') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + + }) + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/module.json b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..add832ed30dc5b5017e9975662529d6daf5aa7d6 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/module.json @@ -0,0 +1,38 @@ +{ + "module": { + "package": "com.example.myapplication", + "name": "entry", + "mainAbility": "com.example.myapplication.MainAbility", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:entry_desc", + "mainElement": "MainAbility", + "deviceTypes": [ + "phone" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "com.example.myapplication.MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:MainAbility_desc", + "icon": "$media:icon", + "label": "$string:MainAbility_label", + "visible": true, + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ] + } + ] + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/element/string.json b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..cf4e93d9ec5f5722daf3fa0233402b5f97c6c6df --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/element/string.json @@ -0,0 +1,16 @@ +{ + "string": [ + { + "name": "entry_desc", + "value": "description" + }, + { + "name": "MainAbility_desc", + "value": "description" + }, + { + "name": "MainAbility_label", + "value": "ActsDataShareRdbTest" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..feec276e105eeb8d621c20aaf838f318b0a94150 --- /dev/null +++ b/distributeddatamgr/windowStage/dataShareRdbtest/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/distributeddatamgr/windowStage/dataShareRdbtest/signature/openharmony_sx.p7b b/distributeddatamgr/windowStage/dataShareRdbtest/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..66b4457a8a81fb8d3356cf46d67226c850944858 Binary files /dev/null and b/distributeddatamgr/windowStage/dataShareRdbtest/signature/openharmony_sx.p7b differ diff --git a/distributeddatamgr/windowStage/server/rdbService/AppScope/app.json b/distributeddatamgr/windowStage/server/rdbService/AppScope/app.json new file mode 100644 index 0000000000000000000000000000000000000000..0bc4417ed44937b05d2e98c4ed05391708c0daf9 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/AppScope/app.json @@ -0,0 +1,20 @@ +{ + "app": { + "bundleName": "com.samples.datasharetest", + "vendor": "example", + "versionCode": 1000000, + "versionName": "1.0.0", + "icon": "$media:app_icon", + "label": "$string:app_name", + "debug": false, + "distributedNotificationEnabled": true, + "keepAlive": true, + "singleUser": true, + "minAPIVersion": 9, + "targetAPIVersion": 9, + "car": { + "apiCompatibleVersion": 9, + "singleUser": false + } + } +} diff --git a/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/element/string.json b/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..616c648fb1daa54ca2376c77ea5ac703fa0b205f --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/element/string.json @@ -0,0 +1,8 @@ +{ + "string": [ + { + "name": "app_name", + "value": "datasharetest" + } + ] +} diff --git a/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/media/app_icon.png b/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/media/app_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/windowStage/server/rdbService/AppScope/resources/base/media/app_icon.png differ diff --git a/distributeddatamgr/windowStage/server/rdbService/BUILD.gn b/distributeddatamgr/windowStage/server/rdbService/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8c437f27e44d66b09546a020dae1b72c33359e88 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/BUILD.gn @@ -0,0 +1,44 @@ +# 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("//test/xts/tools/build/suite.gni") + +ohos_hap("ActsRdbServiceHap") { + hap_profile = "./entry/src/main/module.json" + + hap_name = "ActsRdbServiceHap" + subsystem_name = XTS_SUITENAME + final_hap_path = + "${SUITES_OUTPUT_ROOT}/${XTS_SUITENAME}/testcases/${hap_name}.hap" + js_build_mode = "debug" + deps = [ + ":kvService_js_assets", + ":kvService_resources", + ] + ets2abc = true + certificate_profile = "./signature/openharmony_sx.p7b" +} +ohos_app_scope("dataSharekv_app_profile") { + app_profile = "AppScope/app.json" + sources = [ "AppScope/resources" ] +} + +ohos_js_assets("kvService_js_assets") { + source_dir = "./entry/src/main/ets" +} + +ohos_resources("kvService_resources") { + sources = [ "./entry/src/main/resources" ] + deps = [ ":dataSharekv_app_profile" ] + hap_profile = "./entry/src/main/module.json" +} diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts new file mode 100644 index 0000000000000000000000000000000000000000..39b7d7001a454cbfc1ee8fd0355fe788dd3bc787 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/Application/AbilityStage.ts @@ -0,0 +1,22 @@ +/* + * 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 AbilityStage from "@ohos.application.AbilityStage" + +export default class MyAbilityStage extends AbilityStage { + onCreate() { + console.log("[ttt] [DataShareTest] MyAbilityStage onCreate"); + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..5201c63954b96b682b6eebdbef49f111f31a097c --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/DataShareExtAbility/DataShareExtAbility.ts @@ -0,0 +1,246 @@ +/* + * 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 Extension from '@ohos.application.DataShareExtensionAbility' +import distributedData from '@ohos.data.distributedData'; +import dataAbility from '@ohos.data.dataAbility'; +import rdb from '@ohos.data.rdb'; +import hilog from '@ohos.hilog'; +import featureAbility from '@ohos.ability.featureAbility' +import fileIo from '@ohos.fileio' +import deviceManager from '@ohos.distributedHardware.deviceManager'; + + +let DB_NAME = "DB00.db"; +let TBL_NAME = "TBL00"; +let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS " ++ TBL_NAME ++ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)"; +const BUNDLE_NAME = 'com.samples.datasharetest'; + +let rdbStore; +let result; +let devManager; +let deviceIds = []; + +export default class DataShareExtAbility extends Extension { + private rdbStore_; + private kvdbStore_; + + onCreate(want, callback) { + console.log('[ttt] [DataShareTest] <> DataShareExtAbility onCreate, want:' + want.abilityName); + console.log('[ttt] [DataShareTest] <> this.context:' + this.context); + result = this.context.cacheDir + '/datashare.txt' + console.info('[ttt] [DataAbilityTest] <> resultpath = ' + result); + rdb.getRdbStore(this.context, { + name: DB_NAME + }, 1, function (err, data) { + console.log('[ttt] [DataShareTest] <> DataShareExtAbility onCreate, getRdbStore done err:' + JSON.stringify(err)); + console.log('[ttt] [DataShareTest] <> DataShareExtAbility onCreate, getRdbStore done data:' + JSON.stringify(data)); + rdbStore = data; + rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) { + console.log('[ttt] [DataShareTest] <> DataShareExtAbility onCreate, executeSql done err:' + JSON.stringify(err)); + }); + callback(); + }); + } + + + async insert(uri, value, callback) { + console.info('[ttt] [DataShareTest] <> [insert] enter'); +// deviceManager.createDeviceManager(BUNDLE_NAME, (err, value) => { +// if (err) { +// console.info("[ttt] [DataShareTest] <> [createDeviceManager] err = " + err); +// } +// devManager = value; +// console.info('[ttt] [DataShareTest] <> [createDeviceManager] enter'); +// // get deviceIds +// if (devManager != null) { +// var devices = devManager.getTrustedDeviceListSync(); +// for (var i = 0; i < devices.length; i++) { +// deviceIds[i] = devices[i].deviceId; +// } +// } +// console.log("[ttt] [DataShareTest] <> deviceIds :" + deviceIds); +// }); + if (value == null) { + console.info('[ttt] [DataShareTest] <> [insert] invalid valueBuckets'); + return; + } + console.info('[ttt] [DataShareTest] <> [insert] value = ' + value); + console.info('[ttt] [DataShareTest] <> [insert] value = ' + JSON.stringify(value)); + await rdbStore.insert(TBL_NAME, value, function (err, ret) { + console.info('[ttt] [DataShareTest] <> [insert] callback ret:' + ret); + if (callback != undefined) { + callback(err, ret); + } + }); +// let predicate = new rdb.RdbPredicates('TBL00') +// predicate.inAllDevices(); +// rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH,predicate,(err,data) => { +// if(err) { +// console.info("[ttt] [DataShareTest] <> [sync] err = " + err); +// } +// console.info("[ttt] [DataShareTest] <> [sync] data = " + JSON.stringify(data)); +// }) + console.info('[ttt] [DataShareTest] <> [insert] leave'); + } + + update(uri, predicates, value, callback) { + console.info('[ttt] [DataShareTest] <> [update] enter'); + if (predicates == null || predicates == undefined) { + console.info('[ttt] [DataShareTest] <> [update] invalid predicates'); + return; + } + console.info('[ttt] [DataShareTest] <> [update] values = ' + value); + console.info('[ttt] [DataShareTest] <> [update] values = ' + JSON.stringify(value)); + console.info('[ttt] [DataShareTest] <> [update] predicates = ' + predicates); + console.info('[ttt] [DataShareTest] <> [update] predicates = ' + JSON.stringify(predicates)); + try { + rdbStore.update(TBL_NAME,value, predicates, function (err, ret) { + console.info('[ttt] [DataShareTest] <> [update] callback ret:' + ret); + console.info('[ttt] [DataShareTest] <> [update] callback err:' + err); + if (callback != undefined) { + callback(err, ret); + } + }); + } catch (err) { + console.error('[ttt] [DataShareTest] <> [update] error' + err); + } + console.info('[ttt] [DataShareTest] <> [update] leave'); + } + + delete(uri, predicates, callback) { + console.info('[ttt] [DataShareTest] <> [delete] enter'); + if (predicates == null || predicates == undefined) { + console.info('[ttt] [DataShareTest] <> [delete] invalid predicates'); + return; + } + console.info('[ttt] [DataShareTest] <> [delete] predicates = ' + predicates); + console.info('[ttt] [DataShareTest] <> [delete] predicates = ' + JSON.stringify(predicates)); + try { + rdbStore.delete(TBL_NAME,predicates, function (err, ret) { + console.info('[ttt] [DataShareTest] <> [delete] ret:' + ret); + if (callback != undefined) { + callback(err, ret); + } + }); + } catch (err) { + console.error('[ttt] [DataShareTest] <> [delete] error' + err); + } + console.info('[ttt] [DataShareTest] <> [delete] leave'); + } + + query(uri, predicates, columns, callback) { + console.info('[ttt] [DataShareTest] <> [query] enter'); + if (predicates == null || predicates == undefined) { + console.info('[ttt] [DataShareTest] <> [query] invalid predicates'); + } + console.info('[ttt] [DataShareTest] <> [query] values = ' + columns); + console.info('[ttt] [DataShareTest] <> [query] values = ' + JSON.stringify(columns)); + console.info('[ttt] [DataShareTest] <> [query] predicates = ' + predicates); + console.info('[ttt] [DataShareTest] <> [query] predicates = ' + JSON.stringify(predicates)); + try { +// let da = new dataSharePredicates.DataSharePredicates(); +// da.notEqualTo("name", "ert"); +// da.limit(1,0); + rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) { + console.info('[ttt] [DataShareTest] <> [query] ret: ' + resultSet); + if (resultSet != undefined) { + console.info('[ttt] [DataShareTest] <> [query] resultSet.rowCount: ' + resultSet.rowCount); + } + if (callback != undefined) { + callback(err, resultSet); + } + }); + } catch (err) { + console.error('[ttt] [DataShareTest] <> [query] error' + err); + } + console.info('[ttt] [DataShareTest] <> [query] leave'); + } + + + batchInsert(uri: string, valueBuckets, callback) { + console.info('[ttt] [DataShareTest] <> [batchInsert] enter'); + if (valueBuckets == null || valueBuckets.length == undefined) { + console.info('[ttt] [DataShareTest] <> [batchInsert] invalid valueBuckets'); + return; + } + console.info('[ttt] [DataShareTest] <> [batchInsert] valueBuckets.length:' + valueBuckets.length); + let resultNum = valueBuckets.length + valueBuckets.forEach(vb => { + console.info('[ttt] [DataShareTest] <> [batchInsert] vb:' + JSON.stringify(vb)); + rdbStore.insert(TBL_NAME, vb, function (err, ret) { + console.info('[ttt] [DataShareTest] <> [batchInsert] callback ret:' + ret); + if (callback != undefined) { + callback(err, resultNum); + } + }); + }); + console.info('[ttt] [DataShareTest] <> [batchInsert] leave'); + } + + getType(uri: string,callback) { + console.info('[ttt] [DataShareTest] <> [getType] enter'); + let ret = "image"; + console.info('[ttt] [DataShareTest] <> [getType] leave, ret:' + ret); + let err = {"code":0}; + callback(err,ret); + return ret; + } + + getFileTypes(uri: string, mimeTypeFilter: string, callback) { + console.info('[ttt] [DataShareTest] <> [getFileTypes] enter'); + let ret = new Array("type01", "type02", "type03"); + console.info('[ttt] [DataShareTest] <> [getFileTypes] leave, ret:' + ret); + let err = {"code":2}; + callback(err,ret); + return ret; + } + + openFile(uri: string, mode: string, callback) { + console.info('[ttt] [DataAbilityTest] <> DataAbility openFile in'); + fileIo.open(result, 0o2 | 0o100, 0o666, function(err, fd) { + if(err) { + console.info('[ttt] [DataAbilityTest] <> OpenFile err = ' + err); + console.info('[ttt] [DataAbilityTest] <> OpenFile err = ' + JSON.stringify(err)); + } + console.log('[ttt] [DataAbilityTest] <> EtsFileIo fd =' + fd); + let num = fileIo.writeSync(fd, "this is a interesting test of DataAbility from the Great RPF"); + console.info("[ttt] [DataAbillityTest] <> WriteSync length = " + num); + console.info("[ttt] [DataAbillityTest] <> WriteSync fd = " + fd); + callback(err,fd); + }) + } + + normalizeUri(uri: string,callback) { + console.info('[ttt] [DataShareTest] <> [normalizeUri] enter'); + let ret = "normalize+" + uri; + console.info('[ttt] [DataShareTest] <> [normalizeUri] leave, ret:' + ret); + let err = {"code":2}; + console.info('[ttt] [DataShareTest] <> [normalizeUri] enter!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + callback(err,ret); + console.info('[ttt] [DataShareTest] <> [normalizeUri] leave!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + } + + denormalizeUri(uri: string,callback) { + console.info('[ttt] [DataShareTest] <> [denormalizeUri] enter'); + let ret = "denormalize+" + uri; + console.info('[ttt] [DataShareTest] <> [denormalizeUri] leave, ret:' + ret); + let err = {"code":2}; + callback(err,ret); + return ret; + } +}; \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts new file mode 100644 index 0000000000000000000000000000000000000000..10ab8c7525e65d2a78dc7bd714a4bd212ef34eb4 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/MainAbility/MainAbility.ts @@ -0,0 +1,455 @@ +/* + * 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 Ability from '@ohos.application.Ability' +import ability_particleAbility from '@ohos.ability.particleAbility' +import dataSharePredicates from '@ohos.data.dataSharePredicates' +import dataShare from '@ohos.data.dataShare' +import featureAbility from '@ohos.ability.featureAbility' + + +import dataAbility from '@ohos.data.dataAbility' +import rdb from '@ohos.data.rdb'; + +import rpc from "@ohos.rpc"; + +var seConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> seConnect onConnect called."); + console.log("[ttt] [DataShareTest] <> seConnect onConnect elementName = " + elementName); + console.log("[ttt] [DataShareTest] <> seConnect onConnect proxy = " + proxy); + let data = rpc.MessageParcel.create(); + let reply = rpc.MessageParcel.create(); + let option = new rpc.MessageOption(); + data.writeInterfaceToken("connect-test"); + data.writeInt(111); + + console.log("[ttt] [DataShareTest] <> seConnect onConnect sendRequest."); + proxy.sendRequest(1, data, reply, option) + .then(function (result) { + if (result.errCode === 0) { + // let msg = reply.readString(); + let msg = result.reply.readInt(); + console.log("[ttt] [DataShareTest] <> seConnect reply msg: " + msg); + } else { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest failed, errCode: " + result.errCode); + } + // callback没有返回值,默认返回undefined + }).catch(function (e) { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest got exception: " + e); + }).finally (async () => { + console.log("[ttt] [DataShareTest] <> seConnect sendRequest ends, reclaim parcel"); + data.reclaim(); + reply.reclaim(); + }) + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> seConnect onDisconnect"); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> seConnect onFailed"); + } +}; + +let dseProxy = 0; +let dseUri = ("datashare:///com.samples.datasharetest.DataShare"); + +var dseConnect = { + onConnect:function (elementName, proxy) { + console.log("[ttt] [DataShareTest] <> dseConnect onConnect called."); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect elementName = " + elementName); + // console.log("[ttt] [DataShareTest] <> dseConnect onConnect proxy = " + proxy); + dseProxy = proxy; + }, + onDisconnect:function (elementName) { + console.log("[ttt] [DataShareTest] <> dseConnect onDisconnect, elementName:" + elementName); + }, + onFailed:function (code) { + console.log("[ttt] [DataShareTest] <> dseConnect onFailed, code:" + code); + } +}; + +let seConnectionId = -1; +let dseConnectionId = -1; + +let seWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "ServiceExtAbility", +} + +let dseWant = { + "bundleName": "com.samples.datasharetest", + "abilityName": "DataShareExtAbility", +} + +export function onCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer on callback ****"); +} + +export function offCallback() { + console.info("[ttt] [DataShareTest] <> **** Observer off callback ****"); +} + +export default class MainAbility extends Ability { + onCreate(want, launchParam) { + // Ability is creating, initialize resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onCreate") + globalThis.abilityWant = want; + } + + onDestroy() { + // Ability is destroying, release resources for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onDestroy") + } + + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageCreate") + globalThis.abilityContext = this.context; + let context = this.context; +// console.log('[ttt] [DataShareTest] <> MainAbility onWindowStageCreate this.context.stageMode:' + context.stageMode); +// console.log('[ttt] [DataShareTest] <> MainAbility onWindowStageCreate this.context.bundleName:' + context.bundleName); +// console.log('[ttt] [DataShareTest] <> MainAbility onWindowStageCreate this.context.name:' + context.name); + globalThis.connectServiceExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> connectServiceExtAbility begin"); + seConnectionId = await context.connectAbility(seWant, seConnect); + console.log("[ttt] [DataShareTest] <> connectServiceExtAbility end, seConnectionId:" + seConnectionId); + }) + + globalThis.disconnectServiceExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> disconnectServiceExtAbility begin"); + await context.disconnectAbility(seConnectionId).then((data) => { + console.info("[ttt] [DataShareTest] <> startAbility success:" + JSON.stringify(data)); + }).catch((error) => { + console.error("[ttt] [DataShareTest] <> startAbility failed:" + JSON.stringify(error)); + }); + console.log("[ttt] [DataShareTest] <> disconnectServiceExtAbility end, seConnectionId:" + seConnectionId); + }) + + + + globalThis.connectDataShareExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> connectDataShareExtAbility begin"); +// globalThis.dsHelper = await dataShare.createDataShareHelper(this.context,dseUri); + + await dataShare.createDataShareHelper(globalThis.abilityContext, dseUri, (err,data)=>{ + globalThis.dsHelper = data; + console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.dsHelper = " + globalThis.dsHelper); + console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); + console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); + console.info("[ttt] [DataShareTest] <> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err)); + }); + +// await dataShare.createDataShareHelper(this.context,dseUri).then((data)=>{ +// globalThis.dsHelper = data; +// console.info("[ttt] [DataShareTest] <> ----- 1 -----, globalThis.dsHelper = " + globalThis.dsHelper); +// console.info("[ttt] [DataShareTest] <> ----- 2 -----, data = " + data); +// }).catch((err)=>{ +// console.info("[ttt] [DataShareTest] <> ----- 3 -----, err = " + err); +// console.info("[ttt] [DataShareTest] <> ----- 4 -----, JSON.stringify(err) = " + JSON.stringify(err)); +// }) + dseConnectionId = await context.connectAbility(dseWant, dseConnect); +// console.log("[ttt] [DataShareTest] <> ----- 5 -----, globalThis.dsHelper = " + globalThis.dsHelper); +// console.log("[ttt] [DataShareTest] <> connectDataShareExtAbility end, dseConnectionId:" + dseConnectionId); + }) + + globalThis.disconnectDataShareExtAbility = (async () => { + console.log("[ttt] [DataShareTest] <> disconnectDataShareExtAbility begin"); + await context.disconnectAbility(dseConnectionId).then((data) => { + console.info("[ttt] [DataShareTest] <> disconnectDataShareExtAbility success:" + JSON.stringify(data)); + }).catch((error) => { + console.error("[ttt] [DataShareTest] <> disconnectDataShareExtAbility failed:" + JSON.stringify(error)); + }); + globalThis.dsHelper = null; + console.log("[ttt] [DataShareTest] <> disconnectDataShareExtAbility end, dseConnectionId:" + dseConnectionId); + }) + + globalThis.on = (async () => { + console.log("[ttt] [DataShareTest] <> on begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> on end, DSHelper is null"); + return; + } + await globalThis.dsHelper.on("dataChange", dseUri, onCallback); + console.log("[ttt] [DataShareTest] <> on end"); + }) + + globalThis.off = (async () => { + console.log("[ttt] [DataShareTest] <> off begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> off end, DSHelper is null"); + return; + } + await globalThis.dsHelper.off("dataChange", dseUri); + await globalThis.dsHelper.off("dataChange", dseUri, offCallback); + console.log("[ttt] [DataShareTest] <> off end"); + }) + + globalThis.query = (async () => { + console.log("[ttt] [DataShareTest] <> query begin"); + let da = new dataSharePredicates.DataSharePredicates(); + if (da == null || da == undefined) { + console.log("[ttt] [DataShareTest] <> da is null or undefined"); + return; + } + let count = 0; + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> query end, DSHelper is null"); + return; + } + da.notEqualTo("$.name", "rpf"); + da.limit(1,0); + let result = await globalThis.dsHelper.query(dseUri, da, ["*"], (err,resultSet)=> { + if (err) { + console.error("[ttt] [DataShareTest] <> query err:" + JSON.stringify(err)); + console.log("[ttt] [DataShareTest] <> query data:" + resultSet); + console.log("[ttt] [DataShareTest] <> query data.rowCount:" + resultSet.rowCount); + console.log("[ttt] [DataShareTest] <> query data.columnCount:" + resultSet.columnCount); + } else { + console.log("[ttt] [DataShareTest] <> query data:" + resultSet); + console.log("[ttt] [DataShareTest] <> query data.rowCount:" + resultSet.rowCount); + console.log("[ttt] [DataShareTest] <> query data.columnCount:" + resultSet.columnCount); + } + }); + if (result != undefined) { + count = result.rowCount; + } + console.log("[ttt] [DataShareTest] <> query end, count:" + count); + return count; + }) + + globalThis.insert = (async () => { + + console.log("[ttt] [DataShareTest] <> insert begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> insert end, DSHelper is null"); + return; + } + let vb = {"age": 21} + + let v8Arr = []; + let ar = new Uint8Array([1,2,3,4,5,6]); + let arr = new Uint8Array([4,5,6,7]); + let vb1 = {"key":ar,"value":arr} + v8Arr.push(vb1); + + console.log("[ttt] [DataShareTest] <> insert vb:" + JSON.stringify(vb)); + console.log("[ttt] [DataShareTest] <> insert vb:" + JSON.stringify(vb)); + let ret = await globalThis.dsHelper.insert(dseUri, vb, (err,ret)=>{ + if(err){ + console.error("[ttt] [DataShareTest] <> insert err:" + JSON.stringify(err)); + console.log("[ttt] [DataShareTest] <> insert data:" + ret); + }else { + console.log("[ttt] [DataShareTest] <> insert data:" + ret); + } + }); + await globalThis.notifyChange(); + console.log("[ttt] [DataShareTest] <> insert end, ret:" + ret); + return ret; + }) + + globalThis.update = (async () => { + console.log("[ttt] [DataShareTest] <> update begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> update end, DSHelper is null"); + return; + } + console.log("[ttt] [DataShareTest] <> update begin RPF666"); + let da = new dataSharePredicates.DataSharePredicates(); + console.log("[ttt] [DataShareTest] <> update begin RPF777"); + if (da == null || da == undefined) { + console.log("[ttt] [DataShareTest] <> da is null or u" + + "ndefined"); + return; + } +// da.equalTo("name", "ZhangSan"); + let ret = await globalThis.dsHelper.update(dseUri, da, {"age": 31}, (err,ret)=>{ + if(err){ + console.error("[ttt] [DataShareTest] <> update err:" + JSON.stringify(err)); + console.log("[ttt] [DataShareTest] <> update data:" + ret); + }else { + console.log("[ttt] [DataShareTest] <> update data:" + ret); + } + }); + await globalThis.notifyChange(); + console.log("[ttt] [DataShareTest] <> update end, result:" + ret); + return ret; + }) + + globalThis.delete = (async () => { + console.log("[ttt] [DataShareTest] <> delete begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> delete end, DSHelper is null"); + return; + } + let da = new dataSharePredicates.DataSharePredicates(); + if (da == null || da == undefined) { + console.log("[ttt] [DataShareTest] <> da is null or undefined"); + return; + } +// da.equalTo("name", "ZhangSan"); + let ret = globalThis.dsHelper.delete(dseUri, da, (err,ret)=>{ + if(err){ + console.error("[ttt] [DataShareTest] <> delete err:" + JSON.stringify(err)); + console.log("[ttt] [DataShareTest] <> delete data:" + ret); + }else { + console.log("[ttt] [DataShareTest] <> delete data:" + ret); + } + }); + await globalThis.notifyChange(); + console.log("[ttt] [DataShareTest] <> delete end, result:" + ret); + return ret; + }) + + globalThis.batchInsert = (async () => { + console.log("[ttt] [DataShareTest] <> batchInsert begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> batchInsert end, DSHelper is null"); + return; + } + let ar = new Uint8Array([1,2,3,4,5,6]); + let arr = new Uint8Array([4,5,6,7]); + let people = new Array( + {"name": "LiSi", "age": 41, "Binary": ar}, + {"name": "WangWu", "age": 21, "Binary": arr}, + {"name": "ZhaoLiu", "age": 61, "Binary": arr}); +// let ar = new Uint8Array([1,2,3,4,5,6]); +// let arr = new Uint8Array([4,5,6,7]); +// let v8Arr = []; +// let vb = {"key":ar,"jii":arr,"value":arr,"njj":arr}; +// v8Arr.push(vb) + let ret = await globalThis.dsHelper.batchInsert(dseUri, people); + await globalThis.notifyChange(); + console.log("[ttt] [DataShareTest] <> batchInsert end, result:" + ret); + return ret; + }) + + globalThis.notifyChange = (async () => { + console.log("[ttt] [DataShareTest] <> notifyChange begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> notifyChange end, DSHelper is null"); + return; + } + await globalThis.dsHelper.notifyChange(dseUri); + console.log("[ttt] [DataShareTest] <> notifyChange end"); + }) + + globalThis.openFile = (async () => { + console.log("[ttt] [DataShareTest] <> openFile begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> openFile end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.openFile(dseUri, "rwt"); + console.log("[ttt] [DataShareTest] <> openFile end, result:" + result); + return result; + }) + + globalThis.getType = (async () => { + console.log("[ttt] [DataShareTest] <> getType begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> getType end, DSHelper is null"); + return; + } + let result; + globalThis.dsHelper.getType(dseUri,(err,data)=>{ + if(err){ + console.log("[ttt] [DataShareTest] <> getType err, err:" + JSON.stringify(err)); + console.log("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + }else{ + console.log("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + } + }); + console.log("[ttt] [DataShareTest] <> getType end, result:" + result); + return result; + }) + + globalThis.getFileTypes = (async () => { + console.log("[ttt] [DataShareTest] <> getFileTypes begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> getFileTypes end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.getFileTypes(dseUri, "image/*",(err,data)=>{ + if(err){ + console.log("[ttt] [DataShareTest] <> getType err, err:" + JSON.stringify(err)); + console.log("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + }else{ + console.log("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); + result = data; + } + }); + return result; + }) + + globalThis.normalizeUri = (async () => { + console.log("[ttt] [DataShareTest] <> normalizeUri begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> normalizeUri end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.normalizeUri(dseUri,(err,data)=>{ + if(err){ + console.log("[ttt] [DataShareTest] <> normalizeUri err, err:" + JSON.stringify(err)); +// console.log("[ttt] [DataShareTest] <> getType end, data:" + JSON.stringify(data)); +// result = data; + }else{ + console.log("[ttt] [DataShareTest] <> normalizeUri end, data:" + JSON.stringify(data)); + result = data; + } + }); + return result; + }) + + globalThis.denormalizeUri = (async () => { + console.log("[ttt] [DataShareTest] <> denormalizeUri begin"); + if (globalThis.dsHelper == null) { + console.log("[ttt] [DataShareTest] <> denormalizeUri end, DSHelper is null"); + return; + } + let result = await globalThis.dsHelper.denormalizeUri(dseUri,(err,data)=>{ + if(err){ + console.log("[ttt] [DataShareTest] <> denormalizeUri err, err:" + JSON.stringify(err)); +// console.log("[ttt] [DataShareTest] <> getType end, err:" + JSON.stringify(data)); +// result = data; + }else{ + console.log("[ttt] [DataShareTest] <> denormalizeUri end, err:" + JSON.stringify(data)); + result = data; + } + }); + return result; + }) + + windowStage.setUIContent(this.context, "pages/index", null) + } + + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log("[ttt] [DataShareTest] <> MainAbility onWindowStageDestroy") + } + + onForeground() { + // Ability has brought to foreground + console.log("[ttt] [DataShareTest] <> MainAbility onForeground") + } + + onBackground() { + // Ability has back to background + console.log("[ttt] [DataShareTest] <> MainAbility onBackground") + } +}; diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/pages/index.ets b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..384decf875d181f33bb65d2eb135689e2d8b6ebb --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/ets/pages/index.ets @@ -0,0 +1,414 @@ +/* + * 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 dataSharePredicates from '@ohos.data.dataSharePredicates' + +@Entry +@Component +struct Index { + @State message: string = "Main thread message filed" + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { + Text('DataShare Extension Ability Test') + .fontSize(40) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> dataSharePredicates build begin'); + let da = new dataSharePredicates.DataSharePredicates(); + da.equalTo("name", "zhangsan"); + da.notEqualTo("name", "lisi"); + da.beginWrap(); + da.endWrap(); + da.or(); + da.and(); + da.contains("name", "zhang"); + da.beginsWith("name", "z"); + da.endsWith("name", "n"); + da.isNull("name"); + da.isNotNull("name"); + da.like("name", "zhang"); + da.unlike("name", "li"); + da.glob("name", "???"); + da.between("age", 18, 22); + da.notBetween("age", 18, 22); + da.greaterThan("age", 18); + da.lessThan("age", 22); + da.greaterThanOrEqualTo("age", 18); + da.lessThanOrEqualTo("age", 22); + da.orderByAsc("age"); + da.orderByDesc("age"); + da.distinct(); + da.limit(10, 5); + da.groupBy(["name", "age"]); + da.indexedBy("name"); + da.in("name", []); + da.notIn("name", []); + da.prefixKey("name"); + console.info('[ttt] [DataShareTest] <> dataSharePredicates = ' + JSON.stringify(da)); + console.info('[ttt] [DataShareTest] <> dataSharePredicates build end'); + }) + + Text(`${this.message}`) + .fontSize(30) + .height('15%') + .width('100%') + .textAlign(TextAlign.Center) + +// Row() { +// Button() { +// Text('ConnectServiceExtension') +// .fontSize(25) +// .fontWeight(FontWeight.Bold) +// }.type(ButtonType.Capsule) +// .margin({ +// top: 20 +// }) +// .width('45%') +// .height('8%') +// .backgroundColor('#0ddffb') +// .onClick(async () => { +// console.info('[ttt] [DataShareTest] <> ConnectServiceExtension onclick enter') +// this.message = 'ConnectServiceExtension onclick' +// globalThis.connectServiceExtAbility() +// console.info('[ttt] [DataShareTest] <> ConnectServiceExtension onclick leave') +// }) +// +// Button() { +// Text('DisconnectServiceExtension') +// .fontSize(25) +// .fontWeight(FontWeight.Bold) +// }.type(ButtonType.Capsule) +// .margin({ +// top: 20 +// }) +// .width('45%') +// .height('8%') +// .backgroundColor('#0ddffb') +// .onClick(async () => { +// console.info('[ttt] [DataShareTest] <> DisconnectServiceExtension onclick enter') +// this.message = 'DisconnectServiceExtension onclick' +// globalThis.disconnectServiceExtAbility() +// console.info('[ttt] [DataShareTest] <> DisconnectServiceExtension onclick leave') +// }) +// } + + Row() { + Button() { + Text('Connect') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Connect onclick enter') + this.message = 'Connect onclick' + await globalThis.connectDataShareExtAbility() + console.info('[ttt] [DataShareTest] <> Connect onclick leave') + }) + + Button() { + Text('Disconnect') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Disconnect onclick enter') + this.message = 'Disconnect onclick' + await globalThis.disconnectDataShareExtAbility() + console.info('[ttt] [DataShareTest] <> Disconnect onclick leave') + }) + } + + Row() { + Button() { + Text('On') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> On onclick enter') + this.message = '~ On onclick' + try { + await globalThis.on(); + } catch (err) { + console.error('[ttt] [DataAbilityTest] Observer on catch(err)====>:' + err); + } + console.info('[ttt] [DataShareTest] <> On onclick leave') + }) + + Button() { + Text('Off') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Off onclick enter') + this.message = '~ Off onclick' + try { + await globalThis.off(); + } catch (err) { + console.error('[ttt] [DataAbilityTest] Observer Off catch(err)====>:' + err); + } + console.info('[ttt] [DataShareTest] <> Off onclick leave') + }) + + Button() { + Text('OpenFile') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('30%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> OpenFile onclick enter') + this.message = 'OpenFile onclick' + let ret = await globalThis.openFile() + console.info('[ttt] [DataShareTest] <> OpenFile onclick ret = ' + ret); + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> OpenFile onclick leave') + }) + } + + Row() { + Button() { + Text('Query') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Query onclick enter') + this.message = 'Query onclick' + let ret = await globalThis.query() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Query onclick leave') + }) + + Button() { + Text('Insert') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Insert onclick enter') + this.message = 'Insert onclick' + let ret = await globalThis.insert() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Insert onclick leave') + }) + } + + Row() { + Button() { + Text('Update') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Update onclick enter') + this.message = 'Update onclick' + let ret = await globalThis.update() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Update onclick leave') + }) + + Button() { + Text('Delete') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> Delete onclick enter') + this.message = 'Delete onclick' + let ret = await globalThis.delete() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> Delete onclick leave') + }) + } + + Row() { + Button() { + Text('BatchInsert') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> BatchInsert onclick enter') + this.message = 'BatchInsert onclick' + let ret = await globalThis.batchInsert() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> BatchInsert onclick leave') + }) + + Button() { + Text('NotifyChange') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> NotifyChange onclick enter') + this.message = 'NotifyChange onclick' + await globalThis.notifyChange() + console.info('[ttt] [DataShareTest] <> NotifyChange onclick leave') + }) + } + + Row() { + Button() { + Text('GetType') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> GetType onclick enter') + this.message = 'GetType onclick' + let ret = await globalThis.getType() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> GetType onclick leave') + }) + + Button() { + Text('GetFileTypes') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> GetFileTypes onclick enter') + this.message = 'GetFileTypes onclick' + let ret = await globalThis.getFileTypes() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> GetFileTypes onclick leave') + }) + } + + Row() { + Button() { + Text('NormalizeUri') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> NormalizeUri onclick enter') + this.message = 'NormalizeUri onclick' + let ret = await globalThis.normalizeUri() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> NormalizeUri onclick leave') + }) + + Button() { + Text('DenormalizeUri') + .fontSize(25) + .fontWeight(FontWeight.Bold) + }.type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .width('45%') + .height('8%') + .backgroundColor('#0ddffb') + .onClick(async () => { + console.info('[ttt] [DataShareTest] <> DenormalizeUri onclick enter') + this.message = 'DenormalizeUri onclick' + let ret = await globalThis.denormalizeUri() + this.message += "\n\n Test Result: " + ret; + console.info('[ttt] [DataShareTest] <> DenormalizeUri onclick leave') + }) + } + } + .width('100%') + .height('100%') + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/module.json b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/module.json new file mode 100644 index 0000000000000000000000000000000000000000..72d0f2c42e43e9275acc3dfad9b2f26f909158a9 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/module.json @@ -0,0 +1,50 @@ +{ + "module": { + "name": "entry", + "type": "entry", + "srcEntrance": "./ets/Application/AbilityStage.ts", + "description": "$string:phone_entry_dsc", + "mainElement": "MainAbility", + "deviceTypes": [ + "default" + ], + "deliveryWithInstall": true, + "installationFree": false, + "pages": "$profile:main_pages", + "uiSyntax": "ets", + "abilities": [ + { + "name": "MainAbility", + "srcEntrance": "./ets/MainAbility/MainAbility.ts", + "description": "$string:phone_entry_main", + "icon": "$media:icon", + "label": "$string:entry_label", + "visible": true, + + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "startWindowIcon":"$media:icon", + "startWindowBackground": "$color:color_1" + } + ], + "extensionAbilities": [ + { + "srcEntrance": "./ets/DataShareExtAbility/DataShareExtAbility.ts", + "name": "DataShareExtAbility", + "icon": "$media:icon", + "description": "$string:description_datashareextability", + "type": "dataShare", + "uri": "datashare://com.samples.datasharetest.DataShare", + "visible": true + } + ] + } +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/datashare.json b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/datashare.json new file mode 100644 index 0000000000000000000000000000000000000000..c946d63748451e44cc2861cf10f392df713f8224 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/datashare.json @@ -0,0 +1,8 @@ +{ + "color": [ + { + "name": "color_1", + "value": "#ff0000" + } + ] +} \ No newline at end of file diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/string.json b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..9dbfd151dbaa3d374b8c496e97a0acec5c9634b8 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/element/string.json @@ -0,0 +1,40 @@ +{ + "string": [ + { + "name": "phone_entry_dsc", + "value": "i am an entry for phone" + }, + { + "name": "phone_entry_main", + "value": "the phone entry ability" + }, + { + "name": "entry_label", + "value": "ActsRdbServiceHap" + }, + { + "name": "form_description", + "value": "my form" + }, + { + "name": "serviceability_description", + "value": "my whether" + }, + { + "name": "description_application", + "value": "DataShareTest" + }, + { + "name": "app_name", + "value": "ActsRdbServiceHap" + }, + { + "name": "description_datashareextability", + "value": "description_datashareextability" + }, + { + "name": "description_serviceability", + "value": "description_serviceability" + } + ] +} diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/media/icon.png b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/media/icon.png differ diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/form_config.json b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/form_config.json new file mode 100644 index 0000000000000000000000000000000000000000..ba3489dd5c6ee9435d07201193fcb137e3ad083e --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/form_config.json @@ -0,0 +1,24 @@ +{ + "forms": [ + { + "name": "Form_Js", + "description": "$string:form_description", + "src": "pages/card/index", + "window": { + "designWidth": 720, + "autoDesignWidth": true + }, + "colorMode": "auto", + "formConfigAbility": "ability://xxxxx", + "formVisibleNotify": false, + "isDefault": true, + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "defaultDimension": "2*2", + "supportDimensions": [ + "2*2" + ] + } + ] +} diff --git a/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/main_pages.json b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/main_pages.json new file mode 100644 index 0000000000000000000000000000000000000000..50b961efe7eba3554818d73178d6c4aa735bcd16 --- /dev/null +++ b/distributeddatamgr/windowStage/server/rdbService/entry/src/main/resources/base/profile/main_pages.json @@ -0,0 +1,5 @@ +{ + "src": [ + "pages/index" + ] +} diff --git a/distributeddatamgr/windowStage/server/rdbService/signature/openharmony_sx.p7b b/distributeddatamgr/windowStage/server/rdbService/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..7ffcdc78527c5c1aa24520ab7e913c5f47c703f0 Binary files /dev/null and b/distributeddatamgr/windowStage/server/rdbService/signature/openharmony_sx.p7b differ