Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit d4bb75a

Browse files
cuiyanxgrgustaf
authored andcommitted
[tests] Add sensor.timestamp in GenericSensor module (#951)
Signed-off-by: cuiyanx <[email protected]>
1 parent f3d587d commit d4bb75a

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

modules/GenericSensor.js

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function GenericSensor() {
5959
var changeFlag = false;
6060
var errorFlag = true;
6161
var defaultState, startState, stopState, middleState, middleNum;
62+
var middleNumX, middleNumY, middleNumZ, tmpTimestamp;
6263

6364
genericSensor.test = function(sensor, sensorType) {
6465
assert(typeof sensor === "object" && sensor !== null,
@@ -99,33 +100,52 @@ function GenericSensor() {
99100
};
100101

101102
sensor.onchange = function() {
103+
tmpTimestamp = sensor.timestamp;
104+
102105
if (changeFlag === true) {
106+
assert(typeof sensor.timestamp === "number" &&
107+
sensor.timestamp !== null,
108+
"sensor: timestamp value is defined");
109+
110+
middleNum = sensor.timestamp;
111+
sensor.timestamp = middleNum + 1;
112+
assert(sensor.timestamp === middleNum,
113+
"sensor: timestamp is readonly property");
114+
103115
if (sensorType === "AmbientLight") {
104116
assert(typeof sensor.illuminance === "number" &&
105-
typeof sensor.illuminance !== null,
117+
sensor.illuminance !== null,
106118
"sensor: reading value for '" + sensorType + "'");
107119

108120
middleNum = sensor.illuminance;
109121
sensor.illuminance = middleNum + 1;
110122
assert(sensor.illuminance === middleNum,
111123
"sensor: reading is readonly property");
112124

125+
console.log("sensor.timestamp: " + sensor.timestamp);
113126
console.log(sensorType + ": " + sensor.illuminance);
114127
} else if (sensorType === "Accelerometer" ||
115128
sensorType === "Gyroscope") {
116129
assert(typeof sensor.x === "number" &&
117-
typeof sensor.x !== null &&
130+
sensor.x !== null &&
118131
typeof sensor.y === "number" &&
119-
typeof sensor.y !== null &&
132+
sensor.y !== null &&
120133
typeof sensor.z === "number" &&
121-
typeof sensor.z !== null,
134+
sensor.z !== null,
122135
"sensor: reading value for '" + sensorType + "'");
123136

124-
middleNum = sensor.x;
125-
sensor.x = middleNum + 1;
126-
assert(sensor.x === middleNum,
137+
middleNumX = sensor.x;
138+
sensor.x = middleNumX + 1;
139+
middleNumY = sensor.y;
140+
sensor.y = middleNumY + 1;
141+
middleNumZ = sensor.z;
142+
sensor.z = middleNumZ + 1;
143+
assert(sensor.x === middleNumX &&
144+
sensor.y === middleNumY &&
145+
sensor.z === middleNumZ,
127146
"sensor: reading is readonly property");
128147

148+
console.log("sensor.timestamp: " + sensor.timestamp);
129149
console.log(sensorType + ": " +
130150
" x=" + sensor.x +
131151
" y=" + sensor.y +
@@ -171,6 +191,9 @@ function GenericSensor() {
171191
}, 20000);
172192

173193
setTimeout(function() {
194+
assert(tmpTimestamp === sensor.timestamp,
195+
"sensor: timestamp value is latest reading value");
196+
174197
result();
175198
}, 25000);
176199
}

0 commit comments

Comments
 (0)