2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2014 Philipp Spitzer, gregor herrmann, Stefan Stahl
5 * This file is part of ConfClerk.
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
20 #include "eventtest.h"
23 #include <QSqlDatabase>
29 void EventTest::initTestCase()
31 // Connect to the test database. Ask Mr. Pavelka to generate one for you :)
32 QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
33 db.setDatabaseName("ConfClerk-test.sqlite");
37 void EventTest::getById()
39 Event event = Event::getById(500, 1);
41 QCOMPARE(event.id(), 500);
42 QCOMPARE(event.start(), QDateTime(QDate(2009, 2, 7), QTime(11, 30, 0), Qt::UTC));
43 QCOMPARE(event.trackId(), 123);
45 // !!! TODO: typeId and languageId
46 QCOMPARE(event.type(), QString("Podium"));
47 QCOMPARE(event.language(), QString("English"));
50 void EventTest::getByDate()
52 QCOMPARE(Event::getByDate(QDate(2009, 2, 7), 1).count(), 127);
53 QCOMPARE(Event::getByDate(QDate(2009, 2, 8), 1).count(), 154);
56 void EventTest::storingValues()
61 event.setConferenceId(20);
62 event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
63 event.setDuration(30);
65 event.setType(QString("type"));
66 event.setLanguage(QString("language"));
68 QCOMPARE(event.id(), 10);
69 QCOMPARE(event.conferenceId(), 20);
70 QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
71 QCOMPARE(event.duration(), 30);
72 QCOMPARE(event.trackId(), 40);
73 QCOMPARE(event.type(), QString("type"));
74 QCOMPARE(event.language(), QString("language"));
77 void EventTest::hydrate()
80 record.append(QSqlField("duration", QVariant::Int));
81 record.append(QSqlField("id", QVariant::Int));
82 record.setValue(0, 10);
83 record.setValue(1, 20);
85 Event event = Event::hydrate(record);
86 QCOMPARE(event.id(), 20);
87 QCOMPARE(event.duration(), 10);
90 void EventTest::columnsForSelect()
92 QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_track,type,language"));
93 QCOMPARE(Event::columnsForSelect("t0"),
94 QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_track,t0.type,t0.language"));
97 void EventTest::selectQuery()
99 QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_track,type,language FROM event "));