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
|
#include <gtest/gtest.h>
#include <QStringBuilder>
#include <QFileInfo>
#include "library/coverartcache.h"
#include "library/coverartutils.h"
#include "library/trackcollection.h"
#include "test/mixxxtest.h"
#include "sources/soundsourceproxy.h"
// first inherit from MixxxTest to construct a QApplication to be able to
// construct the default QPixmap in CoverArtCache
class CoverArtCacheTest : public MixxxTest, public CoverArtCache {
protected:
void loadCoverFromMetadata(QString trackLocation) {
CoverInfo info;
info.type = CoverInfo::METADATA;
info.source = CoverInfo::GUESSED;
info.coverLocation = QString();
info.trackLocation = trackLocation;
CoverArtCache::FutureResult res;
res = CoverArtCache::loadCover(info, NULL, 0, false);
EXPECT_QSTRING_EQ(QString(), res.cover.coverLocation);
EXPECT_EQ(info.hash, res.cover.hash);
SecurityTokenPointer securityToken = Sandbox::openSecurityToken(
QDir(trackLocation), true);
TrackPointer pTrack(Track::newTemporary(trackLocation, securityToken));
SoundSourceProxy proxy(pTrack);
QImage img(SoundSourceProxy(pTrack).parseCoverImage());
EXPECT_FALSE(img.isNull());
EXPECT_EQ(img, res.cover.image);
}
void loadCoverFromFile(QString trackLocation, QString coverLocation, QString absoluteCoverLocation) {
QImage img = QImage(absoluteCoverLocation);
CoverInfo info;
info.type = CoverInfo::FILE;
info.source = CoverInfo::GUESSED;
info.coverLocation = coverLocation;
info.trackLocation = trackLocation;
info.hash = 4321; // fake cover hash
CoverArtCache::FutureResult res;
res = CoverArtCache::loadCover(info, NULL, 0, false);
EXPECT_QSTRING_EQ(info.coverLocation, res.cover.coverLocation);
EXPECT_EQ(info.hash, res.cover.hash);
EXPECT_FALSE(img.isNull());
EXPECT_EQ(img, res.cover.image);
}
};
const QString kCoverFileTest("cover_test.jpg");
const QString kCoverLocationTest(QDir::currentPath() %
"/src/test/id3-test-data/" % kCoverFileTest);
const QString kTrackLocationTest(QDir::currentPath() %
"/src/test/id3-test-data/cover-test-png.mp3");
// We need 3 separate test cases:
// 1) loadCoverFromMetadata()
// - CoverInfo::METADATA
// - absolute trackLocation
// - empty coverLocation (will be ignored)
// 2) loadCoverFromFileRelative()
// - CoverInfo::FILE
// - absolute trackLocation
// - coverLocation="cover_test.jpg"
// 3) loadCoverFromFileAbsolute()
// - CoverInfo::FILE
// - empty trackLocation
// - absolute coverLocation
TEST_F(CoverArtCacheTest, loadCover) {
loadCoverFromMetadata(kTrackLocationTest);
loadCoverFromFile(kTrackLocationTest, kCoverFileTest, kCoverLocationTest); //relative
loadCoverFromFile(QString(), kCoverLocationTest, kCoverLocationTest); //absolute
}
|