summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio D'Urso <fabiodurso@hotmail.it>2014-08-23 17:09:18 (GMT)
committerFabio D'Urso <fabiodurso@hotmail.it>2014-08-23 19:40:01 (GMT)
commit2a52e0c4e143249644697cf534806135cd34e409 (patch)
tree090d80493dc19e2fc6662d59d40c3457f92ec452
parent12810d361dfb8701463a851da266e376b4de6302 (diff)
Ported tests to QtTest, added missing trailing / to KDESRCDIR
I've also added some extra checks so that tests fail early instead of crashing later if a document fails to be opened
-rw-r--r--generators/kimgio/tests/kimgiotest.cpp6
-rw-r--r--tests/CMakeLists.txt10
-rw-r--r--tests/addremoveannotationtest.cpp6
-rw-r--r--tests/annotationstest.cpp12
-rw-r--r--tests/documenttest.cpp12
-rw-r--r--tests/editannotationcontentstest.cpp7
-rw-r--r--tests/editformstest.cpp7
-rw-r--r--tests/mainshelltest.cpp6
-rw-r--r--tests/modifyannotationpropertiestest.cpp7
-rw-r--r--tests/parttest.cpp39
-rw-r--r--tests/searchtest.cpp5
-rw-r--r--tests/shelltest.cpp7
-rw-r--r--tests/translateannotationtest.cpp7
-rw-r--r--tests/urldetecttest.cpp5
14 files changed, 77 insertions, 59 deletions
diff --git a/generators/kimgio/tests/kimgiotest.cpp b/generators/kimgio/tests/kimgiotest.cpp
index 3a578b3..99f3ff9 100644
--- a/generators/kimgio/tests/kimgiotest.cpp
+++ b/generators/kimgio/tests/kimgiotest.cpp
@@ -7,7 +7,6 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
#include "../generator_kimgio.h"
#include "../../settings_core.h"
@@ -16,7 +15,8 @@
#include <core/page.h>
#include <ui/pagepainter.h>
-#include <KTempDir>
+#include <QtTest>
+
#include <QImage>
#include <QPainter>
#include <QTemporaryFile>
@@ -97,5 +97,5 @@ void KIMGIOTest::testExifOrientation()
delete m_document;
}
-QTEST_KDEMAIN( KIMGIOTest, GUI )
+QTEST_MAIN(KIMGIOTest)
#include "kimgiotest.moc"
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9454a15..0a0f546 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,5 @@
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
-add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}" )
+add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" )
include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
@@ -13,10 +13,10 @@ ecm_add_test(parttest parttest.cpp
LINK_LIBRARIES Qt5::Widgets Qt5::Test Qt5::Xml okularcore okularpart KF5::KDELibs4Support
)
-#ecm_add_test(documenttest documenttest.cpp
-# TEST_NAME "documenttest"
-# LINK_LIBRARIES Qt5::Widgets Qt5::Test Qt5::Xml okularcore KF5::KDELibs4Support
-#)
+ecm_add_test(documenttest documenttest.cpp
+ TEST_NAME "documenttest"
+ LINK_LIBRARIES Qt5::Widgets Qt5::Test Qt5::Xml okularcore KF5::KDELibs4Support KF5::ThreadWeaver
+)
ecm_add_test(searchtest searchtest.cpp
TEST_NAME "searchtest"
diff --git a/tests/addremoveannotationtest.cpp b/tests/addremoveannotationtest.cpp
index 27d77b7..42e5b1b 100644
--- a/tests/addremoveannotationtest.cpp
+++ b/tests/addremoveannotationtest.cpp
@@ -7,7 +7,7 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
#include "../core/document.h"
#include "../core/page.h"
@@ -41,7 +41,7 @@ void AddRemoveAnnotationTest::init()
{
const QString testFile = KDESRCDIR "data/file1.pdf";
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
- m_document->openDocument(testFile, KUrl(), mime);
+ QCOMPARE( m_document->openDocument(testFile, KUrl(), mime), Okular::Document::OpenSuccess );
}
void AddRemoveAnnotationTest::cleanup()
@@ -186,5 +186,5 @@ void AddRemoveAnnotationTest::testRemoveAnnotations()
QVERIFY( TestingUtils::AnnotationDisposeWatcher::disposedAnnotationName() == annot1Name );
}
-QTEST_KDEMAIN( AddRemoveAnnotationTest, GUI )
+QTEST_MAIN( AddRemoveAnnotationTest )
#include "addremoveannotationtest.moc"
diff --git a/tests/annotationstest.cpp b/tests/annotationstest.cpp
index 7dd3e1b..830ef37 100644
--- a/tests/annotationstest.cpp
+++ b/tests/annotationstest.cpp
@@ -7,7 +7,7 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
#include "../core/document.h"
#include "../core/page.h"
@@ -42,13 +42,14 @@ void AnnotationTest::initTestCase()
m_document = new Okular::Document( 0 );
const QString testFile = KDESRCDIR "data/file1.pdf";
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
- m_document->openDocument(testFile, KUrl(), mime);
+ QCOMPARE( m_document->openDocument(testFile, KUrl(), mime), Okular::Document::OpenSuccess );
}
void AnnotationTest::cleanupTestCase()
{
- foreach ( Okular::Annotation* annotation, m_document->page( 0 )->annotations() )
- m_document->removePageAnnotation( 0, annotation );
+ if ( m_document->isOpened() )
+ foreach ( Okular::Annotation* annotation, m_document->page( 0 )->annotations() )
+ m_document->removePageAnnotation( 0, annotation );
}
@@ -139,6 +140,5 @@ void AnnotationTest::testDistance_data()
}
-QTEST_KDEMAIN( AnnotationTest, GUI )
-
+QTEST_MAIN( AnnotationTest )
#include "annotationstest.moc"
diff --git a/tests/documenttest.cpp b/tests/documenttest.cpp
index 8a56136..6b11dc7 100644
--- a/tests/documenttest.cpp
+++ b/tests/documenttest.cpp
@@ -7,9 +7,9 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
-#include <threadweaver/ThreadWeaver.h>
+#include <threadweaver/queue.h>
#include "../core/document.h"
#include "../core/generator.h"
@@ -42,7 +42,7 @@ void DocumentTest::testCloseDuringRotationJob()
m_document->setRotation( 1 );
// Tell ThreadWeaver not to start any new job
- ThreadWeaver::Weaver::instance()->suspend();
+ ThreadWeaver::Queue::instance()->suspend();
// Request a pixmap. A RotationJob will be enqueued but not started
Okular::PixmapRequest *pixmapReq = new Okular::PixmapRequest(
@@ -53,10 +53,10 @@ void DocumentTest::testCloseDuringRotationJob()
delete m_document;
// Resume job processing and wait for the RotationJob to finish
- ThreadWeaver::Weaver::instance()->resume();
- ThreadWeaver::Weaver::instance()->finish();
+ ThreadWeaver::Queue::instance()->resume();
+ ThreadWeaver::Queue::instance()->finish();
qApp->processEvents();
}
-QTEST_KDEMAIN( DocumentTest, GUI )
+QTEST_MAIN( DocumentTest )
#include "documenttest.moc"
diff --git a/tests/editannotationcontentstest.cpp b/tests/editannotationcontentstest.cpp
index 2b34bd2..fba1c45 100644
--- a/tests/editannotationcontentstest.cpp
+++ b/tests/editannotationcontentstest.cpp
@@ -7,7 +7,8 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
+
#include <kmimetype.h>
#include "../settings_core.h"
#include "core/annotations.h"
@@ -105,7 +106,7 @@ void EditAnnotationContentsTest::init()
{
const QString testFile = KDESRCDIR "data/file1.pdf";
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
- m_document->openDocument(testFile, KUrl(), mime);
+ QCOMPARE( m_document->openDocument(testFile, KUrl(), mime), Okular::Document::OpenSuccess );
// Undo and Redo should be unavailable when docuemnt is first opened.
QVERIFY( !m_document->canUndo() );
@@ -515,5 +516,5 @@ void EditAnnotationContentsTest::testCombinations()
QCOMPARE( 12, m_editor1->anchorPos() );
}
-QTEST_KDEMAIN( EditAnnotationContentsTest, GUI )
+QTEST_MAIN( EditAnnotationContentsTest )
#include "editannotationcontentstest.moc"
diff --git a/tests/editformstest.cpp b/tests/editformstest.cpp
index bc192c9..5c9f537 100644
--- a/tests/editformstest.cpp
+++ b/tests/editformstest.cpp
@@ -7,7 +7,8 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
+
#include <kmimetype.h>
#include "../settings_core.h"
#include "core/document.h"
@@ -65,7 +66,7 @@ void EditFormsTest::init()
{
const QString testFile = KDESRCDIR "data/formSamples.pdf";
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
- m_document->openDocument( testFile, KUrl(), mime );
+ QCOMPARE( m_document->openDocument(testFile, KUrl(), mime), Okular::Document::OpenSuccess );
// Undo and Redo should be unavailable when docuemnt is first opened.
QVERIFY( !m_document->canUndo() );
@@ -427,5 +428,5 @@ void EditFormsTest::verifyTextForm( Okular::FormFieldText* form )
QVERIFY( m_document->canRedo() );
}
-QTEST_KDEMAIN( EditFormsTest, GUI )
+QTEST_MAIN( EditFormsTest )
#include "editformstest.moc"
diff --git a/tests/mainshelltest.cpp b/tests/mainshelltest.cpp
index c5d7289..42d0aac 100644
--- a/tests/mainshelltest.cpp
+++ b/tests/mainshelltest.cpp
@@ -7,9 +7,11 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
+
#include <qprintdialog.h>
#include <qwidget.h>
+#include <kglobal.h>
#include <ktabwidget.h>
#include "../shell/okular_main.h"
@@ -468,5 +470,5 @@ void MainShellTest::test2FilesError()
}
-QTEST_KDEMAIN( MainShellTest, GUI )
+QTEST_MAIN( MainShellTest )
#include "mainshelltest.moc"
diff --git a/tests/modifyannotationpropertiestest.cpp b/tests/modifyannotationpropertiestest.cpp
index 16d9f9b..802d181 100644
--- a/tests/modifyannotationpropertiestest.cpp
+++ b/tests/modifyannotationpropertiestest.cpp
@@ -7,7 +7,8 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
+
#include <kmimetype.h>
#include "../settings_core.h"
#include <core/area.h>
@@ -51,7 +52,7 @@ void ModifyAnnotationPropertiesTest::init()
{
const QString testFile = KDESRCDIR "data/file1.pdf";
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
- m_document->openDocument(testFile, KUrl(), mime);
+ QCOMPARE( m_document->openDocument(testFile, KUrl(), mime), Okular::Document::OpenSuccess );
// Undo and Redo should be unavailable when docuemnt is first opened.
QVERIFY( !m_document->canUndo() );
@@ -164,5 +165,5 @@ void ModifyAnnotationPropertiesTest::testModifyAnnotationPropertiesWithRotation_
QCOMPARE( transformedBoundingRect, m_annot1->transformedBoundingRectangle() );
}
-QTEST_KDEMAIN( ModifyAnnotationPropertiesTest, GUI )
+QTEST_MAIN( ModifyAnnotationPropertiesTest )
#include "modifyannotationpropertiestest.moc"
diff --git a/tests/parttest.cpp b/tests/parttest.cpp
index dd34688..dab23f6 100644
--- a/tests/parttest.cpp
+++ b/tests/parttest.cpp
@@ -7,12 +7,13 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
#include "../part.h"
#include "../ui/toc.h"
#include <KConfigDialog>
+#include <KGlobal>
#include <KStandardDirs>
#include <KTempDir>
#include <K4AboutData>
@@ -26,6 +27,8 @@ class PartTest
{
Q_OBJECT
+ static bool openDocument(Okular::Part *part, const QString &filePath);
+
private slots:
void testReload();
void testCanceledReload();
@@ -62,12 +65,18 @@ class PartThatHijacksQueryClose : public Okular::Part
Behavior behavior;
};
+bool PartTest::openDocument(Okular::Part *part, const QString &filePath)
+{
+ part->openDocument( filePath );
+ return part->m_document->isOpened();
+}
+
// Test that Okular doesn't crash after a successful reload
void PartTest::testReload()
{
QVariantList dummyArgs;
Okular::Part part(NULL, NULL, dummyArgs);
- part.openDocument(KDESRCDIR "data/file1.pdf");
+ QVERIFY( openDocument(&part, KDESRCDIR "data/file1.pdf") );
part.reload();
qApp->processEvents();
}
@@ -77,7 +86,7 @@ void PartTest::testCanceledReload()
{
QVariantList dummyArgs;
PartThatHijacksQueryClose part(NULL, NULL, dummyArgs, KGlobal::mainComponent());
- part.openDocument(KDESRCDIR "data/file1.pdf");
+ QVERIFY( openDocument(&part, KDESRCDIR "data/file1.pdf") );
// When queryClose() returns false, the reload operation is canceled (as if
// the user had chosen Cancel in the "Save changes?" message box)
@@ -92,7 +101,7 @@ void PartTest::testTOCReload()
{
QVariantList dummyArgs;
Okular::Part part(NULL, NULL, dummyArgs);
- part.openDocument(KDESRCDIR "data/tocreload.pdf");
+ QVERIFY( openDocument(&part, KDESRCDIR "data/tocreload.pdf") );
QCOMPARE(part.m_toc->expandedNodes().count(), 0);
part.m_toc->m_treeView->expandAll();
QCOMPARE(part.m_toc->expandedNodes().count(), 3);
@@ -108,21 +117,24 @@ void PartTest::testFowardPDF()
QVariantList dummyArgs;
Okular::Part part(NULL, NULL, dummyArgs);
- KTempDir tempDir(dir);
+ // Create temp dir named like this: ${system temp dir}/${random string}/${dir}
+ const QTemporaryDir tempDir;
+ const QDir workDir(QDir(tempDir.path()).filePath(dir));
+ workDir.mkpath(".");
+
QFile f(KDESRCDIR "data/synctextest.tex");
- const QString texDestination = tempDir.name() + "synctextest.tex";
+ const QString texDestination = workDir.path() + "/synctextest.tex";
QVERIFY(f.copy(texDestination));
-
QProcess process;
- process.setWorkingDirectory(tempDir.name());
+ process.setWorkingDirectory(workDir.path());
process.start("pdflatex", QStringList() << "-synctex=1" << "-interaction=nonstopmode" << texDestination);
process.waitForFinished();
- const QString pdfResult = tempDir.name() + "synctextest.pdf";
+ const QString pdfResult = workDir.path() + "/synctextest.pdf";
QVERIFY(QFile::exists(pdfResult));
- part.openDocument(pdfResult);
+ QVERIFY( openDocument(&part, pdfResult) );
part.m_document->setViewportPage(0);
QCOMPARE(part.m_document->currentPage(), 0u);
part.closeUrl();
@@ -137,8 +149,8 @@ void PartTest::testFowardPDF_data()
{
QTest::addColumn<QString>("dir");
- QTest::newRow("non-utf8") << QString(KGlobal::dirs()->resourceDirs("tmp")[0] + QString::fromUtf8("synctextest"));
- QTest::newRow("utf8") << QString(KGlobal::dirs()->resourceDirs("tmp")[0] + QString::fromUtf8("ßðđđŋßðđŋ"));
+ QTest::newRow("non-utf8") << QString::fromUtf8("synctextest");
+ QTest::newRow("utf8") << QString::fromUtf8("ßðđđŋßðđŋ");
}
void PartTest::testGeneratorPreferences()
@@ -163,9 +175,10 @@ void PartTest::testGeneratorPreferences()
int main(int argc, char *argv[])
{
+#pragma message("KF5 What to do with this?")
// This is QTEST_KDEMAIN withouth the LC_ALL set
setenv("LC_ALL", "en_US.UTF-8", 1);
- assert( !QDir::homePath().isEmpty() );
+ Q_ASSERT( !QDir::homePath().isEmpty() );
setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test") ).constData(), 1);
setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/local") ).constData(), 1);
setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/config") ).constData(), 1);
diff --git a/tests/searchtest.cpp b/tests/searchtest.cpp
index 08648d9..ab459af 100644
--- a/tests/searchtest.cpp
+++ b/tests/searchtest.cpp
@@ -7,7 +7,7 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
#include "../core/document.h"
#include "../core/page.h"
@@ -429,6 +429,5 @@ void SearchTest::testTwoColumns()
delete page;
}
-QTEST_KDEMAIN( SearchTest, GUI )
-
+QTEST_MAIN( SearchTest )
#include "searchtest.moc"
diff --git a/tests/shelltest.cpp b/tests/shelltest.cpp
index b6edd23..9a4a86c 100644
--- a/tests/shelltest.cpp
+++ b/tests/shelltest.cpp
@@ -7,8 +7,10 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
+
#include <qdir.h>
+#include <kcmdlineargs.h>
#include <kurl.h>
#include "../shell/shellutils.h"
@@ -116,6 +118,5 @@ void ShellTest::testUrlArgs()
QCOMPARE( url, resUrl );
}
-QTEST_KDEMAIN_CORE( ShellTest )
-
+QTEST_GUILESS_MAIN( ShellTest )
#include "shelltest.moc"
diff --git a/tests/translateannotationtest.cpp b/tests/translateannotationtest.cpp
index 184b947..7d53a9d 100644
--- a/tests/translateannotationtest.cpp
+++ b/tests/translateannotationtest.cpp
@@ -7,7 +7,8 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
+
#include <kmimetype.h>
#include "../settings_core.h"
#include "core/annotations.h"
@@ -107,7 +108,7 @@ void TranslateAnnotationTest::init()
{
const QString testFile = KDESRCDIR "data/file1.pdf";
const KMimeType::Ptr mime = KMimeType::findByPath( testFile );
- m_document->openDocument(testFile, KUrl(), mime);
+ QCOMPARE( m_document->openDocument(testFile, KUrl(), mime), Okular::Document::OpenSuccess );
// Undo and Redo should be unavailable when docuemnt is first opened.
QVERIFY( !m_document->canUndo() );
@@ -233,5 +234,5 @@ void TranslateAnnotationTest::testAlternateTranslationsNotMerged()
-QTEST_KDEMAIN( TranslateAnnotationTest, GUI )
+QTEST_MAIN( TranslateAnnotationTest )
#include "translateannotationtest.moc"
diff --git a/tests/urldetecttest.cpp b/tests/urldetecttest.cpp
index b90d272..5cd2f54 100644
--- a/tests/urldetecttest.cpp
+++ b/tests/urldetecttest.cpp
@@ -7,7 +7,7 @@
* (at your option) any later version. *
***************************************************************************/
-#include <qtest_kde.h>
+#include <QtTest>
#include "../ui/url_utils.h"
@@ -52,6 +52,5 @@ void UrlDetectTest::testURL_data()
}
-QTEST_KDEMAIN_CORE( Okular::UrlDetectTest )
-
+QTEST_MAIN( Okular::UrlDetectTest )
#include "urldetecttest.moc"