Commit c1c67113 authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Port scheme tests to resources

parent 989d031a
......@@ -131,12 +131,15 @@ 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)
......@@ -50,7 +50,7 @@ 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());
......
......@@ -51,13 +51,13 @@ 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());
......
......@@ -22,10 +22,12 @@
#include "core/language.h"
#include "core/unit.h"
#include "core/phrase.h"
#include "core/resources/courseparser.h"
#include <QTest>
#include <QDebug>
#include <QTemporaryFile>
#include <QDirIterator>
#include <QUrl>
#include <QIODevice>
......@@ -49,42 +51,9 @@ 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());
......@@ -92,17 +61,18 @@ void TestLanguageFiles::languageSchemeValidationTest()
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());
......
......@@ -54,25 +54,6 @@ private slots:
* 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment