aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp7
-rw-r--r--tests/auto/qtquick2/qquicktext/data/images/face-sad.pngbin0 -> 6148 bytes
-rw-r--r--tests/auto/qtquick2/qquicktext/data/images/heart200.pngbin0 -> 8248 bytes
-rw-r--r--tests/auto/qtquick2/qquicktext/data/images/starfish_2.pngbin0 -> 18243 bytes
-rw-r--r--tests/auto/qtquick2/qquicktext/data/imgTagsElide.qml24
-rw-r--r--tests/auto/qtquick2/qquicktext/data/imgTagsUpdates.qml12
-rw-r--r--tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp120
7 files changed, 161 insertions, 2 deletions
diff --git a/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp b/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp
index 46acbb2db3..b4e0ba1b7a 100644
--- a/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp
+++ b/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp
@@ -41,7 +41,8 @@
#include <qtest.h>
#include <QtTest/QtTest>
#include <QtGui/QTextLayout>
-#include <private/qdeclarativestyledtext_p.h>
+#include <QtCore/QList>
+#include <QtQuick/private/qdeclarativestyledtext_p.h>
class tst_qdeclarativestyledtext : public QObject
{
@@ -148,6 +149,7 @@ void tst_qdeclarativestyledtext::textOutput_data()
QTest::newRow("space before bold") << "this is <b>bold</b>" << "this is bold" << (FormatList() << Format(Format::Bold, 8, 4));
QTest::newRow("space leading bold") << "this is<b> bold</b>" << "this is bold" << (FormatList() << Format(Format::Bold, 7, 5));
QTest::newRow("space trailing bold") << "this is <b>bold </b>" << "this is bold " << (FormatList() << Format(Format::Bold, 8, 5));
+ QTest::newRow("img") << "a<img src=\"blah.png\"/>b" << "a b" << FormatList();
}
void tst_qdeclarativestyledtext::textOutput()
@@ -157,7 +159,8 @@ void tst_qdeclarativestyledtext::textOutput()
QFETCH(FormatList, formats);
QTextLayout layout;
- QDeclarativeStyledText::parse(input, layout);
+ QList<QDeclarativeStyledTextImgTag*> imgTags;
+ QDeclarativeStyledText::parse(input, layout, imgTags, 0, false);
QCOMPARE(layout.text(), output);
diff --git a/tests/auto/qtquick2/qquicktext/data/images/face-sad.png b/tests/auto/qtquick2/qquicktext/data/images/face-sad.png
new file mode 100644
index 0000000000..24188b7985
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/images/face-sad.png
Binary files differ
diff --git a/tests/auto/qtquick2/qquicktext/data/images/heart200.png b/tests/auto/qtquick2/qquicktext/data/images/heart200.png
new file mode 100644
index 0000000000..cedd3ea608
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/images/heart200.png
Binary files differ
diff --git a/tests/auto/qtquick2/qquicktext/data/images/starfish_2.png b/tests/auto/qtquick2/qquicktext/data/images/starfish_2.png
new file mode 100644
index 0000000000..132c20ffd0
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/images/starfish_2.png
Binary files differ
diff --git a/tests/auto/qtquick2/qquicktext/data/imgTagsElide.qml b/tests/auto/qtquick2/qquicktext/data/imgTagsElide.qml
new file mode 100644
index 0000000000..fbd64cc5bf
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/imgTagsElide.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+
+Item {
+ width: 300
+ height: 200
+
+ Text {
+ id: myText
+ objectName: "myText"
+ elide: Text.ElideRight
+ maximumLineCount: 2
+ width: 200
+ wrapMode: Text.WordWrap
+ text: "This is a sad face aligned to the top. Lorem ipsum dolor sit amet. Nulla sed turpis risus. Integer sit amet odio quis mauris varius venenatis<img src=\"images/face-sad.png\" width=\"30\" height=\"30\" align=\"top\">Lorem ipsum dolor sit amet. Nulla sed turpis risus. Integer sit amet odio quis mauris varius venenatis. Lorem ipsum dolor sit amet. Nulla sed turpis risus.Lorem ipsum dolor sit amet. Nulla sed turpis risus. Lorem ipsum dolor sit amet. Nulla sed turpis risus.Lorem ipsum dolor sit amet. Nulla sed turpis risus."
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: myText.width = 400
+
+ }
+}
+
+
diff --git a/tests/auto/qtquick2/qquicktext/data/imgTagsUpdates.qml b/tests/auto/qtquick2/qquicktext/data/imgTagsUpdates.qml
new file mode 100644
index 0000000000..baf5113e52
--- /dev/null
+++ b/tests/auto/qtquick2/qquicktext/data/imgTagsUpdates.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+
+Rectangle {
+ id: main
+ width: 300; height: 400
+
+ Text {
+ id: myText
+ objectName: "myText"
+ text: ""
+ }
+}
diff --git a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
index 706276c52f..cac65196eb 100644
--- a/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/qtquick2/qquicktext/tst_qquicktext.cpp
@@ -107,6 +107,12 @@ private slots:
void lineLaidOut();
+ void imgTagsAlign_data();
+ void imgTagsAlign();
+ void imgTagsMultipleImages();
+ void imgTagsElide();
+ void imgTagsUpdates();
+ void imgTagsError();
private:
QStringList standard;
@@ -1478,6 +1484,120 @@ void tst_qquicktext::lineLaidOut()
delete canvas;
}
+void tst_qquicktext::imgTagsAlign_data()
+{
+ QTest::addColumn<QString>("src");
+ QTest::addColumn<int>("imgHeight");
+ QTest::addColumn<QString>("align");
+ QTest::newRow("heart-bottom") << "data/images/heart200.png" << 181 << "bottom";
+ QTest::newRow("heart-middle") << "data/images/heart200.png" << 181 << "middle";
+ QTest::newRow("heart-top") << "data/images/heart200.png" << 181 << "top";
+ QTest::newRow("starfish-bottom") << "data/images/starfish_2.png" << 217 << "bottom";
+ QTest::newRow("starfish-middle") << "data/images/starfish_2.png" << 217 << "middle";
+ QTest::newRow("starfish-top") << "data/images/starfish_2.png" << 217 << "top";
+}
+
+void tst_qquicktext::imgTagsAlign()
+{
+ QFETCH(QString, src);
+ QFETCH(int, imgHeight);
+ QFETCH(QString, align);
+ QString componentStr = "import QtQuick 2.0\nText { text: \"This is a test <img src=\\\"" + src + "\\\" align=\\\"" + align + "\\\"> of image.\" }";
+ QDeclarativeComponent textComponent(&engine);
+ textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->height() == imgHeight);
+
+ QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject);
+ QVERIFY(textPrivate != 0);
+
+ QRectF br = textPrivate->layout.boundingRect();
+ if (align == "bottom")
+ QVERIFY(br.y() == imgHeight - br.height());
+ else if (align == "middle")
+ QVERIFY(br.y() == imgHeight / 2.0 - br.height() / 2.0);
+ else if (align == "top")
+ QVERIFY(br.y() == 0);
+
+ delete textObject;
+}
+
+void tst_qquicktext::imgTagsMultipleImages()
+{
+ QString componentStr = "import QtQuick 2.0\nText { text: \"This is a starfish<img src=\\\"data/images/starfish_2.png\\\" width=\\\"60\\\" height=\\\"60\\\" > and another one<img src=\\\"data/images/heart200.png\\\" width=\\\"85\\\" height=\\\"85\\\">.\" }";
+
+ QDeclarativeComponent textComponent(&engine);
+ textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->height() == 85);
+
+ QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject);
+ QVERIFY(textPrivate != 0);
+ QVERIFY(textPrivate->visibleImgTags.count() == 2);
+
+ delete textObject;
+}
+
+void tst_qquicktext::imgTagsElide()
+{
+ QQuickView *canvas = createView(testFile("imgTagsElide.qml"));
+ QQuickText *myText = canvas->rootObject()->findChild<QQuickText*>("myText");
+ QVERIFY(myText != 0);
+
+ QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(myText);
+ QVERIFY(textPrivate != 0);
+ QVERIFY(textPrivate->visibleImgTags.count() == 0);
+ myText->setMaximumLineCount(20);
+ QTRY_VERIFY(textPrivate->visibleImgTags.count() == 1);
+
+ delete myText;
+ delete canvas;
+}
+
+void tst_qquicktext::imgTagsUpdates()
+{
+ QQuickView *canvas = createView(testFile("imgTagsUpdates.qml"));
+ QQuickText *myText = canvas->rootObject()->findChild<QQuickText*>("myText");
+ QVERIFY(myText != 0);
+
+ QSignalSpy spy(myText, SIGNAL(paintedSizeChanged()));
+
+ QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(myText);
+ QVERIFY(textPrivate != 0);
+
+ myText->setText("This is a heart<img src=\"images/heart200.png\">.");
+ QVERIFY(textPrivate->visibleImgTags.count() == 1);
+ QVERIFY(spy.count() == 1);
+
+ myText->setMaximumLineCount(2);
+ myText->setText("This is another heart<img src=\"images/heart200.png\">.");
+ QTRY_VERIFY(textPrivate->visibleImgTags.count() == 1);
+
+ // if maximumLineCount is set and the img tag doesn't have an explicit size
+ // we relayout twice.
+ QVERIFY(spy.count() == 3);
+
+ delete myText;
+ delete canvas;
+}
+
+void tst_qquicktext::imgTagsError()
+{
+ QString componentStr = "import QtQuick 2.0\nText { text: \"This is a starfish<img src=\\\"data/images/starfish_2.pn\\\" width=\\\"60\\\" height=\\\"60\\\">.\" }";
+
+ QDeclarativeComponent textComponent(&engine);
+ QTest::ignoreMessage(QtWarningMsg, "file::2:1: QML Text: Cannot open: file:data/images/starfish_2.pn");
+ textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ delete textObject;
+}
+
QTEST_MAIN(tst_qquicktext)
#include "tst_qquicktext.moc"