| OLD | NEW |
| 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 | 10 |
| 10 #include "mojo/application/public/cpp/application_impl.h" | 11 #include "mojo/application/public/cpp/application_impl.h" |
| 11 #include "mojo/util/capture_util.h" | 12 #include "mojo/util/capture_util.h" |
| 12 #include "sql/mojo/mojo_vfs.h" | 13 #include "sql/mojo/mojo_vfs.h" |
| 13 #include "sql/test/test_helpers.h" | 14 #include "sql/test/test_helpers.h" |
| 14 | 15 |
| 15 using mojo::Capture; | 16 using mojo::Capture; |
| 16 | 17 |
| 17 namespace sql { | 18 namespace sql { |
| 18 | 19 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 filesystem::FileInformationPtr info; | 73 filesystem::FileInformationPtr info; |
| 73 file_ptr->Stat(Capture(&error, &info)); | 74 file_ptr->Stat(Capture(&error, &info)); |
| 74 file_ptr.WaitForIncomingResponse(); | 75 file_ptr.WaitForIncomingResponse(); |
| 75 if (error != filesystem::FILE_ERROR_OK) | 76 if (error != filesystem::FILE_ERROR_OK) |
| 76 return false; | 77 return false; |
| 77 int64_t db_size = info->size; | 78 int64_t db_size = info->size; |
| 78 | 79 |
| 79 test::CorruptSizeInHeaderMemory(&header.front(), db_size); | 80 test::CorruptSizeInHeaderMemory(&header.front(), db_size); |
| 80 | 81 |
| 81 uint32_t num_bytes_written = 0; | 82 uint32_t num_bytes_written = 0; |
| 82 file_ptr->Write(header.Pass(), 0, filesystem::WHENCE_FROM_BEGIN, | 83 file_ptr->Write(std::move(header), 0, filesystem::WHENCE_FROM_BEGIN, |
| 83 Capture(&error, &num_bytes_written)); | 84 Capture(&error, &num_bytes_written)); |
| 84 file_ptr.WaitForIncomingResponse(); | 85 file_ptr.WaitForIncomingResponse(); |
| 85 if (error != filesystem::FILE_ERROR_OK) | 86 if (error != filesystem::FILE_ERROR_OK) |
| 86 return false; | 87 return false; |
| 87 if (num_bytes_written != kHeaderSize) | 88 if (num_bytes_written != kHeaderSize) |
| 88 return false; | 89 return false; |
| 89 | 90 |
| 90 return true; | 91 return true; |
| 91 } | 92 } |
| 92 | 93 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 Capture(&error)); | 106 Capture(&error)); |
| 106 vfs_->GetDirectory().WaitForIncomingResponse(); | 107 vfs_->GetDirectory().WaitForIncomingResponse(); |
| 107 if (error != filesystem::FILE_ERROR_OK) | 108 if (error != filesystem::FILE_ERROR_OK) |
| 108 return; | 109 return; |
| 109 | 110 |
| 110 const char* kJunk = "Now is the winter of our discontent."; | 111 const char* kJunk = "Now is the winter of our discontent."; |
| 111 mojo::Array<uint8_t> data(strlen(kJunk)); | 112 mojo::Array<uint8_t> data(strlen(kJunk)); |
| 112 memcpy(&data.front(), kJunk, strlen(kJunk)); | 113 memcpy(&data.front(), kJunk, strlen(kJunk)); |
| 113 | 114 |
| 114 uint32_t num_bytes_written = 0; | 115 uint32_t num_bytes_written = 0; |
| 115 file_ptr->Write(data.Pass(), 0, filesystem::WHENCE_FROM_BEGIN, | 116 file_ptr->Write(std::move(data), 0, filesystem::WHENCE_FROM_BEGIN, |
| 116 Capture(&error, &num_bytes_written)); | 117 Capture(&error, &num_bytes_written)); |
| 117 file_ptr.WaitForIncomingResponse(); | 118 file_ptr.WaitForIncomingResponse(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void SQLTestBase::TruncateDatabase() { | 121 void SQLTestBase::TruncateDatabase() { |
| 121 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 122 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
| 122 filesystem::FilePtr file_ptr; | 123 filesystem::FilePtr file_ptr; |
| 123 vfs_->GetDirectory()->OpenFile( | 124 vfs_->GetDirectory()->OpenFile( |
| 124 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr), | 125 mojo::String(db_path().AsUTF8Unsafe()), GetProxy(&file_ptr), |
| 125 filesystem::kFlagWrite | filesystem::kFlagOpen, | 126 filesystem::kFlagWrite | filesystem::kFlagOpen, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 136 void SQLTestBase::SetUp() { | 137 void SQLTestBase::SetUp() { |
| 137 ApplicationTestBase::SetUp(); | 138 ApplicationTestBase::SetUp(); |
| 138 | 139 |
| 139 application_impl()->ConnectToService("mojo:filesystem", &files_); | 140 application_impl()->ConnectToService("mojo:filesystem", &files_); |
| 140 | 141 |
| 141 filesystem::FileSystemClientPtr client; | 142 filesystem::FileSystemClientPtr client; |
| 142 binding_.Bind(GetProxy(&client)); | 143 binding_.Bind(GetProxy(&client)); |
| 143 | 144 |
| 144 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; | 145 filesystem::FileError error = filesystem::FILE_ERROR_FAILED; |
| 145 filesystem::DirectoryPtr directory; | 146 filesystem::DirectoryPtr directory; |
| 146 files()->OpenFileSystem("temp", GetProxy(&directory), client.Pass(), | 147 files()->OpenFileSystem("temp", GetProxy(&directory), std::move(client), |
| 147 Capture(&error)); | 148 Capture(&error)); |
| 148 ASSERT_TRUE(files().WaitForIncomingResponse()); | 149 ASSERT_TRUE(files().WaitForIncomingResponse()); |
| 149 ASSERT_EQ(filesystem::FILE_ERROR_OK, error); | 150 ASSERT_EQ(filesystem::FILE_ERROR_OK, error); |
| 150 | 151 |
| 151 vfs_.reset(new ScopedMojoFilesystemVFS(directory.Pass())); | 152 vfs_.reset(new ScopedMojoFilesystemVFS(std::move(directory))); |
| 152 ASSERT_TRUE(db_.Open(db_path())); | 153 ASSERT_TRUE(db_.Open(db_path())); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void SQLTestBase::TearDown() { | 156 void SQLTestBase::TearDown() { |
| 156 db_.Close(); | 157 db_.Close(); |
| 157 vfs_.reset(); | 158 vfs_.reset(); |
| 158 | 159 |
| 159 ApplicationTestBase::TearDown(); | 160 ApplicationTestBase::TearDown(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 void SQLTestBase::OnFileSystemShutdown() { | 163 void SQLTestBase::OnFileSystemShutdown() { |
| 163 } | 164 } |
| 164 | 165 |
| 165 } // namespace sql | 166 } // namespace sql |
| OLD | NEW |