summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp')
-rw-r--r--tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp73
1 files changed, 51 insertions, 22 deletions
diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
index f1a367f..5a81881 100644
--- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
+++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp
@@ -53,14 +53,34 @@
#include <private/qdeclarativetextedit_p_p.h>
#include <QFontMetrics>
#include <QDeclarativeView>
+#include <QDir>
#include <QStyle>
#include <QInputContext>
+#include <private/qapplication_p.h>
+#include <private/qtextcontrol_p.h>
#ifdef Q_OS_SYMBIAN
// In Symbian OS test data is located in applications private dir
#define SRCDIR "."
#endif
+QString createExpectedFileIfNotFound(const QString& filebasename, const QImage& actual)
+{
+ // XXX This will be replaced by some clever persistent platform image store.
+ QString persistent_dir = SRCDIR "/data";
+ QString arch = "unknown-architecture"; // QTest needs to help with this.
+
+ QString expectfile = persistent_dir + QDir::separator() + filebasename + "-" + arch + ".png";
+
+ if (!QFile::exists(expectfile)) {
+ actual.save(expectfile);
+ qWarning() << "created" << expectfile;
+ }
+
+ return expectfile;
+}
+
+
class tst_qdeclarativetextedit : public QObject
{
@@ -206,7 +226,7 @@ void tst_qdeclarativetextedit::width()
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->width(), 1.);//+1 for cursor
+ QCOMPARE(textEditObject->width(), 0.0);
}
for (int i = 0; i < standard.size(); i++)
@@ -222,7 +242,7 @@ void tst_qdeclarativetextedit::width()
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->width(), qreal(metricWidth + 1 + 3));//+3 is the current way of accounting for space between cursor and last character.
+ QCOMPARE(textEditObject->width(), qreal(metricWidth));
}
for (int i = 0; i < richText.size(); i++)
@@ -239,7 +259,7 @@ void tst_qdeclarativetextedit::width()
QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
QVERIFY(textEditObject != 0);
- QCOMPARE(textEditObject->width(), qreal(documentWidth + 1 + 3));
+ QCOMPARE(textEditObject->width(), qreal(documentWidth));
}
}
@@ -305,17 +325,17 @@ void tst_qdeclarativetextedit::alignments_data()
QTest::addColumn<int>("vAlign");
QTest::addColumn<QString>("expectfile");
- QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << SRCDIR "/data/alignments_lt.png";
- QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << SRCDIR "/data/alignments_rt.png";
- QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << SRCDIR "/data/alignments_ct.png";
+ QTest::newRow("LT") << int(Qt::AlignLeft) << int(Qt::AlignTop) << "alignments_lt";
+ QTest::newRow("RT") << int(Qt::AlignRight) << int(Qt::AlignTop) << "alignments_rt";
+ QTest::newRow("CT") << int(Qt::AlignHCenter) << int(Qt::AlignTop) << "alignments_ct";
- QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_lb.png";
- QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_rb.png";
- QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << SRCDIR "/data/alignments_cb.png";
+ QTest::newRow("LB") << int(Qt::AlignLeft) << int(Qt::AlignBottom) << "alignments_lb";
+ QTest::newRow("RB") << int(Qt::AlignRight) << int(Qt::AlignBottom) << "alignments_rb";
+ QTest::newRow("CB") << int(Qt::AlignHCenter) << int(Qt::AlignBottom) << "alignments_cb";
- QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_lc.png";
- QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_rc.png";
- QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << SRCDIR "/data/alignments_cc.png";
+ QTest::newRow("LC") << int(Qt::AlignLeft) << int(Qt::AlignVCenter) << "alignments_lc";
+ QTest::newRow("RC") << int(Qt::AlignRight) << int(Qt::AlignVCenter) << "alignments_rc";
+ QTest::newRow("CC") << int(Qt::AlignHCenter) << int(Qt::AlignVCenter) << "alignments_cc";
}
@@ -325,13 +345,6 @@ void tst_qdeclarativetextedit::alignments()
QFETCH(int, vAlign);
QFETCH(QString, expectfile);
-#ifdef Q_WS_X11
- // Font-specific, but not likely platform-specific, so only test on one platform
- QFont fn;
- fn.setRawName("-misc-fixed-medium-r-*-*-8-*-*-*-*-*-*-*");
- QApplication::setFont(fn);
-#endif
-
QDeclarativeView *canvas = createView(SRCDIR "/data/alignments.qml");
canvas->show();
@@ -349,12 +362,11 @@ void tst_qdeclarativetextedit::alignments()
QPainter p(&actual);
canvas->render(&p);
+ expectfile = createExpectedFileIfNotFound(expectfile, actual);
+
QImage expect(expectfile);
-#ifdef Q_WS_X11
- // Font-specific, but not likely platform-specific, so only test on one platform
QCOMPARE(actual,expect);
-#endif
}
@@ -489,6 +501,23 @@ void tst_qdeclarativetextedit::font()
void tst_qdeclarativetextedit::color()
{
+ //test initial color
+ {
+ QString componentStr = "import Qt 4.7\nTextEdit { text: \"Hello World\" }";
+ QDeclarativeComponent texteditComponent(&engine);
+ texteditComponent.setData(componentStr.toLatin1(), QUrl());
+ QDeclarativeTextEdit *textEditObject = qobject_cast<QDeclarativeTextEdit*>(texteditComponent.create());
+
+ QDeclarativeTextEditPrivate *textEditPrivate = static_cast<QDeclarativeTextEditPrivate*>(QDeclarativeItemPrivate::get(textEditObject));
+
+ QVERIFY(textEditObject);
+ QVERIFY(textEditPrivate);
+ QVERIFY(textEditPrivate->control);
+
+ QPalette pal = textEditPrivate->control->palette();
+ QCOMPARE(textEditPrivate->color, QColor("black"));
+ QCOMPARE(textEditPrivate->color, pal.color(QPalette::Text));
+ }
//test normal
for (int i = 0; i < colorStrings.size(); i++)
{