Index: chrome/browser/media_galleries/fileapi/itunes_library_parser_unittest.cc |
diff --git a/chrome/browser/media_galleries/fileapi/itunes_library_parser_unittest.cc b/chrome/browser/media_galleries/fileapi/itunes_library_parser_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..19110bb2e99f2ef58f1b866b9c9d8384f08031a1 |
--- /dev/null |
+++ b/chrome/browser/media_galleries/fileapi/itunes_library_parser_unittest.cc |
@@ -0,0 +1,189 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/logging.h" |
+#include "chrome/browser/media_galleries/fileapi/itunes_library_parser.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace itunes { |
+ |
+namespace { |
+ |
+void CompareTrack(const ITunesLibraryParser::Track& a, |
+ const ITunesLibraryParser::Track& b) { |
+ EXPECT_EQ(a.id, b.id); |
+ EXPECT_EQ(a.location, b.location); |
+} |
+ |
+void CompareAlbum(const ITunesLibraryParser::Album& a, |
+ const ITunesLibraryParser::Album& b) { |
+ EXPECT_EQ(a.size(), b.size()); |
+ |
+ ITunesLibraryParser::Album::const_iterator a_it; |
+ ITunesLibraryParser::Album::const_iterator b_it; |
+ for (a_it = a.begin(), b_it = b.begin(); |
+ a_it != a.end() && b_it != b.end(); |
+ ++a_it, ++b_it) { |
+ CompareTrack(*a_it, *b_it); |
+ } |
+} |
+ |
+void CompareAlbums(const ITunesLibraryParser::Albums& a, |
+ const ITunesLibraryParser::Albums& b) { |
+ EXPECT_EQ(a.size(), b.size()); |
+ |
+ ITunesLibraryParser::Albums::const_iterator a_it; |
+ ITunesLibraryParser::Albums::const_iterator b_it; |
+ for (a_it = a.begin(), b_it = b.begin(); |
+ a_it != a.end() && b_it != b.end(); |
+ ++a_it, ++b_it) { |
+ EXPECT_EQ(a_it->first, b_it->first); |
+ CompareAlbum(a_it->second, b_it->second); |
+ } |
+} |
+ |
+void CompareLibrary(const ITunesLibraryParser::Library& a, |
+ const ITunesLibraryParser::Library& b) { |
+ EXPECT_EQ(a.size(), b.size()); |
+ |
+ ITunesLibraryParser::Library::const_iterator a_it; |
+ ITunesLibraryParser::Library::const_iterator b_it; |
+ for (a_it = a.begin(), b_it = b.begin(); |
+ a_it != a.end() && b_it != b.end(); |
+ ++a_it, ++b_it) { |
+ EXPECT_EQ(a_it->first, b_it->first); |
+ CompareAlbums(a_it->second, b_it->second); |
+ } |
+} |
+ |
+class ITunesLibraryParserTest : public testing::Test { |
+ public: |
+ ITunesLibraryParserTest() {} |
+ |
+ void TestParser(bool expected_result, const std::string& xml) { |
+ ITunesLibraryParser parser; |
+ |
+ EXPECT_EQ(expected_result, parser.Parse(xml)); |
+ if (!expected_result) |
+ return; |
+ |
+ CompareLibrary(expected_tracks_, parser.library()); |
+ } |
+ |
+ void AddExpectedTrack(uint32_t id, const std::string& location, |
+ const std::string& artist, const std::string& album) { |
+ ITunesLibraryParser::Track track(id, |
+ base::FilePath::FromUTF8Unsafe(location)); |
+ expected_tracks_[artist][album].insert(track); |
+ } |
+ |
+ private: |
+ ITunesLibraryParser::Library expected_tracks_; |
Lei Zhang
2013/05/31 04:34:35
expected_library_ ?
vandebo (ex-Chrome)
2013/05/31 21:41:12
Done.
|
+ |
+ DISALLOW_COPY_AND_ASSIGN(ITunesLibraryParserTest); |
+}; |
+ |
+TEST_F(ITunesLibraryParserTest, EmptyLibrary) { |
+ TestParser(false, ""); |
+} |
+ |
+TEST_F(ITunesLibraryParserTest, MinimalXML) { |
+ AddExpectedTrack(1, "C:/dir/Song With Space.mp3", "Artist A", "Album A"); |
+ TestParser( |
+ true, |
+ "<plist>" |
+ " <dict>" |
+ " <key>Tracks</key>" |
+ " <dict>" |
+ " <key>1</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>1</integer>" |
+ " <key>Location</key>" |
+ "<string>file://localhost/C:/dir/Song%20With%20Space.mp3</string>" |
+ " <key>Album Artist</key><string>Artist A</string>" |
+ " <key>Album</key><string>Album A</string>" |
+ " </dict>" |
+ " </dict>" |
+ " </dict>" |
+ "</plist>"); |
+} |
+ |
+TEST_F(ITunesLibraryParserTest, MultibleSongs) { |
+ AddExpectedTrack(1, "C:/dir/Song With Space.mp3", "Artist A", "Album A"); |
+ AddExpectedTrack(2, "C:/dir/SongA2.mp3", "Artist A", "Album A"); |
+ AddExpectedTrack(3, "C:/dir/SongA3.mp3", "Artist A", "Album A"); |
+ AddExpectedTrack(4, "C:/dir/SongB1.mp3", "Artist A", "Album B"); |
+ AddExpectedTrack(5, "C:/dir/SongB2.mp3", "Artist A", "Album B"); |
+ AddExpectedTrack(6, "C:/dir2/SongB1.mp3", "Artist B", "Album B"); |
+ AddExpectedTrack(7, "C:/dir2/SongB2.mp3", "Artist B", "Album B"); |
+ TestParser( |
+ true, |
+ "<plist>" |
+ " <dict>" |
+ " <key>Tracks</key>" |
+ " <dict>" |
+ " <key>1</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>1</integer>" |
+ " <key>Location</key>" |
+ "<string>file://localhost/C:/dir/Song%20With%20Space.mp3</string>" |
+ " <key>Album Artist</key><string>Artist A</string>" |
+ " <key>Album</key><string>Album A</string>" |
+ " </dict>" |
+ " <key>2</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>2</integer>" |
+ " <key>Location</key>" |
+ " <string>file://localhost/C:/dir/SongA2.mp3</string>" |
+ " <key>Album Artist</key><string>Artist A</string>" |
+ " <key>Album</key><string>Album A</string>" |
+ " </dict>" |
+ " <key>3</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>3</integer>" |
+ " <key>Location</key>" |
+ " <string>file://localhost/C:/dir/SongA3.mp3</string>" |
+ " <key>Album Artist</key><string>Artist A</string>" |
+ " <key>Album</key><string>Album A</string>" |
+ " </dict>" |
+ " <key>4</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>4</integer>" |
+ " <key>Location</key>" |
+ " <string>file://localhost/C:/dir/SongB1.mp3</string>" |
+ " <key>Album Artist</key><string>Artist A</string>" |
+ " <key>Album</key><string>Album B</string>" |
+ " </dict>" |
+ " <key>5</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>5</integer>" |
+ " <key>Location</key>" |
+ " <string>file://localhost/C:/dir/SongB2.mp3</string>" |
+ " <key>Album Artist</key><string>Artist A</string>" |
+ " <key>Album</key><string>Album B</string>" |
+ " </dict>" |
+ " <key>6</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>6</integer>" |
+ " <key>Location</key>" |
+ " <string>file://localhost/C:/dir2/SongB1.mp3</string>" |
+ " <key>Album Artist</key><string>Artist B</string>" |
+ " <key>Album</key><string>Album B</string>" |
+ " </dict>" |
+ " <key>7</key>" |
+ " <dict>" |
+ " <key>Track ID</key><integer>7</integer>" |
+ " <key>Location</key>" |
+ " <string>file://localhost/C:/dir2/SongB2.mp3</string>" |
+ " <key>Album Artist</key><string>Artist B</string>" |
+ " <key>Album</key><string>Album B</string>" |
+ " </dict>" |
+ " </dict>" |
+ " </dict>" |
+ "</plist>"); |
+} |
+ |
+} // namespace |
+ |
+} // namespace itunes |