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 5dc7cc4a7fd4d282f1bd57f6453150bc01222bce..e320899a07190dedcc63cfaa5d097ff148229d83 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 @@ -2342,6 +2342,77 @@ describe('threadWorkerTest', function () { done(); }) + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_008 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_008', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_026.js"); + let flag = false; + let result; + let isTerminate = false; + class MyModel + { + name = "module"; + Init() { + this.name = "Init"; + } + } + let model = new MyModel() + ss.onmessage = function(d) { + result = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + ss.postMessage(model); + while (!flag) { + await promiseCase(); + } + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + + expect(result).assertEqual("module"); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: threadWorker_support_types_test_009 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('threadWorker_support_types_test_009', 0, async function (done) { + let ss = new worker.ThreadWorker("entry/ets/workers/newworker_027.js"); + let result = ""; + let isTerminate = false; + class MyModel + { + name = "module"; + Init() { + this.name = "Init"; + } + } + let model = new MyModel() + + ss.onerror = function (e){ + result = "unInit"; + } + ss.onexit = function() { + isTerminate = true; + } + ss.postMessage(model); + while (!isTerminate) { + await promiseCase(); + } + + expect(result).assertEqual("unInit"); + done(); + }) + // Check the postmessage of worker is ok. /** * @tc.name: threadWorker_worker_postmessage_test_001 diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_026.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_026.js new file mode 100644 index 0000000000000000000000000000000000000000..c37b4e2053fd887b3cacc99434b41f5a6f7ac770 --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_026.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +workerPort.onmessage = function(e) { + let model = e.data; + let str = model.name; + workerPort.postMessage(str); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_027.js b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_027.js new file mode 100644 index 0000000000000000000000000000000000000000..fab999317890d39ee44fb6461a87f8979572c66e --- /dev/null +++ b/commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_027.js @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const workerPort = worker.workerPort; + +workerPort.onmessage = function(e) { + let model = e.data; + let str = model.Init(); +} \ 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 ffdcdb7ddb9d85f3393e34853b0bf4ec1cf5ecdb..6708070abce1e220b5cdd2d917c472ba931fb769 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 @@ -1640,5 +1640,76 @@ describe('WorkerTest', function () { expect(flag).assertTrue(); done(); }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_008 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_008', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_022.js"); + let flag = false; + let result; + let isTerminate = false; + class MyModel + { + name = "module"; + Init() { + this.name = "Init"; + } + } + let model = new MyModel() + ss.onmessage = function(d) { + result = d.data; + flag = true; + } + ss.onexit = function() { + isTerminate = true; + } + ss.postMessage(model); + while (!flag) { + await promiseCase(); + } + ss.terminate(); + while (!isTerminate) { + await promiseCase(); + } + + expect(result).assertEqual("module"); + done(); + }) + + // Check the transmission types supported by Worker is ok. + /** + * @tc.name: worker_support_types_test_009 + * @tc.desc: Check the transmission types supported by Worker is ok. + */ + it('worker_support_types_test_009', 0, async function (done) { + let ss = new worker.Worker("entry/ets/workers/worker_023.js"); + let result = ""; + let isTerminate = false; + class MyModel + { + name = "module"; + Init() { + this.name = "Init"; + } + } + let model = new MyModel() + + ss.onerror = function (e){ + result = "unInit"; + } + ss.onexit = function() { + isTerminate = true; + } + ss.postMessage(model); + while (!isTerminate) { + await promiseCase(); + } + + expect(result).assertEqual("unInit"); + done(); + }) }) } \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_022.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_022.js new file mode 100644 index 0000000000000000000000000000000000000000..35880c35ac4db000b12f1d4e1e17696a82bcb90e --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_022.js @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let model = e.data; + let str = model.name; + parentPort.postMessage(str); +} \ No newline at end of file diff --git a/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_023.js b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_023.js new file mode 100644 index 0000000000000000000000000000000000000000..d9b4328b5359e18524087c632da3e78c333eb2c5 --- /dev/null +++ b/commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_023.js @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import worker from '@ohos.worker'; +const parentPort = worker.parentPort; + +parentPort.onmessage = function(e) { + let model = e.data; + let str = model.Init(); +} \ No newline at end of file