Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1720)

Unified Diff: app/sql/connection_unittest.cc

Issue 7353026: Move app/sql/* files to sql/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « app/sql/connection.cc ('k') | app/sql/diagnostic_error_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: app/sql/connection_unittest.cc
diff --git a/app/sql/connection_unittest.cc b/app/sql/connection_unittest.cc
deleted file mode 100644
index 2c1a5a0360f5de113b10f1f023c61188196ee2e9..0000000000000000000000000000000000000000
--- a/app/sql/connection_unittest.cc
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) 2011 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 "app/sql/connection.h"
-#include "app/sql/statement.h"
-#include "base/file_util.h"
-#include "base/scoped_temp_dir.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/sqlite/sqlite3.h"
-
-class SQLConnectionTest : public testing::Test {
- public:
- SQLConnectionTest() {}
-
- void SetUp() {
- ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
- ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLConnectionTest.db")));
- }
-
- void TearDown() {
- db_.Close();
- }
-
- sql::Connection& db() { return db_; }
-
- private:
- ScopedTempDir temp_dir_;
- sql::Connection db_;
-};
-
-TEST_F(SQLConnectionTest, Execute) {
- // Valid statement should return true.
- ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
- EXPECT_EQ(SQLITE_OK, db().GetErrorCode());
-
- // Invalid statement should fail.
- ASSERT_FALSE(db().Execute("CREATE TAB foo (a, b"));
- EXPECT_EQ(SQLITE_ERROR, db().GetErrorCode());
-}
-
-TEST_F(SQLConnectionTest, CachedStatement) {
- sql::StatementID id1("foo", 12);
-
- ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
- ASSERT_TRUE(db().Execute("INSERT INTO foo(a, b) VALUES (12, 13)"));
-
- // Create a new cached statement.
- {
- sql::Statement s(db().GetCachedStatement(id1, "SELECT a FROM foo"));
- ASSERT_FALSE(!s); // Test ! operator for validity.
-
- ASSERT_TRUE(s.Step());
- EXPECT_EQ(12, s.ColumnInt(0));
- }
-
- // The statement should be cached still.
- EXPECT_TRUE(db().HasCachedStatement(id1));
-
- {
- // Get the same statement using different SQL. This should ignore our
- // SQL and use the cached one (so it will be valid).
- sql::Statement s(db().GetCachedStatement(id1, "something invalid("));
- ASSERT_FALSE(!s); // Test ! operator for validity.
-
- ASSERT_TRUE(s.Step());
- EXPECT_EQ(12, s.ColumnInt(0));
- }
-
- // Make sure other statements aren't marked as cached.
- EXPECT_FALSE(db().HasCachedStatement(SQL_FROM_HERE));
-}
-
-TEST_F(SQLConnectionTest, DoesStuffExist) {
- // Test DoesTableExist.
- EXPECT_FALSE(db().DoesTableExist("foo"));
- ASSERT_TRUE(db().Execute("CREATE TABLE foo (a, b)"));
- EXPECT_TRUE(db().DoesTableExist("foo"));
-
- // Should be case sensitive.
- EXPECT_FALSE(db().DoesTableExist("FOO"));
-
- // Test DoesColumnExist.
- EXPECT_FALSE(db().DoesColumnExist("foo", "bar"));
- EXPECT_TRUE(db().DoesColumnExist("foo", "a"));
-
- // Testing for a column on a nonexistent table.
- EXPECT_FALSE(db().DoesColumnExist("bar", "b"));
-}
-
-TEST_F(SQLConnectionTest, GetLastInsertRowId) {
- ASSERT_TRUE(db().Execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"));
-
- ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)"));
-
- // Last insert row ID should be valid.
- int64 row = db().GetLastInsertRowId();
- EXPECT_LT(0, row);
-
- // It should be the primary key of the row we just inserted.
- sql::Statement s(db().GetUniqueStatement("SELECT value FROM foo WHERE id=?"));
- s.BindInt64(0, row);
- ASSERT_TRUE(s.Step());
- EXPECT_EQ(12, s.ColumnInt(0));
-}
-
« no previous file with comments | « app/sql/connection.cc ('k') | app/sql/diagnostic_error_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698