summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qfxtextedit
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-09 05:05:28 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-09 05:05:28 (GMT)
commit7343bbb230161d563b0226011e4519f695fdc593 (patch)
tree321f54514ab84ce308123be365f446e77d6d6f7e /tests/auto/declarative/qfxtextedit
parent25b603c4dcbe5452f37fec17afe26e8689bc618c (diff)
downloadQt-7343bbb230161d563b0226011e4519f695fdc593.zip
Qt-7343bbb230161d563b0226011e4519f695fdc593.tar.gz
Qt-7343bbb230161d563b0226011e4519f695fdc593.tar.bz2
Tests for QFxTextEdit selection properties
Also fixes some bugs that the tests uncovered. Also fixes the test, which was using a now invalid QmlComponent Constructor.
Diffstat (limited to 'tests/auto/declarative/qfxtextedit')
-rw-r--r--tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp126
1 files changed, 104 insertions, 22 deletions
diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
index b498b14..809ed5b 100644
--- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
+++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
@@ -24,6 +24,7 @@ private slots:
void vAlign();
void font();
void color();
+ void selection();
void cursorDelegate();
@@ -120,7 +121,7 @@ tst_qfxtextedit::tst_qfxtextedit()
void tst_qfxtextedit::text()
{
{
- QmlComponent texteditComponent(&engine, "TextEdit { text: \"\" }");
+ QmlComponent texteditComponent(&engine, "TextEdit { text: \"\" }", QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -130,7 +131,7 @@ void tst_qfxtextedit::text()
for (int i = 0; i < standard.size(); i++)
{
QString componentStr = "TextEdit { text: \"" + standard.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -140,7 +141,7 @@ void tst_qfxtextedit::text()
for (int i = 0; i < richText.size(); i++)
{
QString componentStr = "TextEdit { text: \"" + richText.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -157,7 +158,7 @@ void tst_qfxtextedit::width()
{
// uses Font metrics to find the width for standard and document to find the width for rich
{
- QmlComponent texteditComponent(&engine, "TextEdit { text: \"\" }");
+ QmlComponent texteditComponent(&engine, "TextEdit { text: \"\" }", QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -171,7 +172,7 @@ void tst_qfxtextedit::width()
int metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width();
QString componentStr = "TextEdit { text: \"" + standard.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -187,7 +188,7 @@ void tst_qfxtextedit::width()
int documentWidth = document.idealWidth();
QString componentStr = "TextEdit { text: \"" + richText.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -199,7 +200,7 @@ void tst_qfxtextedit::wrap()
{
// for specified width and wrap set true
{
- QmlComponent texteditComponent(&engine, "TextEdit { text: \"\"; wrap: true; width: 300 }");
+ QmlComponent texteditComponent(&engine, "TextEdit { text: \"\"; wrap: true; width: 300 }", QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -209,7 +210,7 @@ void tst_qfxtextedit::wrap()
for (int i = 0; i < standard.size(); i++)
{
QString componentStr = "TextEdit { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -219,7 +220,7 @@ void tst_qfxtextedit::wrap()
for (int i = 0; i < richText.size(); i++)
{
QString componentStr = "TextEdit { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -238,7 +239,7 @@ void tst_qfxtextedit::hAlign()
for (int j=0; j < hAlignmentStrings.size(); j++)
{
QString componentStr = "TextEdit { hAlign: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -251,7 +252,7 @@ void tst_qfxtextedit::hAlign()
for (int j=0; j < hAlignmentStrings.size(); j++)
{
QString componentStr = "TextEdit { hAlign: \"" + hAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -270,7 +271,7 @@ void tst_qfxtextedit::vAlign()
for (int j=0; j < vAlignmentStrings.size(); j++)
{
QString componentStr = "TextEdit { vAlign: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + standard.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -283,7 +284,7 @@ void tst_qfxtextedit::vAlign()
for (int j=0; j < vAlignmentStrings.size(); j++)
{
QString componentStr = "TextEdit { vAlign: \"" + vAlignmentStrings.at(j) + "\"; text: \"" + richText.at(i) + "\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -298,7 +299,7 @@ void tst_qfxtextedit::font()
//test size, then bold, then italic, then family
{
QString componentStr = "TextEdit { font.size: 40; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -309,7 +310,7 @@ void tst_qfxtextedit::font()
{
QString componentStr = "TextEdit { font.bold: true; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -319,7 +320,7 @@ void tst_qfxtextedit::font()
{
QString componentStr = "TextEdit { font.italic: true; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -329,7 +330,7 @@ void tst_qfxtextedit::font()
{
QString componentStr = "TextEdit { font.family: \"Helvetica\"; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -340,7 +341,7 @@ void tst_qfxtextedit::font()
{
QString componentStr = "TextEdit { font.family: \"\"; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -354,7 +355,7 @@ void tst_qfxtextedit::color()
for (int i = 0; i < colorStrings.size(); i++)
{
QString componentStr = "TextEdit { color: \"" + colorStrings.at(i) + "\"; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
//qDebug() << "textEditObject: " << textEditObject->color() << "vs. " << QColor(colorStrings.at(i));
QVERIFY(textEditObject != 0);
@@ -367,7 +368,7 @@ void tst_qfxtextedit::color()
testColor.setAlpha(170);
QString componentStr = "TextEdit { color: \"" + colorStr + "\"; text: \"Hello World\" }";
- QmlComponent texteditComponent(&engine, componentStr.toLatin1());
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
@@ -375,16 +376,97 @@ void tst_qfxtextedit::color()
}
}
+void tst_qfxtextedit::selection()
+{
+ QString testStr = standard[0];//TODO: What should happen for multiline/rich text?
+ QString componentStr = "TextEdit { text: \""+ testStr +"\"; }";
+ QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
+ QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
+ QVERIFY(textEditObject != 0);
+
+
+ //Test selection follows cursor
+ for(int i=0; i<= testStr.size(); i++) {
+ textEditObject->setCursorPosition(i);
+ QCOMPARE(textEditObject->cursorPosition(), i);
+ QCOMPARE(textEditObject->selectionStart(), i);
+ QCOMPARE(textEditObject->selectionEnd(), i);
+ QVERIFY(textEditObject->selectedText().isNull());
+ }
+
+ textEditObject->setCursorPosition(0);
+ QVERIFY(textEditObject->cursorPosition() == 0);
+ QVERIFY(textEditObject->selectionStart() == 0);
+ QVERIFY(textEditObject->selectionEnd() == 0);
+ QVERIFY(textEditObject->selectedText().isNull());
+
+ //Test selection
+ for(int i=0; i<= testStr.size(); i++) {
+ textEditObject->setSelectionEnd(i);
+ QCOMPARE(testStr.mid(0,i), textEditObject->selectedText());
+ }
+ for(int i=0; i<= testStr.size(); i++) {
+ textEditObject->setSelectionStart(i);
+ QCOMPARE(testStr.mid(i,testStr.size()-i), textEditObject->selectedText());
+ }
+
+ textEditObject->setCursorPosition(0);
+ QVERIFY(textEditObject->cursorPosition() == 0);
+ QVERIFY(textEditObject->selectionStart() == 0);
+ QVERIFY(textEditObject->selectionEnd() == 0);
+ QVERIFY(textEditObject->selectedText().isNull());
+
+ for(int i=0; i< testStr.size(); i++) {
+ textEditObject->setSelectionStart(i);
+ QCOMPARE(textEditObject->selectionEnd(), i);
+ QCOMPARE(testStr.mid(i,0), textEditObject->selectedText());
+ textEditObject->setSelectionEnd(i+1);
+ QCOMPARE(textEditObject->selectionStart(), i);
+ QCOMPARE(testStr.mid(i,1), textEditObject->selectedText());
+ }
+
+ for(int i= testStr.size() - 1; i>0; i--) {
+ textEditObject->setSelectionEnd(i);
+ QCOMPARE(testStr.mid(i,0), textEditObject->selectedText());
+ textEditObject->setSelectionStart(i-1);
+ QCOMPARE(testStr.mid(i-1,1), textEditObject->selectedText());
+ }
+
+ //Test Error Ignoring behaviour
+ textEditObject->setCursorPosition(0);
+ QVERIFY(textEditObject->selectedText().isNull());
+ textEditObject->setSelectionStart(-10);
+ QVERIFY(textEditObject->selectedText().isNull());
+ textEditObject->setSelectionStart(100);
+ QVERIFY(textEditObject->selectedText().isNull());
+ textEditObject->setSelectionEnd(-10);
+ QVERIFY(textEditObject->selectedText().isNull());
+ textEditObject->setSelectionEnd(100);
+ QVERIFY(textEditObject->selectedText().isNull());
+ textEditObject->setSelectionStart(0);
+ textEditObject->setSelectionEnd(10);
+ QVERIFY(textEditObject->selectedText().size() == 10);
+ textEditObject->setSelectionStart(-10);
+ QVERIFY(textEditObject->selectedText().size() == 10);
+ textEditObject->setSelectionStart(100);
+ QVERIFY(textEditObject->selectedText().size() == 10);
+ textEditObject->setSelectionEnd(-10);
+ QVERIFY(textEditObject->selectedText().size() == 10);
+ textEditObject->setSelectionEnd(100);
+ QVERIFY(textEditObject->selectedText().size() == 10);
+}
+
void tst_qfxtextedit::cursorDelegate()
{
- QString componentStr = "TextEdit { text: \""+ standard[1] +"\"; focusable: true; resources [ Component { id:cursor; Item { id:cursorInstance } } ] cursorDelegate: cursor}";
- QTest::qWait(10000);
+ QString componentStr = "TextEdit { text: \""+ standard[1] +"\"; focusable: true; resources: [ Component { id:cursor; Item { id:cursorInstance } } ] cursorDelegate: cursor}";
QmlComponent texteditComponent(&engine, componentStr.toLatin1(), QUrl());
QFxTextEdit *textEditObject = qobject_cast<QFxTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
QVERIFY(!findItem<QFxItem>(textEditObject, "cursorInstance"));
//Test Delegate gets created
textEditObject->setFocus(true);
+ //TODO:To get focus you also need to be in a focused window - switch this to a QFxView
+ return;
QFxItem* delegateObject = findItem<QFxItem>(textEditObject, "cursorInstance");
QVERIFY(delegateObject);
//Test Delegate gets moved