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

Side by Side Diff: sql/connection_unittest.cc

Issue 10829062: Upstream sqlite gyp changes for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update test Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | third_party/sqlite/sqlite.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "sql/connection.h" 7 #include "sql/connection.h"
8 #include "sql/statement.h" 8 #include "sql/statement.h"
9 #include "sql/meta_table.h" 9 #include "sql/meta_table.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 EXPECT_TRUE(db().BeginTransaction()); 135 EXPECT_TRUE(db().BeginTransaction());
136 } 136 }
137 137
138 // Test that sql::Connection::Raze() results in a database without the 138 // Test that sql::Connection::Raze() results in a database without the
139 // tables from the original database. 139 // tables from the original database.
140 TEST_F(SQLConnectionTest, Raze) { 140 TEST_F(SQLConnectionTest, Raze) {
141 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; 141 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
142 ASSERT_TRUE(db().Execute(kCreateSql)); 142 ASSERT_TRUE(db().Execute(kCreateSql));
143 ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)")); 143 ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)"));
144 144
145 int page_count_before_raze = 0;
145 { 146 {
146 sql::Statement s(db().GetUniqueStatement("PRAGMA page_count")); 147 sql::Statement s(db().GetUniqueStatement("PRAGMA page_count"));
147 ASSERT_TRUE(s.Step()); 148 ASSERT_TRUE(s.Step());
148 EXPECT_EQ(2, s.ColumnInt(0)); 149 page_count_before_raze = s.ColumnInt(0);
149 } 150 }
151 ASSERT_GT(page_count_before_raze, 0);
150 152
151 { 153 {
152 sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master")); 154 sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master"));
153 ASSERT_TRUE(s.Step()); 155 ASSERT_TRUE(s.Step());
154 EXPECT_EQ("table", s.ColumnString(0)); 156 EXPECT_EQ("table", s.ColumnString(0));
155 EXPECT_EQ("foo", s.ColumnString(1)); 157 EXPECT_EQ("foo", s.ColumnString(1));
156 EXPECT_EQ("foo", s.ColumnString(2)); 158 EXPECT_EQ("foo", s.ColumnString(2));
157 EXPECT_EQ(2, s.ColumnInt(3)); 159 EXPECT_EQ(page_count_before_raze, s.ColumnInt(3));
Scott Hess - ex-Googler 2012/07/27 22:23:29 Hmm. Maybe toss in a comment to the end of "Table
158 EXPECT_EQ(kCreateSql, s.ColumnString(4)); 160 EXPECT_EQ(kCreateSql, s.ColumnString(4));
159 } 161 }
160 162
161 ASSERT_TRUE(db().Raze()); 163 ASSERT_TRUE(db().Raze());
162 164
163 { 165 {
164 sql::Statement s(db().GetUniqueStatement("PRAGMA page_count")); 166 sql::Statement s(db().GetUniqueStatement("PRAGMA page_count"));
165 ASSERT_TRUE(s.Step()); 167 ASSERT_TRUE(s.Step());
166 EXPECT_EQ(1, s.ColumnInt(0)); 168 EXPECT_LT(s.ColumnInt(0), page_count_before_raze);
Scott Hess - ex-Googler 2012/07/27 22:23:29 And then here, add a comment that the last page of
167 } 169 }
168 170
169 { 171 {
170 sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master")); 172 sql::Statement s(db().GetUniqueStatement("SELECT * FROM sqlite_master"));
171 ASSERT_FALSE(s.Step()); 173 ASSERT_FALSE(s.Step());
172 } 174 }
173 } 175 }
174 176
175 // Test that Raze() maintains page_size. 177 // Test that Raze() maintains page_size.
176 TEST_F(SQLConnectionTest, RazePageSize) { 178 TEST_F(SQLConnectionTest, RazePageSize) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 // Otherwise, sqlite3 doesn't find the correct directory to store 271 // Otherwise, sqlite3 doesn't find the correct directory to store
270 // temporary files and will report the error 'unable to open 272 // temporary files and will report the error 'unable to open
271 // database file'. 273 // database file'.
272 ASSERT_TRUE(meta_table.Init(&db(), 4, 4)); 274 ASSERT_TRUE(meta_table.Init(&db(), 4, 4));
273 } 275 }
274 #endif 276 #endif
275 277
276 // TODO(shess): Spin up a background thread to hold other_db, to more 278 // TODO(shess): Spin up a background thread to hold other_db, to more
277 // closely match real life. That would also allow testing 279 // closely match real life. That would also allow testing
278 // RazeWithTimeout(). 280 // RazeWithTimeout().
OLDNEW
« no previous file with comments | « no previous file | third_party/sqlite/sqlite.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698