Commit 2a8721c2 authored by Tobias Deiminger's avatar Tobias Deiminger Committed by Oliver Sander

Add typewriter autotests

Add tests for the typewriter annotation tool

Differential Revision: https://phabricator.kde.org/D15348
parent 187c4740
......@@ -30,6 +30,7 @@ private slots:
// void testInk();
// void testHighlight();
// void testGeom();
void testTypewriter();
void cleanupTestCase();
private:
......@@ -140,6 +141,29 @@ void AnnotationTest::testDistance_data()
QTest::newRow("Highlight: Outside") << (Okular::Annotation*) highlight << 1.0 << 0.9 << qRound( pow( documentX * 0.1, 2 ) );
}
void AnnotationTest::testTypewriter()
{
Okular::Annotation * annot = nullptr;
Okular::TextAnnotation * ta = new Okular::TextAnnotation();
annot = ta;
ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation );
ta->setTextType( Okular::TextAnnotation::InPlace );
ta->setInplaceIntent( Okular::TextAnnotation::TypeWriter );
ta->style().setWidth( 0.0 );
ta->style().setColor( QColor(255,255,255,0) );
annot->setBoundingRectangle( Okular::NormalizedRect( 0.8, 0.1, 0.85, 0.15 ) );
annot->setContents( QStringLiteral("annot contents") );
m_document->addPageAnnotation( 0, annot );
QDomNode annotNode = annot->getAnnotationPropertiesDomNode();
QDomNodeList annotNodeList = annotNode.toElement().elementsByTagName("base");
QDomElement annotEl = annotNodeList.item(0).toElement();
QCOMPARE( annotEl.attribute( QStringLiteral("color") ), QStringLiteral("#00ffffff") );
QCOMPARE( annotEl.attribute( QStringLiteral("flags") ), QStringLiteral("4") );
QCOMPARE( annotEl.attribute( QStringLiteral("contents") ), QStringLiteral("annot contents") );
}
QTEST_MAIN( AnnotationTest )
#include "annotationstest.moc"
......@@ -56,6 +56,12 @@ public:
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
}
// Close a modal dialog, which may not be associated to any other widget
CloseDialogHelper(QDialogButtonBox::StandardButton b) : m_widget(nullptr), m_button(b), m_clicked(false)
{
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
}
~CloseDialogHelper()
{
QVERIFY(m_clicked);
......@@ -64,7 +70,7 @@ public:
private slots:
void closeDialog()
{
QDialog *dialog = m_widget->findChild<QDialog*>();
QWidget *dialog = ( m_widget ) ? m_widget->findChild<QDialog*>() : qApp->activeModalWidget();
if (!dialog) {
QTimer::singleShot(0, this, &CloseDialogHelper::closeDialog);
return;
......@@ -128,6 +134,7 @@ class PartTest
void testCrashTextEditDestroy();
void testAnnotWindow();
void testAdditionalActionTriggers();
void testTypewriterAnnotTool();
void testJumpToPage();
void testTabletProximityBehavior();
......@@ -1794,6 +1801,50 @@ void PartTest::testAdditionalActionTriggers()
verifyTargetStates( QStringLiteral( "pb" ), fields, false, false, false, __LINE__ );
}
void PartTest::testTypewriterAnnotTool()
{
Okular::Part part(nullptr, nullptr, QVariantList());
part.openUrl(QUrl::fromLocalFile(QStringLiteral(KDESRCDIR "data/file1.pdf")));
part.widget()->show();
QVERIFY(QTest::qWaitForWindowExposed(part.widget()));
const int width = part.m_pageView->horizontalScrollBar()->maximum() +
part.m_pageView->viewport()->width();
const int height = part.m_pageView->verticalScrollBar()->maximum() +
part.m_pageView->viewport()->height();
part.m_document->setViewportPage(0);
QMetaObject::invokeMethod(part.m_pageView, "slotToggleAnnotator", Q_ARG( bool, true ));
// Find the button for the TypeWriter annotation
QList<QToolButton *> toolbuttonList = part.m_pageView->findChildren<QToolButton *>();
auto it = std::find_if( toolbuttonList.begin(),
toolbuttonList.end(),
[](const QToolButton * x) { return x->toolTip().contains("Typewriter"); } );
QVERIFY(it != toolbuttonList.end());
QToolButton* typewriterButton = *it;
typewriterButton->click();
QTest::qWait(1000); // Wait for the "add new note" dialog to appear
CloseDialogHelper closeDialogHelper( QDialogButtonBox::Ok );
QTest::mouseClick(part.m_pageView->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(width * 0.5, height * 0.2));
Annotation* annot = part.m_document->page(0)->annotations().first();
TextAnnotation* ta = static_cast<TextAnnotation*>( annot );
QVERIFY( annot );
QVERIFY( ta );
QCOMPARE( annot->subType(), Okular::Annotation::AText );
QCOMPARE( annot->style().color(), QColor(255,255,255,0) );
QCOMPARE( ta->textType(), Okular::TextAnnotation::InPlace );
QCOMPARE( ta->inplaceIntent(), Okular::TextAnnotation::TypeWriter );
}
void PartTest::testJumpToPage() {
const QString testFile = QStringLiteral( KDESRCDIR "data/simple-multipage.pdf" );
const int targetPage = 25;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment