diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 9d2fafb..9c09fd8 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,142 +1,145 @@ ### # Copyright 2013-2019 Andreas Cord-Landwehr # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ### include_directories( ../src/ ../ ${CMAKE_CURRENT_BINARY_DIR} ) # copy test data file(COPY testdata/courses/de.xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/courses/de/) # copy test files file(COPY testdata/courses/fr.xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/courses/fr/) # copy test files file(COPY testdata/contributorrepository/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/contributorrepository/) # copy test files set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) # repository tests set(TestResourceRepository_SRCS resourcerepository/test_resourcerepository.cpp) qt5_add_resources(TestResourceRepository_SRCS ../data/languages.qrc) add_executable(test_resourcerepository ${TestResourceRepository_SRCS}) target_link_libraries(test_resourcerepository artikulatecore Qt5::Test ) add_test(NAME test_resourcerepository COMMAND test_resourcerepository) ecm_mark_as_test(test_resourcerepository) # integration tests for iresource repository interface derived classes set(TestIResourceRepository_SRCS iresourcerepository_integration/test_iresourcerepository.cpp) qt5_add_resources(TestIResourceRepository_SRCS ../data/languages.qrc) add_executable(test_iresourcerepository_integration ${TestIResourceRepository_SRCS}) target_link_libraries(test_iresourcerepository_integration artikulatecore Qt5::Test ) add_test(NAME test_iresourcerepository_integration COMMAND test_iresourcerepository_integration) ecm_mark_as_test(test_iresourcerepository_integration) # training session tests set(TestTrainingSession_SRCS trainingsession/test_trainingsession.cpp) add_executable(test_trainingsession ${TestTrainingSession_SRCS}) target_link_libraries(test_trainingsession artikulatecore Qt5::Test ) add_test(NAME test_trainingsession COMMAND test_trainingsession) ecm_mark_as_test(test_trainingsession) # editor session tests set(TestEditorSession_SRCS editorsession/test_editorsession.cpp editorsession/editablerepositorystub.cpp ) add_executable(test_editorsession ${TestEditorSession_SRCS}) target_link_libraries(test_editorsession artikulatecore Qt5::Test ) add_test(NAME test_editorsession COMMAND test_editorsession) ecm_mark_as_test(test_editorsession) # test course resource class set(TestCourseResource_SRCS courseresource/test_courseresource.cpp courseresource/resourcerepositorystub.cpp ) qt5_add_resources(TestCourseResource_SRCS ../data/languages.qrc) add_executable(test_courseresource ${TestCourseResource_SRCS} ) target_link_libraries(test_courseresource artikulatecore Qt5::Test ) add_test(NAME test_courseresource COMMAND test_courseresource) ecm_mark_as_test(test_courseresource) # test skeleton resource class set(TestSkeletonResource_SRCS skeletonresource/test_skeletonresource.cpp skeletonresource/resourcerepositorystub.cpp ) qt5_add_resources(TestSkeletonResource_SRCS ../data/languages.qrc) add_executable(test_skeletonresource ${TestSkeletonResource_SRCS} ) target_link_libraries(test_skeletonresource artikulatecore Qt5::Test ) add_test(NAME test_skeletonresource COMMAND test_skeletonresource) ecm_mark_as_test(test_skeletonresource) # test editable course resource class set(TestEditableCourseResource_SRCS editablecourseresource/test_editablecourseresource.cpp editablecourseresource/resourcerepositorystub.cpp ) qt5_add_resources(TestEditableCourseResource_SRCS ../data/languages.qrc) qt5_add_resources(TestEditableCourseResource_SRCS testdata/testdata.qrc) add_executable(test_editablecourseresource ${TestEditableCourseResource_SRCS} ) target_link_libraries(test_editablecourseresource artikulatecore Qt5::Test ) add_test(NAME test_editablecourseresource COMMAND test_editablecourseresource) ecm_mark_as_test(test_editablecourseresource) -# basic tests language files (input/output) -set(TestLanguageFiles_SRCS testlanguagefiles.cpp) -add_executable(TestLanguageFiles ${TestLanguageFiles_SRCS} ) -target_link_libraries(TestLanguageFiles +# basic tests language resource conformance with XSD +set(TestLanguageFiles_SRCS + languageresources/testlanguagefiles.cpp +) +qt5_add_resources(TestLanguageFiles_SRCS ../data/languages.qrc) +add_executable(test_languageresources ${TestLanguageFiles_SRCS} ) +target_link_libraries(test_languageresources artikulatecore Qt5::Test ) -add_test(NAME TestLanguageFiles COMMAND TestLanguageFiles) -ecm_mark_as_test(TestLanguageFiles) +add_test(NAME test_languageresources COMMAND test_languageresources) +ecm_mark_as_test(test_languageresources) diff --git a/autotests/courseresource/test_courseresource.cpp b/autotests/courseresource/test_courseresource.cpp index 73a6061..88676f2 100644 --- a/autotests/courseresource/test_courseresource.cpp +++ b/autotests/courseresource/test_courseresource.cpp @@ -1,192 +1,192 @@ /* * Copyright 2013 Andreas Cord-Landwehr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "test_courseresource.h" #include "resourcerepositorystub.h" #include "core/language.h" #include "core/unit.h" #include "core/phrase.h" #include "core/resources/languageresource.h" #include "core/resources/courseresource.h" #include #include #include #include #include #include #include #include #include TestCourseResource::TestCourseResource() { } void TestCourseResource::init() { } void TestCourseResource::cleanup() { } void TestCourseResource::courseSchemeValidationTest() { - QUrl schemeFile = QUrl::fromLocalFile(QStringLiteral("schemes/course.xsd")); + QUrl schemeFile = QUrl::fromLocalFile(":/artikulate/schemes/course.xsd"); QXmlSchema courseSchema; QVERIFY(courseSchema.load(schemeFile)); QVERIFY(courseSchema.isValid()); } void TestCourseResource::loadCourseResource() { Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); const QString courseDirectory = "data/courses/de/"; const QString courseFile = courseDirectory + "de.xml"; CourseResource course(QUrl::fromLocalFile(courseFile), &repository); QCOMPARE(course.file().toLocalFile(), courseFile); QCOMPARE(course.id(), "de"); QCOMPARE(course.foreignId(), "artikulate-basic"); QCOMPARE(course.title(), "Artikulate Deutsch"); QCOMPARE(course.description(), "Ein Kurs in (hoch-)deutscher Aussprache."); QVERIFY(course.language() != nullptr); QCOMPARE(course.language()->id(), "de"); QCOMPARE(course.unitList().count(), 1); const auto unit = course.unitList().first(); QVERIFY(unit != nullptr); QCOMPARE(unit->id(), "1"); QCOMPARE(unit->title(), QStringLiteral("Auf der Straße")); QCOMPARE(unit->foreignId(), "{dd60f04a-eb37-44b7-9787-67aaf7d3578d}"); QCOMPARE(unit->phraseList().count(), 3); // note: this test takes the silent assumption that phrases are added to the list in same // order as they are defined in the file. This assumption should be made explicit or dropped const auto firstPhrase = unit->phraseList().first(); QVERIFY(firstPhrase != nullptr); QCOMPARE(firstPhrase->id(), "1"); QCOMPARE(firstPhrase->foreignId(), "{3a4c1926-60d7-44c6-80d1-03165a641c75}"); QCOMPARE(firstPhrase->text(), "Guten Tag."); QCOMPARE(firstPhrase->soundFileUrl(), courseDirectory + "de_01.ogg"); QCOMPARE(firstPhrase->type(), Phrase::Type::Sentence); QVERIFY(firstPhrase->phonemes().isEmpty()); } void TestCourseResource::unitAddAndRemoveHandling() { // boilerplate Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); const QString courseDirectory = "data/courses/de/"; const QString courseFile = courseDirectory + "de.xml"; CourseResource course(QUrl::fromLocalFile(courseFile), &repository); // begin of test Unit unit; unit.setId("testunit"); const int initialUnitNumber = course.unitList().count(); QCOMPARE(initialUnitNumber, 1); QSignalSpy spyAboutToBeAdded(&course, SIGNAL(unitAboutToBeAdded(Unit*, int))); QSignalSpy spyAdded(&course, SIGNAL(unitAdded())); QCOMPARE(spyAboutToBeAdded.count(), 0); QCOMPARE(spyAdded.count(), 0); course.addUnit(&unit); QCOMPARE(course.unitList().count(), initialUnitNumber + 1); QCOMPARE(spyAboutToBeAdded.count(), 1); QCOMPARE(spyAdded.count(), 1); } void TestCourseResource::coursePropertyChanges() { // boilerplate Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); const QString courseDirectory = "data/courses/de/"; const QString courseFile = courseDirectory + "de.xml"; CourseResource course(QUrl::fromLocalFile(courseFile), &repository); // id { const QString value = "newId"; QSignalSpy spy(&course, SIGNAL(idChanged())); QCOMPARE(spy.count(), 0); course.setId(value); QCOMPARE(course.id(), value); QCOMPARE(spy.count(), 1); } // foreign id { const QString value = "newForeignId"; QSignalSpy spy(&course, SIGNAL(foreignIdChanged())); QCOMPARE(spy.count(), 0); course.setForeignId(value); QCOMPARE(course.foreignId(), value); QCOMPARE(spy.count(), 1); } // title { const QString value = "newTitle"; QSignalSpy spy(&course, SIGNAL(titleChanged())); QCOMPARE(spy.count(), 0); course.setTitle(value); QCOMPARE(course.title(), value); QCOMPARE(spy.count(), 1); } // title { const QString value = "newI18nTitle"; QSignalSpy spy(&course, SIGNAL(i18nTitleChanged())); QCOMPARE(spy.count(), 0); course.setI18nTitle(value); QCOMPARE(course.i18nTitle(), value); QCOMPARE(spy.count(), 1); } // description { const QString value = "newDescription"; QSignalSpy spy(&course, SIGNAL(descriptionChanged())); QCOMPARE(spy.count(), 0); course.setDescription(value); QCOMPARE(course.description(), value); QCOMPARE(spy.count(), 1); } // language { Language testLanguage; QSignalSpy spy(&course, SIGNAL(languageChanged())); QCOMPARE(spy.count(), 0); course.setLanguage(&testLanguage); QCOMPARE(course.language(), &testLanguage); QCOMPARE(spy.count(), 1); } } QTEST_GUILESS_MAIN(TestCourseResource) diff --git a/autotests/editablecourseresource/test_editablecourseresource.cpp b/autotests/editablecourseresource/test_editablecourseresource.cpp index 58ed1b3..d625e6d 100644 --- a/autotests/editablecourseresource/test_editablecourseresource.cpp +++ b/autotests/editablecourseresource/test_editablecourseresource.cpp @@ -1,241 +1,241 @@ /* * Copyright 2013-2019 Andreas Cord-Landwehr * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "test_editablecourseresource.h" #include "resourcerepositorystub.h" #include "core/language.h" #include "core/unit.h" #include "core/phrase.h" #include "core/resources/courseparser.h" #include "core/resources/languageresource.h" #include "core/resources/editablecourseresource.h" #include #include #include #include #include #include #include #include #include TestEditableCourseResource::TestEditableCourseResource() { } void TestEditableCourseResource::init() { } void TestEditableCourseResource::cleanup() { } void TestEditableCourseResource::courseSchemeValidationTest() { - QUrl schemeFile = QUrl::fromLocalFile(QStringLiteral("schemes/course.xsd")); + QUrl schemeFile = QUrl::fromLocalFile(":/artikulate/schemes/course.xsd"); QXmlSchema courseSchema; QVERIFY(courseSchema.load(schemeFile)); QVERIFY(courseSchema.isValid()); //TODO shall be used in skeleton specific test - QUrl skeletonFile = QUrl::fromLocalFile(QStringLiteral("schemes/skeleton.xsd")); + QUrl skeletonFile = QUrl::fromLocalFile(":/artikulate/schemes/skeleton.xsd"); QXmlSchema skeletonScheme; QVERIFY(skeletonScheme.load(skeletonFile)); QVERIFY(skeletonScheme.isValid()); } void TestEditableCourseResource::loadCourseResource() { Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); EditableCourseResource course(QUrl::fromLocalFile(":/courses/de.xml"), &repository); QCOMPARE(course.file().toLocalFile(), ":/courses/de.xml"); QCOMPARE(course.id(), "de"); QCOMPARE(course.foreignId(), "artikulate-basic"); QCOMPARE(course.title(), "Artikulate Deutsch"); QCOMPARE(course.description(), "Ein Kurs in (hoch-)deutscher Aussprache."); QVERIFY(course.language() != nullptr); QCOMPARE(course.language()->id(), "de"); QCOMPARE(course.unitList().count(), 1); const auto unit = course.unitList().first(); QVERIFY(unit != nullptr); QCOMPARE(unit->id(), "1"); QCOMPARE(unit->title(), QStringLiteral("Auf der Straße")); QCOMPARE(unit->foreignId(), "{dd60f04a-eb37-44b7-9787-67aaf7d3578d}"); QCOMPARE(unit->phraseList().count(), 3); // note: this test takes the silent assumption that phrases are added to the list in same // order as they are defined in the file. This assumption should be made explicit or dropped const auto firstPhrase = unit->phraseList().first(); QVERIFY(firstPhrase != nullptr); QCOMPARE(firstPhrase->id(), "1"); QCOMPARE(firstPhrase->foreignId(), "{3a4c1926-60d7-44c6-80d1-03165a641c75}"); QCOMPARE(firstPhrase->text(), "Guten Tag."); QCOMPARE(firstPhrase->soundFileUrl(), ":/courses/de_01.ogg"); QCOMPARE(firstPhrase->type(), Phrase::Type::Sentence); QVERIFY(firstPhrase->phonemes().isEmpty()); } void TestEditableCourseResource::unitAddAndRemoveHandling() { // boilerplate Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); EditableCourseResource course(QUrl::fromLocalFile(":/courses/de.xml"), &repository); // begin of test Unit *unit = new Unit; // TODO: change to unique pointer when interface is changed to scoped pointers unit->setId("testunit"); const int initialUnitNumber = course.unitList().count(); QCOMPARE(initialUnitNumber, 1); QSignalSpy spyAboutToBeAdded(&course, SIGNAL(unitAboutToBeAdded(Unit*, int))); QSignalSpy spyAdded(&course, SIGNAL(unitAdded())); QCOMPARE(spyAboutToBeAdded.count(), 0); QCOMPARE(spyAdded.count(), 0); course.addUnit(unit); QCOMPARE(course.unitList().count(), initialUnitNumber + 1); QCOMPARE(spyAboutToBeAdded.count(), 1); QCOMPARE(spyAdded.count(), 1); } void TestEditableCourseResource::coursePropertyChanges() { // boilerplate Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); CourseResource course(QUrl::fromLocalFile(":/courses/de.xml"), &repository); // id { const QString value = "newId"; QSignalSpy spy(&course, SIGNAL(idChanged())); QCOMPARE(spy.count(), 0); course.setId(value); QCOMPARE(course.id(), value); QCOMPARE(spy.count(), 1); } // foreign id { const QString value = "newForeignId"; QSignalSpy spy(&course, SIGNAL(foreignIdChanged())); QCOMPARE(spy.count(), 0); course.setForeignId(value); QCOMPARE(course.foreignId(), value); QCOMPARE(spy.count(), 1); } // title { const QString value = "newTitle"; QSignalSpy spy(&course, SIGNAL(titleChanged())); QCOMPARE(spy.count(), 0); course.setTitle(value); QCOMPARE(course.title(), value); QCOMPARE(spy.count(), 1); } // title { const QString value = "newI18nTitle"; QSignalSpy spy(&course, SIGNAL(i18nTitleChanged())); QCOMPARE(spy.count(), 0); course.setI18nTitle(value); QCOMPARE(course.i18nTitle(), value); QCOMPARE(spy.count(), 1); } // description { const QString value = "newDescription"; QSignalSpy spy(&course, SIGNAL(descriptionChanged())); QCOMPARE(spy.count(), 0); course.setDescription(value); QCOMPARE(course.description(), value); QCOMPARE(spy.count(), 1); } // language { Language testLanguage; QSignalSpy spy(&course, SIGNAL(languageChanged())); QCOMPARE(spy.count(), 0); course.setLanguage(&testLanguage); QCOMPARE(course.language(), &testLanguage); QCOMPARE(spy.count(), 1); } } void TestEditableCourseResource::fileLoadSaveCompleteness() { // boilerplate Language language; language.setId("de"); ResourceRepositoryStub repository({&language}); EditableCourseResource course(QUrl::fromLocalFile(":/courses/de.xml"), &repository); QTemporaryFile outputFile; outputFile.open(); course.exportCourse(QUrl::fromLocalFile(outputFile.fileName())); // note: this only works, since the resource manager not checks uniqueness of course ids! EditableCourseResource loadedCourse(QUrl::fromLocalFile(outputFile.fileName()), &repository); // test that we actually call the different files QVERIFY(course.file().toLocalFile() != loadedCourse.file().toLocalFile()); QVERIFY(course.id() == loadedCourse.id()); QVERIFY(course.foreignId() == loadedCourse.foreignId()); QVERIFY(course.title() == loadedCourse.title()); QVERIFY(course.description() == loadedCourse.description()); QVERIFY(course.language()->id() == loadedCourse.language()->id()); QVERIFY(course.unitList().count() == loadedCourse.unitList().count()); Unit *testUnit = course.unitList().constFirst(); Unit *compareUnit = loadedCourse.unitList().constFirst(); QVERIFY(testUnit->id() == compareUnit->id()); QVERIFY(testUnit->foreignId() == compareUnit->foreignId()); QVERIFY(testUnit->title() == compareUnit->title()); QVERIFY(testUnit->phraseList().count() == compareUnit->phraseList().count()); Phrase *testPhrase = testUnit->phraseList().constFirst(); Phrase *comparePhrase = new Phrase(this); // note that this actually means that we DO NOT respect phrase orders by list order for (Phrase *phrase : compareUnit->phraseList()) { if (testPhrase->id() == phrase->id()) { comparePhrase = phrase; break; } } QVERIFY(testPhrase->id() == comparePhrase->id()); QVERIFY(testPhrase->foreignId() == comparePhrase->foreignId()); QVERIFY(testPhrase->text() == comparePhrase->text()); QVERIFY(testPhrase->type() == comparePhrase->type()); QVERIFY(testPhrase->sound().fileName() == comparePhrase->sound().fileName()); QVERIFY(testPhrase->phonemes().count() == comparePhrase->phonemes().count()); } QTEST_GUILESS_MAIN(TestEditableCourseResource) diff --git a/autotests/testlanguagefiles.cpp b/autotests/languageresources/testlanguagefiles.cpp similarity index 66% rename from autotests/testlanguagefiles.cpp rename to autotests/languageresources/testlanguagefiles.cpp index 06a9375..cf971bd 100644 --- a/autotests/testlanguagefiles.cpp +++ b/autotests/languageresources/testlanguagefiles.cpp @@ -1,131 +1,101 @@ /* * Copyright 2013 Oindrila Gupta * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "testlanguagefiles.h" #include "core/language.h" #include "core/unit.h" #include "core/phrase.h" +#include "core/resources/courseparser.h" #include #include #include +#include #include #include #include #include #include #include #include TestLanguageFiles::TestLanguageFiles() { } void TestLanguageFiles::init() { // TODO initialization of test case } void TestLanguageFiles::cleanup() { // TODO cleanup after test run } -QXmlSchema TestLanguageFiles::loadXmlSchema(const QString &schemeName) const -{ - QString relPath = QStringLiteral("schemes/%1.xsd").arg(schemeName); - QUrl file = QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::DataLocation, relPath)); - - QXmlSchema schema; - if (schema.load(file) == false) { - qWarning() << "Schema at file " << file.toLocalFile() << " is invalid."; - } - return schema; -} - -QDomDocument TestLanguageFiles::loadDomDocument(const QUrl &path, const QXmlSchema &schema) const -{ - QDomDocument document; - QXmlSchemaValidator validator(schema); - if (!validator.validate(path)) { - qWarning() << "Schema is not valid, aborting loading of XML document:" << path.toLocalFile(); - return document; - } - - QString errorMsg; - QFile file(path.toLocalFile()); - if (file.open(QIODevice::ReadOnly)) { - if (!document.setContent(&file, &errorMsg)) { - qWarning() << errorMsg; - } - } else { - qWarning() << "Could not open XML document " << path.toLocalFile() << " for reading, aborting."; - } - return document; -} - void TestLanguageFiles::languageSchemeValidationTest() { - QUrl languageFile = QUrl::fromLocalFile(QStringLiteral("schemes/language.xsd")); + QUrl languageFile = QUrl::fromLocalFile(":/artikulate/schemes/language.xsd"); QXmlSchema languageSchema; QVERIFY(languageSchema.load(languageFile)); QVERIFY(languageSchema.isValid()); } void TestLanguageFiles::checkIdUniqueness() { - QStringList languageFiles = QStandardPaths::locateAll(QStandardPaths::DataLocation, QStringLiteral("data/languages/*.xml")); - foreach (const QString &file, languageFiles) { + QDirIterator iter(QDir(":/artikulate/languages/")); + while (iter.hasNext()) { + const QString &file = iter.next(); qDebug() << "File being parsed: " << file; QStringList idList; const QUrl &languageFile = QUrl::fromLocalFile(file); QVERIFY(languageFile.isLocalFile()); - QXmlSchema schema = loadXmlSchema(QStringLiteral("language")); + QXmlSchema schema = CourseParser::loadXmlSchema(QStringLiteral("language")); QVERIFY(schema.isValid()); - QDomDocument document = loadDomDocument(languageFile, schema); + QDomDocument document = CourseParser::loadDomDocument(languageFile, schema); QVERIFY(!document.isNull()); QDomElement root(document.documentElement()); Language *language = new Language(this); language->setFile(languageFile); language->setId(root.firstChildElement(QStringLiteral("id")).text()); language->setTitle(root.firstChildElement(QStringLiteral("title")).text()); // create phoneme groups for (QDomElement groupNode = root.firstChildElement(QStringLiteral("phonemeGroups")).firstChildElement(); !groupNode.isNull(); groupNode = groupNode.nextSiblingElement()) { for (QDomElement phonemeNode = groupNode.firstChildElement(QStringLiteral("phonemes")).firstChildElement(); !phonemeNode.isNull(); phonemeNode = phonemeNode.nextSiblingElement()) { QString id = phonemeNode.firstChildElement(QStringLiteral("id")).text(); qDebug() << "ID: " << id; QVERIFY2(!idList.contains(id),"Phoneme ID used more than once in the tested file"); idList.append(id); } } } } QTEST_GUILESS_MAIN(TestLanguageFiles) diff --git a/autotests/testlanguagefiles.h b/autotests/languageresources/testlanguagefiles.h similarity index 68% rename from autotests/testlanguagefiles.h rename to autotests/languageresources/testlanguagefiles.h index 5ac3754..f3ff5a2 100644 --- a/autotests/testlanguagefiles.h +++ b/autotests/languageresources/testlanguagefiles.h @@ -1,78 +1,59 @@ /* * Copyright 2013 Oindrila Gupta * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef TESTLANGUAGEFILES_H #define TESTLANGUAGEFILES_H #include class QXmlSchema; class QDomDocument; class QUrl; class TestLanguageFiles : public QObject { Q_OBJECT public: TestLanguageFiles(); private slots: /** * Called before every test case. */ void init(); /** * Called after every test case. */ void cleanup(); /** * Test if language XSD specification is valid. */ void languageSchemeValidationTest(); /** * Test if id of each phoneme is unique in every language file. */ void checkIdUniqueness(); - -private: - /** - * Load XSD file given by its file name (without ".xsd" suffix). The method searches exclusively - * the standard install dir for XSD files in subdirectory "schemes/". - * - * \param schemeName name of the Xml schema without suffix - * \return loaded XML Schema - */ - QXmlSchema loadXmlSchema(const QString &schemeName) const; - - /** - * Load XML file given by \p file that confirms with XML schema \p scheme. - * - * \param path is the path to the XML file to be loaded - * \param scheme is the XML schema describing the DOM - * \return the loaded DOM document - */ - QDomDocument loadDomDocument(const QUrl &path, const QXmlSchema &schema) const; }; #endif