File indexing completed on 2024-03-24 03:51:02
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 "keduvocpaukerreader.h" 0008 #include "readermanager.h" 0009 0010 #include "readerTestHelpers.h" 0011 0012 #include <QDebug> 0013 #include <QTest> 0014 0015 namespace PaukerReaderUnitTests 0016 { 0017 0018 /** 0019 * @file readerpaukertest.cpp 0020 * Unit Tests of parsing of Pauker strings 0021 * 0022 * Each test creates a QString of Pauker format 0023 * reads, parses and verifies the parse. The portions of the 0024 * XML generator object relevant to each test are defined in this file. 0025 * 0026 *This is the supported format 0027 * @verbatim 0028 <?xml version="1.0" encoding="UTF-8"?> 0029 <!--This is a lesson file for Pauker (http://pauker.sourceforge.net)--> 0030 <Lesson LessonFormat="1.7"> 0031 <Description>Some Description</Description> 0032 <Batch> 0033 <Card> 0034 <FrontSide> 0035 <Text>Front text</Text> 0036 </FrontSide> 0037 <ReverseSide> 0038 <Text>Back Text</Text> 0039 </ReverseSide> 0040 </Card> 0041 ... more cards 0042 </Batch> 0043 </Lesson> 0044 * @endverbatim 0045 * */ 0046 0047 /** 0048 * @brief Unit Tests of parsing of KVTML 2.0 strings 0049 * 0050 * Each test creates a string of XML 0051 * reads, parses and verifies the parse. 0052 * */ 0053 0054 class PaukerReaderTest : public QObject 0055 { 0056 Q_OBJECT 0057 0058 private slots: 0059 /** Initialize the string*/ 0060 void init(); 0061 /** One word doc*/ 0062 void testParseOneWord(); 0063 /** InvalidDoc*/ 0064 void testParseInvalid(); 0065 0066 private: 0067 QString oneGoodDoc; 0068 QString oneBadDoc; 0069 KEduVocDocument::FileType myType; 0070 }; 0071 0072 void PaukerReaderTest::init() 0073 { 0074 oneGoodDoc = QStringLiteral( 0075 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n \ 0076 <!--This is a lesson file for Pauker (http://pauker.sourceforge.net)-->\n \ 0077 <Lesson LessonFormat=\"1.7\">\n \ 0078 <Description>Some Description</Description>\n \ 0079 <Batch>\n \ 0080 <Card>\n \ 0081 <FrontSide>\n \ 0082 <Text>Front text</Text>\n \ 0083 </FrontSide>\n \ 0084 <ReverseSide>\n \ 0085 <Text>Back Text</Text>\n \ 0086 </ReverseSide>\n \ 0087 </Card>\n \ 0088 </Batch>\n \ 0089 </Lesson>\n"); 0090 oneBadDoc = oneGoodDoc + "\ninvalid XML characters "; 0091 0092 myType = KEduVocDocument::Pauker; 0093 } 0094 0095 void PaukerReaderTest::testParseOneWord() 0096 { 0097 KVOCREADER_EXPECT(oneGoodDoc, KEduVocDocument::NoError, myType); 0098 } 0099 0100 void PaukerReaderTest::testParseInvalid() 0101 { 0102 KVOCREADER_EXPECT(oneBadDoc, KEduVocDocument::FileReaderFailed, myType); 0103 } 0104 0105 } 0106 0107 QTEST_MAIN(PaukerReaderUnitTests::PaukerReaderTest) 0108 0109 #include "readerpaukertest.moc"