Changes: added routes with transfers (only displays first bus) and version 0.4
[ptas] / zouba / tests / ut_route / ut_route.cpp
1 #include <QObject>
2 #include <QtDebug>
3 #include <QByteArray>
4 #include "ut_route.h"
5
6 #include "ut_sampleinput.h"
7
8 void Ut_Route::init()
9 {
10     m_subject = new RoutePrivate();
11 }
12
13 void Ut_Route::cleanup()
14 {
15     delete m_subject;
16     m_subject = 0;
17 }
18
19 void Ut_Route::initTestCase()
20 {
21 }
22
23 void Ut_Route::cleanupTestCase()
24 {
25 }
26
27 void Ut_Route::testParseReply()
28 {
29   QFETCH(QByteArray, xmlInput);
30   QFETCH(QList<RouteData>, expectedResults);
31
32   QList<RouteData> routeData = m_subject->parseReply( xmlInput );
33
34   QCOMPARE( routeData.count(), expectedResults.count() );
35
36   for( int index=0; index<routeData.count(); ++index ) {
37     QCOMPARE( routeData.at( index ).lineCode,    expectedResults.at( index ).lineCode );
38     QCOMPARE( routeData.at( index ).arrivalTime, expectedResults.at( index ).arrivalTime );
39   }
40 }
41
42 void Ut_Route::testParseReply_data()
43 {
44   QTest::addColumn<QByteArray>("xmlInput");
45   QTest::addColumn< QList<RouteData> >("expectedResults");
46
47   QTest::newRow("single route")
48     << sampleInput[0]
49     << ( QList<RouteData>()
50         << RouteData( "65A", "18:20" )
51         << RouteData( "102T", "18:26" )
52         << RouteData( "110T", "18:34" )
53         );
54
55   QTest::newRow("route with bus change")
56     << sampleInput[1]
57     << ( QList<RouteData>()
58         << RouteData( "111",  "08:18" )
59         << RouteData( "111",  "08:33" )
60         << RouteData( "111T", "08:34" )
61         << RouteData( "111",  "08:50" )
62         << RouteData( "111",  "09:07" )
63         );
64 }
65
66 void Ut_Route::testSetFromLocation()
67 {
68   Location work( "2551042", "6672829" );
69   QCOMPARE( m_subject->fromValid(), false );
70   m_subject->setFromLocation( &work );
71   QCOMPARE( m_subject->fromLocation()->x(), work.x() );
72   QCOMPARE( m_subject->fromLocation()->y(), work.y() );
73   QCOMPARE( m_subject->fromValid(), true );
74 }
75
76 void Ut_Route::testSetToLocation()
77 {
78   Location work( "2551042", "6672829" );
79   QCOMPARE( m_subject->toValid(), false );
80   m_subject->setToLocation( &work );
81   QCOMPARE( m_subject->toLocation()->x(), work.x() );
82   QCOMPARE( m_subject->toLocation()->y(), work.y() );
83   QCOMPARE( m_subject->toValid(), true );
84 }
85
86 QTEST_APPLESS_MAIN(Ut_Route)