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

Side by Side Diff: sql/test/test_helpers.cc

Issue 1176653002: mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch cleanup now that gn check passes. Created 5 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
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/test/test_helpers.h" 5 #include "sql/test/test_helpers.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_file.h" 10 #include "base/files/scoped_file.h"
(...skipping 24 matching lines...) Expand all
35 bool GetRootPage(sql::Connection* db, const char* name, int* page_number) { 35 bool GetRootPage(sql::Connection* db, const char* name, int* page_number) {
36 const char kPageSql[] = "SELECT rootpage FROM sqlite_master WHERE name = ?"; 36 const char kPageSql[] = "SELECT rootpage FROM sqlite_master WHERE name = ?";
37 sql::Statement s(db->GetUniqueStatement(kPageSql)); 37 sql::Statement s(db->GetUniqueStatement(kPageSql));
38 s.BindString(0, name); 38 s.BindString(0, name);
39 if (!s.Step()) 39 if (!s.Step())
40 return false; 40 return false;
41 *page_number = s.ColumnInt(0); 41 *page_number = s.ColumnInt(0);
42 return true; 42 return true;
43 } 43 }
44 44
45 } // namespace
46
47 namespace sql {
48 namespace test {
49
45 // Helper for reading a number from the SQLite header. 50 // Helper for reading a number from the SQLite header.
46 // See base/big_endian.h. 51 // See base/big_endian.h.
47 unsigned ReadBigEndian(unsigned char* buf, size_t bytes) { 52 unsigned ReadBigEndian(unsigned char* buf, size_t bytes) {
48 unsigned r = buf[0]; 53 unsigned r = buf[0];
49 for (size_t i = 1; i < bytes; i++) { 54 for (size_t i = 1; i < bytes; i++) {
50 r <<= 8; 55 r <<= 8;
51 r |= buf[i]; 56 r |= buf[i];
52 } 57 }
53 return r; 58 return r;
54 } 59 }
55 60
56 // Helper for writing a number to the SQLite header. 61 // Helper for writing a number to the SQLite header.
57 void WriteBigEndian(unsigned val, unsigned char* buf, size_t bytes) { 62 void WriteBigEndian(unsigned val, unsigned char* buf, size_t bytes) {
58 for (size_t i = 0; i < bytes; i++) { 63 for (size_t i = 0; i < bytes; i++) {
59 buf[bytes - i - 1] = (val & 0xFF); 64 buf[bytes - i - 1] = (val & 0xFF);
60 val >>= 8; 65 val >>= 8;
61 } 66 }
62 } 67 }
63 68
64 } // namespace
65
66 namespace sql {
67 namespace test {
68
69 bool CorruptSizeInHeader(const base::FilePath& db_path) { 69 bool CorruptSizeInHeader(const base::FilePath& db_path) {
70 // See http://www.sqlite.org/fileformat.html#database_header 70 // See http://www.sqlite.org/fileformat.html#database_header
71 const size_t kHeaderSize = 100; 71 const size_t kHeaderSize = 100;
72 const size_t kPageSizeOffset = 16; 72 const size_t kPageSizeOffset = 16;
73 const size_t kFileChangeCountOffset = 24; 73 const size_t kFileChangeCountOffset = 24;
74 const size_t kPageCountOffset = 28; 74 const size_t kPageCountOffset = 28;
75 const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset 75 const size_t kVersionValidForOffset = 92; // duplicate kFileChangeCountOffset
76 76
77 unsigned char header[kHeaderSize]; 77 unsigned char header[kHeaderSize];
78 78
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check")); 243 sql::Statement statement(db->GetUniqueStatement("PRAGMA integrity_check"));
244 244
245 // SQLite should always return a row of data. 245 // SQLite should always return a row of data.
246 EXPECT_TRUE(statement.Step()); 246 EXPECT_TRUE(statement.Step());
247 247
248 return statement.ColumnString(0); 248 return statement.ColumnString(0);
249 } 249 }
250 250
251 } // namespace test 251 } // namespace test
252 } // namespace sql 252 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698