You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
4.0 KiB
120 lines
4.0 KiB
/*************************************************************************** |
|
* 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 "../part.h" |
|
#include "../ui/toc.h" |
|
|
|
#include <KStandardDirs> |
|
#include <KTempDir> |
|
|
|
#include <QTreeView> |
|
|
|
namespace Okular |
|
{ |
|
class PartTest |
|
: public QObject |
|
{ |
|
Q_OBJECT |
|
|
|
private slots: |
|
void testReload(); |
|
void testTOCReload(); |
|
void testFowardPDF(); |
|
void testFowardPDF_data(); |
|
}; |
|
|
|
void PartTest::testReload() |
|
{ |
|
QVariantList dummyArgs; |
|
Okular::Part part(NULL, NULL, dummyArgs, KGlobal::mainComponent()); |
|
part.openDocument(KDESRCDIR "data/file1.pdf"); |
|
part.reload(); |
|
qApp->processEvents(); |
|
} |
|
|
|
void PartTest::testTOCReload() |
|
{ |
|
QVariantList dummyArgs; |
|
Okular::Part part(NULL, NULL, dummyArgs, KGlobal::mainComponent()); |
|
part.openDocument(KDESRCDIR "data/tocreload.pdf"); |
|
QCOMPARE(part.m_toc->expandedNodes().count(), 0); |
|
part.m_toc->m_treeView->expandAll(); |
|
QCOMPARE(part.m_toc->expandedNodes().count(), 3); |
|
part.reload(); |
|
qApp->processEvents(); |
|
QCOMPARE(part.m_toc->expandedNodes().count(), 3); |
|
} |
|
|
|
void PartTest::testFowardPDF() |
|
{ |
|
QFETCH(QString, dir); |
|
|
|
QVariantList dummyArgs; |
|
Okular::Part part(NULL, NULL, dummyArgs, KGlobal::mainComponent()); |
|
|
|
KTempDir tempDir(dir); |
|
QFile f(KDESRCDIR "data/synctextest.tex"); |
|
const QString texDestination = tempDir.name() + "synctextest.tex"; |
|
QVERIFY(f.copy(texDestination)); |
|
|
|
QProcess process; |
|
process.setWorkingDirectory(tempDir.name()); |
|
process.start("pdflatex", QStringList() << "-synctex=1" << "-interaction=nonstopmode" << texDestination); |
|
process.waitForFinished(); |
|
|
|
const QString pdfResult = tempDir.name() + "synctextest.pdf"; |
|
|
|
QVERIFY(QFile::exists(pdfResult)); |
|
|
|
part.openDocument(pdfResult); |
|
part.m_document->setViewportPage(0); |
|
QCOMPARE(part.m_document->currentPage(), 0u); |
|
part.closeUrl(); |
|
|
|
KUrl u(pdfResult); |
|
u.setHTMLRef("src:100" + texDestination); |
|
part.openUrl(u); |
|
QCOMPARE(part.m_document->currentPage(), 1u); |
|
} |
|
|
|
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("ßðđđŋßðđŋ")); |
|
} |
|
|
|
} |
|
|
|
int main(int argc, char *argv[]) |
|
{ |
|
// This is QTEST_KDEMAIN withouth the LC_ALL set |
|
setenv("LC_ALL", "en_US.UTF-8", 1); |
|
assert( !QDir::homePath().isEmpty() ); |
|
setenv("KDEHOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test") ), 1); |
|
setenv("XDG_DATA_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/local") ), 1); |
|
setenv("XDG_CONFIG_HOME", QFile::encodeName( QDir::homePath() + QString::fromLatin1("/.kde-unit-test/xdg/config") ), 1); |
|
setenv("KDE_SKIP_KDERC", "1", 1); |
|
unsetenv("KDE_COLOR_DEBUG"); |
|
QFile::remove(QDir::homePath() + QString::fromLatin1("/.kde-unit-test/share/config/qttestrc")); |
|
KAboutData aboutData( QByteArray("qttest"), QByteArray(), ki18n("KDE Test Program"), QByteArray("version") ); |
|
KComponentData cData(&aboutData); |
|
QApplication app( argc, argv ); |
|
app.setApplicationName( QLatin1String("qttest") ); |
|
qRegisterMetaType<KUrl>(); /*as done by kapplication*/ |
|
qRegisterMetaType<KUrl::List>(); |
|
Okular::PartTest test; |
|
KGlobal::ref(); /* don't quit qeventloop after closing a mainwindow */ |
|
return QTest::qExec( &test, argc, argv ); |
|
} |
|
|
|
#include "parttest.moc"
|
|
|