57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#include "model/EditorDocument.h"
|
|
|
|
#include <QtTest>
|
|
|
|
using ws::model::Annotation;
|
|
using ws::model::AnnotationKind;
|
|
using ws::model::EditorDocument;
|
|
|
|
class EditorDocumentTest : public QObject {
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
void add_select_move_delete_cycle();
|
|
void undo_redo_cycle();
|
|
};
|
|
|
|
void EditorDocumentTest::add_select_move_delete_cycle()
|
|
{
|
|
EditorDocument document;
|
|
|
|
Annotation annotation;
|
|
annotation.kind = AnnotationKind::Rectangle;
|
|
annotation.rect = QRectF(10, 10, 100, 80);
|
|
|
|
document.add_annotation(annotation);
|
|
QCOMPARE(document.annotations().size(), 1);
|
|
document.clear_selection();
|
|
QVERIFY(document.select_at(QPointF(20, 20)));
|
|
QVERIFY(document.selected_annotation() != nullptr);
|
|
QVERIFY(document.move_selected_by(QPointF(12, 8)));
|
|
QCOMPARE(document.annotations().front().rect.topLeft(), QPointF(22, 18));
|
|
QVERIFY(document.delete_selected());
|
|
QCOMPARE(document.annotations().size(), 0);
|
|
}
|
|
|
|
void EditorDocumentTest::undo_redo_cycle()
|
|
{
|
|
EditorDocument document;
|
|
|
|
Annotation line;
|
|
line.kind = AnnotationKind::Line;
|
|
line.line = QLineF(QPointF(0, 0), QPointF(50, 50));
|
|
|
|
document.add_annotation(line);
|
|
QCOMPARE(document.annotations().size(), 1);
|
|
QVERIFY(document.can_undo());
|
|
QVERIFY(document.undo());
|
|
QCOMPARE(document.annotations().size(), 0);
|
|
QVERIFY(document.can_redo());
|
|
QVERIFY(document.redo());
|
|
QCOMPARE(document.annotations().size(), 1);
|
|
}
|
|
|
|
QTEST_MAIN(EditorDocumentTest)
|
|
|
|
#include "editor_document_test.moc"
|