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

Side by Side Diff: chrome/common/media_galleries/pmp_test_util.cc

Issue 1548153002: Switch to standard integer types in chrome/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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
OLDNEW
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 "chrome/common/media_galleries/pmp_test_util.h" 5 #include "chrome/common/media_galleries/pmp_test_util.h"
6 6
7 #include <stddef.h>
8
7 #include <algorithm> 9 #include <algorithm>
8 #include <iterator> 10 #include <iterator>
9 11
10 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/common/media_galleries/picasa_types.h" 15 #include "chrome/common/media_galleries/picasa_types.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace picasa { 18 namespace picasa {
17 19
18 namespace { 20 namespace {
19 21
20 // Flatten a vector of elements into an array of bytes. 22 // Flatten a vector of elements into an array of bytes.
21 template<class T> 23 template<class T>
22 std::vector<char> Flatten(const std::vector<T>& elems) { 24 std::vector<char> Flatten(const std::vector<T>& elems) {
23 if (elems.empty()) 25 if (elems.empty())
24 return std::vector<char>(); 26 return std::vector<char>();
25 27
26 const uint8* elems0 = reinterpret_cast<const uint8*>(&elems[0]); 28 const uint8_t* elems0 = reinterpret_cast<const uint8_t*>(&elems[0]);
27 std::vector<char> data_body(elems0, elems0 + sizeof(T) * elems.size()); 29 std::vector<char> data_body(elems0, elems0 + sizeof(T) * elems.size());
28 return data_body; 30 return data_body;
29 } 31 }
30 32
31 // Custom specialization for std::string. 33 // Custom specialization for std::string.
32 template<> 34 template<>
33 std::vector<char> Flatten(const std::vector<std::string>& strings) { 35 std::vector<char> Flatten(const std::vector<std::string>& strings) {
34 std::vector<char> totalchars; 36 std::vector<char> totalchars;
35 37
36 for (std::vector<std::string>::const_iterator it = strings.begin(); 38 for (std::vector<std::string>::const_iterator it = strings.begin();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 field_type, elements_vector.size(), elements_vector); 81 field_type, elements_vector.size(), elements_vector);
80 82
81 size_t bytes_written = base::WriteFile(path, &data[0], data.size()); 83 size_t bytes_written = base::WriteFile(path, &data[0], data.size());
82 return (bytes_written == data.size()); 84 return (bytes_written == data.size());
83 } 85 }
84 86
85 // Explicit Instantiation for all the valid types. 87 // Explicit Instantiation for all the valid types.
86 template bool PmpTestUtil::WriteColumnFileFromVector<std::string>( 88 template bool PmpTestUtil::WriteColumnFileFromVector<std::string>(
87 const base::FilePath&, const std::string&, const std::string&, 89 const base::FilePath&, const std::string&, const std::string&,
88 const PmpFieldType, const std::vector<std::string>&); 90 const PmpFieldType, const std::vector<std::string>&);
89 template bool PmpTestUtil::WriteColumnFileFromVector<uint32>( 91 template bool PmpTestUtil::WriteColumnFileFromVector<uint32_t>(
90 const base::FilePath&, const std::string&, const std::string&, 92 const base::FilePath&,
91 const PmpFieldType, const std::vector<uint32>&); 93 const std::string&,
94 const std::string&,
95 const PmpFieldType,
96 const std::vector<uint32_t>&);
92 template bool PmpTestUtil::WriteColumnFileFromVector<double>( 97 template bool PmpTestUtil::WriteColumnFileFromVector<double>(
93 const base::FilePath&, const std::string&, const std::string&, 98 const base::FilePath&, const std::string&, const std::string&,
94 const PmpFieldType, const std::vector<double>&); 99 const PmpFieldType, const std::vector<double>&);
95 template bool PmpTestUtil::WriteColumnFileFromVector<uint8>( 100 template bool PmpTestUtil::WriteColumnFileFromVector<uint8_t>(
96 const base::FilePath&, const std::string&, const std::string&, 101 const base::FilePath&,
97 const PmpFieldType, const std::vector<uint8>&); 102 const std::string&,
98 template bool PmpTestUtil::WriteColumnFileFromVector<uint64>( 103 const std::string&,
99 const base::FilePath&, const std::string&, const std::string&, 104 const PmpFieldType,
100 const PmpFieldType, const std::vector<uint64>&); 105 const std::vector<uint8_t>&);
106 template bool PmpTestUtil::WriteColumnFileFromVector<uint64_t>(
107 const base::FilePath&,
108 const std::string&,
109 const std::string&,
110 const PmpFieldType,
111 const std::vector<uint64_t>&);
101 112
102 // Return a vector so we don't have to worry about memory management. 113 // Return a vector so we don't have to worry about memory management.
103 std::vector<char> PmpTestUtil::MakeHeader(const PmpFieldType field_type, 114 std::vector<char> PmpTestUtil::MakeHeader(const PmpFieldType field_type,
104 const uint32 row_count) { 115 const uint32_t row_count) {
105 std::vector<char> header(picasa::kPmpHeaderSize); 116 std::vector<char> header(picasa::kPmpHeaderSize);
106 117
107 // Copy in magic bytes. 118 // Copy in magic bytes.
108 memcpy(&header[picasa::kPmpMagic1Offset], &picasa::kPmpMagic1, 119 memcpy(&header[picasa::kPmpMagic1Offset], &picasa::kPmpMagic1,
109 sizeof(picasa::kPmpMagic1)); 120 sizeof(picasa::kPmpMagic1));
110 memcpy(&header[picasa::kPmpMagic2Offset], &picasa::kPmpMagic2, 121 memcpy(&header[picasa::kPmpMagic2Offset], &picasa::kPmpMagic2,
111 sizeof(picasa::kPmpMagic2)); 122 sizeof(picasa::kPmpMagic2));
112 memcpy(&header[picasa::kPmpMagic3Offset], &picasa::kPmpMagic3, 123 memcpy(&header[picasa::kPmpMagic3Offset], &picasa::kPmpMagic3,
113 sizeof(picasa::kPmpMagic3)); 124 sizeof(picasa::kPmpMagic3));
114 memcpy(&header[picasa::kPmpMagic4Offset], &picasa::kPmpMagic4, 125 memcpy(&header[picasa::kPmpMagic4Offset], &picasa::kPmpMagic4,
115 sizeof(picasa::kPmpMagic4)); 126 sizeof(picasa::kPmpMagic4));
116 127
117 // Copy in field type. 128 // Copy in field type.
118 uint16 field_type_short = static_cast<uint16>(field_type); 129 uint16_t field_type_short = static_cast<uint16_t>(field_type);
119 memcpy(&header[picasa::kPmpFieldType1Offset], &field_type_short, 130 memcpy(&header[picasa::kPmpFieldType1Offset], &field_type_short,
120 sizeof(uint16)); 131 sizeof(uint16_t));
121 memcpy(&header[picasa::kPmpFieldType2Offset], &field_type_short, 132 memcpy(&header[picasa::kPmpFieldType2Offset], &field_type_short,
122 sizeof(uint16)); 133 sizeof(uint16_t));
123 134
124 // Copy in row count. 135 // Copy in row count.
125 memcpy(&header[picasa::kPmpRowCountOffset], &row_count, sizeof(uint32)); 136 memcpy(&header[picasa::kPmpRowCountOffset], &row_count, sizeof(uint32_t));
126 137
127 return header; 138 return header;
128 } 139 }
129 140
130 template<class T> 141 template <class T>
131 std::vector<char> PmpTestUtil::MakeHeaderAndBody( 142 std::vector<char> PmpTestUtil::MakeHeaderAndBody(const PmpFieldType field_type,
132 const PmpFieldType field_type, const uint32 row_count, 143 const uint32_t row_count,
133 const std::vector<T>& elems) { 144 const std::vector<T>& elems) {
134 return CombinedVectors(PmpTestUtil::MakeHeader(field_type, row_count), 145 return CombinedVectors(PmpTestUtil::MakeHeader(field_type, row_count),
135 Flatten(elems)); 146 Flatten(elems));
136 } 147 }
137 148
138 // Explicit Instantiation for all the valid types. 149 // Explicit Instantiation for all the valid types.
139 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<std::string>( 150 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<std::string>(
140 const PmpFieldType, const uint32, const std::vector<std::string>&); 151 const PmpFieldType,
141 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<uint32>( 152 const uint32_t,
142 const PmpFieldType, const uint32, const std::vector<uint32>&); 153 const std::vector<std::string>&);
154 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<uint32_t>(
155 const PmpFieldType,
156 const uint32_t,
157 const std::vector<uint32_t>&);
143 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<double>( 158 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<double>(
144 const PmpFieldType, const uint32, const std::vector<double>&); 159 const PmpFieldType,
145 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<uint8>( 160 const uint32_t,
146 const PmpFieldType, const uint32, const std::vector<uint8>&); 161 const std::vector<double>&);
147 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<uint64>( 162 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<uint8_t>(
148 const PmpFieldType, const uint32, const std::vector<uint64>&); 163 const PmpFieldType,
164 const uint32_t,
165 const std::vector<uint8_t>&);
166 template std::vector<char> PmpTestUtil::MakeHeaderAndBody<uint64_t>(
167 const PmpFieldType,
168 const uint32_t,
169 const std::vector<uint64_t>&);
149 170
150 } // namespace picasa 171 } // namespace picasa
OLDNEW
« no previous file with comments | « chrome/common/media_galleries/pmp_test_util.h ('k') | chrome/common/multi_process_lock_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698