diff options
Diffstat (limited to 'tests/unit/CardPack')
-rw-r--r-- | tests/unit/CardPack/CardPack_GenerateCards_test.cpp | 43 | ||||
-rw-r--r-- | tests/unit/CardPack/CardPack_GenerateCards_test.h | 26 | ||||
-rw-r--r-- | tests/unit/CardPack/CardPack_test.cpp | 80 | ||||
-rw-r--r-- | tests/unit/CardPack/CardPack_test.h | 31 | ||||
-rw-r--r-- | tests/unit/CardPack/cPack.pri | 7 |
5 files changed, 187 insertions, 0 deletions
diff --git a/tests/unit/CardPack/CardPack_GenerateCards_test.cpp b/tests/unit/CardPack/CardPack_GenerateCards_test.cpp new file mode 100644 index 0000000..c7e7fcb --- /dev/null +++ b/tests/unit/CardPack/CardPack_GenerateCards_test.cpp @@ -0,0 +1,43 @@ +#include "CardPack_GenerateCards_test.h" + +#include <initializer_list> + +#include "../../common/printQtTypes.h" +#include "../../../src/dictionary/IDictionary.h" +#include "../../../src/dictionary/Field.h" +#include "../../../src/dictionary/DicRecord.h" + +vector<Field*> GenerateCardsTest::fields; + +INSTANTIATE_TEST_CASE_P(, GenerateCardsTest, + testing::ValuesIn(RecordsParam::createParams()) ); + +vector<Field*> GenerateCardsTest::getFields() +{ + static vector<string> names {"English", "Russian"}; + if(fields.empty()) + for(string name: names) + fields.push_back(new Field(name.c_str(), "Normal")); + return fields; +} + +void GenerateCardsTest::TearDownTestCase() +{ + for(Field* field: fields) + delete field; +} + +TEST_P(GenerateCardsTest, generateQuestions) + { + auto param = GetParam(); + dict.addRecords(param.records); + for(int fieldId: param.packFields) + pack.addField(getFields()[ fieldId ]); + pack.generateQuestions(); + + QStringList questions; + for(string question: param.questions) + questions << question.c_str(); + + ASSERT_EQ(questions, pack.getCardQuestions()); +} diff --git a/tests/unit/CardPack/CardPack_GenerateCards_test.h b/tests/unit/CardPack/CardPack_GenerateCards_test.h new file mode 100644 index 0000000..299ee66 --- /dev/null +++ b/tests/unit/CardPack/CardPack_GenerateCards_test.h @@ -0,0 +1,26 @@ +#include <iostream> +#include <vector> +#include <string> +#include <gtest/gtest.h> +#include <QtCore> + +#include "CardPack_test.h" +#include "../../common/RecordsParam.h" + +class DicRecord; + +using std::vector; +using std::string; +using std::ostream; + +class GenerateCardsTest: public CardPackTest, + public testing::WithParamInterface<RecordsParam> +{ +public: + static void TearDownTestCase(); + static vector<Field*> getFields(); + +private: + static vector<Field*> fields; + +}; diff --git a/tests/unit/CardPack/CardPack_test.cpp b/tests/unit/CardPack/CardPack_test.cpp new file mode 100644 index 0000000..47b2387 --- /dev/null +++ b/tests/unit/CardPack/CardPack_test.cpp @@ -0,0 +1,80 @@ +#include "CardPack_test.h" +#include "../../common/printQtTypes.h" +#include "../../../src/dictionary/IDictionary.h" +#include "../../../src/dictionary/Field.h" +#include "../../../src/dictionary/DicRecord.h" + +ostream& operator<<(ostream& os, const Field* field) +{ + return os << field->name().toStdString(); +} + +CardPackTest::CardPackTest(): + pack(&dict), + qstField("Question", "Normal"), + ansField1("Answer1", "Normal"), + ansField2("Answer2", "Normal") +{} + +TEST_F(CardPackTest, empty_QuestionAnswers) + { + ASSERT_EQ(NULL, pack.getQuestionField()); + ASSERT_EQ(QList<const Field*>(), pack.getAnswerFields()); + } + +TEST_F(CardPackTest, empty_Id) + { + ASSERT_EQ("(empty pack)", pack.id()); + } + +TEST_F(CardPackTest, empty_cardQuestions) + { + ASSERT_EQ(QStringList(), pack.getCardQuestions()); + } + +TEST_F(CardPackTest, setQstField) + { + pack.setQstField(&qstField); + ASSERT_EQ(&qstField, pack.getQuestionField()); + } + +TEST_F(CardPackTest, setAnsField_1) + { + ansFields << &ansField1; + + pack.setAnsFields(ansFields); + ASSERT_EQ(ansFields, pack.getAnswerFields()); + } + +TEST_F(CardPackTest, setAnsFields_2) + { + ansFields << &ansField1 << &ansField2; + + pack.setAnsFields(ansFields); + ASSERT_EQ(ansFields, pack.getAnswerFields()); + } + +TEST_F(CardPackTest, addFields) + { + QList<const Field*> allFields; + allFields << &qstField << &ansField1 << &ansField2; + ansFields << &ansField1 << &ansField2; + + pack.addField(&qstField); + pack.addField(&ansField1); + pack.addField(&ansField2); + + ASSERT_EQ(allFields, pack.getFields()); + ASSERT_EQ(&qstField, pack.getQuestionField()); + ASSERT_EQ(ansFields, pack.getAnswerFields()); + } + +TEST_F(CardPackTest, id) + { + ansFields << &ansField1 << &ansField2; + + pack.setQstField(&qstField); + pack.setAnsFields(ansFields); + + ASSERT_EQ("Question - Answer1, Answer2", pack.id()); + } diff --git a/tests/unit/CardPack/CardPack_test.h b/tests/unit/CardPack/CardPack_test.h new file mode 100644 index 0000000..e25c75d --- /dev/null +++ b/tests/unit/CardPack/CardPack_test.h @@ -0,0 +1,31 @@ +#ifndef CARDPACK_TEST_H +#define CARDPACK_TEST_H + +#include <gtest/gtest.h> +#include <iostream> +#include <QtCore> + +#include "../../../src/dictionary/CardPack.h" +#include "../../mocks/Dictionary_mock.h" + +using std::ostream; + +class Field; + +class CardPackTest: public testing::Test +{ +public: + CardPackTest(); + +protected: + MockDictionary dict; + CardPack pack; + Field qstField; + Field ansField1; + Field ansField2; + QList<const Field*> ansFields; +}; + +ostream& operator<<(ostream& os, const Field* field); + +#endif diff --git a/tests/unit/CardPack/cPack.pri b/tests/unit/CardPack/cPack.pri new file mode 100644 index 0000000..e3befe3 --- /dev/null +++ b/tests/unit/CardPack/cPack.pri @@ -0,0 +1,7 @@ +HEADERS += \ + $$PWD/CardPack_test.h \ + $$PWD/CardPack_GenerateCards_test.h + +SOURCES += \ + $$PWD/CardPack_test.cpp \ + $$PWD/CardPack_GenerateCards_test.cpp |