File indexing completed on 2024-04-28 07:36:26

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Andreas Xavier <andxav at zoho dot com>
0003  * SPDX-License-Identifier: GPL-2.0-or-later
0004  */
0005 
0006 #include "keduvocdocument.h"
0007 #include "keduvocxdxfreader.h"
0008 #include "readermanager.h"
0009 
0010 #include "readerTestHelpers.h"
0011 
0012 #include <QDebug>
0013 #include <QTest>
0014 
0015 namespace XdxfReaderUnitTests
0016 {
0017 
0018 /**
0019  * @file readerxdxftest.cpp
0020  * Unit Tests of parsing of Xdxf strings
0021  *
0022  * Each test creates a QString of Xdxf format
0023  * reads, parses and verifies the parse.  The portions of the
0024  * generator object relevant to each test are defined in this file.
0025  *
0026  * The current tests are cursory.
0027  * @todo add check to verify that the words are actually in the kvocdocument
0028  * */
0029 
0030 /**
0031  * @brief Unit Tests of parsing of Xdxf strings
0032  *
0033  * Each test creates a string
0034  * reads, parses and verifies the parse.
0035  * */
0036 
0037 class XdxfReaderTest : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 private slots:
0042     /** Initialize the string*/
0043     void init();
0044     /** Two word doc*/
0045     void testParseTwoWord();
0046     /** InvalidDoc*/
0047     void testParseInvalid();
0048 
0049 private:
0050     QString oneGoodDoc;
0051     KEduVocDocument::FileType myType;
0052 };
0053 
0054 void XdxfReaderTest::init()
0055 {
0056     oneGoodDoc = QStringLiteral("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") + "<!DOCTYPE xdxf SYSTEM \"http://xdxf.sourceforge.net/xdxf_lousy.dtd\">\n"
0057         + "<xdxf lang_from=\"GER\" lang_to=\"SPA\" format=\"visual\">\net" + "<full_name>German Spanish</full_name>\n"
0058         + "<description>Description of German and Spanish</description>\n" + "" + "<ar><k>Hund</k>el perro</ar>\n" + "<ar><k>Schwein</k>el cerdo</ar>\n"
0059         + "</xdxf>\n";
0060     myType = KEduVocDocument::Xdxf;
0061 }
0062 
0063 void XdxfReaderTest::testParseTwoWord()
0064 {
0065     KVOCREADER_EXPECT(oneGoodDoc, KEduVocDocument::NoError, myType);
0066 }
0067 
0068 void XdxfReaderTest::testParseInvalid()
0069 {
0070     QString invalid = oneGoodDoc + " bad parse";
0071 
0072     KVOCREADER_EXPECT(invalid, KEduVocDocument::FileReaderFailed, myType);
0073 }
0074 
0075 }
0076 
0077 QTEST_MAIN(XdxfReaderUnitTests::XdxfReaderTest)
0078 
0079 #include "readerxdxftest.moc"