tests/auto/qapplication/tst_qapplication.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   127     void task109149();
   127     void task109149();
   128 
   128 
   129     void style();
   129     void style();
   130 
   130 
   131     void allWidgets();
   131     void allWidgets();
       
   132     void topLevelWidgets();
   132 
   133 
   133     void setAttribute();
   134     void setAttribute();
   134 
   135 
   135     void windowsCommandLine_data();
   136     void windowsCommandLine_data();
   136     void windowsCommandLine();
   137     void windowsCommandLine();
   137 
   138 
   138     void touchEventPropagation();
   139     void touchEventPropagation();
       
   140 
       
   141     void symbianNeedForTraps();
       
   142     void symbianLeaveThroughMain();
   139 };
   143 };
   140 
   144 
   141 class EventSpy : public QObject
   145 class EventSpy : public QObject
   142 {
   146 {
   143    Q_OBJECT
   147    Q_OBJECT
  1790     delete w;
  1794     delete w;
  1791     w = 0;
  1795     w = 0;
  1792     QVERIFY(!app.allWidgets().contains(w)); // removal test
  1796     QVERIFY(!app.allWidgets().contains(w)); // removal test
  1793 }
  1797 }
  1794 
  1798 
       
  1799 void tst_QApplication::topLevelWidgets()
       
  1800 {
       
  1801     int argc = 1;
       
  1802     QApplication app(argc, &argv0, QApplication::GuiServer);
       
  1803     QWidget *w = new QWidget;
       
  1804     w->show();
       
  1805 #ifndef QT_NO_CLIPBOARD
       
  1806     QClipboard *clipboard = QApplication::clipboard();
       
  1807     QString originalText = clipboard->text();
       
  1808     clipboard->setText(QString("newText"));
       
  1809 #endif
       
  1810     app.processEvents();
       
  1811     QVERIFY(QApplication::topLevelWidgets().contains(w));
       
  1812     QCOMPARE(QApplication::topLevelWidgets().count(), 1);
       
  1813     delete w;
       
  1814     w = 0;
       
  1815     app.processEvents();
       
  1816     QCOMPARE(QApplication::topLevelWidgets().count(), 0);
       
  1817 }
       
  1818 
       
  1819 
  1795 
  1820 
  1796 void tst_QApplication::setAttribute()
  1821 void tst_QApplication::setAttribute()
  1797 {
  1822 {
  1798     int argc = 1;
  1823     int argc = 1;
  1799     QApplication app(argc, &argv0, QApplication::GuiServer);
  1824     QApplication app(argc, &argv0, QApplication::GuiServer);
  2009         QVERIFY(window.seenTouchEvent);
  2034         QVERIFY(window.seenTouchEvent);
  2010         QVERIFY(!window.seenMouseEvent);
  2035         QVERIFY(!window.seenMouseEvent);
  2011     }
  2036     }
  2012 }
  2037 }
  2013 
  2038 
       
  2039 #ifdef Q_OS_SYMBIAN
       
  2040 class CBaseDummy : public CBase
       
  2041 {
       
  2042 public:
       
  2043     CBaseDummy(int *numDestroyed) : numDestroyed(numDestroyed)
       
  2044     {
       
  2045     }
       
  2046     ~CBaseDummy()
       
  2047     {
       
  2048         (*numDestroyed)++;
       
  2049     }
       
  2050 
       
  2051 private:
       
  2052     int *numDestroyed;
       
  2053 };
       
  2054 
       
  2055 static void fakeMain(int *numDestroyed)
       
  2056 {
       
  2057     // Push a few objects, just so that the cleanup stack has something to clean up.
       
  2058     CleanupStack::PushL(new (ELeave) CBaseDummy(numDestroyed));
       
  2059     int argc = 0;
       
  2060     QApplication app(argc, 0);
       
  2061     CleanupStack::PushL(new (ELeave) CBaseDummy(numDestroyed));
       
  2062 
       
  2063     User::Leave(KErrGeneral); // Fake error
       
  2064 }
       
  2065 #endif
       
  2066 
       
  2067 void tst_QApplication::symbianNeedForTraps()
       
  2068 {
       
  2069 #ifndef Q_OS_SYMBIAN
       
  2070     QSKIP("This is a Symbian-only test", SkipAll);
       
  2071 #else
       
  2072     int argc = 0;
       
  2073     QApplication app(argc, 0);
       
  2074     int numDestroyed = 0;
       
  2075 
       
  2076     // This next part should not require a trap. If it does, the test will crash.
       
  2077     CleanupStack::PushL(new (ELeave) CBaseDummy(&numDestroyed));
       
  2078     CleanupStack::PopAndDestroy();
       
  2079 
       
  2080     QCOMPARE(numDestroyed, 1);
       
  2081 
       
  2082     // No other failure condition. The program will crash if it does not pass.
       
  2083 #endif
       
  2084 }
       
  2085 
       
  2086 void tst_QApplication::symbianLeaveThroughMain()
       
  2087 {
       
  2088 #ifndef Q_OS_SYMBIAN
       
  2089     QSKIP("This is a Symbian-only test", SkipAll);
       
  2090 #else
       
  2091     int numDestroyed = 0;
       
  2092     TInt err;
       
  2093     TRAP(err, fakeMain(&numDestroyed));
       
  2094 
       
  2095     QCOMPARE(numDestroyed, 2);
       
  2096 #endif
       
  2097 }
       
  2098 
  2014 //QTEST_APPLESS_MAIN(tst_QApplication)
  2099 //QTEST_APPLESS_MAIN(tst_QApplication)
  2015 int main(int argc, char *argv[])
  2100 int main(int argc, char *argv[])
  2016 {
  2101 {
  2017     tst_QApplication tc;
  2102     tst_QApplication tc;
  2018     argv0 = argv[0];
  2103     argv0 = argv[0];