tst_qquicktext.cpp 96.8 KB
Newer Older
1 2
/****************************************************************************
**
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/
5 6 7 8 9
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
10 11 12 13 14 15
** 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.
16 17
**
** In addition, as a special exception, Nokia gives you certain additional
18
** rights. These rights are described in the Nokia Qt LGPL Exception
19 20
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
21 22 23 24 25 26 27 28 29 30 31
** 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.
32 33 34 35 36
**
**
**
**
**
37
**
38 39 40 41
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qtest.h>
42
#include <QtTest/QSignalSpy>
43
#include <QTextDocument>
44 45
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlcomponent.h>
46
#include <QtQuick/private/qquicktext_p.h>
47
#include <private/qquicktext_p_p.h>
48
#include <private/qqmlvaluetype_p.h>
49 50
#include <QFontMetrics>
#include <qmath.h>
51
#include <QtQuick/QQuickView>
52
#include <private/qguiapplication_p.h>
53
#include <limits.h>
54
#include <QtGui/QMouseEvent>
55
#include "../../shared/util.h"
56 57
#include "testhttpserver.h"

58 59
DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)

60 61
Q_DECLARE_METATYPE(QQuickText::TextFormat)

62
class tst_qquicktext : public QQmlDataTest
63 64 65
{
    Q_OBJECT
public:
66
    tst_qquicktext();
67 68 69 70 71 72

private slots:
    void text();
    void width();
    void wrap();
    void elide();
73
    void multilineElide_data();
74
    void multilineElide();
75 76 77 78 79
    void textFormat();

    void alignments_data();
    void alignments();

80
    void baseUrl();
81 82 83 84 85 86
    void embeddedImages_data();
    void embeddedImages();

    void lineCount();
    void lineHeight();

Kent Hansen's avatar
Kent Hansen committed
87
    // ### these tests may be trivial
88 89 90 91 92 93 94 95
    void horizontalAlignment();
    void horizontalAlignment_RightToLeft();
    void verticalAlignment();
    void font();
    void style();
    void color();
    void smooth();

96
    // QQmlFontValueType
97 98 99 100 101 102 103 104 105 106 107 108
    void weight();
    void underline();
    void overline();
    void strikeout();
    void capitalization();
    void letterSpacing();
    void wordSpacing();

    void clickLink();

    void implicitSize_data();
    void implicitSize();
109
    void contentSize();
110 111
    void implicitSizeBinding_data();
    void implicitSizeBinding();
112

113 114
    void lineLaidOut();

115 116
    void imgTagsBaseUrl_data();
    void imgTagsBaseUrl();
117 118 119 120 121 122
    void imgTagsAlign_data();
    void imgTagsAlign();
    void imgTagsMultipleImages();
    void imgTagsElide();
    void imgTagsUpdates();
    void imgTagsError();
123 124 125 126
    void fontSizeMode_data();
    void fontSizeMode();
    void fontSizeModeMultiline_data();
    void fontSizeModeMultiline();
127 128
    void multilengthStrings_data();
    void multilengthStrings();
129 130
    void fontFormatSizes_data();
    void fontFormatSizes();
131

132 133 134 135 136 137 138 139 140 141 142
private:
    QStringList standard;
    QStringList richText;

    QStringList horizontalAlignmentmentStrings;
    QStringList verticalAlignmentmentStrings;

    QList<Qt::Alignment> verticalAlignmentments;
    QList<Qt::Alignment> horizontalAlignmentments;

    QStringList styleStrings;
143
    QList<QQuickText::TextStyle> styles;
144 145 146

    QStringList colorStrings;

147
    QQmlEngine engine;
148

149
    QQuickView *createView(const QString &filename);
150
};
151

152
tst_qquicktext::tst_qquicktext()
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
{
    standard << "the quick brown fox jumped over the lazy dog"
            << "the quick brown fox\n jumped over the lazy dog";

    richText << "<i>the <b>quick</b> brown <a href=\\\"http://www.google.com\\\">fox</a> jumped over the <b>lazy</b> dog</i>"
            << "<i>the <b>quick</b> brown <a href=\\\"http://www.google.com\\\">fox</a><br>jumped over the <b>lazy</b> dog</i>";

    horizontalAlignmentmentStrings << "AlignLeft"
            << "AlignRight"
            << "AlignHCenter";

    verticalAlignmentmentStrings << "AlignTop"
            << "AlignBottom"
            << "AlignVCenter";

    horizontalAlignmentments << Qt::AlignLeft
            << Qt::AlignRight
            << Qt::AlignHCenter;

    verticalAlignmentments << Qt::AlignTop
            << Qt::AlignBottom
            << Qt::AlignVCenter;

    styleStrings << "Normal"
            << "Outline"
            << "Raised"
            << "Sunken";

181 182 183 184
    styles << QQuickText::Normal
            << QQuickText::Outline
            << QQuickText::Raised
            << QQuickText::Sunken;
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

    colorStrings << "aliceblue"
            << "antiquewhite"
            << "aqua"
            << "darkkhaki"
            << "darkolivegreen"
            << "dimgray"
            << "palevioletred"
            << "lightsteelblue"
            << "#000000"
            << "#AAAAAA"
            << "#FFFFFF"
            << "#2AC05F";
    //
    // need a different test to do alpha channel test
    // << "#AA0011DD"
    // << "#00F16B11";
    //
}

205
QQuickView *tst_qquicktext::createView(const QString &filename)
206
{
207
    QQuickView *canvas = new QQuickView(0);
208 209 210 211 212

    canvas->setSource(QUrl::fromLocalFile(filename));
    return canvas;
}

213
void tst_qquicktext::text()
214 215
{
    {
216
        QQmlComponent textComponent(&engine);
217
        textComponent.setData("import QtQuick 2.0\nText { text: \"\" }", QUrl::fromLocalFile(""));
218
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
219 220 221 222 223 224 225 226 227 228 229

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->text(), QString(""));
        QVERIFY(textObject->width() == 0);

        delete textObject;
    }

    for (int i = 0; i < standard.size(); i++)
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"" + standard.at(i) + "\" }";
230
        QQmlComponent textComponent(&engine);
231 232
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));

233
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
234 235 236 237 238 239 240 241 242 243 244

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->text(), standard.at(i));
        QVERIFY(textObject->width() > 0);

        delete textObject;
    }

    for (int i = 0; i < richText.size(); i++)
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"" + richText.at(i) + "\" }";
245
        QQmlComponent textComponent(&engine);
246
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
247
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
248 249 250 251 252 253 254 255 256 257

        QVERIFY(textObject != 0);
        QString expected = richText.at(i);
        QCOMPARE(textObject->text(), expected.replace("\\\"", "\""));
        QVERIFY(textObject->width() > 0);

        delete textObject;
    }
}

258
void tst_qquicktext::width()
259 260 261
{
    // uses Font metrics to find the width for standard and document to find the width for rich
    {
262
        QQmlComponent textComponent(&engine);
263
        textComponent.setData("import QtQuick 2.0\nText { text: \"\" }", QUrl::fromLocalFile(""));
264
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
265 266 267 268 269 270 271

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->width(), 0.);

        delete textObject;
    }

272 273
    bool requiresUnhintedMetrics = !qmlDisableDistanceField();

274 275 276 277 278
    for (int i = 0; i < standard.size(); i++)
    {
        QVERIFY(!Qt::mightBeRichText(standard.at(i))); // self-test

        QFont f;
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
        qreal metricWidth = 0.0;

        if (requiresUnhintedMetrics) {
            QString s = standard.at(i);
            s.replace(QLatin1Char('\n'), QChar::LineSeparator);

            QTextLayout layout(s);
            layout.setFlags(Qt::TextExpandTabs | Qt::TextShowMnemonic);
            {
                QTextOption option;
                option.setUseDesignMetrics(true);
                layout.setTextOption(option);
            }

            layout.beginLayout();
            forever {
                QTextLine line = layout.createLine();
                if (!line.isValid())
                    break;
            }

            layout.endLayout();

302
            metricWidth = layout.boundingRect().width();
303 304
        } else {
            QFontMetricsF fm(f);
305
            metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width();
306
        }
307 308

        QString componentStr = "import QtQuick 2.0\nText { text: \"" + standard.at(i) + "\" }";
309
        QQmlComponent textComponent(&engine);
310
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
311
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
312 313 314 315

        QVERIFY(textObject != 0);
        QVERIFY(textObject->boundingRect().width() > 0);
        QCOMPARE(textObject->width(), qreal(metricWidth));
316
        QVERIFY(textObject->textFormat() == QQuickText::AutoText); // setting text doesn't change format
317 318 319 320 321 322 323 324

        delete textObject;
    }

    for (int i = 0; i < richText.size(); i++)
    {
        QVERIFY(Qt::mightBeRichText(richText.at(i))); // self-test

325
        QString componentStr = "import QtQuick 2.0\nText { text: \"" + richText.at(i) + "\"; textFormat: Text.RichText }";
326
        QQmlComponent textComponent(&engine);
327
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
328
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
329
        QVERIFY(textObject != 0);
Yann Bodson's avatar
Yann Bodson committed
330

331
        QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject);
Yann Bodson's avatar
Yann Bodson committed
332
        QVERIFY(textPrivate != 0);
333
        QVERIFY(textPrivate->extra.isAllocated());
Yann Bodson's avatar
Yann Bodson committed
334

335
        QTextDocument *doc = textPrivate->extra->doc;
Yann Bodson's avatar
Yann Bodson committed
336 337 338
        QVERIFY(doc != 0);

        QCOMPARE(int(textObject->width()), int(doc->idealWidth()));
339
        QVERIFY(textObject->textFormat() == QQuickText::RichText);
340 341 342 343 344

        delete textObject;
    }
}

345
void tst_qquicktext::wrap()
346 347 348 349
{
    int textHeight = 0;
    // for specified width and wrap set true
    {
350
        QQmlComponent textComponent(&engine);
351
        textComponent.setData("import QtQuick 2.0\nText { text: \"Hello\"; wrapMode: Text.WordWrap; width: 300 }", QUrl::fromLocalFile(""));
352
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
353 354 355
        textHeight = textObject->height();

        QVERIFY(textObject != 0);
356
        QVERIFY(textObject->wrapMode() == QQuickText::WordWrap);
357 358 359 360 361 362 363 364
        QCOMPARE(textObject->width(), 300.);

        delete textObject;
    }

    for (int i = 0; i < standard.size(); i++)
    {
        QString componentStr = "import QtQuick 2.0\nText { wrapMode: Text.WordWrap; width: 30; text: \"" + standard.at(i) + "\" }";
365
        QQmlComponent textComponent(&engine);
366
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
367
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->width(), 30.);
        QVERIFY(textObject->height() > textHeight);

        int oldHeight = textObject->height();
        textObject->setWidth(100);
        QVERIFY(textObject->height() < oldHeight);

        delete textObject;
    }

    for (int i = 0; i < richText.size(); i++)
    {
        QString componentStr = "import QtQuick 2.0\nText { wrapMode: Text.WordWrap; width: 30; text: \"" + richText.at(i) + "\" }";
383
        QQmlComponent textComponent(&engine);
384
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
385
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->width(), 30.);
        QVERIFY(textObject->height() > textHeight);

        qreal oldHeight = textObject->height();
        textObject->setWidth(100);
        QVERIFY(textObject->height() < oldHeight);

        delete textObject;
    }

    // richtext again with a fixed height
    for (int i = 0; i < richText.size(); i++)
    {
        QString componentStr = "import QtQuick 2.0\nText { wrapMode: Text.WordWrap; width: 30; height: 50; text: \"" + richText.at(i) + "\" }";
402
        QQmlComponent textComponent(&engine);
403
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
404
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
405 406 407 408 409 410 411 412 413 414 415 416 417

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->width(), 30.);
        QVERIFY(textObject->implicitHeight() > textHeight);

        qreal oldHeight = textObject->implicitHeight();
        textObject->setWidth(100);
        QVERIFY(textObject->implicitHeight() < oldHeight);

        delete textObject;
    }
}

418
void tst_qquicktext::elide()
419
{
420
    for (QQuickText::TextElideMode m = QQuickText::ElideLeft; m<=QQuickText::ElideNone; m=QQuickText::TextElideMode(int(m)+1)) {
421 422 423 424 425 426
        const char* elidename[]={"ElideLeft", "ElideRight", "ElideMiddle", "ElideNone"};
        QString elide = "elide: Text." + QString(elidename[int(m)]) + ";";

        // XXX Poor coverage.

        {
427
            QQmlComponent textComponent(&engine);
428
            textComponent.setData(("import QtQuick 2.0\nText { text: \"\"; "+elide+" width: 100 }").toLatin1(), QUrl::fromLocalFile(""));
429
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
430 431 432 433 434 435 436 437 438 439

            QCOMPARE(textObject->elideMode(), m);
            QCOMPARE(textObject->width(), 100.);

            delete textObject;
        }

        for (int i = 0; i < standard.size(); i++)
        {
            QString componentStr = "import QtQuick 2.0\nText { "+elide+" width: 100; text: \"" + standard.at(i) + "\" }";
440
            QQmlComponent textComponent(&engine);
441
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
442
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
443 444 445 446

            QCOMPARE(textObject->elideMode(), m);
            QCOMPARE(textObject->width(), 100.);

447 448 449
            if (m != QQuickText::ElideNone && !standard.at(i).contains('\n'))
                QVERIFY(textObject->contentWidth() <= textObject->width());

450 451 452 453 454 455
            delete textObject;
        }

        for (int i = 0; i < richText.size(); i++)
        {
            QString componentStr = "import QtQuick 2.0\nText { "+elide+" width: 100; text: \"" + richText.at(i) + "\" }";
456
            QQmlComponent textComponent(&engine);
457
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
458
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
459 460 461 462

            QCOMPARE(textObject->elideMode(), m);
            QCOMPARE(textObject->width(), 100.);

463 464 465
            if (m != QQuickText::ElideNone && standard.at(i).contains("<br>"))
                QVERIFY(textObject->contentWidth() <= textObject->width());

466 467 468 469 470
            delete textObject;
        }
    }
}

471 472 473 474 475 476 477
void tst_qquicktext::multilineElide_data()
{
    QTest::addColumn<QQuickText::TextFormat>("format");
    QTest::newRow("plain") << QQuickText::PlainText;
    QTest::newRow("styled") << QQuickText::StyledText;
}

478 479
void tst_qquicktext::multilineElide()
{
480
    QFETCH(QQuickText::TextFormat, format);
481
    QQuickView *canvas = createView(testFile("multilineelide.qml"));
482 483 484

    QQuickText *myText = qobject_cast<QQuickText*>(canvas->rootObject());
    QVERIFY(myText != 0);
485
    myText->setTextFormat(format);
486 487 488 489

    QCOMPARE(myText->lineCount(), 3);
    QCOMPARE(myText->truncated(), true);

490
    qreal lineHeight = myText->contentHeight() / 3.;
491

492 493 494 495 496 497
    // Set a valid height greater than the truncated content height and ensure the line count is
    // unchanged.
    myText->setHeight(200);
    QCOMPARE(myText->lineCount(), 3);
    QCOMPARE(myText->truncated(), true);

498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528
    // reduce size and ensure fewer lines are drawn
    myText->setHeight(lineHeight * 2);
    QCOMPARE(myText->lineCount(), 2);

    myText->setHeight(lineHeight);
    QCOMPARE(myText->lineCount(), 1);

    myText->setHeight(5);
    QCOMPARE(myText->lineCount(), 1);

    myText->setHeight(lineHeight * 3);
    QCOMPARE(myText->lineCount(), 3);

    // remove max count and show all lines.
    myText->setHeight(1000);
    myText->resetMaximumLineCount();

    QCOMPARE(myText->truncated(), false);

    // reduce size again
    myText->setHeight(lineHeight * 2);
    QCOMPARE(myText->lineCount(), 2);
    QCOMPARE(myText->truncated(), true);

    // change line height
    myText->setLineHeight(1.1);
    QCOMPARE(myText->lineCount(), 1);

    delete canvas;
}

529
void tst_qquicktext::textFormat()
530 531
{
    {
532
        QQmlComponent textComponent(&engine);
533
        textComponent.setData("import QtQuick 2.0\nText { text: \"Hello\"; textFormat: Text.RichText }", QUrl::fromLocalFile(""));
534
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
535 536

        QVERIFY(textObject != 0);
537
        QVERIFY(textObject->textFormat() == QQuickText::RichText);
538

539
        QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject);
540 541 542 543 544 545
        QVERIFY(textPrivate != 0);
        QVERIFY(textPrivate->richText == true);

        delete textObject;
    }
    {
546
        QQmlComponent textComponent(&engine);
547
        textComponent.setData("import QtQuick 2.0\nText { text: \"<b>Hello</b>\" }", QUrl::fromLocalFile(""));
548
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
549 550

        QVERIFY(textObject != 0);
551
        QVERIFY(textObject->textFormat() == QQuickText::AutoText);
552

553
        QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject);
554 555 556
        QVERIFY(textPrivate != 0);
        QVERIFY(textPrivate->styledText == true);

557 558 559
        delete textObject;
    }
    {
560
        QQmlComponent textComponent(&engine);
561
        textComponent.setData("import QtQuick 2.0\nText { text: \"<b>Hello</b>\"; textFormat: Text.PlainText }", QUrl::fromLocalFile(""));
562
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
563 564

        QVERIFY(textObject != 0);
565
        QVERIFY(textObject->textFormat() == QQuickText::PlainText);
566 567 568 569 570 571

        delete textObject;
    }
}


572
void tst_qquicktext::alignments_data()
573 574 575 576 577
{
    QTest::addColumn<int>("hAlign");
    QTest::addColumn<int>("vAlign");
    QTest::addColumn<QString>("expectfile");

578 579 580
    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");
581

582 583 584
    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");
585

586 587 588
    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");
589 590 591
}


592
void tst_qquicktext::alignments()
593
{
594
    QSKIP("Text alignment pixmap comparison tests will not work with scenegraph");
595
#if (0)// No widgets in scenegraph
596 597 598 599
    QFETCH(int, hAlign);
    QFETCH(int, vAlign);
    QFETCH(QString, expectfile);

600
    QQuickView *canvas = createView(testFile("alignments.qml"));
601
    canvas->show();
602 603
    canvas->requestActivateWindow();
    QTest::qWait(50);
604
    QTRY_COMPARE(QGuiApplication::activeWindow(), static_cast<QWidget *>(canvas));
605 606 607 608 609 610 611 612 613 614 615 616

    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);
617
    if (QGuiApplicationPrivate::graphics_system_name == "raster" || QGuiApplicationPrivate::graphics_system_name == "") {
618 619 620
        QCOMPARE(actual,expect);
    }
    delete canvas;
621
#endif
622 623 624
}

//the alignment tests may be trivial o.oa
625
void tst_qquicktext::horizontalAlignment()
626 627 628 629 630 631 632 633
{
    //test one align each, and then test if two align fails.

    for (int i = 0; i < standard.size(); i++)
    {
        for (int j=0; j < horizontalAlignmentmentStrings.size(); j++)
        {
            QString componentStr = "import QtQuick 2.0\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }";
634
            QQmlComponent textComponent(&engine);
635
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
636
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
637 638 639 640 641 642 643 644 645 646 647 648

            QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j));

            delete textObject;
        }
    }

    for (int i = 0; i < richText.size(); i++)
    {
        for (int j=0; j < horizontalAlignmentmentStrings.size(); j++)
        {
            QString componentStr = "import QtQuick 2.0\nText { horizontalAlignment: \"" + horizontalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }";
649
            QQmlComponent textComponent(&engine);
650
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
651
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
652 653 654 655 656 657 658 659 660

            QCOMPARE((int)textObject->hAlign(), (int)horizontalAlignmentments.at(j));

            delete textObject;
        }
    }

}

661
void tst_qquicktext::horizontalAlignment_RightToLeft()
662
{
663
    QQuickView *canvas = createView(testFile("horizontalAlignment_RightToLeft.qml"));
664
    QQuickText *text = canvas->rootObject()->findChild<QQuickText*>("text");
665 666 667
    QVERIFY(text != 0);
    canvas->show();

668
    QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(text);
669 670
    QVERIFY(textPrivate != 0);

671 672
    QTRY_VERIFY(textPrivate->layout.lineCount());

673
    // implicit alignment should follow the reading direction of RTL text
674
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
675 676 677 678
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);

    // explicitly left aligned text
679 680
    text->setHAlign(QQuickText::AlignLeft);
    QCOMPARE(text->hAlign(), QQuickText::AlignLeft);
681 682 683 684
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2);

    // explicitly right aligned text
685 686
    text->setHAlign(QQuickText::AlignRight);
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
687 688 689 690 691 692
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);

    // change to rich text
    QString textString = text->text();
    text->setText(QString("<i>") + textString + QString("</i>"));
693
    text->setTextFormat(QQuickText::RichText);
694 695 696
    text->resetHAlign();

    // implicitly aligned rich text should follow the reading direction of text
697
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
698
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
699 700
    QVERIFY(textPrivate->extra.isAllocated());
    QVERIFY(textPrivate->extra->doc->defaultTextOption().alignment() & Qt::AlignLeft);
701 702

    // explicitly left aligned rich text
703 704
    text->setHAlign(QQuickText::AlignLeft);
    QCOMPARE(text->hAlign(), QQuickText::AlignLeft);
705
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
706
    QVERIFY(textPrivate->extra->doc->defaultTextOption().alignment() & Qt::AlignRight);
707 708

    // explicitly right aligned rich text
709 710
    text->setHAlign(QQuickText::AlignRight);
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
711
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
712
    QVERIFY(textPrivate->extra->doc->defaultTextOption().alignment() & Qt::AlignLeft);
713 714

    text->setText(textString);
715
    text->setTextFormat(QQuickText::PlainText);
716 717

    // explicitly center aligned
718 719
    text->setHAlign(QQuickText::AlignHCenter);
    QCOMPARE(text->hAlign(), QQuickText::AlignHCenter);
720 721 722 723 724 725
    QCOMPARE(text->effectiveHAlign(), text->hAlign());
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2);
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().right() > canvas->width()/2);

    // reseted alignment should go back to following the text reading direction
    text->resetHAlign();
726
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
727 728 729
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);

    // mirror the text item
730
    QQuickItemPrivate::get(text)->setLayoutMirror(true);
731 732

    // mirrored implicit alignment should continue to follow the reading direction of the text
733 734
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
    QCOMPARE(text->effectiveHAlign(), QQuickText::AlignRight);
735 736 737
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);

    // mirrored explicitly right aligned behaves as left aligned
738 739 740
    text->setHAlign(QQuickText::AlignRight);
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
    QCOMPARE(text->effectiveHAlign(), QQuickText::AlignLeft);
741 742 743
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2);

    // mirrored explicitly left aligned behaves as right aligned
744 745 746
    text->setHAlign(QQuickText::AlignLeft);
    QCOMPARE(text->hAlign(), QQuickText::AlignLeft);
    QCOMPARE(text->effectiveHAlign(), QQuickText::AlignRight);
747 748 749
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() > canvas->width()/2);

    // disable mirroring
750
    QQuickItemPrivate::get(text)->setLayoutMirror(false);
751 752 753 754
    text->resetHAlign();

    // English text should be implicitly left aligned
    text->setText("Hello world!");
755
    QCOMPARE(text->hAlign(), QQuickText::AlignLeft);
756 757 758
    QVERIFY(textPrivate->layout.lineAt(0).naturalTextRect().left() < canvas->width()/2);

    // empty text with implicit alignment follows the system locale-based
759
    // keyboard input direction from QInputMethod::inputDirection()
760
    text->setText("");
761
    QCOMPARE(text->hAlign(), qApp->inputMethod()->inputDirection() == Qt::LeftToRight ?
762 763 764
                                  QQuickText::AlignLeft : QQuickText::AlignRight);
    text->setHAlign(QQuickText::AlignRight);
    QCOMPARE(text->hAlign(), QQuickText::AlignRight);
765 766 767 768 769

    delete canvas;

    // alignment of Text with no text set to it
    QString componentStr = "import QtQuick 2.0\nText {}";
770
    QQmlComponent textComponent(&engine);
771
    textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
772
    QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
773
    QCOMPARE(textObject->hAlign(), qApp->inputMethod()->inputDirection() == Qt::LeftToRight ?
774
                                  QQuickText::AlignLeft : QQuickText::AlignRight);
775 776 777
    delete textObject;
}

778
void tst_qquicktext::verticalAlignment()
779 780 781 782 783 784 785 786
{
    //test one align each, and then test if two align fails.

    for (int i = 0; i < standard.size(); i++)
    {
        for (int j=0; j < verticalAlignmentmentStrings.size(); j++)
        {
            QString componentStr = "import QtQuick 2.0\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }";
787
            QQmlComponent textComponent(&engine);
788
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
789
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
790 791 792 793 794 795 796 797 798 799 800 801 802

            QVERIFY(textObject != 0);
            QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j));

            delete textObject;
        }
    }

    for (int i = 0; i < richText.size(); i++)
    {
        for (int j=0; j < verticalAlignmentmentStrings.size(); j++)
        {
            QString componentStr = "import QtQuick 2.0\nText { verticalAlignment: \"" + verticalAlignmentmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }";
803
            QQmlComponent textComponent(&engine);
804
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
805
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
806 807 808 809 810 811 812 813 814 815

            QVERIFY(textObject != 0);
            QCOMPARE((int)textObject->vAlign(), (int)verticalAlignmentments.at(j));

            delete textObject;
        }
    }

}

816
void tst_qquicktext::font()
817 818 819 820
{
    //test size, then bold, then italic, then family
    {
        QString componentStr = "import QtQuick 2.0\nText { font.pointSize: 40; text: \"Hello World\" }";
821
        QQmlComponent textComponent(&engine);
822
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
823
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
824 825 826 827 828 829 830 831 832 833

        QCOMPARE(textObject->font().pointSize(), 40);
        QCOMPARE(textObject->font().bold(), false);
        QCOMPARE(textObject->font().italic(), false);

        delete textObject;
    }

    {
        QString componentStr = "import QtQuick 2.0\nText { font.pixelSize: 40; text: \"Hello World\" }";
834
        QQmlComponent textComponent(&engine);
835
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
836
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
837 838 839 840 841 842 843 844

        QCOMPARE(textObject->font().pixelSize(), 40);
        QCOMPARE(textObject->font().bold(), false);
        QCOMPARE(textObject->font().italic(), false);

        delete textObject;
    }

Kent Hansen's avatar
Kent Hansen committed
845
    {
846
        QString componentStr = "import QtQuick 2.0\nText { font.bold: true; text: \"Hello World\" }";
847
        QQmlComponent textComponent(&engine);
848
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
849
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
850 851 852 853 854 855 856

        QCOMPARE(textObject->font().bold(), true);
        QCOMPARE(textObject->font().italic(), false);

        delete textObject;
    }

Kent Hansen's avatar
Kent Hansen committed
857
    {
858
        QString componentStr = "import QtQuick 2.0\nText { font.italic: true; text: \"Hello World\" }";
859
        QQmlComponent textComponent(&engine);
860
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
861
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
862 863 864 865 866 867 868

        QCOMPARE(textObject->font().italic(), true);
        QCOMPARE(textObject->font().bold(), false);

        delete textObject;
    }

Kent Hansen's avatar
Kent Hansen committed
869
    {
870
        QString componentStr = "import QtQuick 2.0\nText { font.family: \"Helvetica\"; text: \"Hello World\" }";
871
        QQmlComponent textComponent(&engine);
872
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
873
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
874 875 876 877 878 879 880 881

        QCOMPARE(textObject->font().family(), QString("Helvetica"));
        QCOMPARE(textObject->font().bold(), false);
        QCOMPARE(textObject->font().italic(), false);

        delete textObject;
    }

Kent Hansen's avatar
Kent Hansen committed
882
    {
883
        QString componentStr = "import QtQuick 2.0\nText { font.family: \"\"; text: \"Hello World\" }";
884
        QQmlComponent textComponent(&engine);
885
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
886
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
887 888 889 890 891 892 893

        QCOMPARE(textObject->font().family(), QString(""));

        delete textObject;
    }
}

894
void tst_qquicktext::style()
895 896 897
{
    //test style
    for (int i = 0; i < styles.size(); i++)
Kent Hansen's avatar
Kent Hansen committed
898
    {
899
        QString componentStr = "import QtQuick 2.0\nText { style: \"" + styleStrings.at(i) + "\"; styleColor: \"white\"; text: \"Hello World\" }";
900
        QQmlComponent textComponent(&engine);
901
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
902
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
903 904 905 906 907 908 909

        QCOMPARE((int)textObject->style(), (int)styles.at(i));
        QCOMPARE(textObject->styleColor(), QColor("white"));

        delete textObject;
    }
    QString componentStr = "import QtQuick 2.0\nText { text: \"Hello World\" }";
910
    QQmlComponent textComponent(&engine);
911
    textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
912
    QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
913 914

    QRectF brPre = textObject->boundingRect();
915
    textObject->setStyle(QQuickText::Outline);
916 917 918 919 920 921 922 923
    QRectF brPost = textObject->boundingRect();

    QVERIFY(brPre.width() < brPost.width());
    QVERIFY(brPre.height() < brPost.height());

    delete textObject;
}

924
void tst_qquicktext::color()
925 926 927
{
    //test style
    for (int i = 0; i < colorStrings.size(); i++)
Kent Hansen's avatar
Kent Hansen committed
928
    {
929
        QString componentStr = "import QtQuick 2.0\nText { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
930
        QQmlComponent textComponent(&engine);
931
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
932
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
933 934

        QCOMPARE(textObject->color(), QColor(colorStrings.at(i)));
935
        QCOMPARE(textObject->styleColor(), QColor("black"));
936
        QCOMPARE(textObject->linkColor(), QColor("blue"));
937 938 939 940 941

        delete textObject;
    }

    for (int i = 0; i < colorStrings.size(); i++)
Kent Hansen's avatar
Kent Hansen committed
942
    {
943
        QString componentStr = "import QtQuick 2.0\nText { styleColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
944
        QQmlComponent textComponent(&engine);
945
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
946
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
947 948 949 950

        QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(i)));
        // default color to black?
        QCOMPARE(textObject->color(), QColor("black"));
951 952 953 954 955 956 957 958
        QCOMPARE(textObject->linkColor(), QColor("blue"));

        delete textObject;
    }

    for (int i = 0; i < colorStrings.size(); i++)
    {
        QString componentStr = "import QtQuick 2.0\nText { linkColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
959
        QQmlComponent textComponent(&engine);
960 961 962
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());

963
        QCOMPARE(textObject->styleColor(), QColor("black"));
964 965
        QCOMPARE(textObject->color(), QColor("black"));
        QCOMPARE(textObject->linkColor(), QColor(colorStrings.at(i)));
966 967 968

        delete textObject;
    }
Kent Hansen's avatar
Kent Hansen committed
969

970
    for (int i = 0; i < colorStrings.size(); i++)
Kent Hansen's avatar
Kent Hansen committed
971
    {
972 973
        for (int j = 0; j < colorStrings.size(); j++)
        {
974 975 976 977 978
            QString componentStr = "import QtQuick 2.0\nText { "
                    "color: \"" + colorStrings.at(i) + "\"; "
                    "styleColor: \"" + colorStrings.at(j) + "\"; "
                    "linkColor: \"" + colorStrings.at(j) + "\"; "
                    "text: \"Hello World\" }";
979
            QQmlComponent textComponent(&engine);
980
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
981
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
982 983 984

            QCOMPARE(textObject->color(), QColor(colorStrings.at(i)));
            QCOMPARE(textObject->styleColor(), QColor(colorStrings.at(j)));
985
            QCOMPARE(textObject->linkColor(), QColor(colorStrings.at(j)));
986 987 988 989 990 991 992 993 994 995

            delete textObject;
        }
    }
    {
        QString colorStr = "#AA001234";
        QColor testColor("#001234");
        testColor.setAlpha(170);

        QString componentStr = "import QtQuick 2.0\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }";
996
        QQmlComponent textComponent(&engine);
997
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
998
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
999 1000 1001 1002

        QCOMPARE(textObject->color(), testColor);

        delete textObject;
1003 1004 1005 1006 1007
    } {
        QString colorStr = "#001234";
        QColor testColor(colorStr);

        QString componentStr = "import QtQuick 2.0\nText { color: \"" + colorStr + "\"; text: \"Hello World\" }";
1008
        QQmlComponent textComponent(&engine);
1009 1010 1011 1012
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
        QScopedPointer<QObject> object(textComponent.create());
        QQuickText *textObject = qobject_cast<QQuickText*>(object.data());

1013
        QSignalSpy spy(textObject, SIGNAL(colorChanged()));
1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028

        QCOMPARE(textObject->color(), testColor);
        textObject->setColor(testColor);
        QCOMPARE(textObject->color(), testColor);
        QCOMPARE(spy.count(), 0);

        testColor = QColor("black");
        textObject->setColor(testColor);
        QCOMPARE(textObject->color(), testColor);
        QCOMPARE(spy.count(), 1);
    } {
        QString colorStr = "#001234";
        QColor testColor(colorStr);

        QString componentStr = "import QtQuick 2.0\nText { styleColor: \"" + colorStr + "\"; text: \"Hello World\" }";
1029
        QQmlComponent textComponent(&engine);
1030 1031 1032 1033
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
        QScopedPointer<QObject> object(textComponent.create());
        QQuickText *textObject = qobject_cast<QQuickText*>(object.data());

1034
        QSignalSpy spy(textObject, SIGNAL(styleColorChanged()));
1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049

        QCOMPARE(textObject->styleColor(), testColor);
        textObject->setStyleColor(testColor);
        QCOMPARE(textObject->styleColor(), testColor);
        QCOMPARE(spy.count(), 0);

        testColor = QColor("black");
        textObject->setStyleColor(testColor);
        QCOMPARE(textObject->styleColor(), testColor);
        QCOMPARE(spy.count(), 1);
    } {
        QString colorStr = "#001234";
        QColor testColor(colorStr);

        QString componentStr = "import QtQuick 2.0\nText { linkColor: \"" + colorStr + "\"; text: \"Hello World\" }";
1050
        QQmlComponent textComponent(&engine);
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
        QScopedPointer<QObject> object(textComponent.create());
        QQuickText *textObject = qobject_cast<QQuickText*>(object.data());

        QSignalSpy spy(textObject, SIGNAL(linkColorChanged()));

        QCOMPARE(textObject->linkColor(), testColor);
        textObject->setLinkColor(testColor);
        QCOMPARE(textObject->linkColor(), testColor);
        QCOMPARE(spy.count(), 0);

        testColor = QColor("black");
        textObject->setLinkColor(testColor);
        QCOMPARE(textObject->linkColor(), testColor);
        QCOMPARE(spy.count(), 1);
1066 1067 1068
    }
}

1069
void tst_qquicktext::smooth()
1070 1071 1072 1073
{
    for (int i = 0; i < standard.size(); i++)
    {
        {
1074
            QString componentStr = "import QtQuick 2.0\nText { smooth: false; text: \"" + standard.at(i) + "\" }";
1075
            QQmlComponent textComponent(&engine);
1076
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1077
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1078
            QCOMPARE(textObject->smooth(), false);
1079 1080 1081 1082 1083

            delete textObject;
        }
        {
            QString componentStr = "import QtQuick 2.0\nText { text: \"" + standard.at(i) + "\" }";
1084
            QQmlComponent textComponent(&engine);
1085
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1086
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1087
            QCOMPARE(textObject->smooth(), true);
1088 1089 1090 1091 1092 1093 1094

            delete textObject;
        }
    }
    for (int i = 0; i < richText.size(); i++)
    {
        {
1095
            QString componentStr = "import QtQuick 2.0\nText { smooth: false; text: \"" + richText.at(i) + "\" }";
1096
            QQmlComponent textComponent(&engine);
1097
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1098
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1099
            QCOMPARE(textObject->smooth(), false);
1100 1101 1102 1103 1104

            delete textObject;
        }
        {
            QString componentStr = "import QtQuick 2.0\nText { text: \"" + richText.at(i) + "\" }";
1105
            QQmlComponent textComponent(&engine);
1106
            textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1107
            QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1108
            QCOMPARE(textObject->smooth(), true);
1109 1110 1111 1112 1113 1114

            delete textObject;
        }
    }
}

1115
void tst_qquicktext::weight()
1116 1117 1118
{
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }";
1119
        QQmlComponent textComponent(&engine);
1120
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1121
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1122 1123

        QVERIFY(textObject != 0);
1124
        QCOMPARE((int)textObject->font().weight(), (int)QQmlFontValueType::Normal);
1125 1126 1127 1128 1129

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { font.weight: \"Bold\"; text: \"Hello world!\" }";
1130
        QQmlComponent textComponent(&engine);
1131
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1132
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1133 1134

        QVERIFY(textObject != 0);
1135
        QCOMPARE((int)textObject->font().weight(), (int)QQmlFontValueType::Bold);
1136 1137 1138 1139 1140

        delete textObject;
    }
}

1141
void tst_qquicktext::underline()
1142 1143 1144
{
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }";
1145
        QQmlComponent textComponent(&engine);
1146
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1147
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1148 1149 1150 1151 1152 1153 1154 1155

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->font().underline(), false);

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { font.underline: true; text: \"Hello world!\" }";
1156
        QQmlComponent textComponent(&engine);
1157
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1158
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1159 1160 1161 1162 1163 1164 1165 1166

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->font().underline(), true);

        delete textObject;
    }
}

1167
void tst_qquicktext::overline()
1168 1169 1170
{
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }";
1171
        QQmlComponent textComponent(&engine);
1172
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1173
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1174 1175 1176 1177 1178 1179 1180 1181

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->font().overline(), false);

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { font.overline: true; text: \"Hello world!\" }";
1182
        QQmlComponent textComponent(&engine);
1183
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1184
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1185 1186 1187 1188 1189 1190 1191 1192

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->font().overline(), true);

        delete textObject;
    }
}

1193
void tst_qquicktext::strikeout()
1194 1195 1196
{
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }";
1197
        QQmlComponent textComponent(&engine);
1198
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1199
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1200 1201 1202 1203 1204 1205 1206 1207

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->font().strikeOut(), false);

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { font.strikeout: true; text: \"Hello world!\" }";
1208
        QQmlComponent textComponent(&engine);
1209
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1210
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1211 1212 1213 1214 1215 1216 1217 1218

        QVERIFY(textObject != 0);
        QCOMPARE(textObject->font().strikeOut(), true);

        delete textObject;
    }
}

1219
void tst_qquicktext::capitalization()
1220 1221 1222
{
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\" }";
1223
        QQmlComponent textComponent(&engine);
1224
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1225
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1226 1227

        QVERIFY(textObject != 0);
1228
        QCOMPARE((int)textObject->font().capitalization(), (int)QQmlFontValueType::MixedCase);
1229 1230 1231 1232 1233

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\"; font.capitalization: \"AllUppercase\" }";
1234
        QQmlComponent textComponent(&engine);
1235
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1236
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1237 1238

        QVERIFY(textObject != 0);
1239
        QCOMPARE((int)textObject->font().capitalization(), (int)QQmlFontValueType::AllUppercase);
1240 1241 1242 1243 1244

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\"; font.capitalization: \"AllLowercase\" }";
1245
        QQmlComponent textComponent(&engine);
1246
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1247
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1248 1249

        QVERIFY(textObject != 0);
1250
        QCOMPARE((int)textObject->font().capitalization(), (int)QQmlFontValueType::AllLowercase);
1251 1252 1253 1254 1255

        delete textObject;
    }
    {
        QString componentStr = "import QtQuick 2.0\nText { text: \"Hello world!\"; font.capitalization: \"SmallCaps\" }";
1256
        QQmlComponent textComponent(&engine);
1257
        textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
1258
        QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
1259 1260

        QVERIFY(textObject != 0);
1261
        QCOMPARE((int)textObject->font().capitalization(), (int)QQmlFontValueType::SmallCaps);