Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Libraries
KPublicTransport
Commits
d7e71406
Commit
d7e71406
authored
Mar 03, 2021
by
Volker Krause
Browse files
Add basic unit test for vehicle position interpolation
parent
2902d6c0
Pipeline
#52984
passed with stage
in 25 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
autotests/CMakeLists.txt
View file @
d7e71406
...
...
@@ -21,6 +21,7 @@ ecm_add_test(notestest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport)
ecm_add_test
(
backendtest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport
)
ecm_add_test
(
linemetadatatest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport
)
ecm_add_test
(
networkconfigtest.cpp LINK_LIBRARIES Qt5::Test
)
ecm_add_test
(
vehiclelayoutquerymodeltest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport
)
ecm_add_test
(
navitiaparsertest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport
)
ecm_add_test
(
hafasmgateparsertest.cpp LINK_LIBRARIES Qt5::Test KPublicTransport
)
...
...
autotests/vehiclelayoutquerymodeltest.cpp
0 → 100644
View file @
d7e71406
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include
<KPublicTransport/Manager>
#include
<KPublicTransport/Stopover>
#include
<KPublicTransport/VehicleLayoutQueryModel>
#include
<QAbstractItemModelTester>
#include
<QFile>
#include
<QJsonDocument>
#include
<QJsonObject>
#include
<QSignalSpy>
#include
<QTest>
using
namespace
KPublicTransport
;
class
VehicleLayoutQueryModelTest
:
public
QObject
{
Q_OBJECT
private:
QByteArray
readFile
(
const
QString
&
fn
)
{
QFile
f
(
fn
);
f
.
open
(
QFile
::
ReadOnly
);
return
f
.
readAll
();
}
private
Q_SLOTS
:
void
testCoachPositionInterpolation
()
{
Manager
ptMgr
;
VehicleLayoutQueryModel
model
;
QAbstractItemModelTester
modelTest
(
&
model
);
model
.
setManager
(
&
ptMgr
);
QSignalSpy
resetSpy
(
&
model
,
&
QAbstractItemModel
::
modelReset
);
const
auto
inVec
=
Vehicle
::
fromJson
(
QJsonDocument
::
fromJson
(
readFile
(
QStringLiteral
(
SOURCE_DIR
"/data/hafas/rem-I-JF-sbb-ic-train-formation-bern-vehicle.json"
))).
object
());
QCOMPARE
(
inVec
.
sections
().
size
(),
10
);
QVERIFY
(
!
inVec
.
hasPlatformPositions
());
QVERIFY
(
inVec
.
hasPlatformSectionNames
());
const
auto
inPlat
=
Platform
::
fromJson
(
QJsonDocument
::
fromJson
(
readFile
(
QStringLiteral
(
SOURCE_DIR
"/data/hafas/rem-I-XP-sbb-platform-bern.json"
))).
object
());
QVERIFY
(
!
inPlat
.
sections
().
empty
());
Stopover
s
;
s
.
setVehicleLayout
(
inVec
);
s
.
setPlatformLayout
(
inPlat
);
s
.
setScheduledDepartureTime
(
QDateTime
::
currentDateTime
());
Line
line
;
line
.
setName
(
QStringLiteral
(
"IC 8"
));
Route
route
;
route
.
setLine
(
line
);
s
.
setRoute
(
route
);
VehicleLayoutRequest
req
(
s
);
QVERIFY
(
req
.
isValid
());
model
.
setRequest
(
req
);
QVERIFY
(
resetSpy
.
wait
(
10
));
// query is started, initial requested data is set
QCOMPARE
(
model
.
rowCount
(),
10
);
resetSpy
.
clear
();
QVERIFY
(
resetSpy
.
wait
(
10
));
// query finished, interpolation is triggered
QCOMPARE
(
model
.
rowCount
(),
10
);
for
(
int
i
=
0
;
i
<
model
.
rowCount
();
++
i
)
{
const
auto
idx
=
model
.
index
(
i
,
0
);
const
auto
sec
=
idx
.
data
(
VehicleLayoutQueryModel
::
VehicleSectionRole
).
value
<
VehicleSection
>
();
QVERIFY
(
sec
.
hasPlatformPosition
());
}
}
};
QTEST_GUILESS_MAIN
(
VehicleLayoutQueryModelTest
)
#include
"vehiclelayoutquerymodeltest.moc"
src/lib/models/vehiclelayoutquerymodel.h
View file @
d7e71406
...
...
@@ -51,7 +51,7 @@ public:
};
Q_ENUM
(
Roles
)
int
rowCount
(
const
QModelIndex
&
parent
)
const
override
;
int
rowCount
(
const
QModelIndex
&
parent
=
{}
)
const
override
;
QVariant
data
(
const
QModelIndex
&
index
,
int
role
)
const
override
;
QHash
<
int
,
QByteArray
>
roleNames
()
const
override
;
Q_SIGNALS:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment