From 2015b37f3b366dacf1bbef498e03fa9a72229b1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sami=20R=C3=A4m=C3=B6?= Date: Tue, 13 Jul 2010 17:06:55 +0300 Subject: [PATCH] Implemented GeoCoordinate class and unit tests --- src/coordinates/geocoordinate.cpp | 83 ++++++++++++++++++ src/coordinates/geocoordinate.h | 91 +++++++++++++++++++ tests/coordinates/geocoordinate/geocoordinate.pro | 27 ++++++ .../geocoordinate/testgeocoordinate.cpp | 92 ++++++++++++++++++++ 4 files changed, 293 insertions(+) create mode 100644 src/coordinates/geocoordinate.cpp create mode 100644 src/coordinates/geocoordinate.h create mode 100644 tests/coordinates/geocoordinate/geocoordinate.pro create mode 100644 tests/coordinates/geocoordinate/testgeocoordinate.cpp diff --git a/src/coordinates/geocoordinate.cpp b/src/coordinates/geocoordinate.cpp new file mode 100644 index 0000000..1fcdb31 --- /dev/null +++ b/src/coordinates/geocoordinate.cpp @@ -0,0 +1,83 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare 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 Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include + +#include "geocoordinate.h" + +GeoCoordinate::GeoCoordinate() : + m_latitude(0), + m_longitude(0) +{ + qDebug() << __PRETTY_FUNCTION__; +} + +GeoCoordinate::GeoCoordinate(double latitude, double longitude) : + m_latitude(latitude), + m_longitude(longitude) +{ + qDebug() << __PRETTY_FUNCTION__; +} + +bool GeoCoordinate::isNull() const +{ + qDebug() << __PRETTY_FUNCTION__; + + if (m_latitude == 0 && m_longitude == 0) + return true; + + return false; +} + +double GeoCoordinate::latitude() const +{ + qDebug() << __PRETTY_FUNCTION__; + + return m_latitude; +} + +double GeoCoordinate::longitude() const +{ + qDebug() << __PRETTY_FUNCTION__; + + return m_longitude; +} + +void GeoCoordinate::setLatitude(double latitude) +{ + qDebug() << __PRETTY_FUNCTION__; + + m_latitude = latitude; +} + +void GeoCoordinate::setLongitude(double longitude) +{ + qDebug() << __PRETTY_FUNCTION__; + + m_longitude = longitude; +} + +QDebug operator<<(QDebug dbg, const GeoCoordinate &coordinate) +{ + dbg.nospace() << "(" << coordinate.latitude() << ", " << coordinate.longitude() << ")"; + + return dbg.space(); +} diff --git a/src/coordinates/geocoordinate.h b/src/coordinates/geocoordinate.h new file mode 100644 index 0000000..7944d23 --- /dev/null +++ b/src/coordinates/geocoordinate.h @@ -0,0 +1,91 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare 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 Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + + +#ifndef GEOCOORDINATE_H +#define GEOCOORDINATE_H + +#include + +/** +* @brief Geographic coordinate +* +* @author Sami Rämö - sami.ramo@ixonos.com +*/ +class GeoCoordinate +{ +public: + /** + * @brief Constructs a null coordinate + */ + GeoCoordinate(); + + /** + * @brief Contsructs a coordinate with given latitude and longitude values + * + * @param latitude Latitude value + * @param longitude Longitude value + */ + GeoCoordinate(double latitude, double longitude); + + /** + * @brief Check if coordinate is (0.0, 0.0) + * + * @returns True if both latitude and longitude are 0.0, otherwise false + */ + bool isNull() const; + + /** + * @brief Returns the latitude value + * + * @returns latitude + */ + double latitude() const; + + /** + * @brief Returns the longitude value + * + * @returns longitude + */ + double longitude() const; + + /** + * @brief Sets the latitude + * + * @param latitude Latitude value + */ + void setLatitude(double latitude); + + /** + * @brief Sets the longitude + * + * @param longitude Longitude value + */ + void setLongitude(double longitude); + +private: + double m_latitude; ///< Latitude value + double m_longitude; ///< Longitude value +}; + +QDebug operator<<(QDebug dbg, const GeoCoordinate &c); + +#endif // GEOCOORDINATE_H diff --git a/tests/coordinates/geocoordinate/geocoordinate.pro b/tests/coordinates/geocoordinate/geocoordinate.pro new file mode 100644 index 0000000..93043a9 --- /dev/null +++ b/tests/coordinates/geocoordinate/geocoordinate.pro @@ -0,0 +1,27 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2010-07-13T16:07:22 +# +#------------------------------------------------- + +QT += testlib + +QT -= gui + +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += testgeocoordinate.cpp \ + ../../../src/coordinates/geocoordinate.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" + +INCLUDEPATH += . \ + ../../../src/ + +HEADERS += \ + ../../../src/coordinates/geocoordinate.h + +DEFINES += QT_NO_DEBUG_OUTPUT diff --git a/tests/coordinates/geocoordinate/testgeocoordinate.cpp b/tests/coordinates/geocoordinate/testgeocoordinate.cpp new file mode 100644 index 0000000..f21890c --- /dev/null +++ b/tests/coordinates/geocoordinate/testgeocoordinate.cpp @@ -0,0 +1,92 @@ +/* + Situare - A location system for Facebook + Copyright (C) 2010 Ixonos Plc. Authors: + + Sami Rämö - sami.ramo@ixonos.com + + Situare is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + version 2 as published by the Free Software Foundation. + + Situare 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 Situare; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + USA. +*/ + +#include +#include +#include + +#include "coordinates/geocoordinate.h" + +const double LATITUDE = 12.345678; +const double LONGITUDE = -89.765432; + +class TestGeoCoordinate : public QObject +{ + Q_OBJECT + +public: + TestGeoCoordinate(); + +private Q_SLOTS: + void constructors(); + void isNull(); + void settersAndGetters(); +}; + +TestGeoCoordinate::TestGeoCoordinate() +{ +} + +void TestGeoCoordinate::constructors() +{ + GeoCoordinate coordinate; + QVERIFY(coordinate.isNull()); + + GeoCoordinate coordinate2(LATITUDE, LONGITUDE); + QCOMPARE(coordinate2.latitude(), LATITUDE); + QCOMPARE(coordinate2.longitude(), LONGITUDE); +} + +void TestGeoCoordinate::isNull() +{ + GeoCoordinate coordinate; + QVERIFY(coordinate.isNull()); + coordinate.setLatitude(1); + QVERIFY(!coordinate.isNull()); + + GeoCoordinate coordinate2; + QVERIFY(coordinate2.isNull()); + coordinate2.setLongitude(1); + QVERIFY(!coordinate.isNull()); + + GeoCoordinate coordinate3; + QVERIFY(coordinate3.isNull()); + coordinate3.setLatitude(1); + coordinate3.setLongitude(1); + QVERIFY(!coordinate.isNull()); +} + +void TestGeoCoordinate::settersAndGetters() +{ + GeoCoordinate coordinate; + QCOMPARE(coordinate.latitude(), (double)0); + QCOMPARE(coordinate.longitude(), (double)0); + + coordinate.setLatitude(LATITUDE); + coordinate.setLongitude(LONGITUDE); + + QCOMPARE(coordinate.latitude(), LATITUDE); + QCOMPARE(coordinate.longitude(), LONGITUDE); +} + +QTEST_APPLESS_MAIN(TestGeoCoordinate); + +#include "testgeocoordinate.moc" -- 1.7.9.5