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 "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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 EXPECT_FALSE(db().DoesTableExist("FOO")); | 103 EXPECT_FALSE(db().DoesTableExist("FOO")); |
104 | 104 |
105 // Test DoesColumnExist. | 105 // Test DoesColumnExist. |
106 EXPECT_FALSE(db().DoesColumnExist("foo", "bar")); | 106 EXPECT_FALSE(db().DoesColumnExist("foo", "bar")); |
107 EXPECT_TRUE(db().DoesColumnExist("foo", "a")); | 107 EXPECT_TRUE(db().DoesColumnExist("foo", "a")); |
108 | 108 |
109 // Testing for a column on a nonexistent table. | 109 // Testing for a column on a nonexistent table. |
110 EXPECT_FALSE(db().DoesColumnExist("bar", "b")); | 110 EXPECT_FALSE(db().DoesColumnExist("bar", "b")); |
111 } | 111 } |
112 | 112 |
113 TEST_F(SQLConnectionTest, GetColumnType) { | |
114 ASSERT_TRUE(db().Execute("CREATE TABLE foo (a bigint, b varchar)")); | |
115 | |
116 const char *table_name = "foo"; | |
117 EXPECT_EQ(db().GetColumnType(table_name, 0), "bigint"); | |
118 EXPECT_EQ(db().GetColumnType(table_name, 1), "varchar"); | |
Scott Hess - ex-Googler
2012/10/02 03:58:47
"bigint" and "varchar" are meaningless to SQLite,
| |
119 } | |
120 | |
113 TEST_F(SQLConnectionTest, GetLastInsertRowId) { | 121 TEST_F(SQLConnectionTest, GetLastInsertRowId) { |
114 ASSERT_TRUE(db().Execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, value)")); | 122 ASSERT_TRUE(db().Execute("CREATE TABLE foo (id INTEGER PRIMARY KEY, value)")); |
115 | 123 |
116 ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)")); | 124 ASSERT_TRUE(db().Execute("INSERT INTO foo (value) VALUES (12)")); |
117 | 125 |
118 // Last insert row ID should be valid. | 126 // Last insert row ID should be valid. |
119 int64 row = db().GetLastInsertRowId(); | 127 int64 row = db().GetLastInsertRowId(); |
120 EXPECT_LT(0, row); | 128 EXPECT_LT(0, row); |
121 | 129 |
122 // It should be the primary key of the row we just inserted. | 130 // It should be the primary key of the row we just inserted. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // Otherwise, sqlite3 doesn't find the correct directory to store | 296 // Otherwise, sqlite3 doesn't find the correct directory to store |
289 // temporary files and will report the error 'unable to open | 297 // temporary files and will report the error 'unable to open |
290 // database file'. | 298 // database file'. |
291 ASSERT_TRUE(meta_table.Init(&db(), 4, 4)); | 299 ASSERT_TRUE(meta_table.Init(&db(), 4, 4)); |
292 } | 300 } |
293 #endif | 301 #endif |
294 | 302 |
295 // TODO(shess): Spin up a background thread to hold other_db, to more | 303 // TODO(shess): Spin up a background thread to hold other_db, to more |
296 // closely match real life. That would also allow testing | 304 // closely match real life. That would also allow testing |
297 // RazeWithTimeout(). | 305 // RazeWithTimeout(). |
OLD | NEW |