You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/08/07 21:21:25 UTC
[10/12] git commit: CB-7160 move to tests dir, add nested plugin.xml
CB-7160 move to tests dir, add nested plugin.xml
F#ixing up auto tests
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/5c22f0d4
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/5c22f0d4
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/5c22f0d4
Branch: refs/heads/master
Commit: 5c22f0d47da00f085c6c4a64148f8036b4df4ca6
Parents: 0defcb7
Author: Staci Cooper <sm...@us.ibm.com>
Authored: Wed Jul 30 16:17:10 2014 -0400
Committer: Staci Cooper <sm...@us.ibm.com>
Committed: Thu Jul 31 12:30:22 2014 -0400
----------------------------------------------------------------------
test/tests.js | 287 --------------------------------------------------
tests/plugin.xml | 29 +++++
tests/tests.js | 287 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 316 insertions(+), 287 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/5c22f0d4/test/tests.js
----------------------------------------------------------------------
diff --git a/test/tests.js b/test/tests.js
deleted file mode 100644
index 75016d0..0000000
--- a/test/tests.js
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.
- *
-*/
-
-exports.defineAutoTests = function () {
- describe('Accelerometer (navigator.accelerometer)', function () {
- var fail = function(done) {
- expect(true).toBe(false);
- done();
- };
-
- it("accelerometer.spec.1 should exist", function () {
- expect(navigator.accelerometer).toBeDefined();
- });
-
- describe("getCurrentAcceleration", function() {
- it("accelerometer.spec.2 should exist", function() {
- expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined();
- expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true);
- });
-
- it("accelerometer.spec.3 success callback should be called with an Acceleration object", function(done) {
- var win = function(a) {
- expect(a).toBeDefined();
- expect(a.x).toBeDefined();
- expect(typeof a.x == 'number').toBe(true);
- expect(a.y).toBeDefined();
- expect(typeof a.y == 'number').toBe(true);
- expect(a.z).toBeDefined();
- expect(typeof a.z == 'number').toBe(true);
- expect(a.timestamp).toBeDefined();
- expect(typeof a.timestamp).toBe('number');
- done();
- };
-
- navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
- });
-
- it("accelerometer.spec.4 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function(done) {
- var reasonableThreshold = 15;
- var win = function(a) {
- expect(a.x).toBeLessThan(reasonableThreshold);
- expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.y).toBeLessThan(reasonableThreshold);
- expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.z).toBeLessThan(reasonableThreshold);
- expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
- done()
- };
-
- navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null,done));
- });
-
- it("accelerometer.spec.5 success callback Acceleration object should return a recent timestamp", function(done) {
- var veryRecently = (new Date()).getTime();
- // Need to check that dates returned are not vastly greater than a recent time stamp.
- // In case the timestamps returned are ridiculously high
- var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
- var win = function(a) {
- expect(a.timestamp).toBeGreaterThan(veryRecently);
- expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
- done();
- };
-
- navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null,done));
- });
- });
-
- describe("watchAcceleration", function() {
- var id;
-
- afterEach(function() {
- navigator.accelerometer.clearWatch(id);
- });
-
- it("accelerometer.spec.6 should exist", function() {
- expect(navigator.accelerometer.watchAcceleration).toBeDefined();
- expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true);
- });
-
- it("accelerometer.spec.7 success callback should be called with an Acceleration object", function(done) {
- var win = function(a) {
- expect(a).toBeDefined();
- expect(a.x).toBeDefined();
- expect(typeof a.x == 'number').toBe(true);
- expect(a.y).toBeDefined();
- expect(typeof a.y == 'number').toBe(true);
- expect(a.z).toBeDefined();
- expect(typeof a.z == 'number').toBe(true);
- expect(a.timestamp).toBeDefined();
- expect(typeof a.timestamp).toBe('number');
- done();
- };
-
- id = navigator.accelerometer.watchAcceleration(win, fail.bind(null,done), {frequency:100});
- });
-
- it("accelerometer.spec.8 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function(done) {
- var reasonableThreshold = 15;
- var win = function(a) {
- expect(a.x).toBeLessThan(reasonableThreshold);
- expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.y).toBeLessThan(reasonableThreshold);
- expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
- expect(a.z).toBeLessThan(reasonableThreshold);
- expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
- done();
- };
-
- id = navigator.accelerometer.watchAcceleration(win, fail.bind(null,done), {frequency:100});
- });
-
- it("accelerometer.spec.9 success callback Acceleration object should return a recent timestamp", function(done) {
- var veryRecently = (new Date()).getTime();
- // Need to check that dates returned are not vastly greater than a recent time stamp.
- // In case the timestamps returned are ridiculously high
- var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
- var win = function(a) {
- expect(a.timestamp).toBeGreaterThan(veryRecently);
- expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
- done();
- };
-
- id = navigator.accelerometer.watchAcceleration(win, fail.bind(null,done), {frequency:100});
- });
- });
-
- describe("clearWatch", function() {
- it("accelerometer.spec.10 should exist", function() {
- expect(navigator.accelerometer.clearWatch).toBeDefined();
- expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true);
- });
-
- it("accelerometer.spec.11 should clear an existing watch", function(done) {
- var id;
-
- // expect win to get called exactly once
- var win = function(a) {
- // clear watch on first call
- navigator.accelerometer.clearWatch(id);
- // if win isn't called again in 201 ms we assume success
- var tid = setTimeout(function() {
- expect(true).toBe(true);
- done();
- }, 101);
- // if win is called again, clear the timeout and fail the test
- win = function() {
- clearTimeout(tid);
- fail(done);
- }
- };
-
- // wrap the success call in a closure since the value of win changes between calls
- id = navigator.accelerometer.watchAcceleration(function() { win(); }, fail.bind(null, done), {frequency:100});
- });
- });
- });
-};
-
-/******************************************************************************/
-/******************************************************************************/
-/******************************************************************************/
-
-exports.defineManualTests = function (contentEl, createActionButton) {
- function roundNumber(num) {
- var dec = 3;
- var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
- return result;
- }
-
- var watchAccelId = null;
-
- /**
- * Start watching acceleration
- */
- var watchAccel = function () {
- console.log("watchAccel()");
-
- // Success callback
- var success = function (a) {
- document.getElementById('x').innerHTML = roundNumber(a.x);
- document.getElementById('y').innerHTML = roundNumber(a.y);
- document.getElementById('z').innerHTML = roundNumber(a.z);
- };
-
- // Fail callback
- var fail = function (e) {
- console.log("watchAccel fail callback with error code " + e);
- stopAccel();
- setAccelStatus(Accelerometer.ERROR_MSG[e]);
- };
-
- // Update acceleration every 1 sec
- var opt = {};
- opt.frequency = 1000;
- watchAccelId = navigator.accelerometer.watchAcceleration(success, fail, opt);
-
- setAccelStatus("Running");
- };
-
- /**
- * Stop watching the acceleration
- */
- var stopAccel = function () {
- console.log("stopAccel()");
- setAccelStatus("Stopped");
- if (watchAccelId) {
- navigator.accelerometer.clearWatch(watchAccelId);
- watchAccelId = null;
- }
- };
-
- /**
- * Get current acceleration
- */
- var getAccel = function () {
- console.log("getAccel()");
-
- // Stop accel if running
- stopAccel();
-
- // Success callback
- var success = function (a) {
- document.getElementById('x').innerHTML = roundNumber(a.x);
- document.getElementById('y').innerHTML = roundNumber(a.y);
- document.getElementById('z').innerHTML = roundNumber(a.z);
- console.log("getAccel success callback");
- };
-
- // Fail callback
- var fail = function (e) {
- console.log("getAccel fail callback with error code " + e);
- setAccelStatus(Accelerometer.ERROR_MSG[e]);
- };
-
- // Make call
- var opt = {};
- navigator.accelerometer.getCurrentAcceleration(success, fail, opt);
- };
-
- /**
- * Set accelerometer status
- */
- var setAccelStatus = function (status) {
- document.getElementById('accel_status').innerHTML = status;
- };
-
- /******************************************************************************/
-
- contentEl.innerHTML = '<div id="info">' +
- 'Status: <span id="accel_status">Stopped</span>' +
- '<table width="100%">' +
- '<tr><td width="20%">X:</td><td id="x"> </td></tr>' +
- '<tr><td width="20%">Y:</td><td id="y"> </td></tr>' +
- '<tr><td width="20%">Z:</td><td id="z"> </td></tr>' +
- '</table></div>' +
- '<div id="actions"></div>';
-
- createActionButton('Get Acceleration', function () {
- getAccel();
- }, 'actions');
-
- createActionButton('Start Watch', function () {
- watchAccel();
- }, 'actions');
-
- createActionButton('Clear Watch', function () {
- stopAccel();
- }, 'actions');
-};
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/5c22f0d4/tests/plugin.xml
----------------------------------------------------------------------
diff --git a/tests/plugin.xml b/tests/plugin.xml
new file mode 100644
index 0000000..bcdbc88
--- /dev/null
+++ b/tests/plugin.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+ id="org.apache.cordova.device-motion.tests"
+ version="0.2.9-dev">
+ <name>Cordova Device Motion Plugin Tests</name>
+ <license>Apache 2.0</license>
+
+ <js-module src="tests.js" name="tests">
+ </js-module>
+</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/5c22f0d4/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
new file mode 100644
index 0000000..1deb0c4
--- /dev/null
+++ b/tests/tests.js
@@ -0,0 +1,287 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+*/
+
+exports.defineAutoTests = function () {
+ describe('Accelerometer (navigator.accelerometer)', function () {
+ var fail = function (done) {
+ expect(true).toBe(false);
+ done();
+ };
+
+ it("accelerometer.spec.1 should exist", function () {
+ expect(navigator.accelerometer).toBeDefined();
+ });
+
+ describe("getCurrentAcceleration", function () {
+ it("accelerometer.spec.2 should exist", function () {
+ expect(typeof navigator.accelerometer.getCurrentAcceleration).toBeDefined();
+ expect(typeof navigator.accelerometer.getCurrentAcceleration == 'function').toBe(true);
+ });
+
+ it("accelerometer.spec.3 success callback should be called with an Acceleration object", function (done) {
+ var win = function (a) {
+ expect(a).toBeDefined();
+ expect(a.x).toBeDefined();
+ expect(typeof a.x == 'number').toBe(true);
+ expect(a.y).toBeDefined();
+ expect(typeof a.y == 'number').toBe(true);
+ expect(a.z).toBeDefined();
+ expect(typeof a.z == 'number').toBe(true);
+ expect(a.timestamp).toBeDefined();
+ expect(typeof a.timestamp).toBe('number');
+ done();
+ };
+
+ navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
+ });
+
+ it("accelerometer.spec.4 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function (done) {
+ var reasonableThreshold = 15;
+ var win = function (a) {
+ expect(a.x).toBeLessThan(reasonableThreshold);
+ expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
+ expect(a.y).toBeLessThan(reasonableThreshold);
+ expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
+ expect(a.z).toBeLessThan(reasonableThreshold);
+ expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
+ done()
+ };
+
+ navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
+ });
+
+ it("accelerometer.spec.5 success callback Acceleration object should return a recent timestamp", function (done) {
+ var veryRecently = (new Date()).getTime();
+ // Need to check that dates returned are not vastly greater than a recent time stamp.
+ // In case the timestamps returned are ridiculously high
+ var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
+ var win = function (a) {
+ expect(a.timestamp).toBeGreaterThan(veryRecently);
+ expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
+ done();
+ };
+
+ navigator.accelerometer.getCurrentAcceleration(win, fail.bind(null, done));
+ });
+ });
+
+ describe("watchAcceleration", function () {
+ var id;
+
+ afterEach(function () {
+ navigator.accelerometer.clearWatch(id);
+ });
+
+ it("accelerometer.spec.6 should exist", function () {
+ expect(navigator.accelerometer.watchAcceleration).toBeDefined();
+ expect(typeof navigator.accelerometer.watchAcceleration == 'function').toBe(true);
+ });
+
+ it("accelerometer.spec.7 success callback should be called with an Acceleration object", function (done) {
+ var win = function (a) {
+ expect(a).toBeDefined();
+ expect(a.x).toBeDefined();
+ expect(typeof a.x == 'number').toBe(true);
+ expect(a.y).toBeDefined();
+ expect(typeof a.y == 'number').toBe(true);
+ expect(a.z).toBeDefined();
+ expect(typeof a.z == 'number').toBe(true);
+ expect(a.timestamp).toBeDefined();
+ expect(typeof a.timestamp).toBe('number');
+ done();
+ };
+
+ id = navigator.accelerometer.watchAcceleration(win, fail.bind(null, done), { frequency: 100 });
+ });
+
+ it("accelerometer.spec.8 success callback Acceleration object should have (reasonable) values for x, y and z expressed in m/s^2", function (done) {
+ var reasonableThreshold = 15;
+ var win = function (a) {
+ expect(a.x).toBeLessThan(reasonableThreshold);
+ expect(a.x).toBeGreaterThan(reasonableThreshold * -1);
+ expect(a.y).toBeLessThan(reasonableThreshold);
+ expect(a.y).toBeGreaterThan(reasonableThreshold * -1);
+ expect(a.z).toBeLessThan(reasonableThreshold);
+ expect(a.z).toBeGreaterThan(reasonableThreshold * -1);
+ done();
+ };
+
+ id = navigator.accelerometer.watchAcceleration(win, fail.bind(null, done), { frequency: 100 });
+ });
+
+ it("accelerometer.spec.9 success callback Acceleration object should return a recent timestamp", function (done) {
+ var veryRecently = (new Date()).getTime();
+ // Need to check that dates returned are not vastly greater than a recent time stamp.
+ // In case the timestamps returned are ridiculously high
+ var reasonableTimeLimit = veryRecently + 5000; // 5 seconds from now
+ var win = function (a) {
+ expect(a.timestamp).toBeGreaterThan(veryRecently);
+ expect(a.timestamp).toBeLessThan(reasonableTimeLimit);
+ done();
+ };
+
+ id = navigator.accelerometer.watchAcceleration(win, fail.bind(null, done), { frequency: 100 });
+ });
+ });
+
+ describe("clearWatch", function () {
+ it("accelerometer.spec.10 should exist", function () {
+ expect(navigator.accelerometer.clearWatch).toBeDefined();
+ expect(typeof navigator.accelerometer.clearWatch == 'function').toBe(true);
+ });
+
+ it("accelerometer.spec.11 should clear an existing watch", function (done) {
+ var id;
+
+ // expect win to get called exactly once
+ var win = function (a) {
+ // clear watch on first call
+ navigator.accelerometer.clearWatch(id);
+ // if win isn't called again in 201 ms we assume success
+ var tid = setTimeout(function () {
+ expect(true).toBe(true);
+ done();
+ }, 101);
+ // if win is called again, clear the timeout and fail the test
+ win = function () {
+ clearTimeout(tid);
+ fail(done);
+ }
+ };
+
+ // wrap the success call in a closure since the value of win changes between calls
+ id = navigator.accelerometer.watchAcceleration(function () { win(); }, fail.bind(null, done), { frequency: 100 });
+ });
+ });
+ });
+};
+
+/******************************************************************************/
+/******************************************************************************/
+/******************************************************************************/
+
+exports.defineManualTests = function (contentEl, createActionButton) {
+ function roundNumber(num) {
+ var dec = 3;
+ var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
+ return result;
+ }
+
+ var watchAccelId = null;
+
+ /**
+ * Start watching acceleration
+ */
+ var watchAccel = function () {
+ console.log("watchAccel()");
+
+ // Success callback
+ var success = function (a) {
+ document.getElementById('x').innerHTML = roundNumber(a.x);
+ document.getElementById('y').innerHTML = roundNumber(a.y);
+ document.getElementById('z').innerHTML = roundNumber(a.z);
+ };
+
+ // Fail callback
+ var fail = function (e) {
+ console.log("watchAccel fail callback with error code " + e);
+ stopAccel();
+ setAccelStatus(Accelerometer.ERROR_MSG[e]);
+ };
+
+ // Update acceleration every 1 sec
+ var opt = {};
+ opt.frequency = 1000;
+ watchAccelId = navigator.accelerometer.watchAcceleration(success, fail, opt);
+
+ setAccelStatus("Running");
+ };
+
+ /**
+ * Stop watching the acceleration
+ */
+ var stopAccel = function () {
+ console.log("stopAccel()");
+ setAccelStatus("Stopped");
+ if (watchAccelId) {
+ navigator.accelerometer.clearWatch(watchAccelId);
+ watchAccelId = null;
+ }
+ };
+
+ /**
+ * Get current acceleration
+ */
+ var getAccel = function () {
+ console.log("getAccel()");
+
+ // Stop accel if running
+ stopAccel();
+
+ // Success callback
+ var success = function (a) {
+ document.getElementById('x').innerHTML = roundNumber(a.x);
+ document.getElementById('y').innerHTML = roundNumber(a.y);
+ document.getElementById('z').innerHTML = roundNumber(a.z);
+ console.log("getAccel success callback");
+ };
+
+ // Fail callback
+ var fail = function (e) {
+ console.log("getAccel fail callback with error code " + e);
+ setAccelStatus(Accelerometer.ERROR_MSG[e]);
+ };
+
+ // Make call
+ var opt = {};
+ navigator.accelerometer.getCurrentAcceleration(success, fail, opt);
+ };
+
+ /**
+ * Set accelerometer status
+ */
+ var setAccelStatus = function (status) {
+ document.getElementById('accel_status').innerHTML = status;
+ };
+
+ /******************************************************************************/
+
+ contentEl.innerHTML = '<div id="info">' +
+ 'Status: <span id="accel_status">Stopped</span>' +
+ '<table width="100%">' +
+ '<tr><td width="20%">X:</td><td id="x"> </td></tr>' +
+ '<tr><td width="20%">Y:</td><td id="y"> </td></tr>' +
+ '<tr><td width="20%">Z:</td><td id="z"> </td></tr>' +
+ '</table></div>' +
+ '<div id="actions"></div>';
+
+ createActionButton('Get Acceleration', function () {
+ getAccel();
+ }, 'actions');
+
+ createActionButton('Start Watch', function () {
+ watchAccel();
+ }, 'actions');
+
+ createActionButton('Clear Watch', function () {
+ stopAccel();
+ }, 'actions');
+};