| 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 "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 24 matching lines...) Expand all Loading... |
| 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) \ |
| 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>ImagePath</key>" \ | 53 " <key>ModDateAsTimerInterval</key>" \ |
| 54 " <string>" path "</string>" \ | 54 " <string>386221543.0000</string>" \ |
| 55 " <key>ThumbPath</key>" \ | 55 " <key>DateAsTimerInterval</key>" \ |
| 56 " <string>" path "</string>" \ | 56 " <string>386221543.0000</string>" \ |
| 57 " <key>DateAsTimerIntervalGMT</key>" \ |
| 58 " <string>385123456.00</string>" \ |
| 59 " <key>ImagePath</key>" \ |
| 60 " <string>" path "</string>" \ |
| 61 " <key>OriginalPath</key>" \ |
| 62 " <string>/original" path "</string>" \ |
| 63 " <key>ThumbPath</key>" \ |
| 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 |
| 63 // Mismatched key/string tag at ImagePath. | 71 // Mismatched key/string tag at ImagePath. |
| 64 #define MALFORMED_PHOTO1(id, guid, path, caption) \ | 72 #define MALFORMED_PHOTO1(id, guid, path, caption) \ |
| 65 " <key>" #id "</key>" \ | 73 " <key>" #id "</key>" \ |
| 66 " <dict>" \ | 74 " <dict>" \ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 92 " <string>" path "</string>" \ | 100 " <string>" path "</string>" \ |
| 93 " </dict>" | 101 " </dict>" |
| 94 | 102 |
| 95 namespace iphoto { | 103 namespace iphoto { |
| 96 | 104 |
| 97 namespace { | 105 namespace { |
| 98 | 106 |
| 99 void ComparePhoto(const parser::Photo& a, const parser::Photo& b) { | 107 void ComparePhoto(const parser::Photo& a, const parser::Photo& b) { |
| 100 EXPECT_EQ(a.id, b.id); | 108 EXPECT_EQ(a.id, b.id); |
| 101 EXPECT_EQ(a.location.value(), b.location.value()); | 109 EXPECT_EQ(a.location.value(), b.location.value()); |
| 110 EXPECT_EQ(a.original_location.value(), b.original_location.value()); |
| 102 } | 111 } |
| 103 | 112 |
| 104 void CompareAlbum(const parser::Album& a, const parser::Album& b) { | 113 void CompareAlbum(const parser::Album& a, const parser::Album& b) { |
| 105 EXPECT_EQ(a.size(), b.size()); | 114 EXPECT_EQ(a.size(), b.size()); |
| 106 | 115 |
| 107 parser::Album::const_iterator a_it; | 116 parser::Album::const_iterator a_it; |
| 108 parser::Album::const_iterator b_it; | 117 parser::Album::const_iterator b_it; |
| 109 for (a_it = a.begin(), b_it = b.begin(); | 118 for (a_it = a.begin(), b_it = b.begin(); |
| 110 a_it != a.end() && b_it != b.end(); | 119 a_it != a.end() && b_it != b.end(); |
| 111 ++a_it, ++b_it) { | 120 ++a_it, ++b_it) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 void TestParser(bool expected_result, const std::string& xml) { | 154 void TestParser(bool expected_result, const std::string& xml) { |
| 146 IPhotoLibraryParser parser; | 155 IPhotoLibraryParser parser; |
| 147 | 156 |
| 148 EXPECT_EQ(expected_result, parser.Parse(xml)); | 157 EXPECT_EQ(expected_result, parser.Parse(xml)); |
| 149 if (!expected_result) | 158 if (!expected_result) |
| 150 return; | 159 return; |
| 151 | 160 |
| 152 CompareLibrary(expected_library_, parser.library()); | 161 CompareLibrary(expected_library_, parser.library()); |
| 153 } | 162 } |
| 154 | 163 |
| 155 void AddExpectedPhoto(uint32 id, const std::string& location, | 164 void AddExpectedPhoto(uint32 id, |
| 165 const std::string& location, |
| 156 const std::string& album) { | 166 const std::string& album) { |
| 157 parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location)); | 167 parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location), |
| 168 base::FilePath::FromUTF8Unsafe("/original" + location)); |
| 158 if (!album.empty()) | 169 if (!album.empty()) |
| 159 expected_library_.albums[album].insert(id); | 170 expected_library_.albums[album].insert(id); |
| 160 expected_library_.all_photos.insert(photo); | 171 expected_library_.all_photos.insert(photo); |
| 161 } | 172 } |
| 162 | 173 |
| 163 private: | 174 private: |
| 164 parser::Library expected_library_; | 175 parser::Library expected_library_; |
| 165 | 176 |
| 166 DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest); | 177 DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest); |
| 167 }; | 178 }; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 false, | 291 false, |
| 281 SIMPLE_HEADER() | 292 SIMPLE_HEADER() |
| 282 ALBUMS_HEADER() | 293 ALBUMS_HEADER() |
| 283 ALBUMS_FOOTER() | 294 ALBUMS_FOOTER() |
| 284 IMAGE_LIST_HEADER() | 295 IMAGE_LIST_HEADER() |
| 285 MALFORMED_PHOTO2(1, 1, "/bad.jpg", "p1") | 296 MALFORMED_PHOTO2(1, 1, "/bad.jpg", "p1") |
| 286 IMAGE_LIST_FOOTER() | 297 IMAGE_LIST_FOOTER() |
| 287 SIMPLE_FOOTER()); | 298 SIMPLE_FOOTER()); |
| 288 } | 299 } |
| 289 | 300 |
| 301 TEST_F(IPhotoLibraryParserTest, DuplicateAlbumNames) { |
| 302 AddExpectedPhoto(1, "/dir/PhotoA1.jpg", "Album 1"); |
| 303 AddExpectedPhoto(2, "/dir/PhotoA2.jpg", "Album 1"); |
| 304 AddExpectedPhoto(3, "/dir/PhotoA3.jpg", "Album 1(11)"); |
| 305 AddExpectedPhoto(4, "/dir/PhotoB1.jpg", "Album 1(11)"); |
| 306 TestParser( |
| 307 true, |
| 308 SIMPLE_HEADER() |
| 309 ALBUMS_HEADER() |
| 310 SIMPLE_ALBUM(10, "Album 1", 1, 2) |
| 311 SIMPLE_ALBUM(11, "Album 1", 3, 4) |
| 312 ALBUMS_FOOTER() |
| 313 IMAGE_LIST_HEADER() |
| 314 SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1") |
| 315 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") |
| 316 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") |
| 317 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") |
| 318 IMAGE_LIST_FOOTER() |
| 319 SIMPLE_FOOTER()); |
| 320 } |
| 321 |
| 290 } // namespace | 322 } // namespace |
| 291 | 323 |
| 292 } // namespace iphoto | 324 } // namespace iphoto |
| OLD | NEW |