Merge branch 'development'
[quandoparte] / test / tst_app.cpp
1 /*
2
3 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING.  If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19
20 */
21
22 #include <QtCore/QString>
23 #include <QtTest/QtTest>
24 #include <QtCore/QCoreApplication>
25
26 #include "../application/stationlistmodel.h"
27
28 class AppTest : public QObject
29 {
30     Q_OBJECT
31
32 public:
33     AppTest();
34
35 private Q_SLOTS:
36     void initTestCase();
37     void cleanupTestCase();
38     void testCase1();
39     void testCase2();
40     void testCase3();
41     void testCase4();
42     void testCase5();
43
44 private:
45     StationListModel *model;
46     QString path;
47 };
48
49 AppTest::AppTest()
50 {
51         model = new StationListModel(this);
52         path = QCoreApplication::applicationDirPath();
53 }
54
55 void AppTest::initTestCase()
56 {
57 }
58
59 void AppTest::cleanupTestCase()
60 {
61 }
62
63 void AppTest::testCase1()
64 {
65     QVERIFY2(false == model->load(path + "/testfiles/missing.qpl"), "File does not exist, should not return ok");
66 }
67
68 void AppTest::testCase2()
69 {
70     QVERIFY2(true == model->load(path + "/testfiles/empty.qpl"), "File cannot be loaeded");
71     QVERIFY2(0 == model->rowCount(), "Should be empty");
72 }
73
74 void AppTest::testCase3()
75 {
76     QVERIFY2(false == model->load(path + "/testfiles/malformed1.qpl"), "Tags are wrong, should not return ok");
77 }
78
79 void AppTest::testCase4()
80 {
81     QVERIFY2(true == model->load(path + "/testfiles/emptystation.qpl"), "cannot open file");
82 }
83
84 void AppTest::testCase5()
85 {
86     qDebug() << model->rowCount();
87     QVERIFY2(true == model->load(path + "/testfiles/teststation.qpl"), "cannot open file");
88     qDebug() << model->rowCount();
89     QVERIFY(model->rowCount() == 1);
90     QVERIFY(model->item(0)->text() == "Topolinia");
91 }
92
93 QTEST_MAIN(AppTest);
94
95 #include "tst_app.moc"