summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
index 01120b1..91b3ca0 100644
--- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
+++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
@@ -47,6 +47,7 @@
#include <QFontMetrics>
#include <QGraphicsSceneMouseEvent>
#include <qmath.h>
+#include <QDeclarativeView>
#include "../../../shared/util.h"
#include "testhttpserver.h"
@@ -70,6 +71,9 @@ private slots:
void elide();
void textFormat();
+ void alignments_data();
+ void alignments();
+
void embeddedImages_data();
void embeddedImages();
@@ -108,6 +112,8 @@ private:
QStringList colorStrings;
QDeclarativeEngine engine;
+
+ QDeclarativeView *createView(const QString &filename);
};
tst_qdeclarativetext::tst_qdeclarativetext()
@@ -163,6 +169,14 @@ tst_qdeclarativetext::tst_qdeclarativetext()
//
}
+QDeclarativeView *tst_qdeclarativetext::createView(const QString &filename)
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+
+ canvas->setSource(QUrl::fromLocalFile(filename));
+ return canvas;
+}
+
void tst_qdeclarativetext::text()
{
{
@@ -383,6 +397,58 @@ void tst_qdeclarativetext::textFormat()
}
}
+
+void tst_qdeclarativetext::alignments_data()
+{
+ QTest::addColumn<int>("hAlign");
+ QTest::addColumn<int>("vAlign");
+ QTest::addColumn<QString>("expectfile");
+
+ QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << SRCDIR "/data/alignments_lt.png";
+ QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << SRCDIR "/data/alignments_rt.png";
+ QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << SRCDIR "/data/alignments_ct.png";
+
+ QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_lb.png";
+ QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_rb.png";
+ QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_cb.png";
+
+ QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_lc.png";
+ QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_rc.png";
+ QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_cc.png";
+}
+
+
+void tst_qdeclarativetext::alignments()
+{
+ QFETCH(int, hAlign);
+ QFETCH(int, vAlign);
+ QFETCH(QString, expectfile);
+
+ QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml");
+
+ canvas->show();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+ QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas));
+
+ QObject *ob = canvas->rootObject();
+ QVERIFY(ob != 0);
+ ob->setProperty("horizontalAlignment",hAlign);
+ ob->setProperty("verticalAlignment",vAlign);
+ QTRY_COMPARE(ob->property("running").toBool(),false);
+ QImage actual(canvas->width(), canvas->height(), QImage::Format_RGB32);
+ actual.fill(qRgb(255,255,255));
+ QPainter p(&actual);
+ canvas->render(&p);
+
+ QImage expect(expectfile);
+
+#ifdef Q_OS_LINUX
+ // Font-specific, but not likely platform-specific, so only test on one platform
+ QCOMPARE(actual,expect);
+#endif
+}
+
//the alignment tests may be trivial o.oa
void tst_qdeclarativetext::horizontalAlignment()
{