From bacde40a6f291e148e2c0137a30b464aa9329845 Mon Sep 17 00:00:00 2001
From: logic42 <wanglong108@huawei.com>
Date: Sat, 19 Feb 2022 12:22:37 +0000
Subject: [PATCH] add sensor testcasse

Signed-off-by: logic42 <wanglong108@huawei.com>
---
 .../js/default/test/SensorOnOffTest.test.js   | 61 ++++++++++---------
 .../SensorOnOffTest.test_Rotation_Vector.js   | 10 +--
 2 files changed, 37 insertions(+), 34 deletions(-)

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
index c0d7613c2..601361068 100644
--- a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test.js
+++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test.js
@@ -18,10 +18,10 @@
 import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index'
 import sensor from '@ohos.sensor'
 
-function sleep (NumberMillis) {
+function sleep(NumberMillis) {
     var now = new Date()
     var exitTime = now.getTime() + NumberMillis
-    while(true) {
+    while (true) {
         now = new Date()
         if (now.getTime > exitTime) {
             return
@@ -30,20 +30,20 @@ function sleep (NumberMillis) {
 }
 
 describe('SystemParameterTest', function () {
-    beforeAll(function() {
-         console.info('beforeAll caled')
+    beforeAll(function () {
+        console.info('beforeAll caled')
     })
-    
-    afterAll(function() {
-         console.info('afterAll caled')
+
+    afterAll(function () {
+        console.info('afterAll caled')
     })
-    
-    beforeEach(function() {
-         console.info('beforeEach caled')
+
+    beforeEach(function () {
+        console.info('beforeEach caled')
     })
-    
-    afterEach(function() {
-         console.info('afterEach caled')
+
+    afterEach(function () {
+        console.info('afterEach caled')
     })
 
     /**
@@ -51,9 +51,9 @@ describe('SystemParameterTest', function () {
      * @tc.name      testRegisterSensortest001
      * @tc.desc      test get sensor data by sensor id.
      */
-     it('SUB_SENSORS_Sensor_JSTest_0010', 0, async function (done) {
+    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) {
+        await sensor.on(0, function (error, data) {
             if (error) {
                 console.info('testRegisterSensortest001  on error');
                 expect(false).assertTrue();
@@ -61,6 +61,7 @@ describe('SystemParameterTest', function () {
             } else {
                 console.info('testRegisterSensortest001  on success');
                 expect(data.x).assertInstanceOf('Number');
+                expect(data.timestamp).assertInstanceOf('Number');
                 done();
             }
         });
@@ -72,20 +73,20 @@ describe('SystemParameterTest', function () {
      * @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');
-        })
+    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/js/default/test/SensorOnOffTest.test_Rotation_Vector.js b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Rotation_Vector.js
index 6bbf400fb..e877ccf01 100755
--- a/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Rotation_Vector.js
+++ b/sensors/sensor_standard/src/main/js/default/test/SensorOnOffTest.test_Rotation_Vector.js
@@ -86,11 +86,12 @@ describe("SensorJsTest", function () {
                         reject(err);
                     }, 500);
                 } else {
-                    console.info('SensorRotationVectorJSTest001  on  success, x: ' 
-                        + data.x + "y: " + data.y + "z: " + data.z);
+                    console.info('SensorRotationVectorJSTest001  on  success, x: '
+                        + data.x + "y: " + data.y + "z: " + data.z + "w: " + data.w);
                     expect(typeof (data.x)).assertEqual("number");
                     expect(typeof (data.y)).assertEqual("number");
                     expect(typeof (data.z)).assertEqual("number");
+                    expect(typeof (data.w)).assertEqual("number");
                     setTimeout(() => {
                         resolve();
                     }, 500);
@@ -117,11 +118,12 @@ describe("SensorJsTest", function () {
                 console.info('SensorRotationVectorJSTest005  once error');
                 expect(false).assertTrue();
             } else {
-                console.info('SensorRotationVectorJSTest005  on  success, x: ' 
-                    + data.x + "y: " + data.y + "z: " + data.z);
+                console.info('SensorRotationVectorJSTest005  on  success, x: '
+                    + data.x + "y: " + data.y + "z: " + data.z + "w: " + data.w);
                 expect(typeof (data.x)).assertEqual("number");
                 expect(typeof (data.y)).assertEqual("number");
                 expect(typeof (data.z)).assertEqual("number");
+                expect(typeof (data.w)).assertEqual("number");
             }
             setTimeout(() => {
                 done();
-- 
GitLab