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