diff options
Diffstat (limited to 'tests/auto/qlabel/tst_qlabel.cpp')
-rw-r--r-- | tests/auto/qlabel/tst_qlabel.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qlabel/tst_qlabel.cpp b/tests/auto/qlabel/tst_qlabel.cpp index 9d957a5..6b7e106 100644 --- a/tests/auto/qlabel/tst_qlabel.cpp +++ b/tests/auto/qlabel/tst_qlabel.cpp @@ -51,6 +51,7 @@ #include <qmovie.h> #include <qpicture.h> #include <qmessagebox.h> +#include <private/qlabel_p.h> //TESTED_CLASS= //TESTED_FILES= @@ -116,6 +117,9 @@ private slots: void unicodeText_data(); void unicodeText(); + void mnemonic_data(); + void mnemonic(); + private: QLabel *testWidget; QPointer<Widget> test_box; @@ -224,6 +228,7 @@ void tst_QLabel::setBuddy() QVERIFY( !test_edit->hasFocus() ); QTest::keyClick( test_box, 't', Qt::AltModifier ); QVERIFY( test_edit->hasFocus() ); + delete test_box; } void tst_QLabel::text() @@ -245,6 +250,7 @@ void tst_QLabel::setText_data() QTest::newRow( QString(prefix + "data1").toLatin1() ) << QString("This is the first line\nThis is the second line") << QString("Courier"); QTest::newRow( QString(prefix + "data2").toLatin1() ) << QString("This is the first line\nThis is the second line\nThis is the third line") << QString("Helvetica"); QTest::newRow( QString(prefix + "data3").toLatin1() ) << QString("This is <b>bold</b> richtext") << QString("Courier"); + QTest::newRow( QString(prefix + "data4").toLatin1() ) << QString("I Have a &shortcut") << QString("Helvetica"); } void tst_QLabel::setText() @@ -509,5 +515,50 @@ void tst_QLabel::unicodeText() testWidget->show(); } +void tst_QLabel::mnemonic_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<QString>("expectedDocText"); + QTest::addColumn<QString>("expectedShortcutCursor"); + + QTest::newRow("1") << QString("Normal") << QString("Normal") << QString(); + QTest::newRow("2") << QString("&Simple") << QString("Simple") << QString("S"); + QTest::newRow("3") << QString("Also &simple") << QString("Also simple") << QString("s"); + QTest::newRow("4") << QString("&&With &Double &&") << QString("&With Double &") << QString("D"); + QTest::newRow("5") << QString("Hep&&Hop") << QString("Hep&Hop") << QString(""); + QTest::newRow("6") << QString("Hep&&&Hop") << QString("Hep&Hop") << QString("H"); +} + + +void tst_QLabel::mnemonic() +{ + // this test that the mnemonics appears correctly when the label has a text control. + + QFETCH(QString, text); + QFETCH(QString, expectedDocText); + QFETCH(QString, expectedShortcutCursor); + + QWidget w; + QHBoxLayout *hbox = new QHBoxLayout; + QLabel *lab = new QLabel(text); + //lab->setText("plop &plop"); + QLineEdit *lineedit = new QLineEdit; + lab->setBuddy(lineedit); + lab->setTextInteractionFlags(Qt::TextSelectableByMouse); + + hbox->addWidget(lab); + hbox->addWidget(lineedit); + hbox->addWidget(new QLineEdit); + w.setLayout(hbox); + w.show(); + QTest::qWaitForWindowShown(&w); + + QLabelPrivate *d = static_cast<QLabelPrivate *>(QObjectPrivate::get(lab)); + QVERIFY(d->control); + QCOMPARE(d->control->document()->toPlainText(), expectedDocText); + QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); +} + + QTEST_MAIN(tst_QLabel) #include "tst_qlabel.moc" |