summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-11-09 06:43:51 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-11-09 06:43:51 (GMT)
commit9a00f3fe6a4b6363d96369d976cb9b976c4393fd (patch)
tree15fa0bc0be75556bfb6cd650a8b27f6ef211021c /tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp
parent604bcebbb3b37f5958b97c5178e4d2cb7cdef675 (diff)
downloadQt-9a00f3fe6a4b6363d96369d976cb9b976c4393fd.zip
Qt-9a00f3fe6a4b6363d96369d976cb9b976c4393fd.tar.gz
Qt-9a00f3fe6a4b6363d96369d976cb9b976c4393fd.tar.bz2
Improve coverage of TextEdit tests
Diffstat (limited to 'tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp')
-rw-r--r--tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp65
1 files changed, 64 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp
index 4287f01..2b10df5 100644
--- a/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp
+++ b/tests/auto/declarative/qmlgraphicstextedit/tst_qmlgraphicstextedit.cpp
@@ -62,6 +62,7 @@ private slots:
void text();
void width();
void wrap();
+ void textFormat();
// ### these tests may be trivial
void hAlign();
@@ -72,6 +73,7 @@ private slots:
void cursorDelegate();
void navigation();
+ void readOnly();
private:
void simulateKey(QmlView *, int key);
@@ -246,6 +248,24 @@ void tst_qmlgraphicstextedit::wrap()
}
+void tst_qmlgraphicstextedit::textFormat()
+{
+ {
+ QmlComponent textComponent(&engine, "import Qt 4.6\nTextEdit { text: \"Hello\"; textFormat: Text.RichText }", QUrl("file://"));
+ QmlGraphicsTextEdit *textObject = qobject_cast<QmlGraphicsTextEdit*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->textFormat() == QmlGraphicsTextEdit::RichText);
+ }
+ {
+ QmlComponent textComponent(&engine, "import Qt 4.6\nTextEdit { text: \"<b>Hello</b>\"; textFormat: Text.PlainText }", QUrl("file://"));
+ QmlGraphicsTextEdit *textObject = qobject_cast<QmlGraphicsTextEdit*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->textFormat() == QmlGraphicsTextEdit::PlainText);
+ }
+}
+
//the alignment tests may be trivial o.oa
void tst_qmlgraphicstextedit::hAlign()
{
@@ -368,7 +388,7 @@ void tst_qmlgraphicstextedit::font()
void tst_qmlgraphicstextedit::color()
{
- //test style
+ //test normal
for (int i = 0; i < colorStrings.size(); i++)
{
QString componentStr = "import Qt 4.6\nTextEdit { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
@@ -379,6 +399,26 @@ void tst_qmlgraphicstextedit::color()
QCOMPARE(textEditObject->color(), QColor(colorStrings.at(i)));
}
+ //test selection
+ for (int i = 0; i < colorStrings.size(); i++)
+ {
+ QString componentStr = "import Qt 4.6\nTextEdit { selectionColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
+ QmlGraphicsTextEdit *textEditObject = qobject_cast<QmlGraphicsTextEdit*>(texteditComponent.create());
+ QVERIFY(textEditObject != 0);
+ QCOMPARE(textEditObject->selectionColor(), QColor(colorStrings.at(i)));
+ }
+
+ //test selected text
+ for (int i = 0; i < colorStrings.size(); i++)
+ {
+ QString componentStr = "import Qt 4.6\nTextEdit { selectedTextColor: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
+ QmlGraphicsTextEdit *textEditObject = qobject_cast<QmlGraphicsTextEdit*>(texteditComponent.create());
+ QVERIFY(textEditObject != 0);
+ QCOMPARE(textEditObject->selectedTextColor(), QColor(colorStrings.at(i)));
+ }
+
{
QString colorStr = "#AA001234";
QColor testColor("#001234");
@@ -528,6 +568,29 @@ void tst_qmlgraphicstextedit::navigation()
QVERIFY(input->hasFocus() == true);
}
+void tst_qmlgraphicstextedit::readOnly()
+{
+ QmlView *canvas = createView(SRCDIR "/data/readOnly.qml");
+ canvas->execute();
+ canvas->show();
+ canvas->setFocus();
+
+ QVERIFY(canvas->root() != 0);
+
+ QmlGraphicsTextEdit *edit = qobject_cast<QmlGraphicsTextEdit *>(qvariant_cast<QObject *>(canvas->root()->property("myInput")));
+
+ QVERIFY(edit != 0);
+ QTRY_VERIFY(edit->hasFocus() == true);
+ QVERIFY(edit->isReadOnly() == true);
+ QString initial = edit->text();
+ for(int k=Qt::Key_0; k<=Qt::Key_Z; k++)
+ simulateKey(canvas, k);
+ simulateKey(canvas, Qt::Key_Return);
+ simulateKey(canvas, Qt::Key_Space);
+ simulateKey(canvas, Qt::Key_Escape);
+ QCOMPARE(edit->text(), initial);
+}
+
void tst_qmlgraphicstextedit::simulateKey(QmlView *view, int key)
{
QKeyEvent press(QKeyEvent::KeyPress, key, 0);