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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
/* GCompris - GImageGrabberTest.cpp
*
* SPDX-FileCopyrightText: 2025 Timothée Giet <animtim@gmail.com>
*
* Authors:
* Timothée Giet <animtim@gmail.com>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <QTest>
#include <QObject>
#include "src/core/GImageGrabber.h"
class GImageGrabberTest : public QObject
{
public:
Q_OBJECT
private Q_SLOTS:
void SetMaxUndoTest();
void DoUndoTest();
void DoRedoTest();
};
void GImageGrabberTest::SetMaxUndoTest()
{
GImageGrabber grabber;
grabber.setMaxUndo(-1);
QCOMPARE(grabber.maxUndo(), 1);
// set maxUndo to 20
grabber.setMaxUndo(20);
QCOMPARE(grabber.maxUndo(), 20);
// get 21 undo steps
for(int i = 0; i < 21; i++ ) {
grabber.safeGrab(QSize(1, 1));
}
// move 5 undo to redoList
for(int j = 0; j < 5; j++) {
grabber.doUndo();
}
QCOMPARE(grabber.undoSize(), 16);
QCOMPARE(grabber.redoSize(), 5);
grabber.setMaxUndo(12);
QCOMPARE(grabber.undoSize(), 13);
QCOMPARE(grabber.redoSize(), 0);
// move again 5 undo to redoList
for(int j = 0; j < 5; j++) {
grabber.doUndo();
}
QCOMPARE(grabber.undoSize(), 8);
QCOMPARE(grabber.redoSize(), 5);
grabber.setMaxUndo(10);
QCOMPARE(grabber.undoSize(), 8);
QCOMPARE(grabber.redoSize(), 3);
}
void GImageGrabberTest::DoUndoTest()
{
GImageGrabber grabber;
// test with nothing to undo (only 1 safeGrab)
grabber.safeGrab(QSize(1, 1));
QCOMPARE(grabber.undoSize(), 1);
QCOMPARE(grabber.redoSize(), 0);
grabber.doUndo();
QCOMPARE(grabber.undoSize(), 1);
QCOMPARE(grabber.redoSize(), 0);
// test with something to undo (after 2nd safeGrab)
grabber.safeGrab(QSize(1, 1));
QCOMPARE(grabber.undoSize(), 2);
QCOMPARE(grabber.redoSize(), 0);
grabber.doUndo();
QCOMPARE(grabber.undoSize(), 1);
QCOMPARE(grabber.redoSize(), 1);
}
void GImageGrabberTest::DoRedoTest()
{
GImageGrabber grabber;
// make 2 safeGrab to have something to undo
grabber.safeGrab(QSize(1, 1));
grabber.safeGrab(QSize(1, 1));
QCOMPARE(grabber.undoSize(), 2);
QCOMPARE(grabber.redoSize(), 0);
// test with nothing to redo
grabber.doRedo();
QCOMPARE(grabber.undoSize(), 2);
QCOMPARE(grabber.redoSize(), 0);
// test with something to redo
grabber.doUndo();
QCOMPARE(grabber.undoSize(), 1);
QCOMPARE(grabber.redoSize(), 1);
grabber.doRedo();
QCOMPARE(grabber.undoSize(), 2);
QCOMPARE(grabber.redoSize(), 0);
}
QTEST_MAIN(GImageGrabberTest)
#include "GImageGrabberTest.moc"
|