forked from DeaDBeeF-Player/deadbeef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCuesheetTests.cpp
160 lines (117 loc) · 4.7 KB
/
CuesheetTests.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
/*
DeaDBeeF -- the music player
Copyright (C) 2009-2018 Oleksiy Yakovenko and other contributors
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "conf.h"
#include "logger.h"
#include "plmeta.h"
#include <deadbeef/common.h>
#include <gtest/gtest.h>
class CuesheetTests: public ::testing::Test {
protected:
void SetUp() override {
ddb_logger_init ();
conf_init ();
conf_enable_saving (0);
}
void TearDown() override {
conf_free();
ddb_logger_free();
}
};
TEST_F(CuesheetTests, testCueWithoutTitles) {
const char cue[] =
"FILE \"file.wav\" WAVE\n"
"TRACK 01 AUDIO\n"
"INDEX 01 00:00:00\n"
"TRACK 02 AUDIO\n"
"INDEX 01 05:50:65\n"
"TRACK 03 AUDIO\n"
"INDEX 01 09:47:50\n";
playlist_t *plt = plt_alloc("test");
playItem_t *it = pl_item_alloc_init ("testfile.flac", "stdflac");
pl_add_meta (it, "cuesheet", cue);
plt_process_cue(plt, NULL, it, 60*10*44100, 44100);
int cnt = plt_get_item_count(plt, PL_MAIN);
EXPECT_TRUE(cnt == 3);
plt_free (plt);
}
TEST_F(CuesheetTests, test_BogusEmbeddedImageCueInSingleTrack_ReturnsSingleTrackWithCorrectMeta) {
playlist_t *plt = plt_alloc("test");
char path[PATH_MAX];
snprintf (path, sizeof (path), "%s/TestData/bogus_emb_cue.mp3", dbplugindir);
playItem_t *it = plt_insert_file2(0, plt, NULL, path, NULL, NULL, NULL);
EXPECT_NE(it, nullptr);
EXPECT_EQ(plt_get_item_count(plt, PL_MAIN), 1);
EXPECT_EQ(strcmp (pl_find_meta (it, "title"), "TrackTitle2"), 0);
EXPECT_EQ(strcmp (pl_find_meta (it, "track"), "2"), 0);
plt_free (plt);
}
TEST_F(CuesheetTests, test_ImageAndCue_Adds2TracksWithCorrectTitles) {
playlist_t *plt = plt_alloc("test");
char path[PATH_MAX];
snprintf (path, sizeof (path), "%s/TestData/image+cue", dbplugindir);
plt_insert_dir2(0, plt, NULL, path, NULL, NULL, NULL);
EXPECT_EQ(plt_get_item_count(plt, PL_MAIN), 2);
EXPECT_EQ(strcmp (pl_find_meta (plt->head[PL_MAIN], "title"), "Test Track 01"), 0);
EXPECT_EQ(strcmp (pl_find_meta (plt->head[PL_MAIN]->next[PL_MAIN], "title"), "Test Track 02"), 0);
plt_free (plt);
}
TEST_F(CuesheetTests, test_CueWithTrackComposer_SetsCueComposerForOneTrack) {
const char cue[] =
"FILE \"file.wav\" WAVE\n"
"TRACK 01 AUDIO\n"
"REM COMPOSER \"TEST_COMPOSER\"\n"
"INDEX 01 00:00:00\n"
"TRACK 02 AUDIO\n"
"INDEX 01 00:01:00\n";
playlist_t *plt = plt_alloc("test");
playItem_t *it = pl_item_alloc_init ("testfile.flac", "stdflac");
pl_add_meta (it, "cuesheet", cue);
plt_process_cue(plt, NULL, it, 60*10*44100, 44100);
int cnt = plt_get_item_count(plt, PL_MAIN);
EXPECT_EQ(cnt, 2);
playItem_t *cueItem = plt_get_first(plt, PL_MAIN);
const char *composer = pl_find_meta(cueItem, "composer");
EXPECT_TRUE(composer);
EXPECT_TRUE(!strcmp(composer, "TEST_COMPOSER"));
const char *composer2 = pl_find_meta(cueItem->next[PL_MAIN], "composer");
EXPECT_TRUE(composer2 == NULL);
pl_item_unref(cueItem);
plt_free (plt);
}
TEST_F(CuesheetTests, test_CueWithTrackGain_SetsCueTrackGainForOneTrack) {
const char cue[] =
"FILE \"file.wav\" WAVE\n"
"TRACK 01 AUDIO\n"
"REM COMPOSER \"TEST_COMPOSER\"\n"
"REM REPLAYGAIN_TRACK_GAIN +1.00 dB\n"
"INDEX 01 00:00:00\n"
"TRACK 02 AUDIO\n"
"INDEX 01 00:01:00\n";
playlist_t *plt = plt_alloc("test");
playItem_t *it = pl_item_alloc_init ("testfile.flac", "stdflac");
pl_add_meta (it, "cuesheet", cue);
plt_process_cue(plt, NULL, it, 60*10*44100, 44100);
int cnt = plt_get_item_count(plt, PL_MAIN);
EXPECT_EQ(cnt, 2);
playItem_t *cueItem = plt_get_first(plt, PL_MAIN);
const char *trackgain = pl_find_meta (cueItem, ":REPLAYGAIN_TRACKGAIN");
EXPECT_TRUE(trackgain!=NULL);
EXPECT_TRUE(!strcmp(trackgain, "1.00 dB"));
pl_item_unref(cueItem);
plt_free (plt);
}