515ab42295803e7fcc64ec3ec9d72acf4057e70d
[toast/confclerk.git] / src / test / model / eventtest.cpp
1 #include "eventtest.h"
2
3 #include <QtTest>
4 #include <QSqlDatabase>
5
6 #include <QDebug>
7
8 #include <event.h>
9
10 void EventTest::initTestCase()
11 {
12     // Connect to the test database. Ask Mr. Pavelka to generate one for you :)
13     QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
14     db.setDatabaseName("fosdem-test.sqlite");
15     QVERIFY(db.open());
16 }
17
18 void EventTest::getById()
19 {
20     Event event = Event::getById(500, 1);
21
22     QCOMPARE(event.id(), 500);
23     QCOMPARE(event.start(), QDateTime(QDate(2009, 2, 7), QTime(11, 30, 0), Qt::UTC));
24     QCOMPARE(event.activityId(), 123);
25
26     // !!! TODO: typeId and languageId
27     QCOMPARE(event.type(), QString("Podium"));
28     QCOMPARE(event.language(), QString("English"));
29 }
30
31 void EventTest::storingValues()
32 {
33     Event event;
34
35     event.setId(10);
36     event.setConferenceId(20);
37     event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
38     event.setDuration(30);
39     event.setActivityId(40);
40     event.setType(QString("type"));
41     event.setLanguage(QString("language"));
42
43     QCOMPARE(event.id(), 10);
44     QCOMPARE(event.conferenceId(), 20);
45     QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
46     QCOMPARE(event.duration(), 30);
47     QCOMPARE(event.activityId(), 40);
48     QCOMPARE(event.type(), QString("type"));
49     QCOMPARE(event.language(), QString("language"));
50 }
51
52 void EventTest::hydrate()
53 {
54     QSqlRecord record;
55     record.append(QSqlField("duration", QVariant::Int));
56     record.append(QSqlField("id", QVariant::Int));
57     record.setValue(0, 10);
58     record.setValue(1, 20);
59
60     Event event = Event::hydrate(record);
61     QCOMPARE(event.id(), 20);
62     QCOMPARE(event.duration(), 10);
63 }
64
65 void EventTest::columnsForSelect()
66 {
67     QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_activity,type,language"));
68     QCOMPARE(Event::columnsForSelect("t0"),
69              QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_activity,t0.type,t0.language"));
70 }
71
72 void EventTest::selectQuery()
73 {
74     QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_activity,type,language FROM event "));
75 }