]> Git trees. - qtvoc.git/commitdiff
updated tests
authorReto Zingg <g.d0b3rm4n@gmail.com>
Sat, 13 Mar 2010 20:42:53 +0000 (22:42 +0200)
committerReto Zingg <g.d0b3rm4n@gmail.com>
Sat, 13 Mar 2010 20:42:53 +0000 (22:42 +0200)
lib/tests/tests.cpp
lib/tests/tests.kvtml [new file with mode: 0644]
lib/tests/tests.pro

index fe020268de25da503f82985e0313e1429b199df2..ed777a15999801f6011f7047d3f42edebca34fad 100644 (file)
@@ -5,9 +5,11 @@
 #include "keduvocdocument.h"
 #include "keduvoclesson.h"
 #include "keduvocexpression.h"
+#include "keduvocleitnerbox.h"
 
 #include <QTemporaryFile>
-
+#include <QDebug>
+#include <QList>
 
 class RmzTest : public QObject
 {
@@ -29,6 +31,13 @@ private slots:
         const QString comment = QString::fromLatin1( "comment" );
         const QString category = QString::fromLatin1( "test document" );
         const QString title = QString::fromLatin1( "Validator Test Title" );
+        const QString lang1 = QString::fromLatin1( "English" );
+        const QString lang2 = QString::fromLatin1( "German" );
+        const QString locale1 = QString::fromLatin1( "en" );
+        const QString locale2 = QString::fromLatin1( "de" );
+        const QString translation1 = QString::fromLatin1( "this is English" );
+        const QString translation2 = QString::fromLatin1( "das ist Deutsch" );
+        const QString lessonName = QString::fromLatin1( "Lesson No 1" );
         
         KEduVocDocument doc;
         doc.setAuthor( author );
@@ -39,31 +48,49 @@ private slots:
         
         doc.appendIdentifier();
         doc.appendIdentifier();
-        doc.identifier(0).setName("0");
-        doc.identifier(1).setName("1");
-        
-        KEduVocLesson* lesson = new KEduVocLesson("lesson", doc.lesson());
+        doc.identifier(0).setName( lang1 );
+        doc.identifier(0).setLocale( locale1 );
+        doc.identifier(1).setName( lang2 );
+        doc.identifier(1).setLocale( locale2 );
+
+        KEduVocLesson* lesson = new KEduVocLesson(lessonName, doc.lesson());
         doc.lesson()->appendChildContainer(lesson);
         lesson->appendEntry(new KEduVocExpression);
-        lesson->entry(0)->setTranslation(0, "0");
-        lesson->entry(0)->setTranslation(1, "1");
-        
+        lesson->entry(0)->setTranslation(0, translation1);
+        lesson->entry(0)->setTranslation(1, translation2);
+
         doc.saveAs(fileName, KEduVocDocument::Kvtml, generator);
-        
+
         KEduVocDocument docRead;
         docRead.open(fileName);
+
+
+        
+        QList<KEduVocContainer *>  lessons = docRead.lesson()->childContainers();
         
+        KEduVocLesson *m_lesson;
+        
+        foreach(KEduVocContainer * c, lessons) {
+            if (c->containerType() == KEduVocLesson::Lesson) {
+                    m_lesson = static_cast<KEduVocLesson *>(c);
+            }
+        }
+
         QCOMPARE( docRead.generator(), generator );
         QCOMPARE( docRead.author(), author );
         QCOMPARE( docRead.license(), license );
         QCOMPARE( docRead.documentComment(), comment );
         QCOMPARE( docRead.category(), category );
         QCOMPARE( docRead.title(), title );
-        QCOMPARE(doc.identifierCount(), 2);
-        QCOMPARE(lesson->entry(0)->translationIndices().size(), 2);
-        QCOMPARE(lesson->entry(0)->translation(0)->text(), QString("0"));
-        QCOMPARE(lesson->entry(0)->translation(1)->text(), QString("1"));
-        
+        QCOMPARE( docRead.identifierCount(), 2);
+        QCOMPARE( docRead.identifier(0).name(), lang1);
+        QCOMPARE( docRead.identifier(1).name(), lang2);
+        QCOMPARE( docRead.identifier(0).locale(), locale1);
+        QCOMPARE( docRead.identifier(1).locale(), locale2);
+        QCOMPARE( m_lesson->name(), lessonName);
+        QCOMPARE( m_lesson->entry(0)->translationIndices().size(), 2);
+        QCOMPARE( m_lesson->entry(0)->translation(0)->text(), translation1);
+        QCOMPARE( m_lesson->entry(0)->translation(1)->text(), translation2);
     }
     
 };
diff --git a/lib/tests/tests.kvtml b/lib/tests/tests.kvtml
new file mode 100644 (file)
index 0000000..b213355
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE kvtml PUBLIC "kvtml2.dtd" "http://edu.kde.org/kvtml/kvtml2.dtd">
+<kvtml version="2.0" >
+  <information>
+    <generator>Validator Unit Tests</generator>
+    <title>Validator Test Title</title>
+    <author>Validator Test</author>
+    <license>test license</license>
+    <comment>comment</comment>
+    <date>2010-03-13</date>
+    <category>test document</category>
+  </information>
+  <identifiers>
+    <identifier id="0" >
+      <name>English</name>
+      <locale>en</locale>
+    </identifier>
+    <identifier id="1" >
+      <name>German</name>
+      <locale>de</locale>
+    </identifier>
+  </identifiers>
+  <entries>
+    <entry id="0" >
+      <translation id="0" >
+        <text>this is English</text>
+      </translation>
+      <translation id="1" >
+        <text>das ist Deutsch</text>
+      </translation>
+    </entry>
+  </entries>
+  <lessons>
+    <container>
+      <name>lesson No 1</name>
+      <inpractice>true</inpractice>
+      <entry id="0" />
+    </container>
+  </lessons>
+</kvtml>
index 2c41990a04a784a1f8bd830e03362e1a93875621..ed9f625816e19bbcfd0eda4970c1849c1bdf68f7 100644 (file)
@@ -8,7 +8,7 @@ DEPENDPATH += . ../
 INCLUDEPATH += . ../
 LIBS += -L../ -lkeduvocdocument
 QT += core testlib
-CONFIG +=qtestlib
+CONFIG += qtestlib
 
 # Input
 SOURCES += tests.cpp