diff options
Diffstat (limited to 'src/test/mixxxtest.h')
-rw-r--r-- | src/test/mixxxtest.h | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/src/test/mixxxtest.h b/src/test/mixxxtest.h index 92aa601218..92c1df7e95 100644 --- a/src/test/mixxxtest.h +++ b/src/test/mixxxtest.h @@ -1,24 +1,17 @@ -#ifndef MIXXXTEST_H -#define MIXXXTEST_H +#pragma once #include <gtest/gtest.h> #include <QDir> -#include <QTemporaryFile> -#include <QTemporaryDir> #include <QScopedPointer> +#include <QTemporaryDir> #include "mixxxapplication.h" - #include "preferences/usersettings.h" -#include "control/controlobject.h" -#include "control/controlproxy.h" #define EXPECT_QSTRING_EQ(expected, test) EXPECT_STREQ(qPrintable(expected), qPrintable(test)) #define ASSERT_QSTRING_EQ(expected, test) ASSERT_STREQ(qPrintable(expected), qPrintable(test)) -typedef QScopedPointer<QTemporaryFile> ScopedTemporaryFile; - class MixxxTest : public testing::Test { public: MixxxTest(); @@ -29,7 +22,7 @@ class MixxxTest : public testing::Test { // and destroying the QApplication multiple times in the same process. // http://stackoverflow.com/questions/14243858/qapplication-segfaults-in-googletest class ApplicationScope { - public: + public: ApplicationScope(int& argc, char** argv); ~ApplicationScope(); }; @@ -45,21 +38,7 @@ class MixxxTest : public testing::Test { } // Simulate restarting Mixxx by saving and reloading the UserSettings. - void saveAndReloadConfig() { - m_pConfig->save(); - m_pConfig = UserSettingsPointer( - new UserSettings(getTestDataDir().filePath("test.cfg"))); - ControlDoublePrivate::setUserConfig(m_pConfig); - } - - QTemporaryFile* makeTemporaryFile(const QString& contents) const { - QByteArray contentsBa = contents.toLocal8Bit(); - QTemporaryFile* file = new QTemporaryFile(); - file->open(); - file->write(contentsBa); - file->close(); - return file; - } + void saveAndReloadConfig(); QDir getTestDataDir() const { return m_testDataDir.path(); @@ -74,4 +53,33 @@ class MixxxTest : public testing::Test { UserSettingsPointer m_pConfig; }; -#endif /* MIXXXTEST_H */ +namespace mixxxtest { + +/// Returns the full, non-empty file path on success. +/// +/// For the format of fileNameTemplate refer to QTemporaryFile. +QString generateTemporaryFileName(const QString& fileNameTemplate); + +/// Returns the full, non-empty file path on success. +/// +/// For the format of fileNameTemplate refer to QTemporaryFile. +QString createEmptyTemporaryFile(const QString& fileNameTemplate); + +bool copyFile(const QString& srcFileName, const QString& dstFileName); + +class FileRemover final { + public: + explicit FileRemover(const QString& fileName) + : m_fileName(fileName) { + } + ~FileRemover(); + + void keepFile() { + m_fileName = QString(); + } + + private: + QString m_fileName; +}; + +} // namespace mixxxtest |