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

Side by Side Diff: chrome/utility/media_galleries/iphoto_library_parser_unittest.cc

Issue 52093003: [MediaGalleries] iPhoto: Add original file field to the parser. Dedupe album names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add album name dedupe Created 7 years, 1 month 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 | Annotate | Revision Log
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 "base/logging.h" 5 #include "base/logging.h"
6 #include "chrome/common/media_galleries/iphoto_library.h" 6 #include "chrome/common/media_galleries/iphoto_library.h"
7 #include "chrome/utility/media_galleries/iphoto_library_parser.h" 7 #include "chrome/utility/media_galleries/iphoto_library_parser.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 #define SIMPLE_HEADER() \ 10 #define SIMPLE_HEADER() \
(...skipping 23 matching lines...) Expand all
34 " </array>" \ 34 " </array>" \
35 " </dict>" 35 " </dict>"
36 36
37 #define IMAGE_LIST_HEADER() \ 37 #define IMAGE_LIST_HEADER() \
38 " <key>Master Image List</key>" \ 38 " <key>Master Image List</key>" \
39 " <dict>" 39 " <dict>"
40 40
41 #define IMAGE_LIST_FOOTER() \ 41 #define IMAGE_LIST_FOOTER() \
42 " </dict>" 42 " </dict>"
43 43
44 #define SIMPLE_PHOTO(id, guid, path, caption) \ 44 #define SIMPLE_PHOTO(id, guid, path, caption, date) \
45 " <key>" #id "</key>" \ 45 " <key>" #id "</key>" \
46 " <dict>" \ 46 " <dict>" \
47 " <key>MediaType</key>" \ 47 " <key>MediaType</key>" \
48 " <string>Image</string>" \ 48 " <string>Image</string>" \
49 " <key>Caption</key>" \ 49 " <key>Caption</key>" \
50 " <string>" caption "</string>" \ 50 " <string>" caption "</string>" \
51 " <key>GUID</key>" \ 51 " <key>GUID</key>" \
52 " <string>" #guid "</string>" \ 52 " <string>" #guid "</string>" \
53 " <key>ModDateAsTimerInterval</key>" \
54 " <string>386221543.0000</string>" \
55 " <key>DateAsTimerInterval</key>" \
56 " <string>386221543.0000</string>" \
57 " <key>DateAsTimerIntervalGMT</key>" \
58 " <string>" date "</string>" \
53 " <key>ImagePath</key>" \ 59 " <key>ImagePath</key>" \
54 " <string>" path "</string>" \ 60 " <string>" path "</string>" \
61 " <key>OriginalPath</key>" \
62 " <string>/original" path "</string>" \
55 " <key>ThumbPath</key>" \ 63 " <key>ThumbPath</key>" \
56 " <string>" path "</string>" \ 64 " <string>" path "</string>" \
57 " </dict>" 65 " </dict>"
58 66
59 #define SIMPLE_FOOTER() \ 67 #define SIMPLE_FOOTER() \
60 " </dict>" \ 68 " </dict>" \
61 "</plist>" 69 "</plist>"
62 70
71 #define TIMESTAMP "385123456.00"
72
63 namespace iphoto { 73 namespace iphoto {
64 74
65 namespace { 75 namespace {
66 76
67 void ComparePhoto(const parser::Photo& a, const parser::Photo& b) { 77 void ComparePhoto(const parser::Photo& a, const parser::Photo& b) {
68 EXPECT_EQ(a.id, b.id); 78 EXPECT_EQ(a.id, b.id);
69 EXPECT_EQ(a.location.value(), b.location.value()); 79 EXPECT_EQ(a.location.value(), b.location.value());
80 EXPECT_EQ(a.original_location.value(), b.original_location.value());
81 EXPECT_EQ(a.photo_time.ToInternalValue(), b.photo_time.ToInternalValue());
70 } 82 }
71 83
72 void CompareAlbum(const parser::Album& a, const parser::Album& b) { 84 void CompareAlbum(const parser::Album& a, const parser::Album& b) {
73 EXPECT_EQ(a.size(), b.size()); 85 EXPECT_EQ(a.size(), b.size());
74 86
75 parser::Album::const_iterator a_it; 87 parser::Album::const_iterator a_it;
76 parser::Album::const_iterator b_it; 88 parser::Album::const_iterator b_it;
77 for (a_it = a.begin(), b_it = b.begin(); 89 for (a_it = a.begin(), b_it = b.begin();
78 a_it != a.end() && b_it != b.end(); 90 a_it != a.end() && b_it != b.end();
79 ++a_it, ++b_it) { 91 ++a_it, ++b_it) {
(...skipping 19 matching lines...) Expand all
99 111
100 std::set<parser::Photo>::const_iterator a_it; 112 std::set<parser::Photo>::const_iterator a_it;
101 std::set<parser::Photo>::const_iterator b_it; 113 std::set<parser::Photo>::const_iterator b_it;
102 for (a_it = a.all_photos.begin(), b_it = b.all_photos.begin(); 114 for (a_it = a.all_photos.begin(), b_it = b.all_photos.begin();
103 a_it != a.all_photos.end() && b_it != b.all_photos.end(); 115 a_it != a.all_photos.end() && b_it != b.all_photos.end();
104 ++a_it, ++b_it) { 116 ++a_it, ++b_it) {
105 ComparePhoto(*a_it, *b_it); 117 ComparePhoto(*a_it, *b_it);
106 } 118 }
107 } 119 }
108 120
121 static const int64 kTimestampInt = 385123456;
122
109 class IPhotoLibraryParserTest : public testing::Test { 123 class IPhotoLibraryParserTest : public testing::Test {
110 public: 124 public:
111 IPhotoLibraryParserTest() {} 125 IPhotoLibraryParserTest() {}
112 126
113 void TestParser(bool expected_result, const std::string& xml) { 127 void TestParser(bool expected_result, const std::string& xml) {
114 IPhotoLibraryParser parser; 128 IPhotoLibraryParser parser;
115 129
116 EXPECT_EQ(expected_result, parser.Parse(xml)); 130 EXPECT_EQ(expected_result, parser.Parse(xml));
117 if (!expected_result) 131 if (!expected_result)
118 return; 132 return;
119 133
120 CompareLibrary(expected_library_, parser.library()); 134 CompareLibrary(expected_library_, parser.library());
121 } 135 }
122 136
123 void AddExpectedPhoto(uint32 id, const std::string& location, 137 void AddExpectedPhoto(uint32 id,
138 const std::string& location,
139 const base::Time& time,
124 const std::string& album) { 140 const std::string& album) {
125 parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location)); 141 parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location),
142 base::FilePath::FromUTF8Unsafe("/original" + location),
143 time);
126 if (!album.empty()) 144 if (!album.empty())
127 expected_library_.albums[album].insert(id); 145 expected_library_.albums[album].insert(id);
128 expected_library_.all_photos.insert(photo); 146 expected_library_.all_photos.insert(photo);
129 } 147 }
130 148
149 base::Time GetTime(int64 time_2001) {
150 // Apple epoch
151 base::Time::Exploded e;
152 e.year = 2001;
153 e.month = 1;
154 e.day_of_month = 1;
155 e.hour = 0;
156 e.minute = 0;
157 e.second = 0;
158 e.millisecond = 0;
159 base::Time t = base::Time::FromUTCExploded(e);
160 t += base::TimeDelta::FromSeconds(time_2001);
161 return t;
162 }
163
131 private: 164 private:
132 parser::Library expected_library_; 165 parser::Library expected_library_;
133 166
134 DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest); 167 DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest);
135 }; 168 };
136 169
137 TEST_F(IPhotoLibraryParserTest, EmptyLibrary) { 170 TEST_F(IPhotoLibraryParserTest, EmptyLibrary) {
138 TestParser(false, ""); 171 TestParser(false, "");
139 } 172 }
140 173
141 TEST_F(IPhotoLibraryParserTest, MinimalXML) { 174 TEST_F(IPhotoLibraryParserTest, MinimalXML) {
142 AddExpectedPhoto(1, "/dir/Photo With Space.jpg", ""); 175 AddExpectedPhoto(1, "/dir/Photo With Space.jpg", GetTime(kTimestampInt), "");
143 TestParser( 176 TestParser(
144 true, 177 true,
145 SIMPLE_HEADER() 178 SIMPLE_HEADER()
146 IMAGE_LIST_HEADER() 179 IMAGE_LIST_HEADER()
147 SIMPLE_PHOTO(1, 1, "/dir/Photo With Space.jpg", "Photo 1") 180 SIMPLE_PHOTO(1, 1, "/dir/Photo With Space.jpg", "Photo 1", TIMESTAMP)
148 IMAGE_LIST_FOOTER() 181 IMAGE_LIST_FOOTER()
149 SIMPLE_FOOTER()); 182 SIMPLE_FOOTER());
150 } 183 }
151 184
152 TEST_F(IPhotoLibraryParserTest, MultiplePhotos) { 185 TEST_F(IPhotoLibraryParserTest, MultiplePhotos) {
153 AddExpectedPhoto(1, "/dir/SongA1.jpg", ""); 186 AddExpectedPhoto(1, "/dir/SongA1.jpg", GetTime(kTimestampInt), "");
154 AddExpectedPhoto(2, "/dir/SongA2.jpg", ""); 187 AddExpectedPhoto(2, "/dir/SongA2.jpg", GetTime(kTimestampInt), "");
155 AddExpectedPhoto(3, "/dir/SongA3.jpg", ""); 188 AddExpectedPhoto(3, "/dir/SongA3.jpg", GetTime(kTimestampInt), "");
156 AddExpectedPhoto(4, "/dir/SongB1.jpg", ""); 189 AddExpectedPhoto(4, "/dir/SongB1.jpg", GetTime(kTimestampInt), "");
157 AddExpectedPhoto(5, "/dir/SongB2.jpg", ""); 190 AddExpectedPhoto(5, "/dir/SongB2.jpg", GetTime(kTimestampInt), "");
158 AddExpectedPhoto(6, "/dir2/SongB1.jpg", ""); 191 AddExpectedPhoto(6, "/dir2/SongB1.jpg", GetTime(kTimestampInt), "");
159 AddExpectedPhoto(7, "/dir2/SongB2.jpg", ""); 192 AddExpectedPhoto(7, "/dir2/SongB2.jpg", GetTime(kTimestampInt), "");
160 TestParser( 193 TestParser(
161 true, 194 true,
162 SIMPLE_HEADER() 195 SIMPLE_HEADER()
163 IMAGE_LIST_HEADER() 196 IMAGE_LIST_HEADER()
164 SIMPLE_PHOTO(1, 1, "/dir/SongA1.jpg", "Photo 1") 197 SIMPLE_PHOTO(1, 1, "/dir/SongA1.jpg", "Photo 1", TIMESTAMP)
165 SIMPLE_PHOTO(2, 2, "/dir/SongA2.jpg", "Photo 2") 198 SIMPLE_PHOTO(2, 2, "/dir/SongA2.jpg", "Photo 2", TIMESTAMP)
166 SIMPLE_PHOTO(3, 3, "/dir/SongA3.jpg", "Photo 3") 199 SIMPLE_PHOTO(3, 3, "/dir/SongA3.jpg", "Photo 3", TIMESTAMP)
167 SIMPLE_PHOTO(4, 4, "/dir/SongB1.jpg", "Photo 4") 200 SIMPLE_PHOTO(4, 4, "/dir/SongB1.jpg", "Photo 4", TIMESTAMP)
168 SIMPLE_PHOTO(5, 5, "/dir/SongB2.jpg", "Photo 5") 201 SIMPLE_PHOTO(5, 5, "/dir/SongB2.jpg", "Photo 5", TIMESTAMP)
169 SIMPLE_PHOTO(6, 6, "/dir2/SongB1.jpg", "Photo 6") 202 SIMPLE_PHOTO(6, 6, "/dir2/SongB1.jpg", "Photo 6", TIMESTAMP)
170 SIMPLE_PHOTO(7, 7, "/dir2/SongB2.jpg", "Photo 7") 203 SIMPLE_PHOTO(7, 7, "/dir2/SongB2.jpg", "Photo 7", TIMESTAMP)
171 IMAGE_LIST_FOOTER() 204 IMAGE_LIST_FOOTER()
172 SIMPLE_FOOTER()); 205 SIMPLE_FOOTER());
173 } 206 }
174 207
175 TEST_F(IPhotoLibraryParserTest, Albums) { 208 TEST_F(IPhotoLibraryParserTest, Albums) {
176 AddExpectedPhoto(1, "/dir/PhotoA1.jpg", "Album 1"); 209 AddExpectedPhoto(1, "/dir/PhotoA1.jpg", GetTime(kTimestampInt), "Album 1");
177 AddExpectedPhoto(2, "/dir/PhotoA2.jpg", "Album 1"); 210 AddExpectedPhoto(2, "/dir/PhotoA2.jpg", GetTime(kTimestampInt), "Album 1");
178 AddExpectedPhoto(3, "/dir/PhotoA3.jpg", "Album 2"); 211 AddExpectedPhoto(3, "/dir/PhotoA3.jpg", GetTime(kTimestampInt), "Album 2");
179 AddExpectedPhoto(4, "/dir/PhotoB1.jpg", "Album 2"); 212 AddExpectedPhoto(4, "/dir/PhotoB1.jpg", GetTime(kTimestampInt), "Album 2");
180 AddExpectedPhoto(5, "/dir/PhotoB2.jpg", "Album 3"); 213 AddExpectedPhoto(5, "/dir/PhotoB2.jpg", GetTime(kTimestampInt), "Album 3");
181 AddExpectedPhoto(6, "/dir2/PhotoB1.jpg", "Album 3"); 214 AddExpectedPhoto(6, "/dir2/PhotoB1.jpg", GetTime(kTimestampInt), "Album 3");
182 AddExpectedPhoto(7, "/dir2/PhotoB2.jpg", ""); 215 AddExpectedPhoto(7, "/dir2/PhotoB2.jpg", GetTime(kTimestampInt), "");
183 TestParser( 216 TestParser(
184 true, 217 true,
185 SIMPLE_HEADER() 218 SIMPLE_HEADER()
186 ALBUMS_HEADER() 219 ALBUMS_HEADER()
187 SIMPLE_ALBUM(10, "Album 1", 1, 2) 220 SIMPLE_ALBUM(10, "Album 1", 1, 2)
188 SIMPLE_ALBUM(11, "Album 2", 3, 4) 221 SIMPLE_ALBUM(11, "Album 2", 3, 4)
189 SIMPLE_ALBUM(11, "Album/3", 5, 6) 222 SIMPLE_ALBUM(11, "Album/3", 5, 6)
190 ALBUMS_FOOTER() 223 ALBUMS_FOOTER()
191 IMAGE_LIST_HEADER() 224 IMAGE_LIST_HEADER()
192 SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1") 225 SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1", TIMESTAMP)
193 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") 226 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2", TIMESTAMP)
194 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") 227 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3", TIMESTAMP)
195 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") 228 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4", TIMESTAMP)
196 SIMPLE_PHOTO(5, 5, "/dir/PhotoB2.jpg", "Photo 5") 229 SIMPLE_PHOTO(5, 5, "/dir/PhotoB2.jpg", "Photo 5", TIMESTAMP)
197 SIMPLE_PHOTO(6, 6, "/dir2/PhotoB1.jpg", "Photo 6") 230 SIMPLE_PHOTO(6, 6, "/dir2/PhotoB1.jpg", "Photo 6", TIMESTAMP)
198 SIMPLE_PHOTO(7, 7, "/dir2/PhotoB2.jpg", "Photo 7") 231 SIMPLE_PHOTO(7, 7, "/dir2/PhotoB2.jpg", "Photo 7", TIMESTAMP)
199 IMAGE_LIST_FOOTER() 232 IMAGE_LIST_FOOTER()
200 SIMPLE_FOOTER()); 233 SIMPLE_FOOTER());
201 } 234 }
235
236 TEST_F(IPhotoLibraryParserTest, DuplicateAlbumNames) {
237 AddExpectedPhoto(1, "/dir/PhotoA1.jpg", GetTime(kTimestampInt), "Album 1");
238 AddExpectedPhoto(2, "/dir/PhotoA2.jpg", GetTime(kTimestampInt), "Album 1");
239 AddExpectedPhoto(3, "/dir/PhotoA3.jpg", GetTime(kTimestampInt),
240 "Album 1(11)");
241 AddExpectedPhoto(4, "/dir/PhotoB1.jpg", GetTime(kTimestampInt),
242 "Album 1(11)");
243 TestParser(
244 true,
245 SIMPLE_HEADER()
246 ALBUMS_HEADER()
247 SIMPLE_ALBUM(10, "Album 1", 1, 2)
248 SIMPLE_ALBUM(11, "Album 1", 3, 4)
249 ALBUMS_FOOTER()
250 IMAGE_LIST_HEADER()
251 SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1", TIMESTAMP)
252 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2", TIMESTAMP)
253 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3", TIMESTAMP)
254 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4", TIMESTAMP)
255 IMAGE_LIST_FOOTER()
256 SIMPLE_FOOTER());
257 }
202 258
203 } // namespace 259 } // namespace
204 260
205 } // namespace iphoto 261 } // namespace iphoto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698