mirror of
https://invent.kde.org/graphics/okular
synced 2024-09-13 21:21:12 +00:00
Add test for 311232
This commit is contained in:
parent
a1ce96bc4a
commit
e81589e77d
|
@ -5,3 +5,6 @@ target_link_libraries( shelltest ${KDE4_KDECORE_LIBS} ${QT_QTTEST_LIBRARY} )
|
|||
|
||||
kde4_add_unit_test( parttest parttest.cpp )
|
||||
target_link_libraries( parttest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} okularpart )
|
||||
|
||||
kde4_add_unit_test( searchtest searchtest.cpp )
|
||||
target_link_libraries( searchtest ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${QT_QTTEST_LIBRARY} okularcore )
|
||||
|
|
82
tests/searchtest.cpp
Normal file
82
tests/searchtest.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2013 by Albert Astals Cid <aacid@kde.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest_kde.h>
|
||||
|
||||
#include "../core/document.h"
|
||||
#include "../settings_core.h"
|
||||
|
||||
Q_DECLARE_METATYPE(Okular::Document::SearchStatus)
|
||||
|
||||
class SearchFinishedReceiver : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void searchFinished(int id, Okular::Document::SearchStatus status)
|
||||
{
|
||||
m_id = id;
|
||||
m_status = status;
|
||||
}
|
||||
|
||||
public:
|
||||
int m_id;
|
||||
Okular::Document::SearchStatus m_status;
|
||||
};
|
||||
|
||||
class SearchTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void test311232();
|
||||
};
|
||||
|
||||
void SearchTest::initTestCase()
|
||||
{
|
||||
qRegisterMetaType<Okular::Document::SearchStatus>();
|
||||
}
|
||||
|
||||
void SearchTest::test311232()
|
||||
{
|
||||
Okular::SettingsCore::instance( "searchtest" );
|
||||
Okular::Document d(0);
|
||||
SearchFinishedReceiver receiver;
|
||||
QSignalSpy spy(&d, SIGNAL(searchFinished(int,Okular::Document::SearchStatus)));
|
||||
|
||||
QObject::connect(&d, SIGNAL(searchFinished(int,Okular::Document::SearchStatus)), &receiver, SLOT(searchFinished(int,Okular::Document::SearchStatus)));
|
||||
|
||||
const QString testFile = KDESRCDIR "data/file1.pdf";
|
||||
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
|
||||
d.openDocument(testFile, KUrl(), mime);
|
||||
|
||||
const int searchId = 0;
|
||||
d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor(), true);
|
||||
QTime t;
|
||||
t.start();
|
||||
while (spy.count() != 1 && t.elapsed() < 500)
|
||||
qApp->processEvents();
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QCOMPARE(receiver.m_id, searchId);
|
||||
QCOMPARE(receiver.m_status, Okular::Document::MatchFound);
|
||||
|
||||
|
||||
d.continueSearch( searchId, Okular::Document::PreviousMatch );
|
||||
t.start();
|
||||
while (spy.count() != 2 && t.elapsed() < 500)
|
||||
qApp->processEvents();
|
||||
QCOMPARE(spy.count(), 2);
|
||||
QCOMPARE(receiver.m_id, searchId);
|
||||
QCOMPARE(receiver.m_status, Okular::Document::NoMatchFound);
|
||||
}
|
||||
|
||||
QTEST_KDEMAIN( SearchTest, GUI )
|
||||
|
||||
#include "searchtest.moc"
|
Loading…
Reference in a new issue