]> cloud.milkyroute.net Git - dolphin.git/blob - src/tests/draganddrophelpertest.cpp
Enable test mode in all test
[dolphin.git] / src / tests / draganddrophelpertest.cpp
1 /*
2 * SPDX-FileCopyrightText: 2017 Emirald Mateli <aldo.mateli@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #include <QStandardPaths>
8 #include <QTest>
9 #include <views/draganddrophelper.h>
10
11 class DragAndDropHelperTest : public QObject
12 {
13 Q_OBJECT
14
15 private Q_SLOTS:
16 void initTestCase();
17 void testUrlListMatchesUrl_data();
18 void testUrlListMatchesUrl();
19 };
20
21 void DragAndDropHelperTest::initTestCase()
22 {
23 QStandardPaths::setTestModeEnabled(true);
24 }
25
26 void DragAndDropHelperTest::testUrlListMatchesUrl_data()
27 {
28 QTest::addColumn<QList<QUrl>>("urlList");
29 QTest::addColumn<QUrl>("url");
30 QTest::addColumn<bool>("expected");
31
32 QTest::newRow("test_equal")
33 << QList<QUrl> {QUrl::fromLocalFile("/root")}
34 << QUrl::fromLocalFile("/root")
35 << true;
36
37 QTest::newRow("test_trailing_slash")
38 << QList<QUrl> {QUrl::fromLocalFile("/root/")}
39 << QUrl::fromLocalFile("/root")
40 << true;
41
42 QTest::newRow("test_ftp_scheme")
43 << QList<QUrl> {QUrl("ftp://server:2211/dir")}
44 << QUrl("ftp://server:2211/dir")
45 << true;
46
47 QTest::newRow("test_not_matched")
48 << QList<QUrl> {QUrl::fromLocalFile("/usr/share"), QUrl::fromLocalFile("/usr/local/bin")}
49 << QUrl::fromLocalFile("/usr/bin")
50 << false;
51
52 QTest::newRow("test_empty_target")
53 << QList<QUrl> {QUrl::fromLocalFile("/usr/share"), QUrl::fromLocalFile("/usr/local/bin")}
54 << QUrl()
55 << false;
56
57 QTest::newRow("test_empty_list")
58 << QList<QUrl>()
59 << QUrl::fromLocalFile("/usr/bin")
60 << false;
61 }
62
63 void DragAndDropHelperTest::testUrlListMatchesUrl()
64 {
65 QFETCH(QList<QUrl>, urlList);
66 QFETCH(QUrl, url);
67 QFETCH(bool, expected);
68
69 QCOMPARE(DragAndDropHelper::urlListMatchesUrl(urlList, url), expected);
70 }
71
72
73 QTEST_MAIN(DragAndDropHelperTest)
74
75 #include "draganddrophelpertest.moc"