blob: 5a118f49dff4ca5711aca13e9f5863548f350e34 (
plain)
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
|
#ifndef MIXXXTEST_H
#define MIXXXTEST_H
#include <gtest/gtest.h>
#include <QDir>
#include <QTemporaryFile>
#include <QScopedPointer>
#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();
virtual ~MixxxTest();
// ApplicationScope creates QApplication as a singleton and keeps
// it alive during all tests. This prevents issues with creating
// and destroying the QApplication multiple times in the same process.
// http://stackoverflow.com/questions/14243858/qapplication-segfaults-in-googletest
class ApplicationScope {
public:
ApplicationScope(int& argc, char** argv);
~ApplicationScope();
};
friend class ApplicationScope;
protected:
static QApplication* application() {
return s_pApplication.data();
}
UserSettingsPointer config() const {
return m_pConfig;
}
// 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;
}
QDir getTestDataDir() const {
return m_testDataDir;
}
private:
static QScopedPointer<MixxxApplication> s_pApplication;
const QDir m_testDataDir;
protected:
UserSettingsPointer m_pConfig;
};
#endif /* MIXXXTEST_H */
|