Commit cfb82161 authored by shess@chromium.org's avatar shess@chromium.org

[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
parent 8da69f52
......@@ -39,6 +39,7 @@ _ISOLATE_FILE_PATHS = {
'media_perftests': 'media/media_perftests.isolate',
'media_unittests': 'media/media_unittests.isolate',
'net_unittests': 'net/net_unittests.isolate',
'sql_unittests': 'sql/sql_unittests.isolate',
'ui_unittests': 'ui/ui_unittests.isolate',
'unit_tests': 'chrome/unit_tests.isolate',
'webkit_unit_tests':
......
......@@ -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",
]
......
......@@ -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
......@@ -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',
],
},
],
}],
],
}
# 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',
],
}
// 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
// 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_
// 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)));
}
// 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
// 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_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment