Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
6bd830db
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看板
未验证
提交
6bd830db
编写于
1月 14, 2022
作者:
O
openharmony_ci
提交者:
Gitee
1月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1566 【Sensors】新增sensor测试用例
Merge pull request !1566 from logic42/master
上级
a0a2e479
4e697fbe
变更
18
显示空白变更内容
内联
并排
Showing
18 changed file
with
3194 addition
and
0 deletion
+3194
-0
sensors/miscdevice_standard/BUILD.gn
sensors/miscdevice_standard/BUILD.gn
+31
-0
sensors/miscdevice_standard/Test.json
sensors/miscdevice_standard/Test.json
+18
-0
sensors/miscdevice_standard/signature/openharmony_sx.p7b
sensors/miscdevice_standard/signature/openharmony_sx.p7b
+0
-0
sensors/miscdevice_standard/src/main/config.json
sensors/miscdevice_standard/src/main/config.json
+60
-0
sensors/miscdevice_standard/src/main/js/default/app.js
sensors/miscdevice_standard/src/main/js/default/app.js
+23
-0
sensors/miscdevice_standard/src/main/js/default/i18n/en-US.json
...s/miscdevice_standard/src/main/js/default/i18n/en-US.json
+6
-0
sensors/miscdevice_standard/src/main/js/default/i18n/zh-CN.json
...s/miscdevice_standard/src/main/js/default/i18n/zh-CN.json
+6
-0
sensors/miscdevice_standard/src/main/js/default/pages/index/index.css
...device_standard/src/main/js/default/pages/index/index.css
+9
-0
sensors/miscdevice_standard/src/main/js/default/pages/index/index.hml
...device_standard/src/main/js/default/pages/index/index.hml
+5
-0
sensors/miscdevice_standard/src/main/js/default/pages/index/index.js
...cdevice_standard/src/main/js/default/pages/index/index.js
+46
-0
sensors/miscdevice_standard/src/main/js/default/test/List.test.js
...miscdevice_standard/src/main/js/default/test/List.test.js
+16
-0
sensors/miscdevice_standard/src/main/js/default/test/Vibrator.test.js
...device_standard/src/main/js/default/test/Vibrator.test.js
+506
-0
sensors/miscdevice_standard/src/main/resources/base/element/string.json
...vice_standard/src/main/resources/base/element/string.json
+12
-0
sensors/miscdevice_standard/src/main/resources/base/media/icon.png
...iscdevice_standard/src/main/resources/base/media/icon.png
+0
-0
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_acc.js
...dard/src/main/js/default/test/SensorOnOffTest.test_acc.js
+618
-0
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_gyr.js
...dard/src/main/js/default/test/SensorOnOffTest.test_gyr.js
+618
-0
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_light.js
...rd/src/main/js/default/test/SensorOnOffTest.test_light.js
+602
-0
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_mag.js
...dard/src/main/js/default/test/SensorOnOffTest.test_mag.js
+618
-0
未找到文件。
sensors/miscdevice_standard/BUILD.gn
0 → 100755
浏览文件 @
6bd830db
# 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("//test/xts/tools/build/suite.gni")
ohos_js_hap_suite("sensor_js_test") {
hap_profile = "./src/main/config.json"
deps = [
":sensor_js_assets",
":sensor_js_resources",
]
certificate_profile = "./signature/openharmony_sx.p7b"
hap_name = "ActsSensorJSApiTest"
}
ohos_js_assets("sensor_js_assets") {
source_dir = "./src/main/js/default"
}
ohos_resources("sensor_js_resources") {
sources = [ "./src/main/resources" ]
hap_profile = "./src/main/config.json"
}
sensors/miscdevice_standard/Test.json
0 → 100755
浏览文件 @
6bd830db
{
"description"
:
"Configuration for sensor js api Tests"
,
"driver"
:
{
"type"
:
"JSUnitTest"
,
"test-timeout"
:
"160000"
,
"package"
:
"ohos.acts.sensors.sensor.function"
,
"shell-timeout"
:
"60000"
},
"kits"
:
[
{
"test-file-name"
:
[
"ActsSensorJSApiTest.hap"
],
"type"
:
"AppInstallKit"
,
"cleanup-apps"
:
true
}
]
}
sensors/miscdevice_standard/signature/openharmony_sx.p7b
0 → 100755
浏览文件 @
6bd830db
文件已添加
sensors/miscdevice_standard/src/main/config.json
0 → 100755
浏览文件 @
6bd830db
{
"app"
:
{
"bundleName"
:
"ohos.acts.sensors.sensor.function"
,
"vendor"
:
"example"
,
"version"
:
{
"code"
:
1
,
"name"
:
"1.0"
},
"apiVersion"
:
{
"compatible"
:
4
,
"target"
:
5
}
},
"deviceConfig"
:
{},
"module"
:
{
"package"
:
"ohos.acts.sensors.sensor.function"
,
"name"
:
".MyApplication"
,
"deviceType"
:
[
"phone"
],
"distro"
:
{
"deliveryWithInstall"
:
true
,
"moduleName"
:
"entry"
,
"moduleType"
:
"entry"
},
"abilities"
:
[
{
"visible"
:
true
,
"skills"
:
[
{
"entities"
:
[
"entity.system.home"
],
"actions"
:
[
"action.system.home"
]
}
],
"name"
:
"ohos.acts.sensors.sensor.function.MainAbility"
,
"icon"
:
"$media:icon"
,
"description"
:
"$string:mainability_description"
,
"label"
:
"$string:app_name"
,
"type"
:
"page"
,
"launchType"
:
"standard"
}
],
"js"
:
[
{
"pages"
:
[
"pages/index/index"
],
"name"
:
"default"
,
"window"
:
{
"designWidth"
:
720
,
"autoDesignWidth"
:
false
}
}
]
}
}
sensors/miscdevice_standard/src/main/js/default/app.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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.
*/
export
default
{
onCreate
()
{
console
.
info
(
'
AceApplication onCreate
'
);
},
onDestroy
()
{
console
.
info
(
'
AceApplication onDestroy
'
);
}
};
sensors/miscdevice_standard/src/main/js/default/i18n/en-US.json
0 → 100755
浏览文件 @
6bd830db
{
"strings"
:
{
"hello"
:
"Hello"
,
"world"
:
"World"
}
}
\ No newline at end of file
sensors/miscdevice_standard/src/main/js/default/i18n/zh-CN.json
0 → 100755
浏览文件 @
6bd830db
{
"strings"
:
{
"hello"
:
"您好"
,
"world"
:
"世界"
}
}
\ No newline at end of file
sensors/miscdevice_standard/src/main/js/default/pages/index/index.css
0 → 100755
浏览文件 @
6bd830db
.container
{
flex-direction
:
column
;
justify-content
:
center
;
align-items
:
center
;
}
.title
{
font-size
:
100px
;
}
sensors/miscdevice_standard/src/main/js/default/pages/index/index.hml
0 → 100755
浏览文件 @
6bd830db
<div class="container">
<text class="title">
{{ $t('strings.hello') }} {{ title }}
</text>
</div>
sensors/miscdevice_standard/src/main/js/default/pages/index/index.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
{
Core
,
ExpectExtend
}
from
'
deccjsunit/index
'
const
injectRef
=
Object
.
getPrototypeOf
(
global
)
||
global
injectRef
.
regeneratorRuntime
=
require
(
'
@babel/runtime/regenerator
'
)
export
default
{
data
:
{
title
:
""
},
onInit
()
{
this
.
title
=
this
.
$t
(
'
strings.world
'
);
},
onShow
()
{
console
.
info
(
'
onShow finish
'
)
const
core
=
Core
.
getInstance
()
const
expectExtend
=
new
ExpectExtend
({
'
id
'
:
'
extend
'
})
core
.
addService
(
'
expect
'
,
expectExtend
)
core
.
init
()
const
configService
=
core
.
getDefaultService
(
'
config
'
)
this
.
timeout
=
5000
configService
.
setConfig
(
this
)
require
(
'
../../test/List.test
'
)
core
.
execute
()
},
onReady
()
{
},
}
sensors/miscdevice_standard/src/main/js/default/test/List.test.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
(
'
./Vibrator.test.js
'
)
sensors/miscdevice_standard/src/main/js/default/test/Vibrator.test.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
vibrator
from
'
@ohos.vibrator
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
"
VibratorJsTest
"
,
function
()
{
beforeAll
(
function
()
{
/*
* @tc.setup: setup invoked before all testcases
*/
console
.
info
(
'
beforeAll caled
'
)
})
afterAll
(
function
()
{
/*
* @tc.teardown: teardown invoked after all testcases
*/
console
.
info
(
'
afterAll caled
'
)
})
beforeEach
(
function
()
{
/*
* @tc.setup: setup invoked before each testcases
*/
console
.
info
(
'
beforeEach caled
'
)
})
afterEach
(
function
()
{
/*
* @tc.teardown: teardown invoked after each testcases
*/
console
.
info
(
'
afterEach caled
'
)
})
/*
* @tc.name:VibratorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest001
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest001 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest001 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
10
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest002
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest002 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest002 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
-
1
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest003
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest003 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest003 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
1800000
+
1
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest004
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest004 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest004 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
1800000
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest005
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest005 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest005 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
""
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest006
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest006 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest006 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
"
xxx
"
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest007
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest007 vibrator error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest007 vibrator success
'
);
expect
(
true
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
vibrate
(
"
haptic.clock.timer
"
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest008
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest008 stop error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest008 stop success
'
);
expect
(
true
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
stop
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_PRESET
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest009
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest001---------------------------
'
);
function
stopPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
vibrator
.
stop
(
"
time
"
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest009 stop error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
VibratorJsTest009 stop success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
vibrator
.
vibrate
(
180000
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest009 vibrate error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
VibratorJsTest009 vibrate success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
stopPromise
();
},
()
=>
{
console
.
info
(
"
VibratorJsTest009 reject
"
);
})
done
();
})
/*
* @tc.name:VibratorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest010
"
,
0
,
async
function
(
done
)
{
function
vibrateCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
VibratorJsTest010 stop success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
VibratorJsTest010 stop off
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
vibrator
.
stop
(
""
,
vibrateCallback
);
})
/*
* @tc.name:VibratorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest011
"
,
0
,
async
function
(
done
)
{
vibrator
.
vibrate
(
1000
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest011 vibrate success
"
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
false
).
assertTrue
();
console
.
log
(
"
VibratorJsTest011 vibrate error
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest012
"
,
0
,
async
function
(
done
)
{
vibrator
.
vibrate
(
-
1
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest012 vibrate error
"
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
"
VibratorJsTest012 vibrate success
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest013
"
,
0
,
async
function
(
done
)
{
vibrator
.
vibrate
(
1800000
+
1
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest013 vibrate error
"
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
"
VibratorJsTest013 vibrate success
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest014
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest014
"
,
0
,
async
function
(
done
)
{
vibrator
.
vibrate
(
vibrator
.
EffectId
.
EFFECT_CLOCK_TIMER
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest014 vibrate success
"
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
false
).
assertTrue
();
console
.
log
(
"
VibratorJsTest014 vibrate error
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest015
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest015
"
,
0
,
async
function
(
done
)
{
vibrator
.
vibrate
(
""
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest015 vibrate error
"
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
"
VibratorJsTest015 vibrate success
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest016
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest016
"
,
0
,
async
function
(
done
)
{
vibrator
.
stop
(
""
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest016 stop error
"
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
"
VibratorJsTest016 stop success
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest017
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest017
"
,
0
,
async
function
(
done
)
{
vibrator
.
stop
(
"
preset
"
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest017 off success
"
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
},
500
);
},
(
error
)
=>
{
expect
(
false
).
assertTrue
();
console
.
log
(
"
VibratorJsTest017 off error
"
);
setTimeout
(()
=>
{
done
();
},
500
);
});
})
/*
* @tc.name:VibratorJsTest018
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
VibratorJsTest018
"
,
0
,
async
function
(
done
)
{
function
stopPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
vibrator
.
stop
(
vibrator
.
VibratorStopMode
.
VIBRATOR_STOP_MODE_TIME
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest018 stop success
"
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
},
(
error
)
=>
{
expect
(
false
).
assertTrue
();
console
.
log
(
"
VibratorJsTest018 stop error
"
);
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
});
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
vibrator
.
vibrate
(
180000
).
then
(()
=>
{
console
.
log
(
"
VibratorJsTest018 vibrate success
"
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
},
(
error
)
=>
{
expect
(
false
).
assertTrue
();
console
.
log
(
"
VibratorJsTest018 vibrate error
"
);
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
});
})
await
promise
.
then
(()
=>
{
return
stopPromise
();
},
()
=>
{
console
.
info
(
"
VibratorJsTest018 reject
"
);
})
done
();
})
})
sensors/miscdevice_standard/src/main/resources/base/element/string.json
0 → 100755
浏览文件 @
6bd830db
{
"string"
:
[
{
"name"
:
"app_name"
,
"value"
:
"SensorJSApiTest"
},
{
"name"
:
"mainability_description"
,
"value"
:
"JS_Phone_Empty Feature Ability"
}
]
}
\ No newline at end of file
sensors/miscdevice_standard/src/main/resources/base/media/icon.png
0 → 100755
浏览文件 @
6bd830db
6.6 KB
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_acc.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
sensor
from
'
@ohos.sensor
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
"
SensorJsTest
"
,
function
()
{
beforeAll
(
function
()
{
/*
* @tc.setup: setup invoked before all testcases
*/
console
.
info
(
'
beforeAll caled
'
)
})
afterAll
(
function
()
{
/*
* @tc.teardown: teardown invoked after all testcases
*/
console
.
info
(
'
afterAll caled
'
)
})
beforeEach
(
function
()
{
/*
* @tc.setup: setup invoked before each testcases
*/
console
.
info
(
'
beforeEach caled
'
)
})
afterEach
(
function
()
{
/*
* @tc.teardown: teardown invoked after each testcases
*/
console
.
info
(
'
afterEach caled
'
)
})
/*
* @tc.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest001
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest001---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 off error
'
);
expect
(
false
).
assertTrue
();
console
.
info
(
'
setTimeout ..start
'
)
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 on success, x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest001 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest002
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest002---------------------------
'
);
function
onSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest002 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest002 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
-
1
,
onSensorCallback
);
})
/*
* @tc.name:SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest003
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest003---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
1
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
1
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 on success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
{
'
interval
'
:
200000000
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest003 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest004
"
,
0
,
function
()
{
console
.
info
(
'
----------------------SensorJsTest004---------------------------
'
);
sensor
.
on
(
1
,
function
()
{
},
{
'
interval
'
:
100000000
},
5
);
expect
(
true
).
assertTrue
();
console
.
info
(
'
----------------------SensorJsTest004--------------------------- end
'
);
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest005
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest005 once error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest005 once success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_ACCELEROMETER
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest006
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest006 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest006 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
-
1
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest007
"
,
0
,
function
()
{
sensor
.
once
(
1
,
function
()
{
},
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest008
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest008 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest008 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
-
1
,
offCallback
);
})
/*
* @tc.name:SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest009
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest009 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest009 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
1
,
offCallback
);
})
/*
* @tc.name:SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest010
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest010 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest010 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
1000000
,
offCallback
);
})
/*
* @tc.name:SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest011
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest011 once success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest011 once error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
1000000
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest012
"
,
0
,
async
function
(
done
)
{
function
onCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest012 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest012 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
1000000
,
onCallback
);
})
/*
* @tc.name:SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest013
"
,
0
,
function
()
{
sensor
.
off
(
1
,
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest014
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest014
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest014---------------------------
'
);
function
offPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
1
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off2 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
(
err
);
reject
(
err
)
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
()
},
500
);
}
});
})
}
function
offPromise1
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
1
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off1 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
1
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 on success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise1
();
}).
then
(()
=>
{
return
offPromise2
();
});
done
();
})
/*
* @tc.name:SensorJsTest015
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest015
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest015---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
1
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
onPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
1
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on2 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
1
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on1 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
onPromise2
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
/*
* @tc.name:SensorJsTest016
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest016
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest016---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
1
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
oncePromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
once
(
1
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 once error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 once success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
1
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 on1 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
oncePromise
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
})
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_gyr.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
sensor
from
'
@ohos.sensor
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
"
SensorJsTest
"
,
function
()
{
beforeAll
(
function
()
{
/*
* @tc.setup: setup invoked before all testcases
*/
console
.
info
(
'
beforeAll caled
'
)
})
afterAll
(
function
()
{
/*
* @tc.teardown: teardown invoked after all testcases
*/
console
.
info
(
'
afterAll caled
'
)
})
beforeEach
(
function
()
{
/*
* @tc.setup: setup invoked before each testcases
*/
console
.
info
(
'
beforeEach caled
'
)
})
afterEach
(
function
()
{
/*
* @tc.teardown: teardown invoked after each testcases
*/
console
.
info
(
'
afterEach caled
'
)
})
/*
* @tc.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest001
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest001---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 off error
'
);
expect
(
false
).
assertTrue
();
console
.
info
(
'
setTimeout ..start
'
)
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 on success, x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest001 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest002
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest002---------------------------
'
);
function
onSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest002 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest002 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
-
1
,
onSensorCallback
);
})
/*
* @tc.name:SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest003
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest003---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
2
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
2
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 on success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
{
'
interval
'
:
200000000
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest003 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest004
"
,
0
,
function
()
{
console
.
info
(
'
----------------------SensorJsTest004---------------------------
'
);
sensor
.
on
(
2
,
function
()
{
},
{
'
interval
'
:
100000000
},
5
);
expect
(
true
).
assertTrue
();
console
.
info
(
'
----------------------SensorJsTest004--------------------------- end
'
);
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest005
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest005 once error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest005 once success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_GYROSCOPE
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest006
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest006 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest006 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
-
1
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest007
"
,
0
,
function
()
{
sensor
.
once
(
2
,
function
()
{
},
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest008
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest008 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest008 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
-
1
,
offCallback
);
})
/*
* @tc.name:SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest009
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest009 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest009 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
2
,
offCallback
);
})
/*
* @tc.name:SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest010
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest010 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest010 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
1000000
,
offCallback
);
})
/*
* @tc.name:SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest011
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest011 once success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest011 once error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
1000000
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest012
"
,
0
,
async
function
(
done
)
{
function
onCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest012 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest012 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
1000000
,
onCallback
);
})
/*
* @tc.name:SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest013
"
,
0
,
function
()
{
sensor
.
off
(
2
,
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest014
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest014
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest014---------------------------
'
);
function
offPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
2
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off2 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
)
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
()
},
500
);
}
});
})
}
function
offPromise1
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
2
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off1 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
2
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 on success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise1
();
}).
then
(()
=>
{
return
offPromise2
();
});
done
();
})
/*
* @tc.name:SensorJsTest015
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest015
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest015---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
2
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
onPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
2
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on2 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
2
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on1 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
onPromise2
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
/*
* @tc.name:SensorJsTest016
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest016
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest016---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
2
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
oncePromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
once
(
2
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 once error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 once success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
2
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 on1 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
oncePromise
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
})
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_light.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
sensor
from
'
@ohos.sensor
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
"
SensorJsTest
"
,
function
()
{
beforeAll
(
function
()
{
/*
* @tc.setup: setup invoked before all testcases
*/
console
.
info
(
'
beforeAll caled
'
)
})
afterAll
(
function
()
{
/*
* @tc.teardown: teardown invoked after all testcases
*/
console
.
info
(
'
afterAll caled
'
)
})
beforeEach
(
function
()
{
/*
* @tc.setup: setup invoked before each testcases
*/
console
.
info
(
'
beforeEach caled
'
)
})
afterEach
(
function
()
{
/*
* @tc.teardown: teardown invoked after each testcases
*/
console
.
info
(
'
afterEach caled
'
)
})
/*
* @tc.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest001
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest001---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 off error
'
);
expect
(
false
).
assertTrue
();
console
.
info
(
'
setTimeout ..start
'
)
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 on success, success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest001 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest002
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest002---------------------------
'
);
function
onSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest002 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest002 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
-
1
,
onSensorCallback
);
})
/*
* @tc.name:SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest003
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest003---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
5
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
5
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 on success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
{
'
interval
'
:
200000000
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest003 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest004
"
,
0
,
function
()
{
console
.
info
(
'
----------------------SensorJsTest004---------------------------
'
);
sensor
.
on
(
5
,
function
()
{
},
{
'
interval
'
:
100000000
},
5
);
expect
(
true
).
assertTrue
();
console
.
info
(
'
----------------------SensorJsTest004--------------------------- end
'
);
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest005
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest005 once error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest005 once success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_AMBIENT_LIGHT
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest006
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest006 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest006 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
-
1
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest007
"
,
0
,
function
()
{
sensor
.
once
(
5
,
function
()
{
},
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest008
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest008 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest008 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
-
1
,
offCallback
);
})
/*
* @tc.name:SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest009
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest009 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest009 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
5
,
offCallback
);
})
/*
* @tc.name:SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest010
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest010 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest010 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
2000000
,
offCallback
);
})
/*
* @tc.name:SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest011
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest011 once success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest011 once error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
2000000
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest012
"
,
0
,
async
function
(
done
)
{
function
onCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest012 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest012 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
2000000
,
onCallback
);
})
/*
* @tc.name:SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest013
"
,
0
,
function
()
{
sensor
.
off
(
5
,
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest014
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest014
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest014---------------------------
'
);
function
offPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
5
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off2 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
)
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
()
},
500
);
}
});
})
}
function
offPromise1
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
5
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off1 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
5
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 on success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise1
();
}).
then
(()
=>
{
return
offPromise2
();
});
done
();
})
/*
* @tc.name:SensorJsTest015
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest015
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest015---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
5
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
onPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
5
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on2 success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
5
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on1 success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
onPromise2
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
/*
* @tc.name:SensorJsTest016
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest016
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest016---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
5
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
oncePromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
once
(
5
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 once error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 once success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
5
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 on1 success data:
'
+
data
.
intensity
);
expect
(
typeof
(
data
.
intensity
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
oncePromise
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
})
sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_mag.js
0 → 100755
浏览文件 @
6bd830db
/*
* 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
sensor
from
'
@ohos.sensor
'
import
{
describe
,
beforeAll
,
beforeEach
,
afterEach
,
afterAll
,
it
,
expect
}
from
'
deccjsunit/index
'
describe
(
"
SensorJsTest
"
,
function
()
{
beforeAll
(
function
()
{
/*
* @tc.setup: setup invoked before all testcases
*/
console
.
info
(
'
beforeAll caled
'
)
})
afterAll
(
function
()
{
/*
* @tc.teardown: teardown invoked after all testcases
*/
console
.
info
(
'
afterAll caled
'
)
})
beforeEach
(
function
()
{
/*
* @tc.setup: setup invoked before each testcases
*/
console
.
info
(
'
beforeEach caled
'
)
})
afterEach
(
function
()
{
/*
* @tc.teardown: teardown invoked after each testcases
*/
console
.
info
(
'
afterEach caled
'
)
})
/*
* @tc.name:SensorJsTest001
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest001
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest001---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 off error
'
);
expect
(
false
).
assertTrue
();
console
.
info
(
'
setTimeout ..start
'
)
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest001 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest001 on success, x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest001 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest002
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest002
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest002---------------------------
'
);
function
onSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest002 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest002 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
-
1
,
onSensorCallback
);
})
/*
* @tc.name:SensorJsTest003
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest003
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest003---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
6
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
},
1000
)
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
6
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest003 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest003 on success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
},
{
'
interval
'
:
200000000
});
})
await
promise
.
then
(()
=>
{
return
offPromise
();
},
()
=>
{
console
.
info
(
"
SensorJsTest003 reject
"
);
})
done
();
})
/*
* @tc.name:SensorJsTest004
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest004
"
,
0
,
function
()
{
console
.
info
(
'
----------------------SensorJsTest004---------------------------
'
);
sensor
.
on
(
6
,
function
()
{
},
{
'
interval
'
:
100000000
},
5
);
expect
(
true
).
assertTrue
();
console
.
info
(
'
----------------------SensorJsTest004--------------------------- end
'
);
})
/*
* @tc.name:SensorJsTest005
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest005
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest005 once error
'
);
expect
(
false
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest005 once success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
sensor
.
SensorType
.
SENSOR_TYPE_ID_MAGNETIC_FIELD
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest006
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest006
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest006 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest006 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
-
1
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest007
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest007
"
,
0
,
function
()
{
sensor
.
once
(
6
,
function
()
{
},
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest008
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest008
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest008 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest008 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
-
1
,
offCallback
);
})
/*
* @tc.name:SensorJsTest009
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest009
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest009 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest009 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
6
,
offCallback
);
})
/*
* @tc.name:SensorJsTest010
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest010
"
,
0
,
async
function
(
done
)
{
function
offCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest010 off success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest010 off error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
off
(
1000000
,
offCallback
);
})
/*
* @tc.name:SensorJsTest011
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest011
"
,
0
,
async
function
(
done
)
{
function
onceSensorCallback
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest011 once success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest011 once error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
once
(
1000000
,
onceSensorCallback
);
})
/*
* @tc.name:SensorJsTest012
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest012
"
,
0
,
async
function
(
done
)
{
function
onCallback
(
error
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest012 on success
'
);
expect
(
true
).
assertTrue
();
}
else
{
console
.
info
(
'
SensorJsTest012 on error
'
);
expect
(
false
).
assertTrue
();
}
setTimeout
(()
=>
{
done
();
},
500
);
}
sensor
.
on
(
1000000
,
onCallback
);
})
/*
* @tc.name:SensorJsTest013
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest013
"
,
0
,
function
()
{
sensor
.
off
(
6
,
5
);
expect
(
true
).
assertTrue
();
})
/*
* @tc.name:SensorJsTest014
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest014
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest014---------------------------
'
);
function
offPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
6
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off2 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
)
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
()
},
500
);
}
});
})
}
function
offPromise1
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
6
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 off1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 off1 success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
promise
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
6
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest014 on error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest014 on success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
promise
.
then
(()
=>
{
return
offPromise1
();
}).
then
(()
=>
{
return
offPromise2
();
});
done
();
})
/*
* @tc.name:SensorJsTest015
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest015
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest015---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
6
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
onPromise2
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
6
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on2 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on2 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
6
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest015 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest015 on1 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
onPromise2
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
/*
* @tc.name:SensorJsTest016
* @tc.desc:verify app info is not null
* @tc.type: FUNC
* @tc.require: Issue Number
*/
it
(
"
SensorJsTest016
"
,
0
,
async
function
(
done
)
{
console
.
info
(
'
----------------------SensorJsTest016---------------------------
'
);
function
offPromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
off
(
6
,
(
error
)
=>
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 off error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
done
();
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 off success
'
);
expect
(
true
).
assertTrue
();
setTimeout
(()
=>
{
done
();
resolve
();
},
500
);
}
});
})
}
function
oncePromise
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
once
(
6
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 once error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 once success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
}
let
onPromise1
=
new
Promise
((
resolve
,
reject
)
=>
{
sensor
.
on
(
6
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
info
(
'
SensorJsTest016 on1 error
'
);
expect
(
false
).
assertTrue
();
setTimeout
((
err
)
=>
{
reject
(
err
);
},
500
);
}
else
{
console
.
info
(
'
SensorJsTest016 on1 success x:
'
+
data
.
x
+
"
y:
"
+
data
.
y
+
"
z:
"
+
data
.
z
);
expect
(
typeof
(
data
.
x
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
y
)).
assertEqual
(
"
number
"
);
expect
(
typeof
(
data
.
z
)).
assertEqual
(
"
number
"
);
setTimeout
(()
=>
{
resolve
();
},
500
);
}
});
})
await
onPromise1
.
then
(()
=>
{
return
oncePromise
();
}).
then
(()
=>
{
return
offPromise
();
});
done
();
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录