Adding database loading and data conversion to orm module
[toast/confclerk.git] / src / test / model / eventtest.cpp
index 2219f62e20f30ac0d56c792a54eeb3a51df51b9b..83f1996443abcbf4f9b33136c76b214385eaef2d 100644 (file)
@@ -11,7 +11,7 @@ void EventTest::initTestCase()
 {
     // Connect to the test database. Ask Mr. Pavelka to generate one for you :)
     QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
-    db.setDatabaseName("fostem-test.sqlite");
+    db.setDatabaseName("fosdem-test.sqlite");
     QVERIFY(db.open());
 }
 
@@ -27,40 +27,49 @@ void EventTest::getById()
     QCOMPARE(event.languageId(), 0);
 }
 
-void EventTest::colNames()
-{
-    QCOMPARE(Event::colName(Event::Id), QString("id"));
-    QCOMPARE(Event::colName(Event::Conference), QString("xid_conference"));
-    QCOMPARE(Event::colName(Event::Start), QString("start"));
-    QCOMPARE(Event::colName(Event::Duration), QString("duration"));
-    QCOMPARE(Event::colName(Event::Activity), QString("xid_activity"));
-    QCOMPARE(Event::colName(Event::Type), QString("type"));
-    QCOMPARE(Event::colName(Event::Language), QString("language"));
-}
-
 void EventTest::storingValues()
 {
     Event event;
-    QCOMPARE(event.id(), 0);
 
     event.setId(10);
-    QCOMPARE(event.id(), 10);
-
     event.setConferenceId(20);
-    QCOMPARE(event.conferenceId(), 20);
-
     event.setStart(QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
-    QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
-
     event.setDuration(30);
-    QCOMPARE(event.duration(), 30);
-
     event.setActivityId(40);
-    QCOMPARE(event.activityId(), 40);
-
     event.setTypeId(50);
-    QCOMPARE(event.typeId(), 50);
-
     event.setLanguageId(60);
+
+    QCOMPARE(event.id(), 10);
+    QCOMPARE(event.conferenceId(), 20);
+    QCOMPARE(event.start(), QDateTime::fromString("Sat Feb 7 11:30:00 2009"));
+    QCOMPARE(event.duration(), 30);
+    QCOMPARE(event.activityId(), 40);
+    QCOMPARE(event.typeId(), 50);
     QCOMPARE(event.languageId(), 60);
 }
+
+
+void EventTest::hydrate()
+{
+    QSqlRecord record;
+    record.append(QSqlField("duration", QVariant::Int));
+    record.append(QSqlField("id", QVariant::Int));
+    record.setValue(0, 10);
+    record.setValue(1, 20);
+
+    Event event = Event::hydrate(record);
+    QCOMPARE(event.id(), 20);
+    QCOMPARE(event.duration(), 10);
+}
+
+void EventTest::columnsForSelect()
+{
+    QCOMPARE(Event::columnsForSelect(), QString("id,xid_conference,start,duration,xid_activity,type,language"));
+    QCOMPARE(Event::columnsForSelect("t0"),
+             QString("t0.id,t0.xid_conference,t0.start,t0.duration,t0.xid_activity,t0.type,t0.language"));
+}
+
+void EventTest::selectQuery()
+{
+    QCOMPARE(Event::selectQuery(), QString("SELECT id,xid_conference,start,duration,xid_activity,type,language FROM event "));
+}