summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHartmut Riesenbeck <hartmut.riesenbeck@gmx.de>2016-09-22 18:00:11 (GMT)
committerHartmut Riesenbeck <hartmut.riesenbeck@gmx.de>2016-09-22 18:00:11 (GMT)
commite410bd83ea425a43686394a38c881d5cfb341697 (patch)
tree5e1e446c9fc1d42ba509c078e8c1f93c1f944bbc
parentddb743b7e312e69d7f1eee9a3f4c25ef8031b27b (diff)
Fix faulty assignment and equal to operator of KEduVocTextv16.12.3v16.12.2v16.12.1v16.12.0v16.11.90v16.11.80Applications/16.12
The two members m_preGrade and m_interval were not copied by the assignment operator nor were compared by the equal to operator of the KEduVocText class. Test methods to check correct behaviour were added. REVIEW: 128975
-rw-r--r--keduvocdocument/autotests/CMakeLists.txt1
-rw-r--r--keduvocdocument/autotests/keduvoctexttest.cpp141
-rw-r--r--keduvocdocument/autotests/keduvoctexttest.h48
-rw-r--r--keduvocdocument/keduvoctext.cpp10
-rw-r--r--keduvocdocument/keduvoctext.h4
5 files changed, 199 insertions, 5 deletions
diff --git a/keduvocdocument/autotests/CMakeLists.txt b/keduvocdocument/autotests/CMakeLists.txt
index 679a5f6..e02bbfb 100644
--- a/keduvocdocument/autotests/CMakeLists.txt
+++ b/keduvocdocument/autotests/CMakeLists.txt
@@ -20,6 +20,7 @@ set(kvocdoc_api_unittests
# openAPItest
keduvocdocumenttest
emptydocumenttest
+ keduvoctexttest
)
#Unit Tests linked to objects behind the API wall
diff --git a/keduvocdocument/autotests/keduvoctexttest.cpp b/keduvocdocument/autotests/keduvoctexttest.cpp
new file mode 100644
index 0000000..d28a395
--- /dev/null
+++ b/keduvocdocument/autotests/keduvoctexttest.cpp
@@ -0,0 +1,141 @@
+/***************************************************************************
+ * Copyright (C) 2016 by Hartmut Riesenbeck <hartmut.riesenbeck@gmx.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "keduvoctexttest.h"
+
+#include "keduvoctext.h"
+#include <QTest>
+
+namespace KEduVocTextTests{
+
+void KEduVocTextTest::testAssignmentOperator()
+{
+ // This list should be extended when new data members are added to
+ // KEduVocTextPrivate. Appropriate getter/setter methods needs to be
+ // provided by KEduVocText.
+
+ KEduVocText t1;
+ KEduVocText t2;
+
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setText("foo");
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setPreGrade(1);
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setGrade(1);
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setPracticeCount(1);
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setBadCount(1);
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setPracticeDate(QDateTime::currentDateTime());
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+
+ t1.setInterval(1);
+ QCOMPARE(isEqual(t1, t2), false);
+ t2 = t1;
+ QCOMPARE(isEqual(t1, t2), true);
+}
+
+void KEduVocTextTest::testEqualToOperator()
+{
+ // This list should be extended when new data members are added to
+ // KEduVocTextPrivate. Appropriate getter/setter methods needs to be
+ // provided by KEduVocText.
+
+ KEduVocText t1;
+ KEduVocText t2;
+
+ QCOMPARE(t1 == t2, true);
+
+ t1.setText("foo");
+ QCOMPARE(t1 == t2, false);
+ t2.setText("foo");
+ QCOMPARE(t1 == t2, true);
+
+ t1.setPreGrade(1);
+ QCOMPARE(t1 == t2, false);
+ t2.setPreGrade(1);
+ QCOMPARE(t1 == t2, true);
+
+ t1.setGrade(1);
+ QCOMPARE(t1 == t2, false);
+ t2.setGrade(1);
+ QCOMPARE(t1 == t2, true);
+
+ t1.setPracticeCount(1);
+ QCOMPARE(t1 == t2, false);
+ t2.setPracticeCount(1);
+ QCOMPARE(t1 == t2, true);
+
+ t1.setBadCount(1);
+ QCOMPARE(t1 == t2, false);
+ t2.setBadCount(1);
+ QCOMPARE(t1 == t2, true);
+
+ QDateTime testTime(QDateTime::currentDateTime());
+ t1.setPracticeDate(testTime);
+ QCOMPARE(t1 == t2, false);
+ t2.setPracticeDate(testTime);
+ QCOMPARE(t1 == t2, true);
+
+ t1.setInterval(1);
+ QCOMPARE(t1 == t2, false);
+ t2.setInterval(1);
+ QCOMPARE(t1 == t2, true);
+}
+
+bool KEduVocTextTest::isEqual(const KEduVocText &a, const KEduVocText &b) const
+{
+ // This list should be extended when new data members are added to
+ // KEduVocTextPrivate. Appropriate getter/setter methods needs to be
+ // provided by KEduVocText.
+
+ return a.text() == b.text()
+ && a.preGrade() == b.preGrade()
+ && a.grade() == b.grade()
+ && a.practiceCount() == b.practiceCount()
+ && a.badCount() == b.badCount()
+ && a.practiceDate() == b.practiceDate()
+ && a.interval() == b.interval();
+
+}
+
+}
+
+QTEST_MAIN(KEduVocTextTests::KEduVocTextTest)
+
diff --git a/keduvocdocument/autotests/keduvoctexttest.h b/keduvocdocument/autotests/keduvoctexttest.h
new file mode 100644
index 0000000..de16732
--- /dev/null
+++ b/keduvocdocument/autotests/keduvoctexttest.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2016 by Hartmut Riesenbeck <hartmut.riesenbeck@gmx.de> *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef KEDUVOCTEXTTEST_H
+#define KEDUVOCTEXTTESTH
+
+#include <QObject>
+
+class KEduVocText;
+
+namespace KEduVocTextTests {
+/** @file
+ * \brief KeduVocText test application
+ * Various tests for KeduVocText class.
+ * @author Hartmut Riesenbeck <hartmut.riesenbeck@gmx.de>
+ */
+
+class KEduVocTextTest : public QObject
+{
+Q_OBJECT
+
+private slots:
+ void testAssignmentOperator();
+ void testEqualToOperator();
+
+private:
+ bool isEqual(const KEduVocText &a, const KEduVocText &b) const;
+};
+}
+
+#endif // KEDUVOCTEXTTEST_H
+
diff --git a/keduvocdocument/keduvoctext.cpp b/keduvocdocument/keduvoctext.cpp
index 6205106..a19f590 100644
--- a/keduvocdocument/keduvoctext.cpp
+++ b/keduvocdocument/keduvoctext.cpp
@@ -184,25 +184,29 @@ void KEduVocText::setInterval( quint32 interval )
}
-KEduVocText & KEduVocText::operator =(const KEduVocText & other)
+KEduVocText &KEduVocText::operator=(const KEduVocText &other)
{
d->m_text = other.d->m_text;
+ d->m_preGrade = other.d->m_preGrade;
d->m_grade = other.d->m_grade;
d->m_totalPracticeCount = other.d->m_totalPracticeCount;
d->m_badCount = other.d->m_badCount;
d->m_practiceDate = other.d->m_practiceDate;
+ d->m_interval = other.d->m_interval;
return *this;
}
-bool KEduVocText::operator ==(const KEduVocText & other) const
+bool KEduVocText::operator==(const KEduVocText &other) const
{
return
d->m_text == other.d->m_text &&
+ d->m_preGrade == other.d->m_preGrade &&
d->m_grade == other.d->m_grade &&
d->m_totalPracticeCount == other.d->m_totalPracticeCount &&
d->m_badCount == other.d->m_badCount &&
- d->m_practiceDate == other.d->m_practiceDate;
+ d->m_practiceDate == other.d->m_practiceDate &&
+ d->m_interval == other.d->m_interval;
}
void KEduVocText::toKVTML2(QDomElement& parent)
diff --git a/keduvocdocument/keduvoctext.h b/keduvocdocument/keduvoctext.h
index 7a7408a..d3d43c3 100644
--- a/keduvocdocument/keduvoctext.h
+++ b/keduvocdocument/keduvoctext.h
@@ -88,13 +88,13 @@ public:
* @param other grades copied
* @return reference to the new grades
*/
- KEduVocText& operator= ( const KEduVocText &other );
+ KEduVocText &operator=(const KEduVocText &other);
/**
* Compare two sets of grades.
* @param other
* @return true if equal
*/
- bool operator== ( const KEduVocText &other ) const;
+ bool operator==(const KEduVocText &other) const;
/** returns how often this entry has been practiced as int