Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/logging.h" | |
| 6 #include "chrome/browser/media_galleries/fileapi/itunes_library_parser.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace itunes { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 void CompareTrack(const ITunesLibraryParser::Track& a, | |
| 14 const ITunesLibraryParser::Track& b) { | |
| 15 EXPECT_EQ(a.id, b.id); | |
| 16 EXPECT_EQ(a.location, b.location); | |
| 17 } | |
| 18 | |
| 19 void CompareAlbum(const ITunesLibraryParser::Album& a, | |
| 20 const ITunesLibraryParser::Album& b) { | |
| 21 EXPECT_EQ(a.size(), b.size()); | |
| 22 | |
| 23 ITunesLibraryParser::Album::const_iterator a_it; | |
| 24 ITunesLibraryParser::Album::const_iterator b_it; | |
| 25 for (a_it = a.begin(), b_it = b.begin(); | |
| 26 a_it != a.end() && b_it != b.end(); | |
| 27 ++a_it, ++b_it) { | |
| 28 CompareTrack(*a_it, *b_it); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 void CompareAlbums(const ITunesLibraryParser::Albums& a, | |
| 33 const ITunesLibraryParser::Albums& b) { | |
| 34 EXPECT_EQ(a.size(), b.size()); | |
| 35 | |
| 36 ITunesLibraryParser::Albums::const_iterator a_it; | |
| 37 ITunesLibraryParser::Albums::const_iterator b_it; | |
| 38 for (a_it = a.begin(), b_it = b.begin(); | |
| 39 a_it != a.end() && b_it != b.end(); | |
| 40 ++a_it, ++b_it) { | |
| 41 EXPECT_EQ(a_it->first, b_it->first); | |
| 42 CompareAlbum(a_it->second, b_it->second); | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 void CompareLibrary(const ITunesLibraryParser::Library& a, | |
| 47 const ITunesLibraryParser::Library& b) { | |
| 48 EXPECT_EQ(a.size(), b.size()); | |
| 49 | |
| 50 ITunesLibraryParser::Library::const_iterator a_it; | |
| 51 ITunesLibraryParser::Library::const_iterator b_it; | |
| 52 for (a_it = a.begin(), b_it = b.begin(); | |
| 53 a_it != a.end() && b_it != b.end(); | |
| 54 ++a_it, ++b_it) { | |
| 55 EXPECT_EQ(a_it->first, b_it->first); | |
| 56 CompareAlbums(a_it->second, b_it->second); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 class ITunesLibraryParserTest : public testing::Test { | |
| 61 public: | |
| 62 ITunesLibraryParserTest() {} | |
| 63 | |
| 64 void TestParser(bool expected_result, const std::string& xml) { | |
| 65 ITunesLibraryParser parser; | |
| 66 | |
| 67 EXPECT_EQ(expected_result, parser.Parse(xml)); | |
| 68 if (!expected_result) | |
| 69 return; | |
| 70 | |
| 71 CompareLibrary(expected_tracks_, parser.library()); | |
| 72 } | |
| 73 | |
| 74 void AddExpectedTrack(uint32_t id, const std::string& location, | |
| 75 const std::string& artist, const std::string& album) { | |
| 76 ITunesLibraryParser::Track track(id, | |
| 77 base::FilePath::FromUTF8Unsafe(location)); | |
| 78 expected_tracks_[artist][album].insert(track); | |
| 79 } | |
| 80 | |
| 81 private: | |
| 82 ITunesLibraryParser::Library expected_tracks_; | |
|
Lei Zhang
2013/05/31 04:34:35
expected_library_ ?
vandebo (ex-Chrome)
2013/05/31 21:41:12
Done.
| |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(ITunesLibraryParserTest); | |
| 85 }; | |
| 86 | |
| 87 TEST_F(ITunesLibraryParserTest, EmptyLibrary) { | |
| 88 TestParser(false, ""); | |
| 89 } | |
| 90 | |
| 91 TEST_F(ITunesLibraryParserTest, MinimalXML) { | |
| 92 AddExpectedTrack(1, "C:/dir/Song With Space.mp3", "Artist A", "Album A"); | |
| 93 TestParser( | |
| 94 true, | |
| 95 "<plist>" | |
| 96 " <dict>" | |
| 97 " <key>Tracks</key>" | |
| 98 " <dict>" | |
| 99 " <key>1</key>" | |
| 100 " <dict>" | |
| 101 " <key>Track ID</key><integer>1</integer>" | |
| 102 " <key>Location</key>" | |
| 103 "<string>file://localhost/C:/dir/Song%20With%20Space.mp3</string>" | |
| 104 " <key>Album Artist</key><string>Artist A</string>" | |
| 105 " <key>Album</key><string>Album A</string>" | |
| 106 " </dict>" | |
| 107 " </dict>" | |
| 108 " </dict>" | |
| 109 "</plist>"); | |
| 110 } | |
| 111 | |
| 112 TEST_F(ITunesLibraryParserTest, MultibleSongs) { | |
| 113 AddExpectedTrack(1, "C:/dir/Song With Space.mp3", "Artist A", "Album A"); | |
| 114 AddExpectedTrack(2, "C:/dir/SongA2.mp3", "Artist A", "Album A"); | |
| 115 AddExpectedTrack(3, "C:/dir/SongA3.mp3", "Artist A", "Album A"); | |
| 116 AddExpectedTrack(4, "C:/dir/SongB1.mp3", "Artist A", "Album B"); | |
| 117 AddExpectedTrack(5, "C:/dir/SongB2.mp3", "Artist A", "Album B"); | |
| 118 AddExpectedTrack(6, "C:/dir2/SongB1.mp3", "Artist B", "Album B"); | |
| 119 AddExpectedTrack(7, "C:/dir2/SongB2.mp3", "Artist B", "Album B"); | |
| 120 TestParser( | |
| 121 true, | |
| 122 "<plist>" | |
| 123 " <dict>" | |
| 124 " <key>Tracks</key>" | |
| 125 " <dict>" | |
| 126 " <key>1</key>" | |
| 127 " <dict>" | |
| 128 " <key>Track ID</key><integer>1</integer>" | |
| 129 " <key>Location</key>" | |
| 130 "<string>file://localhost/C:/dir/Song%20With%20Space.mp3</string>" | |
| 131 " <key>Album Artist</key><string>Artist A</string>" | |
| 132 " <key>Album</key><string>Album A</string>" | |
| 133 " </dict>" | |
| 134 " <key>2</key>" | |
| 135 " <dict>" | |
| 136 " <key>Track ID</key><integer>2</integer>" | |
| 137 " <key>Location</key>" | |
| 138 " <string>file://localhost/C:/dir/SongA2.mp3</string>" | |
| 139 " <key>Album Artist</key><string>Artist A</string>" | |
| 140 " <key>Album</key><string>Album A</string>" | |
| 141 " </dict>" | |
| 142 " <key>3</key>" | |
| 143 " <dict>" | |
| 144 " <key>Track ID</key><integer>3</integer>" | |
| 145 " <key>Location</key>" | |
| 146 " <string>file://localhost/C:/dir/SongA3.mp3</string>" | |
| 147 " <key>Album Artist</key><string>Artist A</string>" | |
| 148 " <key>Album</key><string>Album A</string>" | |
| 149 " </dict>" | |
| 150 " <key>4</key>" | |
| 151 " <dict>" | |
| 152 " <key>Track ID</key><integer>4</integer>" | |
| 153 " <key>Location</key>" | |
| 154 " <string>file://localhost/C:/dir/SongB1.mp3</string>" | |
| 155 " <key>Album Artist</key><string>Artist A</string>" | |
| 156 " <key>Album</key><string>Album B</string>" | |
| 157 " </dict>" | |
| 158 " <key>5</key>" | |
| 159 " <dict>" | |
| 160 " <key>Track ID</key><integer>5</integer>" | |
| 161 " <key>Location</key>" | |
| 162 " <string>file://localhost/C:/dir/SongB2.mp3</string>" | |
| 163 " <key>Album Artist</key><string>Artist A</string>" | |
| 164 " <key>Album</key><string>Album B</string>" | |
| 165 " </dict>" | |
| 166 " <key>6</key>" | |
| 167 " <dict>" | |
| 168 " <key>Track ID</key><integer>6</integer>" | |
| 169 " <key>Location</key>" | |
| 170 " <string>file://localhost/C:/dir2/SongB1.mp3</string>" | |
| 171 " <key>Album Artist</key><string>Artist B</string>" | |
| 172 " <key>Album</key><string>Album B</string>" | |
| 173 " </dict>" | |
| 174 " <key>7</key>" | |
| 175 " <dict>" | |
| 176 " <key>Track ID</key><integer>7</integer>" | |
| 177 " <key>Location</key>" | |
| 178 " <string>file://localhost/C:/dir2/SongB2.mp3</string>" | |
| 179 " <key>Album Artist</key><string>Artist B</string>" | |
| 180 " <key>Album</key><string>Album B</string>" | |
| 181 " </dict>" | |
| 182 " </dict>" | |
| 183 " </dict>" | |
| 184 "</plist>"); | |
| 185 } | |
| 186 | |
| 187 } // namespace | |
| 188 | |
| 189 } // namespace itunes | |
| OLD | NEW |