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 "chrome/utility/safe_browsing/mac/udif.h" | 5 #include "chrome/utility/safe_browsing/mac/udif.h" |
6 | 6 |
7 #include <hfs/hfs_format.h> | 7 #include <hfs/hfs_format.h> |
8 #include <libkern/OSByteOrder.h> | 8 #include <libkern/OSByteOrder.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 safe_browsing::dmg::UDIFParser udif(&file_stream); | 87 safe_browsing::dmg::UDIFParser udif(&file_stream); |
88 ASSERT_TRUE(udif.Parse()); | 88 ASSERT_TRUE(udif.Parse()); |
89 | 89 |
90 std::vector<uint8_t> buffer(buffer_size, 0); | 90 std::vector<uint8_t> buffer(buffer_size, 0); |
91 | 91 |
92 for (size_t i = 0; i < udif.GetNumberOfPartitions(); ++i) { | 92 for (size_t i = 0; i < udif.GetNumberOfPartitions(); ++i) { |
93 SCOPED_TRACE(base::StringPrintf("partition %zu", i)); | 93 SCOPED_TRACE(base::StringPrintf("partition %zu", i)); |
94 | 94 |
95 size_t total_size = udif.GetPartitionSize(i); | 95 size_t total_size = udif.GetPartitionSize(i); |
96 size_t total_bytes_read = 0; | 96 size_t total_bytes_read = 0; |
97 scoped_ptr<ReadStream> stream = udif.GetPartitionReadStream(i); | 97 std::unique_ptr<ReadStream> stream = udif.GetPartitionReadStream(i); |
98 | 98 |
99 bool success = false; | 99 bool success = false; |
100 do { | 100 do { |
101 size_t bytes_read = 0; | 101 size_t bytes_read = 0; |
102 success = stream->Read(&buffer[0], buffer.size(), &bytes_read); | 102 success = stream->Read(&buffer[0], buffer.size(), &bytes_read); |
103 total_bytes_read += bytes_read; | 103 total_bytes_read += bytes_read; |
104 EXPECT_TRUE(success); | 104 EXPECT_TRUE(success); |
105 EXPECT_TRUE(bytes_read == buffer_size || | 105 EXPECT_TRUE(bytes_read == buffer_size || |
106 total_bytes_read == total_size) | 106 total_bytes_read == total_size) |
107 << "bytes_read = " << bytes_read; | 107 << "bytes_read = " << bytes_read; |
(...skipping 19 matching lines...) Expand all Loading... |
127 | 127 |
128 size_t expected_partition_count = 0; | 128 size_t expected_partition_count = 0; |
129 for (; test_case.expected_partitions[expected_partition_count]; | 129 for (; test_case.expected_partitions[expected_partition_count]; |
130 ++expected_partition_count) { | 130 ++expected_partition_count) { |
131 } | 131 } |
132 | 132 |
133 EXPECT_EQ(expected_partition_count, udif.GetNumberOfPartitions()); | 133 EXPECT_EQ(expected_partition_count, udif.GetNumberOfPartitions()); |
134 | 134 |
135 for (size_t i = 0; i < udif.GetNumberOfPartitions(); ++i) { | 135 for (size_t i = 0; i < udif.GetNumberOfPartitions(); ++i) { |
136 SCOPED_TRACE(base::StringPrintf("partition %zu", i)); | 136 SCOPED_TRACE(base::StringPrintf("partition %zu", i)); |
137 scoped_ptr<ReadStream> stream = udif.GetPartitionReadStream(i); | 137 std::unique_ptr<ReadStream> stream = udif.GetPartitionReadStream(i); |
138 | 138 |
139 // Apple_HFS will match both HFS and HFSX. | 139 // Apple_HFS will match both HFS and HFSX. |
140 if (udif.GetPartitionType(i).find("Apple_HFS") != std::string::npos) { | 140 if (udif.GetPartitionType(i).find("Apple_HFS") != std::string::npos) { |
141 ASSERT_EQ( | 141 ASSERT_EQ( |
142 (UDIFTestCase::GET_HFS_STREAM & test_case.expected_results) != 0, | 142 (UDIFTestCase::GET_HFS_STREAM & test_case.expected_results) != 0, |
143 stream.get() != nullptr); | 143 stream.get() != nullptr); |
144 if (!stream) | 144 if (!stream) |
145 continue; | 145 continue; |
146 | 146 |
147 EXPECT_EQ(1024, stream->Seek(1024, SEEK_SET)); | 147 EXPECT_EQ(1024, stream->Seek(1024, SEEK_SET)); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 {"dmg_UFBI_SPUD.dmg", kAPMExpectedPartitions, UDIFTestCase::ALL_PASS}, | 251 {"dmg_UFBI_SPUD.dmg", kAPMExpectedPartitions, UDIFTestCase::ALL_PASS}, |
252 }; | 252 }; |
253 | 253 |
254 INSTANTIATE_TEST_CASE_P(UDIFParserTest, UDIFParserTest, | 254 INSTANTIATE_TEST_CASE_P(UDIFParserTest, UDIFParserTest, |
255 testing::ValuesIn(cases), | 255 testing::ValuesIn(cases), |
256 UDIFTestCase::GetTestName); | 256 UDIFTestCase::GetTestName); |
257 | 257 |
258 } // namespace | 258 } // namespace |
259 } // namespace dmg | 259 } // namespace dmg |
260 } // namespace safe_browsing | 260 } // namespace safe_browsing |
OLD | NEW |