[e5bc908] | 1 | #include "eventtest.h" |
---|
| 2 | |
---|
| 3 | #include <QtTest> |
---|
| 4 | #include <QSqlDatabase> |
---|
| 5 | |
---|
[5a73d27] | 6 | #include <QDebug> |
---|
| 7 | |
---|
[e5bc908] | 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"); |
---|
[20a6010] | 14 | db.setDatabaseName("fosdem-test.sqlite"); |
---|
[e5bc908] | 15 | QVERIFY(db.open()); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | void EventTest::getById() |
---|
| 19 | { |
---|
| 20 | Event event = Event::getById(500, 1); |
---|
[489f262] | 21 | |
---|
[e5bc908] | 22 | QCOMPARE(event.id(), 500); |
---|
[489f262] | 23 | QCOMPARE(event.start(), QDateTime(QDate(2009, 2, 7), QTime(11, 30, 0), Qt::UTC)); |
---|
[e5bc908] | 24 | QCOMPARE(event.activityId(), 123); |
---|
| 25 | |
---|
| 26 | // !!! TODO: typeId and languageId |
---|
[489f262] | 27 | QCOMPARE(event.type(), QString("Podium")); |
---|
| 28 | QCOMPARE(event.language(), QString("English")); |
---|
[e5bc908] | 29 | } |
---|
[5a73d27] | 30 | |
---|
[d0d0a66] | 31 | void EventTest::getByDate() |
---|
| 32 | { |
---|
| 33 | QCOMPARE(Event::getByDate(QDate(2009, 2, 7), 1).count(), 127); |
---|
| 34 | QCOMPARE(Event::getByDate(QDate(2009, 2, 8), 1).count(), 154); |
---|
| 35 | } |
---|
| 36 | |
---|
[5a73d27] | 37 | void EventTest::storingValues() |
---|
| 38 | { |
---|
| 39 | Event event; |
---|
| 40 | |
---|
| 41 | event.setId(10); |
---|
| 42 | event.setConferenceId(20); |
---|
| 43 | event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009")); |
---|
| 44 | event.setDuration(30); |
---|
| 45 | event.setActivityId(40); |
---|
[489f262] | 46 | event.setType(QString("type")); |
---|
| 47 | event.setLanguage(QString("language")); |
---|
[20a6010] | 48 | |
---|
| 49 | QCOMPARE(event.id(), 10); |
---|
| 50 | QCOMPARE(event.conferenceId(), 20); |
---|
| 51 | QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009")); |
---|
| 52 | QCOMPARE(event.duration(), 30); |
---|
| 53 | QCOMPARE(event.activityId(), 40); |
---|
[489f262] | 54 | QCOMPARE(event.type(), QString("type")); |
---|
| 55 | QCOMPARE(event.language(), QString("language")); |
---|
[5a73d27] | 56 | } |
---|
[20a6010] | 57 | |
---|
| 58 | void EventTest::hydrate() |
---|
| 59 | { |
---|
| 60 | QSqlRecord record; |
---|
| 61 | record.append(QSqlField("duration", QVariant::Int)); |
---|
| 62 | record.append(QSqlField("id", QVariant::Int)); |
---|
| 63 | record.setValue(0, 10); |
---|
| 64 | record.setValue(1, 20); |
---|
| 65 | |
---|
| 66 | Event event = Event::hydrate(record); |
---|
| 67 | QCOMPARE(event.id(), 20); |
---|
| 68 | QCOMPARE(event.duration(), 10); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | void EventTest::columnsForSelect() |
---|
| 72 | { |
---|
| 73 | QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_activity,type,language")); |
---|
| 74 | QCOMPARE(Event::columnsForSelect("t0"), |
---|
| 75 | QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_activity,t0.type,t0.language")); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void EventTest::selectQuery() |
---|
| 79 | { |
---|
| 80 | QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_activity,type,language FROM event ")); |
---|
| 81 | } |
---|