restore opened file and position
This commit is contained in:
12 files changed
+491
-11
No files matched your search
@@ -0,0 +1,197 @@
|
||||
#include <QtTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QSettings>
|
||||
#include "backend/AppState.h"
|
||||
|
||||
class AppStateTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase()
|
||||
{
|
||||
QCoreApplication::setOrganizationName(QStringLiteral("AsteriaTest"));
|
||||
QCoreApplication::setApplicationName(QStringLiteral("AppStateTest"));
|
||||
}
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
QSettings().clear();
|
||||
}
|
||||
|
||||
void saveAndRestoreLastFilePath()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setLastFilePath(QStringLiteral("/books/test.epub"));
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.lastFilePath(), QStringLiteral("/books/test.epub"));
|
||||
}
|
||||
|
||||
void saveAndRestoreLastChapter()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setLastChapter(5);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.lastChapter(), 5);
|
||||
}
|
||||
|
||||
void saveAndRestoreLastScrollPosition()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setLastScrollPosition(542.5);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.lastScrollPosition(), 542.5);
|
||||
}
|
||||
|
||||
void saveAndRestoreLastScrollIndex()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setLastScrollIndex(42);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.lastScrollIndex(), 42);
|
||||
}
|
||||
|
||||
void saveAndRestoreLastScrollOffset()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setLastScrollOffset(123.75);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.lastScrollOffset(), 123.75);
|
||||
}
|
||||
|
||||
void saveAndRestorePageFlipMode()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setPageFlipMode(QStringLiteral("page"));
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.pageFlipMode(), QStringLiteral("page"));
|
||||
}
|
||||
|
||||
void saveAndRestoreWindowGeometry()
|
||||
{
|
||||
{
|
||||
AppState state;
|
||||
state.setWindowWidth(1280);
|
||||
state.setWindowHeight(800);
|
||||
state.setWindowX(100);
|
||||
state.setWindowY(50);
|
||||
state.save();
|
||||
}
|
||||
AppState state2;
|
||||
state2.restore();
|
||||
QCOMPARE(state2.windowWidth(), 1280);
|
||||
QCOMPARE(state2.windowHeight(), 800);
|
||||
QCOMPARE(state2.windowX(), 100);
|
||||
QCOMPARE(state2.windowY(), 50);
|
||||
}
|
||||
|
||||
void restoreWithNoSavedData()
|
||||
{
|
||||
AppState state;
|
||||
state.restore();
|
||||
QVERIFY(state.lastFilePath().isEmpty());
|
||||
QCOMPARE(state.lastChapter(), 0);
|
||||
QCOMPARE(state.lastScrollPosition(), 0.0);
|
||||
QCOMPARE(state.lastScrollIndex(), 0);
|
||||
QCOMPARE(state.lastScrollOffset(), 0.0);
|
||||
QCOMPARE(state.pageFlipMode(), QStringLiteral("scroll"));
|
||||
QCOMPARE(state.windowWidth(), 1024);
|
||||
QCOMPARE(state.windowHeight(), 768);
|
||||
QCOMPARE(state.windowX(), -1);
|
||||
QCOMPARE(state.windowY(), -1);
|
||||
}
|
||||
|
||||
void settersEmitSignals()
|
||||
{
|
||||
AppState state;
|
||||
QSignalSpy spyFilePath(&state, &AppState::lastFilePathChanged);
|
||||
QSignalSpy spyChapter(&state, &AppState::lastChapterChanged);
|
||||
QSignalSpy spyScroll(&state, &AppState::lastScrollPositionChanged);
|
||||
QSignalSpy spyScrollIndex(&state, &AppState::lastScrollIndexChanged);
|
||||
QSignalSpy spyScrollOffset(&state, &AppState::lastScrollOffsetChanged);
|
||||
QSignalSpy spyFlip(&state, &AppState::pageFlipModeChanged);
|
||||
QSignalSpy spyWidth(&state, &AppState::windowWidthChanged);
|
||||
QSignalSpy spyHeight(&state, &AppState::windowHeightChanged);
|
||||
QSignalSpy spyX(&state, &AppState::windowXChanged);
|
||||
QSignalSpy spyY(&state, &AppState::windowYChanged);
|
||||
|
||||
state.setLastFilePath(QStringLiteral("/foo.txt"));
|
||||
state.setLastChapter(3);
|
||||
state.setLastScrollPosition(10.5);
|
||||
state.setLastScrollIndex(7);
|
||||
state.setLastScrollOffset(55.25);
|
||||
state.setPageFlipMode(QStringLiteral("page"));
|
||||
state.setWindowWidth(800);
|
||||
state.setWindowHeight(600);
|
||||
state.setWindowX(200);
|
||||
state.setWindowY(150);
|
||||
|
||||
QCOMPARE(spyFilePath.count(), 1);
|
||||
QCOMPARE(spyChapter.count(), 1);
|
||||
QCOMPARE(spyScroll.count(), 1);
|
||||
QCOMPARE(spyScrollIndex.count(), 1);
|
||||
QCOMPARE(spyScrollOffset.count(), 1);
|
||||
QCOMPARE(spyFlip.count(), 1);
|
||||
QCOMPARE(spyWidth.count(), 1);
|
||||
QCOMPARE(spyHeight.count(), 1);
|
||||
QCOMPARE(spyX.count(), 1);
|
||||
QCOMPARE(spyY.count(), 1);
|
||||
}
|
||||
|
||||
void restoreEmitsSingleSignal()
|
||||
{
|
||||
AppState state;
|
||||
|
||||
QSignalSpy spyRestored(&state, &AppState::stateRestored);
|
||||
QSignalSpy spyFilePath(&state, &AppState::lastFilePathChanged);
|
||||
QSignalSpy spyChapter(&state, &AppState::lastChapterChanged);
|
||||
QSignalSpy spyScroll(&state, &AppState::lastScrollPositionChanged);
|
||||
QSignalSpy spyScrollIndex(&state, &AppState::lastScrollIndexChanged);
|
||||
QSignalSpy spyScrollOffset(&state, &AppState::lastScrollOffsetChanged);
|
||||
QSignalSpy spyFlip(&state, &AppState::pageFlipModeChanged);
|
||||
QSignalSpy spyWidth(&state, &AppState::windowWidthChanged);
|
||||
QSignalSpy spyHeight(&state, &AppState::windowHeightChanged);
|
||||
QSignalSpy spyX(&state, &AppState::windowXChanged);
|
||||
QSignalSpy spyY(&state, &AppState::windowYChanged);
|
||||
|
||||
state.restore();
|
||||
|
||||
QCOMPARE(spyRestored.count(), 1);
|
||||
QCOMPARE(spyFilePath.count(), 0);
|
||||
QCOMPARE(spyChapter.count(), 0);
|
||||
QCOMPARE(spyScroll.count(), 0);
|
||||
QCOMPARE(spyScrollIndex.count(), 0);
|
||||
QCOMPARE(spyScrollOffset.count(), 0);
|
||||
QCOMPARE(spyFlip.count(), 0);
|
||||
QCOMPARE(spyWidth.count(), 0);
|
||||
QCOMPARE(spyHeight.count(), 0);
|
||||
QCOMPARE(spyX.count(), 0);
|
||||
QCOMPARE(spyY.count(), 0);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(AppStateTest)
|
||||
#include "AppStateTest.moc"
|
||||
@@ -88,6 +88,27 @@ private slots:
|
||||
// After completion, loading should be false
|
||||
QVERIFY(!ctrl.loading());
|
||||
}
|
||||
|
||||
void currentFilePathInitiallyEmpty()
|
||||
{
|
||||
BookController ctrl;
|
||||
QVERIFY(ctrl.currentFilePath().isEmpty());
|
||||
}
|
||||
|
||||
void currentFilePathSetOnOpen()
|
||||
{
|
||||
BookController ctrl;
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
QCOMPARE(ctrl.currentFilePath(), fixturePath("sample.txt"));
|
||||
}
|
||||
|
||||
void currentFilePathClearedOnClose()
|
||||
{
|
||||
BookController ctrl;
|
||||
ctrl.openBook(QUrl::fromLocalFile(fixturePath("sample.txt")));
|
||||
ctrl.closeBook();
|
||||
QVERIFY(ctrl.currentFilePath().isEmpty());
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(BookControllerTest)
|
||||
|
||||
Reference in new issue
Block a user