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

Side by Side Diff: sql/recovery_unittest.cc

Issue 1991503002: [sql] sql::ScopedErrorIgnorer rename to sql::test::ScopedErrorExpecter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 6 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
« no previous file with comments | « sql/connection_unittest.cc ('k') | sql/sql.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 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 #include "sql/recovery.h" 5 #include "sql/recovery.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "sql/connection.h" 19 #include "sql/connection.h"
20 #include "sql/meta_table.h" 20 #include "sql/meta_table.h"
21 #include "sql/statement.h" 21 #include "sql/statement.h"
22 #include "sql/test/paths.h" 22 #include "sql/test/paths.h"
23 #include "sql/test/scoped_error_ignorer.h" 23 #include "sql/test/scoped_error_expecter.h"
24 #include "sql/test/sql_test_base.h" 24 #include "sql/test/sql_test_base.h"
25 #include "sql/test/test_helpers.h" 25 #include "sql/test/test_helpers.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "third_party/sqlite/sqlite3.h" 27 #include "third_party/sqlite/sqlite3.h"
28 28
29 namespace { 29 namespace {
30 30
31 // Execute |sql|, and stringify the results with |column_sep| between 31 // Execute |sql|, and stringify the results with |column_sep| between
32 // columns and |row_sep| between rows. 32 // columns and |row_sep| between rows.
33 // TODO(shess): Promote this to a central testing helper. 33 // TODO(shess): Promote this to a central testing helper.
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 EXPECT_FALSE(recovery->GetMetaVersionNumber(&version)); 415 EXPECT_FALSE(recovery->GetMetaVersionNumber(&version));
416 EXPECT_EQ(0, version); 416 EXPECT_EQ(0, version);
417 417
418 sql::Recovery::Rollback(std::move(recovery)); 418 sql::Recovery::Rollback(std::move(recovery));
419 } 419 }
420 ASSERT_TRUE(Reopen()); // Handle was poisoned. 420 ASSERT_TRUE(Reopen()); // Handle was poisoned.
421 421
422 // Test meta table missing. 422 // Test meta table missing.
423 EXPECT_TRUE(db().Execute("DROP TABLE meta")); 423 EXPECT_TRUE(db().Execute("DROP TABLE meta"));
424 { 424 {
425 sql::ScopedErrorIgnorer ignore_errors; 425 sql::test::ScopedErrorExpecter expecter;
426 ignore_errors.IgnoreError(SQLITE_CORRUPT); // From virtual table. 426 expecter.ExpectError(SQLITE_CORRUPT); // From virtual table.
427 std::unique_ptr<sql::Recovery> recovery = 427 std::unique_ptr<sql::Recovery> recovery =
428 sql::Recovery::Begin(&db(), db_path()); 428 sql::Recovery::Begin(&db(), db_path());
429 EXPECT_FALSE(recovery->SetupMeta()); 429 EXPECT_FALSE(recovery->SetupMeta());
430 ASSERT_TRUE(ignore_errors.CheckIgnoredErrors()); 430 ASSERT_TRUE(expecter.SawExpectedErrors());
431 } 431 }
432 } 432 }
433 433
434 // Baseline AutoRecoverTable() test. 434 // Baseline AutoRecoverTable() test.
435 TEST_F(SQLRecoveryTest, AutoRecoverTable) { 435 TEST_F(SQLRecoveryTest, AutoRecoverTable) {
436 // BIGINT and VARCHAR to test type affinity. 436 // BIGINT and VARCHAR to test type affinity.
437 const char kCreateSql[] = "CREATE TABLE x (id BIGINT, t TEXT, v VARCHAR)"; 437 const char kCreateSql[] = "CREATE TABLE x (id BIGINT, t TEXT, v VARCHAR)";
438 ASSERT_TRUE(db().Execute(kCreateSql)); 438 ASSERT_TRUE(db().Execute(kCreateSql));
439 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (11, 'This is', 'a test')")); 439 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (11, 'This is', 'a test')"));
440 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (5, 'That was', 'a test')")); 440 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (5, 'That was', 'a test')"));
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 sql::Recovery::Begin(&db(), db_path()); 761 sql::Recovery::Begin(&db(), db_path());
762 ASSERT_TRUE(recovery.get()); 762 ASSERT_TRUE(recovery.get());
763 763
764 // In the current implementation, the PRAGMA successfully runs with no result 764 // In the current implementation, the PRAGMA successfully runs with no result
765 // rows. Running with a single result of |0| is also acceptable. 765 // rows. Running with a single result of |0| is also acceptable.
766 sql::Statement s(recovery->db()->GetUniqueStatement("PRAGMA mmap_size")); 766 sql::Statement s(recovery->db()->GetUniqueStatement("PRAGMA mmap_size"));
767 EXPECT_TRUE(!s.Step() || !s.ColumnInt64(0)); 767 EXPECT_TRUE(!s.Step() || !s.ColumnInt64(0));
768 } 768 }
769 769
770 } // namespace 770 } // namespace
OLDNEW
« no previous file with comments | « sql/connection_unittest.cc ('k') | sql/sql.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698