1 | /* |
---|
2 | * Copyright (C) 2010 Ixonos Plc. |
---|
3 | * Copyright (C) 2011-2021 Philipp Spitzer, gregor herrmann, Stefan Stahl |
---|
4 | * |
---|
5 | * This file is part of ConfClerk. |
---|
6 | * |
---|
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) |
---|
10 | * any later version. |
---|
11 | * |
---|
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 |
---|
15 | * more details. |
---|
16 | * |
---|
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/>. |
---|
19 | */ |
---|
20 | #include "eventtest.h" |
---|
21 | |
---|
22 | #include <QtTest> |
---|
23 | #include <QSqlDatabase> |
---|
24 | |
---|
25 | #include <QDebug> |
---|
26 | |
---|
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"); |
---|
33 | db.setDatabaseName("ConfClerk-test.sqlite"); |
---|
34 | QVERIFY(db.open()); |
---|
35 | } |
---|
36 | |
---|
37 | void EventTest::getById() |
---|
38 | { |
---|
39 | Event event = Event::getById(500, 1); |
---|
40 | |
---|
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); |
---|
44 | |
---|
45 | // !!! TODO: typeId and languageId |
---|
46 | QCOMPARE(event.type(), QString("Podium")); |
---|
47 | QCOMPARE(event.language(), QString("English")); |
---|
48 | } |
---|
49 | |
---|
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 | |
---|
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); |
---|
64 | event.setTrackId(40); |
---|
65 | event.setType(QString("type")); |
---|
66 | event.setLanguage(QString("language")); |
---|
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); |
---|
72 | QCOMPARE(event.trackId(), 40); |
---|
73 | QCOMPARE(event.type(), QString("type")); |
---|
74 | QCOMPARE(event.language(), QString("language")); |
---|
75 | } |
---|
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 | { |
---|
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")); |
---|
95 | } |
---|
96 | |
---|
97 | void EventTest::selectQuery() |
---|
98 | { |
---|
99 | QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_track,type,language FROM event ")); |
---|
100 | } |
---|