Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(92)

Delta Between Two Patch Sets: gears/test/testcases/database2_tests.js

Issue 717: Database2Values, argument conversion implemented (Closed) SVN Base: http://google-gears.googlecode.com/svn/contrib/dimitri.glazkov/database2/
Left Patch Set: ready for another look. Created 3 months, 2 weeks ago
Right Patch Set: Created 3 months, 2 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 // Copyright 2008, Google Inc. 1 // Copyright 2008, Google Inc.
2 // 2 //
3 // Redistribution and use in source and binary forms, with or without 3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met: 4 // modification, are permitted provided that the following conditions are met:
5 // 5 //
6 // 1. Redistributions of source code must retain the above copyright notice, 6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer. 7 // this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice, 8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 // this list of conditions and the following disclaimer in the documentation 9 // this list of conditions and the following disclaimer in the documentation
10 // and/or other materials provided with the distribution. 10 // and/or other materials provided with the distribution.
11 // 3. Neither the name of Google Inc. nor the names of its contributors may be 11 // 3. Neither the name of Google Inc. nor the names of its contributors may be
12 // used to endorse or promote products derived from this software without 12 // used to endorse or promote products derived from this software without
13 // specific prior written permission. 13 // specific prior written permission.
14 // 14 //
15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 15 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 16 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 17 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 21 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 22 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 25
26 var db_manager = google.gears.factory.create('beta.databasemanager'); 26 var db_manager = google.gears.factory.create('beta.databasemanager');
27 27
28 function testDatabaseManagerCreation() { 28 function testDatabaseManagerCreation() {
29 assertNotNull(db_manager, 'Database manager should be a value'); 29 assertNotNull(db_manager, 'Database manager should be a value');
30 } 30 }
31 31
32 function testDatabaseManagerApiSig() { 32 function testDatabaseManagerApiSig() {
33 var method = 'DatabaseManager.openDatabase()'; 33 var method = 'DatabaseManager.openDatabase()';
34 assert(db_manager.openDatabase, method + ' should be present'); 34 assert(db_manager.openDatabase, method + ' should be present');
35 assertError(function() { 35 assertError(function() {
36 db_manager.openDatabase(); 36 db_manager.openDatabase();
37 }, null, method + ' has required parameters'); 37 }, null, method + ' has required parameters');
38 assertError(function() { 38 assertError(function() {
39 db_manager.openDatabase('unit_test_db'); 39 db_manager.openDatabase('unit_test_db');
40 }, null, method + ' requires a version parameter'); 40 }, null, method + ' requires a version parameter');
41 } 41 }
42 42
43 function testDatabaseOpening() { 43 function testDatabaseOpening() {
44 var db = db_manager.openDatabase('unit_test_db', '', 'ignored_description', 44 var db = db_manager.openDatabase('unit_test_db', '', 'ignored_description',
45 'ignored_estimated_size'); 45 'ignored_estimated_size');
46 assert(db, 'Database should be a value'); 46 assert(db, 'Database should be a value');
47 } 47 }
48 48
49 function testDatabaseOptionalParams() { 49 function testDatabaseOptionalParams() {
50 var db = db_manager.openDatabase('unit_test_db', ''); 50 var db = db_manager.openDatabase('unit_test_db', '');
(...skipping 71 matching lines...) Show 10 above Show 10 below
122 } 122 }
123 123
124 // test statement execution 124 // test statement execution
125 db.synchronousTransaction(function(tx) { 125 db.synchronousTransaction(function(tx) {
126 var method = 'Database2Transaction.executeSql()'; 126 var method = 'Database2Transaction.executeSql()';
127 var rs = tx.executeSql('SELECT * FROM Pages;'); 127 var rs = tx.executeSql('SELECT * FROM Pages;');
128 assert(rs, method + ' should return a result set'); 128 assert(rs, method + ' should return a result set');
129 }); 129 });
130 }); 130 });
131 } 131 }
132 132
133 function testStatementArguments() { 133 function testStatementArguments() {
134 withDb(function(db) { 134 withDb(function(db) {
135 db.synchronousTransaction(function(tx) { 135 db.synchronousTransaction(function(tx) {
136 // valid arguments 136 // valid arguments
137 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?', 137 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?',
138 [ 1972, '1.0.0.0' ]); 138 [ 1972, '1.0.0.0' ]);
139 // arguments with null 139 // arguments with null
140 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?', 140 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?',
141 [ 1972, null ]); 141 [ 1972, null ]);
142 // null arguments 142 // null arguments
143 tx.executeSql('SELECT * FROM Pages', null); 143 tx.executeSql('SELECT * FROM Pages', null);
144 // invalid arguments: function 144 // invalid arguments: function
145 assertError(function() { 145 assertError(function() {
146 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?', 146 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?',
147 [ function() {}, '1.0.0.0' ]); 147 [ function() {}, '1.0.0.0' ]);
148 }, null, 'Function arguments are not allowed'); 148 }, null, 'Function arguments are not allowed');
149 // invalid arguments: object 149 // invalid arguments: object
150 assertError(function() { 150 assertError(function() {
151 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?', 151 tx.executeSql('SELECT * FROM Pages WHERE pageId = ? and version = ?',
152 [ { you: 'is wrong' }, '1.0.0.0' ]); 152 [ { you: 'is wrong' }, '1.0.0.0' ]);
153 }, null, 'Function arguments are not allowed'); 153 }, null, 'Function arguments are not allowed');
154 }); 154 });
155 }); 155 });
156 } 156 }
157 157
158 function testSQLTransactionApiSig() { 158 function testSQLTransactionApiSig() {
159 withDb(function(db) { 159 withDb(function(db) {
160 var method = 'SQLTransaction.executeSql'; 160 var method = 'SQLTransaction.executeSql';
161 db.transaction(function(tx) { 161 db.transaction(function(tx) {
162 assert(tx.executeSQL, method + ' should be present'); 162 assert(tx.executeSQL, method + ' should be present');
163 }); 163 });
164 }); 164 });
165 } 165 }
166 166
167 function withDb(fn, version) { 167 function withDb(fn, version) {
168 db_manager && fn && fn.call( 168 db_manager && fn && fn.call(
169 this, db_manager.openDatabase('unit_test_db', version || '')); 169 this, db_manager.openDatabase('unit_test_db', version || ''));
170 } 170 }
171 171
LEFTRIGHT

Powered by Google App Engine
This is Rietveld r294