forked from cutelyst/cutelyst
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testdispatcherchained.cpp
106 lines (81 loc) · 2.95 KB
/
testdispatcherchained.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef DISPATCHERTEST_H
#define DISPATCHERTEST_H
#include "coverageobject.h"
#include "headers.h"
#include <Cutelyst/application.h>
#include <Cutelyst/controller.h>
#include <Cutelyst/headers.h>
#include <QtCore/QObject>
#include <QtTest/QTest>
using namespace Cutelyst;
class TestDispatcherChained : public CoverageObject
{
Q_OBJECT
public:
explicit TestDispatcherChained(QObject *parent = nullptr)
: CoverageObject(parent)
{
}
private Q_SLOTS:
void initTestCase();
void testController_data();
void testController() { doTest(); }
void cleanupTestCase();
private:
TestEngine *m_engine;
TestEngine *getEngine();
void doTest();
};
void TestDispatcherChained::initTestCase()
{
m_engine = getEngine();
QVERIFY(m_engine);
}
TestEngine *TestDispatcherChained::getEngine()
{
auto app = new TestApplication;
auto engine = new TestEngine(app, QVariantMap());
if (!engine->init()) {
return nullptr;
}
return engine;
}
void TestDispatcherChained::cleanupTestCase()
{
delete m_engine;
}
void TestDispatcherChained::doTest()
{
QFETCH(QString, url);
QFETCH(QByteArray, output);
QUrl urlAux(url);
auto result = m_engine->createRequest(
"GET", urlAux.path(), urlAux.query(QUrl::FullyEncoded).toLatin1(), Headers(), nullptr);
QCOMPARE(result.body, output);
}
void TestDispatcherChained::testController_data()
{
QTest::addColumn<QString>("url");
QTest::addColumn<QByteArray>("output");
// Chained dispatcher
QTest::newRow("chained-test00") << QStringLiteral("/root") << QByteArrayLiteral("/root");
QTest::newRow("chained-test01") << QStringLiteral("/root/") << QByteArrayLiteral("/root");
QTest::newRow("chained-test02") << QStringLiteral("/root////") << QByteArrayLiteral("/root");
QTest::newRow("chained-test03") << QStringLiteral("/root/item") << QByteArrayLiteral("/root");
QTest::newRow("chained-test04") << QStringLiteral("/root/item/") << QByteArrayLiteral("/root");
QTest::newRow("chained-test05")
<< QStringLiteral("/chain/item") << QByteArrayLiteral("/chain/item[MANY]/");
QTest::newRow("chained-test07")
<< QStringLiteral("/chain/item/foo") << QByteArrayLiteral("/chain/item[ONE]/foo");
QTest::newRow("chained-test08")
<< QStringLiteral("/chain/item/foo/bar") << QByteArrayLiteral("/chain/item[MANY]/foo/bar");
QTest::newRow("chained-test09") << QStringLiteral("/chain/midle/one/two/end")
<< QByteArrayLiteral("/chain/midle/one/two/end");
QTest::newRow("chained-test10") << QStringLiteral("/chain/midle/TWO/ONE/end")
<< QByteArrayLiteral("/chain/midle/TWO/ONE/end");
QTest::newRow("chained-test12") << QStringLiteral("/chain/midle/TWO/ONE/end/1/2/3/4/5")
<< QByteArrayLiteral("/chain/midle/TWO/ONE/end/1/2/3/4/5");
}
QTEST_MAIN(TestDispatcherChained)
#include "testdispatcherchained.moc"
#endif