summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2011-04-07 11:08:53 +0200
committeraxis <qt-info@nokia.com>2011-04-07 11:08:53 +0200
commitd54b3f04fa629fe031f1083073eef0145f0d6b1e (patch)
tree2a06736f812c478bdb21aa3781078fe88b5532fa /tests/auto/declarative
parent258c1a8537816f7b4c79e7cf4090a333768a10fa (diff)
parent8031eada2f81963865390b4d899631b09d4ca6f3 (diff)
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt into earth-master
Conflicts: src/corelib/thread/qthread_unix.cpp
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r--tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp22
-rw-r--r--tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml50
-rw-r--r--tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp73
-rw-r--r--tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp22
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml8
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp32
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp85
9 files changed, 266 insertions, 30 deletions
diff --git a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
index 9e090d2e4d..c5a3d149a0 100644
--- a/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
+++ b/tests/auto/declarative/qdeclarativeimage/tst_qdeclarativeimage.cpp
@@ -91,6 +91,7 @@ private slots:
void sourceSize_QTBUG_14303();
void sourceSize_QTBUG_16389();
void nullPixmapPaint();
+ void resetSourceSize();
void testQtQuick11Attributes();
void testQtQuick11Attributes_data();
@@ -693,6 +694,27 @@ void tst_qdeclarativeimage::nullPixmapPaint()
delete image;
}
+void tst_qdeclarativeimage::resetSourceSize()
+{
+ QString src = QUrl::fromLocalFile(SRCDIR "/data/heart200.png").toString();
+ QString componentStr = "import QtQuick 1.1\nImage { function reset() { sourceSize = undefined }\nsource: \"" + src + "\"; sourceSize: Qt.size(100,100) }";
+
+ QDeclarativeComponent component(&engine);
+ component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
+ QDeclarativeImage *obj = qobject_cast<QDeclarativeImage*>(component.create());
+ QVERIFY(obj != 0);
+ QCOMPARE(obj->pixmap().width(), 100);
+ QCOMPARE(obj->pixmap().height(), 100);
+ QCOMPARE(obj->sourceSize().height(), 100);
+ QCOMPARE(obj->sourceSize().width(), 100);
+
+ QMetaObject::invokeMethod(obj, "reset");
+ QCOMPARE(obj->pixmap().width(), 200);
+ QCOMPARE(obj->pixmap().height(), 200);
+ QCOMPARE(obj->sourceSize().height(), 200);
+ QCOMPARE(obj->sourceSize().width(), 200);
+}
+
void tst_qdeclarativeimage::testQtQuick11Attributes()
{
QFETCH(QString, code);
diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
index 5a2591f042..2ce493bd2a 100644
--- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
+++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp
@@ -174,7 +174,7 @@ private:
QVERIFY(component.errors().isEmpty()); \
} else { \
QFile file(QLatin1String(SRCDIR) + QLatin1String("/data/") + QLatin1String(errorfile)); \
- QVERIFY(file.open(QIODevice::ReadOnly)); \
+ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \
QByteArray data = file.readAll(); \
file.close(); \
QList<QByteArray> expected = data.split('\n'); \
diff --git a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp
index dc104e23e8..9d1c609616 100644
--- a/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp
+++ b/tests/auto/declarative/qdeclarativemoduleplugin/tst_qdeclarativemoduleplugin.cpp
@@ -85,7 +85,7 @@ private slots:
QVERIFY(component.errors().isEmpty()); \
} else { \
QFile file(QLatin1String("data/") + QLatin1String(errorfile)); \
- QVERIFY(file.open(QIODevice::ReadOnly)); \
+ QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text)); \
QByteArray data = file.readAll(); \
file.close(); \
QList<QByteArray> expected = data.split('\n'); \
diff --git a/tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml b/tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml
new file mode 100644
index 0000000000..2da58fce3a
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativepincharea/data/flickresize.qml
@@ -0,0 +1,50 @@
+import QtQuick 1.1
+
+Flickable {
+ id: flick
+ property real scale: 1.0
+ width: 640
+ height: 360
+ contentWidth: 500
+ contentHeight: 500
+
+ PinchArea {
+ objectName: "pincharea"
+ width: Math.max(flick.contentWidth, flick.width)
+ height: Math.max(flick.contentHeight, flick.height)
+
+ property real initialWidth
+ property real initialHeight
+ onPinchStarted: {
+ initialWidth = flick.contentWidth
+ initialHeight = flick.contentHeight
+ }
+
+ onPinchUpdated: {
+ // adjust content pos due to drag
+ flick.contentX += pinch.previousCenter.x - pinch.center.x
+ flick.contentY += pinch.previousCenter.y - pinch.center.y
+
+ // resize content
+ flick.resizeContent(initialWidth * pinch.scale, initialHeight * pinch.scale, pinch.center)
+ flick.scale = pinch.scale
+ }
+
+ onPinchFinished: {
+ // Move its content within bounds.
+ flick.returnToBounds()
+ }
+
+ Rectangle {
+ width: flick.contentWidth
+ height: flick.contentHeight
+ color: "white"
+ Rectangle {
+ anchors.centerIn: parent
+ width: parent.width-40
+ height: parent.height-40
+ color: "blue"
+ }
+ }
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp b/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp
index f175033e10..90506baedd 100644
--- a/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp
+++ b/tests/auto/declarative/qdeclarativepincharea/tst_qdeclarativepincharea.cpp
@@ -43,6 +43,7 @@
#include <QtTest/QSignalSpy>
#include <private/qdeclarativepincharea_p.h>
#include <private/qdeclarativerectangle_p.h>
+#include <private/qdeclarativeflickable_p.h>
#include <QtDeclarative/qdeclarativeview.h>
#include <QtDeclarative/qdeclarativecontext.h>
@@ -58,6 +59,7 @@ private slots:
void pinchProperties();
void scale();
void pan();
+ void flickable();
private:
QDeclarativeView *createView();
@@ -301,6 +303,77 @@ void tst_QDeclarativePinchArea::pan()
delete canvas;
}
+void tst_QDeclarativePinchArea::flickable()
+{
+ QDeclarativeView *canvas = createView();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/flickresize.qml"));
+ canvas->show();
+ canvas->setFocus();
+ QTest::qWaitForWindowShown(canvas);
+ QVERIFY(canvas->rootObject() != 0);
+ qApp->processEvents();
+
+ QDeclarativePinchArea *pinchArea = canvas->rootObject()->findChild<QDeclarativePinchArea*>("pincharea");
+ QDeclarativePinch *pinch = pinchArea->pinch();
+ QVERIFY(pinchArea != 0);
+ QVERIFY(pinch != 0);
+
+ QDeclarativeFlickable *root = qobject_cast<QDeclarativeFlickable*>(canvas->rootObject());
+ QVERIFY(root != 0);
+
+ QWidget *vp = canvas->viewport();
+
+ QPoint p1(110, 80);
+ QPoint p2(100, 100);
+
+ // begin by moving one touch point (mouse)
+ QTest::mousePress(vp, Qt::LeftButton, 0, canvas->mapFromScene(p1));
+ QTest::touchEvent(vp).press(0, p1);
+ {
+ p1 -= QPoint(10,10);
+ QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p1), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+ QApplication::sendEvent(canvas->viewport(), &mv);
+ QTest::touchEvent(vp).move(0, p1);
+ }
+ {
+ p1 -= QPoint(10,10);
+ QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p1), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+ QApplication::sendEvent(vp, &mv);
+ QTest::touchEvent(vp).move(0, p1);
+ }
+ {
+ p1 -= QPoint(10,10);
+ QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p1), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier);
+ QApplication::sendEvent(vp, &mv);
+ QTest::touchEvent(vp).move(0, p1);
+ }
+
+ // Flickable has reacted to the gesture
+ QVERIFY(root->isMoving());
+ QVERIFY(root->property("scale").toReal() == 1.0);
+
+ // add another touch point and continue moving
+ QTest::touchEvent(vp).stationary(0).press(1, p2);
+ p1 -= QPoint(10,10);
+ p2 += QPoint(10,10);
+ QTest::touchEvent(vp).move(0, p1).move(1, p2);
+
+ QCOMPARE(root->property("scale").toReal(), 1.0);
+
+ p1 -= QPoint(10,10);
+ p2 += QPoint(10,10);
+ QTest::touchEvent(vp).move(0, p1).move(1, p2);
+
+ // PinchArea has stolen the gesture.
+ QVERIFY(!root->isMoving());
+ QVERIFY(root->property("scale").toReal() > 1.0);
+
+ QTest::mouseRelease(vp, Qt::LeftButton, 0, canvas->mapFromScene(p1));
+ QTest::touchEvent(vp).release(0, p1).release(1, p2);
+
+ delete canvas;
+}
+
QDeclarativeView *tst_QDeclarativePinchArea::createView()
{
QDeclarativeView *canvas = new QDeclarativeView(0);
diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
index 92ab72281a..78821cb3d3 100644
--- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
+++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
@@ -154,6 +154,15 @@ void tst_QDeclarativePositioners::test_horizontal_rtl()
QCOMPARE(row->width(), 110.0);
QCOMPARE(row->height(), 50.0);
+ // Change the width of the row and check that items stay to the right
+ row->setWidth(200);
+ QCOMPARE(one->x(), 150.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 130.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 90.0);
+ QCOMPARE(three->y(), 0.0);
+
delete canvas;
}
@@ -527,6 +536,19 @@ void tst_QDeclarativePositioners::test_grid_rightToLeft()
QCOMPARE(grid->width(), 100.0);
QCOMPARE(grid->height(), 100.0);
+ // Change the width of the grid and check that items stay to the right
+ grid->setWidth(200);
+ QCOMPARE(one->x(), 150.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 130.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 100.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 150.0);
+ QCOMPARE(four->y(), 50.0);
+ QCOMPARE(five->x(), 140.0);
+ QCOMPARE(five->y(), 50.0);
+
delete canvas;
}
diff --git a/tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml b/tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml
new file mode 100644
index 0000000000..3af0313692
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextedit/data/CursorRect.qml
@@ -0,0 +1,8 @@
+import QtQuick 1.0
+
+TextEdit {
+ focus: true
+ objectName: "myEdit"
+ width: 50
+ text: "This is a long piece of text"
+}
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index f62c2c57df..8f1be6f8bc 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -148,6 +148,7 @@ private slots:
void preeditMicroFocus();
void inputContextMouseHandler();
void inputMethodComposing();
+ void cursorRectangleSize();
private:
void simulateKey(QDeclarativeView *, int key, Qt::KeyboardModifiers modifiers = 0);
@@ -1340,6 +1341,12 @@ void tst_qdeclarativetextedit::mouseSelection()
else
QVERIFY(str.isEmpty());
+ // Clicking and shift to clicking between the same points should select the same text.
+ textEditObject->setCursorPosition(0);
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, canvas->mapFromScene(QPoint(x1,y)));
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, canvas->mapFromScene(QPoint(x2,y)));
+ QCOMPARE(textEditObject->selectedText(), str);
+
delete canvas;
}
@@ -1436,6 +1443,12 @@ void tst_qdeclarativetextedit::mouseSelectionMode()
QVERIFY(str != text);
}
+ // Clicking and shift to clicking between the same points should select the same text.
+ textEditObject->setCursorPosition(0);
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, canvas->mapFromScene(QPoint(x1,y)));
+ QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, canvas->mapFromScene(QPoint(x2,y)));
+ QCOMPARE(textEditObject->selectedText(), str);
+
delete canvas;
}
@@ -2409,6 +2422,25 @@ void tst_qdeclarativetextedit::inputMethodComposing()
QCOMPARE(spy.count(), 2);
}
+void tst_qdeclarativetextedit::cursorRectangleSize()
+{
+ QDeclarativeView *canvas = createView(SRCDIR "/data/CursorRect.qml");
+ QVERIFY(canvas->rootObject() != 0);
+ canvas->show();
+ canvas->setFocus();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+
+ QDeclarativeTextEdit *textEdit = qobject_cast<QDeclarativeTextEdit *>(canvas->rootObject());
+ QVERIFY(textEdit != 0);
+ textEdit->setFocus(Qt::OtherFocusReason);
+ QRectF cursorRect = textEdit->positionToRectangle(textEdit->cursorPosition());
+ QRectF microFocusFromScene = canvas->scene()->inputMethodQuery(Qt::ImMicroFocus).toRectF();
+ QRectF microFocusFromApp= QApplication::focusWidget()->inputMethodQuery(Qt::ImMicroFocus).toRectF();
+
+ QCOMPARE(microFocusFromScene.size(), cursorRect.size());
+ QCOMPARE(microFocusFromApp.size(), cursorRect.size());
+}
QTEST_MAIN(tst_qdeclarativetextedit)
#include "tst_qdeclarativetextedit.moc"
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index 45f38a4678..ef32ee3567 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -135,6 +135,7 @@ private slots:
void preeditMicroFocus();
void inputContextMouseHandler();
void inputMethodComposing();
+ void cursorRectangleSize();
private:
void simulateKey(QDeclarativeView *, int key);
@@ -604,10 +605,8 @@ void tst_qdeclarativetextinput::moveCursorSelection_data()
<< standard[2] << 13 << 6 << QDeclarativeTextInput::SelectWords << 6 << 13 << false;
QTest::newRow("Hello<(, world!)>|words")
<< standard[2] << 5 << 13 << QDeclarativeTextInput::SelectWords << 5 << 13 << true;
- // Fails due to an issue with QTextBoundaryFinder and punctuation at the end of strings.
- // QTBUG-11365
- // QTest::newRow("world<(!)>|words")
- // << standard[2] << 12 << 13 << QDeclarativeTextInput::SelectWords << 12 << 13 << true;
+ QTest::newRow("world<(!)>|words")
+ << standard[2] << 12 << 13 << QDeclarativeTextInput::SelectWords << 12 << 13 << true;
QTest::newRow("world!<()>)|words")
<< standard[2] << 13 << 13 << QDeclarativeTextInput::SelectWords << 13 << 13 << true;
QTest::newRow("world<()>!)|words")
@@ -653,16 +652,15 @@ void tst_qdeclarativetextinput::moveCursorSelection_data()
QTest::newRow(" <s(pac)ey> text |words")
<< standard[4] << 1 << 4 << QDeclarativeTextInput::SelectWords << 1 << 7 << true;
QTest::newRow(" spacey <t(ex)t> |words")
- << standard[4] << 11 << 13 << QDeclarativeTextInput::SelectWords << 10 << 14 << false; // Should be reversible. QTBUG-11365
+ << standard[4] << 11 << 13 << QDeclarativeTextInput::SelectWords << 10 << 14 << true;
QTest::newRow("<( )>spacey text |words|ltr")
<< standard[4] << 0 << 1 << QDeclarativeTextInput::SelectWords << 0 << 1 << false;
QTest::newRow("<( )spacey> text |words|rtl")
<< standard[4] << 1 << 0 << QDeclarativeTextInput::SelectWords << 0 << 7 << false;
QTest::newRow("spacey <text( )>|words|ltr")
<< standard[4] << 14 << 15 << QDeclarativeTextInput::SelectWords << 10 << 15 << false;
-// QTBUG-11365
-// QTest::newRow("spacey text<( )>|words|rtl")
-// << standard[4] << 15 << 14 << QDeclarativeTextInput::SelectWords << 14 << 15 << false;
+ QTest::newRow("spacey text<( )>|words|rtl")
+ << standard[4] << 15 << 14 << QDeclarativeTextInput::SelectWords << 14 << 15 << false;
QTest::newRow("<()> spacey text |words")
<< standard[4] << 0 << 0 << QDeclarativeTextInput::SelectWords << 0 << 0 << false;
QTest::newRow(" spacey text <()>|words")
@@ -857,23 +855,21 @@ void tst_qdeclarativetextinput::moveCursorSelectionSequence_data()
<< 15 << 12 << 15
<< 10 << 15
<< 15 << 15;
-// QTBUG-11365
-// QTest::newRow(" spacey <te(xt{^ )>}|rtl")
-// << standard[4]
-// << 15 << 12 << 14
-// << 10 << 15
-// << 14 << 15;
+ QTest::newRow(" spacey <te(xt{^ )>}|rtl")
+ << standard[4]
+ << 15 << 12 << 14
+ << 10 << 15
+ << 14 << 15;
QTest::newRow(" spacey {<te(x^t} )>|ltr")
<< standard[4]
<< 12 << 15 << 13
<< 10 << 15
<< 10 << 14;
-// QTBUG-11365
-// QTest::newRow(" spacey {<te(xt^} )>|ltr")
-// << standard[4]
-// << 12 << 15 << 14
-// << 10 << 15
-// << 10 << 14;
+ QTest::newRow(" spacey {<te(xt^} )>|ltr")
+ << standard[4]
+ << 12 << 15 << 14
+ << 10 << 15
+ << 10 << 14;
}
void tst_qdeclarativetextinput::moveCursorSelectionSequence()
@@ -1633,12 +1629,11 @@ void tst_qdeclarativetextinput::cursorDelegate()
//Test Delegate gets moved
for(int i=0; i<= textInputObject->text().length(); i++){
textInputObject->setCursorPosition(i);
- //+5 is because the TextInput cursorRectangle is just a 10xHeight area centered on cursor position
- QCOMPARE(textInputObject->cursorRectangle().x() + 5, qRound(delegateObject->x()));
+ QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x()));
QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y()));
}
textInputObject->setCursorPosition(0);
- QCOMPARE(textInputObject->cursorRectangle().x()+5, qRound(delegateObject->x()));
+ QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x()));
QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y()));
//Test Delegate gets deleted
textInputObject->setCursorDelegate(0);
@@ -1727,19 +1722,26 @@ void tst_qdeclarativetextinput::cursorRectangle()
QRect r;
+ // some tolerance for different fonts.
+#ifdef Q_OS_LINUX
+ const int error = 2;
+#else
+ const int error = 5;
+#endif
+
for (int i = 0; i <= 5; ++i) {
input.setCursorPosition(i);
r = input.cursorRectangle();
int textWidth = fm.width(text.mid(0, i));
- QVERIFY(r.left() < textWidth);
- QVERIFY(r.right() > textWidth);
+ QVERIFY(r.left() < textWidth + error);
+ QVERIFY(r.right() > textWidth - error);
QCOMPARE(input.inputMethodQuery(Qt::ImMicroFocus).toRect(), r);
}
// Check the cursor rectangle remains within the input bounding rect when auto scrolling.
QVERIFY(r.left() < input.boundingRect().width());
- QVERIFY(r.right() >= input.width());
+ QVERIFY(r.right() >= input.width() - error);
for (int i = 6; i < text.length(); ++i) {
input.setCursorPosition(i);
@@ -2240,18 +2242,25 @@ void tst_qdeclarativetextinput::preeditAutoScroll()
QCOMPARE(input.positionAt(0), 0);
QCOMPARE(input.positionAt(input.width()), 5);
+ // some tolerance for different fonts.
+#ifdef Q_OS_LINUX
+ const int error = 2;
+#else
+ const int error = 5;
+#endif
+
// test if the preedit is larger than the text input that the
// character preceding the cursor is still visible.
qreal x = input.positionToRectangle(0).x();
for (int i = 0; i < 3; ++i) {
ic.sendPreeditText(preeditText, i + 1);
- QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i)));
+ QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i)) - error);
QVERIFY(input.positionToRectangle(0).x() < x);
x = input.positionToRectangle(0).x();
}
for (int i = 1; i >= 0; --i) {
ic.sendPreeditText(preeditText, i + 1);
- QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i)));
+ QVERIFY(input.cursorRectangle().right() >= fm.width(preeditText.at(i)) - error);
QVERIFY(input.positionToRectangle(0).x() > x);
x = input.positionToRectangle(0).x();
}
@@ -2489,6 +2498,26 @@ void tst_qdeclarativetextinput::inputMethodComposing()
QCOMPARE(spy.count(), 2);
}
+void tst_qdeclarativetextinput::cursorRectangleSize()
+{
+ QDeclarativeView *canvas = createView(SRCDIR "/data/positionAt.qml");
+ QVERIFY(canvas->rootObject() != 0);
+ canvas->show();
+ canvas->setFocus();
+ QApplication::setActiveWindow(canvas);
+ QTest::qWaitForWindowShown(canvas);
+
+ QDeclarativeTextInput *textInput = qobject_cast<QDeclarativeTextInput *>(canvas->rootObject());
+ QVERIFY(textInput != 0);
+ textInput->setFocus(Qt::OtherFocusReason);
+ QRectF cursorRect = textInput->positionToRectangle(textInput->cursorPosition());
+ QRectF microFocusFromScene = canvas->scene()->inputMethodQuery(Qt::ImMicroFocus).toRectF();
+ QRectF microFocusFromApp= QApplication::focusWidget()->inputMethodQuery(Qt::ImMicroFocus).toRectF();
+
+ QCOMPARE(microFocusFromScene.size(), cursorRect.size());
+ QCOMPARE(microFocusFromApp.size(), cursorRect.size());
+}
+
QTEST_MAIN(tst_qdeclarativetextinput)
#include "tst_qdeclarativetextinput.moc"