Some refactor
This commit is contained in:
37 files changed
+1599
-981
No files matched your search
@@ -0,0 +1,81 @@
|
||||
#include <QtTest>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QSettings>
|
||||
#include <QTemporaryFile>
|
||||
|
||||
#include "backend/AppState.h"
|
||||
#include "backend/state/ReadingPreferences.h"
|
||||
|
||||
class ReadingPreferencesTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void defaultsWhenEmpty()
|
||||
{
|
||||
QTemporaryFile f;
|
||||
f.setFileTemplate(QDir::tempPath() + QStringLiteral("/rp-def-XXXXXX.ini"));
|
||||
f.open(); f.close();
|
||||
QSettings s(f.fileName(), QSettings::IniFormat);
|
||||
AppState appState(s);
|
||||
ReadingPreferences prefs(appState);
|
||||
|
||||
QCOMPARE(prefs.fontSize(), 16);
|
||||
QCOMPARE(prefs.lineSpacing(), 1.6);
|
||||
QCOMPARE(prefs.horizontalMargin(), 32);
|
||||
QCOMPARE(prefs.verticalMargin(), 8);
|
||||
}
|
||||
|
||||
void saveAndRestore()
|
||||
{
|
||||
QString fileName;
|
||||
{
|
||||
QTemporaryFile tmp;
|
||||
tmp.setFileTemplate(QDir::tempPath() + QStringLiteral("/rp-sr-XXXXXX.ini"));
|
||||
tmp.setAutoRemove(false);
|
||||
QVERIFY(tmp.open());
|
||||
fileName = tmp.fileName();
|
||||
}
|
||||
|
||||
{
|
||||
QSettings s(fileName, QSettings::IniFormat);
|
||||
AppState appState(s);
|
||||
ReadingPreferences prefs(appState);
|
||||
prefs.setFontSize(20);
|
||||
prefs.setLineSpacing(2.0);
|
||||
prefs.setHorizontalMargin(48);
|
||||
prefs.setVerticalMargin(16);
|
||||
prefs.save();
|
||||
}
|
||||
|
||||
QSettings s2(fileName, QSettings::IniFormat);
|
||||
AppState appState2(s2);
|
||||
ReadingPreferences prefs2(appState2);
|
||||
|
||||
QCOMPARE(prefs2.fontSize(), 20);
|
||||
QCOMPARE(prefs2.lineSpacing(), 2.0);
|
||||
QCOMPARE(prefs2.horizontalMargin(), 48);
|
||||
QCOMPARE(prefs2.verticalMargin(), 16);
|
||||
|
||||
QFile::remove(fileName);
|
||||
}
|
||||
|
||||
void fontSizeSignal()
|
||||
{
|
||||
QTemporaryFile f;
|
||||
f.setFileTemplate(QDir::tempPath() + QStringLiteral("/rp-sig-XXXXXX.ini"));
|
||||
f.open(); f.close();
|
||||
QSettings s(f.fileName(), QSettings::IniFormat);
|
||||
AppState appState(s);
|
||||
ReadingPreferences prefs(appState);
|
||||
|
||||
QSignalSpy spy(&prefs, &ReadingPreferences::fontSizeChanged);
|
||||
prefs.setFontSize(18);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
prefs.setFontSize(18); // no-op
|
||||
QCOMPARE(spy.count(), 1);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(ReadingPreferencesTest)
|
||||
#include "ReadingPreferencesTest.moc"
|
||||
Reference in new issue
Block a user