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

Side by Side Diff: sql/mojo/sql_test_base.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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/mojo/mojo_vfs.cc ('k') | sql/mojo/vfs_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/mojo/sql_test_base.h" 5 #include "sql/mojo/sql_test_base.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 20 matching lines...) Expand all
31 sql::Connection& SQLTestBase::db() { 31 sql::Connection& SQLTestBase::db() {
32 return db_; 32 return db_;
33 } 33 }
34 34
35 bool SQLTestBase::Reopen() { 35 bool SQLTestBase::Reopen() {
36 db_.Close(); 36 db_.Close();
37 return db_.Open(db_path()); 37 return db_.Open(db_path());
38 } 38 }
39 39
40 bool SQLTestBase::GetPathExists(const base::FilePath& path) { 40 bool SQLTestBase::GetPathExists(const base::FilePath& path) {
41 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 41 filesystem::FileError error = filesystem::FileError::FAILED;
42 bool exists = false; 42 bool exists = false;
43 vfs_->GetDirectory()->Exists(path.AsUTF8Unsafe(), Capture(&error, &exists)); 43 vfs_->GetDirectory()->Exists(path.AsUTF8Unsafe(), Capture(&error, &exists));
44 vfs_->GetDirectory().WaitForIncomingResponse(); 44 vfs_->GetDirectory().WaitForIncomingResponse();
45 if (error != filesystem::FILE_ERROR_OK) 45 if (error != filesystem::FileError::OK)
46 return false; 46 return false;
47 return exists; 47 return exists;
48 } 48 }
49 49
50 bool SQLTestBase::CorruptSizeInHeaderOfDB() { 50 bool SQLTestBase::CorruptSizeInHeaderOfDB() {
51 // See http://www.sqlite.org/fileformat.html#database_header 51 // See http://www.sqlite.org/fileformat.html#database_header
52 const size_t kHeaderSize = 100; 52 const size_t kHeaderSize = 100;
53 53
54 mojo::Array<uint8_t> header; 54 mojo::Array<uint8_t> header;
55 55
56 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 56 filesystem::FileError error = filesystem::FileError::FAILED;
57 filesystem::FilePtr file_ptr; 57 filesystem::FilePtr file_ptr;
58 vfs_->GetDirectory()->OpenFile( 58 vfs_->GetDirectory()->OpenFile(
59 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr), 59 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr),
60 filesystem::kFlagRead | filesystem::kFlagWrite | 60 filesystem::kFlagRead | filesystem::kFlagWrite |
61 filesystem::kFlagOpenAlways, 61 filesystem::kFlagOpenAlways,
62 Capture(&error)); 62 Capture(&error));
63 vfs_->GetDirectory().WaitForIncomingResponse(); 63 vfs_->GetDirectory().WaitForIncomingResponse();
64 if (error != filesystem::FILE_ERROR_OK) 64 if (error != filesystem::FileError::OK)
65 return false; 65 return false;
66 66
67 file_ptr->Read(kHeaderSize, 0, filesystem::WHENCE_FROM_BEGIN, 67 file_ptr->Read(kHeaderSize, 0, filesystem::Whence::FROM_BEGIN,
68 Capture(&error, &header)); 68 Capture(&error, &header));
69 file_ptr.WaitForIncomingResponse(); 69 file_ptr.WaitForIncomingResponse();
70 if (error != filesystem::FILE_ERROR_OK) 70 if (error != filesystem::FileError::OK)
71 return false; 71 return false;
72 72
73 filesystem::FileInformationPtr info; 73 filesystem::FileInformationPtr info;
74 file_ptr->Stat(Capture(&error, &info)); 74 file_ptr->Stat(Capture(&error, &info));
75 file_ptr.WaitForIncomingResponse(); 75 file_ptr.WaitForIncomingResponse();
76 if (error != filesystem::FILE_ERROR_OK) 76 if (error != filesystem::FileError::OK)
77 return false; 77 return false;
78 int64_t db_size = info->size; 78 int64_t db_size = info->size;
79 79
80 test::CorruptSizeInHeaderMemory(&header.front(), db_size); 80 test::CorruptSizeInHeaderMemory(&header.front(), db_size);
81 81
82 uint32_t num_bytes_written = 0; 82 uint32_t num_bytes_written = 0;
83 file_ptr->Write(std::move(header), 0, filesystem::WHENCE_FROM_BEGIN, 83 file_ptr->Write(std::move(header), 0, filesystem::Whence::FROM_BEGIN,
84 Capture(&error, &num_bytes_written)); 84 Capture(&error, &num_bytes_written));
85 file_ptr.WaitForIncomingResponse(); 85 file_ptr.WaitForIncomingResponse();
86 if (error != filesystem::FILE_ERROR_OK) 86 if (error != filesystem::FileError::OK)
87 return false; 87 return false;
88 if (num_bytes_written != kHeaderSize) 88 if (num_bytes_written != kHeaderSize)
89 return false; 89 return false;
90 90
91 return true; 91 return true;
92 } 92 }
93 93
94 void SQLTestBase::WriteJunkToDatabase(WriteJunkType type) { 94 void SQLTestBase::WriteJunkToDatabase(WriteJunkType type) {
95 uint32_t flags = 0; 95 uint32_t flags = 0;
96 if (type == TYPE_OVERWRITE_AND_TRUNCATE) 96 if (type == TYPE_OVERWRITE_AND_TRUNCATE)
97 flags = filesystem::kFlagWrite | filesystem::kFlagCreate; 97 flags = filesystem::kFlagWrite | filesystem::kFlagCreate;
98 else 98 else
99 flags = filesystem::kFlagWrite | filesystem::kFlagOpen; 99 flags = filesystem::kFlagWrite | filesystem::kFlagOpen;
100 100
101 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 101 filesystem::FileError error = filesystem::FileError::FAILED;
102 filesystem::FilePtr file_ptr; 102 filesystem::FilePtr file_ptr;
103 vfs_->GetDirectory()->OpenFile( 103 vfs_->GetDirectory()->OpenFile(
104 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr), 104 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr),
105 flags, 105 flags,
106 Capture(&error)); 106 Capture(&error));
107 vfs_->GetDirectory().WaitForIncomingResponse(); 107 vfs_->GetDirectory().WaitForIncomingResponse();
108 if (error != filesystem::FILE_ERROR_OK) 108 if (error != filesystem::FileError::OK)
109 return; 109 return;
110 110
111 const char* kJunk = "Now is the winter of our discontent."; 111 const char* kJunk = "Now is the winter of our discontent.";
112 mojo::Array<uint8_t> data(strlen(kJunk)); 112 mojo::Array<uint8_t> data(strlen(kJunk));
113 memcpy(&data.front(), kJunk, strlen(kJunk)); 113 memcpy(&data.front(), kJunk, strlen(kJunk));
114 114
115 uint32_t num_bytes_written = 0; 115 uint32_t num_bytes_written = 0;
116 file_ptr->Write(std::move(data), 0, filesystem::WHENCE_FROM_BEGIN, 116 file_ptr->Write(std::move(data), 0, filesystem::Whence::FROM_BEGIN,
117 Capture(&error, &num_bytes_written)); 117 Capture(&error, &num_bytes_written));
118 file_ptr.WaitForIncomingResponse(); 118 file_ptr.WaitForIncomingResponse();
119 } 119 }
120 120
121 void SQLTestBase::TruncateDatabase() { 121 void SQLTestBase::TruncateDatabase() {
122 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 122 filesystem::FileError error = filesystem::FileError::FAILED;
123 filesystem::FilePtr file_ptr; 123 filesystem::FilePtr file_ptr;
124 vfs_->GetDirectory()->OpenFile( 124 vfs_->GetDirectory()->OpenFile(
125 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr), 125 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr),
126 filesystem::kFlagWrite | filesystem::kFlagOpen, 126 filesystem::kFlagWrite | filesystem::kFlagOpen,
127 Capture(&error)); 127 Capture(&error));
128 vfs_->GetDirectory().WaitForIncomingResponse(); 128 vfs_->GetDirectory().WaitForIncomingResponse();
129 if (error != filesystem::FILE_ERROR_OK) 129 if (error != filesystem::FileError::OK)
130 return; 130 return;
131 131
132 file_ptr->Truncate(0, Capture(&error)); 132 file_ptr->Truncate(0, Capture(&error));
133 file_ptr.WaitForIncomingResponse(); 133 file_ptr.WaitForIncomingResponse();
134 ASSERT_EQ(filesystem::FILE_ERROR_OK, error); 134 ASSERT_EQ(filesystem::FileError::OK, error);
135 } 135 }
136 136
137 void SQLTestBase::SetUp() { 137 void SQLTestBase::SetUp() {
138 ApplicationTestBase::SetUp(); 138 ApplicationTestBase::SetUp();
139 139
140 application_impl()->ConnectToService("mojo:filesystem", &files_); 140 application_impl()->ConnectToService("mojo:filesystem", &files_);
141 141
142 filesystem::FileSystemClientPtr client; 142 filesystem::FileSystemClientPtr client;
143 binding_.Bind(GetProxy(&client)); 143 binding_.Bind(GetProxy(&client));
144 144
145 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; 145 filesystem::FileError error = filesystem::FileError::FAILED;
146 filesystem::DirectoryPtr directory; 146 filesystem::DirectoryPtr directory;
147 files()->OpenFileSystem("temp", GetProxy(&directory), std::move(client), 147 files()->OpenFileSystem("temp", GetProxy(&directory), std::move(client),
148 Capture(&error)); 148 Capture(&error));
149 ASSERT_TRUE(files().WaitForIncomingResponse()); 149 ASSERT_TRUE(files().WaitForIncomingResponse());
150 ASSERT_EQ(filesystem::FILE_ERROR_OK, error); 150 ASSERT_EQ(filesystem::FileError::OK, error);
151 151
152 vfs_.reset(new ScopedMojoFilesystemVFS(std::move(directory))); 152 vfs_.reset(new ScopedMojoFilesystemVFS(std::move(directory)));
153 ASSERT_TRUE(db_.Open(db_path())); 153 ASSERT_TRUE(db_.Open(db_path()));
154 } 154 }
155 155
156 void SQLTestBase::TearDown() { 156 void SQLTestBase::TearDown() {
157 db_.Close(); 157 db_.Close();
158 vfs_.reset(); 158 vfs_.reset();
159 159
160 ApplicationTestBase::TearDown(); 160 ApplicationTestBase::TearDown();
161 } 161 }
162 162
163 void SQLTestBase::OnFileSystemShutdown() { 163 void SQLTestBase::OnFileSystemShutdown() {
164 } 164 }
165 165
166 } // namespace sql 166 } // namespace sql
OLDNEW
« no previous file with comments | « sql/mojo/mojo_vfs.cc ('k') | sql/mojo/vfs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698