aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-08-06 16:07:23 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-06 18:26:47 +0200
commitf1b9ba8c6ee6b991ef4e513bc4f39045fd55d1e6 (patch)
treecd587156a07344e98aca0cd1511075fe272bfec5 /tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
parent27deff6d2b5a9eb1d98cd7b377ab934a35086664 (diff)
parent1d3b9db5b54d8ae99c6b149c8d3d91eda19b5838 (diff)
Merge "Merge branch 'stable' into dev" into refs/staging/dev
Diffstat (limited to 'tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp')
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp82
1 files changed, 51 insertions, 31 deletions
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 6a136aeb7e..ff9554718b 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -657,7 +657,7 @@ void tst_qquicktextedit::hAlign_RightToLeft()
QQuickView window(testFileUrl("horizontalAlignment_RightToLeft.qml"));
QQuickTextEdit *textEdit = window.rootObject()->findChild<QQuickTextEdit*>("text");
QVERIFY(textEdit != 0);
- window.show();
+ window.showNormal();
const QString rtlText = textEdit->text();
@@ -821,42 +821,66 @@ static int numberOfNonWhitePixels(int fromX, int toX, const QImage &image)
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_qquicktextedit::hAlignVisual()
{
QQuickView view(testFileUrl("hAlignVisual.qml"));
- view.show();
+ view.setFlags(view.flags() | Qt::WindowStaysOnTopHint); // Prevent being obscured by other windows.
+ view.showNormal();
QVERIFY(QTest::qWaitForWindowExposed(&view));
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);
+ image.save("test3.png");
+ QVERIFY2(left < mid, msgNotLessThan(left, mid).constData());
+ QVERIFY2(mid < right, msgNotLessThan(mid, right).constData());
}
text->setWidth(200);
@@ -867,8 +891,8 @@ void tst_qquicktextedit::hAlignVisual()
int x = qCeil(text->implicitWidth());
int left = numberOfNonWhitePixels(0, x, image);
int right = numberOfNonWhitePixels(x, image.width() - x, image);
- QVERIFY(left > 0);
- QVERIFY(right == 0);
+ QVERIFY2(left > 0, msgNotGreaterThan(left, 0).constData());
+ QCOMPARE(right, 0);
}
{
// HCenter Align
@@ -879,9 +903,9 @@ void tst_qquicktextedit::hAlignVisual()
int left = numberOfNonWhitePixels(0, x1, image);
int mid = numberOfNonWhitePixels(x1, x2 - x1, image);
int right = numberOfNonWhitePixels(x2, image.width() - x2, image);
- QVERIFY(left == 0);
- QVERIFY(mid > 0);
- QVERIFY(right == 0);
+ QCOMPARE(left, 0);
+ QVERIFY2(mid > 0, msgNotGreaterThan(left, 0).constData());
+ QCOMPARE(right, 0);
}
{
// Right Align
@@ -890,8 +914,8 @@ void tst_qquicktextedit::hAlignVisual()
int x = image.width() - qCeil(text->implicitWidth());
int left = numberOfNonWhitePixels(0, x, image);
int right = numberOfNonWhitePixels(x, image.width() - x, image);
- QVERIFY(left == 0);
- QVERIFY(right > 0);
+ QCOMPARE(left, 0);
+ QVERIFY2(right > 0, msgNotGreaterThan(left, 0).constData());
}
}
@@ -1241,7 +1265,7 @@ void tst_qquicktextedit::focusOnPress()
QQuickWindow window;
window.resize(100, 50);
textEditObject->setParentItem(window.contentItem());
- window.show();
+ window.showNormal();
window.requestActivate();
QTest::qWaitForWindowActive(&window);
@@ -2520,7 +2544,7 @@ void tst_qquicktextedit::remoteCursorDelegate()
view.rootContext()->setContextProperty("contextDelegate", &component);
view.setSource(testFileUrl("cursorTestRemote.qml"));
- view.show();
+ view.showNormal();
view.requestActivate();
QTest::qWaitForWindowActive(&view);
QQuickTextEdit *textEditObject = view.rootObject()->findChild<QQuickTextEdit*>("textEditObject");
@@ -2534,10 +2558,6 @@ void tst_qquicktextedit::remoteCursorDelegate()
textEditObject->setFocus(true);
QVERIFY(textEditObject->isCursorVisible());
- QCOMPARE(component.status(), QQmlComponent::Loading);
- QVERIFY(!textEditObject->findChild<QQuickItem*>("cursorInstance"));
- server.sendDelayedItem();
-
// Wait for component to load.
QTRY_COMPARE(component.status(), QQmlComponent::Ready);
QVERIFY(textEditObject->findChild<QQuickItem*>("cursorInstance"));
@@ -3047,7 +3067,7 @@ void tst_qquicktextedit::openInputPanel()
inputMethodPrivate->testContext = &platformInputContext;
QQuickView view(testFileUrl("openInputPanel.qml"));
- view.show();
+ view.showNormal();
view.requestActivate();
QTest::qWaitForWindowActive(&view);