Skip to content

Commit

Permalink
Make testDir() a QDir
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Apr 22, 2022
1 parent 695f2b6 commit 3881228
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 127 deletions.
6 changes: 3 additions & 3 deletions src/test/autodjprocessor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using ::testing::Return;

static int kDefaultTransitionTime = 10;
const mixxx::audio::ChannelCount kChannelCount = mixxx::kEngineChannelCount;
const QString kTrackLocationTest = QStringLiteral("/id3-test-data/cover-test-png.mp3");
const QString kTrackLocationTest = QStringLiteral("id3-test-data/cover-test-png.mp3");

class FakeMaster {
public:
Expand Down Expand Up @@ -175,7 +175,7 @@ class AutoDJProcessorTest : public LibraryTest {

TrackPointer newTestTrack(TrackId trackId) const {
TrackPointer pTrack(
Track::newDummy(getTestPath() + kTrackLocationTest, trackId));
Track::newDummy(getTestDir().filePath(kTrackLocationTest), trackId));
EXPECT_EQ(
SoundSourceProxy::UpdateTrackFromSourceResult::MetadataImportedAndUpdated,
SoundSourceProxy(pTrack).updateTrackFromSource(
Expand Down Expand Up @@ -231,7 +231,7 @@ class AutoDJProcessorTest : public LibraryTest {

TrackId addTrackToCollection(const QString& trackLocation) {
TrackPointer pTrack =
getOrAddTrackByLocation(getTestPath() + trackLocation);
getOrAddTrackByLocation(getTestDir().filePath(trackLocation));
return pTrack ? pTrack->getId() : TrackId();
}

Expand Down
18 changes: 10 additions & 8 deletions src/test/coverartcache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class CoverArtCacheTest : public LibraryTest, public CoverArtCache {
};

const QString kCoverFileTest = QStringLiteral("cover_test.jpg");
const QString kCoverLocationTest = QStringLiteral("/id3-test-data/") + kCoverFileTest;
const QString kTrackLocationTest = QStringLiteral("/id3-test-data/cover-test-png.mp3");
const QString kCoverLocationTest = QStringLiteral("id3-test-data/") + kCoverFileTest;
const QString kTrackLocationTest = QStringLiteral("id3-test-data/cover-test-png.mp3");

// We need 3 separate test cases:
// 1) loadCoverFromMetadata()
Expand All @@ -73,17 +73,19 @@ const QString kTrackLocationTest = QStringLiteral("/id3-test-data/cover-test-png
// - absolute coverLocation

TEST_F(CoverArtCacheTest, loadCoverFromMetadata) {
loadCoverFromMetadata(getTestPath() + kTrackLocationTest);
loadCoverFromMetadata(getTestDir().filePath(kTrackLocationTest));
}

TEST_F(CoverArtCacheTest, loadCoverFromFileRelative) {
loadCoverFromFile(getTestPath() + kTrackLocationTest,
loadCoverFromFile(
getTestDir().filePath(kTrackLocationTest),
kCoverFileTest,
getTestPath() + kCoverLocationTest);
getTestDir().filePath(kCoverLocationTest));
}

TEST_F(CoverArtCacheTest, loadCoverFromFileAbsolute) {
loadCoverFromFile(QString(),
getTestPath() + kCoverLocationTest,
getTestPath() + kCoverLocationTest);
loadCoverFromFile(
QString(),
getTestDir().filePath(kCoverLocationTest),
getTestDir().filePath(kCoverLocationTest));
}
64 changes: 34 additions & 30 deletions src/test/coverartutils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace {

const QString kReferencePNGLocationTest = QStringLiteral("/id3-test-data/reference_cover.png");
const QString kReferenceJPGLocationTest = QStringLiteral("/id3-test-data/cover_test.jpg");
const QString kReferencePNGLocationTest = QStringLiteral("id3-test-data/reference_cover.png");
const QString kReferenceJPGLocationTest = QStringLiteral("id3-test-data/cover_test.jpg");

void extractEmbeddedCover(
const QString& trackLocation,
Expand All @@ -32,69 +32,73 @@ class CoverArtUtilTest : public LibraryTest, CoverArtCache {
};

TEST_F(CoverArtUtilTest, extractEmbeddedCover) {
QImage referencePNGImage = QImage(getTestPath() + kReferencePNGLocationTest);
QImage referenceJPGImage = QImage(getTestPath() + kReferenceJPGLocationTest);
QImage referencePNGImage = QImage(getTestDir().filePath(kReferencePNGLocationTest));
QImage referenceJPGImage = QImage(getTestDir().filePath(kReferenceJPGLocationTest));

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("aiff"))) {
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test.aiff"),
extractEmbeddedCover(getTestDir().filePath(QStringLiteral("id3-test-data/cover-test.aiff")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("flac"))) {
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test.flac"),
extractEmbeddedCover(getTestDir().filePath(QStringLiteral("id3-test-data/cover-test.flac")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("m4a"))) {
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test-itunes-12.3.0-aac.m4a"),
extractEmbeddedCover(
getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test-itunes-12.3.0-aac.m4a")),
referencePNGImage);
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test-itunes-12.7.0-aac.m4a"),
extractEmbeddedCover(
getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test-itunes-12.7.0-aac.m4a")),
referencePNGImage);
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test-itunes-12.7.0-alac.m4a"),
extractEmbeddedCover(
getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test-itunes-12.7.0-alac.m4a")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("m4v"))) {
extractEmbeddedCover(
getTestPath() + QStringLiteral("/id3-test-data/cover-test.m4v"), referencePNGImage);
extractEmbeddedCover(getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test.m4v")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("mp3"))) {
// PNG
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test-png.mp3"),
extractEmbeddedCover(getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test-png.mp3")),
referencePNGImage);
// JPEG
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test-jpg.mp3"),
extractEmbeddedCover(getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test-jpg.mp3")),
referenceJPGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("ogg"))) {
extractEmbeddedCover(
getTestPath() + QStringLiteral("/id3-test-data/cover-test.ogg"), referencePNGImage);
extractEmbeddedCover(getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test.ogg")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("opus"))) {
// opus
extractEmbeddedCover(getTestPath() +
QStringLiteral("/id3-test-data/cover-test.opus"),
extractEmbeddedCover(getTestDir().filePath(QStringLiteral("id3-test-data/cover-test.opus")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("wav"))) {
extractEmbeddedCover(
getTestPath() + QStringLiteral("/id3-test-data/cover-test.wav"), referencePNGImage);
extractEmbeddedCover(getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test.wav")),
referencePNGImage);
}

if (SoundSourceProxy::isFileSuffixSupported(QStringLiteral("wv"))) {
extractEmbeddedCover(
getTestPath() + QStringLiteral("/id3-test-data/cover-test.wv"), referencePNGImage);
extractEmbeddedCover(getTestDir().filePath(QStringLiteral(
"id3-test-data/cover-test.wv")),
referencePNGImage);
}
}

Expand All @@ -104,8 +108,8 @@ TEST_F(CoverArtUtilTest, searchImage) {
ASSERT_TRUE(tempTrackDir.isValid());
QString trackdir = QString(tempTrackDir.path());

const QString kTrackLocationTest(getTestPath() +
QStringLiteral("/id3-test-data/cover-test-png.mp3"));
const QString kTrackLocationTest(getTestDir().filePath(
QStringLiteral("id3-test-data/cover-test-png.mp3")));

TrackPointer pTrack(Track::newTemporary(kTrackLocationTest));
QList<QFileInfo> covers;
Expand Down
2 changes: 1 addition & 1 deletion src/test/cuecontrol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CueControlTest : public BaseSignalPathTest {
}

TrackPointer createTestTrack() const {
const QString kTrackLocationTest = getTestPath() + QStringLiteral("/sine-30.wav");
const QString kTrackLocationTest = getTestDir().filePath(QStringLiteral("sine-30.wav"));
const auto pTrack = Track::newTemporary(
mixxx::FileAccess(mixxx::FileInfo(kTrackLocationTest)));
pTrack->setAudioProperties(
Expand Down
12 changes: 6 additions & 6 deletions src/test/globaltrackcache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace {

const QString kTestFile = QStringLiteral("/id3-test-data/cover-test.flac");
const QString kTestFile2 = QStringLiteral("/id3-test-data/cover-test.ogg");
const QString kTestFile = QStringLiteral("id3-test-data/cover-test.flac");
const QString kTestFile2 = QStringLiteral("id3-test-data/cover-test.ogg");

class TrackTitleThread: public QThread {
public:
Expand Down Expand Up @@ -95,7 +95,7 @@ TEST_F(GlobalTrackCacheTest, resolveByFileInfo) {

TrackPointer track;
{
auto testFileAccess = mixxx::FileAccess(mixxx::FileInfo(getTestPath() + kTestFile));
auto testFileAccess = mixxx::FileAccess(mixxx::FileInfo(getTestDir().filePath(kTestFile)));
GlobalTrackCacheResolver resolver(testFileAccess);
track = resolver.getTrack();
EXPECT_TRUE(static_cast<bool>(track));
Expand Down Expand Up @@ -145,7 +145,7 @@ TEST_F(GlobalTrackCacheTest, concurrentDelete) {
TrackTitleThread workerThread;
workerThread.start();

const auto testFile = mixxx::FileInfo(getTestPath() + kTestFile);
const auto testFile = mixxx::FileInfo(getTestDir().filePath(kTestFile));

// lp1744550: A decent number of iterations is needed to reliably
// reveal potential race conditions while evicting tracks from
Expand Down Expand Up @@ -203,12 +203,12 @@ TEST_F(GlobalTrackCacheTest, evictWhileMoving) {
ASSERT_TRUE(GlobalTrackCacheLocker().isEmpty());

TrackPointer track1 = GlobalTrackCacheResolver(
mixxx::FileAccess(mixxx::FileInfo(getTestPath() + kTestFile)))
mixxx::FileAccess(mixxx::FileInfo(getTestDir().filePath(kTestFile))))
.getTrack();
EXPECT_TRUE(static_cast<bool>(track1));

TrackPointer track2 = GlobalTrackCacheResolver(
mixxx::FileAccess(mixxx::FileInfo(getTestPath() + kTestFile2)))
mixxx::FileAccess(mixxx::FileInfo(getTestDir().filePath(kTestFile2))))
.getTrack();
EXPECT_TRUE(static_cast<bool>(track2));

Expand Down
2 changes: 1 addition & 1 deletion src/test/hotcuecontrol_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class HotcueControlTest : public BaseSignalPathTest {
}

TrackPointer createTestTrack() const {
const QString kTrackLocationTest = getTestPath() + QStringLiteral("/sine-30.wav");
const QString kTrackLocationTest = getTestDir().filePath(QStringLiteral("sine-30.wav"));
const auto pTrack = Track::newTemporary(
mixxx::FileAccess(mixxx::FileInfo(kTrackLocationTest)));
pTrack->setAudioProperties(
Expand Down
2 changes: 1 addition & 1 deletion src/test/mixxxtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ QString makeTestConfigFile(const QString& path) {

// Static initialization
QScopedPointer<MixxxApplication> MixxxTest::s_pApplication;
QString MixxxTest::s_TestPath;
QDir MixxxTest::s_TestDir;

MixxxTest::ApplicationScope::ApplicationScope(int& argc, char** argv) {
CmdlineArgs args;
Expand Down
21 changes: 11 additions & 10 deletions src/test/mixxxtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace {

// We assume that the test folder is a sibling to the res folder
const QString kTestPath = QStringLiteral("/../src/test");
const QString kTestPath = QStringLiteral("../src/test");

} // namespace

Expand All @@ -35,11 +35,12 @@ class MixxxTest : public testing::Test {
};
friend class ApplicationScope;

static const QString& testPath() {
if (s_TestPath.isEmpty()) {
s_TestPath = ConfigObject<ConfigValue>::computeResourcePath() + kTestPath;
static const QDir& testDir() {
if (s_TestDir.path() == ".") {
s_TestDir.setPath(ConfigObject<ConfigValue>::computeResourcePath() +
QChar('/') + kTestPath);
}
return s_TestPath;
return s_TestDir;
}

protected:
Expand All @@ -58,16 +59,16 @@ class MixxxTest : public testing::Test {
return m_testDataDir.path();
}

const QString& getTestPath() const {
if (s_TestPath.isEmpty()) {
s_TestPath = m_pConfig->getResourcePath() + kTestPath;
const QDir& getTestDir() const {
if (s_TestDir.path() == ".") {
s_TestDir.setPath(m_pConfig->getResourcePath() + QChar('/') + kTestPath);
}
return s_TestPath;
return s_TestDir;
}

private:
static QScopedPointer<MixxxApplication> s_pApplication;
static QString s_TestPath;
static QDir s_TestDir;
const QTemporaryDir m_testDataDir;

protected:
Expand Down
14 changes: 7 additions & 7 deletions src/test/playermanagertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

namespace {

const QString kTrackLocationTest1 = QStringLiteral("/id3-test-data/cover-test-png.mp3");
const QString kTrackLocationTest2 = QStringLiteral("/id3-test-data/cover-test-vbr.mp3");
const QString kTrackLocationTest1 = QStringLiteral("id3-test-data/cover-test-png.mp3");
const QString kTrackLocationTest2 = QStringLiteral("id3-test-data/cover-test-vbr.mp3");

void deleteTrack(Track* pTrack) {
// Delete track objects directly in unit tests with
Expand Down Expand Up @@ -119,7 +119,7 @@ TEST_F(PlayerManagerTest, UnEjectTest) {
ASSERT_EQ(nullptr, deck1->getLoadedTrack());

// Load a track and eject it
TrackPointer pTrack1 = getOrAddTrackByLocation(getTestPath() + kTrackLocationTest1);
TrackPointer pTrack1 = getOrAddTrackByLocation(getTestDir().filePath(kTrackLocationTest1));
ASSERT_NE(nullptr, pTrack1);
TrackId testId1 = pTrack1->getId();
ASSERT_TRUE(testId1.isValid());
Expand All @@ -133,7 +133,7 @@ TEST_F(PlayerManagerTest, UnEjectTest) {
deck1->slotEjectTrack(1.0);

// Load another track.
TrackPointer pTrack2 = getOrAddTrackByLocation(getTestPath() + kTrackLocationTest2);
TrackPointer pTrack2 = getOrAddTrackByLocation(getTestDir().filePath(kTrackLocationTest2));
ASSERT_NE(nullptr, pTrack2);
deck1->slotLoadTrack(pTrack2, false);

Expand All @@ -150,7 +150,7 @@ TEST_F(PlayerManagerTest, UnEjectTest) {
TEST_F(PlayerManagerTest, UnEjectReplaceTrackTest) {
auto deck1 = m_pPlayerManager->getDeck(1);
// Load a track and the load another one
TrackPointer pTrack1 = getOrAddTrackByLocation(getTestPath() + kTrackLocationTest1);
TrackPointer pTrack1 = getOrAddTrackByLocation(getTestDir().filePath(kTrackLocationTest1));
ASSERT_NE(nullptr, pTrack1);
TrackId testId1 = pTrack1->getId();
ASSERT_TRUE(testId1.isValid());
Expand All @@ -163,7 +163,7 @@ TEST_F(PlayerManagerTest, UnEjectReplaceTrackTest) {
}

// Load another track, replacing the first, causing it to be unloaded.
TrackPointer pTrack2 = getOrAddTrackByLocation(getTestPath() + kTrackLocationTest2);
TrackPointer pTrack2 = getOrAddTrackByLocation(getTestDir().filePath(kTrackLocationTest2));
ASSERT_NE(nullptr, pTrack2);
deck1->slotLoadTrack(pTrack2, false);
m_pEngine->process(1024);
Expand All @@ -181,7 +181,7 @@ TEST_F(PlayerManagerTest, UnEjectReplaceTrackTest) {

TEST_F(PlayerManagerTest, UnEjectInvalidTrackIdTest) {
// Save an invalid trackid in playermanager.
auto pTrack = Track::newDummy(getTestPath() + kTrackLocationTest1, TrackId(10));
auto pTrack = Track::newDummy(getTestDir().filePath(kTrackLocationTest1), TrackId(10));
ASSERT_NE(nullptr, pTrack);
m_pPlayerManager->slotSaveEjectedTrack(pTrack);
auto deck1 = m_pPlayerManager->getDeck(1);
Expand Down
2 changes: 1 addition & 1 deletion src/test/replaygaintest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ TEST_F(ReplayGainTest, NormalizePeak) {
class AdjustReplayGainTest : public MockedEngineBackendTest {};

TEST_F(AdjustReplayGainTest, AdjustReplayGainUpdatesPregain) {
const QString kTrackLocationTest = getTestPath() + QStringLiteral("/sine-30.wav");
const QString kTrackLocationTest = getTestDir().filePath(QStringLiteral("sine-30.wav"));
TrackPointer pTrack(Track::newTemporary(kTrackLocationTest));

// Load the same track in decks 1 and 2 so we can see that the pregain is adjusted on both
Expand Down
Loading

0 comments on commit 3881228

Please sign in to comment.