Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfilewidgettest.cpp
Show All 16 Lines | 3 | Copyright (c) 2016 Albert Astals Cid <aacid@kde.org> | |||
---|---|---|---|---|---|
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to | ||
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
19 | Boston, MA 02110-1301, USA. | 19 | Boston, MA 02110-1301, USA. | ||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "kfilewidget.h" | 22 | #include "kfilewidget.h" | ||
23 | 23 | | |||
24 | #include <QLabel> | 24 | #include <QLabel> | ||
25 | #include <QTemporaryDir> | ||||
25 | #include <QTest> | 26 | #include <QTest> | ||
26 | #include <QStandardPaths> | 27 | #include <QStandardPaths> | ||
27 | #include <QSignalSpy> | 28 | #include <QSignalSpy> | ||
28 | 29 | | |||
29 | #include <kdiroperator.h> | 30 | #include <kdiroperator.h> | ||
30 | #include <KFileFilterCombo> | 31 | #include <KFileFilterCombo> | ||
31 | #include <klocalizedstring.h> | 32 | #include <klocalizedstring.h> | ||
32 | #include <kurlnavigator.h> | 33 | #include <kurlnavigator.h> | ||
▲ Show 20 Lines • Show All 470 Lines • ▼ Show 20 Line(s) | 455 | { | |||
503 | // which calls KFileWidget::selectedUrls(). | 504 | // which calls KFileWidget::selectedUrls(). | ||
504 | // Accept the filename to ensure that a filename is selected. | 505 | // Accept the filename to ensure that a filename is selected. | ||
505 | connect(&fileWidget, &KFileWidget::accepted, &fileWidget, &KFileWidget::accept); | 506 | connect(&fileWidget, &KFileWidget::accepted, &fileWidget, &KFileWidget::accept); | ||
506 | QTest::keyClick(fileWidget.locationEdit(), Qt::Key_Return); | 507 | QTest::keyClick(fileWidget.locationEdit(), Qt::Key_Return); | ||
507 | QList<QUrl> urls = fileWidget.selectedUrls(); | 508 | QList<QUrl> urls = fileWidget.selectedUrls(); | ||
508 | QCOMPARE(urls.size(), 1); | 509 | QCOMPARE(urls.size(), 1); | ||
509 | QCOMPARE(urls[0], fileUrl); | 510 | QCOMPARE(urls[0], fileUrl); | ||
510 | } | 511 | } | ||
512 | | ||||
513 | void testCreateNestedNewFolders() | ||||
514 | { | ||||
515 | // when creating multiple nested new folders in the "save as" dialog, where folders are | ||||
516 | //created and entered, kdirlister would hit an assert (in reinsert()), bug 408801 | ||||
517 | QTemporaryDir tempDir; | ||||
dfaure: This test fails when being run twice in a row (without the fix), or if /tmp/folder1 already… | |||||
Yes, it does fail if the dir got created and the test didn't finish running for whatever reason; I was thinking of CI (which will nuke the whole build and start over), rather than of other people running the test locally. ahmadsamir: Yes, it does fail if the dir got created and the test didn't finish running for whatever reason… | |||||
518 | QVERIFY(tempDir.isValid()); | ||||
519 | const QString dir = tempDir.path(); | ||||
520 | const QUrl url = QUrl::fromLocalFile(dir); | ||||
521 | KFileWidget fw(url); | ||||
522 | fw.setOperationMode(KFileWidget::Saving); | ||||
523 | fw.setMode(KFile::File); | ||||
show() and activateWindow() are not needed for this unittest to demonstrate the failure. I'm trying to reduce the number of stuff popping up when running ctest, since that's rather annoying if I'm doing something else at the same time :-) dfaure: show() and activateWindow() are not needed for this unittest to demonstrate the failure.
I'm… | |||||
Yes, they're quiet sudden, and disappear too quickly too. But it won't matter for KIO tests, it's just one of many many dialogs :) ahmadsamir: Yes, they're quiet sudden, and disappear too quickly too. But it won't matter for KIO tests… | |||||
524 | | ||||
525 | // create the nested folders | ||||
526 | for (int i = 1; i < 6; ++i) { | ||||
527 | fw.dirOperator()->mkdir(QStringLiteral("folder%1").arg(i), true); | ||||
528 | // simulate the time the user will take to type the new folder name | ||||
529 | QTest::qWait(1000); | ||||
530 | } | ||||
531 | | ||||
532 | QVERIFY(QFile::exists(dir + QStringLiteral("/folder1/folder2/folder3/folder4/folder5"))); | ||||
533 | } | ||||
511 | }; | 534 | }; | ||
dfaure: Not needed, I get the assert even without this line. | |||||
512 | 535 | | |||
513 | QTEST_MAIN(KFileWidgetTest) | 536 | QTEST_MAIN(KFileWidgetTest) | ||
514 | 537 | | |||
515 | #include "kfilewidgettest.moc" | 538 | #include "kfilewidgettest.moc" |
This test fails when being run twice in a row (without the fix), or if /tmp/folder1 already exists for some unrelated reason.
I suggest using QTemporaryDir instead of QDir::tempPath, so that the deletion of the QTemporaryDir cleans up in all cases (success or failure).
I did it locally to debug this, here it is:
(and then you can remove the cleanup code at the end of the method)