michael@0: /*-*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: *vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /** michael@0: * This file tests to make sure that SQLite was compiled with michael@0: * SQLITE_SECURE_DELETE=1. michael@0: */ michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Helper Methods michael@0: michael@0: /** michael@0: * Reads the contents of a file and returns it as a string. michael@0: * michael@0: * @param aFile michael@0: * The file to return from. michael@0: * @return the contents of the file in the form of a string. michael@0: */ michael@0: function getFileContents(aFile) michael@0: { michael@0: let fstream = Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(Ci.nsIFileInputStream); michael@0: fstream.init(aFile, -1, 0, 0); michael@0: michael@0: let bstream = Cc["@mozilla.org/binaryinputstream;1"]. michael@0: createInstance(Ci.nsIBinaryInputStream); michael@0: bstream.setInputStream(fstream); michael@0: return bstream.readBytes(bstream.available()); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Tests michael@0: michael@0: function test_delete_removes_data() michael@0: { michael@0: const TEST_STRING = "SomeRandomStringToFind"; michael@0: michael@0: let file = getTestDB(); michael@0: let db = getService().openDatabase(file); michael@0: michael@0: // Create the table and insert the data. michael@0: db.createTable("test", "data TEXT"); michael@0: let stmt = db.createStatement("INSERT INTO test VALUES(:data)"); michael@0: stmt.params.data = TEST_STRING; michael@0: try { michael@0: stmt.execute(); michael@0: } michael@0: finally { michael@0: stmt.finalize(); michael@0: } michael@0: michael@0: // Make sure this test is actually testing what it thinks by making sure the michael@0: // string shows up in the database. Because the previous statement was michael@0: // automatically wrapped in a transaction, the contents are already on disk. michael@0: let contents = getFileContents(file); michael@0: do_check_neq(-1, contents.indexOf(TEST_STRING)); michael@0: michael@0: // Delete the data, and then close the database. michael@0: stmt = db.createStatement("DELETE FROM test WHERE data = :data"); michael@0: stmt.params.data = TEST_STRING; michael@0: try { michael@0: stmt.execute(); michael@0: } michael@0: finally { michael@0: stmt.finalize(); michael@0: } michael@0: db.close(); michael@0: michael@0: // Check the file to see if the string can be found. michael@0: contents = getFileContents(file); michael@0: do_check_eq(-1, contents.indexOf(TEST_STRING)); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: //////////////////////////////////////////////////////////////////////////////// michael@0: //// Test Runner michael@0: michael@0: [ michael@0: test_delete_removes_data, michael@0: ].forEach(add_test); michael@0: michael@0: function run_test() michael@0: { michael@0: cleanup(); michael@0: run_next_test(); michael@0: }