| OLD | NEW |
| 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 "webkit/fileapi/media/picasa/pmp_test_helper.h" | 5 #include "webkit/fileapi/media/picasa/pmp_test_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 std::vector<uint8> total; | 52 std::vector<uint8> total; |
| 53 | 53 |
| 54 std::copy(a.begin(), a.end(), std::back_inserter(total)); | 54 std::copy(a.begin(), a.end(), std::back_inserter(total)); |
| 55 std::copy(b.begin(), b.end(), std::back_inserter(total)); | 55 std::copy(b.begin(), b.end(), std::back_inserter(total)); |
| 56 | 56 |
| 57 return total; | 57 return total; |
| 58 } | 58 } |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 PmpTestHelper::PmpTestHelper() { } | 62 PmpTestHelper::PmpTestHelper() {} |
| 63 | 63 |
| 64 bool PmpTestHelper::Init() { | 64 bool PmpTestHelper::Init() { |
| 65 return temp_dir_.CreateUniqueTempDir(); | 65 return temp_dir_.CreateUniqueTempDir(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 base::FilePath PmpTestHelper::GetTempDirPath() { | 68 base::FilePath PmpTestHelper::GetTempDirPath() { |
| 69 DCHECK(temp_dir_.IsValid()); | 69 DCHECK(temp_dir_.IsValid()); |
| 70 return temp_dir_.path(); | 70 return temp_dir_.path(); |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 99 const std::vector<double>&); | 99 const std::vector<double>&); |
| 100 template bool PmpTestHelper::WriteColumnFileFromVector<uint8>( | 100 template bool PmpTestHelper::WriteColumnFileFromVector<uint8>( |
| 101 const std::string&, const std::string&, const PmpFieldType, | 101 const std::string&, const std::string&, const PmpFieldType, |
| 102 const std::vector<uint8>&); | 102 const std::vector<uint8>&); |
| 103 template bool PmpTestHelper::WriteColumnFileFromVector<uint64>( | 103 template bool PmpTestHelper::WriteColumnFileFromVector<uint64>( |
| 104 const std::string&, const std::string&, const PmpFieldType, | 104 const std::string&, const std::string&, const PmpFieldType, |
| 105 const std::vector<uint64>&); | 105 const std::vector<uint64>&); |
| 106 | 106 |
| 107 bool PmpTestHelper::InitColumnReaderFromBytes( | 107 bool PmpTestHelper::InitColumnReaderFromBytes( |
| 108 PmpColumnReader* const reader, const std::vector<uint8>& data, | 108 PmpColumnReader* const reader, const std::vector<uint8>& data, |
| 109 uint32* rows_read) { | 109 const PmpFieldType expected_type, uint32* rows_read) { |
| 110 DCHECK(temp_dir_.IsValid()); | 110 DCHECK(temp_dir_.IsValid()); |
| 111 | 111 |
| 112 base::FilePath temp_path; | 112 base::FilePath temp_path; |
| 113 | 113 |
| 114 if (!file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path) || | 114 if (!file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path) || |
| 115 !WriteToFile(temp_path, data)) { | 115 !WriteToFile(temp_path, data)) { |
| 116 return false; | 116 return false; |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool success = reader->Init(temp_path, rows_read); | 119 bool success = reader->Init(temp_path, expected_type, rows_read); |
| 120 | 120 |
| 121 file_util::Delete(temp_path, true); | 121 file_util::Delete(temp_path, true); |
| 122 | 122 |
| 123 return success; | 123 return success; |
| 124 | 124 |
| 125 } | 125 } |
| 126 | 126 |
| 127 // Return a vector so we don't have to worry about memory management. | 127 // Return a vector so we don't have to worry about memory management. |
| 128 std::vector<uint8> PmpTestHelper::MakeHeader(const PmpFieldType field_type, | 128 std::vector<uint8> PmpTestHelper::MakeHeader(const PmpFieldType field_type, |
| 129 const uint32 row_count) { | 129 const uint32 row_count) { |
| 130 std::vector<uint8> header(picasaimport::kPmpHeaderSize); | 130 std::vector<uint8> header(picasaimport::kPmpHeaderSize); |
| 131 | 131 |
| 132 // Copy in magic bytes. | 132 // Copy in magic bytes. |
| 133 memcpy(&header[picasaimport::kPmpMagic1Offset], &picasaimport::kPmpMagic1, | 133 memcpy(&header[picasaimport::kPmpMagic1Offset], &picasaimport::kPmpMagic1, |
| 134 sizeof(picasaimport::kPmpMagic1)); | 134 sizeof(picasaimport::kPmpMagic1)); |
| 135 memcpy(&header[picasaimport::kPmpMagic2Offset], &picasaimport::kPmpMagic2, | 135 memcpy(&header[picasaimport::kPmpMagic2Offset], &picasaimport::kPmpMagic2, |
| 136 sizeof(picasaimport::kPmpMagic2)); | 136 sizeof(picasaimport::kPmpMagic2)); |
| 137 memcpy(&header[picasaimport::kPmpMagic3Offset], &picasaimport::kPmpMagic3, | 137 memcpy(&header[picasaimport::kPmpMagic3Offset], &picasaimport::kPmpMagic3, |
| 138 sizeof(picasaimport::kPmpMagic3)); | 138 sizeof(picasaimport::kPmpMagic3)); |
| 139 memcpy(&header[picasaimport::kPmpMagic4Offset], &picasaimport::kPmpMagic4, | 139 memcpy(&header[picasaimport::kPmpMagic4Offset], &picasaimport::kPmpMagic4, |
| 140 sizeof(picasaimport::kPmpMagic4)); | 140 sizeof(picasaimport::kPmpMagic4)); |
| 141 | 141 |
| 142 // Copy in field type. | 142 // Copy in field type. |
| 143 memcpy(&header[picasaimport::kPmpFieldType1Offset], &field_type, 2); | 143 uint16 field_type_short = static_cast<uint16>(field_type); |
| 144 memcpy(&header[picasaimport::kPmpFieldType2Offset], &field_type, 2); | 144 memcpy(&header[picasaimport::kPmpFieldType1Offset], &field_type_short, |
| 145 sizeof(uint16)); |
| 146 memcpy(&header[picasaimport::kPmpFieldType2Offset], &field_type_short, |
| 147 sizeof(uint16)); |
| 145 | 148 |
| 146 // Copy in row count. | 149 // Copy in row count. |
| 147 memcpy(&header[picasaimport::kPmpRowCountOffset], &row_count, 4); | 150 memcpy(&header[picasaimport::kPmpRowCountOffset], &row_count, sizeof(uint32)); |
| 148 | 151 |
| 149 return header; | 152 return header; |
| 150 } | 153 } |
| 151 | 154 |
| 152 template<class T> | 155 template<class T> |
| 153 std::vector<uint8> PmpTestHelper::MakeHeaderAndBody( | 156 std::vector<uint8> PmpTestHelper::MakeHeaderAndBody( |
| 154 const PmpFieldType field_type, const uint32 row_count, | 157 const PmpFieldType field_type, const uint32 row_count, |
| 155 const std::vector<T>& elems) { | 158 const std::vector<T>& elems) { |
| 156 return CombinedVectors(PmpTestHelper::MakeHeader(field_type, row_count), | 159 return CombinedVectors(PmpTestHelper::MakeHeader(field_type, row_count), |
| 157 Flatten(elems)); | 160 Flatten(elems)); |
| 158 } | 161 } |
| 159 | 162 |
| 160 // Explicit Instantiation for all the valid types. | 163 // Explicit Instantiation for all the valid types. |
| 161 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<std::string>( | 164 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<std::string>( |
| 162 const PmpFieldType, const uint32, const std::vector<std::string>&); | 165 const PmpFieldType, const uint32, const std::vector<std::string>&); |
| 163 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint32>( | 166 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint32>( |
| 164 const PmpFieldType, const uint32, const std::vector<uint32>&); | 167 const PmpFieldType, const uint32, const std::vector<uint32>&); |
| 165 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<double>( | 168 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<double>( |
| 166 const PmpFieldType, const uint32, const std::vector<double>&); | 169 const PmpFieldType, const uint32, const std::vector<double>&); |
| 167 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint8>( | 170 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint8>( |
| 168 const PmpFieldType, const uint32, const std::vector<uint8>&); | 171 const PmpFieldType, const uint32, const std::vector<uint8>&); |
| 169 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint64>( | 172 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint64>( |
| 170 const PmpFieldType, const uint32, const std::vector<uint64>&); | 173 const PmpFieldType, const uint32, const std::vector<uint64>&); |
| 171 | 174 |
| 172 } // namespace picasaimport | 175 } // namespace picasaimport |
| OLD | NEW |