OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS 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 <sys/stat.h> | 5 #include <sys/stat.h> |
6 #include <sys/types.h> | 6 #include <sys/types.h> |
7 #include <unistd.h> | 7 #include <unistd.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 size_t bytes_written = 0; | 230 size_t bytes_written = 0; |
231 while (bytes_written < (block_count * kBlockSize)) { | 231 while (bytes_written < (block_count * kBlockSize)) { |
232 size_t bytes_to_write = min(block_count * kBlockSize - bytes_written, | 232 size_t bytes_to_write = min(block_count * kBlockSize - bytes_written, |
233 data.size()); | 233 data.size()); |
234 EXPECT_TRUE(direct_writer.Write(&data[0], bytes_to_write)); | 234 EXPECT_TRUE(direct_writer.Write(&data[0], bytes_to_write)); |
235 bytes_written += bytes_to_write; | 235 bytes_written += bytes_to_write; |
236 } | 236 } |
237 EXPECT_TRUE(direct_writer.End()); | 237 EXPECT_TRUE(direct_writer.End()); |
238 | 238 |
239 // check file size, then data inside | 239 // check file size, then data inside |
240 ASSERT_EQ(2 * kBlockSize, FileSize(path())); | 240 ASSERT_EQ(2 * kBlockSize, utils::FileSize(path())); |
241 | 241 |
242 vector<char> resultant_data; | 242 vector<char> resultant_data; |
243 EXPECT_TRUE(utils::ReadFile(path(), &resultant_data)); | 243 EXPECT_TRUE(utils::ReadFile(path(), &resultant_data)); |
244 | 244 |
245 // Create expected data | 245 // Create expected data |
246 vector<char> expected_data(on_disk_count * kBlockSize); | 246 vector<char> expected_data(on_disk_count * kBlockSize); |
247 vector<char> big(block_count * kBlockSize); | 247 vector<char> big(block_count * kBlockSize); |
248 for (vector<char>::size_type i = 0; i < big.size(); i++) { | 248 for (vector<char>::size_type i = 0; i < big.size(); i++) { |
249 big[i] = data[i % data.size()]; | 249 big[i] = data[i % data.size()]; |
250 } | 250 } |
251 memcpy(&expected_data[kBlockSize], &big[0], kBlockSize); | 251 memcpy(&expected_data[kBlockSize], &big[0], kBlockSize); |
252 memcpy(&expected_data[0], &big[3 * kBlockSize], kBlockSize); | 252 memcpy(&expected_data[0], &big[3 * kBlockSize], kBlockSize); |
253 ExpectVectorsEq(expected_data, resultant_data); | 253 ExpectVectorsEq(expected_data, resultant_data); |
254 } | 254 } |
255 | 255 |
256 } // namespace chromeos_update_engine | 256 } // namespace chromeos_update_engine |
OLD | NEW |