diff --git a/compileruntime/BUILD.gn b/compileruntime/BUILD.gn index 9ffdd79f7fcad35925d05dc9ee93462fc7d0e971..5fbd3642ba1d79c335e3708b32fbc206ca56f532 100644 --- a/compileruntime/BUILD.gn +++ b/compileruntime/BUILD.gn @@ -10,13 +10,16 @@ # 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("jsapi") { +group("compileruntime") { testonly = true - deps = [ - "StartupProcessJSApiTest:startup_process_js_test", - "StartupUrlJSApiTest:startup_url_js_test", - "StartupUtilJSApiTest:startup_util_js_test", - "StartupWorkerJSApiTest:startup_worker_js_test", - ] + if (is_standard_system) { + deps = [ + "process_lib_standard:process_js_test", + "url_lib_standard:url_js_test", + "util_lib_standard:util_js_test", + "worker_lib_standard:worker_js_hap", + ] + } } diff --git a/compileruntime/process_lib_standard/BUILD.gn b/compileruntime/process_lib_standard/BUILD.gn index ef3f729ceadd7765a30011224aeace6b39aaa476..0c4e64017034ee77ca09f22d519c32ba1a790b4c 100644 --- a/compileruntime/process_lib_standard/BUILD.gn +++ b/compileruntime/process_lib_standard/BUILD.gn @@ -10,9 +10,29 @@ # 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("process_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":process_js_assets", + ":process_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "ProcessJSApiTest" -ohos_js_hap_suite("startup_process_js_test") { - test_hap_name = "StartupProcessJSApiTest" - hap_source_path = "hap/entry-debug-rich-unsigned.hap" + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("process_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("process_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" } diff --git a/compileruntime/process_lib_standard/Test.json b/compileruntime/process_lib_standard/Test.json index 6198140443d33c42a5fb35869cb2ec59edeef9cf..58980316e8915f8eea5c050347c26b97f1ab9773 100644 --- a/compileruntime/process_lib_standard/Test.json +++ b/compileruntime/process_lib_standard/Test.json @@ -9,7 +9,7 @@ "kits": [ { "test-file-name": [ - "StartupProcessJSApiTest.hap" + "ProcessJSApiTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/compileruntime/process_lib_standard/project/entry/package.json b/compileruntime/process_lib_standard/project/entry/package.json deleted file mode 100644 index 69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f..0000000000000000000000000000000000000000 --- a/compileruntime/process_lib_standard/project/entry/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/compileruntime/process_lib_standard/signature/openharmony_sx.p7b b/compileruntime/process_lib_standard/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/compileruntime/process_lib_standard/signature/openharmony_sx.p7b differ diff --git a/compileruntime/util_lib_standard/project/entry/src/main/config.json b/compileruntime/process_lib_standard/src/main/config.json similarity index 95% rename from compileruntime/util_lib_standard/project/entry/src/main/config.json rename to compileruntime/process_lib_standard/src/main/config.json index f3773ec2f0f5dea54ee945b3a7e23a50d9dba61e..75d1ac14458c1ede210bf40739cb9c9fc80e74b4 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/config.json +++ b/compileruntime/process_lib_standard/src/main/config.json @@ -1,57 +1,57 @@ -{ - "app": { - "bundleName": "com.example.childprocess", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.childprocess", - "name": ".MyApplication", - "mainAbility": "com.example.childprocess.MainAbility", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.childprocess.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:entry_MainAbility", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": true - } - } - ] - } +{ + "app": { + "bundleName": "com.example.childprocess", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.childprocess", + "name": ".MyApplication", + "mainAbility": "com.example.childprocess.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.childprocess.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } } \ No newline at end of file diff --git a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/childprocess/MainAbility.java b/compileruntime/process_lib_standard/src/main/java/com/example/childprocess/MainAbility.java similarity index 96% rename from compileruntime/util_lib_standard/project/entry/src/main/java/com/example/childprocess/MainAbility.java rename to compileruntime/process_lib_standard/src/main/java/com/example/childprocess/MainAbility.java index 1bc0c4d53723f9549e7fd388dc64fe12c460e128..dbdddf742e23f2568178756f1cea558603671535 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/childprocess/MainAbility.java +++ b/compileruntime/process_lib_standard/src/main/java/com/example/childprocess/MainAbility.java @@ -1,31 +1,31 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.childprocess; - -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.childprocess; + +import ohos.ace.ability.AceAbility; +import ohos.aafwk.content.Intent; + +public class MainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/childprocess/MyApplication.java b/compileruntime/process_lib_standard/src/main/java/com/example/childprocess/MyApplication.java similarity index 97% rename from compileruntime/util_lib_standard/project/entry/src/main/java/com/example/childprocess/MyApplication.java rename to compileruntime/process_lib_standard/src/main/java/com/example/childprocess/MyApplication.java index b27ffa96e3bb28be14523100030474a1398ab5e9..bf24a9676c68a8c8fe00508525160c66d0378e80 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/childprocess/MyApplication.java +++ b/compileruntime/process_lib_standard/src/main/java/com/example/childprocess/MyApplication.java @@ -1,25 +1,25 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.childprocess; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.childprocess; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/default/app.js b/compileruntime/process_lib_standard/src/main/js/default/app.js similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/default/app.js rename to compileruntime/process_lib_standard/src/main/js/default/app.js diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/default/i18n/en-US.json b/compileruntime/process_lib_standard/src/main/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/default/i18n/en-US.json rename to compileruntime/process_lib_standard/src/main/js/default/i18n/en-US.json diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json b/compileruntime/process_lib_standard/src/main/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json rename to compileruntime/process_lib_standard/src/main/js/default/i18n/zh-CN.json diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/default/pages/index/index.css b/compileruntime/process_lib_standard/src/main/js/default/pages/index/index.css similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/default/pages/index/index.css rename to compileruntime/process_lib_standard/src/main/js/default/pages/index/index.css diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/default/pages/index/index.hml b/compileruntime/process_lib_standard/src/main/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/default/pages/index/index.hml rename to compileruntime/process_lib_standard/src/main/js/default/pages/index/index.hml diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/default/pages/index/index.js b/compileruntime/process_lib_standard/src/main/js/default/pages/index/index.js similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/default/pages/index/index.js rename to compileruntime/process_lib_standard/src/main/js/default/pages/index/index.js diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js b/compileruntime/process_lib_standard/src/main/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js rename to compileruntime/process_lib_standard/src/main/js/test/ExampleJsunit.test.js diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/test/List.test.js b/compileruntime/process_lib_standard/src/main/js/test/List.test.js similarity index 93% rename from compileruntime/process_lib_standard/project/entry/src/main/js/test/List.test.js rename to compileruntime/process_lib_standard/src/main/js/test/List.test.js index fe9706bb65c4c771ce2c398576f79dcdc0fc0d34..ccd2b4ce70fe504d549a4bae9286c851ba3a04e2 100644 --- a/compileruntime/process_lib_standard/project/entry/src/main/js/test/List.test.js +++ b/compileruntime/process_lib_standard/src/main/js/test/List.test.js @@ -1,17 +1,17 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -require('./ExampleJsunit.test.js') +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require('./ExampleJsunit.test.js') require('./Process.test.js') \ No newline at end of file diff --git a/compileruntime/process_lib_standard/project/entry/src/main/js/test/Process.test.js b/compileruntime/process_lib_standard/src/main/js/test/Process.test.js similarity index 79% rename from compileruntime/process_lib_standard/project/entry/src/main/js/test/Process.test.js rename to compileruntime/process_lib_standard/src/main/js/test/Process.test.js index 63a957bdffd768c887ca101d474e5d637012e75e..801ed7f409ada7a18ffe18cfca1e13ac9be5a5cb 100644 --- a/compileruntime/process_lib_standard/project/entry/src/main/js/test/Process.test.js +++ b/compileruntime/process_lib_standard/src/main/js/test/Process.test.js @@ -1,515 +1,486 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/lite' -import process from '@ohos.process' - -describe('ChildProcessTest', function () { - - // childprocess runCmd test - it('test_runCmd_001', 0, async function () { - var child = process.runCmd('echo abc') - child.wait() - var array = new Uint8Array([97, 98, 99, 10, 0]) - child.getOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - }) - - it('test_runCmd_002', 0, async function () { - var child = process.runCmd('echo abc;', { maxBuffer : 2 }) - child.wait() - var array = new Uint8Array([97, 98, 0]) - child.getOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - }) - - it('test_runCmd_003', 0, async function () { - var child = process.runCmd('sleep 5; echo abc;', { timeout : 1, killSignal : 9 }) - child.wait() - var array = new Uint8Array([0]) - child.getOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - expect(child.exitCode).assertEqual(9) - }) - - it('test_runCmd_004', 0, async function () { - var child = process.runCmd('sleep 2; echo abc;', { timeout : 9000, killSignal : 9 }) - child.wait() - var array = new Uint8Array([97, 98, 99, 10, 0]) - child.getOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - expect(child.exitCode).assertEqual(0) - }) - - // childprocess getOutput test - it('test_getOutput_001', 0, async function () { - var child = process.runCmd('echo bcd;') - child.wait() - var array = new Uint8Array([98, 99, 100, 0]) - child.getOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - }) - - // childprocess getErrorOutput test - it('test_getErrorOutput_001', 0, async function () { - var child = process.runCmd('makdir 1.txt') - child.wait() - var array = new Uint8Array([115, 104, 58, 32, 109, 97, 107, 100, 105, 114, 58, 32, 105, 110, 97, 99, 99, - 101, 115, 115, 105, 98, 108, 101, 32, 111, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 10, 0]) - child.getErrorOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - }) - - it('test_getErrorOutput_002', 0, async function () { - var child = process.runCmd('echo "error" 1>&2') - child.wait() - var array = new Uint8Array([101, 114, 111, 114, 10, 0]) - child.getErrorOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - }) - - it('test_getErrorOutput_003', 0, async function () { - var child = process.runCmd('1') - child.wait() - var array = new Uint8Array([115, 104, 58, 32, 49, 58, 32, 105, 110, 97, 99, 99, 101, 115, 115, 105, 98, - 108, 101, 32, 111, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 10, 0]) - child.getErrorOutput().then(val=>{ - for (var i = 0; i < array.length; i++) { - expect(val[i]).assertEqual(array[i]) - } - }) - }) - - // childprocess wait test - it('test_wait_001', 0, async function () { - var child = process.runCmd('ls') - var status = child.wait() - status.then(val=>{ - expect(val).assertEqual(0) - }) - }) - - it('test_wait_002', 0, async function () { - var child = process.runCmd('ls; sleep 5;') - child.kill(9); - var status = child.wait() - status.then(val=>{ - expect(val).assertEqual(9) - }) - }) - - // childprocess pid test - it('test_pid_001', 0, function () { - var child = process.runCmd('ls; sleep 5;') - child.wait() - var pid_ = child.pid - expect(pid_ > 0).assertEqual(true) - }) - - // childprocess ppid test - it('test_ppid_001', 0, function () { - var child = process.runCmd('ls; sleep 5;') - var status = child.wait() - var ppid_ = child.ppid - expect(ppid_ > 0).assertEqual(true) - }) - - // childprocess kill test - it('test_kill_001', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill(13) - var temp = child.killed - expect(temp).assertEqual(true) - }) - - it('test_kill_002', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill(1) - var temp = child.killed - expect(temp).assertEqual(true) - }) - - it('test_kill_003', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill('SIGHUP') - var temp = child.killed - expect(temp).assertEqual(true) - }) - - it('test_kill_004', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill('ABC') - var temp = child.killed - expect(temp).assertEqual(true) - }) - - it('test_kill_005', 0, function () { - var child = process.runCmd('ls') - child.wait() - var result = child.kill(9) - var temp = child.killed - expect(temp).assertEqual(false) - }) - - // childprocess close test - it('test_close_001', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var result = child.close() - expect(child.exitCode).assertEqual(9) - }) - - it('test_close_002', 0, function () { - var child = process.runCmd('ls') - function sleep(ms, callback) { - setTimeout(callback, ms) - } - sleep(1000, () => {} ) - var result = child.close() - expect(child.exitCode===0).assertEqual(false) - }) - - it('test_close_003', 0, function () { - var child = process.runCmd('ls;') - var status = child.wait() - var result = child.close() - expect(child.exitCode).assertEqual(0) - }) - - // childprocess killed test - it('test_killed_001', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var result = child.kill(3) - var temp = child.killed - expect(temp).assertEqual(true) - }) - - // childprocess exitCode test - it('test_exitCode_001', 0, function () { - var child = process.runCmd('ls; sleep 5s;') - var temp = child.kill(9) - child.wait() - var result = child.exitCode - expect(result).assertEqual(9) - }) - - // process GetUid test - it('GetUid_test_001', 0, function () { - var that = new process.Process() - var result = that.getUid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('GetUid_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++){ - var result = that.getUid - if(result != null) { - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - } - }) - - // process GetGid test - it('GetGid_test_001', 0, function () { - var that = new process.Process() - var result = that.getGid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('GetGid_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++){ - var result = that.getGid - if(result != null) { - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - } - }) - - // process GetEuid test - it('GetEuid_test_001', 0, function () { - var that = new process.Process() - var result = that.getEuid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('GetEuid_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++){ - var result = that.getEuid - if(result != null) { - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - } - }) - - // process GetEgid test - it('GetEgid_test_001', 0, function () { - var that = new process.Process() - var result = that.getEgid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('GetEgid_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++){ - var result = that.getEgid - if(result != null) { - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - } - }) - - // process GetGroups test - it('GetGroups_test_001', 0, function () { - var that = new process.Process() - var result = that.getGroups - var len = result.length - if(len > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('GetGroups_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++){ - var result = that.getGroups - if(result != null) { - var len = result.length - if(len > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - } - }) - - // process chdir test - it('chdir_test_001', 0, function () { - var that = new process.Process() - var result = that.chdir('/system') - var result1 = that.cwd() - expect(result1).assertEqual('/system') - }) - - it('chdir_test_002', 0, function () { - var that = new process.Process() - var result = that.chdir('/system/lib') - var result1 = that.cwd() - expect(result1).assertEqual('/system/lib') - }) - - it('chdir_test_003', 0, function () { - var that = new process.Process() - var result = that.chdir('/..') - var result1 = that.cwd() - expect(result1).assertEqual('/') - }) - - // process kill test - it('kill_test_001', 0, function () { - var that = new process.Process() - var result = that.kill(123, 3) - expect(result).assertEqual(false) - }) - - it('kill_test_002', 0, function () { - var that = new process.Process() - var pres = that.getPid - var result = that.kill(pres, 23) - expect(result).assertEqual(true) - }) - - it('kill_test_003', 0, function () { - var that = new process.Process() - var pres = that.getPid - var result = that.kill(pres, 28) - expect(result).assertEqual(true) - }) - - it('kill_test_004', 0, function () { - var that = new process.Process() - var pres = that.getPid - var result = that.kill(pres, 17) - expect(result).assertEqual(true) - }) - - // process uptime test - it('uptime_test_001', 0, function () { - var that = new process.Process() - var result1 = that.uptime() - function sleep(d){ - while(that.uptime() - result1 <= d); - } - sleep(5); - var result2 = that.uptime() - 6 - expect(result1).assertEqual(result2) - }) - - it('uptime_test_002', 0, function () { - var that = new process.Process() - var result1 = that.uptime() - function sleep(d){ - while(that.uptime() - result1 <= d); - } - sleep(8); - var result2 = that.uptime() - 9 - expect(result1).assertEqual(result2) - }) - - it('uptime_test_003', 0, function () { - var that = new process.Process() - var result1 = that.uptime() - function sleep(d){ - while(that.uptime() - result1 <= d); - } - sleep(10); - var result2 = that.uptime() - 11 - expect(result1).assertEqual(result2) - }) - - // process pid test - it('pid_test_001', 0, function () { - var that = new process.Process() - var result = that.getPid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('pid_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++) - { - var result = that.getPid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - }) - - // process ppid test - it('ppid_test_001', 0, function () { - var that = new process.Process() - var result = that.getPpid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - }) - - it('ppid_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++) - { - var result = that.getPpid - if(result > 0) { - var flag = true - } - expect(flag).assertEqual(true) - } - }) - - // process cwd test - it('cwd_test_001', 0, function () { - var that =new process.Process() - var cwd = that.cwd() - expect(cwd).assertEqual('/') - }) - - it('cwd_test_002', 0, function () { - var that = new process.Process() - for(var i = 0; i < 3; i++) - { - var cwd = that.cwd() - expect(cwd).assertEqual('/') - } - }) - - // process on test - it('on_test_001', 0, function () { - var that = new process.Process() - function add(){ - var value = 3 + 2 - } - var ontest = that.on(1, add) - expect(ontest).assertEqual(false) - }) - - it('on_test_002', 0, function () { - var that = new process.Process() - function add1(num){ - var value = num + 3 - } - var on = that.on("add123", add1) - }) - - it('on_test_003', 0, function () { - var that = new process.Process() - function add2(num0, num1){ - var value = num0 + num1 - } - var ontest = that.on(879, add2) - expect(ontest).assertEqual(false) - }) +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/lite' +import process from '@ohos.process' + +describe('ChildProcessTest', function () { + + // childprocess runCmd test + it('test_runCmd_001', 0, async function () { + var child = process.runCmd('echo abc') + child.wait() + var array = new Uint8Array([97, 98, 99, 10, 0]) + child.getOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + }) + + it('test_runCmd_002', 0, async function () { + var child = process.runCmd('echo abc;', { maxBuffer : 2 }) + child.wait() + var array = new Uint8Array([97, 98, 0]) + child.getOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + }) + + it('test_runCmd_003', 0, async function () { + var child = process.runCmd('sleep 5; echo abc;', { timeout : 1, killSignal : 9 }) + child.wait() + var array = new Uint8Array([0]) + child.getOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + expect(child.exitCode).assertEqual(9) + }) + + it('test_runCmd_004', 0, async function () { + var child = process.runCmd('sleep 2; echo abc;', { timeout : 9000, killSignal : 9 }) + child.wait() + var array = new Uint8Array([97, 98, 99, 10, 0]) + child.getOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + expect(child.exitCode).assertEqual(0) + }) + + // childprocess getOutput test + it('test_getOutput_001', 0, async function () { + var child = process.runCmd('echo bcd;') + child.wait() + var array = new Uint8Array([98, 99, 100, 0]) + child.getOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + }) + + // childprocess getErrorOutput test + it('test_getErrorOutput_001', 0, async function () { + var child = process.runCmd('makdir 1.txt') + child.wait() + var array = new Uint8Array([115, 104, 58, 32, 109, 97, 107, 100, 105, 114, 58, 32, 105, 110, 97, 99, 99, + 101, 115, 115, 105, 98, 108, 101, 32, 111, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 10, 0]) + child.getErrorOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + }) + + it('test_getErrorOutput_002', 0, async function () { + var child = process.runCmd('echo "error" 1>&2') + child.wait() + var array = new Uint8Array([101, 114, 111, 114, 10, 0]) + child.getErrorOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + }) + + it('test_getErrorOutput_003', 0, async function () { + var child = process.runCmd('1') + child.wait() + var array = new Uint8Array([115, 104, 58, 32, 49, 58, 32, 105, 110, 97, 99, 99, 101, 115, 115, 105, 98, + 108, 101, 32, 111, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 10, 0]) + child.getErrorOutput().then(val=>{ + for (var i = 0; i < array.length; i++) { + expect(val[i]).assertEqual(array[i]) + } + }) + }) + + // childprocess wait test + it('test_wait_001', 0, async function () { + var child = process.runCmd('ls') + var status = child.wait() + status.then(val=>{ + expect(val).assertEqual(0) + }) + }) + + it('test_wait_002', 0, async function () { + var child = process.runCmd('ls; sleep 5;') + child.kill(9); + var status = child.wait() + status.then(val=>{ + expect(val).assertEqual(9) + }) + }) + + // childprocess pid test + it('test_pid_001', 0, function () { + var child = process.runCmd('ls; sleep 5;') + child.wait() + var pid_ = child.pid + expect(pid_ > 0).assertEqual(true) + }) + + // childprocess ppid test + it('test_ppid_001', 0, function () { + var child = process.runCmd('ls; sleep 5;') + var status = child.wait() + var ppid_ = child.ppid + expect(ppid_ > 0).assertEqual(true) + }) + + // childprocess kill test + it('test_kill_001', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill(13) + var temp = child.killed + expect(temp).assertEqual(true) + }) + + it('test_kill_002', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill(1) + var temp = child.killed + expect(temp).assertEqual(true) + }) + + it('test_kill_003', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill('SIGHUP') + var temp = child.killed + expect(temp).assertEqual(true) + }) + + it('test_kill_004', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill('ABC') + var temp = child.killed + expect(temp).assertEqual(true) + }) + + it('test_kill_005', 0, function () { + var child = process.runCmd('ls') + child.wait() + var result = child.kill(9) + var temp = child.killed + expect(temp).assertEqual(false) + }) + + // childprocess close test + it('test_close_001', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var result = child.close() + expect(child.exitCode).assertEqual(9) + }) + + it('test_close_002', 0, function () { + var child = process.runCmd('ls') + function sleep(ms, callback) { + setTimeout(callback, ms) + } + sleep(1000, () => {} ) + var result = child.close() + expect(child.exitCode===0).assertEqual(false) + }) + + it('test_close_003', 0, function () { + var child = process.runCmd('ls;') + var status = child.wait() + var result = child.close() + expect(child.exitCode).assertEqual(0) + }) + + // childprocess killed test + it('test_killed_001', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var result = child.kill(3) + var temp = child.killed + expect(temp).assertEqual(true) + }) + + // childprocess exitCode test + it('test_exitCode_001', 0, function () { + var child = process.runCmd('ls; sleep 5s;') + var temp = child.kill(9) + child.wait() + var result = child.exitCode + expect(result).assertEqual(9) + }) + + // process GetUid test + it('GetUid_test_001', 0, function () { + var result = process.getUid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('GetUid_test_002', 0, function () { + for(var i = 0; i < 3; i++){ + var result = process.getUid + if(result != null) { + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + } + }) + + // process GetGid test + it('GetGid_test_001', 0, function () { + var result = process.getGid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('GetGid_test_002', 0, function () { + for(var i = 0; i < 3; i++){ + var result = process.getGid + if(result != null) { + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + } + }) + + // process GetEuid test + it('GetEuid_test_001', 0, function () { + var result = process.getEuid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('GetEuid_test_002', 0, function () { + for(var i = 0; i < 3; i++){ + var result = process.getEuid + if(result != null) { + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + } + }) + + // process GetEgid test + it('GetEgid_test_001', 0, function () { + var result = process.getEgid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('GetEgid_test_002', 0, function () { + for(var i = 0; i < 3; i++){ + var result = process.getEgid + if(result != null) { + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + } + }) + + // process GetGroups test + it('GetGroups_test_001', 0, function () { + var result = process.getGroups + var len = result.length + if(len > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('GetGroups_test_002', 0, function () { + for(var i = 0; i < 3; i++){ + var result = process.getGroups + if(result != null) { + var len = result.length + if(len > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + } + }) + + // process chdir test + it('chdir_test_001', 0, function () { + var result = process.chdir('/system') + var result1 = process.cwd() + expect(result1).assertEqual('/system') + }) + + it('chdir_test_002', 0, function () { + var result = process.chdir('/system/lib') + var result1 = process.cwd() + expect(result1).assertEqual('/system/lib') + }) + + it('chdir_test_003', 0, function () { + var result = process.chdir('/..') + var result1 = process.cwd() + expect(result1).assertEqual('/') + }) + + // process kill test + it('kill_test_001', 0, function () { + var result = process.kill(123, 3) + expect(result).assertEqual(false) + }) + + it('kill_test_002', 0, function () { + var pres = process.getPid + var result = process.kill(pres, 23) + expect(result).assertEqual(true) + }) + + it('kill_test_003', 0, function () { + var pres = process.getPid + var result = process.kill(pres, 28) + expect(result).assertEqual(true) + }) + + it('kill_test_004', 0, function () { + var pres = process.getPid + var result = process.kill(pres, 17) + expect(result).assertEqual(true) + }) + + // process uptime test + it('uptime_test_001', 0, function () { + var result1 = process.uptime() + function sleep(d){ + while(process.uptime() - result1 <= d); + } + sleep(5); + var result2 = process.uptime() - 6 + expect(result1).assertEqual(result2) + }) + + it('uptime_test_002', 0, function () { + var result1 = process.uptime() + function sleep(d){ + while(process.uptime() - result1 <= d); + } + sleep(8); + var result2 = process.uptime() - 9 + expect(result1).assertEqual(result2) + }) + + it('uptime_test_003', 0, function () { + var result1 = process.uptime() + function sleep(d){ + while(process.uptime() - result1 <= d); + } + sleep(10); + var result2 = process.uptime() - 11 + expect(result1).assertEqual(result2) + }) + + // process pid test + it('pid_test_001', 0, function () { + var result = process.getPid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('pid_test_002', 0, function () { + for(var i = 0; i < 3; i++) + { + var result = process.getPid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + }) + + // process ppid test + it('ppid_test_001', 0, function () { + var result = process.getPpid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + }) + + it('ppid_test_002', 0, function () { + for(var i = 0; i < 3; i++) + { + var result = process.getPpid + if(result > 0) { + var flag = true + } + expect(flag).assertEqual(true) + } + }) + + // process cwd test + it('cwd_test_001', 0, function () { + var cwd = process.cwd() + expect(cwd).assertEqual('/') + }) + + it('cwd_test_002', 0, function () { + for(var i = 0; i < 3; i++) + { + var cwd = process.cwd() + expect(cwd).assertEqual('/') + } + }) + + // process on test + it('on_test_001', 0, function () { + function add(){ + var value = 3 + 2 + } + var ontest = process.on(1, add) + expect(ontest).assertEqual(false) + }) + + it('on_test_002', 0, function () { + function add1(num){ + var value = num + 3 + } + var on = process.on("add123", add1) + }) + + it('on_test_003', 0, function () { + function add2(num0, num1){ + var value = num0 + num1 + } + var ontest = process.on(879, add2) + expect(ontest).assertEqual(false) + }) }) \ No newline at end of file diff --git a/compileruntime/process_lib_standard/project/entry/src/main/resources/base/element/string.json b/compileruntime/process_lib_standard/src/main/resources/base/element/string.json similarity index 94% rename from compileruntime/process_lib_standard/project/entry/src/main/resources/base/element/string.json rename to compileruntime/process_lib_standard/src/main/resources/base/element/string.json index c0dd3a09e5dcefc69f22b5e00e92296f1c3f55a5..0bae6bd40f7360d5d818998221b199d3ec0f69c0 100644 --- a/compileruntime/process_lib_standard/project/entry/src/main/resources/base/element/string.json +++ b/compileruntime/process_lib_standard/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "entry_MainAbility" - }, - { - "name": "mainability_description", - "value": "JS_Empty Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] } \ No newline at end of file diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/app.js b/compileruntime/process_lib_standard/src/ohosTest/js/default/app.js similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/app.js rename to compileruntime/process_lib_standard/src/ohosTest/js/default/app.js diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/i18n/en-US.json b/compileruntime/process_lib_standard/src/ohosTest/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/i18n/en-US.json rename to compileruntime/process_lib_standard/src/ohosTest/js/default/i18n/en-US.json diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/i18n/zh-CN.json b/compileruntime/process_lib_standard/src/ohosTest/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/i18n/zh-CN.json rename to compileruntime/process_lib_standard/src/ohosTest/js/default/i18n/zh-CN.json diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.css b/compileruntime/process_lib_standard/src/ohosTest/js/default/pages/index/index.css similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.css rename to compileruntime/process_lib_standard/src/ohosTest/js/default/pages/index/index.css diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.hml b/compileruntime/process_lib_standard/src/ohosTest/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.hml rename to compileruntime/process_lib_standard/src/ohosTest/js/default/pages/index/index.hml diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.js b/compileruntime/process_lib_standard/src/ohosTest/js/default/pages/index/index.js similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.js rename to compileruntime/process_lib_standard/src/ohosTest/js/default/pages/index/index.js diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/compileruntime/process_lib_standard/src/ohosTest/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/test/ExampleJsunit.test.js rename to compileruntime/process_lib_standard/src/ohosTest/js/test/ExampleJsunit.test.js diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/test/List.test.js b/compileruntime/process_lib_standard/src/ohosTest/js/test/List.test.js similarity index 92% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/test/List.test.js rename to compileruntime/process_lib_standard/src/ohosTest/js/test/List.test.js index d21d417581975daf4033529f6c2bfc7dca43c24a..86ae9fa262b8d3fa27e4ac734dbd529d37d0b7cd 100644 --- a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/test/List.test.js +++ b/compileruntime/process_lib_standard/src/ohosTest/js/test/List.test.js @@ -1,16 +1,16 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json b/compileruntime/process_lib_standard/src/ohosTest/resources/base/element/string.json similarity index 93% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json rename to compileruntime/process_lib_standard/src/ohosTest/resources/base/element/string.json index e6620b59dd56bd464bfbff923446fc493fdc0425..757cc9dc2301c1b3f60ffe9c69f4508cf79aca06 100644 --- a/compileruntime/process_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json +++ b/compileruntime/process_lib_standard/src/ohosTest/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "app_name", - "value": "childprocess" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] +{ + "string": [ + { + "name": "app_name", + "value": "childprocess" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] } \ No newline at end of file diff --git a/compileruntime/url_lib_standard/BUILD.gn b/compileruntime/url_lib_standard/BUILD.gn index a5f48ae0fdbd1eacb09b2740b46e1f60023b8e0f..967123cbcc929b29432bf2a48625f85eaf355ede 100644 --- a/compileruntime/url_lib_standard/BUILD.gn +++ b/compileruntime/url_lib_standard/BUILD.gn @@ -10,9 +10,29 @@ # 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("url_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":url_js_assets", + ":url_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "UrlJsTest" -ohos_js_hap_suite("startup_url_js_test") { - test_hap_name = "StartupUrlJSApiTest" - hap_source_path = "hap/entry-debug-rich-unsigned.hap" + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("url_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("url_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" } diff --git a/compileruntime/url_lib_standard/Test.json b/compileruntime/url_lib_standard/Test.json index a5d217e9f346bca6fa09086e59995d4e48c808d9..7246972760202009369848a23f34724daea489d3 100644 --- a/compileruntime/url_lib_standard/Test.json +++ b/compileruntime/url_lib_standard/Test.json @@ -9,7 +9,7 @@ "kits": [ { "test-file-name": [ - "startup_url_js_test.hap" + "UrlJsTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/compileruntime/url_lib_standard/project/entry/package.json b/compileruntime/url_lib_standard/project/entry/package.json deleted file mode 100644 index 69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f..0000000000000000000000000000000000000000 --- a/compileruntime/url_lib_standard/project/entry/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/compileruntime/url_lib_standard/signature/openharmony_sx.p7b b/compileruntime/url_lib_standard/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/compileruntime/url_lib_standard/signature/openharmony_sx.p7b differ diff --git a/compileruntime/url_lib_standard/project/entry/src/main/config.json b/compileruntime/url_lib_standard/src/main/config.json similarity index 95% rename from compileruntime/url_lib_standard/project/entry/src/main/config.json rename to compileruntime/url_lib_standard/src/main/config.json index 31cf457ed8776ee292172a9ab4aebf70d6de7d4e..eded041ca18822a8db943ab7a2293fd8c32d1f85 100644 --- a/compileruntime/url_lib_standard/project/entry/src/main/config.json +++ b/compileruntime/url_lib_standard/src/main/config.json @@ -1,57 +1,57 @@ -{ - "app": { - "bundleName": "com.example.url", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.url", - "name": ".MyApplication", - "mainAbility": "com.example.url.MainAbility", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.url.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:entry_MainAbility", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": true - } - } - ] - } +{ + "app": { + "bundleName": "com.example.url", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.url", + "name": ".MyApplication", + "mainAbility": "com.example.url.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.url.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } } \ No newline at end of file diff --git a/compileruntime/url_lib_standard/project/entry/src/main/java/com/example/url/MainAbility.java b/compileruntime/url_lib_standard/src/main/java/com/example/url/MainAbility.java similarity index 96% rename from compileruntime/url_lib_standard/project/entry/src/main/java/com/example/url/MainAbility.java rename to compileruntime/url_lib_standard/src/main/java/com/example/url/MainAbility.java index ab25e441fe3c7562739c4096192b071262ab2a66..1029c01195535d7671415ad1490aa483571d41e5 100644 --- a/compileruntime/url_lib_standard/project/entry/src/main/java/com/example/url/MainAbility.java +++ b/compileruntime/url_lib_standard/src/main/java/com/example/url/MainAbility.java @@ -1,30 +1,30 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.url; - -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.url; + +import ohos.ace.ability.AceAbility; +import ohos.aafwk.content.Intent; + +public class MainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/url/MyApplication.java b/compileruntime/url_lib_standard/src/main/java/com/example/url/MyApplication.java similarity index 97% rename from compileruntime/util_lib_standard/project/entry/src/main/java/com/example/url/MyApplication.java rename to compileruntime/url_lib_standard/src/main/java/com/example/url/MyApplication.java index 8b5743ec691ee927229078e83a92bf65a2398d02..d0bd8e832c63d6b1e691f5fc58c9284982cbde3b 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/url/MyApplication.java +++ b/compileruntime/url_lib_standard/src/main/java/com/example/url/MyApplication.java @@ -1,24 +1,24 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.url; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.url; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/app.js b/compileruntime/url_lib_standard/src/main/js/default/app.js similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/app.js rename to compileruntime/url_lib_standard/src/main/js/default/app.js diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/common/images/Wallpaper.png b/compileruntime/url_lib_standard/src/main/js/default/common/images/Wallpaper.png similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/common/images/Wallpaper.png rename to compileruntime/url_lib_standard/src/main/js/default/common/images/Wallpaper.png diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/common/images/bg-tv.jpg b/compileruntime/url_lib_standard/src/main/js/default/common/images/bg-tv.jpg similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/common/images/bg-tv.jpg rename to compileruntime/url_lib_standard/src/main/js/default/common/images/bg-tv.jpg diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/i18n/en-US.json b/compileruntime/url_lib_standard/src/main/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/i18n/en-US.json rename to compileruntime/url_lib_standard/src/main/js/default/i18n/en-US.json diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json b/compileruntime/url_lib_standard/src/main/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json rename to compileruntime/url_lib_standard/src/main/js/default/i18n/zh-CN.json diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/pages/index/index.css b/compileruntime/url_lib_standard/src/main/js/default/pages/index/index.css similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/pages/index/index.css rename to compileruntime/url_lib_standard/src/main/js/default/pages/index/index.css diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/pages/index/index.hml b/compileruntime/url_lib_standard/src/main/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/pages/index/index.hml rename to compileruntime/url_lib_standard/src/main/js/default/pages/index/index.hml diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/default/pages/index/index.js b/compileruntime/url_lib_standard/src/main/js/default/pages/index/index.js similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/default/pages/index/index.js rename to compileruntime/url_lib_standard/src/main/js/default/pages/index/index.js diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js b/compileruntime/url_lib_standard/src/main/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js rename to compileruntime/url_lib_standard/src/main/js/test/ExampleJsunit.test.js diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/test/List.test.js b/compileruntime/url_lib_standard/src/main/js/test/List.test.js similarity index 97% rename from compileruntime/url_lib_standard/project/entry/src/main/js/test/List.test.js rename to compileruntime/url_lib_standard/src/main/js/test/List.test.js index dca81774825aa96e9e67b89c4d6c92d4d53b590e..8a9a35ff2dc4ccb7b55bd59545e29f4cb3785b52 100644 --- a/compileruntime/url_lib_standard/project/entry/src/main/js/test/List.test.js +++ b/compileruntime/url_lib_standard/src/main/js/test/List.test.js @@ -1,16 +1,16 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -require('./url.test.js') -require('./ExampleJsunit.test.js') +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +require('./url.test.js') +require('./ExampleJsunit.test.js') diff --git a/compileruntime/url_lib_standard/project/entry/src/main/js/test/url.test.js b/compileruntime/url_lib_standard/src/main/js/test/url.test.js similarity index 97% rename from compileruntime/url_lib_standard/project/entry/src/main/js/test/url.test.js rename to compileruntime/url_lib_standard/src/main/js/test/url.test.js index df00cd8abfbd88a30043280e045920ded47ad986..19e410b3280ea692acfa26a093ea6e6e75cfdb40 100644 --- a/compileruntime/url_lib_standard/project/entry/src/main/js/test/url.test.js +++ b/compileruntime/url_lib_standard/src/main/js/test/url.test.js @@ -1,564 +1,564 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License') - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/lite' -import Url from '@ohos.url' - -describe('Url_mxa_jk_Test', function () { - it('Url_append_test_001', 0, function () { - var that = new Url.URL('http://username:password@host:8080/directory/file?foo=1&bar=2') - var params = new Url.URLSearchParams(that.search) - params.append('ma', 'jk') - var result = params.toString() - expect(result).assertEqual('foo=1&bar=2&ma=jk') - }) - it('Url_append_test_002', 0, function () { - let that = new Url.URL('https://example.com?foo=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.append('ma 大', 'jk¥') - var result = params.toString() - expect(result).assertEqual('foo=1&bar=2&ma+%E5%A4%A7=jk%EF%BF%A5') - }) - it('Url_append_test_003', 0, function () { - let that = new Url.URL('https://example.com?foo=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.append('foo~!@#$%^&*()_+-=', 'jk') - var result = params.toString() - expect(result).assertEqual('foo=1&bar=2&foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk') - }) - it('Url_delete_test_001', 0, function () { - let that = new Url.URL('https://example.com?foo=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.delete('foo') - var result = params.toString() - expect(result).assertEqual('bar=2') - }) - it('Url_delete_test_002', 0, function () { - let that = new Url.URL('https://example.com?foo大=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.delete('foo') - var result = params.toString() - expect(result).assertEqual('foo%E5%A4%A7=1&bar=2') - }) - it('Url_delete_test_003', 0, function () { - let that = new Url.URL('https://example.com?foo大=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.delete('foo大') - var result = params.toString() - expect(result).assertEqual('bar=2') - }) - - it('Url_entries_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var i = 0; - var arr = {}; - for(var pair of params.entries()) { - arr[i] = pair[0]; - i++; - arr[i] = pair[1]; - i++; - } - expect(arr[1]).assertEqual('value1') - }) - it('Url_entries_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var i = 0; - var arr = {}; - for(var pair of params.entries()) { - arr[i] = pair[0]; - i++; - arr[i] = pair[1]; - i++; - } - expect(arr[2]).assertEqual('key2') - }) - it('Url_entries_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('foo', 'jk') - var i = 0; - var arr = {}; - for(var pair of params.entries()) { - arr[i] = pair[0]; - i++; - arr[i] = pair[1]; - i++; - } - expect(arr[5]).assertEqual('jk') - }) - - it('Url_forEach_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var arr = {}; - var i = 0; - function func(str1, str2, params) { - arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params - i++; - } - params.forEach(func) - expect(arr[0]).assertEqual('key=key1 value=value1 flag=key1=value1&key2=value2') - }) - it('Url_forEach_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var arr = {}; - var i = 0; - function func(str1, str2, params) { - arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params - i++; - } - params.forEach(func) - expect(arr[1]).assertEqual('key=key2 value=value2 flag=key1=value1&key2=value2') - }) - it('Url_forEach_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('foo', 'jk') - var arr = {}; - var i = 0; - function func(str1, str2, params) { - arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params - i++; - } - params.forEach(func) - expect(arr[2]).assertEqual('key=foo value=jk flag=key1=value1&key2=value2&foo=jk') - }) - it('Url_get_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var result = params.get('1') - expect(result).assertEqual(undefined) - }) - it('Url_get_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var result = params.get('key2') - expect(result).assertEqual('value2') - }) - it('Url_get_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('5', 'JKL') - var result = params.get('5') - expect(result).assertEqual('JKL') - }) - it('Url_getAll_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('key1', 'AAA') - var result = params.getAll('key1') - expect(result).assertEqual('value1,AAA') - }) - it('Url_getAll_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&8=DEF') - params.append('8', 'A8A') - var result = params.getAll('8') - expect(result).assertEqual('DEF,A8A') - }) - it('Url_getAll_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') - params.append('key3', 'A3A') - var result = params.getAll('key3') - expect(result).assertEqual('大,A3A') - }) - it('Url_has_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') - var result = params.has('2') - expect(result).assertEqual(false) - }) - it('Url_has_test_002', 0, function () { - let params = new Url.URLSearchParams('小=value1&key2=value2&key3=大') - var result = params.has('小') - expect(result).assertEqual(true) - }) - it('Url_has_test_003', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - params.append('¥', 'ACA') - var result = params.has('¥') - expect(result).assertEqual(true) - }) - it('Url_keys_test_001', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - var arr = {}; - var i = 0; - for (var key of params.keys()) { - arr[i] = key; - i++; - } - expect(arr[0]).assertEqual('小') - }) - it('Url_keys_test_002', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - var arr = {}; - var i = 0; - for (var key of params.keys()) { - arr[i] = key; - i++; - } - expect(arr[1]).assertEqual('¥') - }) - it('Url_keys_test_003', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - var arr = {}; - var i = 0; - for (var key of params.keys()) { - arr[i] = key; - i++; - } - expect(arr[2]).assertEqual('key3') - }) - it('Url_set_test_001', 0, function () { - let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') - params.set('11', 'CCC') - var res = params.toString() - expect(res).assertEqual('1=value1&2=value2&key3=3&11=CCC') - }) - it('Url_set_test_002', 0, function () { - let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') - params.set('10', 'BBB') - var res = params.toString() - expect(res).assertEqual('1=value1&2=value2&key3=3&10=BBB') - }) - it('Url_set_test_003', 0, function () { - let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') - params.set('ma 大', '10¥') - var res = params.toString() - expect(res).assertEqual('1=value1&2=value2&key3=3&ma+%E5%A4%A7=10%EF%BF%A5') - }) - it('Url_sort_test_001', 0, function () { - let params = new Url.URLSearchParams('1=value1&3=value3&2=key2') - params.sort() - var res = params.toString() - expect(res).assertEqual('1=value1&2=key2&3=value3') - }) - it('Url_sort_test_002', 0, function () { - let params = new Url.URLSearchParams('a=value1&c=value2&b=key2') - params.sort() - var res = params.toString() - expect(res).assertEqual('a=value1&b=key2&c=value2') - }) - it('Url_sort_test_003', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=33') - params.append('a', 'ACA') - params.sort() - var res = params.toString() - expect(res).assertEqual('a=ACA&b=33&c=value2&d=value1') - }) - it('Url_Values_test_001', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - var arr = {}; - var i = 0; - for (var value of params.values()) { - arr[i] = value; - i++; - } - expect(arr[0]).assertEqual('value1') - }) - it('Url_Values_test_002', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - var arr = {}; - var i = 0; - for (var value of params.values()) { - arr[i] = value; - i++; - } - expect(arr[1]).assertEqual('value2') - }) - it('Url_Values_test_003', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - params.append('a', 'ACA') - var arr = {}; - var i = 0; - for (var value of params.values()) { - arr[i] = value; - i++; - } - expect(arr[3]).assertEqual('ACA') - }) - it('Url_toString_test_001', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - var result = params.toString() - expect(result).assertEqual('d=value1&c=value2&b=%E5%A4%A7') - }) - it('Url_toString_test_002', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b= 大') - params.append('1 12', 'QQQ') - var result = params.toString() - expect(result).assertEqual('d=value1&c=value2&b=+%E5%A4%A7&1+12=QQQ') - }) - it('Url_toString_test_003', 0, function () { - let params = new Url.URLSearchParams('¥=)') - params.delete('5') - var result = params.toString() - expect(result).assertEqual('%EF%BF%A5=%29') - }) - //new url SearchParams - it('Url_construction_test_001', 0, function () { - let params = new Url.URLSearchParams('?user=abc&query=xyz') - var result = params.toString() - expect(result).assertEqual('user=abc&query=xyz') - }) - it('Url_construction_test_002', 0, function () { - let params = new Url.URLSearchParams({ - user: 'abc', - query: ['first', 'second'] - }) - var result = params.toString() - expect(result).assertEqual('user=abc&query=first%2Csecond') - }) - it('Url_construction_test_003', 0, function () { - let params = new Url.URLSearchParams([ - ['user', 'abc'], - ['query', 'first'], - ['query', 'second'], - ]) - var result = params.toString() - expect(result).assertEqual('user=abc&query=first&query=second') - }) - it('Url_construction_test_004', 0, function () { - const map = new Map() - map.set('user', 'abc') - map.set('query', 'xyz') - let params = new Url.URLSearchParams(map) - var result = params.toString() - expect(result).assertEqual('user=abc&query=xyz') - }) - it('Url_construction_test_004', 0, function () { - function* getQueryPairs() { - yield ['user', 'abc'] - yield ['query', 'first'] - yield ['query', 'second'] - } - let params = new Url.URLSearchParams(getQueryPairs()) - var result = params.toString() - expect(result).assertEqual('user=abc&query=first&query=second') - }) - //new url - get - it('Url_to_string_test_001', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.to_string() - expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') - }) - - it('Url_href_test_002', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.href - expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') - }) - it('Url_origin_test_003', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.origin - expect(result).assertEqual('http://host:8080') - }) - it('Url_protocol_test_004', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.protocol - expect(result).assertEqual('http:') - }) - it('Url_username_test_005', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.username - expect(result).assertEqual('username') - }) - it('Url_password_test_006', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.password - expect(result).assertEqual('password') - }) - it('Url_host_test_007', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.host - expect(result).assertEqual('host:8080') - }) - it('Url_hostname_test_008', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.hostname - expect(result).assertEqual('host') - }) - it('Url_port_test_009', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.port - expect(result).assertEqual('8080') - }) - it('Url_pathname_test_010', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result = params.pathname - expect(result).assertEqual('/directory/file') - }) - it('Url_search_test_011', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') - var result = params.search - expect(result).assertEqual('?query=qqqq') - }) - it('Url_search_test_012', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') - var result = params.search - expect(result).assertEqual('?query=pppppp') - }) - it('Url_hash_test_013', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') - var result = params.hash - expect(result).assertEqual('#fragment') - }) - //new url - set - it('Url_href_test_001', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.href = 'http://[::192.9.5.5]/ipng' - var result = params.href - expect(result).assertEqual('http://[::c009:505]/ipng') - }) - it('Url_protocol_test_002', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.protocol = 'https:' - var result = params.href - expect(result).assertEqual('https://username:password@host:8080/directory/file?query#fragment') - }) - it('Url_username_test_003', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.username = 'username1' - var result = params.href - expect(result).assertEqual('http://username1:password@host:8080/directory/file?query#fragment') - }) - it('Url_password_test_004', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.password = 'passwd' - var result = params.href - expect(result).assertEqual('http://username:passwd@host:8080/directory/file?query#fragment') - }) - - it('Url_host_test_005', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.host = 'www.baidu.com:99' - var result = params.href - expect(result).assertEqual('http://username:password@www.baidu.com:99/directory/file?query#fragment') - }) - - it('Url_hostname_test_006', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.hostname = 'www.baidu.com' - var result = params.href - expect(result).assertEqual('http://username:password@www.baidu.com:8080/directory/file?query#fragment') - }) - it('Url_port_test_007', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.port = '99' - var result = params.href - expect(result).assertEqual('http://username:password@host:99/directory/file?query#fragment') - }) - it('Url_pathname_test_008', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.pathname = '/path/ddd' - var result = params.href - expect(result).assertEqual('http://username:password@host:8080/path/ddd?query#fragment') - }) - it('Url_search_test_009', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') - params.search = '?pppppp=1234' - var result = params.href - expect(result).assertEqual('http://username:password@host:8080/directory/file?pppppp=1234#fragment') - }) - it('Url_hash_test_010', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') - params.hash = '#qwer=da' - var result = params.href - expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') - }) - //new url JSON - it('Url_toJSON_test_001', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') - var result = params.toJSON() - expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') - }) - //new url IPV6 - it('Url_IPV6_test_001', 0, function () { - let params = new Url.URL('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html') - var result = params.href - expect(result).assertEqual('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html') - }) - it('Url_IPV6_test_002', 0, function () { - let params = new Url.URL('http://[1080:0:0:0:8:800:200C:417A]/index.html') - var result = params.href - expect(result).assertEqual('http://[1080::8:800:200c:417a]/index.html') - }) - it('Url_IPV6_test_003', 0, function () { - let params = new Url.URL('http://[::FFFF:129.144.52.38]:80/index.html') - var result = params.href - expect(result).assertEqual('http://[::ffff:8190:3426]/index.html') - }) - //new url IPV4 - it('Url_IPV4_test_001', 0, function () { - let params = new Url.URL('http://0377.0xff.255.1:80/index.html') - var result = params.href - expect(result).assertEqual('http://255.255.255.1/index.html') - }) - it('Url_IPV4_test_002', 0, function () { - let params = new Url.URL('http://0377.0xff.255.g/index.html') - var result = params.href - expect(result).assertEqual('http://0377.0xff.255.g/index.html') - }) - it('Url_IPV4_test_003', 0, function () { - let params = new Url.URL('http://190.254.245.9:80/index.html') - var result = params.href - expect(result).assertEqual('http://190.254.245.9/index.html') - }) - //new url url_base - it('Url_base_test_001', 0, function () { - let params = new Url.URL('https://developer.mozilla.org',) - var result = params.href - expect(result).assertEqual('https://developer.mozilla.org/') - }) - it('Url_base_test_002', 0, function () { - let params = new Url.URL('https://developer.mozilla.org', 'flie:/developer.mozilla.org') - var result = params.href - expect(result).assertEqual('https://developer.mozilla.org/') - }) - it('Url_base_test_003', 0, function () { - let params = new Url.URL('https://developer.mozilla.org', 'ftp://www.example.com') - var result = params.href - expect(result).assertEqual('https://developer.mozilla.org/') - }) - it('Url_base_test_004', 0, function () { - let params = new Url.URL(' ', 'http://www.example.com') - var result = params.href - expect(result).assertEqual('http://www.example.com/') - }) - it('Url_base_test_005', 0, function () { - let params = new Url.URL('.', 'http://www.example.com') - var result = params.href - expect(result).assertEqual('http://www.example.com/') - }) - it('Url_base_test_006', 0, function () { - let params = new Url.URL('../h:', 'http://www.example.com') - var result = params.href - expect(result).assertEqual('http://www.example.com/h:') - }) - it('Url_base_test_007', 0, function () { - let params = new Url.URL('/sca/./path/path/../scasa/jjjjj', 'http://www.example.com') - var result = params.href - expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_008', 0, function () { - let params = new Url.URL('sca/./path/path/../scasa/jjjjj', 'http://www.example.com') - var result = params.href - expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_009', 0, function () { - let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'http://www.example.com') - var result = params.href - expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_010', 0, function () { - let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'file://www.example.com') - var result = params.href - expect(result).assertEqual('file://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_011', 0, function () { - let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'file1://www.example.com') - var result = params.href - expect(result).assertEqual('file1://www.example.com/sca/path/scasa/jjjjj') - }) +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License') + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/lite' +import Url from '@ohos.url' + +describe('Url_mxa_jk_Test', function () { + it('Url_append_test_001', 0, function () { + var that = new Url.URL('http://username:password@host:8080/directory/file?foo=1&bar=2') + var params = new Url.URLSearchParams(that.search) + params.append('ma', 'jk') + var result = params.toString() + expect(result).assertEqual('foo=1&bar=2&ma=jk') + }) + it('Url_append_test_002', 0, function () { + let that = new Url.URL('https://example.com?foo=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.append('ma 大', 'jk¥') + var result = params.toString() + expect(result).assertEqual('foo=1&bar=2&ma+%E5%A4%A7=jk%EF%BF%A5') + }) + it('Url_append_test_003', 0, function () { + let that = new Url.URL('https://example.com?foo=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.append('foo~!@#$%^&*()_+-=', 'jk') + var result = params.toString() + expect(result).assertEqual('foo=1&bar=2&foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk') + }) + it('Url_delete_test_001', 0, function () { + let that = new Url.URL('https://example.com?foo=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.delete('foo') + var result = params.toString() + expect(result).assertEqual('bar=2') + }) + it('Url_delete_test_002', 0, function () { + let that = new Url.URL('https://example.com?foo大=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.delete('foo') + var result = params.toString() + expect(result).assertEqual('foo%E5%A4%A7=1&bar=2') + }) + it('Url_delete_test_003', 0, function () { + let that = new Url.URL('https://example.com?foo大=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.delete('foo大') + var result = params.toString() + expect(result).assertEqual('bar=2') + }) + + it('Url_entries_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var i = 0; + var arr = {}; + for(var pair of params.entries()) { + arr[i] = pair[0]; + i++; + arr[i] = pair[1]; + i++; + } + expect(arr[1]).assertEqual('value1') + }) + it('Url_entries_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var i = 0; + var arr = {}; + for(var pair of params.entries()) { + arr[i] = pair[0]; + i++; + arr[i] = pair[1]; + i++; + } + expect(arr[2]).assertEqual('key2') + }) + it('Url_entries_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('foo', 'jk') + var i = 0; + var arr = {}; + for(var pair of params.entries()) { + arr[i] = pair[0]; + i++; + arr[i] = pair[1]; + i++; + } + expect(arr[5]).assertEqual('jk') + }) + + it('Url_forEach_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var arr = {}; + var i = 0; + function func(str1, str2, params) { + arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params + i++; + } + params.forEach(func) + expect(arr[0]).assertEqual('key=key1 value=value1 flag=key1=value1&key2=value2') + }) + it('Url_forEach_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var arr = {}; + var i = 0; + function func(str1, str2, params) { + arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params + i++; + } + params.forEach(func) + expect(arr[1]).assertEqual('key=key2 value=value2 flag=key1=value1&key2=value2') + }) + it('Url_forEach_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('foo', 'jk') + var arr = {}; + var i = 0; + function func(str1, str2, params) { + arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params + i++; + } + params.forEach(func) + expect(arr[2]).assertEqual('key=foo value=jk flag=key1=value1&key2=value2&foo=jk') + }) + it('Url_get_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var result = params.get('1') + expect(result).assertEqual(undefined) + }) + it('Url_get_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var result = params.get('key2') + expect(result).assertEqual('value2') + }) + it('Url_get_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('5', 'JKL') + var result = params.get('5') + expect(result).assertEqual('JKL') + }) + it('Url_getAll_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('key1', 'AAA') + var result = params.getAll('key1') + expect(result).assertEqual('value1,AAA') + }) + it('Url_getAll_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&8=DEF') + params.append('8', 'A8A') + var result = params.getAll('8') + expect(result).assertEqual('DEF,A8A') + }) + it('Url_getAll_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') + params.append('key3', 'A3A') + var result = params.getAll('key3') + expect(result).assertEqual('大,A3A') + }) + it('Url_has_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') + var result = params.has('2') + expect(result).assertEqual(false) + }) + it('Url_has_test_002', 0, function () { + let params = new Url.URLSearchParams('小=value1&key2=value2&key3=大') + var result = params.has('小') + expect(result).assertEqual(true) + }) + it('Url_has_test_003', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + params.append('¥', 'ACA') + var result = params.has('¥') + expect(result).assertEqual(true) + }) + it('Url_keys_test_001', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + var arr = {}; + var i = 0; + for (var key of params.keys()) { + arr[i] = key; + i++; + } + expect(arr[0]).assertEqual('小') + }) + it('Url_keys_test_002', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + var arr = {}; + var i = 0; + for (var key of params.keys()) { + arr[i] = key; + i++; + } + expect(arr[1]).assertEqual('¥') + }) + it('Url_keys_test_003', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + var arr = {}; + var i = 0; + for (var key of params.keys()) { + arr[i] = key; + i++; + } + expect(arr[2]).assertEqual('key3') + }) + it('Url_set_test_001', 0, function () { + let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') + params.set('11', 'CCC') + var res = params.toString() + expect(res).assertEqual('1=value1&2=value2&key3=3&11=CCC') + }) + it('Url_set_test_002', 0, function () { + let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') + params.set('10', 'BBB') + var res = params.toString() + expect(res).assertEqual('1=value1&2=value2&key3=3&10=BBB') + }) + it('Url_set_test_003', 0, function () { + let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') + params.set('ma 大', '10¥') + var res = params.toString() + expect(res).assertEqual('1=value1&2=value2&key3=3&ma+%E5%A4%A7=10%EF%BF%A5') + }) + it('Url_sort_test_001', 0, function () { + let params = new Url.URLSearchParams('1=value1&3=value3&2=key2') + params.sort() + var res = params.toString() + expect(res).assertEqual('1=value1&2=key2&3=value3') + }) + it('Url_sort_test_002', 0, function () { + let params = new Url.URLSearchParams('a=value1&c=value2&b=key2') + params.sort() + var res = params.toString() + expect(res).assertEqual('a=value1&b=key2&c=value2') + }) + it('Url_sort_test_003', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=33') + params.append('a', 'ACA') + params.sort() + var res = params.toString() + expect(res).assertEqual('a=ACA&b=33&c=value2&d=value1') + }) + it('Url_Values_test_001', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + var arr = {}; + var i = 0; + for (var value of params.values()) { + arr[i] = value; + i++; + } + expect(arr[0]).assertEqual('value1') + }) + it('Url_Values_test_002', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + var arr = {}; + var i = 0; + for (var value of params.values()) { + arr[i] = value; + i++; + } + expect(arr[1]).assertEqual('value2') + }) + it('Url_Values_test_003', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + params.append('a', 'ACA') + var arr = {}; + var i = 0; + for (var value of params.values()) { + arr[i] = value; + i++; + } + expect(arr[3]).assertEqual('ACA') + }) + it('Url_toString_test_001', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + var result = params.toString() + expect(result).assertEqual('d=value1&c=value2&b=%E5%A4%A7') + }) + it('Url_toString_test_002', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b= 大') + params.append('1 12', 'QQQ') + var result = params.toString() + expect(result).assertEqual('d=value1&c=value2&b=+%E5%A4%A7&1+12=QQQ') + }) + it('Url_toString_test_003', 0, function () { + let params = new Url.URLSearchParams('¥=)') + params.delete('5') + var result = params.toString() + expect(result).assertEqual('%EF%BF%A5=%29') + }) + //new url SearchParams + it('Url_construction_test_001', 0, function () { + let params = new Url.URLSearchParams('?user=abc&query=xyz') + var result = params.toString() + expect(result).assertEqual('user=abc&query=xyz') + }) + it('Url_construction_test_002', 0, function () { + let params = new Url.URLSearchParams({ + user: 'abc', + query: ['first', 'second'] + }) + var result = params.toString() + expect(result).assertEqual('user=abc&query=first%2Csecond') + }) + it('Url_construction_test_003', 0, function () { + let params = new Url.URLSearchParams([ + ['user', 'abc'], + ['query', 'first'], + ['query', 'second'], + ]) + var result = params.toString() + expect(result).assertEqual('user=abc&query=first&query=second') + }) + it('Url_construction_test_004', 0, function () { + const map = new Map() + map.set('user', 'abc') + map.set('query', 'xyz') + let params = new Url.URLSearchParams(map) + var result = params.toString() + expect(result).assertEqual('user=abc&query=xyz') + }) + it('Url_construction_test_004', 0, function () { + function* getQueryPairs() { + yield ['user', 'abc'] + yield ['query', 'first'] + yield ['query', 'second'] + } + let params = new Url.URLSearchParams(getQueryPairs()) + var result = params.toString() + expect(result).assertEqual('user=abc&query=first&query=second') + }) + //new url - get + it('Url_to_string_test_001', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.to_string() + expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') + }) + + it('Url_href_test_002', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.href + expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') + }) + it('Url_origin_test_003', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.origin + expect(result).assertEqual('http://host:8080') + }) + it('Url_protocol_test_004', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.protocol + expect(result).assertEqual('http:') + }) + it('Url_username_test_005', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.username + expect(result).assertEqual('username') + }) + it('Url_password_test_006', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.password + expect(result).assertEqual('password') + }) + it('Url_host_test_007', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.host + expect(result).assertEqual('host:8080') + }) + it('Url_hostname_test_008', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.hostname + expect(result).assertEqual('host') + }) + it('Url_port_test_009', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.port + expect(result).assertEqual('8080') + }) + it('Url_pathname_test_010', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result = params.pathname + expect(result).assertEqual('/directory/file') + }) + it('Url_search_test_011', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') + var result = params.search + expect(result).assertEqual('?query=qqqq') + }) + it('Url_search_test_012', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') + var result = params.search + expect(result).assertEqual('?query=pppppp') + }) + it('Url_hash_test_013', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') + var result = params.hash + expect(result).assertEqual('#fragment') + }) + //new url - set + it('Url_href_test_001', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.href = 'http://[::192.9.5.5]/ipng' + var result = params.href + expect(result).assertEqual('http://[::c009:505]/ipng') + }) + it('Url_protocol_test_002', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.protocol = 'https:' + var result = params.href + expect(result).assertEqual('https://username:password@host:8080/directory/file?query#fragment') + }) + it('Url_username_test_003', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.username = 'username1' + var result = params.href + expect(result).assertEqual('http://username1:password@host:8080/directory/file?query#fragment') + }) + it('Url_password_test_004', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.password = 'passwd' + var result = params.href + expect(result).assertEqual('http://username:passwd@host:8080/directory/file?query#fragment') + }) + + it('Url_host_test_005', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.host = 'www.baidu.com:99' + var result = params.href + expect(result).assertEqual('http://username:password@www.baidu.com:99/directory/file?query#fragment') + }) + + it('Url_hostname_test_006', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.hostname = 'www.baidu.com' + var result = params.href + expect(result).assertEqual('http://username:password@www.baidu.com:8080/directory/file?query#fragment') + }) + it('Url_port_test_007', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.port = '99' + var result = params.href + expect(result).assertEqual('http://username:password@host:99/directory/file?query#fragment') + }) + it('Url_pathname_test_008', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.pathname = '/path/ddd' + var result = params.href + expect(result).assertEqual('http://username:password@host:8080/path/ddd?query#fragment') + }) + it('Url_search_test_009', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') + params.search = '?pppppp=1234' + var result = params.href + expect(result).assertEqual('http://username:password@host:8080/directory/file?pppppp=1234#fragment') + }) + it('Url_hash_test_010', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') + params.hash = '#qwer=da' + var result = params.href + expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') + }) + //new url JSON + it('Url_toJSON_test_001', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') + var result = params.toJSON() + expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') + }) + //new url IPV6 + it('Url_IPV6_test_001', 0, function () { + let params = new Url.URL('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html') + var result = params.href + expect(result).assertEqual('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html') + }) + it('Url_IPV6_test_002', 0, function () { + let params = new Url.URL('http://[1080:0:0:0:8:800:200C:417A]/index.html') + var result = params.href + expect(result).assertEqual('http://[1080::8:800:200c:417a]/index.html') + }) + it('Url_IPV6_test_003', 0, function () { + let params = new Url.URL('http://[::FFFF:129.144.52.38]:80/index.html') + var result = params.href + expect(result).assertEqual('http://[::ffff:8190:3426]/index.html') + }) + //new url IPV4 + it('Url_IPV4_test_001', 0, function () { + let params = new Url.URL('http://0377.0xff.255.1:80/index.html') + var result = params.href + expect(result).assertEqual('http://255.255.255.1/index.html') + }) + it('Url_IPV4_test_002', 0, function () { + let params = new Url.URL('http://0377.0xff.255.g/index.html') + var result = params.href + expect(result).assertEqual('http://0377.0xff.255.g/index.html') + }) + it('Url_IPV4_test_003', 0, function () { + let params = new Url.URL('http://190.254.245.9:80/index.html') + var result = params.href + expect(result).assertEqual('http://190.254.245.9/index.html') + }) + //new url url_base + it('Url_base_test_001', 0, function () { + let params = new Url.URL('https://developer.mozilla.org',) + var result = params.href + expect(result).assertEqual('https://developer.mozilla.org/') + }) + it('Url_base_test_002', 0, function () { + let params = new Url.URL('https://developer.mozilla.org', 'flie:/developer.mozilla.org') + var result = params.href + expect(result).assertEqual('https://developer.mozilla.org/') + }) + it('Url_base_test_003', 0, function () { + let params = new Url.URL('https://developer.mozilla.org', 'ftp://www.example.com') + var result = params.href + expect(result).assertEqual('https://developer.mozilla.org/') + }) + it('Url_base_test_004', 0, function () { + let params = new Url.URL(' ', 'http://www.example.com') + var result = params.href + expect(result).assertEqual('http://www.example.com/') + }) + it('Url_base_test_005', 0, function () { + let params = new Url.URL('.', 'http://www.example.com') + var result = params.href + expect(result).assertEqual('http://www.example.com/') + }) + it('Url_base_test_006', 0, function () { + let params = new Url.URL('../h:', 'http://www.example.com') + var result = params.href + expect(result).assertEqual('http://www.example.com/h:') + }) + it('Url_base_test_007', 0, function () { + let params = new Url.URL('/sca/./path/path/../scasa/jjjjj', 'http://www.example.com') + var result = params.href + expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_008', 0, function () { + let params = new Url.URL('sca/./path/path/../scasa/jjjjj', 'http://www.example.com') + var result = params.href + expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_009', 0, function () { + let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'http://www.example.com') + var result = params.href + expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_010', 0, function () { + let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'file://www.example.com') + var result = params.href + expect(result).assertEqual('file://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_011', 0, function () { + let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'file1://www.example.com') + var result = params.href + expect(result).assertEqual('file1://www.example.com/sca/path/scasa/jjjjj') + }) }) \ No newline at end of file diff --git a/compileruntime/util_lib_standard/project/entry/src/main/resources/base/element/string.json b/compileruntime/url_lib_standard/src/main/resources/base/element/string.json similarity index 94% rename from compileruntime/util_lib_standard/project/entry/src/main/resources/base/element/string.json rename to compileruntime/url_lib_standard/src/main/resources/base/element/string.json index c0dd3a09e5dcefc69f22b5e00e92296f1c3f55a5..0bae6bd40f7360d5d818998221b199d3ec0f69c0 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/resources/base/element/string.json +++ b/compileruntime/url_lib_standard/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "entry_MainAbility" - }, - { - "name": "mainability_description", - "value": "JS_Empty Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] } \ No newline at end of file diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/app.js b/compileruntime/url_lib_standard/src/ohosTest/js/default/app.js similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/app.js rename to compileruntime/url_lib_standard/src/ohosTest/js/default/app.js diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/i18n/en-US.json b/compileruntime/url_lib_standard/src/ohosTest/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/i18n/en-US.json rename to compileruntime/url_lib_standard/src/ohosTest/js/default/i18n/en-US.json diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/i18n/zh-CN.json b/compileruntime/url_lib_standard/src/ohosTest/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/i18n/zh-CN.json rename to compileruntime/url_lib_standard/src/ohosTest/js/default/i18n/zh-CN.json diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.css b/compileruntime/url_lib_standard/src/ohosTest/js/default/pages/index/index.css similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.css rename to compileruntime/url_lib_standard/src/ohosTest/js/default/pages/index/index.css diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.hml b/compileruntime/url_lib_standard/src/ohosTest/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.hml rename to compileruntime/url_lib_standard/src/ohosTest/js/default/pages/index/index.hml diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.js b/compileruntime/url_lib_standard/src/ohosTest/js/default/pages/index/index.js similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.js rename to compileruntime/url_lib_standard/src/ohosTest/js/default/pages/index/index.js diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/compileruntime/url_lib_standard/src/ohosTest/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/js/test/ExampleJsunit.test.js rename to compileruntime/url_lib_standard/src/ohosTest/js/test/ExampleJsunit.test.js diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/test/List.test.js b/compileruntime/url_lib_standard/src/ohosTest/js/test/List.test.js similarity index 92% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/test/List.test.js rename to compileruntime/url_lib_standard/src/ohosTest/js/test/List.test.js index d21d417581975daf4033529f6c2bfc7dca43c24a..86ae9fa262b8d3fa27e4ac734dbd529d37d0b7cd 100644 --- a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/test/List.test.js +++ b/compileruntime/url_lib_standard/src/ohosTest/js/test/List.test.js @@ -1,16 +1,16 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/compileruntime/url_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json b/compileruntime/url_lib_standard/src/ohosTest/resources/base/element/string.json similarity index 93% rename from compileruntime/url_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json rename to compileruntime/url_lib_standard/src/ohosTest/resources/base/element/string.json index 3b04ea845ef2a4345f8dae4f80266b2b3eeeb1a1..2dffe5ba6503c2c0d7ddcfff2d9d03759f459947 100644 --- a/compileruntime/url_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json +++ b/compileruntime/url_lib_standard/src/ohosTest/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "app_name", - "value": "URL" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "URL" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/compileruntime/util_lib_standard/BUILD.gn b/compileruntime/util_lib_standard/BUILD.gn index b428754deb201e269df4316b9c5990a6714ed12b..cceaf8a1fa00455fe33f09e2d5b9f5b0beac5c4f 100644 --- a/compileruntime/util_lib_standard/BUILD.gn +++ b/compileruntime/util_lib_standard/BUILD.gn @@ -10,9 +10,29 @@ # 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("util_js_test") { + hap_profile = "./src/main/config.json" + deps = [ + ":util_js_assets", + ":util_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "UtilJsTest" -ohos_js_hap_suite("startup_util_js_test") { - test_hap_name = "StartupUtilJSApiTest" - hap_source_path = "hap/entry-debug-rich-unsigned.hap" + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("util_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("util_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" } diff --git a/compileruntime/util_lib_standard/Test.json b/compileruntime/util_lib_standard/Test.json index 301ce904e31aba73552e3f6b6fff1d5abb80618d..111d1ab5e2d3e7b4d8a64ea0365d15fa9f193447 100644 --- a/compileruntime/util_lib_standard/Test.json +++ b/compileruntime/util_lib_standard/Test.json @@ -9,7 +9,7 @@ "kits": [ { "test-file-name": [ - "startup_util_js_test.hap" + "UtilJsTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/compileruntime/util_lib_standard/project/entry/package.json b/compileruntime/util_lib_standard/project/entry/package.json deleted file mode 100644 index 69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f..0000000000000000000000000000000000000000 --- a/compileruntime/util_lib_standard/project/entry/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/compileruntime/util_lib_standard/signature/openharmony_sx.p7b b/compileruntime/util_lib_standard/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/compileruntime/util_lib_standard/signature/openharmony_sx.p7b differ diff --git a/compileruntime/process_lib_standard/project/entry/src/main/config.json b/compileruntime/util_lib_standard/src/main/config.json similarity index 95% rename from compileruntime/process_lib_standard/project/entry/src/main/config.json rename to compileruntime/util_lib_standard/src/main/config.json index f3773ec2f0f5dea54ee945b3a7e23a50d9dba61e..75d1ac14458c1ede210bf40739cb9c9fc80e74b4 100644 --- a/compileruntime/process_lib_standard/project/entry/src/main/config.json +++ b/compileruntime/util_lib_standard/src/main/config.json @@ -1,57 +1,57 @@ -{ - "app": { - "bundleName": "com.example.childprocess", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.childprocess", - "name": ".MyApplication", - "mainAbility": "com.example.childprocess.MainAbility", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "name": "com.example.childprocess.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "label": "$string:entry_MainAbility", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": true - } - } - ] - } +{ + "app": { + "bundleName": "com.example.childprocess", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.childprocess", + "name": ".MyApplication", + "mainAbility": "com.example.childprocess.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "name": "com.example.childprocess.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } } \ No newline at end of file diff --git a/compileruntime/process_lib_standard/project/entry/src/main/java/com/example/childprocess/MainAbility.java b/compileruntime/util_lib_standard/src/main/java/com/example/childprocess/MainAbility.java similarity index 96% rename from compileruntime/process_lib_standard/project/entry/src/main/java/com/example/childprocess/MainAbility.java rename to compileruntime/util_lib_standard/src/main/java/com/example/childprocess/MainAbility.java index 1bc0c4d53723f9549e7fd388dc64fe12c460e128..dbdddf742e23f2568178756f1cea558603671535 100644 --- a/compileruntime/process_lib_standard/project/entry/src/main/java/com/example/childprocess/MainAbility.java +++ b/compileruntime/util_lib_standard/src/main/java/com/example/childprocess/MainAbility.java @@ -1,31 +1,31 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.childprocess; - -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.childprocess; + +import ohos.ace.ability.AceAbility; +import ohos.aafwk.content.Intent; + +public class MainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/compileruntime/process_lib_standard/project/entry/src/main/java/com/example/childprocess/MyApplication.java b/compileruntime/util_lib_standard/src/main/java/com/example/childprocess/MyApplication.java similarity index 97% rename from compileruntime/process_lib_standard/project/entry/src/main/java/com/example/childprocess/MyApplication.java rename to compileruntime/util_lib_standard/src/main/java/com/example/childprocess/MyApplication.java index b27ffa96e3bb28be14523100030474a1398ab5e9..bf24a9676c68a8c8fe00508525160c66d0378e80 100644 --- a/compileruntime/process_lib_standard/project/entry/src/main/java/com/example/childprocess/MyApplication.java +++ b/compileruntime/util_lib_standard/src/main/java/com/example/childprocess/MyApplication.java @@ -1,25 +1,25 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.example.childprocess; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.childprocess; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/url/MainAbility.java b/compileruntime/util_lib_standard/src/main/java/com/example/url/MainAbility.java similarity index 96% rename from compileruntime/util_lib_standard/project/entry/src/main/java/com/example/url/MainAbility.java rename to compileruntime/util_lib_standard/src/main/java/com/example/url/MainAbility.java index ab25e441fe3c7562739c4096192b071262ab2a66..1029c01195535d7671415ad1490aa483571d41e5 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/java/com/example/url/MainAbility.java +++ b/compileruntime/util_lib_standard/src/main/java/com/example/url/MainAbility.java @@ -1,30 +1,30 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.url; - -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.url; + +import ohos.ace.ability.AceAbility; +import ohos.aafwk.content.Intent; + +public class MainAbility extends AceAbility { + @Override + public void onStart(Intent intent) { + super.onStart(intent); + } + + @Override + public void onStop() { + super.onStop(); + } +} diff --git a/compileruntime/url_lib_standard/project/entry/src/main/java/com/example/url/MyApplication.java b/compileruntime/util_lib_standard/src/main/java/com/example/url/MyApplication.java similarity index 97% rename from compileruntime/url_lib_standard/project/entry/src/main/java/com/example/url/MyApplication.java rename to compileruntime/util_lib_standard/src/main/java/com/example/url/MyApplication.java index 8b5743ec691ee927229078e83a92bf65a2398d02..d0bd8e832c63d6b1e691f5fc58c9284982cbde3b 100644 --- a/compileruntime/url_lib_standard/project/entry/src/main/java/com/example/url/MyApplication.java +++ b/compileruntime/util_lib_standard/src/main/java/com/example/url/MyApplication.java @@ -1,24 +1,24 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.example.url; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.url; + +import ohos.aafwk.ability.AbilityPackage; + +public class MyApplication extends AbilityPackage { + @Override + public void onInitialize() { + super.onInitialize(); + } +} diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/app.js b/compileruntime/util_lib_standard/src/main/js/default/app.js similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/app.js rename to compileruntime/util_lib_standard/src/main/js/default/app.js diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/common/images/Wallpaper.png b/compileruntime/util_lib_standard/src/main/js/default/common/images/Wallpaper.png similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/common/images/Wallpaper.png rename to compileruntime/util_lib_standard/src/main/js/default/common/images/Wallpaper.png diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/common/images/bg-tv.jpg b/compileruntime/util_lib_standard/src/main/js/default/common/images/bg-tv.jpg similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/common/images/bg-tv.jpg rename to compileruntime/util_lib_standard/src/main/js/default/common/images/bg-tv.jpg diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/i18n/en-US.json b/compileruntime/util_lib_standard/src/main/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/i18n/en-US.json rename to compileruntime/util_lib_standard/src/main/js/default/i18n/en-US.json diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json b/compileruntime/util_lib_standard/src/main/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json rename to compileruntime/util_lib_standard/src/main/js/default/i18n/zh-CN.json diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/pages/index/index.css b/compileruntime/util_lib_standard/src/main/js/default/pages/index/index.css similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/pages/index/index.css rename to compileruntime/util_lib_standard/src/main/js/default/pages/index/index.css diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/pages/index/index.hml b/compileruntime/util_lib_standard/src/main/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/pages/index/index.hml rename to compileruntime/util_lib_standard/src/main/js/default/pages/index/index.hml diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/default/pages/index/index.js b/compileruntime/util_lib_standard/src/main/js/default/pages/index/index.js similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/default/pages/index/index.js rename to compileruntime/util_lib_standard/src/main/js/default/pages/index/index.js diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js b/compileruntime/util_lib_standard/src/main/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js rename to compileruntime/util_lib_standard/src/main/js/test/ExampleJsunit.test.js diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/test/List.test.js b/compileruntime/util_lib_standard/src/main/js/test/List.test.js similarity index 93% rename from compileruntime/util_lib_standard/project/entry/src/main/js/test/List.test.js rename to compileruntime/util_lib_standard/src/main/js/test/List.test.js index 78c997a16242681effc14303e0b26178220ce38e..e4726ba94e7d3fefb579529084da7329a3a4e292 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/js/test/List.test.js +++ b/compileruntime/util_lib_standard/src/main/js/test/List.test.js @@ -1,17 +1,17 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -require('./ExampleJsunit.test.js') +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require('./ExampleJsunit.test.js') require('./TextCodr.test.js') \ No newline at end of file diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/test/TextCodr.test.js b/compileruntime/util_lib_standard/src/main/js/test/TextCodr.test.js similarity index 96% rename from compileruntime/util_lib_standard/project/entry/src/main/js/test/TextCodr.test.js rename to compileruntime/util_lib_standard/src/main/js/test/TextCodr.test.js index 147a1d7c1a2bada530cbcebd5f8807eb3f586ec6..9026eca17b6ff0d4d5c27b3f64392fcf5e0f7fe7 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/js/test/TextCodr.test.js +++ b/compileruntime/util_lib_standard/src/main/js/test/TextCodr.test.js @@ -1,449 +1,449 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License'); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' -import util from '@ohos.util' -describe('textEncoderTest', function () { - it('util_printf_test_001', 0, function () { - var format = "%i,%s"; - var value1 = 1.5; - var value2 = "qwer"; - var value3 = 15; - var result = util.printf(format, value1, value2, value3); - expect(result).assertEqual("1,qwer 15"); - }) - - it('util_printf_test_002', 0, function () { - var format = "%O"; - var value = { name: 'jack', age: 15 }; - var result = util.printf(format, value); - expect(result).assertEqual("{ name: 'jack' ,age: 15 }\n"); - }) - - it('util_printf_test_003', 0, function () { - var format = "%o"; - var value = [1, 2, 3]; - var result = util.printf(format, value); - var res = '[ 1, 2, 3, [length]: 3 ]' - expect(result).assertEqual(' [ 1, 2, 3, [length]: 3 ]'); - }) - - it('util_printf_test_004', 0, function () { - var format = "%s,%s,%s"; - var value1 = "1.5"; - var value2 = "qwer"; - var result = util.printf(format, value1, value2); - expect(result).assertEqual('1.5,qwer,%s'); - }) - - it('util_getErrorString_test_001', 0, async function () { - var errnum = 10; - var result = util.getErrorString(errnum); - expect(result).assertEqual('No child process'); - }) - - it('util_getErrorString_test_002', 0, async function () { - console.log('--SK-- util_getErrorString_test_002'); - var errnum = 0; - var result = util.getErrorString(errnum); - expect(result).assertEqual('No error information'); - }) - - it('util_getErrorString_test_003', 0, async function () { - var errnum = -1; - var result = util.getErrorString(errnum); - expect(result).assertEqual('No error information'); - }) - - it('util_promisewrapper_test_002', 0, async function () { - function aysnFun(str1, str2, callback) { - if (typeof str1 === 'string' && typeof str1 === 'string') { - callback(null, str1 + str2); - } else { - callback('type err'); - } - } - let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); - newPromiseObj.then(res => { - expect(res).strictEqual('HelloWorld'); - }) - }) - - it('util_promisewrapper_test_003', 0, async function () { - function aysnFun(str1, str2, callback) { - if (typeof str1 === 'string' && typeof str1 === 'string') { - callback(null, str1 + str2); - } else { - callback('type err'); - } - } - let newPromiseObj = util.promiseWrapper(aysnFun)([1, 2], 'World'); - newPromiseObj.catch(err => { - expect(err).strictEqual('type err'); - }) - }) - - it('util_promisewrapper_test_004', 0, async function () { - const a = util.promiseWrapper(function() {}); - const b = util.promiseWrapper(a); - expect(a).strictEqual(b); - }) - - it('util_promisewrapper_test_005', 0, async function () { - let errToThrow; - const thrower = util.promiseWrapper(function(a, b, c, cb) { - errToThrow = new Error(); - throw errToThrow; - }); - thrower(1, 2, 3).catch(err => { - expect(err).strictEqual(errToThrow); - }) - }) - - it('util_promisewrapper_test_006', 0, async function () { - const err = new Error(); - const a = util.promiseWrapper((cb) => cb(err))(); - const b = util.promiseWrapper(() => {throw err;})(); - Promise.all([ - a.then(e => { - expect(e).strictEqual(err); - }), - b.then(e => { - expect(e).strictEqual(err); - }) - ]); - }) - - it('util_promisewrapper_test_007', 0, async function () { - const err = new Error('callback with the error.'); - const stack = err.stack; - const fn = util.promiseWrapper(function(cb) { - cb(null); - cb(err); - }); - (async () => { - await fn(); - await Promise.resolve(); - return expect(stack).strictEqual(err.stack); - })(); - }) - - it('util_promisewrapper_test_008', 0, async function () { - function fn(err, val, callback) { - callback(err, val); - } - (async () => { - const value = await util.promiseWrapper(fn)(null, 42); - expect(value).strictEqual(42); - })(); - }) - - it('util_callbackWrapper_test_001', 0, async function () { - const promiseFn = [1, 2]; - try { - util.callbackWrapper(promiseFn); - } catch(e) { - expect(e.message).strictEqual('original is not function'); - } - }) - - it('util_callbackWrapper_test_002', 0, async function () { - async function promiseFn() { - return Promise.resolve('value'); - }; - var cb = util.callbackWrapper(promiseFn); - cb((err, ret) => { - expect(err).strictEqual(null); - expect(ret).strictEqual('value'); - }) - }) - - it('util_callbackWrapper_test_003', 0, async function () { - async function promiseFn() { - return 42; - }; - var cb = util.callbackWrapper(promiseFn); - cb((err, ret) => { - expect(err).strictEqual(null); - expect(ret).strictEqual(42); - }) - }) - - it('util_callbackWrapper_test_004', 0, async function () { - async function promiseFn() { - return Promise.reject('value'); - }; - var cb = util.callbackWrapper(promiseFn); - cb((err, ret) => { - expect(err).strictEqual('value'); - expect(ret).strictEqual(undefined); - }) - }) - - it('util_callbackWrapper_test_005', 0, async function () { - async function promiseFn(a, b) { - return a + b; - }; - var cb = util.callbackWrapper(promiseFn); - cb(1, 2, (err, ret) => { - expect(err).strictEqual(null); - expect(ret).strictEqual(3); - }) - }) - - it('util_callbackWrapper_test_006', 0, async function () { - async function promiseFn(){ - return null; - }; - var cb = util.callbackWrapper(promiseFn); - try { - cb([1, 2]) - } catch(err) { - expect(err.message).strictEqual('maybe is not function'); - } - }) - - it('encoding_test_001', 0, function () { - var that = new util.TextDecoder('utf-8', { ignoreBOM : true }) - var retStr = that.encoding - expect(retStr).assertEqual('utf-8') - }) - - // encoding test - it('encoding_test_002', 0, function () { - var that = new util.TextDecoder('utf-16le') - var encodingStr = that.encoding - expect(encodingStr).assertEqual('utf-16le') - }) - - it('encoding_test_003', 0, function () { - var that = new util.TextDecoder('utf-16be') - var encodingStr = that.encoding - expect(encodingStr).assertEqual('utf-16be') - }) - - // fatal test - it('fatal_test_001', 0, function () { - var that = new util.TextDecoder('utf-16be', { fatal : true }) - var fatalStr = that.fatal - expect(fatalStr).assertEqual(true) - }) - - it('fatal_test_002', 0, function () { - var that = new util.TextDecoder('utf-16be', { fatal : false }) - var fatalStr = that.fatal - expect(fatalStr).assertEqual(false) - }) - - it('fatal_test_003', 0, function () { - var that = new util.TextDecoder('utf-16be') - var fatalStr = that.fatal - expect(fatalStr).assertEqual(false) - }) - - it('fatal_test_004', 0, function () { - var that = new util.TextDecoder('utf-8') - var fatalStr = that.fatal - expect(fatalStr).assertEqual(false) - }) - - // ignoreBOM test - it('ignoreBOM_test_001', 0, function () { - var that = new util.TextDecoder('utf-16be', { ignoreBOM : true }) - var ignoreBOMStr = that.ignoreBOM - expect(ignoreBOMStr).assertEqual(true) - }) - - it('ignoreBOM_test_002', 0, function () { - var that = new util.TextDecoder('utf-16be', { ignoreBOM : false }) - var ignoreBOMStr = that.ignoreBOM - expect(ignoreBOMStr).assertEqual(false) - }) - - it('ignoreBOM_test_003', 0, function () { - var that = new util.TextDecoder('utf-16be') - var ignoreBOMStr = that.ignoreBOM - expect(ignoreBOMStr).assertEqual(false) - }) - - it('ignoreBOM_test_004', 0, function () { - var that = new util.TextDecoder('utf-8') - var ignoreBOMStr = that.ignoreBOM - expect(ignoreBOMStr).assertEqual(false) - }) - - it('decode_test_001', 0, function () { - var that = new util.TextDecoder('utf-8'); - var arr = new Uint8Array(3); - for (var i = 0; i < 3; i++) { - arr[i] = 0x61 + i; - } - var retStr = that.decode(arr); - var rel = 'abc'; - expect(retStr).assertEqual(rel); - }) - - it('decode_test_002', 0, function () { - var that = new util.TextDecoder('utf-16le') - var arr = new Uint8Array(6) - arr[0] = 0x61; - arr[1] = 0x00; - arr[2] = 0x62; - arr[3] = 0x00; - arr[4] = 0x63; - arr[5] = 0x00; - var retStr = that.decode(arr) - var rel = 'abc' - expect(retStr).assertEqual(rel) - }) - - it('decode_test_003', 0, function () { - var that = new util.TextDecoder('utf-16be'); - var arr = new Uint8Array(6); - arr[0] = 0x00; - arr[1] = 0x61; - arr[2] = 0x00; - arr[3] = 0x62; - arr[4] = 0x00; - arr[5] = 0x63; - var retStr = that.decode(arr); - var rel = 'abc' - expect(retStr).assertEqual(rel); - }) - - it('decode_test_004', 0, function () { - var that = new util.TextDecoder('utf-8', { ignoreBOM : true }) - var arr = new Uint8Array(6) - arr[0] = 0xEF; - arr[1] = 0xBB; - arr[2] = 0xBF; - arr[3] = 0x61; - arr[4] = 0x62; - arr[5] = 0x63; - var retStr = that.decode(arr, {stream:true}) - var BOM = '\uFEFF' - var rel = 'abc' - var re = BOM + rel - expect(retStr).assertEqual(re); - }) - - it('decode_test_005', 0, function () { - var that = new util.TextDecoder('utf-16le', { ignoreBOM : false }) - var arr = new Uint8Array(8) - arr[0] = 0xFF; - arr[1] = 0xFE; - arr[2] = 0x61; - arr[3] = 0x00; - arr[4] = 0x62; - arr[5] = 0x00 - arr[6] = 0x63; - arr[7] = 0x00; - var retStr = that.decode(arr, { stream : false }) - var BOM = '\uFEFF' - var rel = 'abc' - var re = BOM + rel - expect(retStr).assertEqual(re) - }) - - // encode test - it('test_get_encoding', 0, function () { - var that = new util.TextEncoder() - var str = that.encoding - expect(str).assertEqual('utf-8') - }) - - it('test_encode_01', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(20) - var result = new Uint8Array(buffer) - result = that.encode('\uD800楼楼') - expect(result[5]).assertEqual(188) - }) - - it('test_encode_02', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(20) - var result = new Uint8Array(buffer) - result = that.encode('a\uD800楼楼') - expect(result[0]).assertEqual(0x61) - }) - - it('test_encode_03', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(20) - var result = new Uint8Array(buffer) - result = that.encode('abc\uD800楼楼') - expect(result[1]).assertEqual(0x62) - }) - - it('test_encode_04', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(20) - var result = new Uint8Array(buffer) - result = that.encode('123\uD800楼楼') - expect(result[0]).assertEqual(49) - expect(result[9]).assertEqual(230) - }) - - it('test_encodeInto_01', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(20) - var dest = new Uint8Array(buffer, 0, 13) - var result = new Uint32Array(20) - result = that.encodeInto('\uD800A\uDF06A楼HiA', dest) - expect(result.read).assertEqual(7) - expect(result.written).assertEqual(13) - }) - - it('test_encodeInto_02', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(6) - var dest = new Uint8Array(buffer) - var result = new Object() - result = that.encodeInto('abc\u2603d', dest) - expect(result.read).assertEqual(4) - expect(result.written).assertEqual(6) - }) - - it('test_encodeInto_03', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(4) - var dest = new Uint8Array(buffer) - var result = new Object() - result = that.encodeInto('abcd', dest) - expect(result.read).assertEqual(4) - expect(result.written).assertEqual(4) - }) - - it('test_encodeInto_04', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(4) - var dest = new Uint8Array(buffer) - var result = new Object() - result = that.encodeInto('12345', dest) - expect(result.read).assertEqual(4) - expect(result.written).assertEqual(4) - }) - - it('test_encodeInto_05', 0, function () { - var that = new util.TextEncoder() - var buffer = new ArrayBuffer(4) - var dest = new Uint8Array(buffer) - var result = new Object() - result = that.encodeInto('123 4*!@#', dest) - expect(result.read).assertEqual(4) - expect(result.written).assertEqual(4) - }) +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +import util from '@ohos.util' +describe('textEncoderTest', function () { + it('util_printf_test_001', 0, function () { + var format = "%i,%s"; + var value1 = 1.5; + var value2 = "qwer"; + var value3 = 15; + var result = util.printf(format, value1, value2, value3); + expect(result).assertEqual("1,qwer 15"); + }) + + it('util_printf_test_002', 0, function () { + var format = "%O"; + var value = { name: 'jack', age: 15 }; + var result = util.printf(format, value); + expect(result).assertEqual("{ name: 'jack' ,age: 15 }\n"); + }) + + it('util_printf_test_003', 0, function () { + var format = "%o"; + var value = [1, 2, 3]; + var result = util.printf(format, value); + var res = '[ 1, 2, 3, [length]: 3 ]' + expect(result).assertEqual(' [ 1, 2, 3, [length]: 3 ]'); + }) + + it('util_printf_test_004', 0, function () { + var format = "%s,%s,%s"; + var value1 = "1.5"; + var value2 = "qwer"; + var result = util.printf(format, value1, value2); + expect(result).assertEqual('1.5,qwer,%s'); + }) + + it('util_getErrorString_test_001', 0, async function () { + var errnum = 10; + var result = util.getErrorString(errnum); + expect(result).assertEqual('No child process'); + }) + + it('util_getErrorString_test_002', 0, async function () { + console.log('--SK-- util_getErrorString_test_002'); + var errnum = 0; + var result = util.getErrorString(errnum); + expect(result).assertEqual('No error information'); + }) + + it('util_getErrorString_test_003', 0, async function () { + var errnum = -1; + var result = util.getErrorString(errnum); + expect(result).assertEqual('No error information'); + }) + + it('util_promisewrapper_test_002', 0, async function () { + function aysnFun(str1, str2, callback) { + if (typeof str1 === 'string' && typeof str1 === 'string') { + callback(null, str1 + str2); + } else { + callback('type err'); + } + } + let newPromiseObj = util.promiseWrapper(aysnFun)("Hello", 'World'); + newPromiseObj.then(res => { + expect(res).strictEqual('HelloWorld'); + }) + }) + + it('util_promisewrapper_test_003', 0, async function () { + function aysnFun(str1, str2, callback) { + if (typeof str1 === 'string' && typeof str1 === 'string') { + callback(null, str1 + str2); + } else { + callback('type err'); + } + } + let newPromiseObj = util.promiseWrapper(aysnFun)([1, 2], 'World'); + newPromiseObj.catch(err => { + expect(err).strictEqual('type err'); + }) + }) + + it('util_promisewrapper_test_004', 0, async function () { + const a = util.promiseWrapper(function() {}); + const b = util.promiseWrapper(a); + expect(a).strictEqual(b); + }) + + it('util_promisewrapper_test_005', 0, async function () { + let errToThrow; + const thrower = util.promiseWrapper(function(a, b, c, cb) { + errToThrow = new Error(); + throw errToThrow; + }); + thrower(1, 2, 3).catch(err => { + expect(err).strictEqual(errToThrow); + }) + }) + + it('util_promisewrapper_test_006', 0, async function () { + const err = new Error(); + const a = util.promiseWrapper((cb) => cb(err))(); + const b = util.promiseWrapper(() => {throw err;})(); + Promise.all([ + a.then(e => { + expect(e).strictEqual(err); + }), + b.then(e => { + expect(e).strictEqual(err); + }) + ]); + }) + + it('util_promisewrapper_test_007', 0, async function () { + const err = new Error('callback with the error.'); + const stack = err.stack; + const fn = util.promiseWrapper(function(cb) { + cb(null); + cb(err); + }); + (async () => { + await fn(); + await Promise.resolve(); + return expect(stack).strictEqual(err.stack); + })(); + }) + + it('util_promisewrapper_test_008', 0, async function () { + function fn(err, val, callback) { + callback(err, val); + } + (async () => { + const value = await util.promiseWrapper(fn)(null, 42); + expect(value).strictEqual(42); + })(); + }) + + it('util_callbackWrapper_test_001', 0, async function () { + const promiseFn = [1, 2]; + try { + util.callbackWrapper(promiseFn); + } catch(e) { + expect(e.message).strictEqual('original is not function'); + } + }) + + it('util_callbackWrapper_test_002', 0, async function () { + async function promiseFn() { + return Promise.resolve('value'); + }; + var cb = util.callbackWrapper(promiseFn); + cb((err, ret) => { + expect(err).strictEqual(null); + expect(ret).strictEqual('value'); + }) + }) + + it('util_callbackWrapper_test_003', 0, async function () { + async function promiseFn() { + return 42; + }; + var cb = util.callbackWrapper(promiseFn); + cb((err, ret) => { + expect(err).strictEqual(null); + expect(ret).strictEqual(42); + }) + }) + + it('util_callbackWrapper_test_004', 0, async function () { + async function promiseFn() { + return Promise.reject('value'); + }; + var cb = util.callbackWrapper(promiseFn); + cb((err, ret) => { + expect(err).strictEqual('value'); + expect(ret).strictEqual(undefined); + }) + }) + + it('util_callbackWrapper_test_005', 0, async function () { + async function promiseFn(a, b) { + return a + b; + }; + var cb = util.callbackWrapper(promiseFn); + cb(1, 2, (err, ret) => { + expect(err).strictEqual(null); + expect(ret).strictEqual(3); + }) + }) + + it('util_callbackWrapper_test_006', 0, async function () { + async function promiseFn(){ + return null; + }; + var cb = util.callbackWrapper(promiseFn); + try { + cb([1, 2]) + } catch(err) { + expect(err.message).strictEqual('maybe is not function'); + } + }) + + it('encoding_test_001', 0, function () { + var that = new util.TextDecoder('utf-8', { ignoreBOM : true }) + var retStr = that.encoding + expect(retStr).assertEqual('utf-8') + }) + + // encoding test + it('encoding_test_002', 0, function () { + var that = new util.TextDecoder('utf-16le') + var encodingStr = that.encoding + expect(encodingStr).assertEqual('utf-16le') + }) + + it('encoding_test_003', 0, function () { + var that = new util.TextDecoder('utf-16be') + var encodingStr = that.encoding + expect(encodingStr).assertEqual('utf-16be') + }) + + // fatal test + it('fatal_test_001', 0, function () { + var that = new util.TextDecoder('utf-16be', { fatal : true }) + var fatalStr = that.fatal + expect(fatalStr).assertEqual(true) + }) + + it('fatal_test_002', 0, function () { + var that = new util.TextDecoder('utf-16be', { fatal : false }) + var fatalStr = that.fatal + expect(fatalStr).assertEqual(false) + }) + + it('fatal_test_003', 0, function () { + var that = new util.TextDecoder('utf-16be') + var fatalStr = that.fatal + expect(fatalStr).assertEqual(false) + }) + + it('fatal_test_004', 0, function () { + var that = new util.TextDecoder('utf-8') + var fatalStr = that.fatal + expect(fatalStr).assertEqual(false) + }) + + // ignoreBOM test + it('ignoreBOM_test_001', 0, function () { + var that = new util.TextDecoder('utf-16be', { ignoreBOM : true }) + var ignoreBOMStr = that.ignoreBOM + expect(ignoreBOMStr).assertEqual(true) + }) + + it('ignoreBOM_test_002', 0, function () { + var that = new util.TextDecoder('utf-16be', { ignoreBOM : false }) + var ignoreBOMStr = that.ignoreBOM + expect(ignoreBOMStr).assertEqual(false) + }) + + it('ignoreBOM_test_003', 0, function () { + var that = new util.TextDecoder('utf-16be') + var ignoreBOMStr = that.ignoreBOM + expect(ignoreBOMStr).assertEqual(false) + }) + + it('ignoreBOM_test_004', 0, function () { + var that = new util.TextDecoder('utf-8') + var ignoreBOMStr = that.ignoreBOM + expect(ignoreBOMStr).assertEqual(false) + }) + + it('decode_test_001', 0, function () { + var that = new util.TextDecoder('utf-8'); + var arr = new Uint8Array(3); + for (var i = 0; i < 3; i++) { + arr[i] = 0x61 + i; + } + var retStr = that.decode(arr); + var rel = 'abc'; + expect(retStr).assertEqual(rel); + }) + + it('decode_test_002', 0, function () { + var that = new util.TextDecoder('utf-16le') + var arr = new Uint8Array(6) + arr[0] = 0x61; + arr[1] = 0x00; + arr[2] = 0x62; + arr[3] = 0x00; + arr[4] = 0x63; + arr[5] = 0x00; + var retStr = that.decode(arr) + var rel = 'abc' + expect(retStr).assertEqual(rel) + }) + + it('decode_test_003', 0, function () { + var that = new util.TextDecoder('utf-16be'); + var arr = new Uint8Array(6); + arr[0] = 0x00; + arr[1] = 0x61; + arr[2] = 0x00; + arr[3] = 0x62; + arr[4] = 0x00; + arr[5] = 0x63; + var retStr = that.decode(arr); + var rel = 'abc' + expect(retStr).assertEqual(rel); + }) + + it('decode_test_004', 0, function () { + var that = new util.TextDecoder('utf-8', { ignoreBOM : true }) + var arr = new Uint8Array(6) + arr[0] = 0xEF; + arr[1] = 0xBB; + arr[2] = 0xBF; + arr[3] = 0x61; + arr[4] = 0x62; + arr[5] = 0x63; + var retStr = that.decode(arr, {stream:true}) + var BOM = '\uFEFF' + var rel = 'abc' + var re = BOM + rel + expect(retStr).assertEqual(re); + }) + + it('decode_test_005', 0, function () { + var that = new util.TextDecoder('utf-16le', { ignoreBOM : false }) + var arr = new Uint8Array(8) + arr[0] = 0xFF; + arr[1] = 0xFE; + arr[2] = 0x61; + arr[3] = 0x00; + arr[4] = 0x62; + arr[5] = 0x00 + arr[6] = 0x63; + arr[7] = 0x00; + var retStr = that.decode(arr, { stream : false }) + var BOM = '\uFEFF' + var rel = 'abc' + var re = BOM + rel + expect(retStr).assertEqual(re) + }) + + // encode test + it('test_get_encoding', 0, function () { + var that = new util.TextEncoder() + var str = that.encoding + expect(str).assertEqual('utf-8') + }) + + it('test_encode_01', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(20) + var result = new Uint8Array(buffer) + result = that.encode('\uD800楼楼') + expect(result[5]).assertEqual(188) + }) + + it('test_encode_02', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(20) + var result = new Uint8Array(buffer) + result = that.encode('a\uD800楼楼') + expect(result[0]).assertEqual(0x61) + }) + + it('test_encode_03', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(20) + var result = new Uint8Array(buffer) + result = that.encode('abc\uD800楼楼') + expect(result[1]).assertEqual(0x62) + }) + + it('test_encode_04', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(20) + var result = new Uint8Array(buffer) + result = that.encode('123\uD800楼楼') + expect(result[0]).assertEqual(49) + expect(result[9]).assertEqual(230) + }) + + it('test_encodeInto_01', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(20) + var dest = new Uint8Array(buffer, 0, 13) + var result = new Uint32Array(20) + result = that.encodeInto('\uD800A\uDF06A楼HiA', dest) + expect(result.read).assertEqual(7) + expect(result.written).assertEqual(13) + }) + + it('test_encodeInto_02', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(6) + var dest = new Uint8Array(buffer) + var result = new Object() + result = that.encodeInto('abc\u2603d', dest) + expect(result.read).assertEqual(4) + expect(result.written).assertEqual(6) + }) + + it('test_encodeInto_03', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(4) + var dest = new Uint8Array(buffer) + var result = new Object() + result = that.encodeInto('abcd', dest) + expect(result.read).assertEqual(4) + expect(result.written).assertEqual(4) + }) + + it('test_encodeInto_04', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(4) + var dest = new Uint8Array(buffer) + var result = new Object() + result = that.encodeInto('12345', dest) + expect(result.read).assertEqual(4) + expect(result.written).assertEqual(4) + }) + + it('test_encodeInto_05', 0, function () { + var that = new util.TextEncoder() + var buffer = new ArrayBuffer(4) + var dest = new Uint8Array(buffer) + var result = new Object() + result = that.encodeInto('123 4*!@#', dest) + expect(result.read).assertEqual(4) + expect(result.written).assertEqual(4) + }) }) \ No newline at end of file diff --git a/compileruntime/util_lib_standard/project/entry/src/main/js/test/url.test.js b/compileruntime/util_lib_standard/src/main/js/test/url.test.js similarity index 97% rename from compileruntime/util_lib_standard/project/entry/src/main/js/test/url.test.js rename to compileruntime/util_lib_standard/src/main/js/test/url.test.js index 0c9363cd0948e897e101a44f8b99839e6fb0645f..fe429b9e678525777005525dcb31b1ba91e54fcf 100644 --- a/compileruntime/util_lib_standard/project/entry/src/main/js/test/url.test.js +++ b/compileruntime/util_lib_standard/src/main/js/test/url.test.js @@ -1,564 +1,564 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the 'License') - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an 'AS IS' BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/lite' -import Url from '@ohos.url' - -describe('Url_mxa_jk_Test', function () { - it('Url_append_test_001', 0, function () { - var that = new Url.URL('http://username:password@host:8080/directory/file?foo=1&bar=2') - var params = new Url.URLSearchParams(that.search) - params.append('ma', 'jk') - var result = params.toString() - expect(result).assertEqual('foo=1&bar=2&ma=jk') - }) - it('Url_append_test_002', 0, function () { - let that = new Url.URL('https://example.com?foo=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.append('ma 大', 'jk¥') - var result = params.toString() - expect(result).assertEqual('foo=1&bar=2&ma+%E5%A4%A7=jk%EF%BF%A5') - }) - it('Url_append_test_003', 0, function () { - let that = new Url.URL('https://example.com?foo=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.append('foo~!@#$%^&*()_+-=','jk') - var result = params.toString() - expect(result).assertEqual('foo=1&bar=2&foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk') - }) - it('Url_delete_test_001', 0, function () { - let that = new Url.URL('https://example.com?foo=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.delete('foo') - var result = params.toString() - expect(result).assertEqual('bar=2') - }) - it('Url_delete_test_002', 0, function () { - let that = new Url.URL('https://example.com?foo大=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.delete('foo') - var result = params.toString() - expect(result).assertEqual('foo%E5%A4%A7=1&bar=2') - }) - it('Url_delete_test_003', 0, function () { - let that = new Url.URL('https://example.com?foo大=1&bar=2') - let params = new Url.URLSearchParams(that.search) - params.delete('foo大') - var result = params.toString() - expect(result).assertEqual('bar=2') - }) - - it('Url_entries_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var i = 0; - var arr = {}; - for(var pair of params.entries()) { - arr[i]=pair[0]; - i++; - arr[i]=pair[1]; - i++; - } - expect(arr[1]).assertEqual('value1') - }) - it('Url_entries_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var i = 0; - var arr = {}; - for(var pair of params.entries()) { - arr[i]=pair[0]; - i++; - arr[i]=pair[1]; - i++; - } - expect(arr[2]).assertEqual('key2') - }) - it('Url_entries_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('foo', 'jk') - var i = 0; - var arr = {}; - for(var pair of params.entries()) { - arr[i]=pair[0]; - i++; - arr[i]=pair[1]; - i++; - } - expect(arr[5]).assertEqual('jk') - }) - - it('Url_forEach_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var arr = {}; - var i = 0; - function func(str1, str2, params) { - arr[i] = 'key=' + str1 + ' ' +'value=' + str2 + ' ' + 'flag=' + params - i++; - } - params.forEach(func) - expect(arr[0]).assertEqual('key=key1 value=value1 flag=key1=value1&key2=value2') - }) - it('Url_forEach_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var arr = {}; - var i = 0; - function func(str1, str2, params) { - arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params - i++; - } - params.forEach(func) - expect(arr[1]).assertEqual('key=key2 value=value2 flag=key1=value1&key2=value2') - }) - it('Url_forEach_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('foo', 'jk') - var arr = {}; - var i = 0; - function func(str1, str2, params) { - arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params - i++; - } - params.forEach(func) - expect(arr[2]).assertEqual('key=foo value=jk flag=key1=value1&key2=value2&foo=jk') - }) - it('Url_get_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var result = params.get('1') - expect(result).assertEqual(undefined) - }) - it('Url_get_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - var result = params.get('key2') - expect(result).assertEqual('value2') - }) - it('Url_get_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('5', 'JKL') - var result = params.get('5') - expect(result).assertEqual('JKL') - }) - it('Url_getAll_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2') - params.append('key1', 'AAA') - var result = params.getAll('key1') - expect(result).assertEqual('value1,AAA') - }) - it('Url_getAll_test_002', 0, function () { - let params = new Url.URLSearchParams('key1=value1&8=DEF') - params.append('8', 'A8A') - var result = params.getAll('8') - expect(result).assertEqual('DEF,A8A') - }) - it('Url_getAll_test_003', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') - params.append('key3', 'A3A') - var result = params.getAll('key3') - expect(result).assertEqual('大,A3A') - }) - it('Url_has_test_001', 0, function () { - let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') - var result = params.has('2') - expect(result).assertEqual(false) - }) - it('Url_has_test_002', 0, function () { - let params = new Url.URLSearchParams('小=value1&key2=value2&key3=大') - var result = params.has('小') - expect(result).assertEqual(true) - }) - it('Url_has_test_003', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - params.append('¥', 'ACA') - var result = params.has('¥') - expect(result).assertEqual(true) - }) - it('Url_keys_test_001', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - var arr = {}; - var i = 0; - for(var key of params.keys()) { - arr[i] = key; - i++; - } - expect(arr[0]).assertEqual('小') - }) - it('Url_keys_test_002', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - var arr = {}; - var i = 0; - for(var key of params.keys()) { - arr[i] = key; - i++; - } - expect(arr[1]).assertEqual('¥') - }) - it('Url_keys_test_003', 0, function () { - let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') - var arr = {}; - var i = 0; - for(var key of params.keys()) { - arr[i] = key; - i++; - } - expect(arr[2]).assertEqual('key3') - }) - it('Url_set_test_001', 0, function () { - let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') - params.set('11', 'CCC') - var res = params.toString() - expect(res).assertEqual('1=value1&2=value2&key3=3&11=CCC') - }) - it('Url_set_test_002', 0, function () { - let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') - params.set('10', 'BBB') - var res = params.toString() - expect(res).assertEqual('1=value1&2=value2&key3=3&10=BBB') - }) - it('Url_set_test_003', 0, function () { - let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') - params.set('ma 大', '10¥') - var res = params.toString() - expect(res).assertEqual('1=value1&2=value2&key3=3&ma+%E5%A4%A7=10%EF%BF%A5') - }) - it('Url_sort_test_001', 0, function () { - let params = new Url.URLSearchParams('1=value1&3=value3&2=key2') - params.sort() - var res = params.toString() - expect(res).assertEqual('1=value1&2=key2&3=value3') - }) - it('Url_sort_test_002', 0, function () { - let params = new Url.URLSearchParams('a=value1&c=value2&b=key2') - params.sort() - var res = params.toString() - expect(res).assertEqual('a=value1&b=key2&c=value2') - }) - it('Url_sort_test_003', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=33') - params.append('a', 'ACA') - params.sort() - var res = params.toString() - expect(res).assertEqual('a=ACA&b=33&c=value2&d=value1') - }) - it('Url_Values_test_001', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - var arr = {}; - var i = 0; - for(var value of params.values()) { - arr[i] = value; - i++; - } - expect(arr[0]).assertEqual('value1') - }) - it('Url_Values_test_002', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - var arr = {}; - var i = 0; - for(var value of params.values()) { - arr[i] = value; - i++; - } - expect(arr[1]).assertEqual('value2') - }) - it('Url_Values_test_003', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - params.append('a', 'ACA') - var arr = {}; - var i = 0; - for(var value of params.values()) { - arr[i] = value; - i++; - } - expect(arr[3]).assertEqual('ACA') - }) - it('Url_toString_test_001', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b=大') - var result= params.toString() - expect(result).assertEqual('d=value1&c=value2&b=%E5%A4%A7') - }) - it('Url_toString_test_002', 0, function () { - let params = new Url.URLSearchParams('d=value1&c=value2&b= 大') - params.append('1 12','QQQ') - var result= params.toString() - expect(result).assertEqual('d=value1&c=value2&b=+%E5%A4%A7&1+12=QQQ') - }) - it('Url_toString_test_003', 0, function () { - let params = new Url.URLSearchParams('¥=)') - params.delete('5') - var result= params.toString() - expect(result).assertEqual('%EF%BF%A5=%29') - }) - //new url SearchParams - it('Url_construction_test_001', 0, function () { - let params = new Url.URLSearchParams('?user=abc&query=xyz') - var result= params.toString() - expect(result).assertEqual('user=abc&query=xyz') - }) - it('Url_construction_test_002', 0, function () { - let params = new Url.URLSearchParams({ - user: 'abc', - query: ['first', 'second'] - }) - var result= params.toString() - expect(result).assertEqual('user=abc&query=first%2Csecond') - }) - it('Url_construction_test_003', 0, function () { - let params = new Url.URLSearchParams([ - ['user', 'abc'], - ['query', 'first'], - ['query', 'second'], - ]) - var result= params.toString() - expect(result).assertEqual('user=abc&query=first&query=second') - }) - it('Url_construction_test_004', 0, function () { - const map = new Map() - map.set('user', 'abc') - map.set('query', 'xyz') - let params = new Url.URLSearchParams(map) - var result= params.toString() - expect(result).assertEqual('user=abc&query=xyz') - }) - it('Url_construction_test_004', 0, function () { - function* getQueryPairs() { - yield ['user', 'abc'] - yield ['query', 'first'] - yield ['query', 'second'] - } - let params = new Url.URLSearchParams(getQueryPairs()) - var result= params.toString() - expect(result).assertEqual('user=abc&query=first&query=second') - }) - //new url - get - it('Url_to_string_test_001', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.to_string() - expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') - }) - - it('Url_href_test_002', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.href - expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') - }) - it('Url_origin_test_003', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.origin - expect(result).assertEqual('http://host:8080') - }) - it('Url_protocol_test_004', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.protocol - expect(result).assertEqual('http:') - }) - it('Url_username_test_005', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.username - expect(result).assertEqual('username') - }) - it('Url_password_test_006', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.password - expect(result).assertEqual('password') - }) - it('Url_host_test_007', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.host - expect(result).assertEqual('host:8080') - }) - it('Url_hostname_test_008', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.hostname - expect(result).assertEqual('host') - }) - it('Url_port_test_009', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.port - expect(result).assertEqual('8080') - }) - it('Url_pathname_test_010', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - var result= params.pathname - expect(result).assertEqual('/directory/file') - }) - it('Url_search_test_011', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') - var result= params.search - expect(result).assertEqual('?query=qqqq') - }) - it('Url_search_test_012', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') - var result= params.search - expect(result).assertEqual('?query=pppppp') - }) - it('Url_hash_test_013', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') - var result= params.hash - expect(result).assertEqual('#fragment') - }) - //new url - set - it('Url_href_test_001', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.href = 'http://[::192.9.5.5]/ipng' - var result = params.href - expect(result).assertEqual('http://[::c009:505]/ipng') - }) - it('Url_protocol_test_002', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.protocol = 'https:' - var result= params.href - expect(result).assertEqual('https://username:password@host:8080/directory/file?query#fragment') - }) - it('Url_username_test_003', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.username = 'username1' - var result= params.href - expect(result).assertEqual('http://username1:password@host:8080/directory/file?query#fragment') - }) - it('Url_password_test_004', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.password = 'passwd' - var result= params.href - expect(result).assertEqual('http://username:passwd@host:8080/directory/file?query#fragment') - }) - - it('Url_host_test_005', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.host = 'www.baidu.com:99' - var result= params.href - expect(result).assertEqual('http://username:password@www.baidu.com:99/directory/file?query#fragment') - }) - - it('Url_hostname_test_006', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.hostname = 'www.baidu.com' - var result= params.href - expect(result).assertEqual('http://username:password@www.baidu.com:8080/directory/file?query#fragment') - }) - it('Url_port_test_007', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.port = '99' - var result= params.href - expect(result).assertEqual('http://username:password@host:99/directory/file?query#fragment') - }) - it('Url_pathname_test_008', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') - params.pathname = '/path/ddd' - var result= params.href - expect(result).assertEqual('http://username:password@host:8080/path/ddd?query#fragment') - }) - it('Url_search_test_009', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') - params.search = '?pppppp=1234' - var result= params.href - expect(result).assertEqual('http://username:password@host:8080/directory/file?pppppp=1234#fragment') - }) - it('Url_hash_test_010', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') - params.hash = '#qwer=da' - var result= params.href - expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') - }) - //new url JSON - it('Url_toJSON_test_001', 0, function () { - let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') - var result= params.toJSON() - expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') - }) - //new url IPV6 - it('Url_IPV6_test_001', 0, function () { - let params = new Url.URL('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html') - var result= params.href - expect(result).assertEqual('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html') - }) - it('Url_IPV6_test_002', 0, function () { - let params = new Url.URL('http://[1080:0:0:0:8:800:200C:417A]/index.html') - var result= params.href - expect(result).assertEqual('http://[1080::8:800:200c:417a]/index.html') - }) - it('Url_IPV6_test_003', 0, function () { - let params = new Url.URL('http://[::FFFF:129.144.52.38]:80/index.html') - var result= params.href - expect(result).assertEqual('http://[::ffff:8190:3426]/index.html') - }) - //new url IPV4 - it('Url_IPV4_test_001', 0, function () { - let params = new Url.URL('http://0377.0xff.255.1:80/index.html') - var result= params.href - expect(result).assertEqual('http://255.255.255.1/index.html') - }) - it('Url_IPV4_test_002', 0, function () { - let params = new Url.URL('http://0377.0xff.255.g/index.html') - var result= params.href - expect(result).assertEqual('http://0377.0xff.255.g/index.html') - }) - it('Url_IPV4_test_003', 0, function () { - let params = new Url.URL('http://190.254.245.9:80/index.html') - var result= params.href - expect(result).assertEqual('http://190.254.245.9/index.html') - }) - //new url url_base - it('Url_base_test_001', 0, function () { - let params = new Url.URL('https://developer.mozilla.org',) - var result= params.href - expect(result).assertEqual('https://developer.mozilla.org/') - }) - it('Url_base_test_002', 0, function () { - let params = new Url.URL('https://developer.mozilla.org', 'flie:/developer.mozilla.org') - var result= params.href - expect(result).assertEqual('https://developer.mozilla.org/') - }) - it('Url_base_test_003', 0, function () { - let params = new Url.URL('https://developer.mozilla.org', 'ftp://www.example.com') - var result= params.href - expect(result).assertEqual('https://developer.mozilla.org/') - }) - it('Url_base_test_004', 0, function () { - let params = new Url.URL(' ', 'http://www.example.com') - var result= params.href - expect(result).assertEqual('http://www.example.com/') - }) - it('Url_base_test_005', 0, function () { - let params = new Url.URL('.', 'http://www.example.com') - var result= params.href - expect(result).assertEqual('http://www.example.com/') - }) - it('Url_base_test_006', 0, function () { - let params = new Url.URL('../h:', 'http://www.example.com') - var result= params.href - expect(result).assertEqual('http://www.example.com/h:') - }) - it('Url_base_test_007', 0, function () { - let params = new Url.URL('/sca/./path/path/../scasa/jjjjj', 'http://www.example.com') - var result= params.href - expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_008', 0, function () { - let params = new Url.URL('sca/./path/path/../scasa/jjjjj', 'http://www.example.com') - var result= params.href - expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_009', 0, function () { - let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'http://www.example.com') - var result= params.href - expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_010', 0, function () { - let params = new Url.URL( '/../sca/./path/path/../scasa/jjjjj', 'file://www.example.com') - var result= params.href - expect(result).assertEqual('file://www.example.com/sca/path/scasa/jjjjj') - }) - it('Url_base_test_011', 0, function () { - let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'file1://www.example.com') - var result= params.href - expect(result).assertEqual('file1://www.example.com/sca/path/scasa/jjjjj') - }) +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License') + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/lite' +import Url from '@ohos.url' + +describe('Url_mxa_jk_Test', function () { + it('Url_append_test_001', 0, function () { + var that = new Url.URL('http://username:password@host:8080/directory/file?foo=1&bar=2') + var params = new Url.URLSearchParams(that.search) + params.append('ma', 'jk') + var result = params.toString() + expect(result).assertEqual('foo=1&bar=2&ma=jk') + }) + it('Url_append_test_002', 0, function () { + let that = new Url.URL('https://example.com?foo=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.append('ma 大', 'jk¥') + var result = params.toString() + expect(result).assertEqual('foo=1&bar=2&ma+%E5%A4%A7=jk%EF%BF%A5') + }) + it('Url_append_test_003', 0, function () { + let that = new Url.URL('https://example.com?foo=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.append('foo~!@#$%^&*()_+-=','jk') + var result = params.toString() + expect(result).assertEqual('foo=1&bar=2&foo%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D=jk') + }) + it('Url_delete_test_001', 0, function () { + let that = new Url.URL('https://example.com?foo=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.delete('foo') + var result = params.toString() + expect(result).assertEqual('bar=2') + }) + it('Url_delete_test_002', 0, function () { + let that = new Url.URL('https://example.com?foo大=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.delete('foo') + var result = params.toString() + expect(result).assertEqual('foo%E5%A4%A7=1&bar=2') + }) + it('Url_delete_test_003', 0, function () { + let that = new Url.URL('https://example.com?foo大=1&bar=2') + let params = new Url.URLSearchParams(that.search) + params.delete('foo大') + var result = params.toString() + expect(result).assertEqual('bar=2') + }) + + it('Url_entries_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var i = 0; + var arr = {}; + for(var pair of params.entries()) { + arr[i]=pair[0]; + i++; + arr[i]=pair[1]; + i++; + } + expect(arr[1]).assertEqual('value1') + }) + it('Url_entries_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var i = 0; + var arr = {}; + for(var pair of params.entries()) { + arr[i]=pair[0]; + i++; + arr[i]=pair[1]; + i++; + } + expect(arr[2]).assertEqual('key2') + }) + it('Url_entries_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('foo', 'jk') + var i = 0; + var arr = {}; + for(var pair of params.entries()) { + arr[i]=pair[0]; + i++; + arr[i]=pair[1]; + i++; + } + expect(arr[5]).assertEqual('jk') + }) + + it('Url_forEach_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var arr = {}; + var i = 0; + function func(str1, str2, params) { + arr[i] = 'key=' + str1 + ' ' +'value=' + str2 + ' ' + 'flag=' + params + i++; + } + params.forEach(func) + expect(arr[0]).assertEqual('key=key1 value=value1 flag=key1=value1&key2=value2') + }) + it('Url_forEach_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var arr = {}; + var i = 0; + function func(str1, str2, params) { + arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params + i++; + } + params.forEach(func) + expect(arr[1]).assertEqual('key=key2 value=value2 flag=key1=value1&key2=value2') + }) + it('Url_forEach_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('foo', 'jk') + var arr = {}; + var i = 0; + function func(str1, str2, params) { + arr[i] = 'key=' + str1 + ' ' + 'value=' + str2 + ' ' + 'flag=' + params + i++; + } + params.forEach(func) + expect(arr[2]).assertEqual('key=foo value=jk flag=key1=value1&key2=value2&foo=jk') + }) + it('Url_get_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var result = params.get('1') + expect(result).assertEqual(undefined) + }) + it('Url_get_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + var result = params.get('key2') + expect(result).assertEqual('value2') + }) + it('Url_get_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('5', 'JKL') + var result = params.get('5') + expect(result).assertEqual('JKL') + }) + it('Url_getAll_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2') + params.append('key1', 'AAA') + var result = params.getAll('key1') + expect(result).assertEqual('value1,AAA') + }) + it('Url_getAll_test_002', 0, function () { + let params = new Url.URLSearchParams('key1=value1&8=DEF') + params.append('8', 'A8A') + var result = params.getAll('8') + expect(result).assertEqual('DEF,A8A') + }) + it('Url_getAll_test_003', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') + params.append('key3', 'A3A') + var result = params.getAll('key3') + expect(result).assertEqual('大,A3A') + }) + it('Url_has_test_001', 0, function () { + let params = new Url.URLSearchParams('key1=value1&key2=value2&key3=大') + var result = params.has('2') + expect(result).assertEqual(false) + }) + it('Url_has_test_002', 0, function () { + let params = new Url.URLSearchParams('小=value1&key2=value2&key3=大') + var result = params.has('小') + expect(result).assertEqual(true) + }) + it('Url_has_test_003', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + params.append('¥', 'ACA') + var result = params.has('¥') + expect(result).assertEqual(true) + }) + it('Url_keys_test_001', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + var arr = {}; + var i = 0; + for(var key of params.keys()) { + arr[i] = key; + i++; + } + expect(arr[0]).assertEqual('小') + }) + it('Url_keys_test_002', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + var arr = {}; + var i = 0; + for(var key of params.keys()) { + arr[i] = key; + i++; + } + expect(arr[1]).assertEqual('¥') + }) + it('Url_keys_test_003', 0, function () { + let params = new Url.URLSearchParams('小=value1&¥=value2&key3=大') + var arr = {}; + var i = 0; + for(var key of params.keys()) { + arr[i] = key; + i++; + } + expect(arr[2]).assertEqual('key3') + }) + it('Url_set_test_001', 0, function () { + let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') + params.set('11', 'CCC') + var res = params.toString() + expect(res).assertEqual('1=value1&2=value2&key3=3&11=CCC') + }) + it('Url_set_test_002', 0, function () { + let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') + params.set('10', 'BBB') + var res = params.toString() + expect(res).assertEqual('1=value1&2=value2&key3=3&10=BBB') + }) + it('Url_set_test_003', 0, function () { + let params = new Url.URLSearchParams('1=value1&2=value2&key3=3') + params.set('ma 大', '10¥') + var res = params.toString() + expect(res).assertEqual('1=value1&2=value2&key3=3&ma+%E5%A4%A7=10%EF%BF%A5') + }) + it('Url_sort_test_001', 0, function () { + let params = new Url.URLSearchParams('1=value1&3=value3&2=key2') + params.sort() + var res = params.toString() + expect(res).assertEqual('1=value1&2=key2&3=value3') + }) + it('Url_sort_test_002', 0, function () { + let params = new Url.URLSearchParams('a=value1&c=value2&b=key2') + params.sort() + var res = params.toString() + expect(res).assertEqual('a=value1&b=key2&c=value2') + }) + it('Url_sort_test_003', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=33') + params.append('a', 'ACA') + params.sort() + var res = params.toString() + expect(res).assertEqual('a=ACA&b=33&c=value2&d=value1') + }) + it('Url_Values_test_001', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + var arr = {}; + var i = 0; + for(var value of params.values()) { + arr[i] = value; + i++; + } + expect(arr[0]).assertEqual('value1') + }) + it('Url_Values_test_002', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + var arr = {}; + var i = 0; + for(var value of params.values()) { + arr[i] = value; + i++; + } + expect(arr[1]).assertEqual('value2') + }) + it('Url_Values_test_003', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + params.append('a', 'ACA') + var arr = {}; + var i = 0; + for(var value of params.values()) { + arr[i] = value; + i++; + } + expect(arr[3]).assertEqual('ACA') + }) + it('Url_toString_test_001', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b=大') + var result= params.toString() + expect(result).assertEqual('d=value1&c=value2&b=%E5%A4%A7') + }) + it('Url_toString_test_002', 0, function () { + let params = new Url.URLSearchParams('d=value1&c=value2&b= 大') + params.append('1 12','QQQ') + var result= params.toString() + expect(result).assertEqual('d=value1&c=value2&b=+%E5%A4%A7&1+12=QQQ') + }) + it('Url_toString_test_003', 0, function () { + let params = new Url.URLSearchParams('¥=)') + params.delete('5') + var result= params.toString() + expect(result).assertEqual('%EF%BF%A5=%29') + }) + //new url SearchParams + it('Url_construction_test_001', 0, function () { + let params = new Url.URLSearchParams('?user=abc&query=xyz') + var result= params.toString() + expect(result).assertEqual('user=abc&query=xyz') + }) + it('Url_construction_test_002', 0, function () { + let params = new Url.URLSearchParams({ + user: 'abc', + query: ['first', 'second'] + }) + var result= params.toString() + expect(result).assertEqual('user=abc&query=first%2Csecond') + }) + it('Url_construction_test_003', 0, function () { + let params = new Url.URLSearchParams([ + ['user', 'abc'], + ['query', 'first'], + ['query', 'second'], + ]) + var result= params.toString() + expect(result).assertEqual('user=abc&query=first&query=second') + }) + it('Url_construction_test_004', 0, function () { + const map = new Map() + map.set('user', 'abc') + map.set('query', 'xyz') + let params = new Url.URLSearchParams(map) + var result= params.toString() + expect(result).assertEqual('user=abc&query=xyz') + }) + it('Url_construction_test_004', 0, function () { + function* getQueryPairs() { + yield ['user', 'abc'] + yield ['query', 'first'] + yield ['query', 'second'] + } + let params = new Url.URLSearchParams(getQueryPairs()) + var result= params.toString() + expect(result).assertEqual('user=abc&query=first&query=second') + }) + //new url - get + it('Url_to_string_test_001', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.to_string() + expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') + }) + + it('Url_href_test_002', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.href + expect(result).assertEqual('http://username:password@host:8080/directory/file?query#fragment') + }) + it('Url_origin_test_003', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.origin + expect(result).assertEqual('http://host:8080') + }) + it('Url_protocol_test_004', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.protocol + expect(result).assertEqual('http:') + }) + it('Url_username_test_005', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.username + expect(result).assertEqual('username') + }) + it('Url_password_test_006', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.password + expect(result).assertEqual('password') + }) + it('Url_host_test_007', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.host + expect(result).assertEqual('host:8080') + }) + it('Url_hostname_test_008', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.hostname + expect(result).assertEqual('host') + }) + it('Url_port_test_009', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.port + expect(result).assertEqual('8080') + }) + it('Url_pathname_test_010', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + var result= params.pathname + expect(result).assertEqual('/directory/file') + }) + it('Url_search_test_011', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') + var result= params.search + expect(result).assertEqual('?query=qqqq') + }) + it('Url_search_test_012', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') + var result= params.search + expect(result).assertEqual('?query=pppppp') + }) + it('Url_hash_test_013', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') + var result= params.hash + expect(result).assertEqual('#fragment') + }) + //new url - set + it('Url_href_test_001', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.href = 'http://[::192.9.5.5]/ipng' + var result = params.href + expect(result).assertEqual('http://[::c009:505]/ipng') + }) + it('Url_protocol_test_002', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.protocol = 'https:' + var result= params.href + expect(result).assertEqual('https://username:password@host:8080/directory/file?query#fragment') + }) + it('Url_username_test_003', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.username = 'username1' + var result= params.href + expect(result).assertEqual('http://username1:password@host:8080/directory/file?query#fragment') + }) + it('Url_password_test_004', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.password = 'passwd' + var result= params.href + expect(result).assertEqual('http://username:passwd@host:8080/directory/file?query#fragment') + }) + + it('Url_host_test_005', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.host = 'www.baidu.com:99' + var result= params.href + expect(result).assertEqual('http://username:password@www.baidu.com:99/directory/file?query#fragment') + }) + + it('Url_hostname_test_006', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.hostname = 'www.baidu.com' + var result= params.href + expect(result).assertEqual('http://username:password@www.baidu.com:8080/directory/file?query#fragment') + }) + it('Url_port_test_007', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.port = '99' + var result= params.href + expect(result).assertEqual('http://username:password@host:99/directory/file?query#fragment') + }) + it('Url_pathname_test_008', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query#fragment') + params.pathname = '/path/ddd' + var result= params.href + expect(result).assertEqual('http://username:password@host:8080/path/ddd?query#fragment') + }) + it('Url_search_test_009', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=qqqq#fragment') + params.search = '?pppppp=1234' + var result= params.href + expect(result).assertEqual('http://username:password@host:8080/directory/file?pppppp=1234#fragment') + }) + it('Url_hash_test_010', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#fragment') + params.hash = '#qwer=da' + var result= params.href + expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') + }) + //new url JSON + it('Url_toJSON_test_001', 0, function () { + let params = new Url.URL('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') + var result= params.toJSON() + expect(result).assertEqual('http://username:password@host:8080/directory/file?query=pppppp#qwer=da') + }) + //new url IPV6 + it('Url_IPV6_test_001', 0, function () { + let params = new Url.URL('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html') + var result= params.href + expect(result).assertEqual('http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/index.html') + }) + it('Url_IPV6_test_002', 0, function () { + let params = new Url.URL('http://[1080:0:0:0:8:800:200C:417A]/index.html') + var result= params.href + expect(result).assertEqual('http://[1080::8:800:200c:417a]/index.html') + }) + it('Url_IPV6_test_003', 0, function () { + let params = new Url.URL('http://[::FFFF:129.144.52.38]:80/index.html') + var result= params.href + expect(result).assertEqual('http://[::ffff:8190:3426]/index.html') + }) + //new url IPV4 + it('Url_IPV4_test_001', 0, function () { + let params = new Url.URL('http://0377.0xff.255.1:80/index.html') + var result= params.href + expect(result).assertEqual('http://255.255.255.1/index.html') + }) + it('Url_IPV4_test_002', 0, function () { + let params = new Url.URL('http://0377.0xff.255.g/index.html') + var result= params.href + expect(result).assertEqual('http://0377.0xff.255.g/index.html') + }) + it('Url_IPV4_test_003', 0, function () { + let params = new Url.URL('http://190.254.245.9:80/index.html') + var result= params.href + expect(result).assertEqual('http://190.254.245.9/index.html') + }) + //new url url_base + it('Url_base_test_001', 0, function () { + let params = new Url.URL('https://developer.mozilla.org',) + var result= params.href + expect(result).assertEqual('https://developer.mozilla.org/') + }) + it('Url_base_test_002', 0, function () { + let params = new Url.URL('https://developer.mozilla.org', 'flie:/developer.mozilla.org') + var result= params.href + expect(result).assertEqual('https://developer.mozilla.org/') + }) + it('Url_base_test_003', 0, function () { + let params = new Url.URL('https://developer.mozilla.org', 'ftp://www.example.com') + var result= params.href + expect(result).assertEqual('https://developer.mozilla.org/') + }) + it('Url_base_test_004', 0, function () { + let params = new Url.URL(' ', 'http://www.example.com') + var result= params.href + expect(result).assertEqual('http://www.example.com/') + }) + it('Url_base_test_005', 0, function () { + let params = new Url.URL('.', 'http://www.example.com') + var result= params.href + expect(result).assertEqual('http://www.example.com/') + }) + it('Url_base_test_006', 0, function () { + let params = new Url.URL('../h:', 'http://www.example.com') + var result= params.href + expect(result).assertEqual('http://www.example.com/h:') + }) + it('Url_base_test_007', 0, function () { + let params = new Url.URL('/sca/./path/path/../scasa/jjjjj', 'http://www.example.com') + var result= params.href + expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_008', 0, function () { + let params = new Url.URL('sca/./path/path/../scasa/jjjjj', 'http://www.example.com') + var result= params.href + expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_009', 0, function () { + let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'http://www.example.com') + var result= params.href + expect(result).assertEqual('http://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_010', 0, function () { + let params = new Url.URL( '/../sca/./path/path/../scasa/jjjjj', 'file://www.example.com') + var result= params.href + expect(result).assertEqual('file://www.example.com/sca/path/scasa/jjjjj') + }) + it('Url_base_test_011', 0, function () { + let params = new Url.URL('/../sca/./path/path/../scasa/jjjjj', 'file1://www.example.com') + var result= params.href + expect(result).assertEqual('file1://www.example.com/sca/path/scasa/jjjjj') + }) }) \ No newline at end of file diff --git a/compileruntime/url_lib_standard/project/entry/src/main/resources/base/element/string.json b/compileruntime/util_lib_standard/src/main/resources/base/element/string.json similarity index 94% rename from compileruntime/url_lib_standard/project/entry/src/main/resources/base/element/string.json rename to compileruntime/util_lib_standard/src/main/resources/base/element/string.json index c0dd3a09e5dcefc69f22b5e00e92296f1c3f55a5..0bae6bd40f7360d5d818998221b199d3ec0f69c0 100644 --- a/compileruntime/url_lib_standard/project/entry/src/main/resources/base/element/string.json +++ b/compileruntime/util_lib_standard/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "entry_MainAbility" - }, - { - "name": "mainability_description", - "value": "JS_Empty Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] } \ No newline at end of file diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/app.js b/compileruntime/util_lib_standard/src/ohosTest/js/default/app.js similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/app.js rename to compileruntime/util_lib_standard/src/ohosTest/js/default/app.js diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/i18n/en-US.json b/compileruntime/util_lib_standard/src/ohosTest/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/i18n/en-US.json rename to compileruntime/util_lib_standard/src/ohosTest/js/default/i18n/en-US.json diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/i18n/zh-CN.json b/compileruntime/util_lib_standard/src/ohosTest/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/i18n/zh-CN.json rename to compileruntime/util_lib_standard/src/ohosTest/js/default/i18n/zh-CN.json diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.css b/compileruntime/util_lib_standard/src/ohosTest/js/default/pages/index/index.css similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.css rename to compileruntime/util_lib_standard/src/ohosTest/js/default/pages/index/index.css diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.hml b/compileruntime/util_lib_standard/src/ohosTest/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.hml rename to compileruntime/util_lib_standard/src/ohosTest/js/default/pages/index/index.hml diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.js b/compileruntime/util_lib_standard/src/ohosTest/js/default/pages/index/index.js similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/default/pages/index/index.js rename to compileruntime/util_lib_standard/src/ohosTest/js/default/pages/index/index.js diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/js/test/ExampleJsunit.test.js b/compileruntime/util_lib_standard/src/ohosTest/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/js/test/ExampleJsunit.test.js rename to compileruntime/util_lib_standard/src/ohosTest/js/test/ExampleJsunit.test.js diff --git a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/test/List.test.js b/compileruntime/util_lib_standard/src/ohosTest/js/test/List.test.js similarity index 92% rename from compileruntime/process_lib_standard/project/entry/src/ohosTest/js/test/List.test.js rename to compileruntime/util_lib_standard/src/ohosTest/js/test/List.test.js index d21d417581975daf4033529f6c2bfc7dca43c24a..86ae9fa262b8d3fa27e4ac734dbd529d37d0b7cd 100644 --- a/compileruntime/process_lib_standard/project/entry/src/ohosTest/js/test/List.test.js +++ b/compileruntime/util_lib_standard/src/ohosTest/js/test/List.test.js @@ -1,16 +1,16 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + require('./ExampleJsunit.test.js') \ No newline at end of file diff --git a/compileruntime/util_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json b/compileruntime/util_lib_standard/src/ohosTest/resources/base/element/string.json similarity index 93% rename from compileruntime/util_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json rename to compileruntime/util_lib_standard/src/ohosTest/resources/base/element/string.json index a1d8e0cb17b5d75fe2913172fefb4e30889ac229..ee04e287523beb449e633f5be2900410f7be79af 100644 --- a/compileruntime/util_lib_standard/project/entry/src/ohosTest/resources/base/element/string.json +++ b/compileruntime/util_lib_standard/src/ohosTest/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "app_name", - "value": "childprocess" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] -} +{ + "string": [ + { + "name": "app_name", + "value": "childprocess" + }, + { + "name": "mainability_description", + "value": "hap sample empty page" + } + ] +} diff --git a/compileruntime/worker_lib_standard/BUILD.gn b/compileruntime/worker_lib_standard/BUILD.gn index 74c9b2ba4f6e437cfcd3cb52dd4a4d528afef7f7..9fcf8c928c8b8cf68d6e0ddfdbc223f87bb417c1 100644 --- a/compileruntime/worker_lib_standard/BUILD.gn +++ b/compileruntime/worker_lib_standard/BUILD.gn @@ -10,9 +10,29 @@ # 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("worker_js_hap") { + hap_profile = "./src/main/config.json" + deps = [ + ":worker_js_assets", + ":worker_resources", + ] + + # shared_libraries = [ + # "//third_party/giflib:libgif", + # "//third_party/libpng:libpng", + # ] + certificate_profile = "./signature/openharmony_sx.p7b" + hap_name = "WorkerJSTest" -ohos_js_hap_suite("startup_worker_js_test") { - test_hap_name = "StartupWorkerJSApiTest" - hap_source_path = "hap/entry-debug-standard-unsigned.hap" + # part_name = "prebuilt_hap" + # subsystem_name = "xts" +} +ohos_js_assets("worker_js_assets") { + source_dir = "./src/main/js/default" +} +ohos_resources("worker_resources") { + sources = [ "./src/main/resources" ] + hap_profile = "./src/main/config.json" } diff --git a/compileruntime/worker_lib_standard/Test.json b/compileruntime/worker_lib_standard/Test.json index 35b00e6e01d0c700d1f500e9732c0012bc7b8741..92175f082f627dea2b01176adcc35e649b81f391 100644 --- a/compileruntime/worker_lib_standard/Test.json +++ b/compileruntime/worker_lib_standard/Test.json @@ -9,7 +9,7 @@ "kits": [ { "test-file-name": [ - "startup_worker_js_test.hap" + "WorkerJSTest.hap" ], "type": "AppInstallKit", "cleanup-apps": true diff --git a/compileruntime/worker_lib_standard/hap/entry-debug-standard-unsigned.hap b/compileruntime/worker_lib_standard/hap/entry-debug-standard-unsigned.hap deleted file mode 100644 index 2dd20e91797124322c3e93ef891286a28e0a7f75..0000000000000000000000000000000000000000 Binary files a/compileruntime/worker_lib_standard/hap/entry-debug-standard-unsigned.hap and /dev/null differ diff --git a/compileruntime/worker_lib_standard/project/entry/package.json b/compileruntime/worker_lib_standard/project/entry/package.json deleted file mode 100644 index 69a88e3b65423624fe7ea8b0f8beefcc62cc3d5f..0000000000000000000000000000000000000000 --- a/compileruntime/worker_lib_standard/project/entry/package.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/compileruntime/worker_lib_standard/signature/openharmony_sx.p7b b/compileruntime/worker_lib_standard/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/compileruntime/worker_lib_standard/signature/openharmony_sx.p7b differ diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/config.json b/compileruntime/worker_lib_standard/src/main/config.json similarity index 95% rename from compileruntime/worker_lib_standard/project/entry/src/main/config.json rename to compileruntime/worker_lib_standard/src/main/config.json index d3dc9f3b3fc2f5113f94dee54d03d5070a70ec7e..18665aeb48d8098fa1232be5e0195d8145ada9e7 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/config.json +++ b/compileruntime/worker_lib_standard/src/main/config.json @@ -1,60 +1,60 @@ -{ - "app": { - "bundleName": "com.example.workerxts", - "vendor": "example", - "version": { - "code": 1000000, - "name": "1.0.0" - } - }, - "deviceConfig": {}, - "module": { - "package": "com.example.workerxts", - "name": ".MyApplication", - "mainAbility": "com.example.workerxts.MainAbility", - "deviceType": [ - "phone" - ], - "distro": { - "deliveryWithInstall": true, - "moduleName": "entry", - "moduleType": "entry", - "installationFree": false - }, - "abilities": [ - { - "skills": [ - { - "entities": [ - "entity.system.home" - ], - "actions": [ - "action.system.home" - ] - } - ], - "orientation": "unspecified", - "name": "com.example.workerxts.MainAbility", - "icon": "$media:icon", - "description": "$string:mainability_description", - "formsEnabled": false, - "label": "$string:entry_MainAbility", - "type": "page", - "launchType": "standard" - } - ], - "js": [ - { - "pages": [ - "pages/index/index", - "pages/second/second" - ], - "name": "default", - "window": { - "designWidth": 720, - "autoDesignWidth": false - } - } - ] - } +{ + "app": { + "bundleName": "com.example.workerxts", + "vendor": "example", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.example.workerxts", + "name": ".MyApplication", + "mainAbility": "com.example.workerxts.MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "name": "com.example.workerxts.MainAbility", + "icon": "$media:icon", + "description": "$string:mainability_description", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "pages": [ + "pages/index/index", + "pages/second/second" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } } \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/app.js b/compileruntime/worker_lib_standard/src/main/js/default/app.js similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/app.js rename to compileruntime/worker_lib_standard/src/main/js/default/app.js diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/i18n/en-US.json b/compileruntime/worker_lib_standard/src/main/js/default/i18n/en-US.json similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/i18n/en-US.json rename to compileruntime/worker_lib_standard/src/main/js/default/i18n/en-US.json diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json b/compileruntime/worker_lib_standard/src/main/js/default/i18n/zh-CN.json similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/i18n/zh-CN.json rename to compileruntime/worker_lib_standard/src/main/js/default/i18n/zh-CN.json diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/index/index.css b/compileruntime/worker_lib_standard/src/main/js/default/pages/index/index.css similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/index/index.css rename to compileruntime/worker_lib_standard/src/main/js/default/pages/index/index.css diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/index/index.hml b/compileruntime/worker_lib_standard/src/main/js/default/pages/index/index.hml similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/index/index.hml rename to compileruntime/worker_lib_standard/src/main/js/default/pages/index/index.hml diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/index/index.js b/compileruntime/worker_lib_standard/src/main/js/default/pages/index/index.js similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/index/index.js rename to compileruntime/worker_lib_standard/src/main/js/default/pages/index/index.js diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/second/second.css b/compileruntime/worker_lib_standard/src/main/js/default/pages/second/second.css similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/second/second.css rename to compileruntime/worker_lib_standard/src/main/js/default/pages/second/second.css diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/second/second.hml b/compileruntime/worker_lib_standard/src/main/js/default/pages/second/second.hml similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/second/second.hml rename to compileruntime/worker_lib_standard/src/main/js/default/pages/second/second.hml diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/second/second.js b/compileruntime/worker_lib_standard/src/main/js/default/pages/second/second.js similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/pages/second/second.js rename to compileruntime/worker_lib_standard/src/main/js/default/pages/second/second.js diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js index 178918c03d37a06dcf723458797317dbfd6eaf7a..461c656778e9f3b27daf295f197e64b74665c54e 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker.js @@ -1,66 +1,66 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - function foo(x) {return x} - - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - console.info("worker:: new version") - - parentPort.onclose = function() { - console.info("worker::worker.js onclose"); - } - - parentPort.onmessage = function(e) { - var data = e.data; - console.info("worker:: worker thread worker data is " + data.data); - switch(data.type) { - case "normal": - console.info("worker:: worker thread receive data " + data.data); - parentPort.postMessage(data); - console.info("worker:: worker thread post back"); - break; - case "error": - throw new Error("123"); - break; - case "buffer": - console.info("worker:: worker.js receive buffer length is " + data.data.byteLength); - parentPort.postMessage(data, [data.data]); - console.info("worker:: worker.js post buffer length is " + data.data.byteLength); - break; - default: - console.info("worker:: worker.js receive unknow type"); - break - } - } - - // 反序列错误 - parentPort.onmessageerror = function() { - console.info("worker:: worker.js onmessageerror"); - } - - // js执行异常 - parentPort.onerror = function(data) { - console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + function foo(x) {return x} + + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + console.info("worker:: new version") + + parentPort.onclose = function() { + console.info("worker::worker.js onclose"); + } + + parentPort.onmessage = function(e) { + var data = e.data; + console.info("worker:: worker thread worker data is " + data.data); + switch(data.type) { + case "normal": + console.info("worker:: worker thread receive data " + data.data); + parentPort.postMessage(data); + console.info("worker:: worker thread post back"); + break; + case "error": + throw new Error("123"); + break; + case "buffer": + console.info("worker:: worker.js receive buffer length is " + data.data.byteLength); + parentPort.postMessage(data, [data.data]); + console.info("worker:: worker.js post buffer length is " + data.data.byteLength); + break; + default: + console.info("worker:: worker.js receive unknow type"); + break + } + } + + // 反序列错误 + parentPort.onmessageerror = function() { + console.info("worker:: worker.js onmessageerror"); + } + + // js执行异常 + parentPort.onerror = function(data) { + console.info("worker:: worker.js onerror " + data.lineno + ", msg = " + data.message + ", filename = " + data.filename + ", colno = " + data.colno); + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_002.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_002.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js index b4d4dac2e2ac99e900b398d720ed2621d82da6ce..5914eea6d23eb11c8582a5b24a6bbe87844757be 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_002.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_002.js @@ -1,32 +1,32 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - console.log("worker:: run script"); - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - console.log("worker:: worker receive data " + e.data); - var data = e.data + " worker"; - parentPort.postMessage(data) - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + console.log("worker:: run script"); + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + console.log("worker:: worker receive data " + e.data); + var data = e.data + " worker"; + parentPort.postMessage(data) + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_003.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_003.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js index 4bd01e96b3a07d546e75448dc84286bb8ac5c9e9..a680ac1788fdca88e9ca08f75ccad03accfbf692 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_003.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_003.js @@ -1,30 +1,30 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - var data = e.data * 2 + 1 - parentPort.postMessage(data) - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + var data = e.data * 2 + 1 + parentPort.postMessage(data) + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_004.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_004.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js index de3fdc7608213ac7ba198f240c73af9da4bd32cb..49e4423840930b19e290e3eb4e672d0d20918527 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_004.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_004.js @@ -1,31 +1,31 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - var data = e.data; - data.message = "hello world " + "worker" - parentPort.postMessage(data) - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + var data = e.data; + data.message = "hello world " + "worker" + parentPort.postMessage(data) + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_005.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_005.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js index d5414270ed04a612dd2a31a8ffd365ed80bcf65c..cc1cbaaad826dbd06bb862f4faa540498f2cf365 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_005.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_005.js @@ -1,29 +1,29 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - parentPort.postMessage(name) - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + parentPort.postMessage(name) + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_006.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_006.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js index bc79a4796406bd3e124f027ba1e8c73a4fdaa8ee..6b9ce1e02dcf9a32709948b487861bbf2f854fb0 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_006.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_006.js @@ -1,29 +1,29 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - parentPort.postMessage("hello world") - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + parentPort.postMessage("hello world") + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_007.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_007.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js index f3163c5bde137f82dc2095689be83db34889cb36..9d5790347a917d7827d1b6276968e4e205734360 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_007.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_007.js @@ -1,29 +1,29 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - throw new Error(123) - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + throw new Error(123) + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_008.js b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js similarity index 97% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_008.js rename to compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js index fa3ce5a3594a5da52fda6a0c5c6ee4731494a8fb..02d4825b98377c83d4bbc9e8a8542b7dea6fd262 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/default/workers/worker_008.js +++ b/compileruntime/worker_lib_standard/src/main/js/default/workers/worker_008.js @@ -1,29 +1,29 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/******/ (() => { // webpackBootstrap - var __webpack_exports__ = {}; - /*!********************************************************************************************!*\ - !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! - \********************************************************************************************/ - var worker = globalThis.requireNapi('worker'); - - const parentPort = worker.parentPort; - - parentPort.onmessage = function(e) { - parentPort.close() - } - /******/ })() +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/******/ (() => { // webpackBootstrap + var __webpack_exports__ = {}; + /*!********************************************************************************************!*\ + !*** d:\workspace\my_works\MyApplication\entry\src\main\ets\default\workers\WorkerDemo.js ***! + \********************************************************************************************/ + var worker = globalThis.requireNapi('worker'); + + const parentPort = worker.parentPort; + + parentPort.onmessage = function(e) { + parentPort.close() + } + /******/ })() ; \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js b/compileruntime/worker_lib_standard/src/main/js/test/ExampleJsunit.test.js similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/test/ExampleJsunit.test.js rename to compileruntime/worker_lib_standard/src/main/js/test/ExampleJsunit.test.js diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/test/List.test.js b/compileruntime/worker_lib_standard/src/main/js/test/List.test.js similarity index 93% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/test/List.test.js rename to compileruntime/worker_lib_standard/src/main/js/test/List.test.js index 2fbe075f96d534a05fae9f4a8b3a1d685a178ad5..f0714ab28b031c9721288cfc773fb9cd5a9133f6 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/test/List.test.js +++ b/compileruntime/worker_lib_standard/src/main/js/test/List.test.js @@ -1,17 +1,17 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -require('./ExampleJsunit.test.js') +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +require('./ExampleJsunit.test.js') require("./Worker.test.js") \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/js/test/Worker.test.js b/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js similarity index 96% rename from compileruntime/worker_lib_standard/project/entry/src/main/js/test/Worker.test.js rename to compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js index a878e9c51b6dce5fef3b29f419082b0503265883..0b5a96cd747ca2e3c0a7c303d07dfa372ce4bcf5 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/js/test/Worker.test.js +++ b/compileruntime/worker_lib_standard/src/main/js/test/Worker.test.js @@ -1,546 +1,546 @@ -/* - * Copyright (C) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// @ts-nocheck -import app from '@system.app' -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' -//import worker from "@ohos.worker"; -var worker = globalThis.requireNapi('worker'); - -describe('workerTest', function () { - - afterAll(function () { - console.info('total case over') - }) - - function PromiseCase() { - let p = new Promise(function (resolve, reject) { - setTimeout(function () { - resolve() - }, 100); - }).then(undefined, (error) => { - }) - return p - } - - // check worker constructor is ok - it('worker_constructor_test_001', 0, function () { - var ss = new worker.Worker("workers/worker.js") - expect(ss != null).assertTrue() - }) - - it('worker_constructor_test_002', 0, function () { - var ss = new worker.Worker("workers/worker.js",{name:"second worker",shared:"False"}) - expect(ss != null).assertTrue() - }) - - it('worker_constructor_test_003', 0, function () { - var ss = new worker.Worker("workers/worker.js",{type:"classic",name:"second worker",shared:"false"}) - expect(ss != null).assertTrue() - }) - - it('worker_constructor_test_004', 0, function () { - var ss = new worker.Worker("workers/worker.js",{type:"classic",name:"third worker",shared:"true"}) - expect(ss != null).assertTrue() - }) - - // check postMessage is ok - // main post "hello world", will receive "hello world worker" - it('worker_postMessage_test_001', 0, async function (done) { - var ss = new worker.Worker("workers/worker_002.js"); - - var res = undefined - var flag = false - - ss.onmessage = function (e) { - res = e.data; - flag = true - } - - ss.postMessage("hello world") - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual("hello world worker") - done() - }) - - // check postMessage is ok - // main post 12 , will receive 12 * 2 + 1 - it('worker_postMessage_test_002', 0, async function (done) { - var ss = new worker.Worker("workers/worker_003.js"); - - var res = undefined - var flag = false - - ss.onmessage = function (e) { - res = e.data; - flag = true - } - - ss.postMessage(12) - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual(25) - done() - }) - - // check postMessage is ok - // main post {message:"hello world"} , will receive {message:"hello world worker"} - it('worker_postMessage_test_003', 0, async function (done) { - var ss = new worker.Worker("workers/worker_004.js"); - - var res = undefined - var flag = false - - ss.onmessage = function (e) { - res = e.data.message; - flag = true - } - - ss.postMessage({"message":"hello world"}) - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual("hello world worker") - done() - }) - - // check worker name is ok - it('worker_postMessage_test_004', 0, async function (done) { - var ss = new worker.Worker("workers/worker_005.js", {name: "zhangsan"}); - - var res = undefined - var flag = false - - ss.onmessage = function (e) { - res = e.data; - flag = true - } - - ss.postMessage("hello world") - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual("zhangsan") - done() - }) - - // check worker transfer buffer is ok - it('worker_postMessage_test_005', 0, function () { - var ss = new worker.Worker("workers/worker_006.js"); - - const buffer = new ArrayBuffer(8) - expect(buffer.byteLength).assertEqual(8) - ss.postMessage(buffer, [buffer]) - expect(buffer.byteLength).assertEqual(0) - }) - - // check worker handle error is ok - it('worker_postMessage_test_006', 0, async function (done) { - var ss = new worker.Worker("workers/worker_007.js"); - - var res = undefined - var flag = false - - ss.onerror = function (e) { - res = e.message; - flag = true - } - - ss.postMessage("hello world") - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual("Error: 123") - done() - }) - - // check worker terminate is ok - it('worker_terminate_test_001', 0, async function (done) { - var ss = new worker.Worker("workers/worker.js"); - var res = 0 - var flag = false - - ss.onexit = function () { - flag = true - res++; - } - ss.terminate() - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual(1) - done() - }) - - // check worker terminate is ok - it('worker_terminate_test_002', 0, async function (done) { - var ss = new worker.Worker("workers/worker.js"); - var res = 0 - var flag = false - - ss.onexit = function () { - flag = true - res++; - } - - // Repeated execution terminate - ss.terminate() - ss.terminate() - - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual(1) - done() - }) - - // check worker terminate is ok - it('worker_terminate_test_003', 0, async function (done) { - var ss = new worker.Worker("workers/worker.js"); - var res = 0 - var flag = false - - ss.onexit = function () { - flag = true - res++; - } - - ss.onmessage = function (e) { - res++; - } - - ss.terminate() - while (!flag) { - await PromiseCase() - } - expect(res).assertEqual(1) - - ss.postMessage("hello world") - await PromiseCase() - expect(res).assertEqual(1) - done() - }) - - // check worker on function is ok - it('worker_on_test_001', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.on("zhangsan", ()=>{ - times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - - expect(times).assertEqual(1) - }) - - // check worker on function is ok - it('worker_on_test_002', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.on("zhangsan", ()=>{ - times--; - }) - - ss.on("lisi", ()=>{ - times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) - - expect(times).assertEqual(0) - }) - - // check worker on function is ok - it('worker_on_test_003', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.on("zhangsan", ()=>{ - times++; - }) - - for (var i=0;i<10;i++) - { - ss.dispatchEvent({type: "zhangsan"}) - } - console.log("times " + times); - expect(times).assertEqual(10) - }) - - // check worker once function is ok - it('worker_once_test_001', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.once("zhangsan", ()=>{ - times++; - }) - ss.dispatchEvent({type: "zhangsan"}) - expect(times).assertEqual(1) - }) - - // check worker once function is ok - it('worker_once_test_002', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.once("zhangsan", ()=>{ - times++; - }) - - for (var i=0;i<10;i++) - { - ss.dispatchEvent({type: "zhangsan"}) - } - - expect(times).assertEqual(1) - }) - - it('worker_once_test_003', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.once("zhangsan", ()=>{ - times--; - }) - - ss.once("lisi", ()=>{ - times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) - - expect(times).assertEqual(0) - }) - - // check worker addEventListener function is ok - it('worker_addEventListener_test_001', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.addEventListener("zhangsan", ()=>{ - times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - - expect(times).assertEqual(2) - }) - - // check worker addEventListener function is ok - it('worker_addEventListener_test_002', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.addEventListener("zhangsan", ()=>{ - times++; - }) - - ss.addEventListener("lisi", ()=>{ - times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "lisi"}) - - expect(times).assertEqual(2) - }) - - // check worker addEventListener function is ok - it('worker_addEventListener_test_003', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var times = 0; - ss.addEventListener("zhangsan", ()=>{ - times++; - }) - - for (var i=0;i<10;i++) - { - ss.dispatchEvent({type: "zhangsan"}) - } - - expect(times).assertEqual(10) - }) - - // check worker removeEventListener function is ok - it('worker_removeListener_test_001', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var zhangsan_times = 0; - ss.addEventListener("zhangsan", ()=>{ - zhangsan_times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangsan_times).assertEqual(1) - - ss.removeEventListener("zhangsan") - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangsan_times).assertEqual(1) - }) - - // check worker removeEventListener function is ok - it('worker_removeListener_test_002', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var zhangsan_times = 0; - ss.addEventListener("zhangsan", ()=>{ - zhangsan_times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangsan_times).assertEqual(2) - - for (var i=0;i<3;i++) - { - ss.removeEventListener("zhangsan") - } - - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangsan_times).assertEqual(2) - - }) - - // check worker removeAllListener function is ok - it('worker_removeListener_test_003', 0, function () { - var ss = new worker.Worker("workers/worker.js"); - - var zhangsan_times = 0; - ss.addEventListener("zhangsan", ()=>{ - zhangsan_times++; - }) - - var lisi_times = 0; - ss.addEventListener("lisi", ()=>{ - lisi_times++; - }) - - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangsan_times).assertEqual(2) - - ss.dispatchEvent({type: "lisi"}) - ss.dispatchEvent({type: "lisi"}) - expect(lisi_times).assertEqual(2) - - ss.removeAllListener() - ss.dispatchEvent({type: "zhangsan"}) - ss.dispatchEvent({type: "zhangsan"}) - expect(zhangsan_times).assertEqual(2) - - ss.dispatchEvent({type: "lisi"}) - ss.dispatchEvent({type: "lisi"}) - expect(lisi_times).assertEqual(2) - }) - - // check parentPort.close is ok - it('worker_parentPortClose_test_001', 0, async function (done) { - var ss = new worker.Worker("workers/worker_008.js"); - var res = 0 - - ss.onmessage = function (e) { - res++; - } - - ss.postMessage("abc") - await PromiseCase() - expect(res).assertEqual(0) - done() - }) - - // check parentPort.close is ok - it('worker_parentPortClose_test_002', 0, async function (done) { - var ss1 = new worker.Worker("workers/worker_008.js"); - var ss2 = new worker.Worker("workers/worker_008.js"); - var res = 0 - var times = 0 - - ss1.onmessage = function (e) { - res++; - } - - ss1.postMessage("abc") - await PromiseCase() - expect(res).assertEqual(0) - - ss2.postMessage("hello world") - await PromiseCase() - expect(res).assertEqual(0) - - done() - }) - - // check parentPort.close is ok - it('worker_parentPortClose_test_003', 0, async function (done) { - var ss1 = new worker.Worker("workers/worker_008.js"); - var ss2 = new worker.Worker("workers/worker_008.js"); - var res = 0 - var times = 0 - - ss1.onmessage = function (e) { - res++; - } - - ss1.postMessage("abc") - await PromiseCase() - expect(res).assertEqual(0) - - ss2.addEventListener("zhangsan", ()=>{ - times++; - }) - - ss2.dispatchEvent({type: "zhangsan"}) - expect(times).assertEqual(1) - done() - }) - - // check parentPort.close is ok - it('worker_parentPortClose_test_004', 0, async function (done) { - var ss = new worker.Worker("workers/worker_008.js"); - var res = 0 - var flag = false; - - ss.onexit = function () { - flag = true - } - - ss.onmessage = function (e) { - res++; - } - - ss.postMessage("abc") - while (!flag) { - await PromiseCase() - } - - ss.postMessage("hello") - await PromiseCase() - expect(res).assertEqual(0) - done() - }) +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-nocheck +import app from '@system.app' +import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' +//import worker from "@ohos.worker"; +var worker = globalThis.requireNapi('worker'); + +describe('workerTest', function () { + + afterAll(function () { + console.info('total case over') + }) + + function PromiseCase() { + let p = new Promise(function (resolve, reject) { + setTimeout(function () { + resolve() + }, 100); + }).then(undefined, (error) => { + }) + return p + } + + // check worker constructor is ok + it('worker_constructor_test_001', 0, function () { + var ss = new worker.Worker("workers/worker.js") + expect(ss != null).assertTrue() + }) + + it('worker_constructor_test_002', 0, function () { + var ss = new worker.Worker("workers/worker.js",{name:"second worker",shared:"False"}) + expect(ss != null).assertTrue() + }) + + it('worker_constructor_test_003', 0, function () { + var ss = new worker.Worker("workers/worker.js",{type:"classic",name:"second worker",shared:"false"}) + expect(ss != null).assertTrue() + }) + + it('worker_constructor_test_004', 0, function () { + var ss = new worker.Worker("workers/worker.js",{type:"classic",name:"third worker",shared:"true"}) + expect(ss != null).assertTrue() + }) + + // check postMessage is ok + // main post "hello world", will receive "hello world worker" + it('worker_postMessage_test_001', 0, async function (done) { + var ss = new worker.Worker("workers/worker_002.js"); + + var res = undefined + var flag = false + + ss.onmessage = function (e) { + res = e.data; + flag = true + } + + ss.postMessage("hello world") + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual("hello world worker") + done() + }) + + // check postMessage is ok + // main post 12 , will receive 12 * 2 + 1 + it('worker_postMessage_test_002', 0, async function (done) { + var ss = new worker.Worker("workers/worker_003.js"); + + var res = undefined + var flag = false + + ss.onmessage = function (e) { + res = e.data; + flag = true + } + + ss.postMessage(12) + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual(25) + done() + }) + + // check postMessage is ok + // main post {message:"hello world"} , will receive {message:"hello world worker"} + it('worker_postMessage_test_003', 0, async function (done) { + var ss = new worker.Worker("workers/worker_004.js"); + + var res = undefined + var flag = false + + ss.onmessage = function (e) { + res = e.data.message; + flag = true + } + + ss.postMessage({"message":"hello world"}) + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual("hello world worker") + done() + }) + + // check worker name is ok + it('worker_postMessage_test_004', 0, async function (done) { + var ss = new worker.Worker("workers/worker_005.js", {name: "zhangsan"}); + + var res = undefined + var flag = false + + ss.onmessage = function (e) { + res = e.data; + flag = true + } + + ss.postMessage("hello world") + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual("zhangsan") + done() + }) + + // check worker transfer buffer is ok + it('worker_postMessage_test_005', 0, function () { + var ss = new worker.Worker("workers/worker_006.js"); + + const buffer = new ArrayBuffer(8) + expect(buffer.byteLength).assertEqual(8) + ss.postMessage(buffer, [buffer]) + expect(buffer.byteLength).assertEqual(0) + }) + + // check worker handle error is ok + it('worker_postMessage_test_006', 0, async function (done) { + var ss = new worker.Worker("workers/worker_007.js"); + + var res = undefined + var flag = false + + ss.onerror = function (e) { + res = e.message; + flag = true + } + + ss.postMessage("hello world") + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual("Error: 123") + done() + }) + + // check worker terminate is ok + it('worker_terminate_test_001', 0, async function (done) { + var ss = new worker.Worker("workers/worker.js"); + var res = 0 + var flag = false + + ss.onexit = function () { + flag = true + res++; + } + ss.terminate() + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual(1) + done() + }) + + // check worker terminate is ok + it('worker_terminate_test_002', 0, async function (done) { + var ss = new worker.Worker("workers/worker.js"); + var res = 0 + var flag = false + + ss.onexit = function () { + flag = true + res++; + } + + // Repeated execution terminate + ss.terminate() + ss.terminate() + + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual(1) + done() + }) + + // check worker terminate is ok + it('worker_terminate_test_003', 0, async function (done) { + var ss = new worker.Worker("workers/worker.js"); + var res = 0 + var flag = false + + ss.onexit = function () { + flag = true + res++; + } + + ss.onmessage = function (e) { + res++; + } + + ss.terminate() + while (!flag) { + await PromiseCase() + } + expect(res).assertEqual(1) + + ss.postMessage("hello world") + await PromiseCase() + expect(res).assertEqual(1) + done() + }) + + // check worker on function is ok + it('worker_on_test_001', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.on("zhangsan", ()=>{ + times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + + expect(times).assertEqual(1) + }) + + // check worker on function is ok + it('worker_on_test_002', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.on("zhangsan", ()=>{ + times--; + }) + + ss.on("lisi", ()=>{ + times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "lisi"}) + + expect(times).assertEqual(0) + }) + + // check worker on function is ok + it('worker_on_test_003', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.on("zhangsan", ()=>{ + times++; + }) + + for (var i=0;i<10;i++) + { + ss.dispatchEvent({type: "zhangsan"}) + } + console.log("times " + times); + expect(times).assertEqual(10) + }) + + // check worker once function is ok + it('worker_once_test_001', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.once("zhangsan", ()=>{ + times++; + }) + ss.dispatchEvent({type: "zhangsan"}) + expect(times).assertEqual(1) + }) + + // check worker once function is ok + it('worker_once_test_002', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.once("zhangsan", ()=>{ + times++; + }) + + for (var i=0;i<10;i++) + { + ss.dispatchEvent({type: "zhangsan"}) + } + + expect(times).assertEqual(1) + }) + + it('worker_once_test_003', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.once("zhangsan", ()=>{ + times--; + }) + + ss.once("lisi", ()=>{ + times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "lisi"}) + + expect(times).assertEqual(0) + }) + + // check worker addEventListener function is ok + it('worker_addEventListener_test_001', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.addEventListener("zhangsan", ()=>{ + times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + + expect(times).assertEqual(2) + }) + + // check worker addEventListener function is ok + it('worker_addEventListener_test_002', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.addEventListener("zhangsan", ()=>{ + times++; + }) + + ss.addEventListener("lisi", ()=>{ + times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "lisi"}) + + expect(times).assertEqual(2) + }) + + // check worker addEventListener function is ok + it('worker_addEventListener_test_003', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var times = 0; + ss.addEventListener("zhangsan", ()=>{ + times++; + }) + + for (var i=0;i<10;i++) + { + ss.dispatchEvent({type: "zhangsan"}) + } + + expect(times).assertEqual(10) + }) + + // check worker removeEventListener function is ok + it('worker_removeListener_test_001', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var zhangsan_times = 0; + ss.addEventListener("zhangsan", ()=>{ + zhangsan_times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(1) + + ss.removeEventListener("zhangsan") + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(1) + }) + + // check worker removeEventListener function is ok + it('worker_removeListener_test_002', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var zhangsan_times = 0; + ss.addEventListener("zhangsan", ()=>{ + zhangsan_times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(2) + + for (var i=0;i<3;i++) + { + ss.removeEventListener("zhangsan") + } + + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(2) + + }) + + // check worker removeAllListener function is ok + it('worker_removeListener_test_003', 0, function () { + var ss = new worker.Worker("workers/worker.js"); + + var zhangsan_times = 0; + ss.addEventListener("zhangsan", ()=>{ + zhangsan_times++; + }) + + var lisi_times = 0; + ss.addEventListener("lisi", ()=>{ + lisi_times++; + }) + + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(2) + + ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "lisi"}) + expect(lisi_times).assertEqual(2) + + ss.removeAllListener() + ss.dispatchEvent({type: "zhangsan"}) + ss.dispatchEvent({type: "zhangsan"}) + expect(zhangsan_times).assertEqual(2) + + ss.dispatchEvent({type: "lisi"}) + ss.dispatchEvent({type: "lisi"}) + expect(lisi_times).assertEqual(2) + }) + + // check parentPort.close is ok + it('worker_parentPortClose_test_001', 0, async function (done) { + var ss = new worker.Worker("workers/worker_008.js"); + var res = 0 + + ss.onmessage = function (e) { + res++; + } + + ss.postMessage("abc") + await PromiseCase() + expect(res).assertEqual(0) + done() + }) + + // check parentPort.close is ok + it('worker_parentPortClose_test_002', 0, async function (done) { + var ss1 = new worker.Worker("workers/worker_008.js"); + var ss2 = new worker.Worker("workers/worker_008.js"); + var res = 0 + var times = 0 + + ss1.onmessage = function (e) { + res++; + } + + ss1.postMessage("abc") + await PromiseCase() + expect(res).assertEqual(0) + + ss2.postMessage("hello world") + await PromiseCase() + expect(res).assertEqual(0) + + done() + }) + + // check parentPort.close is ok + it('worker_parentPortClose_test_003', 0, async function (done) { + var ss1 = new worker.Worker("workers/worker_008.js"); + var ss2 = new worker.Worker("workers/worker_008.js"); + var res = 0 + var times = 0 + + ss1.onmessage = function (e) { + res++; + } + + ss1.postMessage("abc") + await PromiseCase() + expect(res).assertEqual(0) + + ss2.addEventListener("zhangsan", ()=>{ + times++; + }) + + ss2.dispatchEvent({type: "zhangsan"}) + expect(times).assertEqual(1) + done() + }) + + // check parentPort.close is ok + it('worker_parentPortClose_test_004', 0, async function (done) { + var ss = new worker.Worker("workers/worker_008.js"); + var res = 0 + var flag = false; + + ss.onexit = function () { + flag = true + } + + ss.onmessage = function (e) { + res++; + } + + ss.postMessage("abc") + while (!flag) { + await PromiseCase() + } + + ss.postMessage("hello") + await PromiseCase() + expect(res).assertEqual(0) + done() + }) }) \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/resources/base/element/string.json b/compileruntime/worker_lib_standard/src/main/resources/base/element/string.json similarity index 94% rename from compileruntime/worker_lib_standard/project/entry/src/main/resources/base/element/string.json rename to compileruntime/worker_lib_standard/src/main/resources/base/element/string.json index c0dd3a09e5dcefc69f22b5e00e92296f1c3f55a5..0bae6bd40f7360d5d818998221b199d3ec0f69c0 100644 --- a/compileruntime/worker_lib_standard/project/entry/src/main/resources/base/element/string.json +++ b/compileruntime/worker_lib_standard/src/main/resources/base/element/string.json @@ -1,12 +1,12 @@ -{ - "string": [ - { - "name": "entry_MainAbility", - "value": "entry_MainAbility" - }, - { - "name": "mainability_description", - "value": "JS_Empty Ability" - } - ] +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "entry_MainAbility" + }, + { + "name": "mainability_description", + "value": "JS_Empty Ability" + } + ] } \ No newline at end of file diff --git a/compileruntime/worker_lib_standard/project/entry/src/main/resources/base/media/icon.png b/compileruntime/worker_lib_standard/src/main/resources/base/media/icon.png similarity index 100% rename from compileruntime/worker_lib_standard/project/entry/src/main/resources/base/media/icon.png rename to compileruntime/worker_lib_standard/src/main/resources/base/media/icon.png