From 5c28d3fb6ec5a39d7415b068da47e6b01898d6d7 Mon Sep 17 00:00:00 2001 From: Aki Koskinen Date: Sun, 28 Mar 2010 22:03:22 +0300 Subject: [PATCH] Added assignment operator to KKJ class. --- src/kkj.cpp | 9 +++++++++ src/kkj.h | 7 +++++++ tests/ut_kkj/ut_kkj.cpp | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/kkj.cpp b/src/kkj.cpp index 5961353..5948293 100644 --- a/src/kkj.cpp +++ b/src/kkj.cpp @@ -37,6 +37,15 @@ bool KKJ::operator==(const KKJ &rhs) const return northing() == rhs.northing() && easting() == rhs.easting(); } +KKJ& KKJ::operator=(const KKJ &rhs) +{ + Q_D(KKJ); + d->northing = rhs.northing(); + d->easting = rhs.easting(); + + return *this; +} + unsigned int KKJ::northing() const { Q_D(const KKJ); diff --git a/src/kkj.h b/src/kkj.h index 5daddde..ec7d79b 100644 --- a/src/kkj.h +++ b/src/kkj.h @@ -33,6 +33,13 @@ public: bool operator==(const KKJ &rhs) const; /** + * Assignment operator. + * @param rhs the object that is copied. + * @return this object. + */ + KKJ& operator=(const KKJ &rhs); + + /** * Returns the northing of the coordinate. * @return the northing. */ diff --git a/tests/ut_kkj/ut_kkj.cpp b/tests/ut_kkj/ut_kkj.cpp index 22ec962..6988ac6 100644 --- a/tests/ut_kkj/ut_kkj.cpp +++ b/tests/ut_kkj/ut_kkj.cpp @@ -3,6 +3,8 @@ #include #include +#include "stlhelpers.h" + class KKJTest : public ::testing::Test { public: @@ -44,6 +46,15 @@ TEST_F(KKJTest, EqualsOperatorReturnsFalseForCoordinatesWithDifferentEasting) ASSERT_FALSE(kkj1 == kkj2); } +TEST_F(KKJTest, AssignmentOperator) +{ + const KKJ kkj1(northing, easting); + KKJ kkj2(0, 0); + kkj2 = kkj1; + ASSERT_EQ(northing, kkj2.northing()); + ASSERT_EQ(easting, kkj2.easting()); +} + int main(int argc, char *argv[]) { ::testing::InitGoogleMock(&argc, argv); -- 1.7.9.5