forked from clementine-player/Clementine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcueparser_test.cpp
317 lines (252 loc) · 11.3 KB
/
cueparser_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gmock/gmock-matchers.h"
#include "gtest/gtest.h"
#include "test_utils.h"
#include "core/timeconstants.h"
#include "playlistparsers/cueparser.h"
#include <QUrl>
class CueParserTest : public ::testing::Test {
protected:
CueParserTest()
: parser_(nullptr) {
}
// We believe CUE - all songs with proper CUE entries should be valid.
bool validate_songs(SongList songs) {
foreach(const Song& song, songs) {
if(!song.is_valid()) {
return false;
}
}
return true;
}
qlonglong to_nanosec(int minutes, int seconds, int frames) {
return (minutes * 60 * 75 + seconds * 75 + frames) * kNsecPerSec / 75;
}
CueParser parser_;
};
TEST_F(CueParserTest, ParsesASong) {
QFile file(":testdata/onesong.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "CUEPATH", QDir(""));
// one song
ASSERT_EQ(1, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
ASSERT_EQ("Un soffio caldo", first_song.title());
ASSERT_EQ("Zucchero", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ("", first_song.album());
ASSERT_EQ(to_nanosec(0, 1, 15), first_song.beginning_nanosec());
ASSERT_EQ(1, first_song.track());
ASSERT_EQ("CUEPATH", first_song.cue_path());
validate_songs(song_list);
}
TEST_F(CueParserTest, ParsesTwoSongs) {
QFile file(":testdata/twosongs.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "", QDir(""));
// two songs
ASSERT_EQ(2, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
Song second_song = song_list.at(1);
ASSERT_EQ("Un soffio caldo", first_song.title());
ASSERT_EQ("Chocabeck", first_song.album());
ASSERT_EQ("Zucchero himself", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(1, first_song.track());
ASSERT_EQ("Somewon Else's Tears", second_song.title());
ASSERT_EQ("Chocabeck", second_song.album());
ASSERT_EQ("Zucchero himself", second_song.artist());
ASSERT_EQ("Zucchero himself", second_song.albumartist());
ASSERT_EQ(to_nanosec(5, 3, 68), second_song.beginning_nanosec());
ASSERT_EQ(2, second_song.track());
validate_songs(song_list);
}
TEST_F(CueParserTest, SkipsBrokenSongs) {
QFile file(":testdata/brokensong.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "", QDir(""));
// two songs (the broken one is not in the list)
ASSERT_EQ(2, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
Song second_song = song_list.at(1);
ASSERT_EQ("Un soffio caldo", first_song.title());
ASSERT_EQ("Chocabeck", first_song.album());
ASSERT_EQ("Zucchero himself", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
// includes the broken song too; this entry will span from it's
// INDEX (beginning) to the end of the next correct song
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(1, first_song.track());
ASSERT_EQ("Somewon Else's Tears", second_song.title());
ASSERT_EQ("Chocabeck", second_song.album());
ASSERT_EQ("Zucchero himself", second_song.artist());
ASSERT_EQ("Zucchero himself", second_song.albumartist());
ASSERT_EQ(to_nanosec(5, 0, 0), second_song.beginning_nanosec());
ASSERT_EQ(2, second_song.track());
validate_songs(song_list);
}
TEST_F(CueParserTest, UsesAllMetadataInformation) {
QFile file(":testdata/fullmetadata.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "", QDir(""));
// two songs
ASSERT_EQ(2, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
Song second_song = song_list.at(1);
ASSERT_TRUE(first_song.url().toString().endsWith("a_file.mp3"));
ASSERT_EQ("Un soffio caldo", first_song.title());
ASSERT_EQ("Album", first_song.album());
ASSERT_EQ("Zucchero", first_song.artist());
ASSERT_EQ("Zucchero himself", first_song.albumartist());
ASSERT_EQ("Some guy", first_song.composer());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(1, first_song.track());
ASSERT_TRUE(second_song.url().toString().endsWith("a_file.mp3"));
ASSERT_EQ("Hey you!", second_song.title());
ASSERT_EQ("Album", second_song.album());
ASSERT_EQ("Zucchero himself", second_song.artist());
ASSERT_EQ("Zucchero himself", second_song.albumartist());
ASSERT_EQ("Some other guy", second_song.composer());
ASSERT_EQ(to_nanosec(0, 2, 0), second_song.beginning_nanosec());
ASSERT_EQ(2, second_song.track());
validate_songs(song_list);
}
TEST_F(CueParserTest, AcceptsMultipleFileBasedCues) {
QFile file(":testdata/manyfiles.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "CUEPATH", QDir(""));
// five songs
ASSERT_EQ(5, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
Song second_song = song_list.at(1);
Song third_song = song_list.at(2);
Song fourth_song = song_list.at(3);
Song fifth_song = song_list.at(4);
ASSERT_TRUE(first_song.url().toString().endsWith("files/longer_one.mp3"));
ASSERT_EQ("A1Song1", first_song.title());
ASSERT_EQ("Artist One Album", first_song.album());
ASSERT_EQ("Artist One", first_song.artist());
ASSERT_EQ("Artist One", first_song.albumartist());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(-1, first_song.track());
ASSERT_EQ("CUEPATH", first_song.cue_path());
ASSERT_TRUE(second_song.url().toString().endsWith("files/longer_one.mp3"));
ASSERT_EQ("A1Song2", second_song.title());
ASSERT_EQ("Artist One Album", second_song.album());
ASSERT_EQ("Artist One", second_song.artist());
ASSERT_EQ("Artist One", second_song.albumartist());
ASSERT_EQ(to_nanosec(5, 3, 68), second_song.beginning_nanosec());
ASSERT_EQ(-1, second_song.track());
ASSERT_TRUE(third_song.url().toString().endsWith("files/longer_two_p1.mp3"));
ASSERT_EQ("A2P1Song1", third_song.title());
ASSERT_EQ("Artist Two Album", third_song.album());
ASSERT_EQ("Artist X", third_song.artist());
ASSERT_EQ("Artist Two", third_song.albumartist());
ASSERT_EQ(to_nanosec(0, 0, 12), third_song.beginning_nanosec());
ASSERT_EQ(fourth_song.beginning_nanosec() - third_song.beginning_nanosec(), third_song.length_nanosec());
ASSERT_EQ(-1, third_song.track());
ASSERT_EQ("CUEPATH", third_song.cue_path());
ASSERT_TRUE(fourth_song.url().toString().endsWith("files/longer_two_p1.mp3"));
ASSERT_EQ("A2P1Song2", fourth_song.title());
ASSERT_EQ("Artist Two Album", fourth_song.album());
ASSERT_EQ("Artist Two", fourth_song.artist());
ASSERT_EQ("Artist Two", fourth_song.albumartist());
ASSERT_EQ(to_nanosec(4, 0, 13), fourth_song.beginning_nanosec());
ASSERT_EQ(-1, fourth_song.track());
ASSERT_TRUE(fifth_song.url().toString().endsWith("files/longer_two_p2.mp3"));
ASSERT_EQ("A2P2Song1", fifth_song.title());
ASSERT_EQ("Artist Two Album", fifth_song.album());
ASSERT_EQ("Artist Two", fifth_song.artist());
ASSERT_EQ("Artist Two", fifth_song.albumartist());
ASSERT_EQ(to_nanosec(0, 1, 0), fifth_song.beginning_nanosec());
ASSERT_EQ(-1, fifth_song.track());
ASSERT_EQ("CUEPATH", fifth_song.cue_path());
validate_songs(song_list);
}
TEST_F(CueParserTest, SkipsBrokenSongsInMultipleFileBasedCues) {
QFile file(":testdata/manyfilesbroken.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "", QDir(""));
// four songs
ASSERT_EQ(4, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
Song second_song = song_list.at(1);
Song third_song = song_list.at(2);
Song fourth_song = song_list.at(3);
// A* - broken song in the middle
ASSERT_TRUE(first_song.url().toString().endsWith("file1.mp3"));
ASSERT_EQ("Artist One", first_song.artist());
ASSERT_EQ("Artist One Album", first_song.album());
ASSERT_EQ("A1", first_song.title());
ASSERT_EQ(to_nanosec(0, 1, 15), first_song.beginning_nanosec());
ASSERT_EQ(second_song.beginning_nanosec() - first_song.beginning_nanosec(), first_song.length_nanosec());
ASSERT_EQ(-1, first_song.track());
ASSERT_TRUE(second_song.url().toString().endsWith("file1.mp3"));
ASSERT_EQ("Artist One", second_song.artist());
ASSERT_EQ("Artist One Album", second_song.album());
ASSERT_EQ("A3", second_song.title());
ASSERT_EQ(to_nanosec(1, 0, 16), second_song.beginning_nanosec());
ASSERT_EQ(-1, second_song.track());
// all B* songs are broken
// C* - broken song at the end
ASSERT_TRUE(third_song.url().toString().endsWith("file3.mp3"));
ASSERT_EQ("Artist Three", third_song.artist());
ASSERT_EQ("Artist Three Album", third_song.album());
ASSERT_EQ("C1", third_song.title());
ASSERT_EQ(to_nanosec(0, 1, 0), third_song.beginning_nanosec());
ASSERT_EQ(-1, third_song.track());
// D* - broken song at the beginning
ASSERT_TRUE(fourth_song.url().toString().endsWith("file4.mp3"));
ASSERT_EQ("Artist Four", fourth_song.artist());
ASSERT_EQ("Artist Four Album", fourth_song.album());
ASSERT_EQ("D2", fourth_song.title());
ASSERT_EQ(to_nanosec(15, 55, 66), fourth_song.beginning_nanosec());
ASSERT_EQ(-1, fourth_song.track());
validate_songs(song_list);
}
TEST_F(CueParserTest, SkipsDataFiles) {
QFile file(":testdata/withdatafiles.cue");
file.open(QIODevice::ReadOnly);
SongList song_list = parser_.Load(&file, "", QDir(""));
// two songs
ASSERT_EQ(2, song_list.size());
// with the specified metadata
Song first_song = song_list.at(0);
Song second_song = song_list.at(1);
ASSERT_TRUE(first_song.url().toString().endsWith("file1.mp3"));
ASSERT_EQ("Artist One", first_song.artist());
ASSERT_EQ("Artist One Album", first_song.album());
ASSERT_EQ("A1", first_song.title());
ASSERT_EQ(to_nanosec(0, 1, 0), first_song.beginning_nanosec());
ASSERT_EQ(-1, first_song.track());
ASSERT_TRUE(second_song.url().toString().endsWith("file4.mp3"));
ASSERT_EQ("Artist Four", second_song.artist());
ASSERT_EQ("Artist Four Album", second_song.album());
ASSERT_EQ("D1", second_song.title());
ASSERT_EQ(to_nanosec(1, 1, 0), second_song.beginning_nanosec());
ASSERT_EQ(-1, second_song.track());
validate_songs(song_list);
}