Implemented SceneCoordinate class and unit tests
authorSami Rämö <sami.ramo@ixonos.com>
Tue, 13 Jul 2010 14:27:01 +0000 (17:27 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Tue, 13 Jul 2010 14:27:01 +0000 (17:27 +0300)
src/coordinates/geocoordinate.h
src/coordinates/scenecoordinate.cpp [new file with mode: 0644]
src/coordinates/scenecoordinate.h [new file with mode: 0644]
tests/coordinates/geocoordinate/testgeocoordinate.cpp
tests/coordinates/scenecoordinate/scenecoordinate.pro [new file with mode: 0644]
tests/coordinates/scenecoordinate/testscenecoordinate.cpp [new file with mode: 0644]

index 7944d23..ff4dd6a 100644 (file)
@@ -39,7 +39,7 @@ public:
     GeoCoordinate();
 
     /**
-    * @brief Contsructs a coordinate with given latitude and longitude values
+    * @brief Constructs a coordinate with given latitude and longitude values
     *
     * @param latitude Latitude value
     * @param longitude Longitude value
diff --git a/src/coordinates/scenecoordinate.cpp b/src/coordinates/scenecoordinate.cpp
new file mode 100644 (file)
index 0000000..f846ea1
--- /dev/null
@@ -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 <QDebug>
+
+#include "scenecoordinate.h"
+
+SceneCoordinate::SceneCoordinate() :
+        m_x(0),
+        m_y(0)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+SceneCoordinate::SceneCoordinate(double x, double y) :
+        m_x(x),
+        m_y(y)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
+bool SceneCoordinate::isNull() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_x == 0 && m_y == 0)
+        return true;
+
+    return false;
+}
+
+double SceneCoordinate::x() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_x;
+}
+
+double SceneCoordinate::y() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_y;
+}
+
+void SceneCoordinate::setX(double x)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_x = x;
+}
+
+void SceneCoordinate::setY(double y)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_y = y;
+}
+
+QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate)
+{
+    dbg.nospace() << "(" << coordinate.x() << ", " << coordinate.y() << ")";
+
+    return dbg.space();
+}
diff --git a/src/coordinates/scenecoordinate.h b/src/coordinates/scenecoordinate.h
new file mode 100644 (file)
index 0000000..cc7f22f
--- /dev/null
@@ -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 SCENECOORDINATE_H
+#define SCENECOORDINATE_H
+
+#include <QDebug>
+
+/**
+* @brief Scene coordinate
+*
+* @author Sami Rämö - sami.ramo@ixonos.com
+*/
+class SceneCoordinate
+{
+public:
+    /**
+    * @brief Constructs a null coordinate
+    */
+    SceneCoordinate();
+
+    /**
+    * @brief Constructs a coordinate with given x and y
+    *
+    * @param x X value
+    * @param y Y value
+    */
+    SceneCoordinate(double x, double y);
+
+    /**
+    * @brief Check if coordinate is (0.0, 0.0)
+    *
+    * @returns True if both X and Y are 0.0, otherwise false
+    */
+    bool isNull() const;
+
+    /**
+    * @brief Sets the latitude
+    *
+    * @param x X value
+    */
+    void setX(double x);
+
+    /**
+    * @brief Sets the longitude
+    *
+    * @param y Y value
+    */
+    void setY(double y);
+
+    /**
+    * @brief Returns the x value
+    *
+    * @returns x
+    */
+    double x() const;
+
+    /**
+    * @brief Returns the y value
+    *
+    * @returns y
+    */
+    double y() const;
+
+private:
+    double m_x;         ///< X value
+    double m_y;         ///< Y value
+};
+
+QDebug operator<<(QDebug dbg, const SceneCoordinate &c);
+
+#endif // SCENECOORDINATE_H
index f21890c..efeb59e 100644 (file)
@@ -20,7 +20,6 @@
 */
 
 #include <QtCore/QString>
-#include <QDebug>
 #include <QtTest/QtTest>
 
 #include "coordinates/geocoordinate.h"
diff --git a/tests/coordinates/scenecoordinate/scenecoordinate.pro b/tests/coordinates/scenecoordinate/scenecoordinate.pro
new file mode 100644 (file)
index 0000000..949579c
--- /dev/null
@@ -0,0 +1,27 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-07-13T16:06:32
+#
+#-------------------------------------------------
+
+QT       += testlib
+
+QT       -= gui
+
+CONFIG   += console
+CONFIG   -= app_bundle
+
+TEMPLATE = app
+
+
+SOURCES += testscenecoordinate.cpp \
+    ../../../src/coordinates/scenecoordinate.cpp
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+
+HEADERS += \
+    ../../../src/coordinates/scenecoordinate.h
+
+INCLUDEPATH += . \
+    ../../../src/
+
+DEFINES += QT_NO_DEBUG_OUTPUT
diff --git a/tests/coordinates/scenecoordinate/testscenecoordinate.cpp b/tests/coordinates/scenecoordinate/testscenecoordinate.cpp
new file mode 100644 (file)
index 0000000..6bcc848
--- /dev/null
@@ -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.
+*/
+
+#include <QtCore/QString>
+#include <QtTest/QtTest>
+
+#include "coordinates/scenecoordinate.h"
+
+const double X = 12.345678;
+const double Y = -89.765432;
+
+class TestSceneCoordinate : public QObject
+{
+    Q_OBJECT
+
+public:
+    TestSceneCoordinate();
+
+private Q_SLOTS:
+    void constructors();
+    void isNull();
+    void settersAndGetters();
+};
+
+TestSceneCoordinate::TestSceneCoordinate()
+{
+}
+
+void TestSceneCoordinate::constructors()
+{
+    SceneCoordinate coordinate;
+    QVERIFY(coordinate.isNull());
+
+    SceneCoordinate coordinate2(X, Y);
+    QCOMPARE(coordinate2.x(), X);
+    QCOMPARE(coordinate2.y(), Y);
+}
+
+void TestSceneCoordinate::isNull()
+{
+    SceneCoordinate coordinate;
+    QVERIFY(coordinate.isNull());
+    coordinate.setX(1);
+    QVERIFY(!coordinate.isNull());
+
+    SceneCoordinate coordinate2;
+    QVERIFY(coordinate2.isNull());
+    coordinate2.setY(1);
+    QVERIFY(!coordinate.isNull());
+
+    SceneCoordinate coordinate3;
+    QVERIFY(coordinate3.isNull());
+    coordinate3.setX(1);
+    coordinate3.setY(1);
+    QVERIFY(!coordinate.isNull());
+}
+
+void TestSceneCoordinate::settersAndGetters()
+{
+    SceneCoordinate coordinate;
+    QCOMPARE(coordinate.x(), (double)0);
+    QCOMPARE(coordinate.y(), (double)0);
+
+    coordinate.setX(X);
+    coordinate.setY(Y);
+
+    QCOMPARE(coordinate.x(), X);
+    QCOMPARE(coordinate.y(), Y);
+}
+
+QTEST_APPLESS_MAIN(TestSceneCoordinate);
+
+#include "testscenecoordinate.moc"