File indexing completed on 2022-09-27 12:38:59

0001 /*
0002     SPDX-FileCopyrightText: 2019 Hartmut Riesenbeck <hartmut.riesenbeck@gmx.de>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 #include "testentrytest.h"
0006 
0007 #include "prefs.h"
0008 #include "testentry.h"
0009 #include <QTest>
0010 
0011 namespace TestEntryTests
0012 {
0013 void TestEntryTest::initTestCase()
0014 {
0015     /*
0016      * A TestEntry object is created with following grade levels set:
0017      *   translation index 0
0018      *     base - grade 1
0019      *     article - grade 2
0020      *     conjugations - grades 3, 4 and 5
0021      *     comparatives - grades 6 and 7
0022      *   translation index 1
0023      *     base - grade 0
0024      *     article - grade 0
0025      *     conjugations - grades 0, 0 and 0
0026      *     comparatives - grades 0, 0 and 0
0027      */
0028     m_gradeExpression = makeKEduVocExpressionGrade();
0029     m_gradeTestEntry = makeTestEntry(m_gradeExpression);
0030 
0031     /*
0032      * A TestEntry object is created with following pregrade levels set:
0033      *   translation index 0
0034      *     base - pregrad 1
0035      *     article - pregrad 2
0036      *     conjugations - pregrads 3, 4 and 5
0037      *     comparatives - pregrads 6 and 7
0038      *   translation index 1
0039      *     base - pregrad 0
0040      *     article - pregrad 0
0041      *     conjugations - pregrads 0, 0 and 0
0042      *     comparatives - pregrads 0, 0 and 0
0043      */
0044     m_preGradeExpression = makeKEduVocExpressionPreGrade();
0045     m_preGradeTestEntry = makeTestEntry(m_preGradeExpression);
0046 
0047     // Prevent writing by tast case modified pareleys config file to current users configuration
0048     QStandardPaths::setTestModeEnabled(true);
0049 }
0050 
0051 KEduVocExpression *TestEntryTest::makeKEduVocExpressionGrade()
0052 {
0053     KEduVocExpression *expression = new KEduVocExpression;
0054     expression->setTranslation(0, QStringLiteral("translation 0"));
0055     KEduVocTranslation *translation0 = expression->translation(0);
0056 
0057     translation0->setGrade(KV_LEV1_GRADE);
0058 
0059     KEduVocText text;
0060     text.setGrade(KV_LEV2_GRADE);
0061     translation0->setArticle(text);
0062 
0063     KEduVocConjugation conjugation0;
0064     text.setText(QStringLiteral("conjugation 00"));
0065     text.setGrade(KV_LEV3_GRADE);
0066     conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First);
0067     text.setText(QStringLiteral("conjugation 01"));
0068     text.setGrade(KV_LEV4_GRADE);
0069     conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second);
0070     text.setText(QStringLiteral("conjugation 03"));
0071     text.setGrade(KV_LEV5_GRADE);
0072     conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter);
0073     translation0->setConjugation(QStringLiteral("tense"), conjugation0);
0074 
0075     text.setText(QStringLiteral("comparative 0"));
0076     text.setGrade(KV_LEV6_GRADE);
0077     translation0->setComparativeForm(text);
0078 
0079     text.setText(QStringLiteral("superlative 0"));
0080     text.setGrade(KV_LEV7_GRADE);
0081     translation0->setSuperlativeForm(text);
0082 
0083     expression->setTranslation(1, QStringLiteral("translation 1"));
0084     KEduVocTranslation *translation1 = expression->translation(1);
0085 
0086     translation1->setArticle(KEduVocText());
0087 
0088     KEduVocConjugation conjugation1;
0089     conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), KEduVocWordFlag::Singular | KEduVocWordFlag::First);
0090     conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), KEduVocWordFlag::Singular | KEduVocWordFlag::Second);
0091     conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter);
0092     translation1->setConjugation(QStringLiteral("tense"), conjugation1);
0093 
0094     translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1")));
0095     translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1")));
0096 
0097     return expression;
0098 }
0099 
0100 KEduVocExpression *TestEntryTest::makeKEduVocExpressionPreGrade()
0101 {
0102     KEduVocExpression *expression = new KEduVocExpression;
0103     expression->setTranslation(0, QStringLiteral("translation 0"));
0104     KEduVocTranslation *translation0 = expression->translation(0);
0105 
0106     translation0->setPreGrade(KV_LEV1_GRADE);
0107 
0108     KEduVocText text;
0109     text.setPreGrade(KV_LEV2_GRADE);
0110     translation0->setArticle(text);
0111 
0112     KEduVocConjugation conjugation0;
0113     text.setText(QStringLiteral("conjugation 00"));
0114     text.setPreGrade(KV_LEV3_GRADE);
0115     conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::First);
0116     text.setText(QStringLiteral("conjugation 01"));
0117     text.setPreGrade(KV_LEV4_GRADE);
0118     conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Second);
0119     text.setText(QStringLiteral("conjugation 03"));
0120     text.setPreGrade(KV_LEV5_GRADE);
0121     conjugation0.setConjugation(text, KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter);
0122     translation0->setConjugation(QStringLiteral("tense"), conjugation0);
0123 
0124     text.setText(QStringLiteral("comparative 0"));
0125     text.setPreGrade(KV_LEV6_GRADE);
0126     translation0->setComparativeForm(text);
0127 
0128     text.setText(QStringLiteral("superlative 0"));
0129     text.setPreGrade(KV_LEV7_GRADE);
0130     translation0->setSuperlativeForm(text);
0131 
0132     expression->setTranslation(1, QStringLiteral("translation 1"));
0133     KEduVocTranslation *translation1 = expression->translation(1);
0134 
0135     translation1->setArticle(KEduVocText());
0136 
0137     KEduVocConjugation conjugation1;
0138     conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 10")), KEduVocWordFlag::Singular | KEduVocWordFlag::First);
0139     conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 11")), KEduVocWordFlag::Singular | KEduVocWordFlag::Second);
0140     conjugation1.setConjugation(KEduVocText(QStringLiteral("conjugation 13")), KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter);
0141 
0142     translation1->setConjugation(QStringLiteral("tense"), conjugation1);
0143     translation1->setComparativeForm(KEduVocText(QStringLiteral("comparative 1")));
0144     translation1->setSuperlativeForm(KEduVocText(QStringLiteral("superlative 1")));
0145 
0146     return expression;
0147 }
0148 
0149 TestEntry *TestEntryTest::makeTestEntry(KEduVocExpression *expression)
0150 {
0151     TestEntry *testEntry = new TestEntry(expression);
0152     testEntry->setLanguageTo(0);
0153     testEntry->setLanguageFrom(1);
0154     testEntry->setConjugationTense(QStringLiteral("tense"));
0155     testEntry->setConjugationPronouns({KEduVocWordFlag::Singular | KEduVocWordFlag::First,
0156                                        KEduVocWordFlag::Singular | KEduVocWordFlag::Second,
0157                                        KEduVocWordFlag::Singular | KEduVocWordFlag::Third | KEduVocWordFlag::Neuter});
0158 
0159     return testEntry;
0160 }
0161 
0162 void TestEntryTest::cleanupTestCase()
0163 {
0164     delete m_gradeTestEntry;
0165     delete m_gradeExpression;
0166     delete m_preGradeTestEntry;
0167     delete m_preGradeExpression;
0168 
0169     // Remove temporary parley config file
0170     if (QStandardPaths::isTestModeEnabled()) {
0171         QFileInfo prefsFile(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation), Prefs::self()->config()->name());
0172         if (prefsFile.exists()) {
0173             QFile::remove(prefsFile.filePath());
0174         }
0175     }
0176 }
0177 
0178 void TestEntryTest::test_practiceModeDependentMinGrade_written()
0179 {
0180     Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice);
0181     QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), static_cast<grade_t>(KV_LEV1_GRADE));
0182 }
0183 
0184 void TestEntryTest::test_practiceModeDependentMinGrade_gender()
0185 {
0186     Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice);
0187     QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), static_cast<grade_t>(KV_LEV2_GRADE));
0188 }
0189 
0190 void TestEntryTest::test_practiceModeDependentMinGrade_conjugation()
0191 {
0192     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice);
0193     QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), static_cast<grade_t>(KV_LEV3_GRADE));
0194 }
0195 
0196 void TestEntryTest::test_practiceModeDependentMinGrade_comparsion()
0197 {
0198     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice);
0199     QCOMPARE(m_gradeTestEntry->practiceModeDependentMinGrade(), static_cast<grade_t>(KV_LEV6_GRADE));
0200 }
0201 
0202 void TestEntryTest::test_practiceModeDependentMaxGrade_written()
0203 {
0204     Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice);
0205     QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), static_cast<grade_t>(KV_LEV1_GRADE));
0206 }
0207 
0208 void TestEntryTest::test_practiceModeDependentMaxGrade_gender()
0209 {
0210     Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice);
0211     QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), static_cast<grade_t>(KV_LEV2_GRADE));
0212 }
0213 
0214 void TestEntryTest::test_practiceModeDependentMaxGrade_conjugation()
0215 {
0216     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice);
0217     QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), static_cast<grade_t>(KV_LEV5_GRADE));
0218 }
0219 
0220 void TestEntryTest::test_practiceModeDependentMaxGrade_comparsion()
0221 {
0222     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice);
0223     QCOMPARE(m_gradeTestEntry->practiceModeDependentMaxGrade(), static_cast<grade_t>(KV_LEV7_GRADE));
0224 }
0225 
0226 void TestEntryTest::test_practiceModeDependentMinPreGrade_written()
0227 {
0228     Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice);
0229     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), static_cast<grade_t>(KV_LEV1_GRADE));
0230 }
0231 
0232 void TestEntryTest::test_practiceModeDependentMinPreGrade_gender()
0233 {
0234     Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice);
0235     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), static_cast<grade_t>(KV_LEV2_GRADE));
0236 }
0237 
0238 void TestEntryTest::test_practiceModeDependentMinPreGrade_conjugation()
0239 {
0240     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice);
0241     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), static_cast<grade_t>(KV_LEV3_GRADE));
0242 }
0243 
0244 void TestEntryTest::test_practiceModeDependentMinPreGrade_comparsion()
0245 {
0246     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice);
0247     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMinPreGrade(), static_cast<grade_t>(KV_LEV6_GRADE));
0248 }
0249 
0250 void TestEntryTest::test_practiceModeDependentMaxPreGrade_written()
0251 {
0252     Prefs::setPracticeMode(Prefs::EnumPracticeMode::WrittenPractice);
0253     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), static_cast<grade_t>(KV_LEV1_GRADE));
0254 }
0255 
0256 void TestEntryTest::test_practiceModeDependentMaxPreGrade_gender()
0257 {
0258     Prefs::setPracticeMode(Prefs::EnumPracticeMode::GenderPractice);
0259     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), static_cast<grade_t>(KV_LEV2_GRADE));
0260 }
0261 
0262 void TestEntryTest::test_practiceModeDependentMaxPreGrade_conjugation()
0263 {
0264     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ConjugationPractice);
0265     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), static_cast<grade_t>(KV_LEV5_GRADE));
0266 }
0267 
0268 void TestEntryTest::test_practiceModeDependentMaxPreGrade_comparsion()
0269 {
0270     Prefs::setPracticeMode(Prefs::EnumPracticeMode::ComparisonPractice);
0271     QCOMPARE(m_preGradeTestEntry->practiceModeDependentMaxPreGrade(), static_cast<grade_t>(KV_LEV7_GRADE));
0272 }
0273 
0274 }
0275 
0276 QTEST_GUILESS_MAIN(TestEntryTests::TestEntryTest)