summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-10 00:48:06 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-10 00:48:06 +0000
commitcfb82161a738147a3c2621ee8e6d0083bbe54c22 (patch)
treebe2702b2e653bcdc832a6db3803f64295d9698e8 /sql
parent8da69f52a6eedded81e2c44e5c64cfab215516ce (diff)
downloadchromium_src-cfb82161a738147a3c2621ee8e6d0083bbe54c22.zip
chromium_src-cfb82161a738147a3c2621ee8e6d0083bbe54c22.tar.gz
chromium_src-cfb82161a738147a3c2621ee8e6d0083bbe54c22.tar.bz2
[sql] Test recovery of corrupt golden file.
Manually modify a SQLite database to have the problem described by the bug, then test that it can be recovered. Also, infrastructure to introduce testing data to sql/ tests. BUG=387868 Review URL: https://codereview.chromium.org/355093003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r--sql/BUILD.gn7
-rw-r--r--sql/recovery_unittest.cc32
-rw-r--r--sql/sql.gyp24
-rw-r--r--sql/sql_unittests.isolate17
-rw-r--r--sql/test/paths.cc48
-rw-r--r--sql/test/paths.h25
-rw-r--r--sql/test/run_all_unittests.cc16
-rw-r--r--sql/test/sql_test_suite.cc25
-rw-r--r--sql/test/sql_test_suite.h29
9 files changed, 221 insertions, 2 deletions
diff --git a/sql/BUILD.gn b/sql/BUILD.gn
index d672841..2029dc3 100644
--- a/sql/BUILD.gn
+++ b/sql/BUILD.gn
@@ -56,6 +56,11 @@ test("sql_unittests") {
"recovery_unittest.cc",
"sqlite_features_unittest.cc",
"statement_unittest.cc",
+ "test/paths.cc",
+ "test/paths.h",
+ "test/run_all_unittests.cc",
+ "test/sql_test_suite.cc",
+ "test/sql_test_suite.h",
"transaction_unittest.cc",
]
@@ -67,7 +72,7 @@ test("sql_unittests") {
":sql",
":test_support",
"//base/allocator",
- "//base/test:run_all_unittests",
+ "//base/test:test_support",
"//testing/gtest",
"//third_party/sqlite",
]
diff --git a/sql/recovery_unittest.cc b/sql/recovery_unittest.cc
index ce3884b..201966d 100644
--- a/sql/recovery_unittest.cc
+++ b/sql/recovery_unittest.cc
@@ -5,13 +5,16 @@
#include <string>
#include "base/bind.h"
+#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
+#include "base/path_service.h"
#include "base/strings/string_number_conversions.h"
#include "sql/connection.h"
#include "sql/meta_table.h"
#include "sql/recovery.h"
#include "sql/statement.h"
+#include "sql/test/paths.h"
#include "sql/test/scoped_error_ignorer.h"
#include "sql/test/test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -683,6 +686,35 @@ TEST_F(SQLRecoveryTest, AutoRecoverTableExtendColumns) {
ASSERT_EQ(orig_schema, GetSchema(&db()));
ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
}
+
+// Recover a golden file where an interior page has been manually modified so
+// that the number of cells is greater than will fit on a single page. This
+// case happened in <http://crbug.com/387868>.
+TEST_F(SQLRecoveryTest, Bug387868) {
+ base::FilePath golden_path;
+ ASSERT_TRUE(PathService::Get(sql::test::DIR_TEST_DATA, &golden_path));
+ golden_path = golden_path.AppendASCII("recovery_387868");
+ db().Close();
+ ASSERT_TRUE(base::CopyFile(golden_path, db_path()));
+ ASSERT_TRUE(Reopen());
+
+ {
+ scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
+ ASSERT_TRUE(recovery.get());
+
+ // Create the new version of the table.
+ const char kCreateSql[] =
+ "CREATE TABLE x (id INTEGER PRIMARY KEY, t0 TEXT)";
+ ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
+
+ size_t rows = 0;
+ EXPECT_TRUE(recovery->AutoRecoverTable("x", 0, &rows));
+ EXPECT_EQ(43u, rows);
+
+ // Successfully recovered.
+ EXPECT_TRUE(sql::Recovery::Recovered(recovery.Pass()));
+ }
+}
#endif // !defined(USE_SYSTEM_SQLITE)
} // namespace
diff --git a/sql/sql.gyp b/sql/sql.gyp
index 37c6ae7..975cd12 100644
--- a/sql/sql.gyp
+++ b/sql/sql.gyp
@@ -80,7 +80,6 @@
'dependencies': [
'sql',
'test_support_sql',
- '../base/base.gyp:run_all_unittests',
'../base/base.gyp:test_support_base',
'../testing/gtest.gyp:gtest',
'../third_party/sqlite/sqlite.gyp:sqlite',
@@ -91,6 +90,11 @@
'recovery_unittest.cc',
'sqlite_features_unittest.cc',
'statement_unittest.cc',
+ 'test/paths.cc',
+ 'test/paths.h',
+ 'test/run_all_unittests.cc',
+ 'test/sql_test_suite.cc',
+ 'test/sql_test_suite.h',
'transaction_unittest.cc',
],
'include_dirs': [
@@ -132,5 +136,23 @@
},
],
}],
+ ['test_isolation_mode != "noop"', {
+ 'targets': [
+ {
+ 'target_name': 'sql_unittests_run',
+ 'type': 'none',
+ 'dependencies': [
+ 'sql_unittests',
+ ],
+ 'includes': [
+ '../build/isolate.gypi',
+ 'sql_unittests.isolate',
+ ],
+ 'sources': [
+ 'sql_unittests.isolate',
+ ],
+ },
+ ],
+ }],
],
}
diff --git a/sql/sql_unittests.isolate b/sql/sql_unittests.isolate
new file mode 100644
index 0000000..75e776d
--- /dev/null
+++ b/sql/sql_unittests.isolate
@@ -0,0 +1,17 @@
+# Copyright 2014 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+{
+ 'conditions': [
+ ['OS=="android" or OS=="linux" or OS=="mac" or OS=="win"', {
+ 'variables': {
+ 'isolate_dependency_untracked': [
+ 'test/data/',
+ ],
+ },
+ }],
+ ],
+ 'includes': [
+ '../base/base.isolate',
+ ],
+}
diff --git a/sql/test/paths.cc b/sql/test/paths.cc
new file mode 100644
index 0000000..df579341
--- /dev/null
+++ b/sql/test/paths.cc
@@ -0,0 +1,48 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sql/test/paths.h"
+
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/path_service.h"
+
+namespace sql {
+namespace test {
+
+namespace {
+
+bool PathProvider(int key, base::FilePath* result) {
+ base::FilePath cur;
+ switch (key) {
+ // The following are only valid in the development environment, and
+ // will fail if executed from an installed executable (because the
+ // generated path won't exist).
+ case DIR_TEST_DATA:
+ if (!PathService::Get(base::DIR_SOURCE_ROOT, &cur))
+ return false;
+ cur = cur.Append(FILE_PATH_LITERAL("sql"));
+ cur = cur.Append(FILE_PATH_LITERAL("test"));
+ cur = cur.Append(FILE_PATH_LITERAL("data"));
+ if (!base::PathExists(cur)) // we don't want to create this
+ return false;
+ break;
+ default:
+ return false;
+ }
+
+ *result = cur;
+ return true;
+}
+
+} // namespace
+
+// This cannot be done as a static initializer sadly since Visual Studio will
+// eliminate this object file if there is no direct entry point into it.
+void RegisterPathProvider() {
+ PathService::RegisterProvider(PathProvider, PATH_START, PATH_END);
+}
+
+} // namespace test
+} // namespace sql
diff --git a/sql/test/paths.h b/sql/test/paths.h
new file mode 100644
index 0000000..d932106c
--- /dev/null
+++ b/sql/test/paths.h
@@ -0,0 +1,25 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SQL_TEST_PATHS_H_
+#define SQL_TEST_PATHS_H_
+
+namespace sql {
+namespace test {
+
+enum {
+ PATH_START = 10000,
+
+ // Valid only in testing environments.
+ DIR_TEST_DATA,
+ PATH_END
+};
+
+// Call once to register the provider for the path keys defined above.
+void RegisterPathProvider();
+
+} // namespace test
+} // namespace sql
+
+#endif // SQL_TEST_PATHS_H_
diff --git a/sql/test/run_all_unittests.cc b/sql/test/run_all_unittests.cc
new file mode 100644
index 0000000..85ceac0
--- /dev/null
+++ b/sql/test/run_all_unittests.cc
@@ -0,0 +1,16 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/test/launcher/unit_test_launcher.h"
+#include "sql/test/sql_test_suite.h"
+
+int main(int argc, char** argv) {
+ sql::SQLTestSuite test_suite(argc, argv);
+
+ return base::LaunchUnitTests(
+ argc,
+ argv,
+ base::Bind(&sql::SQLTestSuite::Run, base::Unretained(&test_suite)));
+}
diff --git a/sql/test/sql_test_suite.cc b/sql/test/sql_test_suite.cc
new file mode 100644
index 0000000..bfda3a0
--- /dev/null
+++ b/sql/test/sql_test_suite.cc
@@ -0,0 +1,25 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sql/test/sql_test_suite.h"
+
+#include "sql/test/paths.h"
+
+namespace sql {
+
+SQLTestSuite::SQLTestSuite(int argc, char** argv)
+ : base::TestSuite(argc, argv) {}
+
+SQLTestSuite::~SQLTestSuite() {}
+
+void SQLTestSuite::Initialize() {
+ base::TestSuite::Initialize();
+ sql::test::RegisterPathProvider();
+}
+
+void SQLTestSuite::Shutdown() {
+ base::TestSuite::Shutdown();
+}
+
+} // namespace sql
diff --git a/sql/test/sql_test_suite.h b/sql/test/sql_test_suite.h
new file mode 100644
index 0000000..3c15373
--- /dev/null
+++ b/sql/test/sql_test_suite.h
@@ -0,0 +1,29 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SQL_TEST_SQL_TEST_SUITE_H_
+#define SQL_TEST_SQL_TEST_SUITE_H_
+
+#include "base/macros.h"
+#include "base/test/test_suite.h"
+
+namespace sql {
+
+class SQLTestSuite : public base::TestSuite {
+ public:
+ SQLTestSuite(int argc, char** argv);
+ virtual ~SQLTestSuite();
+
+ protected:
+ // Overridden from base::TestSuite:
+ virtual void Initialize() OVERRIDE;
+ virtual void Shutdown() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SQLTestSuite);
+};
+
+} // namespace sql
+
+#endif // SQL_TEST_SQL_TEST_SUITE_H_