tests/auto/qlabel/tst_qlabel.cpp
changeset 30 5dc02b23752f
parent 18 2f34d5167611
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   117     void unicodeText_data();
   117     void unicodeText_data();
   118     void unicodeText();
   118     void unicodeText();
   119 
   119 
   120     void mnemonic_data();
   120     void mnemonic_data();
   121     void mnemonic();
   121     void mnemonic();
       
   122     void selection();
       
   123 
       
   124 #ifndef QT_NO_CONTEXTMENU
       
   125     void taskQTBUG_7902_contextMenuCrash();
       
   126 #endif
   122 
   127 
   123 private:
   128 private:
   124     QLabel *testWidget;
   129     QLabel *testWidget;
   125     QPointer<Widget> test_box;
   130     QPointer<Widget> test_box;
   126     QPointer<QLabel> test_label;
   131     QPointer<QLabel> test_label;
   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"