diff options
author | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-08-05 10:42:21 +0200 |
---|---|---|
committer | Sergio Ahumada <sergio.ahumada@digia.com> | 2013-08-05 10:42:21 +0200 |
commit | 1d3b9db5b54d8ae99c6b149c8d3d91eda19b5838 (patch) | |
tree | 9ffbf9d6d2ed6b0aef6155215767c56655ff405b /tests/auto/quick/qquicktext | |
parent | 45792359f25813af18b7416e4c18737ed4b20bff (diff) | |
parent | 0316506d9ddbc3ca9f26f880b9e7fb5d5b0fec36 (diff) |
Merge branch 'stable' into dev
Conflicts:
.qmake.conf
Change-Id: I06f79bcbde13c7b12905492a17dbcbb4a594e557
Diffstat (limited to 'tests/auto/quick/qquicktext')
-rw-r--r-- | tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml | 2 | ||||
-rw-r--r-- | tests/auto/quick/qquicktext/tst_qquicktext.cpp | 52 |
2 files changed, 38 insertions, 16 deletions
diff --git a/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml b/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml index 136e5d21a2..9c9318d3cc 100644 --- a/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml +++ b/tests/auto/quick/qquicktext/data/hAlignImplicitWidth.qml @@ -6,7 +6,7 @@ Rectangle { Text { objectName: "textItem" - text: "AA\nBBBBB\nCCCCCCCCCCCCCCCC" + text: "AA\nBBBBBBB\nCCCCCCCCCCCCCCCC" anchors.centerIn: parent horizontalAlignment: Text.AlignLeft } diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index 32099ae187..6b93791545 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -854,9 +854,20 @@ int tst_qquicktext::numberOfNonWhitePixels(int fromX, int toX, const QImage &ima return pixels; } +static inline QByteArray msgNotGreaterThan(int n1, int n2) +{ + return QByteArray::number(n1) + QByteArrayLiteral(" is not greater than ") + QByteArray::number(n2); +} + +static inline QByteArray msgNotLessThan(int n1, int n2) +{ + return QByteArray::number(n1) + QByteArrayLiteral(" is not less than ") + QByteArray::number(n2); +} + void tst_qquicktext::hAlignImplicitWidth() { QQuickView view(testFileUrl("hAlignImplicitWidth.qml")); + view.setFlags(view.flags() | Qt::WindowStaysOnTopHint); // Prevent being obscured by other windows. view.show(); view.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -864,34 +875,45 @@ void tst_qquicktext::hAlignImplicitWidth() QQuickText *text = view.rootObject()->findChild<QQuickText*>("textItem"); QVERIFY(text != 0); + // Try to check whether alignment works by checking the number of black + // pixels in the thirds of the grabbed image. + const int windowWidth = 200; + const int textWidth = qCeil(text->implicitWidth()); + QVERIFY2(textWidth < windowWidth, "System font too large."); + const int sectionWidth = textWidth / 3; + const int centeredSection1 = (windowWidth - textWidth) / 2; + const int centeredSection2 = centeredSection1 + sectionWidth; + const int centeredSection3 = centeredSection2 + sectionWidth; + const int centeredSection3End = centeredSection3 + sectionWidth; + { // Left Align QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left > mid); - QVERIFY(mid > right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left > mid, msgNotGreaterThan(left, mid).constData()); + QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData()); } { // HCenter Align text->setHAlign(QQuickText::AlignHCenter); QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left < mid); - QVERIFY(mid > right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left < mid, msgNotLessThan(left, mid).constData()); + QVERIFY2(mid > right, msgNotGreaterThan(mid, right).constData()); } { // Right Align text->setHAlign(QQuickText::AlignRight); QImage image = view.grabWindow(); - int left = numberOfNonWhitePixels(0, image.width() / 3, image); - int mid = numberOfNonWhitePixels(image.width() / 3, 2 * image.width() / 3, image); - int right = numberOfNonWhitePixels( 2 * image.width() / 3, image.width(), image); - QVERIFY(left < mid); - QVERIFY(mid < right); + const int left = numberOfNonWhitePixels(centeredSection1, centeredSection2, image); + const int mid = numberOfNonWhitePixels(centeredSection2, centeredSection3, image); + const int right = numberOfNonWhitePixels(centeredSection3, centeredSection3End, image); + QVERIFY2(left < mid, msgNotLessThan(left, mid).constData()); + QVERIFY2(mid < right, msgNotLessThan(mid, right).constData()); } } |