File indexing completed on 2024-04-21 03:48:17
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 "keduvocvokabelnreader.h" 0008 #include "readermanager.h" 0009 0010 #include "readerTestHelpers.h" 0011 0012 #include <QDebug> 0013 #include <QTest> 0014 0015 namespace VokabelnReaderUnitTests 0016 { 0017 0018 /** 0019 * @file readervokabelntest.cpp 0020 * Unit Tests of parsing of Vokabeln strings 0021 * 0022 * Each test creates a QString of Vokabeln 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 and the reader is fragile. 0027 * */ 0028 0029 /** 0030 * @brief Unit Tests of parsing of Vokabeln strings 0031 * 0032 * Each test creates a string 0033 * reads, parses and verifies the parse. 0034 * */ 0035 0036 class VokabelnReaderTest : public QObject 0037 { 0038 Q_OBJECT 0039 0040 private slots: 0041 /** Initialize the string*/ 0042 void init(); 0043 /** Tow word doc*/ 0044 void testParseTwoWord(); 0045 /** InvalidDoc*/ 0046 void testParseInvalid(); 0047 0048 private: 0049 QString oneGoodDoc; 0050 QString oneBadDoc; 0051 KEduVocDocument::FileType myType; 0052 }; 0053 0054 void VokabelnReaderTest::init() 0055 { 0056 oneGoodDoc = QStringLiteral("\"A Title of S0me Sort\n") + "en - de\n" + "Still more text\",3,456,789\n" + "0\n" + "Skipped Line\n" + "\"en\",\"de\"\n" 0057 + "skipped stuff\n" + "8. Lernhilfe\n" + "1\n" + "2\n" + "3\n" + "4\n" + "5\n" + "6\n" + "7\n" + "8\n" + "9\n" + "0\n" + "11\n" + "12\n" + "13\n" 0058 + "14\n" + "15\n" + "\"dog\",\"Hund\",1\n" + "skip 1\n" + "skip 2\n" + "\"cat\",\"Katze\",2\n" + "skip 1\n" + "skip 2\n" + "skip a\n" + "skip b\n" 0059 + "skip c\n" + "\"Lesson Title A\"\n" + "skip a\n" + "\"Lesson Title B\"\n" + "skip b\n" + "\"Extra Lesson Title\"\n"; 0060 0061 oneBadDoc = QStringLiteral("\"A Title of S0me Sort\n") + "en - de\n" + "Still more text\",3,456,789\n" + "0\n" + "Skipped Line\n"; 0062 0063 myType = KEduVocDocument::Vokabeln; 0064 } 0065 0066 void VokabelnReaderTest::testParseTwoWord() 0067 { 0068 KVOCREADER_EXPECT(oneGoodDoc, KEduVocDocument::NoError, myType); 0069 } 0070 0071 void VokabelnReaderTest::testParseInvalid() 0072 { 0073 KVOCREADER_EXPECT(oneBadDoc, KEduVocDocument::FileReaderFailed, myType); 0074 } 0075 0076 } 0077 0078 QTEST_MAIN(VokabelnReaderUnitTests::VokabelnReaderTest) 0079 0080 #include "readervokabelntest.moc"