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

Unified Diff: sql/test/test_helpers.h

Issue 2441153002: [sql] Test helpers to ease testing of simple queries. (Closed)
Patch Set: Created 4 years, 2 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 | « sql/recovery_unittest.cc ('k') | sql/test/test_helpers.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/test/test_helpers.h
diff --git a/sql/test/test_helpers.h b/sql/test/test_helpers.h
index 6ea666197bf5eaf56f7eed884eeeb2479a2c82b4..d40fbbf88a605d83472083f931b443d6f3578609 100644
--- a/sql/test/test_helpers.h
+++ b/sql/test/test_helpers.h
@@ -98,6 +98,27 @@ bool CreateDatabaseFromSQL(const base::FilePath& db_path,
// same, but not as convenient for testing. Maybe combine.
std::string IntegrityCheck(sql::Connection* db) WARN_UNUSED_RESULT;
+// ExecuteWithResult() executes |sql| and returns the first column of the first
+// row as a string. The empty string is returned for no rows. This makes it
+// easier to test simple query results using EXPECT_EQ(). For instance:
+// EXPECT_EQ("1024", ExecuteWithResult(db, "PRAGMA page_size"));
+//
+// ExecuteWithResults() stringifies a larger result set by putting |column_sep|
+// between columns and |row_sep| between rows. For instance:
+// EXPECT_EQ("1,3,5", ExecuteWithResults(
+// db, "SELECT id FROM t ORDER BY id", "|", ","));
+// Note that EXPECT_EQ() can nicely diff when using \n as |row_sep|.
+//
+// To test NULL, use the COALESCE() function:
+// EXPECT_EQ("<NULL>", ExecuteWithResult(
+// db, "SELECT c || '<NULL>' FROM t WHERE id = 1"));
+// To test blobs use the HEX() function.
+std::string ExecuteWithResult(sql::Connection* db, const char* sql);
+std::string ExecuteWithResults(sql::Connection* db,
+ const char* sql,
+ const char* column_sep,
+ const char* row_sep);
+
} // namespace test
} // namespace sql
« no previous file with comments | « sql/recovery_unittest.cc ('k') | sql/test/test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698