summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorshess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 23:44:50 +0000
committershess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 23:44:50 +0000
commit43ffdd8281b45450b010d8d3f44c6e7c4a55c216 (patch)
treea07179891a2c81c7fc7a69c984efacb1665a38e9 /sql
parent3b3a16b5915710431a8bad1d53dbf4867d8d1393 (diff)
downloadchromium_src-43ffdd8281b45450b010d8d3f44c6e7c4a55c216.zip
chromium_src-43ffdd8281b45450b010d8d3f44c6e7c4a55c216.tar.gz
chromium_src-43ffdd8281b45450b010d8d3f44c6e7c4a55c216.tar.bz2
Rewrite Thumbnail and Top Sites test with golden files.
Previously, the tests manually changes the current schema to look like an old schema, then targetted specific implementation functions. Change to instead create the schema from a golden file, testing that Init() works correctly, and the expected data is in place. BUG=none R=pkotwicz@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/23536014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r--sql/sql.gyp2
-rw-r--r--sql/test/test_helpers.cc75
-rw-r--r--sql/test/test_helpers.h45
3 files changed, 122 insertions, 0 deletions
diff --git a/sql/sql.gyp b/sql/sql.gyp
index 861a1dd..7add51c 100644
--- a/sql/sql.gyp
+++ b/sql/sql.gyp
@@ -62,6 +62,8 @@
'test/error_callback_support.h',
'test/scoped_error_ignorer.cc',
'test/scoped_error_ignorer.h',
+ 'test/test_helpers.cc',
+ 'test/test_helpers.h',
],
'include_dirs': [
'..',
diff --git a/sql/test/test_helpers.cc b/sql/test/test_helpers.cc
new file mode 100644
index 0000000..607f146
--- /dev/null
+++ b/sql/test/test_helpers.cc
@@ -0,0 +1,75 @@
+// Copyright 2013 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/test_helpers.h"
+
+#include <string>
+
+#include "base/file_util.h"
+#include "sql/connection.h"
+#include "sql/statement.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+size_t CountSQLItemsOfType(sql::Connection* db, const char* type) {
+ const char kTypeSQL[] = "SELECT COUNT(*) FROM sqlite_master WHERE type = ?";
+ sql::Statement s(db->GetUniqueStatement(kTypeSQL));
+ s.BindCString(0, type);
+ EXPECT_TRUE(s.Step());
+ return s.ColumnInt(0);
+}
+
+} // namespace
+
+namespace sql {
+namespace test {
+
+size_t CountSQLTables(sql::Connection* db) {
+ return CountSQLItemsOfType(db, "table");
+}
+
+size_t CountSQLIndices(sql::Connection* db) {
+ return CountSQLItemsOfType(db, "index");
+}
+
+size_t CountTableColumns(sql::Connection* db, const char* table) {
+ // TODO(shess): sql::Connection::QuoteForSQL() would make sense.
+ std::string quoted_table;
+ {
+ const char kQuoteSQL[] = "SELECT quote(?)";
+ sql::Statement s(db->GetUniqueStatement(kQuoteSQL));
+ s.BindCString(0, table);
+ EXPECT_TRUE(s.Step());
+ quoted_table = s.ColumnString(0);
+ }
+
+ std::string sql = "PRAGMA table_info(" + quoted_table + ")";
+ sql::Statement s(db->GetUniqueStatement(sql.c_str()));
+ size_t rows = 0;
+ while (s.Step()) {
+ ++rows;
+ }
+ EXPECT_TRUE(s.Succeeded());
+ return rows;
+}
+
+bool CreateDatabaseFromSQL(const base::FilePath& db_path,
+ const base::FilePath& sql_path) {
+ if (base::PathExists(db_path) || !base::PathExists(sql_path))
+ return false;
+
+ std::string sql;
+ if (!base::ReadFileToString(sql_path, &sql))
+ return false;
+
+ sql::Connection db;
+ if (!db.Open(db_path))
+ return false;
+
+ return db.Execute(sql.c_str());
+}
+
+} // namespace test
+} // namespace sql
diff --git a/sql/test/test_helpers.h b/sql/test/test_helpers.h
new file mode 100644
index 0000000..2e01ecd
--- /dev/null
+++ b/sql/test/test_helpers.h
@@ -0,0 +1,45 @@
+// Copyright 2013 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_TEST_HELPERS_H_
+#define SQL_TEST_TEST_HELPERS_H_
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+
+// Collection of test-only convenience functions.
+
+namespace base {
+class FilePath;
+}
+
+namespace sql {
+class Connection;
+}
+
+namespace sql {
+namespace test {
+
+// Return the number of tables in sqlite_master.
+size_t CountSQLTables(sql::Connection* db) WARN_UNUSED_RESULT;
+
+// Return the number of indices in sqlite_master.
+size_t CountSQLIndices(sql::Connection* db) WARN_UNUSED_RESULT;
+
+// Returns the number of columns in the named table. 0 indicates an
+// error (probably no such table).
+size_t CountTableColumns(sql::Connection* db, const char* table)
+ WARN_UNUSED_RESULT;
+
+// Creates a SQLite database at |db_path| from the sqlite .dump output
+// at |sql_path|. Returns false if |db_path| already exists, or if
+// sql_path does not exist or cannot be read, or if there is an error
+// executing the statements.
+bool CreateDatabaseFromSQL(const base::FilePath& db_path,
+ const base::FilePath& sql_path) WARN_UNUSED_RESULT;
+
+} // namespace test
+} // namespace sql
+
+#endif // SQL_TEST_TEST_HELPERS_H_