[gegl-qt] Tests: NodeViewImplementation, viewAreaChanged on computed and translations
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-qt] Tests: NodeViewImplementation, viewAreaChanged on computed and translations
- Date: Mon, 22 Aug 2011 20:49:41 +0000 (UTC)
commit d4981631780458df9f8873a7fda2f4a9aa715bfa
Author: Jon Nordby <jononor gmail com>
Date: Mon Aug 22 22:38:07 2011 +0200
Tests: NodeViewImplementation, viewAreaChanged on computed and translations
.../test-nodeviewimplementation.cpp | 129 +++++++++++++++++++-
.../test-nodeviewimplementation.h | 17 +++-
2 files changed, 138 insertions(+), 8 deletions(-)
---
diff --git a/tests/test-nodeviewimplementation/test-nodeviewimplementation.cpp b/tests/test-nodeviewimplementation/test-nodeviewimplementation.cpp
index 79b6bef..b9c3248 100644
--- a/tests/test-nodeviewimplementation/test-nodeviewimplementation.cpp
+++ b/tests/test-nodeviewimplementation/test-nodeviewimplementation.cpp
@@ -18,23 +18,140 @@
#include "test-nodeviewimplementation.h"
-#include <gegl-qt/internal/nodeviewimplementation.h>
-
#include <QtTest>
using namespace GeglQt;
-/* Tests GeglQtViewImplementation, not the widgets
- * themselves. */
+/* Tests the node view implementation, which is used by the different node view widgets.
+ * TODO:
+ * - Test that the GeglNode is processed (emits 'computed' signal) when invalidated
+ * - Test scaling
+ * - Test redraw behavior on option changes
+ * - Test autoscaling
+ * - Test autocentering
+ */
TestNodeViewImplementation::TestNodeViewImplementation(QObject *parent) :
QObject(parent)
{}
-void TestNodeViewImplementation::testNothing()
+void TestNodeViewImplementation::init()
+{
+ mViewImplementation = new NodeViewImplementation();
+ mGeglNode = gegl_node_new();
+
+ mViewImplementation->setInputNode(mGeglNode);
+}
+
+void TestNodeViewImplementation::clean()
+{
+ g_object_unref(mGeglNode);
+ delete mViewImplementation;
+}
+
+/* Does nothing. */
+void TestNodeViewImplementation::testSanity()
{
- NodeViewImplementation viewImplementation;
+
}
+/* When the attached GeglNode emits the "computed" signal,
+ * the NodeViewImplementation shall emit a "viewAreaChanged" signal
+ */
+void TestNodeViewImplementation::testComputedSignalEmitsViewAreaChanged_data()
+{
+ QTest::addColumn<QRect>("input");
+ QTest::addColumn<QRectF>("expectedOutput");
+
+ QTest::newRow("0,0 100x100")
+ << QRect(0, 0, 100, 100)
+ << QRectF(0, 0, 100, 100);
+ QTest::newRow("0,0 100000x100000")
+ << QRect(0, 0, 100000, 100000)
+ << QRectF(0, 0, 100000, 100000);
+
+ QTest::newRow("13,13 1000x1000")
+ << QRect(13, 13, 1000, 1000)
+ << QRectF(13, 13, 1000, 1000);
+ QTest::newRow("-13,-13 1000x1000")
+ << QRect(-13, -13, 1000, 1000)
+ << QRectF(-13, -13, 1000, 1000);
+
+ QTest::newRow("130000,130000 1000x1000")
+ << QRect(130000, 130000, 1000, 1000)
+ << QRectF(130000, 130000, 1000, 1000);
+ QTest::newRow("-130000,-130000 1000x1000")
+ << QRect(-130000, -130000, 1000, 1000)
+ << QRectF(-130000, -130000, 1000, 1000);
+
+}
+void TestNodeViewImplementation::testComputedSignalEmitsViewAreaChanged()
+{
+ /* NOTE: tests the default transformation as a side-effect */
+ QFETCH(QRect, input);
+ QFETCH(QRectF, expectedOutput);
+ GeglRectangle computedRect = {input.x(), input.y(), input.width(), input.height()};
+
+ QSignalSpy signalSpy(mViewImplementation, SIGNAL(viewAreaChanged(QRectF)));
+
+ g_signal_emit_by_name(mGeglNode, "computed", &computedRect, NULL);
+
+ QCOMPARE(signalSpy.count(), 1);
+ QCOMPARE(signalSpy.at(0).first().toRectF(), expectedOutput);
+}
+
+/* Test that the computed -> viewAreaChanged obeys translations correctly */
+void TestNodeViewImplementation::testViewAreaChangedWithTranslation_data()
+{
+ QTest::addColumn<QRect>("input");
+ QTest::addColumn<QPointF>("translation");
+ QTest::addColumn<QRectF>("expectedOutput");
+
+ QTest::newRow("0,0 100x100. Translated by (0,0)")
+ << QRect(0, 0, 100, 100) << QPointF(0,0)
+ << QRectF(0, 0, 100, 100);
+ QTest::newRow("0,0 100x100. Translated by (9,9)")
+ << QRect(0, 0, 100, 100) << QPointF(9,9)
+ << QRectF(9, 9, 100, 100);
+
+ QTest::newRow("9,9 100x100. Translated by (9,9)")
+ << QRect(9, 9, 100, 100) << QPointF(9,9)
+ << QRectF(18, 18, 100, 100);
+ QTest::newRow("-9,-9 100x100. Translated by (9,9)")
+ << QRect(-9, -9, 100, 100) << QPointF(9,9)
+ << QRectF(0, 0, 100, 100);
+
+ QTest::newRow("9999,9999 10000x10000. Translated by (99,0)")
+ << QRect(9999, 9999, 10000, 10000) << QPointF(99,0)
+ << QRectF(10098, 9999, 10000, 10000);
+ QTest::newRow("-9999,-9999 10000x10000. Translated by (0,99)")
+ << QRect(-9999, -9999, 10000, 10000) << QPointF(0,99)
+ << QRectF(-9999, -9900, 10000, 10000);
+
+ QTest::newRow("100,100 100x100. Translated by (0.5,-0.5)")
+ << QRect(100, 100, 100, 100) << QPointF(0.5,-0.5)
+ << QRectF(100.5, 99.5, 100, 100);
+ QTest::newRow("-100,-100 100x100. Translated by (-0.5,0.5)")
+ << QRect(-100, -100, 100, 100) << QPointF(-0.5,0.5)
+ << QRectF(-100.5, -99.5, 100, 100);
+
+}
+void TestNodeViewImplementation::testViewAreaChangedWithTranslation()
+{
+ /* NOTE: tests the default scale value as a side-effect */
+ QFETCH(QRect, input);
+ QFETCH(QPointF, translation);
+ QFETCH(QRectF, expectedOutput);
+ GeglRectangle computedRect = {input.x(), input.y(), input.width(), input.height()};
+
+ mViewImplementation->options()->setTranslationX(translation.x());
+ mViewImplementation->options()->setTranslationY(translation.y());
+
+ QSignalSpy signalSpy(mViewImplementation, SIGNAL(viewAreaChanged(QRectF)));
+ g_signal_emit_by_name(mGeglNode, "computed", &computedRect, NULL);
+
+ QCOMPARE(signalSpy.count(), 1);
+ QCOMPARE(signalSpy.at(0).first().toRectF(), expectedOutput);
+}
QTEST_MAIN(TestNodeViewImplementation)
diff --git a/tests/test-nodeviewimplementation/test-nodeviewimplementation.h b/tests/test-nodeviewimplementation/test-nodeviewimplementation.h
index 05d6eab..487b87b 100644
--- a/tests/test-nodeviewimplementation/test-nodeviewimplementation.h
+++ b/tests/test-nodeviewimplementation/test-nodeviewimplementation.h
@@ -2,6 +2,9 @@
#define TESTNODEVIEWIMPLEMENTATION_H
#include <QObject>
+#include <gegl.h>
+
+#include <gegl-qt/internal/nodeviewimplementation.h>
class TestNodeViewImplementation : public QObject
{
@@ -10,10 +13,20 @@ public:
explicit TestNodeViewImplementation(QObject *parent = 0);
private Q_SLOTS:
- void testNothing();
+ void init();
+ void clean();
-private:
+ void testSanity();
+
+ void testComputedSignalEmitsViewAreaChanged_data();
+ void testComputedSignalEmitsViewAreaChanged();
+ void testViewAreaChangedWithTranslation_data();
+ void testViewAreaChangedWithTranslation();
+
+private:
+ GeglQt::NodeViewImplementation *mViewImplementation;
+ GeglNode *mGeglNode;
};
#endif // TESTNODEVIEWIMPLEMENTATION_H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]