summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2010-12-16 06:53:08 +0100
committerGunnar Sletta <gunnar.sletta@nokia.com>2010-12-16 06:53:42 +0100
commit6bdfa1a7529a9f4dd379b3eca4dec1cb4ce7364d (patch)
tree2be044b5d1c1eb47c60fdf03f996f89d3871f085
parent1ee64e326b037e3da4d68b21597939dbf4728bc4 (diff)
autotest for the texture manager
-rw-r--r--qt-scene-graph.pro3
-rwxr-xr-xtests/auto/run_tests.sh18
-rw-r--r--tests/auto/texturemanager/texturemanager.pro17
-rw-r--r--tests/auto/texturemanager/tst_texturemanagertest.cpp89
4 files changed, 126 insertions, 1 deletions
diff --git a/qt-scene-graph.pro b/qt-scene-graph.pro
index ab9a0bd..30287dd 100644
--- a/qt-scene-graph.pro
+++ b/qt-scene-graph.pro
@@ -1,3 +1,4 @@
TEMPLATE = subdirs
-SUBDIRS += src tools plugins examples
+SUBDIRS += src tools plugins examples \
+ tests/auto/texturemanager
CONFIG += ordered
diff --git a/tests/auto/run_tests.sh b/tests/auto/run_tests.sh
new file mode 100755
index 0000000..87025c0
--- /dev/null
+++ b/tests/auto/run_tests.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+function execute_test()
+{
+ cd $1
+ qmake
+ make
+ ./tst_$1
+ cd ..
+}
+
+for val in *
+do
+ if [ -d "$val" ]
+ then
+ execute_test $val
+ fi
+done
diff --git a/tests/auto/texturemanager/texturemanager.pro b/tests/auto/texturemanager/texturemanager.pro
new file mode 100644
index 0000000..e203d26
--- /dev/null
+++ b/tests/auto/texturemanager/texturemanager.pro
@@ -0,0 +1,17 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2010-12-16T06:09:44
+#
+#-------------------------------------------------
+
+QT += opengl testlib
+
+TARGET = tst_texturemanager
+CONFIG += console
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+SOURCES += tst_texturemanagertest.cpp
+
+include(../../../src/scenegraph_include.pri)
diff --git a/tests/auto/texturemanager/tst_texturemanagertest.cpp b/tests/auto/texturemanager/tst_texturemanagertest.cpp
new file mode 100644
index 0000000..853d527
--- /dev/null
+++ b/tests/auto/texturemanager/tst_texturemanagertest.cpp
@@ -0,0 +1,89 @@
+#include <QtCore/QString>
+#include <QtTest/QtTest>
+#include <QtCore/QCoreApplication>
+
+#include <qsgcontext.h>
+#include <qsgtexturemanager.h>
+
+class TextureManagerTest : public QObject
+{
+ Q_OBJECT
+
+public:
+ TextureManagerTest();
+
+private Q_SLOTS:
+ void initTestCase();
+ void cleanupTestCase();
+
+ void upload();
+ void uploadSameImageTwice();
+
+private:
+ QSGContext *context;
+ QGLWidget *glWidget;
+ QSGTextureManager *tm;
+};
+
+
+TextureManagerTest::TextureManagerTest()
+{
+}
+
+
+void TextureManagerTest::initTestCase()
+{
+ glWidget = new QGLWidget();
+ glWidget->resize(300, 200);
+ glWidget->show();
+
+ context = new QSGContext();
+ context->initialize(const_cast<QGLContext *>(glWidget->context()));
+
+ tm = context->textureManager();
+}
+
+
+void TextureManagerTest::cleanupTestCase()
+{
+ delete context;
+ delete glWidget;
+}
+
+
+/*!
+ Verify that uploads work and are synchronous and that
+ size of returned texture must be at least image dims.
+ */
+void TextureManagerTest::upload()
+{
+ QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
+ QSGTextureRef t = tm->upload(image);
+
+ QVERIFY(!t.isNull());
+ QVERIFY(t.isReady());
+ QVERIFY(t->textureId() > 0);
+
+ QVERIFY(t->textureSize().width() >= image.width());
+ QVERIFY(t->textureSize().height() >= image.height());
+}
+
+
+/*!
+ Verify that two requests of the same image returns the same texture.
+ */
+void TextureManagerTest::uploadSameImageTwice()
+{
+ QImage image(100, 100, QImage::Format_ARGB32_Premultiplied);
+ QSGTextureRef t = tm->upload(image);
+
+ QImage shallowCopy = image;
+ QSGTextureRef t2 = tm->upload(shallowCopy);
+ QCOMPARE(t.texture(), t2.texture());
+
+}
+
+
+QTEST_MAIN(TextureManagerTest);
+
+#include "tst_texturemanagertest.moc"