aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktext
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2012-03-27 16:43:26 +0200
committerKent Hansen <kent.hansen@nokia.com>2012-03-27 16:56:14 +0200
commit24fb8dc27eddfdd62bd2c3a6e863cbf433762cd6 (patch)
tree917eff8c50fe4699547b9de852ee53257c1585cf /tests/auto/quick/qquicktext
parent3e6a8eca00334df344a45f09afbcf8fd8e2b7c54 (diff)
parentffdbf216dc80b3d781307bb6b4b7150281c874a3 (diff)
Merge master into api_changes
Conflicts: src/qml/debugger/qqmlenginedebugservice.cpp src/qml/debugger/qqmlprofilerservice_p.h src/qml/qml/qqmlboundsignal.cpp src/qml/qml/qqmlpropertycache.cpp src/quick/util/qquickimageprovider.cpp Change-Id: I0609aa5ed54c7769f1e2773a96a7cd43a69f133c
Diffstat (limited to 'tests/auto/quick/qquicktext')
-rw-r--r--tests/auto/quick/qquicktext/qquicktext.pro2
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp76
2 files changed, 76 insertions, 2 deletions
diff --git a/tests/auto/quick/qquicktext/qquicktext.pro b/tests/auto/quick/qquicktext/qquicktext.pro
index daa7bed97b..8932664fa3 100644
--- a/tests/auto/quick/qquicktext/qquicktext.pro
+++ b/tests/auto/quick/qquicktext/qquicktext.pro
@@ -15,5 +15,3 @@ TESTDATA = data/*
CONFIG += parallel_test
QT += core-private gui-private v8-private qml-private quick-private network testlib
-
-win32:CONFIG += insignificant_test # QTBUG-24789
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index affb355837..f4ba0864e5 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -110,6 +110,8 @@ private slots:
void implicitSizeBinding_data();
void implicitSizeBinding();
+ void boundingRect_data();
+ void boundingRect();
void lineLaidOut();
void imgTagsBaseUrl_data();
@@ -1669,6 +1671,80 @@ void tst_qquicktext::implicitSizeBinding()
QCOMPARE(textObject->height(), textObject->implicitHeight());
}
+void tst_qquicktext::boundingRect_data()
+{
+ QTest::addColumn<QString>("format");
+ QTest::newRow("PlainText") << "Text.PlainText";
+ QTest::newRow("StyledText") << "Text.StyledText";
+ QTest::newRow("RichText") << "Text.RichText";
+}
+
+void tst_qquicktext::boundingRect()
+{
+ QFETCH(QString, format);
+
+ QDeclarativeComponent component(&engine);
+ component.setData("import QtQuick 2.0\n Text { textFormat:" + format.toUtf8() + "}", QUrl());
+ QScopedPointer<QObject> object(component.create());
+ QQuickText *text = qobject_cast<QQuickText *>(object.data());
+ QVERIFY(text);
+
+ QCOMPARE(text->boundingRect().x(), qreal(0));
+ QCOMPARE(text->boundingRect().y(), qreal(0));
+ QCOMPARE(text->boundingRect().width(), qreal(0));
+ QCOMPARE(text->boundingRect().height(), QFontMetricsF(text->font()).height());
+
+ text->setText("Hello World");
+
+ QTextLayout layout(text->text());
+ layout.setFont(text->font());
+
+ if (!qmlDisableDistanceField()) {
+ QTextOption option;
+ option.setUseDesignMetrics(true);
+ layout.setTextOption(option);
+ }
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ layout.endLayout();
+
+ QCOMPARE(text->boundingRect().x(), qreal(0));
+ QCOMPARE(text->boundingRect().y(), qreal(0));
+ QCOMPARE(text->boundingRect().width(), line.naturalTextWidth());
+ QCOMPARE(text->boundingRect().height(), line.height());
+
+ // the size of the bounding rect shouldn't be bounded by the size of item.
+ text->setWidth(text->width() / 2);
+ QCOMPARE(text->boundingRect().x(), qreal(0));
+ QCOMPARE(text->boundingRect().y(), qreal(0));
+ QCOMPARE(text->boundingRect().width(), line.naturalTextWidth());
+ QCOMPARE(text->boundingRect().height(), line.height());
+
+ text->setHeight(text->height() * 2);
+ QCOMPARE(text->boundingRect().x(), qreal(0));
+ QCOMPARE(text->boundingRect().y(), qreal(0));
+ QCOMPARE(text->boundingRect().width(), line.naturalTextWidth());
+ QCOMPARE(text->boundingRect().height(), line.height());
+
+ text->setHAlign(QQuickText::AlignRight);
+ QCOMPARE(text->boundingRect().x(), text->width() - line.naturalTextWidth());
+ QCOMPARE(text->boundingRect().y(), qreal(0));
+ QCOMPARE(text->boundingRect().width(), line.naturalTextWidth());
+ QCOMPARE(text->boundingRect().height(), line.height());
+
+ text->setWrapMode(QQuickText::Wrap);
+ QCOMPARE(text->boundingRect().right(), text->width());
+ QCOMPARE(text->boundingRect().y(), qreal(0));
+ QVERIFY(text->boundingRect().width() < line.naturalTextWidth());
+ QVERIFY(text->boundingRect().height() > line.height());
+
+ text->setVAlign(QQuickText::AlignBottom);
+ QCOMPARE(text->boundingRect().right(), text->width());
+ QCOMPARE(text->boundingRect().bottom(), text->height());
+ QVERIFY(text->boundingRect().width() < line.naturalTextWidth());
+ QVERIFY(text->boundingRect().height() > line.height());
+}
+
void tst_qquicktext::lineLaidOut()
{
QQuickView *canvas = createView(testFile("lineLayout.qml"));