All QWindow properties that have "window" in them have been renamed.
[profile/ivi/qtdeclarative.git] / tests / auto / quick / qquicktext / tst_qquicktext.cpp
index 57ba6ce..c5ffe7d 100644 (file)
@@ -1,38 +1,38 @@
 /****************************************************************************
 **
-** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
 **
 ** This file is part of the test suite of the Qt Toolkit.
 **
 ** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.  For licensing terms and
+** conditions see http://qt.digia.com/licensing.  For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
 ** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 **
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
+** In addition, as a special exception, Digia gives you certain additional
+** rights.  These rights are described in the Digia Qt LGPL Exception
 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 **
 ** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
 **
 **
 ** $QT_END_LICENSE$
@@ -83,9 +83,6 @@ private slots:
     void implicitElide();
     void textFormat();
 
-    void alignments_data();
-    void alignments();
-
     void baseUrl();
     void embeddedImages_data();
     void embeddedImages();
@@ -102,6 +99,7 @@ private slots:
     void style();
     void color();
     void smooth();
+    void renderType();
 
     // QQuickFontValueType
     void weight();
@@ -437,6 +435,29 @@ void tst_qquicktext::wrap()
 
         delete textObject;
     }
+
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n Text {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickText *textObject = qobject_cast<QQuickText *>(object.data());
+        QVERIFY(textObject);
+
+        QSignalSpy spy(textObject, SIGNAL(wrapModeChanged()));
+
+        QCOMPARE(textObject->wrapMode(), QQuickText::NoWrap);
+
+        textObject->setWrapMode(QQuickText::Wrap);
+        QCOMPARE(textObject->wrapMode(), QQuickText::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        textObject->setWrapMode(QQuickText::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        textObject->setWrapMode(QQuickText::NoWrap);
+        QCOMPARE(textObject->wrapMode(), QQuickText::NoWrap);
+        QCOMPARE(spy.count(), 2);
+    }
 }
 
 void tst_qquicktext::elide()
@@ -640,59 +661,29 @@ void tst_qquicktext::textFormat()
 
         delete textObject;
     }
-}
-
-
-void tst_qquicktext::alignments_data()
-{
-    QTest::addColumn<int>("hAlign");
-    QTest::addColumn<int>("vAlign");
-    QTest::addColumn<QString>("expectfile");
 
-    QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << testFile("alignments_lt.png");
-    QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << testFile("alignments_rt.png");
-    QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << testFile("alignments_ct.png");
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n Text {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickText *text = qobject_cast<QQuickText *>(object.data());
+        QVERIFY(text);
 
-    QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << testFile("alignments_lb.png");
-    QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << testFile("alignments_rb.png");
-    QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << testFile("alignments_cb.png");
+        QSignalSpy spy(text, SIGNAL(textFormatChanged(TextFormat)));
 
-    QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << testFile("alignments_lc.png");
-    QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << testFile("alignments_rc.png");
-    QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << testFile("alignments_cc.png");
-}
+        QCOMPARE(text->textFormat(), QQuickText::AutoText);
 
+        text->setTextFormat(QQuickText::StyledText);
+        QCOMPARE(text->textFormat(), QQuickText::StyledText);
+        QCOMPARE(spy.count(), 1);
 
-void tst_qquicktext::alignments()
-{
-    QSKIP("Text alignment pixmap comparison tests will not work with scenegraph");
-#if (0)// No widgets in scenegraph
-    QFETCH(int, hAlign);
-    QFETCH(int, vAlign);
-    QFETCH(QString, expectfile);
+        text->setTextFormat(QQuickText::StyledText);
+        QCOMPARE(spy.count(), 1);
 
-    QQuickView *window = createView(testFile("alignments.qml"));
-    window->show();
-    window->requestActivateWindow();
-    QTest::qWait(50);
-    QTRY_COMPARE(QGuiApplication::activeWindow(), static_cast<QWidget *>(window));
-
-    QObject *ob = window->rootObject();
-    QVERIFY(ob != 0);
-    ob->setProperty("horizontalAlignment",hAlign);
-    ob->setProperty("verticalAlignment",vAlign);
-    QTRY_COMPARE(ob->property("running").toBool(),false);
-    QImage actual(window->width(), window->height(), QImage::Format_RGB32);
-    actual.fill(qRgb(255,255,255));
-    QPainter p(&actual);
-    window->render(&p);
-
-    QImage expect(expectfile);
-    if (QGuiApplicationPrivate::graphics_system_name == "raster" || QGuiApplicationPrivate::graphics_system_name == "") {
-        QCOMPARE(actual,expect);
+        text->setTextFormat(QQuickText::AutoText);
+        QCOMPARE(text->textFormat(), QQuickText::AutoText);
+        QCOMPARE(spy.count(), 2);
     }
-    delete window;
-#endif
 }
 
 //the alignment tests may be trivial o.oa
@@ -865,8 +856,8 @@ void tst_qquicktext::hAlignImplicitWidth()
 {
     QQuickView view(testFileUrl("hAlignImplicitWidth.qml"));
     view.show();
-    view.requestActivateWindow();
-    QTest::qWaitForWindowShown(&view);
+    view.requestActivate();
+    QVERIFY(QTest::qWaitForWindowActive(&view));
 
     QQuickText *text = view.rootObject()->findChild<QQuickText*>("textItem");
     QVERIFY(text != 0);
@@ -1077,6 +1068,31 @@ void tst_qquicktext::color()
         QCOMPARE(textObject->color(), QColor("black"));
         QCOMPARE(textObject->linkColor(), QColor("blue"));
 
+        QSignalSpy colorSpy(textObject, SIGNAL(colorChanged()));
+        QSignalSpy linkColorSpy(textObject, SIGNAL(linkColorChanged()));
+
+        textObject->setColor(QColor("white"));
+        QCOMPARE(textObject->color(), QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textObject->setLinkColor(QColor("black"));
+        QCOMPARE(textObject->linkColor(), QColor("black"));
+        QCOMPARE(linkColorSpy.count(), 1);
+
+        textObject->setColor(QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textObject->setLinkColor(QColor("black"));
+        QCOMPARE(linkColorSpy.count(), 1);
+
+        textObject->setColor(QColor("black"));
+        QCOMPARE(textObject->color(), QColor("black"));
+        QCOMPARE(colorSpy.count(), 2);
+
+        textObject->setLinkColor(QColor("blue"));
+        QCOMPARE(textObject->linkColor(), QColor("blue"));
+        QCOMPARE(linkColorSpy.count(), 2);
+
         delete textObject;
     }
 
@@ -1239,6 +1255,30 @@ void tst_qquicktext::smooth()
     }
 }
 
+void tst_qquicktext::renderType()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n Text {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickText *text = qobject_cast<QQuickText *>(object.data());
+    QVERIFY(text);
+
+    QSignalSpy spy(text, SIGNAL(renderTypeChanged()));
+
+    QCOMPARE(text->renderType(), QQuickText::QtRendering);
+
+    text->setRenderType(QQuickText::NativeRendering);
+    QCOMPARE(text->renderType(), QQuickText::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    text->setRenderType(QQuickText::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    text->setRenderType(QQuickText::QtRendering);
+    QCOMPARE(text->renderType(), QQuickText::QtRendering);
+    QCOMPARE(spy.count(), 2);
+}
+
 void tst_qquicktext::weight()
 {
     {
@@ -1269,8 +1309,8 @@ void tst_qquicktext::underline()
 {
     QQuickView view(testFileUrl("underline.qml"));
     view.show();
-    view.requestActivateWindow();
-    QTest::qWaitForWindowShown(&view);
+    view.requestActivate();
+    QVERIFY(QTest::qWaitForWindowActive(&view));
     QQuickText *textObject = view.rootObject()->findChild<QQuickText*>("myText");
     QVERIFY(textObject != 0);
     QCOMPARE(textObject->font().overline(), false);
@@ -1282,8 +1322,8 @@ void tst_qquicktext::overline()
 {
     QQuickView view(testFileUrl("overline.qml"));
     view.show();
-    view.requestActivateWindow();
-    QTest::qWaitForWindowShown(&view);
+    view.requestActivate();
+    QVERIFY(QTest::qWaitForWindowActive(&view));
     QQuickText *textObject = view.rootObject()->findChild<QQuickText*>("myText");
     QVERIFY(textObject != 0);
     QCOMPARE(textObject->font().overline(), true);
@@ -1295,8 +1335,8 @@ void tst_qquicktext::strikeout()
 {
     QQuickView view(testFileUrl("strikeout.qml"));
     view.show();
-    view.requestActivateWindow();
-    QTest::qWaitForWindowShown(&view);
+    view.requestActivate();
+    QVERIFY(QTest::qWaitForWindowActive(&view));
     QQuickText *textObject = view.rootObject()->findChild<QQuickText*>("myText");
     QVERIFY(textObject != 0);
     QCOMPARE(textObject->font().overline(), false);
@@ -1437,9 +1477,6 @@ void tst_qquicktext::wordSpacing()
     }
 }
 
-
-
-
 class EventSender : public QQuickItem
 {
 public:
@@ -1857,7 +1894,7 @@ void tst_qquicktext::embeddedImages()
 
     QQuickView *view = new QQuickView(qmlfile);
     view->show();
-    view->requestActivateWindow();
+    view->requestActivate();
     QVERIFY(QTest::qWaitForWindowActive(view));
     QQuickText *textObject = qobject_cast<QQuickText*>(view->rootObject());
 
@@ -2469,7 +2506,7 @@ void tst_qquicktext::lineLaidOutRelayout()
     QQuickView *window = createView(testFile("lineLayoutRelayout.qml"));
 
     window->show();
-    window->requestActivateWindow();
+    window->requestActivate();
     QVERIFY(QTest::qWaitForWindowActive(window));
 
     QQuickText *myText = window->rootObject()->findChild<QQuickText*>("myText");
@@ -3574,7 +3611,7 @@ void tst_qquicktext::htmlLists()
     textObject->setText(text);
 
     view->show();
-    view->requestActivateWindow();
+    view->requestActivate();
     QVERIFY(QTest::qWaitForWindowActive(view));
 
     QCOMPARE(textPrivate->extra->doc->lineCount(), nbLines);