Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/libbugzilla/autotests/bugtest.cpp
- This file was added.
1 | #include <QTest> | ||||
---|---|---|---|---|---|
2 | | ||||
3 | #include <QDebug> | ||||
4 | | ||||
5 | #include "../bug.h" | ||||
6 | #include "../product.h" | ||||
7 | | ||||
8 | namespace Bugzilla | ||||
9 | { | ||||
10 | | ||||
11 | class JobDouble : public APIJob | ||||
12 | { | ||||
13 | Q_OBJECT | ||||
14 | public: | ||||
15 | using APIJob::APIJob; | ||||
16 | | ||||
17 | JobDouble(QString fixture) | ||||
18 | : m_fixture(fixture) | ||||
19 | { | ||||
20 | } | ||||
21 | | ||||
22 | virtual QByteArray data() const override | ||||
23 | { | ||||
24 | Q_ASSERT(!m_fixture.isEmpty()); | ||||
25 | QFile file(m_fixture); | ||||
26 | Q_ASSERT(file.open(QFile::ReadOnly | QFile::Text)); | ||||
27 | QTextStream in(&file); | ||||
28 | return in.readAll().toUtf8(); | ||||
29 | } | ||||
30 | | ||||
31 | QString m_fixture; | ||||
32 | }; | ||||
33 | | ||||
34 | class ConnectionDouble : public Connection | ||||
35 | { | ||||
36 | public: | ||||
37 | using Connection::Connection; | ||||
38 | | ||||
39 | virtual void setToken(const QString &) override | ||||
40 | { | ||||
41 | Q_UNREACHABLE(); | ||||
42 | } | ||||
43 | | ||||
44 | virtual APIJob *get(const QString &path, | ||||
45 | const QUrlQuery &query = QUrlQuery()) const override | ||||
46 | { | ||||
47 | if (path == "/bug" && query.toString() == "product=dragonplayer") { | ||||
48 | return new JobDouble { QFINDTESTDATA("data/bugs.dragonplayer.json") }; | ||||
49 | } | ||||
50 | Q_ASSERT_X(false, "get", | ||||
51 | qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); | ||||
52 | return nullptr; | ||||
53 | } | ||||
54 | | ||||
55 | virtual APIJob *post(const QString &path, | ||||
56 | const QByteArray &, | ||||
57 | const QUrlQuery &query = QUrlQuery()) const override | ||||
58 | { | ||||
59 | qDebug() << path << query.toString(); | ||||
60 | Q_UNREACHABLE(); | ||||
61 | return nullptr; | ||||
62 | } | ||||
63 | | ||||
64 | virtual APIJob *put(const QString &, | ||||
65 | const QByteArray &, | ||||
66 | const QUrlQuery & = QUrlQuery()) const override | ||||
67 | { | ||||
68 | Q_UNREACHABLE(); | ||||
69 | } | ||||
70 | }; | ||||
71 | | ||||
72 | class BugTest : public QObject | ||||
73 | { | ||||
74 | Q_OBJECT | ||||
75 | private Q_SLOTS: | ||||
76 | | ||||
77 | void initTestCase() | ||||
78 | { | ||||
79 | Bugzilla::setConnection(m_doubleConnection); | ||||
80 | } | ||||
81 | | ||||
82 | void testSearch() | ||||
83 | { | ||||
84 | Bugzilla::Search search; | ||||
85 | search.products = QStringList { "dragonplayer" }; | ||||
86 | auto job = Bugzilla::BugClient().search(search); | ||||
87 | job->start(); | ||||
88 | QList<Bug::Ptr> bugs = Bugzilla::BugClient().search(job); | ||||
89 | QCOMPARE(bugs.size(), 2); | ||||
90 | Bug::Ptr bug; | ||||
91 | for (auto it = bugs.begin(); it != bugs.end(); ++it) { | ||||
92 | if ((*it)->id() == 156514) { | ||||
93 | bug = *it; | ||||
94 | } | ||||
95 | } | ||||
96 | | ||||
97 | QCOMPARE(bug.isNull(), false); | ||||
98 | QCOMPARE(bug->id(), 156514); | ||||
99 | QCOMPARE(bug->product(), "dragonplayer"); | ||||
100 | QCOMPARE(bug->component(), "general"); | ||||
101 | QCOMPARE(bug->summary(), "Supported filetypes not shown in Play File.. Dialog"); | ||||
102 | QCOMPARE(bug->version(), "unspecified"); | ||||
103 | QCOMPARE(bug->op_sys(), "Linux"); | ||||
104 | QCOMPARE(bug->priority(), "NOR"); | ||||
105 | QCOMPARE(bug->severity(), "normal"); | ||||
106 | QCOMPARE(bug->status(), Bug::Status::RESOLVED); | ||||
107 | QCOMPARE(bug->resolution(), Bug::Resolution::FIXED); | ||||
108 | } | ||||
109 | | ||||
110 | private: | ||||
111 | Bugzilla::ConnectionDouble *m_doubleConnection = new Bugzilla::ConnectionDouble; | ||||
112 | }; | ||||
113 | | ||||
114 | } // namespace Bugzilla | ||||
115 | | ||||
116 | QTEST_MAIN(Bugzilla::BugTest) | ||||
117 | | ||||
118 | #include "bugtest.moc" |