| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "sql/connection.h" | 10 #include "sql/connection.h" |
| 11 #include "sql/correct_sql_test_base.h" |
| 11 #include "sql/statement.h" | 12 #include "sql/statement.h" |
| 12 #include "sql/test/error_callback_support.h" | 13 #include "sql/test/error_callback_support.h" |
| 13 #include "sql/test/scoped_error_ignorer.h" | 14 #include "sql/test/scoped_error_ignorer.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/sqlite/sqlite3.h" | 16 #include "third_party/sqlite/sqlite3.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 class SQLStatementTest : public testing::Test { | 20 using SQLStatementTest = sql::SQLTestBase; |
| 20 public: | |
| 21 void SetUp() override { | |
| 22 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 23 ASSERT_TRUE(db_.Open(temp_dir_.path().AppendASCII("SQLStatementTest.db"))); | |
| 24 } | |
| 25 | |
| 26 void TearDown() override { db_.Close(); } | |
| 27 | |
| 28 sql::Connection& db() { return db_; } | |
| 29 | |
| 30 private: | |
| 31 base::ScopedTempDir temp_dir_; | |
| 32 sql::Connection db_; | |
| 33 }; | |
| 34 | 21 |
| 35 } // namespace | 22 } // namespace |
| 36 | 23 |
| 37 TEST_F(SQLStatementTest, Assign) { | 24 TEST_F(SQLStatementTest, Assign) { |
| 38 sql::Statement s; | 25 sql::Statement s; |
| 39 EXPECT_FALSE(s.is_valid()); | 26 EXPECT_FALSE(s.is_valid()); |
| 40 | 27 |
| 41 s.Assign(db().GetUniqueStatement("CREATE TABLE foo (a, b)")); | 28 s.Assign(db().GetUniqueStatement("CREATE TABLE foo (a, b)")); |
| 42 EXPECT_TRUE(s.is_valid()); | 29 EXPECT_TRUE(s.is_valid()); |
| 43 } | 30 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 106 |
| 120 s.Reset(false); | 107 s.Reset(false); |
| 121 // Verify that we can get all rows again. | 108 // Verify that we can get all rows again. |
| 122 ASSERT_TRUE(s.Step()); | 109 ASSERT_TRUE(s.Step()); |
| 123 EXPECT_EQ(12, s.ColumnInt(0)); | 110 EXPECT_EQ(12, s.ColumnInt(0)); |
| 124 EXPECT_FALSE(s.Step()); | 111 EXPECT_FALSE(s.Step()); |
| 125 | 112 |
| 126 s.Reset(true); | 113 s.Reset(true); |
| 127 ASSERT_FALSE(s.Step()); | 114 ASSERT_FALSE(s.Step()); |
| 128 } | 115 } |
| OLD | NEW |