tests/auto/qsoftkeymanager/tst_qsoftkeymanager.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    44 #include "qevent.h"
    44 #include "qevent.h"
    45 #include "qdialog.h"
    45 #include "qdialog.h"
    46 #include "qpushbutton.h"
    46 #include "qpushbutton.h"
    47 #include "qdialogbuttonbox.h"
    47 #include "qdialogbuttonbox.h"
    48 #include "private/qsoftkeymanager_p.h"
    48 #include "private/qsoftkeymanager_p.h"
       
    49 
       
    50 #ifdef Q_OS_SYMBIAN
       
    51 #include "qsymbianevent.h"
       
    52 #endif
    49 
    53 
    50 #ifdef Q_WS_S60
    54 #ifdef Q_WS_S60
    51 static const int s60CommandStart = 6000;
    55 static const int s60CommandStart = 6000;
    52 #endif
    56 #endif
    53 
    57 
    67     void cleanup();
    71     void cleanup();
    68 private slots:
    72 private slots:
    69     void updateSoftKeysCompressed();
    73     void updateSoftKeysCompressed();
    70     void handleCommand();
    74     void handleCommand();
    71     void checkSoftkeyEnableStates();
    75     void checkSoftkeyEnableStates();
       
    76     void noMergingOverWindowBoundary();
       
    77 
       
    78 private: // utils
       
    79     inline void simulateSymbianCommand(int command)
       
    80     {
       
    81         QSymbianEvent event1(QSymbianEvent::CommandEvent, command);
       
    82         qApp->symbianProcessEvent(&event1);
       
    83     };
    72 };
    84 };
    73 
    85 
    74 class EventListener : public QObject
    86 class EventListener : public QObject
    75 {
    87 {
    76 public:
    88 public:
   165 
   177 
   166     // These should work eventually, but do not yet
   178     // These should work eventually, but do not yet
   167 //    QTest::keyPress(&w, Qt::Key_Context1);
   179 //    QTest::keyPress(&w, Qt::Key_Context1);
   168 //    QTest::keyPress(&w, Qt::Key_Context2);
   180 //    QTest::keyPress(&w, Qt::Key_Context2);
   169 
   181 
   170     qApp->symbianHandleCommand(6000);
   182     simulateSymbianCommand(6000);
   171     qApp->symbianHandleCommand(6001);
   183     simulateSymbianCommand(6001);
   172 
   184 
   173     QApplication::processEvents();
   185     QApplication::processEvents();
   174 
   186 
   175     QCOMPARE(spy0.count(), 1);
   187     QCOMPARE(spy0.count(), 1);
   176     QCOMPARE(spy1.count(), 1);
   188     QCOMPARE(spy1.count(), 1);
   198 
   210 
   199     //Verify that enabled button gets all the action trigger signals and
   211     //Verify that enabled button gets all the action trigger signals and
   200     //disabled button gets none.
   212     //disabled button gets none.
   201     for (int i = 0; i < 10; i++) {
   213     for (int i = 0; i < 10; i++) {
   202         //simulate "Restore Defaults" softkey press
   214         //simulate "Restore Defaults" softkey press
   203         qApp->symbianHandleCommand(s60CommandStart);
   215         simulateSymbianCommand(s60CommandStart);
   204         //simulate "help" softkey press
   216         //simulate "help" softkey press
   205         qApp->symbianHandleCommand(s60CommandStart + 1);
   217         simulateSymbianCommand(s60CommandStart + 1);
   206     }
   218     }
   207     QApplication::processEvents();
   219     QApplication::processEvents();
   208     QCOMPARE(spy0.count(), 10);
   220     QCOMPARE(spy0.count(), 10);
   209     QCOMPARE(spy1.count(), 0);
   221     QCOMPARE(spy1.count(), 0);
   210     spy0.clear();
   222     spy0.clear();
   211     spy1.clear();
   223     spy1.clear();
   212 
   224 
   213     for (int i = 0; i < 10; i++) {
   225     for (int i = 0; i < 10; i++) {
   214         //simulate "Restore Defaults" softkey press
   226         //simulate "Restore Defaults" softkey press
   215         qApp->symbianHandleCommand(s60CommandStart);
   227         simulateSymbianCommand(s60CommandStart);
   216         //simulate "help" softkey press
   228         //simulate "help" softkey press
   217         qApp->symbianHandleCommand(s60CommandStart + 1);
   229         simulateSymbianCommand(s60CommandStart + 1);
   218         //switch enabled button to disabled and vice versa
   230         //switch enabled button to disabled and vice versa
   219         pBHelp->setEnabled(!pBHelp->isEnabled());
   231         pBHelp->setEnabled(!pBHelp->isEnabled());
   220         pBDefaults->setEnabled(!pBDefaults->isEnabled());
   232         pBDefaults->setEnabled(!pBDefaults->isEnabled());
   221     }
   233     }
   222     QApplication::processEvents();
   234     QApplication::processEvents();
   223     QCOMPARE(spy0.count(), 5);
   235     QCOMPARE(spy0.count(), 5);
   224     QCOMPARE(spy1.count(), 5);    
   236     QCOMPARE(spy1.count(), 5);
       
   237 }
       
   238 
       
   239 /*
       
   240     This tests that the softkeys are not merged over window boundaries. I.e. dialogs
       
   241     don't get softkeys of base widget by default - QTBUG-6163.
       
   242 */
       
   243 void tst_QSoftKeyManager::noMergingOverWindowBoundary()
       
   244 {
       
   245     // Create base window against which the dialog softkeys will ve verified
       
   246     QWidget base;
       
   247 
       
   248     QAction* baseLeft = new QAction(tr("BaseLeft"), &base);
       
   249     baseLeft->setSoftKeyRole(QAction::PositiveSoftKey);
       
   250     base.addAction(baseLeft);
       
   251 
       
   252     QAction* baseRight = new QAction(tr("BaseRight"), &base);
       
   253     baseRight->setSoftKeyRole(QAction::NegativeSoftKey);
       
   254     base.addAction(baseRight);
       
   255 
       
   256     base.showMaximized();
       
   257     QApplication::processEvents();
       
   258 
       
   259     QSignalSpy baseLeftSpy(baseLeft, SIGNAL(triggered()));
       
   260     QSignalSpy baseRightSpy(baseRight, SIGNAL(triggered()));
       
   261 
       
   262     //Verify that both base softkeys emit triggered signals
       
   263     simulateSymbianCommand(s60CommandStart);
       
   264     simulateSymbianCommand(s60CommandStart + 1);
       
   265 
       
   266     QCOMPARE(baseLeftSpy.count(), 1);
       
   267     QCOMPARE(baseRightSpy.count(), 1);
       
   268     baseLeftSpy.clear();
       
   269     baseRightSpy.clear();
       
   270 
       
   271     // Verify that no softkey merging when using dialog without parent
       
   272     QDialog dlg;
       
   273     dlg.show();
       
   274 
       
   275     QApplication::processEvents();
       
   276 
       
   277     simulateSymbianCommand(s60CommandStart);
       
   278     simulateSymbianCommand(s60CommandStart + 1);
       
   279 
       
   280     QCOMPARE(baseLeftSpy.count(), 0);
       
   281     QCOMPARE(baseRightSpy.count(), 0);
       
   282 
       
   283     // Ensure base view has focus again
       
   284     dlg.hide();
       
   285     base.showMaximized();
       
   286 
       
   287     // Verify that no softkey merging when using dialog with parent
       
   288     QDialog dlg2(&base);
       
   289     dlg2.show();
       
   290 
       
   291     QApplication::processEvents();
       
   292 
       
   293     simulateSymbianCommand(s60CommandStart);
       
   294     simulateSymbianCommand(s60CommandStart + 1);
       
   295 
       
   296     QCOMPARE(baseLeftSpy.count(), 0);
       
   297     QCOMPARE(baseRightSpy.count(), 0);
   225 }
   298 }
   226 
   299 
   227 QTEST_MAIN(tst_QSoftKeyManager)
   300 QTEST_MAIN(tst_QSoftKeyManager)
   228 #include "tst_qsoftkeymanager.moc"
   301 #include "tst_qsoftkeymanager.moc"