557 QVERIFY(d->control); |
562 QVERIFY(d->control); |
558 QCOMPARE(d->control->document()->toPlainText(), expectedDocText); |
563 QCOMPARE(d->control->document()->toPlainText(), expectedDocText); |
559 QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); |
564 QCOMPARE(d->shortcutCursor.selectedText(), expectedShortcutCursor); |
560 } |
565 } |
561 |
566 |
|
567 void tst_QLabel::selection() |
|
568 { |
|
569 QLabel label; |
|
570 label.setText("Hello world"); |
|
571 |
|
572 label.setTextInteractionFlags(Qt::TextSelectableByMouse); |
|
573 |
|
574 QVERIFY(!label.hasSelectedText()); |
|
575 QCOMPARE(label.selectedText(), QString()); |
|
576 QCOMPARE(label.selectionStart(), -1); |
|
577 |
|
578 label.setSelection(0, 4); |
|
579 QVERIFY(label.hasSelectedText()); |
|
580 QCOMPARE(label.selectedText(), QString::fromLatin1("Hell")); |
|
581 QCOMPARE(label.selectionStart(), 0); |
|
582 |
|
583 label.setSelection(6, 5); |
|
584 QVERIFY(label.hasSelectedText()); |
|
585 QCOMPARE(label.selectedText(), QString::fromLatin1("world")); |
|
586 QCOMPARE(label.selectionStart(), 6); |
|
587 } |
|
588 |
|
589 #ifndef QT_NO_CONTEXTMENU |
|
590 void tst_QLabel::taskQTBUG_7902_contextMenuCrash() |
|
591 { |
|
592 QLabel *w = new QLabel("Test or crash?"); |
|
593 w->setTextInteractionFlags(Qt::TextSelectableByMouse); |
|
594 w->show(); |
|
595 QTest::qWaitForWindowShown(w); |
|
596 |
|
597 QTimer ti; |
|
598 w->connect(&ti, SIGNAL(timeout()), w, SLOT(deleteLater())); |
|
599 ti.start(300); |
|
600 |
|
601 QContextMenuEvent *cme = new QContextMenuEvent(QContextMenuEvent::Mouse, w->rect().center()); |
|
602 qApp->postEvent(w, cme); |
|
603 |
|
604 QTest::qWait(350); |
|
605 // No crash, it's allright. |
|
606 } |
|
607 #endif |
562 |
608 |
563 QTEST_MAIN(tst_QLabel) |
609 QTEST_MAIN(tst_QLabel) |
564 #include "tst_qlabel.moc" |
610 #include "tst_qlabel.moc" |