diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js index c5e8da9c5acffb7cdeb9c0356b1c97786acfc445..325d74e06154c973a1d153231e147d87275854af 100644 --- a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js @@ -209,6 +209,42 @@ describe('threadWorkerTest', function () { } }) + /** + * @tc.name: threadWorker_constructor_test_010 + * @tc.desc: worker constructor to Creates a worker instance. + */ + it('threadWorker_constructor_test_010', 0, async function (done) { + let ss = new worker.ThreadWorker("/entry/ets/workers/newworker.js"); + let isTerminate = false + ss.onexit = function () { + isTerminate = true + } + expect(ss != null).assertTrue() + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + /** + * @tc.name: threadWorker_constructor_test_011 + * @tc.desc: worker constructor to Creates a worker instance. + */ + it('threadWorker_constructor_test_011', 0, async function (done) { + let ss = new worker.ThreadWorker("@bundle:com.example.threadWorkertest/entry/ets/workers/newworker.js"); + let isTerminate = false + ss.onexit = function () { + isTerminate = true + } + expect(ss != null).assertTrue() + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + // check postMessage is ok // main post "hello world", will receive "hello world worker" /** @@ -2018,5 +2054,261 @@ describe('threadWorkerTest', function () { expect(res).assertEqual("terminate") done() }) + + function CreateArray(type,b) { + switch(type) { + case 0 : + return new Int8Array(b); + case 1 : + return new Int16Array(b); + case 2 : + return new Int32Array(b); + case 3 : + return new Uint8Array(b); + case 4 : + return new Uint16Array(b); + case 5 : + return new Uint32Array(b); + case 6 : + return new Float32Array(b); + case 7 : + return new Float64Array(b); + case 8 : + return new BigInt64Array(b); + case 9 : + return new BigUint64Array(b); + default : + return; + } + } + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_001 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_001', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_016.js"); + let array = [] + for (let i = 0; i < 10; i++) { + array[i] = CreateArray(i, 62); + } + + let res = 0; + let flag = 0; + let isTerminate = false; + ss.onmessage = function(d) { + res += d.data; + flag += 1; + } + ss.onexit = function() { + isTerminate = true; + } + + for (let i = 0; i < 10; i++) { + ss.postMessage(array[i]); + } + + while (flag != 10) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res).assertEqual(620) + + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_002 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_002', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_017.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data.name; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + ss.postMessage("start"); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res).assertEqual("worker") + + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_003 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_003', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_018.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const data = new Set(); + ss.postMessage(data); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res.has(1)).assertTrue() + expect(res.has(2)).assertTrue() + expect(!res.has(1010)).assertTrue() + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_004 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_004', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_019.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const data = new Map(); + ss.postMessage(data); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res.get("worker")).assertEqual("success"); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_005 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_005', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_020.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const buffer = new ArrayBuffer(8); + ss.postMessage(buffer); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res[res.length - 1]).assertEqual(3); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_006 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_006', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_021.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + var re = new RegExp("(\\w+)\\s(\\w+)"); + ss.postMessage(re); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res).assertEqual("Worker, HI!"); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_007 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_007', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_021.js"); + let flag = false; + let isTerminate = false; + ss.onmessageerror = function(d) { + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + try { + const data = Symbol(); + ss.postMessage(data); + } catch (error) { + console.info("worker:: recv error message: " + error.message) + while (!flag) { + await promiseCase(); + } + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + } + expect(flag).assertTrue(); + done(); + }) }) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_016.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_016.js new file mode 100644 index 0000000000000000000000000000000000000000..074986206479aeecf44c10574a24e330fb91f0a0 --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_016.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.workerPort; + +parentPort.onmessage = function(e) { + console.info("worker:: worker receive data " + e.data); + let data = e.data; + parentPort.postMessage(data.length); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_017.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_017.js new file mode 100644 index 0000000000000000000000000000000000000000..1cca8e9f13a88e1467a96c0f16723b4480105147 --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_017.js @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +class MyModel { + name = "worker" + Init() { + this.name = "MyModel" + } +} + +workerPort.onmessage = function(e) { + let obj = new MyModel(); + workerPort.postMessage(obj); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_018.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_018.js new file mode 100644 index 0000000000000000000000000000000000000000..362592a30b84ac88ee233a6c677dc0d6b725b555 --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_018.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +workerPort.onmessage = function(e) { + const data = e.data; + data.add(1); + data.add(2); + workerPort.postMessage(data); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_019.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_019.js new file mode 100644 index 0000000000000000000000000000000000000000..877efeec28792bacc0fcbb519b9d7447024f4a55 --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_019.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +workerPort.onmessage = function(e) { + const data = e.data; + data.set("worker", "success"); + workerPort.postMessage(data); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_020.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_020.js new file mode 100644 index 0000000000000000000000000000000000000000..db984c6eb8adeb3a2607641bd72cc0eaf51a253d --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_020.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +workerPort.onmessage = function(e) { + const data = e.data; + const view = new Int8Array(data).fill(3); + workerPort.postMessage(view); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_021.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_021.js new file mode 100644 index 0000000000000000000000000000000000000000..5c92783aa9a5f59d7418ac904356b01a8e51fbfa --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_021.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +workerPort.onmessage = function(e) { + const data = e.data; + let str = "HI Worker"; + let newStr = str.replace(data, "$2, $1!"); + workerPort.postMessage(newStr); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js index bba30e377a5deb43777d277db63bcf2119e61629..3c10b3befabdeadcec436b83db991ebe785e7b60 100644 --- a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js @@ -120,6 +120,42 @@ describe('WorkerTest', function () { done() }) + /** + * @tc.name: worker_constructor_test_005 + * @tc.desc: worker constructor to Creates a worker instance. + */ + it('worker_constructor_test_005', 0, async function (done) { + let ss = new worker.Worker("/entry/ets/workers/worker.js"); + let isTerminate = false + ss.onexit = function () { + isTerminate = true + } + expect(ss != null).assertTrue() + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + + /** + * @tc.name: worker_constructor_test_006 + * @tc.desc: worker constructor to Creates a worker instance. + */ + it('worker_constructor_test_006', 0, async function (done) { + let ss = new worker.Worker("@bundle:com.example.workertest/entry/ets/workers/worker.js"); + let isTerminate = false + ss.onexit = function () { + isTerminate = true + } + expect(ss != null).assertTrue() + ss.terminate() + while (!isTerminate) { + await promiseCase() + } + done() + }) + // check postMessage is ok // main post "hello world", will receive "hello world worker" /** @@ -1351,5 +1387,259 @@ describe('WorkerTest', function () { expect(res).assertEqual("terminate") done() }) + + function CreateArray(type,b) { + switch(type) { + case 0 : + return new Int8Array(b); + case 1 : + return new Int16Array(b); + case 2 : + return new Int32Array(b); + case 3 : + return new Uint8Array(b); + case 4 : + return new Uint16Array(b); + case 5 : + return new Uint32Array(b); + case 6 : + return new Float32Array(b); + case 7 : + return new Float64Array(b); + case 8 : + return new BigInt64Array(b); + case 9 : + return new BigUint64Array(b); + default : + return; + } + } + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_001 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_001', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_016.js"); + let array = [] + for (let i = 0; i < 10; i++) { + array[i] = CreateArray(i, 62); + } + + let res = 0; + let flag = 0; + let isTerminate = false; + ss.onmessage = function(d) { + res += d.data; + flag += 1; + } + ss.onexit = function() { + isTerminate = true; + } + + for (let i = 0; i < 10; i++) { + ss.postMessage(array[i]); + } + + while (flag != 10) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res).assertEqual(620) + + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_002 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_002', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_017.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data.name; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + ss.postMessage("start"); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res).assertEqual("worker") + + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_003 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_003', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_018.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const data = new Set(); + ss.postMessage(data); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res.has(1)).assertTrue() + expect(res.has(2)).assertTrue() + expect(!res.has(1010)).assertTrue() + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_004 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_004', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_019.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const data = new Map(); + ss.postMessage(data); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res.get("worker")).assertEqual("success"); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_005 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_005', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_020.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const buffer = new ArrayBuffer(8); + ss.postMessage(buffer); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res[res.length - 1]).assertEqual(3); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_006 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_006', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_021.js"); + let res; + let flag = false; + let isTerminate = false; + ss.onmessage = function(d) { + res = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + var re = new RegExp("(\\w+)\\s(\\w+)"); + ss.postMessage(re); + while (!flag) { + await promiseCase(); + } + + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + expect(res).assertEqual("Worker, HI!"); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_007 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_007', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_021.js"); + let flag = false; + let isTerminate = false; + ss.onmessageerror = function(d) { + console.info("worker:: unsupport the Symbol."); + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + const data = Symbol(); + ss.postMessage(data); + while (!flag) { + await promiseCase(); + } + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + + expect(flag).assertTrue(); + done(); + }) }) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/worker_002.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_016.js similarity index 84% rename from commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/worker_002.js rename to commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_016.js index ab62c6d1fdd1d787497aede7f8c445f5d44ce72f..7f037e29b28f69e00e3ad309be2e91332251e19e 100644 --- a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/worker_002.js +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_016.js @@ -17,7 +17,7 @@ import worker from '@ohos.worker'; const parentPort = worker.parentPort; parentPort.onmessage = function(e) { - console.log("worker:: worker receive data " + e.data); - let data = e.data + " worker"; - parentPort.postMessage(data) + console.info("worker:: worker receive data " + e.data); + let data = e.data; + parentPort.postMessage(data.length); } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_017.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_017.js new file mode 100644 index 0000000000000000000000000000000000000000..63017b9c2b9347e473632b1405f1ad58b0a0b321 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_017.js @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +class MyModel { + name = "worker" + Init() { + this.name = "MyModel" + } +} + +parentPort.onmessage = function(e) { + let obj = new MyModel(); + parentPort.postMessage(obj); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_018.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_018.js new file mode 100644 index 0000000000000000000000000000000000000000..0a2193f4649d9ad17b4df75160de3d5c01102abd --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_018.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + const data = e.data; + data.add(1); + data.add(2); + parentPort.postMessage(data); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_019.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_019.js new file mode 100644 index 0000000000000000000000000000000000000000..719fe02ae203dc3506e322b181fb6b141856f324 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_019.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + const data = e.data; + data.set("worker", "success"); + parentPort.postMessage(data); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_020.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_020.js new file mode 100644 index 0000000000000000000000000000000000000000..2b2c581aac7cd62dc00d66b30d078642eb79b0e2 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_020.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + const data = e.data; + const view = new Int8Array(data).fill(3); + parentPort.postMessage(view); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_021.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_021.js new file mode 100644 index 0000000000000000000000000000000000000000..779e57eadc2b1ce97b6239fbd430e7854427baf2 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_021.js @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + const data = e.data; + let str = "HI Worker"; + let newStr = str.replace(data, "$2, $1!"); + parentPort.postMessage(newStr); +} \ No newline at end of file