From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- tests/mocks/CardPack_mock.cpp | 31 +++++++++++++++++++++++++++++++ tests/mocks/CardPack_mock.h | 23 +++++++++++++++++++++++ tests/mocks/Dictionary_mock.cpp | 6 ++++++ tests/mocks/Dictionary_mock.h | 32 ++++++++++++++++++++++++++++++++ tests/mocks/RandomGenerator_mock.h | 33 +++++++++++++++++++++++++++++++++ tests/mocks/TimeProvider_mock.cpp | 9 +++++++++ 6 files changed, 134 insertions(+) create mode 100644 tests/mocks/CardPack_mock.cpp create mode 100644 tests/mocks/CardPack_mock.h create mode 100644 tests/mocks/Dictionary_mock.cpp create mode 100644 tests/mocks/Dictionary_mock.h create mode 100644 tests/mocks/RandomGenerator_mock.h create mode 100644 tests/mocks/TimeProvider_mock.cpp (limited to 'tests/mocks') diff --git a/tests/mocks/CardPack_mock.cpp b/tests/mocks/CardPack_mock.cpp new file mode 100644 index 0000000..159e0de --- /dev/null +++ b/tests/mocks/CardPack_mock.cpp @@ -0,0 +1,31 @@ +#include "CardPack_mock.h" + +void CardPackMock::addStudyRecord(const QString cardId, const StudyRecord& studyRecord) +{ + studyRecords.insert(cardId, studyRecord); +} + +QList CardPackMock::getStudyRecords(QString cardId) const +{ + return studyRecords.values(cardId); +} + +StudyRecord CardPackMock::getStudyRecord(QString cardId) const +{ + return studyRecords.values(cardId).first(); +} + +QList CardPackMock::getRecords() const +{ + return QList(); +} + +const Field* CardPackMock::getQuestionField() const +{ + return NULL; +} + +QList CardPackMock::getAnswerFields() const +{ + return QList(); +} diff --git a/tests/mocks/CardPack_mock.h b/tests/mocks/CardPack_mock.h new file mode 100644 index 0000000..50e6c13 --- /dev/null +++ b/tests/mocks/CardPack_mock.h @@ -0,0 +1,23 @@ +#ifndef CARDPACK_MOCK_H +#define CARDPACK_MOCK_H + +#include + +#include "../../src/dictionary/ICardPack.h" + +class CardPackMock: public ICardPack +{ +public: + void addStudyRecord(const QString cardId, const StudyRecord& studyRecord); + QList getStudyRecords(QString cardId) const; + StudyRecord getStudyRecord(QString cardId) const; + + QList getRecords() const; + const Field* getQuestionField() const; + QList getAnswerFields() const; + +private: + QMultiHash< QString, StudyRecord > studyRecords; +}; + +#endif diff --git a/tests/mocks/Dictionary_mock.cpp b/tests/mocks/Dictionary_mock.cpp new file mode 100644 index 0000000..905a2f2 --- /dev/null +++ b/tests/mocks/Dictionary_mock.cpp @@ -0,0 +1,6 @@ +#include "Dictionary_mock.h" + +void MockDictionary::addCardPack(CardPack* aCardPack) +{ + m_cardPacks << aCardPack; +} diff --git a/tests/mocks/Dictionary_mock.h b/tests/mocks/Dictionary_mock.h new file mode 100644 index 0000000..0b29fbb --- /dev/null +++ b/tests/mocks/Dictionary_mock.h @@ -0,0 +1,32 @@ +#ifndef DICTIONARY_MOCK_H +#define DICTIONARY_MOCK_H + +#include + +#include "../../src/dictionary/IDictionary.h" +#include "../../src/dictionary/TreeItem.h" + +class MockDictionary: public TreeItem, public IDictionary +{ +Q_OBJECT +public: + const TreeItem* parent() const { return NULL; } + const TreeItem* child(int) const { return NULL; } + int childCount() const { return 0; } + int columnCount() const { return 0; } + QVariant data(int) const { return QVariant(); } + int row() const { return 0; } + int topParentRow() const { return 0; } + + const Field* field(int) const { return NULL; } + const Field* field(const QString) const { return NULL; } + int indexOfCardPack(CardPack*) const { return 0; } + + void addCardPack(CardPack* aCardPack); + +signals: + void entryChanged( int aEntryIx, int aFieldIx ); + void entriesRemoved( int aIndex, int aNum ); +}; + +#endif diff --git a/tests/mocks/RandomGenerator_mock.h b/tests/mocks/RandomGenerator_mock.h new file mode 100644 index 0000000..0d3ef97 --- /dev/null +++ b/tests/mocks/RandomGenerator_mock.h @@ -0,0 +1,33 @@ +#ifndef RANDOM_GENERATOR_MOCK_H +#define RANDOM_GENERATOR_MOCK_H + +#include "../../src/utils/IRandomGenerator.h" + +class MockRandomGenerator: public IRandomGenerator +{ +public: + MockRandomGenerator(): + dRandom(0), rand(0) {} + double getInRange_11() const { return dRandom; } + double getInRange_01() const { return dRandom; } + int getRand() const { return rand; } + int getRand(int maxNum) const + { + int r = rand; + if(r >= maxNum) + r = maxNum -1; + return r; + } + QByteArray getArray() const { return array; } + + void setDouble(double dRandom) { this->dRandom = dRandom; } + void setRand(int rand) { this->rand = rand; } + void setArray(const QByteArray& array) { this->array = array; } + +private: + double dRandom; + int rand; + QByteArray array; +}; + +#endif diff --git a/tests/mocks/TimeProvider_mock.cpp b/tests/mocks/TimeProvider_mock.cpp new file mode 100644 index 0000000..22cfb43 --- /dev/null +++ b/tests/mocks/TimeProvider_mock.cpp @@ -0,0 +1,9 @@ +#include "../../src/utils/TimeProvider.h" + +// TODO: Make interface with virtual function. Use Time provider as singleton. + +QDateTime TimeProvider::get() +{ + static QDateTime time = QDateTime::currentDateTime(); + return time; +} -- cgit