File: readerwordquiztest.cpp

package info (click to toggle)
libkeduvocdocument 4%3A16.08.0-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 948 kB
  • ctags: 1,086
  • sloc: cpp: 7,995; sh: 16; makefile: 10
file content (158 lines) | stat: -rw-r--r-- 3,635 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 Copyright 2014 Andreas Xavier <andxav at zoho dot com>

 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) any later version.

 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, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 USA
*/

#include "keduvocdocument.h"
#include "readermanager.h"
#include "keduvocwqlreader.h"

#include "readerTestHelpers.h"

#include <qobject.h>
#include <qdebug.h>
#include <QtTest>

namespace WordQuizReaderTests {

/**
 * @file Unit Tests of parsing of WordQuiz WQL Files
 *
 * Each test creates a QString in WQL format
 * */

/**
 * @brief Unit Tests of parsing of WQL
 *
 * Each test creates a string
 * reads, parses and verifies the parse.
 *
 * Most of the WQL file is ignored in the parser
 * , so it is replaced in test with a=1 etc.
 * */

class WqlReaderTest : public QObject
{
    Q_OBJECT

private slots:
    /** Smallest passing File
     * */
    void testParseMinimalWQL();
    /** Missing Font Info*/
    void testParseMissingFontInfo();

private :

};

/**
 * @brief WQLGenerator builds the WQL doc
 * This is to minimize repetition in the unit tests.
 * */
class WQLGenerator
{
public:
    WQLGenerator();
    ~WQLGenerator();

    //String Data
    const QString headerText,  fontTag,  gridTag,  vocabTag;
    const QString lang0loc, lang1loc;
    const QString word0Left,  word0Right;

    //Generators of parts of the WQL Doc
    WQLGenerator & preamble();
    WQLGenerator & minimalFontInfo();
    WQLGenerator & minimalGridInfo();
    WQLGenerator & minimalVocab();

    /** Convert to the QIODevice that the reader expects*/
    QIODevice * toQIODevice();
    QByteArray m_barray;
    QBuffer * m_buffer;
    QString m_string;

    KEduVocDocument::FileType myType;

};

WQLGenerator::WQLGenerator()
    : headerText( "WordQuiz\n5\n")
    , fontTag( "[Font Info]" )
    , gridTag( "[Grid Info]" )
    , vocabTag( "[Vocabulary]" )
    , lang0loc( "en" )
    , lang1loc( "de" )
    , word0Left( "dog" )
    , word0Right( "Hund" )
    , m_buffer( 0 )
    , m_string( "" )
    , myType( KEduVocDocument::Wql )

{
}
WQLGenerator::~WQLGenerator()
{
    if ( m_buffer ) {
        delete m_buffer;
    }
}

WQLGenerator & WQLGenerator::preamble() {
    m_string = headerText;
    return *this;
}

WQLGenerator & WQLGenerator::minimalFontInfo() {
    m_string += fontTag + "\na=1\nb=1\nc=1\nd=1\n";
    return *this;
}

WQLGenerator & WQLGenerator::minimalGridInfo() {
    m_string += gridTag + "\na=1\nb=1\nc=1\n";
    return *this;
}

WQLGenerator & WQLGenerator::minimalVocab() {
    m_string += vocabTag + "\n" + word0Left + "[\n" + word0Right +"\n";
    return *this;
}


void WqlReaderTest::testParseMinimalWQL()
{
    WQLGenerator gen;
    gen.preamble().minimalFontInfo().minimalGridInfo().minimalVocab();

    KVOCREADER_EXPECT( gen.m_string , KEduVocDocument::NoError , gen.myType );
}

void WqlReaderTest::testParseMissingFontInfo()
{
    WQLGenerator gen;
    gen.preamble();

    KVOCREADER_EXPECT( gen.m_string , KEduVocDocument::FileReaderFailed , gen.myType );
}


}

QTEST_MAIN( WordQuizReaderTests::WqlReaderTest )

#include "readerwordquiztest.moc"