Commit e410bd83 authored by Hartmut Riesenbeck's avatar Hartmut Riesenbeck
Browse files

Fix faulty assignment and equal to operator of KEduVocText

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
parent ddb743b7
......@@ -20,6 +20,7 @@ set(kvocdoc_api_unittests
# openAPItest
keduvocdocumenttest
emptydocumenttest
keduvoctexttest
)
#Unit Tests linked to objects behind the API wall
......
/***************************************************************************
* 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)
/***************************************************************************
* 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
......@@ -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)
......
......@@ -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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment