Adding database loading and data conversion to orm module
[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     QCOMPARE(event.id(), 500);
22     QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
23     QCOMPARE(event.activityId(), 123);
24
25     // !!! TODO: typeId and languageId
26     QCOMPARE(event.typeId(), 0);
27     QCOMPARE(event.languageId(), 0);
28 }
29
30 void EventTest::storingValues()
31 {
32     Event event;
33
34     event.setId(10);
35     event.setConferenceId(20);
36     event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
37     event.setDuration(30);
38     event.setActivityId(40);
39     event.setTypeId(50);
40     event.setLanguageId(60);
41
42     QCOMPARE(event.id(), 10);
43     QCOMPARE(event.conferenceId(), 20);
44     QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
45     QCOMPARE(event.duration(), 30);
46     QCOMPARE(event.activityId(), 40);
47     QCOMPARE(event.typeId(), 50);
48     QCOMPARE(event.languageId(), 60);
49 }
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 }