Added first version of unit tests for PixMap
authorJukka Saastamoinen <juksa@czc6303cj1.ixonos.local>
Tue, 13 Apr 2010 09:16:16 +0000 (12:16 +0300)
committerJukka Saastamoinen <juksa@czc6303cj1.ixonos.local>
Tue, 13 Apr 2010 09:16:16 +0000 (12:16 +0300)
scripts/master_test_script.sh [changed mode: 0644->0755]
src/src.pro
tests/testui/testpixmap/dummy_personal_infotab_background.png [new file with mode: 0644]
tests/testui/testpixmap/testpixmap.cpp [new file with mode: 0644]
tests/testui/testpixmap/testpixmap.pro [new file with mode: 0644]

old mode 100644 (file)
new mode 100755 (executable)
index 4a487da..56c8a7b 100644 (file)
@@ -3,6 +3,9 @@
 # -------------------------------------------------
 TARGET = ../situare
 TEMPLATE = app
+
+RESOURCES += images.qrc
+
 SOURCES += main.cpp \
     ui/mainwindow.cpp \
     ui/mapviewscreen.cpp \
@@ -47,4 +50,3 @@ unix {
     target.path = $$BINDIR
     INSTALLS += target
 }
-RESOURCES += images.qrc
diff --git a/tests/testui/testpixmap/dummy_personal_infotab_background.png b/tests/testui/testpixmap/dummy_personal_infotab_background.png
new file mode 100644 (file)
index 0000000..08dca9d
Binary files /dev/null and b/tests/testui/testpixmap/dummy_personal_infotab_background.png differ
diff --git a/tests/testui/testpixmap/testpixmap.cpp b/tests/testui/testpixmap/testpixmap.cpp
new file mode 100644 (file)
index 0000000..1b85356
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+     Situare - A location system for Facebook
+     Copyright (C) 2010  Ixonos Plc. Authors:
+
+         Jukka Saastamoinen - jukka.saastamoinen@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 <QtTest>
+#include <QtGui>
+#include "ui/pixmap.h"
+
+
+class TestPixmap: public QObject
+{
+    Q_OBJECT
+private slots:
+    void constructorTest();
+    void boundingRegionTest();
+private:
+    bool pixelCompareImages( const QImage &a, const QImage &b );
+};
+
+/**
+* @brief Tests that the class accepts the png file used to draw the image
+*/
+void TestPixmap::constructorTest()
+{
+    Pixmap *infoTab = new Pixmap(QPixmap("dummy_personal_infotab_background.png"));
+    delete infoTab;
+    infoTab=NULL;
+    QVERIFY(!infoTab);
+}
+
+/**
+* @brief Tests that the bounding area reserved for the picture is the same as
+* the picture size.
+*/
+
+void TestPixmap::boundingRegionTest()
+{
+    Pixmap testPic(QPixmap("dummy_personal_infotab_background.png")); //350x300 pix
+    QPixmap refPic("dummy_personal_infotab_background.png");
+    QRectF boundArea = testPic.boundingRect();
+    QRectF refArea;
+    refArea.setSize(refPic.size());
+    QVERIFY(boundArea.size()==refArea.size());
+}
+
+bool TestPixmap::pixelCompareImages( const QImage &a, const QImage &b )
+{
+  if( a.size() != b.size() )
+    return false;
+
+  if( a.format() != b.format() )
+    return false;
+
+  for( int x=0; x<a.width(); ++x )
+    for( int y=0; y<a.height(); ++y )
+      if( a.pixel(x,y) != b.pixel(x,y) )
+        return false;
+
+  return true;
+}
+
+QTEST_MAIN(TestPixmap)
+#include "testpixmap.moc"
+
+
diff --git a/tests/testui/testpixmap/testpixmap.pro b/tests/testui/testpixmap/testpixmap.pro
new file mode 100644 (file)
index 0000000..4eaec95
--- /dev/null
@@ -0,0 +1,10 @@
+CONFIG += qtestlib
+TEMPLATE = app
+TARGET = 
+DEPENDPATH += .
+INCLUDEPATH += . \
+    ../../../src/
+
+SOURCES += testpixmap.cpp \
+       ../../../src/ui/pixmap.cpp
+HEADERS += ../../../src/ui/pixmap.h