tests/benchmarks/qapplication/main.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
    37 **
    37 **
    38 ** $QT_END_LICENSE$
    38 ** $QT_END_LICENSE$
    39 **
    39 **
    40 ****************************************************************************/
    40 ****************************************************************************/
    41 #include <QApplication>
    41 #include <QApplication>
    42 #include <QProcess>
       
    43 
    42 
    44 #include <qtest.h>
    43 #include <qtest.h>
    45 
    44 
    46 
    45 
    47 class tst_qapplication : public QObject
    46 class tst_qapplication : public QObject
    52 };
    51 };
    53 
    52 
    54 /*
    53 /*
    55     Test the performance of the QApplication constructor.
    54     Test the performance of the QApplication constructor.
    56 
    55 
    57     This test creates a new process and thus includes process creation overhead.
    56     Note: results from the second start on can be misleading,
    58     Callgrind results are meaningless since the child process is not traced.
    57     since all global statics are already initialized.
    59 */
    58 */
    60 void tst_qapplication::ctor()
    59 void tst_qapplication::ctor()
    61 {
    60 {
    62     QProcess proc;
    61     // simulate reasonable argc, argv
    63     const QString program       = QCoreApplication::applicationFilePath();
    62     int argc = 1;
    64     const QStringList arguments = QStringList() << QLatin1String("--exit-now");
    63     char *argv[] = { "tst_qapplication" };
    65 
       
    66     QBENCHMARK {
    64     QBENCHMARK {
    67         proc.start(program, arguments);
    65         QApplication app(argc, argv);
    68         QVERIFY(proc.waitForStarted());
       
    69         QVERIFY(proc.waitForFinished());
       
    70         QCOMPARE(proc.exitStatus(), QProcess::NormalExit);
       
    71         QCOMPARE(proc.exitCode(), 0);
       
    72     }
    66     }
    73 }
    67 }
    74 
    68 
    75 int main(int argc, char** argv)
    69 QTEST_APPLESS_MAIN(tst_qapplication)
    76 {
       
    77     QApplication app(argc, argv);
       
    78 
       
    79     if (argc == 2 && QLatin1String("--exit-now") == QLatin1String(argv[1])) {
       
    80         return 0;
       
    81     }
       
    82 
       
    83     tst_qapplication test;
       
    84     return QTest::qExec(&test, argc, argv);
       
    85 }
       
    86 
    70 
    87 #include "main.moc"
    71 #include "main.moc"