~ubuntu-branches/debian/jessie/qtdeclarative-opensource-src/jessie

« back to all changes in this revision

Viewing changes to tests/auto/quick/qquicktext/tst_qquicktext.cpp

  • Committer: Package Import Robot
  • Author(s): Lisandro Damián Nicanor Pérez Meyer, Lisandro Damián Nicanor Pérez Meyer
  • Date: 2013-08-30 22:09:43 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130830220943-en0u2dm8cfxpi53o
Tags: 5.1.1-1
[ Lisandro Damián Nicanor Pérez Meyer ]
* New upstream release.
* Update symbols file with buildds' logs.
* Remove fix_systemdialogs_path, applied upstream.
* Adjust examples install file.
* Update symbols files with current build.
* Tighten Qt 5 build dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
    void htmlLists();
150
150
    void htmlLists_data();
151
151
 
 
152
    void elideBeforeMaximumLineCount();
 
153
 
152
154
private:
153
155
    QStringList standard;
154
156
    QStringList richText;
852
854
    return pixels;
853
855
}
854
856
 
 
857
static inline QByteArray msgNotGreaterThan(int n1, int n2)
 
858
{
 
859
    return QByteArray::number(n1) + QByteArrayLiteral(" is not greater than ") + QByteArray::number(n2);
 
860
}
 
861
 
 
862
static inline QByteArray msgNotLessThan(int n1, int n2)
 
863
{
 
864
    return QByteArray::number(n1) + QByteArrayLiteral(" is not less than ") + QByteArray::number(n2);
 
865
}
 
866
 
855
867
void tst_qquicktext::hAlignImplicitWidth()
856
868
{
857
869
    QQuickView view(testFileUrl("hAlignImplicitWidth.qml"));
 
870
    view.setFlags(view.flags() | Qt::WindowStaysOnTopHint); // Prevent being obscured by other windows.
858
871
    view.show();
859
872
    view.requestActivate();
860
873
    QVERIFY(QTest::qWaitForWindowActive(&view));
862
875
    QQuickText *text = view.rootObject()->findChild<QQuickText*>("textItem");
863
876
    QVERIFY(text != 0);
864
877
 
 
878
    // Try to check whether alignment works by checking the number of black
 
879
    // pixels in the thirds of the grabbed image.
 
880
    const int windowWidth = 200;
 
881
    const int textWidth = qCeil(text->implicitWidth());
 
882
    QVERIFY2(textWidth < windowWidth, "System font too large.");
 
883
    const int sectionWidth = textWidth / 3;
 
884
    const int centeredSection1 = (windowWidth - textWidth) / 2;
 
885
    const int centeredSection2 = centeredSection1 + sectionWidth;
 
886
    const int centeredSection3 = centeredSection2 + sectionWidth;
 
887
    const int centeredSection3End = centeredSection3 + sectionWidth;
 
888
 
865
889
    {
866
890
        // Left Align
867
891
        QImage image = view.grabWindow();
868
 
        int left = numberOfNonWhitePixels(0, image.width() / 3, image);
869
 
        int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image);
870
 
        int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image);
871
 
        QVERIFY(left > mid);
872
 
        QVERIFY(mid > right);
 
892
        const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image);
 
893
        const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image);
 
894
        const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image);
 
895
        QVERIFY2(left > mid, msgNotGreaterThan(left, mid).constData());
 
896
        QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData());
873
897
    }
874
898
    {
875
899
        // HCenter Align
876
900
        text->setHAlign(QQuickText::AlignHCenter);
877
901
        QImage image = view.grabWindow();
878
 
        int left = numberOfNonWhitePixels(0, image.width() / 3, image);
879
 
        int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image);
880
 
        int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image);
881
 
        QVERIFY(left < mid);
882
 
        QVERIFY(mid > right);
 
902
        const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image);
 
903
        const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image);
 
904
        const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image);
 
905
        QVERIFY2(left < mid, msgNotLessThan(left, mid).constData());
 
906
        QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData());
883
907
    }
884
908
    {
885
909
        // Right Align
886
910
        text->setHAlign(QQuickText::AlignRight);
887
911
        QImage image = view.grabWindow();
888
 
        int left = numberOfNonWhitePixels(0, image.width() / 3, image);
889
 
        int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image);
890
 
        int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image);
891
 
        QVERIFY(left < mid);
892
 
        QVERIFY(mid < right);
 
912
        const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image);
 
913
        const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image);
 
914
        const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image);
 
915
        QVERIFY2(left < mid, msgNotLessThan(left, mid).constData());
 
916
        QVERIFY2(mid < right, msgNotLessThan(mid, right).constData());
893
917
    }
894
918
}
895
919
 
1842
1866
void tst_qquicktext::baseUrl()
1843
1867
{
1844
1868
    QUrl localUrl("file:///tests/text.qml");
1845
 
    QUrl remoteUrl("http://qt.nokia.com/test.qml");
 
1869
    QUrl remoteUrl("http://www.qt-project.org/test.qml");
1846
1870
 
1847
1871
    QQmlComponent textComponent(&engine);
1848
1872
    textComponent.setData("import QtQuick 2.0\n Text {}", localUrl);
3638
3662
    QTest::newRow("unordered list bad") << "<ul type=\"bad\"><li>one</li><li>two</li></ul>" << 2;
3639
3663
}
3640
3664
 
 
3665
void tst_qquicktext::elideBeforeMaximumLineCount()
 
3666
{   // QTBUG-31471
 
3667
    QQmlComponent component(&engine, testFile("elideBeforeMaximumLineCount.qml"));
 
3668
 
 
3669
    QScopedPointer<QObject> object(component.create());
 
3670
 
 
3671
    QQuickText *item = qobject_cast<QQuickText *>(object.data());
 
3672
    QVERIFY(item);
 
3673
 
 
3674
    QCOMPARE(item->lineCount(), 2);
 
3675
}
 
3676
 
3641
3677
QTEST_MAIN(tst_qquicktext)
3642
3678
 
3643
3679
#include "tst_qquicktext.moc"