1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/storage/test/unit/test_cache_size.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// This file tests that dbs of various page sizes are using the right cache 1.8 +// size (bug 703113). 1.9 + 1.10 +/** 1.11 + * In order to change the cache size, we must open a DB, change the page 1.12 + * size, create a table, close the DB, then re-open the DB. We then check 1.13 + * the cache size after reopening. 1.14 + * 1.15 + * @param dbOpener 1.16 + * function that opens the DB specified in file 1.17 + * @param file 1.18 + * file holding the database 1.19 + * @param pageSize 1.20 + * the DB's page size 1.21 + * @param expectedCacheSize 1.22 + * the expected cache size for the given page size 1.23 + */ 1.24 +function check_size(dbOpener, file, pageSize, expectedCacheSize) 1.25 +{ 1.26 + // Open the DB, immediately change its page size. 1.27 + let db = dbOpener(file); 1.28 + db.executeSimpleSQL("PRAGMA page_size = " + pageSize); 1.29 + 1.30 + // Check the page size change worked. 1.31 + let stmt = db.createStatement("PRAGMA page_size"); 1.32 + do_check_true(stmt.executeStep()); 1.33 + do_check_eq(stmt.row.page_size, pageSize); 1.34 + stmt.finalize(); 1.35 + 1.36 + // Create a simple table. 1.37 + db.executeSimpleSQL("CREATE TABLE test ( id INTEGER PRIMARY KEY )"); 1.38 + 1.39 + // Close and re-open the DB. 1.40 + db.close(); 1.41 + db = dbOpener(file); 1.42 + 1.43 + // Check cache size is as expected. 1.44 + let stmt = db.createStatement("PRAGMA cache_size"); 1.45 + do_check_true(stmt.executeStep()); 1.46 + do_check_eq(stmt.row.cache_size, expectedCacheSize); 1.47 + stmt.finalize(); 1.48 +} 1.49 + 1.50 +function new_file(name) 1.51 +{ 1.52 + let file = dirSvc.get("ProfD", Ci.nsIFile); 1.53 + file.append(name + ".sqlite"); 1.54 + do_check_false(file.exists()); 1.55 + return file; 1.56 +} 1.57 + 1.58 +function run_test() 1.59 +{ 1.60 + const kExpectedCacheSize = -2048; // 2MiB 1.61 + 1.62 + let pageSizes = [ 1.63 + 1024, 1.64 + 4096, 1.65 + 32768, 1.66 + ]; 1.67 + 1.68 + for (let i = 0; i < pageSizes.length; i++) { 1.69 + let pageSize = pageSizes[i]; 1.70 + check_size(getDatabase, 1.71 + new_file("shared" + pageSize), pageSize, kExpectedCacheSize); 1.72 + check_size(getService().openUnsharedDatabase, 1.73 + new_file("unshared" + pageSize), pageSize, kExpectedCacheSize); 1.74 + } 1.75 +}