Changeset View
Changeset View
Standalone View
Standalone View
autotests/testentrytest.cpp
- This file was added.
1 | /*************************************************************************** | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2019 by Hartmut Riesenbeck <hartmut.riesenbeck@gmx.de> * | ||||
3 | * * | ||||
4 | * This program is free software; you can redistribute it and/or modify * | ||||
5 | * it under the terms of the GNU General Public License as published by * | ||||
6 | * the Free Software Foundation; either version 2 of the License, or * | ||||
7 | * (at your option) any later version. * | ||||
8 | * * | ||||
9 | * This program is distributed in the hope that it will be useful, * | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||||
12 | * GNU General Public License for more details. * | ||||
13 | * * | ||||
14 | * You should have received a copy of the GNU General Public License * | ||||
15 | * along with this program; if not, write to the * | ||||
16 | * Free Software Foundation, Inc., * | ||||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * | ||||
18 | ***************************************************************************/ | ||||
19 | | ||||
20 | #include "testentrytest.h" | ||||
21 | | ||||
22 | #include "testentry.h" | ||||
23 | #include "prefs.h" | ||||
24 | #include <QTest> | ||||
25 | | ||||
26 | namespace TestEntryTests{ | ||||
27 | | ||||
28 | void TestEntryTest::initTestCase() | ||||
29 | { | ||||
30 | /* | ||||
31 | * A TestEntry object is created with following grade levels set: | ||||
32 | * translation index 0 | ||||
33 | * base - grade 1 | ||||
34 | * article - grade 2 | ||||
35 | * conjugations - grades 3, 4 and 5 | ||||
36 | * comparatives - grades 6 and 7 | ||||
37 | * translation index 1 | ||||
38 | * base - grade 0 | ||||
39 | * article - grade 0 | ||||
40 | * conjugations - grades 0, 0 and 0 | ||||
41 | * comparatives - grades 0, 0 and 0 | ||||
42 | */ | ||||
43 | m_gradeExpression = makeKEduVocExpressionGrade(); | ||||
44 | m_gradeTestEntry = makeTestEntry(m_gradeExpression); | ||||
45 | | ||||
46 | /* | ||||
47 | * A TestEntry object is created with following pregrade levels set: | ||||
48 | * translation index 0 | ||||
49 | * base - pregrad 1 | ||||
50 | * article - pregrad 2 | ||||
51 | * conjugations - pregrads 3, 4 and 5 | ||||
52 | * comparatives - pregrads 6 and 7 | ||||
53 | * translation index 1 | ||||
54 | * base - pregrad 0 | ||||
55 | * article - pregrad 0 | ||||
56 | * conjugations - pregrads 0, 0 and 0 | ||||
57 | * comparatives - pregrads 0, 0 and 0 | ||||
58 | */ | ||||
59 | m_preGradeExpression = makeKEduVocExpressionPreGrade(); | ||||
60 | m_preGradeTestEntry = makeTestEntry(m_preGradeExpression); | ||||
61 | | ||||
62 | // Prevent writing by tast case modified pareleys config file to current users configuration | ||||
63 | QStandardPaths::setTestModeEnabled(true); | ||||
64 | } | ||||
65 | | ||||
66 | | ||||
67 | KEduVocExpression *TestEntryTest::makeKEduVocExpressionGrade() | ||||
68 | { | ||||
69 | KEduVocExpression *expression = new KEduVocExpression; | ||||
70 | expression->setTranslation(0, QStringLiteral("translation 0")); | ||||
71 | KEduVocTranslation *translation0 = expression->translation(0); | ||||
72 | | ||||
73 | translation0->setGrade(KV_LEV1_GRADE); | ||||
74 | | ||||
75 | KEduVocText text; | ||||
76 | text.setGrade(KV_LEV2_GRADE); | ||||
77 | translation0->setArticle(text); | ||||
78 | | ||||
79 | KEduVocConjugation conjugation0; | ||||
80 | text.setText(QStringLiteral("conjugation 00")); | ||||
81 | text.setGrade(KV_LEV3_GRADE); | ||||
82 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
83 | text.setText(QStringLiteral("conjugation 01")); | ||||
84 | text.setGrade(KV_LEV4_GRADE); | ||||
85 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
86 | text.setText(QStringLiteral("conjugation 03")); | ||||
87 | text.setGrade(KV_LEV5_GRADE); | ||||
88 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | ||||
89 | | KEduVocWordFlag::Third | ||||
90 | | KEduVocWordFlag::Neuter); | ||||
91 | translation0->setConjugation(QStringLiteral("tense"), conjugation0); | ||||
92 | | ||||
93 | text.setText(QStringLiteral("comparative 0")); | ||||
94 | text.setGrade(KV_LEV6_GRADE); | ||||
95 | translation0->setComparativeForm(text); | ||||
96 | | ||||
97 | text.setText(QStringLiteral("superlative 0")); | ||||
98 | text.setGrade(KV_LEV7_GRADE); | ||||
99 | translation0->setSuperlativeForm(text); | ||||
100 | | ||||
101 | | ||||
102 | expression->setTranslation(1, QStringLiteral("translation 1")); | ||||
103 | KEduVocTranslation *translation1 = expression->translation(1); | ||||
104 | | ||||
105 | translation1->setArticle(KEduVocText()); | ||||
106 | | ||||
107 | KEduVocConjugation conjugation1; | ||||
108 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), | ||||
109 | KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
110 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), | ||||
111 | KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
112 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), | ||||
113 | KEduVocWordFlag::Singular | KEduVocWordFlag::Third | ||||
114 | | KEduVocWordFlag::Neuter); | ||||
115 | translation1->setConjugation(QStringLiteral("tense"), conjugation1); | ||||
116 | | ||||
117 | translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1"))); | ||||
118 | translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1"))); | ||||
119 | | ||||
120 | return expression; | ||||
121 | } | ||||
122 | | ||||
123 | | ||||
124 | KEduVocExpression *TestEntryTest::makeKEduVocExpressionPreGrade() | ||||
125 | { | ||||
126 | KEduVocExpression *expression = new KEduVocExpression; | ||||
127 | expression->setTranslation(0, QStringLiteral("translation 0")); | ||||
128 | KEduVocTranslation *translation0 = expression->translation(0); | ||||
129 | | ||||
130 | translation0->setPreGrade(KV_LEV1_GRADE); | ||||
131 | | ||||
132 | KEduVocText text; | ||||
133 | text.setPreGrade(KV_LEV2_GRADE); | ||||
134 | translation0->setArticle(text); | ||||
135 | | ||||
136 | KEduVocConjugation conjugation0; | ||||
137 | text.setText(QStringLiteral("conjugation 00")); | ||||
138 | text.setPreGrade(KV_LEV3_GRADE); | ||||
139 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
140 | text.setText(QStringLiteral("conjugation 01")); | ||||
141 | text.setPreGrade(KV_LEV4_GRADE); | ||||
142 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
143 | text.setText(QStringLiteral("conjugation 03")); | ||||
144 | text.setPreGrade(KV_LEV5_GRADE); | ||||
145 | conjugation0.setConjugation(text, KEduVocWordFlag::Singular | ||||
146 | | KEduVocWordFlag::Third | ||||
147 | | KEduVocWordFlag::Neuter); | ||||
148 | translation0->setConjugation(QStringLiteral("tense"), conjugation0); | ||||
149 | | ||||
150 | text.setText(QStringLiteral("comparative 0")); | ||||
151 | text.setPreGrade(KV_LEV6_GRADE); | ||||
152 | translation0->setComparativeForm(text); | ||||
153 | | ||||
154 | text.setText(QStringLiteral("superlative 0")); | ||||
155 | text.setPreGrade(KV_LEV7_GRADE); | ||||
156 | translation0->setSuperlativeForm(text); | ||||
157 | | ||||
158 | | ||||
159 | expression->setTranslation(1, QStringLiteral("translation 1")); | ||||
160 | KEduVocTranslation *translation1 = expression->translation(1); | ||||
161 | | ||||
162 | translation1->setArticle(KEduVocText()); | ||||
163 | | ||||
164 | KEduVocConjugation conjugation1; | ||||
165 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), | ||||
166 | KEduVocWordFlag::Singular | KEduVocWordFlag::First); | ||||
167 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), | ||||
168 | KEduVocWordFlag::Singular | KEduVocWordFlag::Second); | ||||
169 | conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), | ||||
170 | KEduVocWordFlag::Singular | KEduVocWordFlag::Third | ||||
171 | | KEduVocWordFlag::Neuter); | ||||
172 | | ||||
173 | translation1->setConjugation(QStringLiteral("tense"), conjugation1); | ||||
174 | translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1"))); | ||||
175 | translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1"))); | ||||
176 | | ||||
177 | return expression; | ||||
178 | } | ||||
179 | | ||||
180 | | ||||
181 | TestEntry *TestEntryTest::makeTestEntry(KEduVocExpression *expression) | ||||
182 | { | ||||
183 | TestEntry *testEntry = new TestEntry(expression); | ||||
184 | testEntry->setLanguageTo(0); | ||||
185 | testEntry->setLanguageFrom(1); | ||||
186 | testEntry->setConjugationTense(QStringLiteral("tense")); | ||||
187 | testEntry->setConjugationPronouns({ | ||||
188 | KEduVocWordFlag::Singular | KEduVocWordFlag::First, | ||||
189 | KEduVocWordFlag::Singular | KEduVocWordFlag::Second, | ||||
190 | KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter | ||||
191 | }); | ||||
192 | | ||||
193 | return testEntry; | ||||
194 | } | ||||
195 | | ||||
196 | | ||||
197 | void TestEntryTest::cleanupTestCase() | ||||
198 | { | ||||
199 | delete m_gradeTestEntry; | ||||
200 | delete m_gradeExpression; | ||||
201 | delete m_preGradeTestEntry; | ||||
202 | delete m_preGradeExpression; | ||||
203 | | ||||
204 | // Remove temporary parley config file | ||||
205 | if (QStandardPaths::isTestModeEnabled()) { | ||||
206 | QFileInfo prefsFile(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation), | ||||
207 | Prefs::self()->config()->name()); | ||||
208 | if (prefsFile.exists()) { | ||||
209 | QFile::remove(prefsFile.filePath()); | ||||
210 | } | ||||
211 | } | ||||
212 | } | ||||
213 | | ||||
214 | | ||||
215 | void TestEntryTest::test_practiceModeDependentMinGrade_written() | ||||
216 | { | ||||
217 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
218 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
219 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
220 | } | ||||
221 | | ||||
222 | | ||||
223 | void TestEntryTest::test_practiceModeDependentMinGrade_gender() | ||||
224 | { | ||||
225 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
226 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
227 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
228 | } | ||||
229 | | ||||
230 | | ||||
231 | void TestEntryTest::test_practiceModeDependentMinGrade_conjugation() | ||||
232 | { | ||||
233 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
234 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
235 | static_cast<grade_t>(KV_LEV3_GRADE)); | ||||
236 | } | ||||
237 | | ||||
238 | | ||||
239 | void TestEntryTest::test_practiceModeDependentMinGrade_comparsion() | ||||
240 | { | ||||
241 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
242 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), | ||||
243 | static_cast<grade_t>(KV_LEV6_GRADE)); | ||||
244 | } | ||||
245 | | ||||
246 | | ||||
247 | void TestEntryTest::test_practiceModeDependentMaxGrade_written() | ||||
248 | { | ||||
249 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
250 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
251 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
252 | } | ||||
253 | | ||||
254 | | ||||
255 | void TestEntryTest::test_practiceModeDependentMaxGrade_gender() | ||||
256 | { | ||||
257 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
258 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
259 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
260 | } | ||||
261 | | ||||
262 | | ||||
263 | void TestEntryTest::test_practiceModeDependentMaxGrade_conjugation() | ||||
264 | { | ||||
265 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
266 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
267 | static_cast<grade_t>(KV_LEV5_GRADE)); | ||||
268 | } | ||||
269 | | ||||
270 | | ||||
271 | void TestEntryTest::test_practiceModeDependentMaxGrade_comparsion() | ||||
272 | { | ||||
273 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
274 | QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), | ||||
275 | static_cast<grade_t>(KV_LEV7_GRADE)); | ||||
276 | } | ||||
277 | | ||||
278 | | ||||
279 | void TestEntryTest::test_practiceModeDependentMinPreGrade_written() | ||||
280 | { | ||||
281 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
282 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
283 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
284 | } | ||||
285 | | ||||
286 | | ||||
287 | void TestEntryTest::test_practiceModeDependentMinPreGrade_gender() | ||||
288 | { | ||||
289 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
290 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
291 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
292 | } | ||||
293 | | ||||
294 | | ||||
295 | void TestEntryTest::test_practiceModeDependentMinPreGrade_conjugation() | ||||
296 | { | ||||
297 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
298 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
299 | static_cast<grade_t>(KV_LEV3_GRADE)); | ||||
300 | } | ||||
301 | | ||||
302 | | ||||
303 | void TestEntryTest::test_practiceModeDependentMinPreGrade_comparsion() | ||||
304 | { | ||||
305 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
306 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), | ||||
307 | static_cast<grade_t>(KV_LEV6_GRADE)); | ||||
308 | } | ||||
309 | | ||||
310 | | ||||
311 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_written() | ||||
312 | { | ||||
313 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice); | ||||
314 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
315 | static_cast<grade_t>(KV_LEV1_GRADE)); | ||||
316 | } | ||||
317 | | ||||
318 | | ||||
319 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_gender() | ||||
320 | { | ||||
321 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice); | ||||
322 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
323 | static_cast<grade_t>(KV_LEV2_GRADE)); | ||||
324 | } | ||||
325 | | ||||
326 | | ||||
327 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_conjugation() | ||||
328 | { | ||||
329 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice); | ||||
330 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
331 | static_cast<grade_t>(KV_LEV5_GRADE)); | ||||
332 | } | ||||
333 | | ||||
334 | | ||||
335 | void TestEntryTest::test_practiceModeDependentMaxPreGrade_comparsion() | ||||
336 | { | ||||
337 | Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice); | ||||
338 | QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), | ||||
339 | static_cast<grade_t>(KV_LEV7_GRADE)); | ||||
340 | } | ||||
341 | | ||||
342 | } | ||||
343 | | ||||
344 | QTEST_MAIN(TestEntryTests::TestEntryTest) |