1 /* This file is part of Clementine.
2 Copyright 2010, David Sansome <me@davidsansome.com>
3
4 Clementine is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 Clementine is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Clementine. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "test_utils.h"
19 #include "gmock/gmock-matchers.h"
20 #include "gtest/gtest.h"
21
22 #include "playlistparsers/asxiniparser.h"
23 #include "playlistparsers/playlistparser.h"
24
25 #include <QBuffer>
26 #include <QUrl>
27
28 class AsxIniParserTest : public ::testing::Test {
29 protected:
AsxIniParserTest()30 AsxIniParserTest() : parser_(nullptr) {}
31
32 AsxIniParser parser_;
33 };
34
TEST_F(AsxIniParserTest,ParsesBasicTrackList)35 TEST_F(AsxIniParserTest, ParsesBasicTrackList) {
36 QFile file(":/testdata/test.asxini");
37 file.open(QIODevice::ReadOnly);
38
39 SongList songs = parser_.Load(&file, "", QDir());
40 ASSERT_EQ(2, songs.length());
41 EXPECT_EQ(QUrl("http://195.245.168.21/antena3?MSWMExt=.asf"), songs[0].url());
42 EXPECT_EQ(QUrl("http://195.245.168.21:80/antena3?MSWMExt=.asf"), songs[1].url());
43 EXPECT_TRUE(songs[0].is_valid());
44 EXPECT_TRUE(songs[1].is_valid());
45 }
46
TEST_F(AsxIniParserTest,Magic)47 TEST_F(AsxIniParserTest, Magic) {
48 QFile file(":/testdata/test.asxini");
49 file.open(QIODevice::ReadOnly);
50
51 EXPECT_TRUE(parser_.TryMagic(file.read(PlaylistParser::kMagicSize)));
52 }
53
TEST_F(AsxIniParserTest,WritesBasicTrackList)54 TEST_F(AsxIniParserTest, WritesBasicTrackList) {
55 QByteArray data;
56 QBuffer buffer(&data);
57 buffer.open(QIODevice::WriteOnly);
58
59 Song song;
60 song.set_url(QUrl("http://www.example.com/foo.mp3"));
61
62 SongList songs;
63 songs << song;
64
65 parser_.Save(songs, &buffer);
66 EXPECT_EQ("[Reference]\nRef1=http://www.example.com/foo.mp3\n", QString(data));
67 }
68