Add tests for Text(*) default property values and notifiers.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Tue, 24 Jul 2012 05:54:28 +0000 (15:54 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 30 Jul 2012 05:18:57 +0000 (07:18 +0200)
Change-Id: I64bfe285ab4ddad53a4d323ca93b15ea0426ed51
Reviewed-by: Damian Jansen <damian.jansen@nokia.com>
tests/auto/quick/qquicktext/tst_qquicktext.cpp
tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index e6368c0..deaaa13 100644 (file)
@@ -102,6 +102,7 @@ private slots:
     void style();
     void color();
     void smooth();
+    void renderType();
 
     // QQuickFontValueType
     void weight();
@@ -437,6 +438,29 @@ void tst_qquicktext::wrap()
 
         delete textObject;
     }
+
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n Text {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickText *textObject = qobject_cast<QQuickText *>(object.data());
+        QVERIFY(textObject);
+
+        QSignalSpy spy(textObject, SIGNAL(wrapModeChanged()));
+
+        QCOMPARE(textObject->wrapMode(), QQuickText::NoWrap);
+
+        textObject->setWrapMode(QQuickText::Wrap);
+        QCOMPARE(textObject->wrapMode(), QQuickText::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        textObject->setWrapMode(QQuickText::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        textObject->setWrapMode(QQuickText::NoWrap);
+        QCOMPARE(textObject->wrapMode(), QQuickText::NoWrap);
+        QCOMPARE(spy.count(), 2);
+    }
 }
 
 void tst_qquicktext::elide()
@@ -640,6 +664,29 @@ void tst_qquicktext::textFormat()
 
         delete textObject;
     }
+
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n Text {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickText *text = qobject_cast<QQuickText *>(object.data());
+        QVERIFY(text);
+
+        QSignalSpy spy(text, SIGNAL(textFormatChanged(TextFormat)));
+
+        QCOMPARE(text->textFormat(), QQuickText::AutoText);
+
+        text->setTextFormat(QQuickText::StyledText);
+        QCOMPARE(text->textFormat(), QQuickText::StyledText);
+        QCOMPARE(spy.count(), 1);
+
+        text->setTextFormat(QQuickText::StyledText);
+        QCOMPARE(spy.count(), 1);
+
+        text->setTextFormat(QQuickText::AutoText);
+        QCOMPARE(text->textFormat(), QQuickText::AutoText);
+        QCOMPARE(spy.count(), 2);
+    }
 }
 
 
@@ -1077,6 +1124,31 @@ void tst_qquicktext::color()
         QCOMPARE(textObject->color(), QColor("black"));
         QCOMPARE(textObject->linkColor(), QColor("blue"));
 
+        QSignalSpy colorSpy(textObject, SIGNAL(colorChanged()));
+        QSignalSpy linkColorSpy(textObject, SIGNAL(linkColorChanged()));
+
+        textObject->setColor(QColor("white"));
+        QCOMPARE(textObject->color(), QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textObject->setLinkColor(QColor("black"));
+        QCOMPARE(textObject->linkColor(), QColor("black"));
+        QCOMPARE(linkColorSpy.count(), 1);
+
+        textObject->setColor(QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textObject->setLinkColor(QColor("black"));
+        QCOMPARE(linkColorSpy.count(), 1);
+
+        textObject->setColor(QColor("black"));
+        QCOMPARE(textObject->color(), QColor("black"));
+        QCOMPARE(colorSpy.count(), 2);
+
+        textObject->setLinkColor(QColor("blue"));
+        QCOMPARE(textObject->linkColor(), QColor("blue"));
+        QCOMPARE(linkColorSpy.count(), 2);
+
         delete textObject;
     }
 
@@ -1239,6 +1311,30 @@ void tst_qquicktext::smooth()
     }
 }
 
+void tst_qquicktext::renderType()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n Text {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickText *text = qobject_cast<QQuickText *>(object.data());
+    QVERIFY(text);
+
+    QSignalSpy spy(text, SIGNAL(renderTypeChanged()));
+
+    QCOMPARE(text->renderType(), QQuickText::QtRendering);
+
+    text->setRenderType(QQuickText::NativeRendering);
+    QCOMPARE(text->renderType(), QQuickText::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    text->setRenderType(QQuickText::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    text->setRenderType(QQuickText::QtRendering);
+    QCOMPARE(text->renderType(), QQuickText::QtRendering);
+    QCOMPARE(spy.count(), 2);
+}
+
 void tst_qquicktext::weight()
 {
     {
@@ -1437,9 +1533,6 @@ void tst_qquicktext::wordSpacing()
     }
 }
 
-
-
-
 class EventSender : public QQuickItem
 {
 public:
index 3e74b58..6684e68 100644 (file)
@@ -132,6 +132,9 @@ private slots:
     void mouseSelectionMode_data();
     void mouseSelectionMode();
     void dragMouseSelection();
+    void mouseSelectionMode_accessors();
+    void selectByMouse();
+    void renderType();
     void inputMethodHints();
 
     void positionAt_data();
@@ -532,6 +535,28 @@ void tst_qquicktextedit::wrap()
         QVERIFY(textEditObject != 0);
         QCOMPARE(textEditObject->width(), 300.);
     }
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n TextEdit {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(object.data());
+        QVERIFY(edit);
+
+        QSignalSpy spy(edit, SIGNAL(wrapModeChanged()));
+
+        QCOMPARE(edit->wrapMode(), QQuickTextEdit::NoWrap);
+
+        edit->setWrapMode(QQuickTextEdit::Wrap);
+        QCOMPARE(edit->wrapMode(), QQuickTextEdit::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        edit->setWrapMode(QQuickTextEdit::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        edit->setWrapMode(QQuickTextEdit::NoWrap);
+        QCOMPARE(edit->wrapMode(), QQuickTextEdit::NoWrap);
+        QCOMPARE(spy.count(), 2);
+    }
 
 }
 
@@ -553,6 +578,28 @@ void tst_qquicktextedit::textFormat()
         QVERIFY(textObject != 0);
         QVERIFY(textObject->textFormat() == QQuickTextEdit::PlainText);
     }
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n TextEdit {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(object.data());
+        QVERIFY(edit);
+
+        QSignalSpy spy(edit, SIGNAL(textFormatChanged(TextFormat)));
+
+        QCOMPARE(edit->textFormat(), QQuickTextEdit::PlainText);
+
+        edit->setTextFormat(QQuickTextEdit::RichText);
+        QCOMPARE(edit->textFormat(), QQuickTextEdit::RichText);
+        QCOMPARE(spy.count(), 1);
+
+        edit->setTextFormat(QQuickTextEdit::RichText);
+        QCOMPARE(spy.count(), 1);
+
+        edit->setTextFormat(QQuickTextEdit::PlainText);
+        QCOMPARE(edit->textFormat(), QQuickTextEdit::PlainText);
+        QCOMPARE(spy.count(), 2);
+    }
 }
 
 void tst_qquicktextedit::alignments_data()
@@ -1013,13 +1060,49 @@ void tst_qquicktextedit::color()
         texteditComponent.setData(componentStr.toLatin1(), QUrl());
         QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit*>(texteditComponent.create());
 
-        QQuickTextEditPrivate *textEditPrivate = static_cast<QQuickTextEditPrivate*>(QQuickItemPrivate::get(textEditObject));
-
         QVERIFY(textEditObject);
-        QVERIFY(textEditPrivate);
-        QVERIFY(textEditPrivate->control);
-        QCOMPARE(textEditPrivate->color, QColor("black"));
+        QCOMPARE(textEditObject->color(), QColor("black"));
+        QCOMPARE(textEditObject->selectionColor(), QColor::fromRgba(0xFF000080));
+        QCOMPARE(textEditObject->selectedTextColor(), QColor("white"));
+
+        QSignalSpy colorSpy(textEditObject, SIGNAL(colorChanged(QColor)));
+        QSignalSpy selectionColorSpy(textEditObject, SIGNAL(selectionColorChanged(QColor)));
+        QSignalSpy selectedTextColorSpy(textEditObject, SIGNAL(selectedTextColorChanged(QColor)));
+
+        textEditObject->setColor(QColor("white"));
+        QCOMPARE(textEditObject->color(), QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textEditObject->setSelectionColor(QColor("black"));
+        QCOMPARE(textEditObject->selectionColor(), QColor("black"));
+        QCOMPARE(selectionColorSpy.count(), 1);
+
+        textEditObject->setSelectedTextColor(QColor("blue"));
+        QCOMPARE(textEditObject->selectedTextColor(), QColor("blue"));
+        QCOMPARE(selectedTextColorSpy.count(), 1);
+
+        textEditObject->setColor(QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textEditObject->setSelectionColor(QColor("black"));
+        QCOMPARE(selectionColorSpy.count(), 1);
+
+        textEditObject->setSelectedTextColor(QColor("blue"));
+        QCOMPARE(selectedTextColorSpy.count(), 1);
+
+        textEditObject->setColor(QColor("black"));
+        QCOMPARE(textEditObject->color(), QColor("black"));
+        QCOMPARE(colorSpy.count(), 2);
+
+        textEditObject->setSelectionColor(QColor("blue"));
+        QCOMPARE(textEditObject->selectionColor(), QColor("blue"));
+        QCOMPARE(selectionColorSpy.count(), 2);
+
+        textEditObject->setSelectedTextColor(QColor("white"));
+        QCOMPARE(textEditObject->selectedTextColor(), QColor("white"));
+        QCOMPARE(selectedTextColorSpy.count(), 2);
     }
+
     //test normal
     for (int i = 0; i < colorStrings.size(); i++)
     {
@@ -1929,6 +2012,80 @@ void tst_qquicktextedit::mouseSelectionMode()
     }
 }
 
+void tst_qquicktextedit::mouseSelectionMode_accessors()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n TextEdit {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(object.data());
+    QVERIFY(edit);
+
+    QSignalSpy spy(edit, SIGNAL(mouseSelectionModeChanged(SelectionMode)));
+
+    QCOMPARE(edit->mouseSelectionMode(), QQuickTextEdit::SelectCharacters);
+
+    edit->setMouseSelectionMode(QQuickTextEdit::SelectWords);
+    QCOMPARE(edit->mouseSelectionMode(), QQuickTextEdit::SelectWords);
+    QCOMPARE(spy.count(), 1);
+
+    edit->setMouseSelectionMode(QQuickTextEdit::SelectWords);
+    QCOMPARE(spy.count(), 1);
+
+    edit->setMouseSelectionMode(QQuickTextEdit::SelectCharacters);
+    QCOMPARE(edit->mouseSelectionMode(), QQuickTextEdit::SelectCharacters);
+    QCOMPARE(spy.count(), 2);
+}
+
+void tst_qquicktextedit::selectByMouse()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n TextEdit {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(object.data());
+    QVERIFY(edit);
+
+    QSignalSpy spy(edit, SIGNAL(selectByMouseChanged(bool)));
+
+    QCOMPARE(edit->selectByMouse(), false);
+
+    edit->setSelectByMouse(true);
+    QCOMPARE(edit->selectByMouse(), true);
+    QCOMPARE(spy.count(), 1);
+    QCOMPARE(spy.at(0).at(0).toBool(), true);
+
+    edit->setSelectByMouse(true);
+    QCOMPARE(spy.count(), 1);
+
+    edit->setSelectByMouse(false);
+    QCOMPARE(edit->selectByMouse(), false);
+    QCOMPARE(spy.count(), 2);
+    QCOMPARE(spy.at(1).at(0).toBool(), false);
+}
+
+void tst_qquicktextedit::renderType()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n TextEdit {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickTextEdit *edit = qobject_cast<QQuickTextEdit *>(object.data());
+    QVERIFY(edit);
+
+    QSignalSpy spy(edit, SIGNAL(renderTypeChanged()));
+
+    QCOMPARE(edit->renderType(), QQuickTextEdit::QtRendering);
+
+    edit->setRenderType(QQuickTextEdit::NativeRendering);
+    QCOMPARE(edit->renderType(), QQuickTextEdit::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    edit->setRenderType(QQuickTextEdit::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    edit->setRenderType(QQuickTextEdit::QtRendering);
+    QCOMPARE(edit->renderType(), QQuickTextEdit::QtRendering);
+    QCOMPARE(spy.count(), 2);
+}
+
 void tst_qquicktextedit::inputMethodHints()
 {
     QQuickView window(testFileUrl("inputmethodhints.qml"));
index 3bdaf2e..09d2119 100644 (file)
@@ -126,6 +126,9 @@ private slots:
     void dragMouseSelection();
     void mouseSelectionMode_data();
     void mouseSelectionMode();
+    void mouseSelectionMode_accessors();
+    void selectByMouse();
+    void renderType();
     void tripleClickSelectsAll();
 
     void horizontalAlignment_data();
@@ -468,6 +471,57 @@ void tst_qquicktextinput::font()
 
 void tst_qquicktextinput::color()
 {
+    //test initial color
+    {
+        QString componentStr = "import QtQuick 2.0\nTextInput { text: \"Hello World\" }";
+        QQmlComponent texteditComponent(&engine);
+        texteditComponent.setData(componentStr.toLatin1(), QUrl());
+        QScopedPointer<QObject> object(texteditComponent.create());
+        QQuickTextInput *textInputObject = qobject_cast<QQuickTextInput*>(object.data());
+
+        QVERIFY(textInputObject);
+        QCOMPARE(textInputObject->color(), QColor("black"));
+        QCOMPARE(textInputObject->selectionColor(), QColor::fromRgba(0xFF000080));
+        QCOMPARE(textInputObject->selectedTextColor(), QColor("white"));
+
+        QSignalSpy colorSpy(textInputObject, SIGNAL(colorChanged()));
+        QSignalSpy selectionColorSpy(textInputObject, SIGNAL(selectionColorChanged()));
+        QSignalSpy selectedTextColorSpy(textInputObject, SIGNAL(selectedTextColorChanged()));
+
+        textInputObject->setColor(QColor("white"));
+        QCOMPARE(textInputObject->color(), QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textInputObject->setSelectionColor(QColor("black"));
+        QCOMPARE(textInputObject->selectionColor(), QColor("black"));
+        QCOMPARE(selectionColorSpy.count(), 1);
+
+        textInputObject->setSelectedTextColor(QColor("blue"));
+        QCOMPARE(textInputObject->selectedTextColor(), QColor("blue"));
+        QCOMPARE(selectedTextColorSpy.count(), 1);
+
+        textInputObject->setColor(QColor("white"));
+        QCOMPARE(colorSpy.count(), 1);
+
+        textInputObject->setSelectionColor(QColor("black"));
+        QCOMPARE(selectionColorSpy.count(), 1);
+
+        textInputObject->setSelectedTextColor(QColor("blue"));
+        QCOMPARE(selectedTextColorSpy.count(), 1);
+
+        textInputObject->setColor(QColor("black"));
+        QCOMPARE(textInputObject->color(), QColor("black"));
+        QCOMPARE(colorSpy.count(), 2);
+
+        textInputObject->setSelectionColor(QColor("blue"));
+        QCOMPARE(textInputObject->selectionColor(), QColor("blue"));
+        QCOMPARE(selectionColorSpy.count(), 2);
+
+        textInputObject->setSelectedTextColor(QColor("white"));
+        QCOMPARE(textInputObject->selectedTextColor(), QColor("white"));
+        QCOMPARE(selectedTextColorSpy.count(), 2);
+    }
+
     //test color
     for (int i = 0; i < colorStrings.size(); i++)
     {
@@ -557,6 +611,29 @@ void tst_qquicktextinput::wrap()
 
         delete textObject;
     }
+
+    {
+        QQmlComponent component(&engine);
+        component.setData("import QtQuick 2.0\n TextInput {}", QUrl());
+        QScopedPointer<QObject> object(component.create());
+        QQuickTextInput *input = qobject_cast<QQuickTextInput *>(object.data());
+        QVERIFY(input);
+
+        QSignalSpy spy(input, SIGNAL(wrapModeChanged()));
+
+        QCOMPARE(input->wrapMode(), QQuickTextInput::NoWrap);
+
+        input->setWrapMode(QQuickTextInput::Wrap);
+        QCOMPARE(input->wrapMode(), QQuickTextInput::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        input->setWrapMode(QQuickTextInput::Wrap);
+        QCOMPARE(spy.count(), 1);
+
+        input->setWrapMode(QQuickTextInput::NoWrap);
+        QCOMPARE(input->wrapMode(), QQuickTextInput::NoWrap);
+        QCOMPARE(spy.count(), 2);
+    }
 }
 
 void tst_qquicktextinput::selection()
@@ -1262,6 +1339,80 @@ void tst_qquicktextinput::mouseSelectionMode()
     }
 }
 
+void tst_qquicktextinput::mouseSelectionMode_accessors()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n TextInput {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickTextInput *input = qobject_cast<QQuickTextInput *>(object.data());
+    QVERIFY(input);
+
+    QSignalSpy spy(input, SIGNAL(mouseSelectionModeChanged(SelectionMode)));
+
+    QCOMPARE(input->mouseSelectionMode(), QQuickTextInput::SelectCharacters);
+
+    input->setMouseSelectionMode(QQuickTextInput::SelectWords);
+    QCOMPARE(input->mouseSelectionMode(), QQuickTextInput::SelectWords);
+    QCOMPARE(spy.count(), 1);
+
+    input->setMouseSelectionMode(QQuickTextInput::SelectWords);
+    QCOMPARE(spy.count(), 1);
+
+    input->setMouseSelectionMode(QQuickTextInput::SelectCharacters);
+    QCOMPARE(input->mouseSelectionMode(), QQuickTextInput::SelectCharacters);
+    QCOMPARE(spy.count(), 2);
+}
+
+void tst_qquicktextinput::selectByMouse()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n TextInput {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickTextInput *input = qobject_cast<QQuickTextInput *>(object.data());
+    QVERIFY(input);
+
+    QSignalSpy spy(input, SIGNAL(selectByMouseChanged(bool)));
+
+    QCOMPARE(input->selectByMouse(), false);
+
+    input->setSelectByMouse(true);
+    QCOMPARE(input->selectByMouse(), true);
+    QCOMPARE(spy.count(), 1);
+    QCOMPARE(spy.at(0).at(0).toBool(), true);
+
+    input->setSelectByMouse(true);
+    QCOMPARE(spy.count(), 1);
+
+    input->setSelectByMouse(false);
+    QCOMPARE(input->selectByMouse(), false);
+    QCOMPARE(spy.count(), 2);
+    QCOMPARE(spy.at(1).at(0).toBool(), false);
+}
+
+void tst_qquicktextinput::renderType()
+{
+    QQmlComponent component(&engine);
+    component.setData("import QtQuick 2.0\n TextInput {}", QUrl());
+    QScopedPointer<QObject> object(component.create());
+    QQuickTextInput *input = qobject_cast<QQuickTextInput *>(object.data());
+    QVERIFY(input);
+
+    QSignalSpy spy(input, SIGNAL(renderTypeChanged()));
+
+    QCOMPARE(input->renderType(), QQuickTextInput::QtRendering);
+
+    input->setRenderType(QQuickTextInput::NativeRendering);
+    QCOMPARE(input->renderType(), QQuickTextInput::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    input->setRenderType(QQuickTextInput::NativeRendering);
+    QCOMPARE(spy.count(), 1);
+
+    input->setRenderType(QQuickTextInput::QtRendering);
+    QCOMPARE(input->renderType(), QQuickTextInput::QtRendering);
+    QCOMPARE(spy.count(), 2);
+}
+
 void tst_qquicktextinput::horizontalAlignment_data()
 {
     QTest::addColumn<int>("hAlign");