summaryrefslogtreecommitdiff
path: root/tests/mocks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mocks')
-rw-r--r--tests/mocks/CardPack_mock.cpp31
-rw-r--r--tests/mocks/CardPack_mock.h23
-rw-r--r--tests/mocks/Dictionary_mock.cpp6
-rw-r--r--tests/mocks/Dictionary_mock.h32
-rw-r--r--tests/mocks/RandomGenerator_mock.h33
-rw-r--r--tests/mocks/TimeProvider_mock.cpp9
6 files changed, 134 insertions, 0 deletions
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<StudyRecord> CardPackMock::getStudyRecords(QString cardId) const
+{
+ return studyRecords.values(cardId);
+}
+
+StudyRecord CardPackMock::getStudyRecord(QString cardId) const
+{
+ return studyRecords.values(cardId).first();
+}
+
+QList<DicRecord*> CardPackMock::getRecords() const
+{
+ return QList<DicRecord*>();
+}
+
+const Field* CardPackMock::getQuestionField() const
+{
+ return NULL;
+}
+
+QList<const Field*> CardPackMock::getAnswerFields() const
+{
+ return QList<const Field*>();
+}
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 <QtCore>
+
+#include "../../src/dictionary/ICardPack.h"
+
+class CardPackMock: public ICardPack
+{
+public:
+ void addStudyRecord(const QString cardId, const StudyRecord& studyRecord);
+ QList<StudyRecord> getStudyRecords(QString cardId) const;
+ StudyRecord getStudyRecord(QString cardId) const;
+
+ QList<DicRecord*> getRecords() const;
+ const Field* getQuestionField() const;
+ QList<const Field*> 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 <QtCore>
+
+#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;
+}