From 055766c7dd1a0262399d4088f57e4eea098b3284 Mon Sep 17 00:00:00 2001 From: Tres Finocchiaro Date: Fri, 5 May 2017 20:59:12 -0400 Subject: [PATCH] Unit test improvements --- src/core/ConfigManager.cpp | 7 ++++++- tests/src/core/RelativePathsTest.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/core/ConfigManager.cpp b/src/core/ConfigManager.cpp index 5cdfe3d97a4..13c6d9a85b3 100644 --- a/src/core/ConfigManager.cpp +++ b/src/core/ConfigManager.cpp @@ -63,7 +63,12 @@ ConfigManager::ConfigManager() : // If we're in development (lmms is not installed) let's get the source and // binary directories by reading the CMake Cache - QFile cmakeCache(qApp->applicationDirPath() + "/CMakeCache.txt"); + QDir appPath = qApp->applicationDirPath(); + // If in tests, get parent directory + if (appPath.dirName() == "tests") { + appPath.cdUp(); + } + QFile cmakeCache(appPath.absoluteFilePath("CMakeCache.txt")); if (cmakeCache.exists()) { cmakeCache.open(QFile::ReadOnly); QTextStream stream(&cmakeCache); diff --git a/tests/src/core/RelativePathsTest.cpp b/tests/src/core/RelativePathsTest.cpp index 544a02d7acc..69e7c90f47c 100644 --- a/tests/src/core/RelativePathsTest.cpp +++ b/tests/src/core/RelativePathsTest.cpp @@ -34,8 +34,13 @@ class RelativePathsTest : QTestSuite private slots: void RelativePathComparisonTests() { - QVERIFY(SampleBuffer::tryToMakeRelative(QDir::currentPath() + "/data/samples/drums/kick01.ogg") == "drums/kick01.ogg"); - QVERIFY(SampleBuffer::tryToMakeAbsolute("drums/kick01.ogg") == QDir::currentPath() + "/data/samples/drums/kick01.ogg"); + QFileInfo fi(ConfigManager::inst()->factorySamplesDir() + "/drums/kick01.ogg"); + QVERIFY(fi.exists()); + + QString absPath = fi.absoluteFilePath(); + QString relPath = "drums/kick01.ogg"; + QCOMPARE(SampleBuffer::tryToMakeRelative(absPath), relPath); + QCOMPARE(SampleBuffer::tryToMakeAbsolute(relPath), absPath); } } RelativePathTests;