diff --git a/sensors/BUILD.gn b/sensors/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b9ac3de4b76b5ef1e93c0012611753b7a65ab97f --- /dev/null +++ b/sensors/BUILD.gn @@ -0,0 +1,21 @@ +# 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("//build/ohos_var.gni") + +group("sensor") { + testonly = true + if (is_standard_system) { + deps = [ "sensor_standard:sensor_js_test" ] + } +} diff --git a/sensors/sensor_standard/BUILD.gn b/sensors/sensor_standard/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..564786fe4ef069edb7721f27842ad8c58296e87e --- /dev/null +++ b/sensors/sensor_standard/BUILD.gn @@ -0,0 +1,30 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +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 = "SensorJSApiTest" +} +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" +} diff --git a/sensors/sensor_standard/Test.json b/sensors/sensor_standard/Test.json new file mode 100644 index 0000000000000000000000000000000000000000..6202ee84c3563e09b3decdf8b052296b9293d503 --- /dev/null +++ b/sensors/sensor_standard/Test.json @@ -0,0 +1,18 @@ +{ + "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": [ + "SensorJSApiTest.hap" + ], + "type": "AppInstallKit", + "cleanup-apps": true + } + ] +} diff --git a/sensors/sensor_standard/signature/openharmony_sx.p7b b/sensors/sensor_standard/signature/openharmony_sx.p7b new file mode 100644 index 0000000000000000000000000000000000000000..9be1e98fa4c0c28ca997ed660112fa16b194f0f5 Binary files /dev/null and b/sensors/sensor_standard/signature/openharmony_sx.p7b differ diff --git a/sensors/sensor_standard/src/main/config.json b/sensors/sensor_standard/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..764f279caee28996e84cbbece7d224b097c2e836 --- /dev/null +++ b/sensors/sensor_standard/src/main/config.json @@ -0,0 +1,60 @@ +{ + "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 + } + } + ] + } +} diff --git a/sensors/sensor_standard/src/main/js/default/app.js b/sensors/sensor_standard/src/main/js/default/app.js new file mode 100644 index 0000000000000000000000000000000000000000..e423f4bce4698ec1d7dc86c3eea3990a5e7b1085 --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/app.js @@ -0,0 +1,23 @@ +/* + * 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'); + } +}; diff --git a/sensors/sensor_standard/src/main/js/default/i18n/en-US.json b/sensors/sensor_standard/src/main/js/default/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..e63c70d978a3a53be988388c87182f81785e170c --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/i18n/en-US.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "Hello", + "world": "World" + } +} \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/js/default/i18n/zh-CN.json b/sensors/sensor_standard/src/main/js/default/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..de6ee5748322f44942c1b003319d8e66c837675f --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/i18n/zh-CN.json @@ -0,0 +1,6 @@ +{ + "strings": { + "hello": "您好", + "world": "世界" + } +} \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/js/default/pages/index/index.css b/sensors/sensor_standard/src/main/js/default/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..6fda792753f2e15f22b529c7b90a82185b2770bf --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/pages/index/index.css @@ -0,0 +1,9 @@ +.container { + flex-direction: column; + justify-content: center; + align-items: center; +} + +.title { + font-size: 100px; +} diff --git a/sensors/sensor_standard/src/main/js/default/pages/index/index.hml b/sensors/sensor_standard/src/main/js/default/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..f64b040a5ae394dbaa5e185e1ecd4f4556b92184 --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/pages/index/index.hml @@ -0,0 +1,5 @@ +
+ + {{ $t('strings.hello') }} {{ title }} + +
diff --git a/sensors/sensor_standard/src/main/js/default/pages/index/index.js b/sensors/sensor_standard/src/main/js/default/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..173f299a3b96a91ab293b130a7065f3077e95dbd --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/pages/index/index.js @@ -0,0 +1,46 @@ +/* + * 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() { + }, +} diff --git a/sensors/sensor_standard/src/main/js/default/test/List.test.js b/sensors/sensor_standard/src/main/js/default/test/List.test.js new file mode 100644 index 0000000000000000000000000000000000000000..988585d79106649446b547c85d1bc1705189af8b --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/test/List.test.js @@ -0,0 +1,19 @@ +/* + * 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('./SensorOnOffTest.test.js') + + + diff --git a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d7613c279bc57a7b6e3436f772c8a0b0b402ba --- /dev/null +++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test.js @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the 'License'); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an 'AS IS' BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// @ts-nocheck + +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index' +import sensor from '@ohos.sensor' + +function sleep (NumberMillis) { + var now = new Date() + var exitTime = now.getTime() + NumberMillis + while(true) { + now = new Date() + if (now.getTime > exitTime) { + return + } + } +} + +describe('SystemParameterTest', function () { + beforeAll(function() { + console.info('beforeAll caled') + }) + + afterAll(function() { + console.info('afterAll caled') + }) + + beforeEach(function() { + console.info('beforeEach caled') + }) + + afterEach(function() { + console.info('afterEach caled') + }) + + /** + * @tc.number SUB_SENSORS_Sensor_JSTest_0010 + * @tc.name testRegisterSensortest001 + * @tc.desc test get sensor data by sensor id. + */ + it('SUB_SENSORS_Sensor_JSTest_0010', 0, async function (done) { + console.info('SUB_SENSORS_Sensor_JSTest_0010 start'); + await sensor.on(0, function(error, data) { + if (error) { + console.info('testRegisterSensortest001 on error'); + expect(false).assertTrue(); + done(); + } else { + console.info('testRegisterSensortest001 on success'); + expect(data.x).assertInstanceOf('Number'); + done(); + } + }); + console.info('SUB_SENSORS_Sensor_JSTest_0010 end'); + }) + + /** + * @tc.number SUB_SENSORS_Sensor_JSTest_0020 + * @tc.name testRegisterSensortest002 + * @tc.desc test get sensor data by wrong sensor id. + */ + it('SUB_SENSORS_Sensor_JSTest_0020', 0, async function (done) { + console.info('SUB_SENSORS_Sensor_JSTest_0020 start'); + await sensor.on(-1, function(error, data) { + if (error) { + console.info('testRegisterSensortest002 on error'); + expect(true).assertTrue(); + done(); + } else { + console.info('testRegisterSensortest002 on success'); + expect(false).assertTrue(); + done(); + } + }); + console.info('SUB_SENSORS_Sensor_JSTest_0020 end'); + }) + +}) \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/resources/base/element/string.json b/sensors/sensor_standard/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..7ab5369dd846fbc8870f29fc2b3c79496838da4b --- /dev/null +++ b/sensors/sensor_standard/src/main/resources/base/element/string.json @@ -0,0 +1,12 @@ +{ + "string": [ + { + "name": "app_name", + "value": "SensorJSApiTest" + }, + { + "name": "mainability_description", + "value": "JS_Phone_Empty Feature Ability" + } + ] +} \ No newline at end of file diff --git a/sensors/sensor_standard/src/main/resources/base/media/icon.png b/sensors/sensor_standard/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/sensors/sensor_standard/src/main/resources/base/media/icon.png differ diff --git a/test_packages.gni b/test_packages.gni index 2b73481164402c8b431358b03c37a8e8b770c581..4dd9eb6d3352abd675c34421300cc21bea8d975c 100755 --- a/test_packages.gni +++ b/test_packages.gni @@ -32,6 +32,7 @@ _all_test_packages = [ "${ACTS_ROOT}/miscservices:miscservices", "${ACTS_ROOT}/powermgr:powermgr", "${ACTS_ROOT}/startup:startup", + "${ACTS_ROOT}/sensors:sensor", "${ACTS_ROOT}/distributeddatamgr:distributeddatamgr", # "${ACTS_ROOT}/distributedschedule:distributedschedule",