Changeset View
Changeset View
Standalone View
Standalone View
autotests/drive/aboutfetchjobtest.cpp
Show All 11 Lines | |||||
12 | * This library is distributed in the hope that it will be useful, | 12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU Lesser General Public License for more details. | 15 | * GNU Lesser General Public License for more details. | ||
16 | * | 16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | 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/>. | 18 | * License along with this library. If not, see <https://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | #include <cstring> | |||
21 | #include <QObject> | 21 | #include <QObject> | ||
22 | #include <QTest> | 22 | #include <QTest> | ||
23 | 23 | | |||
24 | #include "fakenetworkaccessmanagerfactory.h" | 24 | #include "fakenetworkaccessmanagerfactory.h" | ||
25 | #include "testutils.h" | 25 | #include "testutils.h" | ||
26 | #include "drivetestutils.h" | 26 | #include "drivetestutils.h" | ||
27 | 27 | | |||
28 | #include "types.h" | 28 | #include "types.h" | ||
29 | #include "aboutfetchjob.h" | 29 | #include "aboutfetchjob.h" | ||
30 | #include "about.h" | 30 | #include "about.h" | ||
31 | #include "account.h" | 31 | #include "account.h" | ||
32 | 32 | | |||
33 | using namespace KGAPI2; | 33 | using namespace KGAPI2; | ||
34 | 34 | | |||
35 | namespace { | ||||
36 | static const char *LimitedFieldTag = "limited fields"; | ||||
37 | } | ||||
38 | | ||||
35 | Q_DECLARE_METATYPE(QList<FakeNetworkAccessManager::Scenario>) | 39 | Q_DECLARE_METATYPE(QList<FakeNetworkAccessManager::Scenario>) | ||
40 | Q_DECLARE_METATYPE(KGAPI2::Drive::AboutPtr) | ||||
36 | 41 | | |||
37 | class AboutFetchJobTest : public QObject | 42 | class AboutFetchJobTest : public QObject | ||
38 | { | 43 | { | ||
39 | Q_OBJECT | 44 | Q_OBJECT | ||
40 | private Q_SLOTS: | 45 | private Q_SLOTS: | ||
41 | void initTestCase() | 46 | void initTestCase() | ||
42 | { | 47 | { | ||
43 | NetworkAccessManagerFactory::setFactory(new FakeNetworkAccessManagerFactory); | 48 | NetworkAccessManagerFactory::setFactory(new FakeNetworkAccessManagerFactory); | ||
44 | } | 49 | } | ||
45 | 50 | | |||
46 | void testFetch() | 51 | void testFetch_data() | ||
47 | { | 52 | { | ||
48 | FakeNetworkAccessManagerFactory::get()->setScenarios({ | 53 | QTest::addColumn<QList<FakeNetworkAccessManager::Scenario>>("scenarios"); | ||
54 | QTest::addColumn<KGAPI2::Drive::AboutPtr>("about"); | ||||
55 | | ||||
56 | QTest::newRow("") | ||||
57 | << QList<FakeNetworkAccessManager::Scenario>{ | ||||
49 | scenarioFromFile(QFINDTESTDATA("data/about_fetch_request.txt"), | 58 | scenarioFromFile(QFINDTESTDATA("data/about_fetch_request.txt"), | ||
50 | QFINDTESTDATA("data/about_fetch_response.txt")) | 59 | QFINDTESTDATA("data/about_fetch_response.txt")) | ||
60 | } | ||||
61 | << aboutFromFile(QFINDTESTDATA("data/about.json")); | ||||
51 | 62 | | |||
52 | }); | 63 | QTest::newRow(LimitedFieldTag) | ||
53 | const auto about = aboutFromFile(QFINDTESTDATA("data/about.json")); | 64 | << QList<FakeNetworkAccessManager::Scenario>{ | ||
65 | scenarioFromFile(QFINDTESTDATA("data/about_fetch_limited_fields_request.txt"), | ||||
66 | QFINDTESTDATA("data/about_fetch_limited_fields_response.txt")) | ||||
67 | } | ||||
68 | << aboutFromFile(QFINDTESTDATA("data/about_limited_fields.json")); | ||||
69 | } | ||||
70 | | ||||
71 | void testFetch() | ||||
72 | { | ||||
73 | QFETCH(QList<FakeNetworkAccessManager::Scenario>, scenarios); | ||||
74 | QFETCH(KGAPI2::Drive::AboutPtr, about); | ||||
75 | | ||||
76 | FakeNetworkAccessManagerFactory::get()->setScenarios(scenarios); | ||||
54 | 77 | | |||
55 | auto account = AccountPtr::create(QStringLiteral("MockAccount"), QStringLiteral("MockToken")); | 78 | auto account = AccountPtr::create(QStringLiteral("MockAccount"), QStringLiteral("MockToken")); | ||
56 | auto job = new Drive::AboutFetchJob(account, nullptr); | 79 | auto job = new Drive::AboutFetchJob(account, nullptr); | ||
80 | | ||||
81 | if (strcmp(LimitedFieldTag, QTest::currentDataTag()) == 0) { | ||||
82 | job->setFields({ Drive::About::Fields::Kind, Drive::About::Fields::PermissionId}); | ||||
83 | } | ||||
84 | | ||||
57 | QVERIFY(execJob(job)); | 85 | QVERIFY(execJob(job)); | ||
58 | const auto items = job->items(); | 86 | const auto items = job->items(); | ||
59 | QCOMPARE(items.count(), 1); | 87 | QCOMPARE(items.count(), 1); | ||
60 | const auto returnedAbout = items.at(0).dynamicCast<Drive::About>(); | 88 | const auto returnedAbout = items.at(0).dynamicCast<Drive::About>(); | ||
61 | QVERIFY(returnedAbout); | 89 | QVERIFY(returnedAbout); | ||
62 | QCOMPARE(*returnedAbout, *about); | 90 | QCOMPARE(*returnedAbout, *about); | ||
63 | } | 91 | } | ||
64 | }; | 92 | }; | ||
65 | 93 | | |||
66 | QTEST_GUILESS_MAIN(AboutFetchJobTest) | 94 | QTEST_GUILESS_MAIN(AboutFetchJobTest) | ||
67 | 95 | | |||
68 | #include "aboutfetchjobtest.moc" | 96 | #include "aboutfetchjobtest.moc" | ||
69 | 97 | | |||
70 | 98 | | |||
71 | 99 | |