diff options
Diffstat (limited to 'tests/unit/Card')
-rw-r--r-- | tests/unit/Card/Card_GenerateAnswers_test.cpp | 66 | ||||
-rw-r--r-- | tests/unit/Card/Card_GenerateAnswers_test.h | 34 | ||||
-rw-r--r-- | tests/unit/Card/Card_test.cpp | 36 | ||||
-rw-r--r-- | tests/unit/Card/Card_test.h | 18 | ||||
-rw-r--r-- | tests/unit/Card/Card_test_QuestionAnswer.cpp | 30 | ||||
-rw-r--r-- | tests/unit/Card/card.pri | 10 |
6 files changed, 194 insertions, 0 deletions
diff --git a/tests/unit/Card/Card_GenerateAnswers_test.cpp b/tests/unit/Card/Card_GenerateAnswers_test.cpp new file mode 100644 index 0000000..f381daf --- /dev/null +++ b/tests/unit/Card/Card_GenerateAnswers_test.cpp @@ -0,0 +1,66 @@ +#include "Card_GenerateAnswers_test.h" + +#include <initializer_list> + +#include "../../common/printQtTypes.h" +#include "../../../src/dictionary/IDictionary.h" +#include "../../../src/dictionary/Field.h" +#include "../../../src/dictionary/DicRecord.h" +#include "../../../src/dictionary/Card.h" + +INSTANTIATE_TEST_CASE_P(, GenerateAnswersTest, + testing::ValuesIn(RecordsParam::createParams()) ); + +void GenerateAnswersTest::TearDown() +{ + for(Field* field: fields) + delete field; +} + +TEST_P(GenerateAnswersTest, generateAnswers) + { + auto param = GetParam(); + dict.addRecords(param.records); + for(int i: param.packFields) + addFieldToPack(i); + + unsigned i = 0; + for(vector<string> expectedCardFields: param.answers) + { + SCOPED_TRACE(i); + Card card(&pack, expectedCardFields[0].c_str()); + for(unsigned j = 1; j < expectedCardFields.size(); j++) + { + SCOPED_TRACE(j); + ASSERT_EQ_QSTR(QString(expectedCardFields[j].c_str()), + card.getAnswers()[j - 1]); + } + i++; + } +} + +TEST_F(GenerateAnswersTest, dropAnswers) + { + const vector<string> fieldValues {"table", "стол"}; + + DicRecord* record = new DicRecord; + dict.addRecord(record); + for(unsigned i = 0; i < fieldValues.size(); i++) + { + addFieldToPack(i); + record->setField(RecordsParam::fieldNames[i].c_str(), fieldValues[i].c_str()); + } + Card card(&pack, fieldValues[0].c_str()); + + ASSERT_EQ(QString(fieldValues[1].c_str()), card.getAnswers().first()); + + record->setField("Russian", "кровать"); + ASSERT_EQ(QString("кровать"), card.getAnswers().first()); +} + +void GenerateAnswersTest::addFieldToPack(unsigned fieldId) +{ + Field* field = new Field(RecordsParam::fieldNames[fieldId].c_str(), "Normal"); + fields.push_back(field); + pack.addField(field); +} diff --git a/tests/unit/Card/Card_GenerateAnswers_test.h b/tests/unit/Card/Card_GenerateAnswers_test.h new file mode 100644 index 0000000..1b69cba --- /dev/null +++ b/tests/unit/Card/Card_GenerateAnswers_test.h @@ -0,0 +1,34 @@ +#include <vector> +#include <string> +#include <gtest/gtest.h> + +#include "../../../src/dictionary/CardPack.h" +#include "../../mocks/Dictionary_mock.h" +#include "../../common/RecordsParam.h" + +class Field; + +using std::vector; +using std::string; + +class GenerateAnswersTest: public testing::TestWithParam<RecordsParam> +{ +public: + GenerateAnswersTest(): + pack(&dict) {} + +protected: + void TearDown(); + void addFieldToPack(unsigned fieldId); + +public: + static const vector<string> fieldNames; + +protected: + vector<Field*> fields; + +protected: + MockDictionary dict; + CardPack pack; +}; + diff --git a/tests/unit/Card/Card_test.cpp b/tests/unit/Card/Card_test.cpp new file mode 100644 index 0000000..bfae243 --- /dev/null +++ b/tests/unit/Card/Card_test.cpp @@ -0,0 +1,36 @@ +#include <gtest/gtest.h> +#include <QtCore> + +#include "Card_test.h" +#include "../../common/printQtTypes.h" +#include "../../../src/dictionary/Card.h" +#include "../../../src/dictionary/ICardPack.h" +#include "../../mocks/CardPack_mock.h" + +void CardTest::SetUp() + { + defaultPack = new CardPackMock; + } + +void CardTest::TearDown() + { + delete defaultPack; + } + +TEST_F(CardTest, Create) + { + Card card(defaultPack); + + ASSERT_EQ(defaultPack, card.getCardPack()); + ASSERT_TRUE(card.getQuestion().isEmpty()); + ASSERT_TRUE(card.getAnswers().isEmpty()); + } + +TEST_F(CardTest, Create_NullPack) + { + Card card(NULL); + + ASSERT_EQ(NULL, card.getCardPack()); + ASSERT_TRUE(card.getQuestion().isEmpty()); + ASSERT_TRUE(card.getAnswers().isEmpty()); + } diff --git a/tests/unit/Card/Card_test.h b/tests/unit/Card/Card_test.h new file mode 100644 index 0000000..e9a0891 --- /dev/null +++ b/tests/unit/Card/Card_test.h @@ -0,0 +1,18 @@ +#ifndef CARD_TEST_H +#define CARD_TEST_H + +#include <gtest/gtest.h> + +class ICardPack; + +class CardTest: public testing::Test +{ +public: + void SetUp(); + void TearDown(); + +protected: + ICardPack* defaultPack; +}; + +#endif diff --git a/tests/unit/Card/Card_test_QuestionAnswer.cpp b/tests/unit/Card/Card_test_QuestionAnswer.cpp new file mode 100644 index 0000000..6100f75 --- /dev/null +++ b/tests/unit/Card/Card_test_QuestionAnswer.cpp @@ -0,0 +1,30 @@ +#include <gtest/gtest.h> + +#include "Card_test.h" +#include "../../../src/dictionary/Card.h" +#include "../../mocks/CardPack_mock.h" + +using testing::Combine; +using testing::Values; +using testing::WithParamInterface; + +class QuestionCardTest: public CardTest, + public WithParamInterface<const char*> +{}; + +INSTANTIATE_TEST_CASE_P(, QuestionCardTest, + Values("", "Question")); + +TEST_P(QuestionCardTest, getName) + { + QString question = GetParam(); + Card card(defaultPack, question); + ASSERT_EQ(question, card.getName()); + } + +TEST_P(QuestionCardTest, getQuestion) + { + QString question = GetParam(); + Card card(defaultPack, question); + ASSERT_EQ(question, card.getQuestion()); + } diff --git a/tests/unit/Card/card.pri b/tests/unit/Card/card.pri new file mode 100644 index 0000000..2eae07d --- /dev/null +++ b/tests/unit/Card/card.pri @@ -0,0 +1,10 @@ +HEADERS += \ + $$PWD/Card_test.h \ + $$PWD/Card_GenerateAnswers_test.h \ + $$TESTS/mocks/CardPack_mock.h + +SOURCES += \ + $$PWD/Card_test.cpp \ + $$PWD/Card_test_QuestionAnswer.cpp \ + $$PWD/Card_GenerateAnswers_test.cpp \ + $$TESTS/mocks/CardPack_mock.cpp |