incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/2] js commit: Adds tests for some of android's exec functions.
Date Fri, 28 Sep 2012 19:07:03 GMT
Adds tests for some of android's exec functions.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/b56626f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/b56626f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/b56626f1

Branch: refs/heads/master
Commit: b56626f1dbe0cd81e35ee88406a45dc859085f63
Parents: 01a2683
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Tue Sep 25 10:17:13 2012 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Sep 28 14:41:00 2012 -0400

----------------------------------------------------------------------
 lib/test/androidexec.js   |    1 +
 test/android/test.exec.js |   86 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/b56626f1/lib/test/androidexec.js
----------------------------------------------------------------------
diff --git a/lib/test/androidexec.js b/lib/test/androidexec.js
new file mode 120000
index 0000000..30a13f8
--- /dev/null
+++ b/lib/test/androidexec.js
@@ -0,0 +1 @@
+../android/exec.js
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/b56626f1/test/android/test.exec.js
----------------------------------------------------------------------
diff --git a/test/android/test.exec.js b/test/android/test.exec.js
new file mode 100644
index 0000000..797fb12
--- /dev/null
+++ b/test/android/test.exec.js
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+describe('exec.processMessages', function () {
+    var cordova = require('cordova'),
+        exec = require('cordova/androidexec'),
+        callbackSpy = jasmine.createSpy('callbackFromNative'),
+        origCallbackFromNative = cordova.callbackFromNative;
+
+    beforeEach(function() {
+        callbackSpy.reset();
+        cordova.callbackFromNative = callbackSpy;
+    });
+
+    afterEach(function() {
+        cordova.callbackFromNative = origCallbackFromNative;
+    });
+
+    function createCallbackMessage(success, keepCallback, status, callbackId, encodedPayload)
{
+        var ret = '';
+        ret += success ? 'S' : 'F';
+        ret += keepCallback ? '1' : '0';
+        ret += ' ' + status;
+        ret += ' ' + callbackId;
+        ret += ' ' + encodedPayload;
+        ret = ret.length + ' ' + ret;
+        return ret;
+    }
+
+    describe('processMessages', function() {
+        it('should handle payloads of false', function() {
+            var messages = createCallbackMessage(true, true, 1, 'id', 'f');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, false, true);
+        });
+        it('should handle payloads of true', function() {
+            var messages = createCallbackMessage(true, true, 1, 'id', 't');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, true, true);
+        });
+        it('should handle payloads of numbers', function() {
+            var messages = createCallbackMessage(true, true, 1, 'id', 'n-3.3');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, -3.3, true);
+        });
+        it('should handle payloads of strings', function() {
+            var messages = createCallbackMessage(true, true, 1, 'id', 'sHello world');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, 'Hello world', true);
+        });
+        it('should handle payloads of JSON objects', function() {
+            var messages = createCallbackMessage(true, true, 1, 'id', '{a:1}');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, {a:1}, true);
+        });
+        it('should handle payloads of JSON arrays', function() {
+            var messages = createCallbackMessage(true, true, 1, 'id', '[1]');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', true, 1, [1], true);
+        });
+        it('should handle other callback opts', function() {
+            var messages = createCallbackMessage(false, false, 3, 'id', 'sfoo');
+            exec.processMessages(messages);
+            expect(callbackSpy).toHaveBeenCalledWith('id', false, 3, 'foo', false);
+        });
+
+    });
+});


Mime
View raw message