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

Side by Side Diff: trunk/src/sql/connection_unittest.cc

Issue 105823009: Revert 239280 "Move more file_util functions to base namespace." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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 | « trunk/src/skia/ext/vector_canvas_unittest.cc ('k') | trunk/src/sql/test/test_helpers.cc » ('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/bind.h" 5 #include "base/bind.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "sql/connection.h" 9 #include "sql/connection.h"
10 #include "sql/meta_table.h" 10 #include "sql/meta_table.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 416 }
417 417
418 // Verify that Raze() can handle an empty file. SQLite should treat 418 // Verify that Raze() can handle an empty file. SQLite should treat
419 // this as an empty database. 419 // this as an empty database.
420 TEST_F(SQLConnectionTest, RazeEmptyDB) { 420 TEST_F(SQLConnectionTest, RazeEmptyDB) {
421 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; 421 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
422 ASSERT_TRUE(db().Execute(kCreateSql)); 422 ASSERT_TRUE(db().Execute(kCreateSql));
423 db().Close(); 423 db().Close();
424 424
425 { 425 {
426 file_util::ScopedFILE file(base::OpenFile(db_path(), "rb+")); 426 file_util::ScopedFILE file(file_util::OpenFile(db_path(), "rb+"));
427 ASSERT_TRUE(file.get() != NULL); 427 ASSERT_TRUE(file.get() != NULL);
428 ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET)); 428 ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET));
429 ASSERT_TRUE(base::TruncateFile(file.get())); 429 ASSERT_TRUE(file_util::TruncateFile(file.get()));
430 } 430 }
431 431
432 ASSERT_TRUE(db().Open(db_path())); 432 ASSERT_TRUE(db().Open(db_path()));
433 ASSERT_TRUE(db().Raze()); 433 ASSERT_TRUE(db().Raze());
434 EXPECT_EQ(0, SqliteMasterCount(&db())); 434 EXPECT_EQ(0, SqliteMasterCount(&db()));
435 } 435 }
436 436
437 // Verify that Raze() can handle a file of junk. 437 // Verify that Raze() can handle a file of junk.
438 TEST_F(SQLConnectionTest, RazeNOTADB) { 438 TEST_F(SQLConnectionTest, RazeNOTADB) {
439 db().Close(); 439 db().Close();
440 sql::Connection::Delete(db_path()); 440 sql::Connection::Delete(db_path());
441 ASSERT_FALSE(base::PathExists(db_path())); 441 ASSERT_FALSE(base::PathExists(db_path()));
442 442
443 { 443 {
444 file_util::ScopedFILE file(base::OpenFile(db_path(), "wb")); 444 file_util::ScopedFILE file(file_util::OpenFile(db_path(), "wb"));
445 ASSERT_TRUE(file.get() != NULL); 445 ASSERT_TRUE(file.get() != NULL);
446 446
447 const char* kJunk = "This is the hour of our discontent."; 447 const char* kJunk = "This is the hour of our discontent.";
448 fputs(kJunk, file.get()); 448 fputs(kJunk, file.get());
449 } 449 }
450 ASSERT_TRUE(base::PathExists(db_path())); 450 ASSERT_TRUE(base::PathExists(db_path()));
451 451
452 // SQLite will successfully open the handle, but will fail with 452 // SQLite will successfully open the handle, but will fail with
453 // SQLITE_IOERR_SHORT_READ on pragma statemenets which read the 453 // SQLITE_IOERR_SHORT_READ on pragma statemenets which read the
454 // header. 454 // header.
(...skipping 12 matching lines...) Expand all
467 } 467 }
468 468
469 // Verify that Raze() can handle a database overwritten with garbage. 469 // Verify that Raze() can handle a database overwritten with garbage.
470 TEST_F(SQLConnectionTest, RazeNOTADB2) { 470 TEST_F(SQLConnectionTest, RazeNOTADB2) {
471 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; 471 const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
472 ASSERT_TRUE(db().Execute(kCreateSql)); 472 ASSERT_TRUE(db().Execute(kCreateSql));
473 ASSERT_EQ(1, SqliteMasterCount(&db())); 473 ASSERT_EQ(1, SqliteMasterCount(&db()));
474 db().Close(); 474 db().Close();
475 475
476 { 476 {
477 file_util::ScopedFILE file(base::OpenFile(db_path(), "rb+")); 477 file_util::ScopedFILE file(file_util::OpenFile(db_path(), "rb+"));
478 ASSERT_TRUE(file.get() != NULL); 478 ASSERT_TRUE(file.get() != NULL);
479 ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET)); 479 ASSERT_EQ(0, fseek(file.get(), 0, SEEK_SET));
480 480
481 const char* kJunk = "This is the hour of our discontent."; 481 const char* kJunk = "This is the hour of our discontent.";
482 fputs(kJunk, file.get()); 482 fputs(kJunk, file.get());
483 } 483 }
484 484
485 // SQLite will successfully open the handle, but will fail with 485 // SQLite will successfully open the handle, but will fail with
486 // SQLITE_NOTADB on pragma statemenets which attempt to read the 486 // SQLITE_NOTADB on pragma statemenets which attempt to read the
487 // corrupted header. 487 // corrupted header.
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 } 816 }
817 817
818 // Detach succeeds outside of a transaction. 818 // Detach succeeds outside of a transaction.
819 db().RollbackTransaction(); 819 db().RollbackTransaction();
820 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint)); 820 EXPECT_TRUE(db().DetachDatabase(kAttachmentPoint));
821 821
822 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar")); 822 EXPECT_FALSE(db().IsSQLValid("SELECT count(*) from other.bar"));
823 } 823 }
824 824
825 } // namespace 825 } // namespace
OLDNEW
« no previous file with comments | « trunk/src/skia/ext/vector_canvas_unittest.cc ('k') | trunk/src/sql/test/test_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698