Changeset View
Changeset View
Standalone View
Standalone View
autotests/drive/driveshidejobtest.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 David Barchiesi <david@barchie.si> | ||||
3 | * | ||||
4 | * This library is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | * later version accepted by the membership of KDE e.V. (or its | ||||
9 | * successor approved by the membership of KDE e.V.), which shall | ||||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | * | ||||
12 | * This library is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU Lesser General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Lesser General Public | ||||
18 | * License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include <QObject> | ||||
22 | #include <QTest> | ||||
23 | | ||||
24 | #include "fakenetworkaccessmanagerfactory.h" | ||||
25 | #include "testutils.h" | ||||
26 | #include "drivetestutils.h" | ||||
27 | | ||||
28 | #include "types.h" | ||||
29 | #include "driveshidejob.h" | ||||
30 | #include "drives.h" | ||||
31 | #include "account.h" | ||||
32 | | ||||
33 | using namespace KGAPI2; | ||||
34 | | ||||
35 | Q_DECLARE_METATYPE(QList<FakeNetworkAccessManager::Scenario>) | ||||
36 | Q_DECLARE_METATYPE(KGAPI2::Drive::DrivesPtr) | ||||
37 | | ||||
38 | class DrivesHideJobTest : public QObject | ||||
39 | { | ||||
40 | Q_OBJECT | ||||
41 | private Q_SLOTS: | ||||
42 | void initTestCase() | ||||
43 | { | ||||
44 | NetworkAccessManagerFactory::setFactory(new FakeNetworkAccessManagerFactory); | ||||
45 | } | ||||
46 | | ||||
47 | void testHide_data() | ||||
48 | { | ||||
49 | QTest::addColumn<QList<FakeNetworkAccessManager::Scenario>>("scenarios"); | ||||
50 | QTest::addColumn<Drive::DrivesPtr>("sourceDrive"); | ||||
51 | QTest::addColumn<Drive::DrivesPtr>("expectedResult"); | ||||
52 | | ||||
53 | QTest::newRow("metadata only") | ||||
54 | << QList<FakeNetworkAccessManager::Scenario>{ | ||||
55 | scenarioFromFile(QFINDTESTDATA("data/drives_hide_request.txt"), | ||||
56 | QFINDTESTDATA("data/drives_hide_response.txt")) | ||||
57 | } | ||||
58 | << drivesFromFile(QFINDTESTDATA("data/drives.json")) | ||||
59 | << drivesFromFile(QFINDTESTDATA("data/drives.json")); | ||||
60 | } | ||||
61 | | ||||
62 | void testHide() | ||||
63 | { | ||||
64 | QFETCH(QList<FakeNetworkAccessManager::Scenario>, scenarios); | ||||
65 | QFETCH(Drive::DrivesPtr, sourceDrive); | ||||
66 | QFETCH(Drive::DrivesPtr, expectedResult); | ||||
67 | | ||||
68 | FakeNetworkAccessManagerFactory::get()->setScenarios(scenarios); | ||||
69 | | ||||
70 | auto account = AccountPtr::create(QStringLiteral("MockAccount"), QStringLiteral("MockToken")); | ||||
71 | Drive::DrivesHideJob *job = new Drive::DrivesHideJob(sourceDrive, true, account); | ||||
72 | | ||||
73 | QVERIFY(execJob(job)); | ||||
74 | const auto items = job->items(); | ||||
75 | QCOMPARE(items.count(), 1); | ||||
76 | QVERIFY(*items.cbegin()); | ||||
77 | QCOMPARE(**items.cbegin(), *expectedResult); | ||||
78 | } | ||||
79 | }; | ||||
80 | | ||||
81 | QTEST_GUILESS_MAIN(DrivesHideJobTest) | ||||
82 | | ||||
83 | #include "driveshidejobtest.moc" | ||||
84 | | ||||
85 | | ||||
86 | | ||||
87 | | ||||
88 | |