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

[tests] Add sensor.timestamp in GenericSensor module #951

Merged
merged 1 commit into from
Apr 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions modules/GenericSensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function GenericSensor() {
var changeFlag = false;
var errorFlag = true;
var defaultState, startState, stopState, middleState, middleNum;
var middleNumX, middleNumY, middleNumZ, tmpTimestamp;

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

sensor.onchange = function() {
tmpTimestamp = sensor.timestamp;

if (changeFlag === true) {
assert(typeof sensor.timestamp === "number" &&
sensor.timestamp !== null,
"sensor: timestamp value is defined");

middleNum = sensor.timestamp;
sensor.timestamp = middleNum + 1;
assert(sensor.timestamp === middleNum,
"sensor: timestamp is readonly property");

if (sensorType === "AmbientLight") {
assert(typeof sensor.illuminance === "number" &&
typeof sensor.illuminance !== null,
sensor.illuminance !== null,
"sensor: reading value for '" + sensorType + "'");

middleNum = sensor.illuminance;
sensor.illuminance = middleNum + 1;
assert(sensor.illuminance === middleNum,
"sensor: reading is readonly property");

console.log("sensor.timestamp: " + sensor.timestamp);
console.log(sensorType + ": " + sensor.illuminance);
} else if (sensorType === "Accelerometer" ||
sensorType === "Gyroscope") {
assert(typeof sensor.x === "number" &&
typeof sensor.x !== null &&
sensor.x !== null &&
typeof sensor.y === "number" &&
typeof sensor.y !== null &&
sensor.y !== null &&
typeof sensor.z === "number" &&
typeof sensor.z !== null,
sensor.z !== null,
"sensor: reading value for '" + sensorType + "'");

middleNum = sensor.x;
sensor.x = middleNum + 1;
assert(sensor.x === middleNum,
middleNumX = sensor.x;
sensor.x = middleNumX + 1;
middleNumY = sensor.y;
sensor.y = middleNumY + 1;
middleNumZ = sensor.z;
sensor.z = middleNumZ + 1;
assert(sensor.x === middleNumX &&
sensor.y === middleNumY &&
sensor.z === middleNumZ,
"sensor: reading is readonly property");

console.log("sensor.timestamp: " + sensor.timestamp);
console.log(sensorType + ": " +
" x=" + sensor.x +
" y=" + sensor.y +
Expand Down Expand Up @@ -171,6 +191,9 @@ function GenericSensor() {
}, 20000);

setTimeout(function() {
assert(tmpTimestamp === sensor.timestamp,
"sensor: timestamp value is latest reading value");

result();
}, 25000);
}
Expand Down