| 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 |
| 71 |
| 63 namespace iphoto { | 72 namespace iphoto { |
| 64 | 73 |
| 65 namespace { | 74 namespace { |
| 66 | 75 |
| 67 void ComparePhoto(const parser::Photo& a, const parser::Photo& b) { | 76 void ComparePhoto(const parser::Photo& a, const parser::Photo& b) { |
| 68 EXPECT_EQ(a.id, b.id); | 77 EXPECT_EQ(a.id, b.id); |
| 69 EXPECT_EQ(a.location.value(), b.location.value()); | 78 EXPECT_EQ(a.location.value(), b.location.value()); |
| 79 EXPECT_EQ(a.original_location.value(), b.original_location.value()); |
| 70 } | 80 } |
| 71 | 81 |
| 72 void CompareAlbum(const parser::Album& a, const parser::Album& b) { | 82 void CompareAlbum(const parser::Album& a, const parser::Album& b) { |
| 73 EXPECT_EQ(a.size(), b.size()); | 83 EXPECT_EQ(a.size(), b.size()); |
| 74 | 84 |
| 75 parser::Album::const_iterator a_it; | 85 parser::Album::const_iterator a_it; |
| 76 parser::Album::const_iterator b_it; | 86 parser::Album::const_iterator b_it; |
| 77 for (a_it = a.begin(), b_it = b.begin(); | 87 for (a_it = a.begin(), b_it = b.begin(); |
| 78 a_it != a.end() && b_it != b.end(); | 88 a_it != a.end() && b_it != b.end(); |
| 79 ++a_it, ++b_it) { | 89 ++a_it, ++b_it) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 void TestParser(bool expected_result, const std::string& xml) { | 123 void TestParser(bool expected_result, const std::string& xml) { |
| 114 IPhotoLibraryParser parser; | 124 IPhotoLibraryParser parser; |
| 115 | 125 |
| 116 EXPECT_EQ(expected_result, parser.Parse(xml)); | 126 EXPECT_EQ(expected_result, parser.Parse(xml)); |
| 117 if (!expected_result) | 127 if (!expected_result) |
| 118 return; | 128 return; |
| 119 | 129 |
| 120 CompareLibrary(expected_library_, parser.library()); | 130 CompareLibrary(expected_library_, parser.library()); |
| 121 } | 131 } |
| 122 | 132 |
| 123 void AddExpectedPhoto(uint32 id, const std::string& location, | 133 void AddExpectedPhoto(uint32 id, |
| 134 const std::string& location, |
| 124 const std::string& album) { | 135 const std::string& album) { |
| 125 parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location)); | 136 parser::Photo photo(id, base::FilePath::FromUTF8Unsafe(location), |
| 137 base::FilePath::FromUTF8Unsafe("/original" + location)); |
| 126 if (!album.empty()) | 138 if (!album.empty()) |
| 127 expected_library_.albums[album].insert(id); | 139 expected_library_.albums[album].insert(id); |
| 128 expected_library_.all_photos.insert(photo); | 140 expected_library_.all_photos.insert(photo); |
| 129 } | 141 } |
| 130 | 142 |
| 131 private: | 143 private: |
| 132 parser::Library expected_library_; | 144 parser::Library expected_library_; |
| 133 | 145 |
| 134 DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest); | 146 DISALLOW_COPY_AND_ASSIGN(IPhotoLibraryParserTest); |
| 135 }; | 147 }; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") | 205 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") |
| 194 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") | 206 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") |
| 195 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") | 207 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") |
| 196 SIMPLE_PHOTO(5, 5, "/dir/PhotoB2.jpg", "Photo 5") | 208 SIMPLE_PHOTO(5, 5, "/dir/PhotoB2.jpg", "Photo 5") |
| 197 SIMPLE_PHOTO(6, 6, "/dir2/PhotoB1.jpg", "Photo 6") | 209 SIMPLE_PHOTO(6, 6, "/dir2/PhotoB1.jpg", "Photo 6") |
| 198 SIMPLE_PHOTO(7, 7, "/dir2/PhotoB2.jpg", "Photo 7") | 210 SIMPLE_PHOTO(7, 7, "/dir2/PhotoB2.jpg", "Photo 7") |
| 199 IMAGE_LIST_FOOTER() | 211 IMAGE_LIST_FOOTER() |
| 200 SIMPLE_FOOTER()); | 212 SIMPLE_FOOTER()); |
| 201 } | 213 } |
| 202 | 214 |
| 215 TEST_F(IPhotoLibraryParserTest, DuplicateAlbumNames) { |
| 216 AddExpectedPhoto(1, "/dir/PhotoA1.jpg", "Album 1"); |
| 217 AddExpectedPhoto(2, "/dir/PhotoA2.jpg", "Album 1"); |
| 218 AddExpectedPhoto(3, "/dir/PhotoA3.jpg", "Album 1(11)"); |
| 219 AddExpectedPhoto(4, "/dir/PhotoB1.jpg", "Album 1(11)"); |
| 220 TestParser( |
| 221 true, |
| 222 SIMPLE_HEADER() |
| 223 ALBUMS_HEADER() |
| 224 SIMPLE_ALBUM(10, "Album 1", 1, 2) |
| 225 SIMPLE_ALBUM(11, "Album 1", 3, 4) |
| 226 ALBUMS_FOOTER() |
| 227 IMAGE_LIST_HEADER() |
| 228 SIMPLE_PHOTO(1, 1, "/dir/PhotoA1.jpg", "Photo 1") |
| 229 SIMPLE_PHOTO(2, 2, "/dir/PhotoA2.jpg", "Photo 2") |
| 230 SIMPLE_PHOTO(3, 3, "/dir/PhotoA3.jpg", "Photo 3") |
| 231 SIMPLE_PHOTO(4, 4, "/dir/PhotoB1.jpg", "Photo 4") |
| 232 IMAGE_LIST_FOOTER() |
| 233 SIMPLE_FOOTER()); |
| 234 } |
| 235 |
| 203 } // namespace | 236 } // namespace |
| 204 | 237 |
| 205 } // namespace iphoto | 238 } // namespace iphoto |
| OLD | NEW |