Changeset View
Changeset View
Standalone View
Standalone View
autotests/mainshelltest.cpp
Show All 13 Lines | |||||
14 | #include <qtabwidget.h> | 14 | #include <qtabwidget.h> | ||
15 | #include <QStandardPaths> | 15 | #include <QStandardPaths> | ||
16 | #include <kconfiggroup.h> | 16 | #include <kconfiggroup.h> | ||
17 | 17 | | |||
18 | #include "../shell/okular_main.h" | 18 | #include "../shell/okular_main.h" | ||
19 | #include "../shell/shell.h" | 19 | #include "../shell/shell.h" | ||
20 | #include "../shell/shellutils.h" | 20 | #include "../shell/shellutils.h" | ||
21 | #include "../core/document_p.h" | 21 | #include "../core/document_p.h" | ||
22 | #include "../ui/findbar.h" | ||||
22 | #include "../ui/presentationwidget.h" | 23 | #include "../ui/presentationwidget.h" | ||
23 | #include "../part.h" | 24 | #include "../part.h" | ||
24 | #include "../settings.h" | 25 | #include "../settings.h" | ||
25 | 26 | | |||
26 | #include <sys/types.h> | 27 | #include <sys/types.h> | ||
27 | #ifndef Q_OS_WIN | 28 | #ifndef Q_OS_WIN | ||
28 | #include <unistd.h> | 29 | #include <unistd.h> | ||
29 | #else | 30 | #else | ||
30 | #include <process.h> | 31 | #include <process.h> | ||
31 | #endif | 32 | #endif | ||
32 | 33 | | |||
33 | namespace Okular { | 34 | namespace Okular { | ||
34 | class PartTest | 35 | class PartTest | ||
35 | { | 36 | { | ||
36 | public: | 37 | public: | ||
37 | Okular::Document *partDocument(Okular::Part *part) const { | 38 | Okular::Document *partDocument(Okular::Part *part) const { | ||
38 | return part->m_document; | 39 | return part->m_document; | ||
39 | } | 40 | } | ||
40 | QWidget *presentationWidget(Okular::Part *part) const { | 41 | QWidget *presentationWidget(Okular::Part *part) const { | ||
41 | return part->m_presentationWidget; | 42 | return part->m_presentationWidget; | ||
42 | } | 43 | } | ||
44 | FindBar *findWidget(Okular::Part *part) const { | ||||
45 | return part->m_findBar; | ||||
46 | } | ||||
43 | }; | 47 | }; | ||
44 | } | 48 | } | ||
45 | 49 | | |||
46 | class ClosePrintDialogHelper : public QObject | 50 | class ClosePrintDialogHelper : public QObject | ||
47 | { | 51 | { | ||
48 | Q_OBJECT | 52 | Q_OBJECT | ||
49 | 53 | | |||
50 | public: | 54 | public: | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 170 | { | |||
170 | QTest::addColumn<QString>("externalProcessPath"); | 174 | QTest::addColumn<QString>("externalProcessPath"); | ||
171 | QTest::addColumn<uint>("expectedPage"); | 175 | QTest::addColumn<uint>("expectedPage"); | ||
172 | QTest::addColumn<bool>("expectPresentation"); | 176 | QTest::addColumn<bool>("expectPresentation"); | ||
173 | QTest::addColumn<bool>("expectPrintDialog"); | 177 | QTest::addColumn<bool>("expectPrintDialog"); | ||
174 | QTest::addColumn<bool>("unique"); | 178 | QTest::addColumn<bool>("unique"); | ||
175 | QTest::addColumn<uint>("externalProcessExpectedPage"); | 179 | QTest::addColumn<uint>("externalProcessExpectedPage"); | ||
176 | QTest::addColumn<bool>("externalProcessExpectPresentation"); | 180 | QTest::addColumn<bool>("externalProcessExpectPresentation"); | ||
177 | QTest::addColumn<bool>("externalProcessExpectPrintDialog"); | 181 | QTest::addColumn<bool>("externalProcessExpectPrintDialog"); | ||
182 | QTest::addColumn<QString>("externalProcessExpectFind"); | ||||
178 | 183 | | |||
179 | const QStringList contentsEpub = QStringList(QStringLiteral(KDESRCDIR "data/contents.epub")); | 184 | const QStringList contentsEpub = QStringList(QStringLiteral(KDESRCDIR "data/contents.epub")); | ||
180 | const QStringList file1 = QStringList(QStringLiteral(KDESRCDIR "data/file1.pdf")); | 185 | const QStringList file1 = QStringList(QStringLiteral(KDESRCDIR "data/file1.pdf")); | ||
181 | QStringList file1AndToc; | 186 | QStringList file1AndToc; | ||
182 | file1AndToc << QStringLiteral(KDESRCDIR "data/file1.pdf"); | 187 | file1AndToc << QStringLiteral(KDESRCDIR "data/file1.pdf"); | ||
183 | file1AndToc << QStringLiteral(KDESRCDIR "data/tocreload.pdf"); | 188 | file1AndToc << QStringLiteral(KDESRCDIR "data/tocreload.pdf"); | ||
184 | const QString tocReload = QStringLiteral(KDESRCDIR "data/tocreload.pdf"); | 189 | const QString tocReload = QStringLiteral(KDESRCDIR "data/tocreload.pdf"); | ||
185 | 190 | | |||
186 | const QString optionsPage2 = ShellUtils::serializeOptions(false, false, false, false, false, QStringLiteral("2")); | 191 | const QString optionsPage2 = ShellUtils::serializeOptions(false, false, false, false, false, QStringLiteral("2"), QString()); | ||
187 | const QString optionsPage2Presentation = ShellUtils::serializeOptions(true, false, false, false, false, QStringLiteral("2")); | 192 | const QString optionsPage2Presentation = ShellUtils::serializeOptions(true, false, false, false, false, QStringLiteral("2"), QString()); | ||
188 | const QString optionsPrint = ShellUtils::serializeOptions(false, true, false, false, false, QString()); | 193 | const QString optionsPrint = ShellUtils::serializeOptions(false, true, false, false, false, QString(), QString()); | ||
189 | const QString optionsUnique = ShellUtils::serializeOptions(false, false, false, true, false, QString()); | 194 | const QString optionsUnique = ShellUtils::serializeOptions(false, false, false, true, false, QString(), QString()); | ||
190 | 195 | const QString optionsFind = ShellUtils::serializeOptions(false, false, false, false ,false , QString(), QStringLiteral("si:next-testing parameters!")); | |||
191 | QTest::newRow("just show shell") << QStringList() << QString() << false << QString() << 0u << false << false << false << 0u << false << false; | 196 | | ||
192 | QTest::newRow("open file") << file1 << QString() << false << QString() << 0u << false << false << false << 0u << false << false; | 197 | QTest::newRow("just show shell") << QStringList() << QString() << false << QString() << 0u << false << false << false << 0u << false << false << QString(); | ||
193 | QTest::newRow("two files no tabs") << file1AndToc << QString() << false << QString() << 0u << false << false << false << 0u << false << false; | 198 | QTest::newRow("open file") << file1 << QString() << false << QString() << 0u << false << false << false << 0u << false << false << QString(); | ||
194 | QTest::newRow("two files with tabs") << file1AndToc << QString() << true << QString() << 0u << false << false << false << 0u << false << false; | 199 | QTest::newRow("two files no tabs") << file1AndToc << QString() << false << QString() << 0u << false << false << false << 0u << false << false << QString(); | ||
195 | QTest::newRow("two files sequence no tabs") << file1 << QString() << false << tocReload << 0u << false << false << false << 0u << false << false; | 200 | QTest::newRow("two files with tabs") << file1AndToc << QString() << true << QString() << 0u << false << false << false << 0u << false << false << QString(); | ||
196 | QTest::newRow("two files sequence with tabs") << file1 << QString() << true << tocReload << 0u << false << false << false << 0u << false << false; | 201 | QTest::newRow("two files sequence no tabs") << file1 << QString() << false << tocReload << 0u << false << false << false << 0u << false << false << QString(); | ||
197 | QTest::newRow("open file page number") << contentsEpub << optionsPage2 << false << QString() << 1u << false << false << false << 0u << false << false; | 202 | QTest::newRow("two files sequence with tabs") << file1 << QString() << true << tocReload << 0u << false << false << false << 0u << false << false << QString(); | ||
198 | QTest::newRow("open file page number and presentation") << contentsEpub << optionsPage2Presentation << false << QString() << 1u << true << false << false << 0u << false << false; | 203 | QTest::newRow("open file page number") << contentsEpub << optionsPage2 << false << QString() << 1u << false << false << false << 0u << false << false << QString(); | ||
199 | QTest::newRow("open file print") << file1 << optionsPrint << false << QString() << 0u << false << true << false << 0u << false << false; | 204 | QTest::newRow("open file page number and presentation") << contentsEpub << optionsPage2Presentation << false << QString() << 1u << true << false << false << 0u << false << false << QString(); | ||
200 | QTest::newRow("open two files unique") << file1 << optionsUnique << false << tocReload << 0u << false << false << true << 0u << false << false; | 205 | QTest::newRow("open file find") << file1 << optionsFind << false << QString() << 0u << false << false << false << 0u << false << false << QString("si:next-testing parameters!"); | ||
201 | QTest::newRow("open two files unique tabs") << file1 << optionsUnique << true << tocReload << 0u << false << false << true << 0u << false << false; | 206 | QTest::newRow("open file print") << file1 << optionsPrint << false << QString() << 0u << false << true << false << 0u << false << false << QString(); | ||
202 | QTest::newRow("page number attach tabs") << file1 << QString() << true << contentsEpub[0] << 0u << false << false << false << 2u << false << false; | 207 | QTest::newRow("open two files unique") << file1 << optionsUnique << false << tocReload << 0u << false << false << true << 0u << false << false << QString(); | ||
203 | QTest::newRow("presentation attach tabs") << file1 << QString() << true << contentsEpub[0] << 0u << false << false << false << 2u << true << false; | 208 | QTest::newRow("open two files unique tabs") << file1 << optionsUnique << true << tocReload << 0u << false << false << true << 0u << false << false << QString(); | ||
204 | QTest::newRow("print attach tabs") << file1 << QString() << true << contentsEpub[0] << 0u << false << true << false << 2u << false << true; | 209 | QTest::newRow("page number attach tabs") << file1 << QString() << true << contentsEpub[0] << 0u << false << false << false << 2u << false << false << QString(); | ||
205 | QTest::newRow("page number attach unique") << file1 << optionsUnique << false << contentsEpub[0] << 0u << false << false << true << 3u << false << false; | 210 | QTest::newRow("presentation attach tabs") << file1 << QString() << true << contentsEpub[0] << 0u << false << false << false << 2u << true << false << QString(); | ||
206 | QTest::newRow("presentation attach unique") << file1 << optionsUnique << false << contentsEpub[0] << 0u << false << false << true << 2u << true << false; | 211 | QTest::newRow("print attach tabs") << file1 << QString() << true << contentsEpub[0] << 0u << false << true << false << 2u << false << true << QString(); | ||
207 | QTest::newRow("print attach unique") << file1 << optionsUnique << false << contentsEpub[0] << 0u << false << false << true << 2u << false << true; | 212 | QTest::newRow("page number attach unique") << file1 << optionsUnique << false << contentsEpub[0] << 0u << false << false << true << 3u << false << false << QString(); | ||
208 | QTest::newRow("page number attach unique tabs") << file1 << optionsUnique << true << contentsEpub[0] << 0u << false << false << true << 3u << false << false; | 213 | QTest::newRow("presentation attach unique") << file1 << optionsUnique << false << contentsEpub[0] << 0u << false << false << true << 2u << true << false << QString(); | ||
209 | QTest::newRow("presentation attach unique tabs") << file1 << optionsUnique << true << contentsEpub[0] << 0u << false << false << true << 2u << true << false; | 214 | QTest::newRow("print attach unique") << file1 << optionsUnique << false << contentsEpub[0] << 0u << false << false << true << 2u << false << true << QString(); | ||
210 | QTest::newRow("print attach unique tabs") << file1 << optionsUnique << true << contentsEpub[0] << 0u << false << false << true << 2u << false << true; | 215 | QTest::newRow("page number attach unique tabs") << file1 << optionsUnique << true << contentsEpub[0] << 0u << false << false << true << 3u << false << false << QString(); | ||
216 | QTest::newRow("presentation attach unique tabs") << file1 << optionsUnique << true << contentsEpub[0] << 0u << false << false << true << 2u << true << false << QString(); | ||||
217 | QTest::newRow("print attach unique tabs") << file1 << optionsUnique << true << contentsEpub[0] << 0u << false << false << true << 2u << false << true << QString(); | ||||
211 | } | 218 | } | ||
212 | 219 | | |||
213 | void MainShellTest::testShell() | 220 | void MainShellTest::testShell() | ||
214 | { | 221 | { | ||
215 | QFETCH(QStringList, paths); | 222 | QFETCH(QStringList, paths); | ||
216 | QFETCH(QString, serializedOptions); | 223 | QFETCH(QString, serializedOptions); | ||
217 | QFETCH(bool, useTabs); | 224 | QFETCH(bool, useTabs); | ||
218 | QFETCH(QString, externalProcessPath); | 225 | QFETCH(QString, externalProcessPath); | ||
219 | QFETCH(uint, expectedPage); | 226 | QFETCH(uint, expectedPage); | ||
220 | QFETCH(bool, expectPresentation); | 227 | QFETCH(bool, expectPresentation); | ||
221 | QFETCH(bool, expectPrintDialog); | 228 | QFETCH(bool, expectPrintDialog); | ||
222 | QFETCH(bool, unique); | 229 | QFETCH(bool, unique); | ||
223 | QFETCH(uint, externalProcessExpectedPage); | 230 | QFETCH(uint, externalProcessExpectedPage); | ||
224 | QFETCH(bool, externalProcessExpectPresentation); | 231 | QFETCH(bool, externalProcessExpectPresentation); | ||
225 | QFETCH(bool, externalProcessExpectPrintDialog); | 232 | QFETCH(bool, externalProcessExpectPrintDialog); | ||
233 | QFETCH(QString, externalProcessExpectFind); | ||||
234 | | ||||
226 | 235 | | |||
227 | QScopedPointer<ClosePrintDialogHelper> helper; | 236 | QScopedPointer<ClosePrintDialogHelper> helper; | ||
228 | 237 | | |||
229 | Okular::Settings::self()->setShellOpenFileInTabs(useTabs); | 238 | Okular::Settings::self()->setShellOpenFileInTabs(useTabs); | ||
230 | 239 | | |||
231 | if (expectPrintDialog || externalProcessExpectPrintDialog) { | 240 | if (expectPrintDialog || externalProcessExpectPrintDialog) { | ||
232 | const int expectedTab = externalProcessExpectPrintDialog && !unique ? 1 : 0; | 241 | const int expectedTab = externalProcessExpectPrintDialog && !unique ? 1 : 0; | ||
233 | helper.reset(new ClosePrintDialogHelper(expectedTab)); | 242 | helper.reset(new ClosePrintDialogHelper(expectedTab)); | ||
234 | QTimer::singleShot(0, helper.data(), SLOT(closePrintDialog())); | 243 | QTimer::singleShot(0, helper.data(), SLOT(closePrintDialog())); | ||
235 | } | 244 | } | ||
236 | 245 | | |||
237 | Okular::Status status = Okular::main(paths, serializedOptions); | 246 | Okular::Status status = Okular::main(paths, serializedOptions); | ||
238 | QCOMPARE(status, Okular::Success); | 247 | QCOMPARE(status, Okular::Success); | ||
239 | Shell *s = findShell(); | 248 | Shell *s = findShell(); | ||
240 | QVERIFY(s); | 249 | QVERIFY(s); | ||
241 | 250 | | |||
242 | if (paths.count() == 1) | 251 | if (paths.count() == 1) | ||
243 | { | 252 | { | ||
244 | QCOMPARE(s->m_tabs.count(), 1); | 253 | QCOMPARE(s->m_tabs.count(), 1); | ||
245 | Okular::Part *part = s->findChild<Okular::Part*>(); | 254 | Okular::Part *part = s->findChild<Okular::Part*>(); | ||
246 | QVERIFY(part); | 255 | QVERIFY(part); | ||
247 | QCOMPARE(part->url().url(), QStringLiteral("file://%1").arg(paths[0])); | 256 | QCOMPARE(part->url().url(), QStringLiteral("file://%1").arg(paths[0])); | ||
248 | QCOMPARE(partDocument(part)->currentPage(), expectedPage); | 257 | QCOMPARE(partDocument(part)->currentPage(), expectedPage); | ||
258 | // Testing if the bar is shown or hidden as expected | ||||
259 | QCOMPARE(findWidget(part)->isHidden(), externalProcessExpectFind.isEmpty()); | ||||
260 | // Checking if the encryption/decryption worked | ||||
261 | QCOMPARE(externalProcessExpectFind, ShellUtils::find(serializedOptions)); | ||||
262 | | ||||
249 | } | 263 | } | ||
250 | else if (paths.count() == 2) | 264 | else if (paths.count() == 2) | ||
251 | { | 265 | { | ||
252 | if (useTabs) | 266 | if (useTabs) | ||
253 | { | 267 | { | ||
254 | Shell *s = findShell(); | 268 | Shell *s = findShell(); | ||
255 | QVERIFY(s); | 269 | QVERIFY(s); | ||
256 | Okular::Part *part = dynamic_cast<Okular::Part*>(s->m_tabs[0].part); | 270 | Okular::Part *part = dynamic_cast<Okular::Part*>(s->m_tabs[0].part); | ||
▲ Show 20 Lines • Show All 143 Lines • ▼ Show 20 Line(s) | |||||
400 | 414 | | |||
401 | void MainShellTest::testFileRemembersPagePosition() | 415 | void MainShellTest::testFileRemembersPagePosition() | ||
402 | { | 416 | { | ||
403 | QFETCH(int, mode); | 417 | QFETCH(int, mode); | ||
404 | 418 | | |||
405 | const QStringList paths = QStringList(QStringLiteral(KDESRCDIR "data/contents.epub")); | 419 | const QStringList paths = QStringList(QStringLiteral(KDESRCDIR "data/contents.epub")); | ||
406 | QString serializedOptions; | 420 | QString serializedOptions; | ||
407 | if (mode == 1 || mode == 3) | 421 | if (mode == 1 || mode == 3) | ||
408 | serializedOptions = ShellUtils::serializeOptions(false, false, false, false, false, QString()); | 422 | serializedOptions = ShellUtils::serializeOptions(false, false, false, false, false, QString(), QString()); | ||
409 | else | 423 | else | ||
410 | serializedOptions = ShellUtils::serializeOptions(false, false, false, true, false, QString()); | 424 | serializedOptions = ShellUtils::serializeOptions(false, false, false, true, false, QString(), QString()); | ||
411 | 425 | | |||
412 | Okular::Settings::self()->setShellOpenFileInTabs(mode == 3); | 426 | Okular::Settings::self()->setShellOpenFileInTabs(mode == 3); | ||
413 | 427 | | |||
414 | Okular::Status status = Okular::main(paths, serializedOptions); | 428 | Okular::Status status = Okular::main(paths, serializedOptions); | ||
415 | QCOMPARE(status, Okular::Success); | 429 | QCOMPARE(status, Okular::Success); | ||
416 | Shell *s = findShell(); | 430 | Shell *s = findShell(); | ||
417 | QVERIFY(s); | 431 | QVERIFY(s); | ||
418 | Okular::Part *part = s->findChild<Okular::Part*>(); | 432 | Okular::Part *part = s->findChild<Okular::Part*>(); | ||
Show All 34 Lines | |||||
453 | QCOMPARE(part->url().url(), QStringLiteral("file://%1").arg(paths[0])); | 467 | QCOMPARE(part->url().url(), QStringLiteral("file://%1").arg(paths[0])); | ||
454 | QCOMPARE(partDocument(part)->currentPage(), 3u); | 468 | QCOMPARE(partDocument(part)->currentPage(), 3u); | ||
455 | } | 469 | } | ||
456 | 470 | | |||
457 | void MainShellTest::test2FilesError_data() | 471 | void MainShellTest::test2FilesError_data() | ||
458 | { | 472 | { | ||
459 | QTest::addColumn<QString>("serializedOptions"); | 473 | QTest::addColumn<QString>("serializedOptions"); | ||
460 | 474 | | |||
461 | QTest::newRow("startInPresentation") << ShellUtils::serializeOptions(true, false, false, false, false, QString()); | 475 | QTest::newRow("startInPresentation") << ShellUtils::serializeOptions(true, false, false, false, false, QString(), QString()); | ||
462 | QTest::newRow("showPrintDialog") << ShellUtils::serializeOptions(false, true, false, false, false, QString()); | 476 | QTest::newRow("showPrintDialog") << ShellUtils::serializeOptions(false, true, false, false, false, QString(), QString()); | ||
463 | QTest::newRow("unique") << ShellUtils::serializeOptions(false, false, false, true, false, QString()); | 477 | QTest::newRow("unique") << ShellUtils::serializeOptions(false, false, false, true, false, QString(), QString()); | ||
464 | QTest::newRow("pageNumger") << ShellUtils::serializeOptions(false, false, false, false, false, QStringLiteral("3")); | 478 | QTest::newRow("pageNumber") << ShellUtils::serializeOptions(false, false, false, false, false, QStringLiteral("3"), QString()); | ||
479 | QTest::newRow("find") << ShellUtils::serializeOptions(false, false, false, false, false, QString(), QStringLiteral("silly")); | ||||
465 | } | 480 | } | ||
466 | 481 | | |||
467 | void MainShellTest::test2FilesError() | 482 | void MainShellTest::test2FilesError() | ||
468 | { | 483 | { | ||
469 | QFETCH(QString, serializedOptions); | 484 | QFETCH(QString, serializedOptions); | ||
470 | 485 | | |||
471 | QStringList paths; | 486 | QStringList paths; | ||
472 | paths << QStringLiteral(KDESRCDIR "data/file1.pdf") << QStringLiteral(KDESRCDIR "data/tocreload.pdf"); | 487 | paths << QStringLiteral(KDESRCDIR "data/file1.pdf") << QStringLiteral(KDESRCDIR "data/tocreload.pdf"); | ||
Show All 10 Lines | 496 | { | |||
483 | QTest::addColumn<QString>("options"); | 498 | QTest::addColumn<QString>("options"); | ||
484 | QTest::addColumn<bool>("useTabsOpen"); | 499 | QTest::addColumn<bool>("useTabsOpen"); | ||
485 | QTest::addColumn<bool>("useTabsRestore"); | 500 | QTest::addColumn<bool>("useTabsRestore"); | ||
486 | 501 | | |||
487 | QStringList oneDocPaths(QStringLiteral( KDESRCDIR "data/file1.pdf" ) ); | 502 | QStringList oneDocPaths(QStringLiteral( KDESRCDIR "data/file1.pdf" ) ); | ||
488 | QStringList twoDocPaths( oneDocPaths ); | 503 | QStringList twoDocPaths( oneDocPaths ); | ||
489 | twoDocPaths << QStringLiteral(KDESRCDIR "data/formSamples.pdf"); | 504 | twoDocPaths << QStringLiteral(KDESRCDIR "data/formSamples.pdf"); | ||
490 | 505 | | |||
491 | const QString options = ShellUtils::serializeOptions(false, false, false, false, false, QString()); | 506 | const QString options = ShellUtils::serializeOptions(false, false, false, false, false, QString(), QString()); | ||
492 | 507 | | |||
493 | QTest::newRow("1 doc, 1 window, tabs") << oneDocPaths << options << true << true; | 508 | QTest::newRow("1 doc, 1 window, tabs") << oneDocPaths << options << true << true; | ||
494 | QTest::newRow("2 docs, 1 window, tabs") << twoDocPaths << options << true << true; | 509 | QTest::newRow("2 docs, 1 window, tabs") << twoDocPaths << options << true << true; | ||
495 | QTest::newRow("2 docs, 2 windows, tabs") << twoDocPaths << options << false << true; | 510 | QTest::newRow("2 docs, 2 windows, tabs") << twoDocPaths << options << false << true; | ||
496 | QTest::newRow("2 docs, 2 windows, no tabs") << twoDocPaths << options << false << false; | 511 | QTest::newRow("2 docs, 2 windows, no tabs") << twoDocPaths << options << false << false; | ||
497 | QTest::newRow("2 docs, 1 window, no tabs") << twoDocPaths << options << true << false; | 512 | QTest::newRow("2 docs, 1 window, no tabs") << twoDocPaths << options << true << false; | ||
498 | } | 513 | } | ||
499 | 514 | | |||
▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines |