OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef SQL_TEST_TEST_HELPERS_H_ | 5 #ifndef SQL_TEST_TEST_HELPERS_H_ |
6 #define SQL_TEST_TEST_HELPERS_H_ | 6 #define SQL_TEST_TEST_HELPERS_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // sql_path does not exist or cannot be read, or if there is an error | 91 // sql_path does not exist or cannot be read, or if there is an error |
92 // executing the statements. | 92 // executing the statements. |
93 bool CreateDatabaseFromSQL(const base::FilePath& db_path, | 93 bool CreateDatabaseFromSQL(const base::FilePath& db_path, |
94 const base::FilePath& sql_path) WARN_UNUSED_RESULT; | 94 const base::FilePath& sql_path) WARN_UNUSED_RESULT; |
95 | 95 |
96 // Return the results of running "PRAGMA integrity_check" on |db|. | 96 // Return the results of running "PRAGMA integrity_check" on |db|. |
97 // TODO(shess): sql::Connection::IntegrityCheck() is basically the | 97 // TODO(shess): sql::Connection::IntegrityCheck() is basically the |
98 // same, but not as convenient for testing. Maybe combine. | 98 // same, but not as convenient for testing. Maybe combine. |
99 std::string IntegrityCheck(sql::Connection* db) WARN_UNUSED_RESULT; | 99 std::string IntegrityCheck(sql::Connection* db) WARN_UNUSED_RESULT; |
100 | 100 |
| 101 // ExecuteWithResult() executes |sql| and returns the first column of the first |
| 102 // row as a string. The empty string is returned for no rows. This makes it |
| 103 // easier to test simple query results using EXPECT_EQ(). For instance: |
| 104 // EXPECT_EQ("1024", ExecuteWithResult(db, "PRAGMA page_size")); |
| 105 // |
| 106 // ExecuteWithResults() stringifies a larger result set by putting |column_sep| |
| 107 // between columns and |row_sep| between rows. For instance: |
| 108 // EXPECT_EQ("1,3,5", ExecuteWithResults( |
| 109 // db, "SELECT id FROM t ORDER BY id", "|", ",")); |
| 110 // Note that EXPECT_EQ() can nicely diff when using \n as |row_sep|. |
| 111 // |
| 112 // To test NULL, use the COALESCE() function: |
| 113 // EXPECT_EQ("<NULL>", ExecuteWithResult( |
| 114 // db, "SELECT c || '<NULL>' FROM t WHERE id = 1")); |
| 115 // To test blobs use the HEX() function. |
| 116 std::string ExecuteWithResult(sql::Connection* db, const char* sql); |
| 117 std::string ExecuteWithResults(sql::Connection* db, |
| 118 const char* sql, |
| 119 const char* column_sep, |
| 120 const char* row_sep); |
| 121 |
101 } // namespace test | 122 } // namespace test |
102 } // namespace sql | 123 } // namespace sql |
103 | 124 |
104 #endif // SQL_TEST_TEST_HELPERS_H_ | 125 #endif // SQL_TEST_TEST_HELPERS_H_ |
OLD | NEW |