Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tresf committed May 4, 2017
1 parent ccd369b commit 2077621
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
7 changes: 6 additions & 1 deletion include/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ class EXPORT ConfigManager
return m_workingDir;
}

const QString & sourceDir() const
{
return m_srcDir;
}

QString userProjectsDir() const
{
return workingDir() + PROJECTS_PATH;
Expand Down Expand Up @@ -253,6 +258,7 @@ class EXPORT ConfigManager

QString m_lmmsRcFile;
QString m_workingDir;
QString m_srcDir;
QString m_dataDir;
QString m_artworkDir;
QString m_vstDir;
Expand All @@ -275,7 +281,6 @@ class EXPORT ConfigManager


friend class LmmsCore;

} ;

#endif
11 changes: 8 additions & 3 deletions src/core/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
QString appPath = qApp->applicationDirPath();
// If in tests, get parent directory
if(appPath.endsWith("/tests")) {
appPath = QFileInfo(appPath).dir().currentPath();
}
QFile cmakeCache(appPath + "/CMakeCache.txt");
if (cmakeCache.exists()) {
cmakeCache.open(QFile::ReadOnly);
QTextStream stream(&cmakeCache);
Expand All @@ -76,8 +81,8 @@ ConfigManager::ConfigManager() :
QString line = stream.readLine();

if (line.startsWith("lmms_SOURCE_DIR:")) {
QString srcDir = line.section('=', -1).trimmed();
QDir::addSearchPath("data", srcDir + "/data/");
m_srcDir = line.section('=', -1).trimmed();
QDir::addSearchPath("data", m_srcDir + "/data/");
done++;
}
if (line.startsWith("lmms_BINARY_DIR:")) {
Expand Down
9 changes: 7 additions & 2 deletions tests/src/core/RelativePathsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

#include "QTestSuite.h"

#include "ConfigManager.h"
#include "SampleBuffer.h"



#include <QDir>

class RelativePathsTest : QTestSuite
Expand All @@ -34,8 +37,10 @@ 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");
// Bail if we can't find the source directory
QVERIFY(ConfigManager::inst()->sourceDir() != nullptr);
QVERIFY(SampleBuffer::tryToMakeRelative(ConfigManager::inst()->sourceDir() + "/data/samples/drums/kick01.ogg") == "drums/kick01.ogg");
QVERIFY(SampleBuffer::tryToMakeAbsolute("drums/kick01.ogg") == ConfigManager::inst()->sourceDir() + "/data/samples/drums/kick01.ogg");
}
} RelativePathTests;

Expand Down

0 comments on commit 2077621

Please sign in to comment.