1 | /* |
---|
2 | * Copyright (C) 2010 Ixonos Plc. |
---|
3 | * |
---|
4 | * This file is part of fosdem-schedule. |
---|
5 | * |
---|
6 | * fosdem-schedule is free software: you can redistribute it and/or modify it |
---|
7 | * under the terms of the GNU General Public License as published by the Free |
---|
8 | * Software Foundation, either version 2 of the License, or (at your option) |
---|
9 | * any later version. |
---|
10 | * |
---|
11 | * fosdem-schedule is distributed in the hope that it will be useful, but |
---|
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
---|
13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
---|
14 | * more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License along with |
---|
17 | * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>. |
---|
18 | */ |
---|
19 | #include "eventtest.h" |
---|
20 | |
---|
21 | #include <QtTest> |
---|
22 | #include <QSqlDatabase> |
---|
23 | |
---|
24 | #include <QDebug> |
---|
25 | |
---|
26 | #include <event.h> |
---|
27 | |
---|
28 | void EventTest::initTestCase() |
---|
29 | { |
---|
30 | // Connect to the test database. Ask Mr. Pavelka to generate one for you :) |
---|
31 | QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); |
---|
32 | db.setDatabaseName("fosdem-test.sqlite"); |
---|
33 | QVERIFY(db.open()); |
---|
34 | } |
---|
35 | |
---|
36 | void EventTest::getById() |
---|
37 | { |
---|
38 | Event event = Event::getById(500, 1); |
---|
39 | |
---|
40 | QCOMPARE(event.id(), 500); |
---|
41 | QCOMPARE(event.start(), QDateTime(QDate(2009, 2, 7), QTime(11, 30, 0), Qt::UTC)); |
---|
42 | QCOMPARE(event.trackId(), 123); |
---|
43 | |
---|
44 | // !!! TODO: typeId and languageId |
---|
45 | QCOMPARE(event.type(), QString("Podium")); |
---|
46 | QCOMPARE(event.language(), QString("English")); |
---|
47 | } |
---|
48 | |
---|
49 | void EventTest::getByDate() |
---|
50 | { |
---|
51 | QCOMPARE(Event::getByDate(QDate(2009, 2, 7), 1).count(), 127); |
---|
52 | QCOMPARE(Event::getByDate(QDate(2009, 2, 8), 1).count(), 154); |
---|
53 | } |
---|
54 | |
---|
55 | void EventTest::storingValues() |
---|
56 | { |
---|
57 | Event event; |
---|
58 | |
---|
59 | event.setId(10); |
---|
60 | event.setConferenceId(20); |
---|
61 | event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009")); |
---|
62 | event.setDuration(30); |
---|
63 | event.setTrackId(40); |
---|
64 | event.setType(QString("type")); |
---|
65 | event.setLanguage(QString("language")); |
---|
66 | |
---|
67 | QCOMPARE(event.id(), 10); |
---|
68 | QCOMPARE(event.conferenceId(), 20); |
---|
69 | QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009")); |
---|
70 | QCOMPARE(event.duration(), 30); |
---|
71 | QCOMPARE(event.trackId(), 40); |
---|
72 | QCOMPARE(event.type(), QString("type")); |
---|
73 | QCOMPARE(event.language(), QString("language")); |
---|
74 | } |
---|
75 | |
---|
76 | void EventTest::hydrate() |
---|
77 | { |
---|
78 | QSqlRecord record; |
---|
79 | record.append(QSqlField("duration", QVariant::Int)); |
---|
80 | record.append(QSqlField("id", QVariant::Int)); |
---|
81 | record.setValue(0, 10); |
---|
82 | record.setValue(1, 20); |
---|
83 | |
---|
84 | Event event = Event::hydrate(record); |
---|
85 | QCOMPARE(event.id(), 20); |
---|
86 | QCOMPARE(event.duration(), 10); |
---|
87 | } |
---|
88 | |
---|
89 | void EventTest::columnsForSelect() |
---|
90 | { |
---|
91 | QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_track,type,language")); |
---|
92 | QCOMPARE(Event::columnsForSelect("t0"), |
---|
93 | QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_track,t0.type,t0.language")); |
---|
94 | } |
---|
95 | |
---|
96 | void EventTest::selectQuery() |
---|
97 | { |
---|
98 | QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_track,type,language FROM event ")); |
---|
99 | } |
---|