1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/test/unit/test_storage_value_array.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,210 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// This file tests the functions of mozIStorageValueArray 1.9 + 1.10 +function setup() 1.11 +{ 1.12 + getOpenedDatabase().createTable("test", "id INTEGER PRIMARY KEY, name TEXT," + 1.13 + "number REAL, nuller NULL, blobber BLOB"); 1.14 + 1.15 + var stmt = createStatement("INSERT INTO test (name, number, blobber) " + 1.16 + "VALUES (?1, ?2, ?3)"); 1.17 + stmt.bindByIndex(0, "foo"); 1.18 + stmt.bindByIndex(1, 2.34); 1.19 + stmt.bindBlobByIndex(2, [], 0); 1.20 + stmt.execute(); 1.21 + 1.22 + stmt.bindByIndex(0, ""); 1.23 + stmt.bindByIndex(1, 1.23); 1.24 + stmt.bindBlobByIndex(2, [1, 2], 2); 1.25 + stmt.execute(); 1.26 + 1.27 + stmt.reset(); 1.28 + stmt.finalize(); 1.29 +} 1.30 + 1.31 +function test_getIsNull_for_null() 1.32 +{ 1.33 + var stmt = createStatement("SELECT nuller, blobber FROM test WHERE id = ?1"); 1.34 + stmt.bindByIndex(0, 1); 1.35 + do_check_true(stmt.executeStep()); 1.36 + 1.37 + do_check_true(stmt.getIsNull(0)); // null field 1.38 + do_check_true(stmt.getIsNull(1)); // data is null if size is 0 1.39 + stmt.reset(); 1.40 + stmt.finalize(); 1.41 +} 1.42 + 1.43 +function test_getIsNull_for_non_null() 1.44 +{ 1.45 + var stmt = createStatement("SELECT name, blobber FROM test WHERE id = ?1"); 1.46 + stmt.bindByIndex(0, 2); 1.47 + do_check_true(stmt.executeStep()); 1.48 + 1.49 + do_check_false(stmt.getIsNull(0)); 1.50 + do_check_false(stmt.getIsNull(1)); 1.51 + stmt.reset(); 1.52 + stmt.finalize(); 1.53 +} 1.54 + 1.55 +function test_value_type_null() 1.56 +{ 1.57 + var stmt = createStatement("SELECT nuller FROM test WHERE id = ?1"); 1.58 + stmt.bindByIndex(0, 1); 1.59 + do_check_true(stmt.executeStep()); 1.60 + 1.61 + do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_NULL, 1.62 + stmt.getTypeOfIndex(0)); 1.63 + stmt.reset(); 1.64 + stmt.finalize(); 1.65 +} 1.66 + 1.67 +function test_value_type_integer() 1.68 +{ 1.69 + var stmt = createStatement("SELECT id FROM test WHERE id = ?1"); 1.70 + stmt.bindByIndex(0, 1); 1.71 + do_check_true(stmt.executeStep()); 1.72 + 1.73 + do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_INTEGER, 1.74 + stmt.getTypeOfIndex(0)); 1.75 + stmt.reset(); 1.76 + stmt.finalize(); 1.77 +} 1.78 + 1.79 +function test_value_type_float() 1.80 +{ 1.81 + var stmt = createStatement("SELECT number FROM test WHERE id = ?1"); 1.82 + stmt.bindByIndex(0, 1); 1.83 + do_check_true(stmt.executeStep()); 1.84 + 1.85 + do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_FLOAT, 1.86 + stmt.getTypeOfIndex(0)); 1.87 + stmt.reset(); 1.88 + stmt.finalize(); 1.89 +} 1.90 + 1.91 +function test_value_type_text() 1.92 +{ 1.93 + var stmt = createStatement("SELECT name FROM test WHERE id = ?1"); 1.94 + stmt.bindByIndex(0, 1); 1.95 + do_check_true(stmt.executeStep()); 1.96 + 1.97 + do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_TEXT, 1.98 + stmt.getTypeOfIndex(0)); 1.99 + stmt.reset(); 1.100 + stmt.finalize(); 1.101 +} 1.102 + 1.103 +function test_value_type_blob() 1.104 +{ 1.105 + var stmt = createStatement("SELECT blobber FROM test WHERE id = ?1"); 1.106 + stmt.bindByIndex(0, 2); 1.107 + do_check_true(stmt.executeStep()); 1.108 + 1.109 + do_check_eq(Ci.mozIStorageValueArray.VALUE_TYPE_BLOB, 1.110 + stmt.getTypeOfIndex(0)); 1.111 + stmt.reset(); 1.112 + stmt.finalize(); 1.113 +} 1.114 + 1.115 +function test_numEntries_one() 1.116 +{ 1.117 + var stmt = createStatement("SELECT blobber FROM test WHERE id = ?1"); 1.118 + stmt.bindByIndex(0, 2); 1.119 + do_check_true(stmt.executeStep()); 1.120 + 1.121 + do_check_eq(1, stmt.numEntries); 1.122 + stmt.reset(); 1.123 + stmt.finalize(); 1.124 +} 1.125 + 1.126 +function test_numEntries_all() 1.127 +{ 1.128 + var stmt = createStatement("SELECT * FROM test WHERE id = ?1"); 1.129 + stmt.bindByIndex(0, 2); 1.130 + do_check_true(stmt.executeStep()); 1.131 + 1.132 + do_check_eq(5, stmt.numEntries); 1.133 + stmt.reset(); 1.134 + stmt.finalize(); 1.135 +} 1.136 + 1.137 +function test_getInt() 1.138 +{ 1.139 + var stmt = createStatement("SELECT id FROM test WHERE id = ?1"); 1.140 + stmt.bindByIndex(0, 2); 1.141 + do_check_true(stmt.executeStep()); 1.142 + 1.143 + do_check_eq(2, stmt.getInt32(0)); 1.144 + do_check_eq(2, stmt.getInt64(0)); 1.145 + stmt.reset(); 1.146 + stmt.finalize(); 1.147 +} 1.148 + 1.149 +function test_getDouble() 1.150 +{ 1.151 + var stmt = createStatement("SELECT number FROM test WHERE id = ?1"); 1.152 + stmt.bindByIndex(0, 2); 1.153 + do_check_true(stmt.executeStep()); 1.154 + 1.155 + do_check_eq(1.23, stmt.getDouble(0)); 1.156 + stmt.reset(); 1.157 + stmt.finalize(); 1.158 +} 1.159 + 1.160 +function test_getUTF8String() 1.161 +{ 1.162 + var stmt = createStatement("SELECT name FROM test WHERE id = ?1"); 1.163 + stmt.bindByIndex(0, 1); 1.164 + do_check_true(stmt.executeStep()); 1.165 + 1.166 + do_check_eq("foo", stmt.getUTF8String(0)); 1.167 + stmt.reset(); 1.168 + stmt.finalize(); 1.169 +} 1.170 + 1.171 +function test_getString() 1.172 +{ 1.173 + var stmt = createStatement("SELECT name FROM test WHERE id = ?1"); 1.174 + stmt.bindByIndex(0, 2); 1.175 + do_check_true(stmt.executeStep()); 1.176 + 1.177 + do_check_eq("", stmt.getString(0)); 1.178 + stmt.reset(); 1.179 + stmt.finalize(); 1.180 +} 1.181 + 1.182 +function test_getBlob() 1.183 +{ 1.184 + var stmt = createStatement("SELECT blobber FROM test WHERE id = ?1"); 1.185 + stmt.bindByIndex(0, 2); 1.186 + do_check_true(stmt.executeStep()); 1.187 + 1.188 + var count = { value: 0 }; 1.189 + var arr = { value: null }; 1.190 + stmt.getBlob(0, count, arr); 1.191 + do_check_eq(2, count.value); 1.192 + do_check_eq(1, arr.value[0]); 1.193 + do_check_eq(2, arr.value[1]); 1.194 + stmt.reset(); 1.195 + stmt.finalize(); 1.196 +} 1.197 + 1.198 +var tests = [test_getIsNull_for_null, test_getIsNull_for_non_null, 1.199 + test_value_type_null, test_value_type_integer, 1.200 + test_value_type_float, test_value_type_text, test_value_type_blob, 1.201 + test_numEntries_one, test_numEntries_all, test_getInt, 1.202 + test_getDouble, test_getUTF8String, test_getString, test_getBlob]; 1.203 + 1.204 +function run_test() 1.205 +{ 1.206 + setup(); 1.207 + 1.208 + for (var i = 0; i < tests.length; i++) 1.209 + tests[i](); 1.210 + 1.211 + cleanup(); 1.212 +} 1.213 +