Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
bf02a40b
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
bf02a40b
编写于
3月 13, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 13, 2023
浏览文件
操作
浏览文件
下载
差异文件
!7897 新增Worker模块的测试用例
Merge pull request !7897 from hwx1130639/cherry-pick-1678417108
上级
1665f2ea
48a810d1
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
854 addition
and
3 deletion
+854
-3
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
...lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
+292
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_016.js
..._lib_standard/entry/src/main/ets/workers/newworker_016.js
+23
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_017.js
..._lib_standard/entry/src/main/ets/workers/newworker_017.js
+29
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_018.js
..._lib_standard/entry/src/main/ets/workers/newworker_018.js
+24
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_019.js
..._lib_standard/entry/src/main/ets/workers/newworker_019.js
+23
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_020.js
..._lib_standard/entry/src/main/ets/workers/newworker_020.js
+23
-0
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_021.js
..._lib_standard/entry/src/main/ets/workers/newworker_021.js
+24
-0
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
...r_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
+290
-0
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_016.js
...ker_lib_standard/entry/src/main/ets/workers/worker_016.js
+3
-3
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_017.js
...ker_lib_standard/entry/src/main/ets/workers/worker_017.js
+29
-0
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_018.js
...ker_lib_standard/entry/src/main/ets/workers/worker_018.js
+24
-0
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_019.js
...ker_lib_standard/entry/src/main/ets/workers/worker_019.js
+23
-0
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_020.js
...ker_lib_standard/entry/src/main/ets/workers/worker_020.js
+23
-0
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_021.js
...ker_lib_standard/entry/src/main/ets/workers/worker_021.js
+24
-0
未找到文件。
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/test/ThreadWorker.test.js
浏览文件 @
bf02a40b
...
@@ -209,6 +209,42 @@ describe('threadWorkerTest', function () {
...
@@ -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
// check postMessage is ok
// main post "hello world", will receive "hello world worker"
// main post "hello world", will receive "hello world worker"
/**
/**
...
@@ -2018,5 +2054,261 @@ describe('threadWorkerTest', function () {
...
@@ -2018,5 +2054,261 @@ describe('threadWorkerTest', function () {
expect
(
res
).
assertEqual
(
"
terminate
"
)
expect
(
res
).
assertEqual
(
"
terminate
"
)
done
()
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
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_016.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_017.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_018.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_019.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_020.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/threadWorker_lib_standard/entry/src/main/ets/workers/newworker_021.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/test/WorkerTest.test.js
浏览文件 @
bf02a40b
...
@@ -120,6 +120,42 @@ describe('WorkerTest', function () {
...
@@ -120,6 +120,42 @@ describe('WorkerTest', function () {
done
()
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
// check postMessage is ok
// main post "hello world", will receive "hello world worker"
// main post "hello world", will receive "hello world worker"
/**
/**
...
@@ -1351,5 +1387,259 @@ describe('WorkerTest', function () {
...
@@ -1351,5 +1387,259 @@ describe('WorkerTest', function () {
expect
(
res
).
assertEqual
(
"
terminate
"
)
expect
(
res
).
assertEqual
(
"
terminate
"
)
done
()
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
commonlibrary/ets_utils/
threadWorker_lib_standard/entry/src/main/ets/workers/worker_002
.js
→
commonlibrary/ets_utils/
worker_lib_standard/entry/src/main/ets/workers/worker_016
.js
浏览文件 @
bf02a40b
...
@@ -17,7 +17,7 @@ import worker from '@ohos.worker';
...
@@ -17,7 +17,7 @@ import worker from '@ohos.worker';
const
parentPort
=
worker
.
parentPort
;
const
parentPort
=
worker
.
parentPort
;
parentPort
.
onmessage
=
function
(
e
)
{
parentPort
.
onmessage
=
function
(
e
)
{
console
.
log
(
"
worker:: worker receive data
"
+
e
.
data
);
console
.
info
(
"
worker:: worker receive data
"
+
e
.
data
);
let
data
=
e
.
data
+
"
worker
"
;
let
data
=
e
.
data
;
parentPort
.
postMessage
(
data
)
parentPort
.
postMessage
(
data
.
length
);
}
}
\ No newline at end of file
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_017.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_018.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_019.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_020.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
commonlibrary/ets_utils/worker_lib_standard/entry/src/main/ets/workers/worker_021.js
0 → 100644
浏览文件 @
bf02a40b
/*
* 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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录