--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp Fri Sep 17 08:34:18 2010 +0300
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp Mon Oct 04 01:19:32 2010 +0300
@@ -98,6 +98,7 @@
void validators();
void inputMethods();
+ void passwordCharacter();
void cursorDelegate();
void navigation();
void copyAndPaste();
@@ -193,7 +194,7 @@
QDeclarativeTextInput *textinputObject = qobject_cast<QDeclarativeTextInput*>(textinputComponent.create());
QVERIFY(textinputObject != 0);
- int delta = abs(int(textinputObject->width()) - metricWidth);
+ int delta = abs(int(int(textinputObject->width()) - metricWidth));
QVERIFY(delta <= 3.0); // As best as we can hope for cross-platform.
delete textinputObject;
@@ -450,7 +451,7 @@
QFontMetrics fm(textinputObject->font());
int pos = textinputObject->positionAt(textinputObject->width()/2);
- int diff = abs(fm.width(textinputObject->text()) - (fm.width(textinputObject->text().left(pos))+textinputObject->width()/2));
+ int diff = abs(int(fm.width(textinputObject->text()) - (fm.width(textinputObject->text().left(pos))+textinputObject->width()/2)));
// some tollerance for different fonts.
#ifdef Q_OS_LINUX
@@ -462,7 +463,7 @@
// Check without autoscroll...
textinputObject->setAutoScroll(false);
pos = textinputObject->positionAt(textinputObject->width()/2);
- diff = abs(fm.width(textinputObject->text().left(pos))-textinputObject->width()/2);
+ diff = abs(int(fm.width(textinputObject->text().left(pos))-textinputObject->width()/2));
// some tollerance for different fonts.
#ifdef Q_OS_LINUX
@@ -741,9 +742,48 @@
textInput->paste();
QCOMPARE(textInput->text(), QString("Hello world!Hello world!"));
QCOMPARE(textInput->text().length(), 24);
+
+ // clear copy buffer
+ QClipboard *clipboard = QApplication::clipboard();
+ QVERIFY(clipboard);
+ clipboard->clear();
+
+ // test that copy functionality is disabled
+ // when echo mode is set to hide text/password mode
+ int index = 0;
+ while (index < 4) {
+ QDeclarativeTextInput::EchoMode echoMode = QDeclarativeTextInput::EchoMode(index);
+ textInput->setEchoMode(echoMode);
+ textInput->setText("My password");
+ textInput->select(0, textInput->text().length());;
+ textInput->copy();
+ if (echoMode == QDeclarativeTextInput::Normal) {
+ QVERIFY(!clipboard->text().isEmpty());
+ QCOMPARE(clipboard->text(), QString("My password"));
+ clipboard->clear();
+ } else {
+ QVERIFY(clipboard->text().isEmpty());
+ }
+ index++;
+ }
#endif
}
+void tst_qdeclarativetextinput::passwordCharacter()
+{
+ QString componentStr = "import Qt 4.7\nTextInput { text: \"Hello world!\"; font.family: \"Helvetica\"; echoMode: TextInput.Password }";
+ QDeclarativeComponent textInputComponent(&engine);
+ textInputComponent.setData(componentStr.toLatin1(), QUrl());
+ QDeclarativeTextInput *textInput = qobject_cast<QDeclarativeTextInput*>(textInputComponent.create());
+ QVERIFY(textInput != 0);
+
+ textInput->setPasswordCharacter("X");
+ QSize contentsSize = textInput->contentsSize();
+ textInput->setPasswordCharacter(".");
+ // QTBUG-12383 content is updated and redrawn
+ QVERIFY(contentsSize != textInput->contentsSize());
+}
+
void tst_qdeclarativetextinput::cursorDelegate()
{
QDeclarativeView* view = createView(SRCDIR "/data/cursorTest.qml");
@@ -998,7 +1038,7 @@
QApplication::processEvents();
QCOMPARE(ic.openInputPanelReceived, true);
ic.openInputPanelReceived = false;
- QCOMPARE(view.inputContext(), &ic);
+ QCOMPARE(view.inputContext(), (QInputContext*)&ic);
QVERIFY(view.testAttribute(Qt::WA_InputMethodEnabled));
// input method should be disabled if focus