2 * Copyright (C) 2010 Ixonos Plc.
4 * This file is part of fosdem-schedule.
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)
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
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/>.
19 #include "eventtest.h"
22 #include <QSqlDatabase>
28 void EventTest::initTestCase()
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");
36 void EventTest::getById()
38 Event event = Event::getById(500, 1);
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);
44 // !!! TODO: typeId and languageId
45 QCOMPARE(event.type(), QString("Podium"));
46 QCOMPARE(event.language(), QString("English"));
49 void EventTest::getByDate()
51 QCOMPARE(Event::getByDate(QDate(2009, 2, 7), 1).count(), 127);
52 QCOMPARE(Event::getByDate(QDate(2009, 2, 8), 1).count(), 154);
55 void EventTest::storingValues()
60 event.setConferenceId(20);
61 event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
62 event.setDuration(30);
64 event.setType(QString("type"));
65 event.setLanguage(QString("language"));
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"));
76 void EventTest::hydrate()
79 record.append(QSqlField("duration", QVariant::Int));
80 record.append(QSqlField("id", QVariant::Int));
81 record.setValue(0, 10);
82 record.setValue(1, 20);
84 Event event = Event::hydrate(record);
85 QCOMPARE(event.id(), 20);
86 QCOMPARE(event.duration(), 10);
89 void EventTest::columnsForSelect()
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"));
96 void EventTest::selectQuery()
98 QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_track,type,language FROM event "));