diff options
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 119 |
1 files changed, 62 insertions, 57 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 32facaf12b..1c3292ead9 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -282,74 +282,74 @@ namespace QTestPrivate namespace QTest { - class WatchDog; +class WatchDog; - static QObject *currentTestObject = 0; - static QString mainSourcePath; +static QObject *currentTestObject = 0; +static QString mainSourcePath; #if defined(Q_OS_MACOS) - bool macNeedsActivate = false; - IOPMAssertionID powerID; +bool macNeedsActivate = false; +IOPMAssertionID powerID; #endif - class TestMethods { - Q_DISABLE_COPY(TestMethods) +class TestMethods { + Q_DISABLE_COPY(TestMethods) public: - typedef std::vector<QMetaMethod> MetaMethods; + typedef std::vector<QMetaMethod> MetaMethods; - explicit TestMethods(const QObject *o, const MetaMethods &m = MetaMethods()); + explicit TestMethods(const QObject *o, const MetaMethods &m = MetaMethods()); - void invokeTests(QObject *testObject) const; + void invokeTests(QObject *testObject) const; - static QMetaMethod findMethod(const QObject *obj, const char *signature); + static QMetaMethod findMethod(const QObject *obj, const char *signature); - private: - bool invokeTest(int index, const char *data, WatchDog *watchDog) const; - void invokeTestOnData(int index) const; +private: + bool invokeTest(int index, const char *data, WatchDog *watchDog) const; + void invokeTestOnData(int index) const; - QMetaMethod m_initTestCaseMethod; // might not exist, check isValid(). - QMetaMethod m_initTestCaseDataMethod; - QMetaMethod m_cleanupTestCaseMethod; - QMetaMethod m_initMethod; - QMetaMethod m_cleanupMethod; + QMetaMethod m_initTestCaseMethod; // might not exist, check isValid(). + QMetaMethod m_initTestCaseDataMethod; + QMetaMethod m_cleanupTestCaseMethod; + QMetaMethod m_initMethod; + QMetaMethod m_cleanupMethod; - MetaMethods m_methods; - }; + MetaMethods m_methods; +}; - TestMethods::TestMethods(const QObject *o, const MetaMethods &m) - : m_initTestCaseMethod(TestMethods::findMethod(o, "initTestCase()")) - , m_initTestCaseDataMethod(TestMethods::findMethod(o, "initTestCase_data()")) - , m_cleanupTestCaseMethod(TestMethods::findMethod(o, "cleanupTestCase()")) - , m_initMethod(TestMethods::findMethod(o, "init()")) - , m_cleanupMethod(TestMethods::findMethod(o, "cleanup()")) - , m_methods(m) - { - if (m.empty()) { - const QMetaObject *metaObject = o->metaObject(); - const int count = metaObject->methodCount(); - m_methods.reserve(count); - for (int i = 0; i < count; ++i) { - const QMetaMethod me = metaObject->method(i); - if (isValidSlot(me)) - m_methods.push_back(me); - } +TestMethods::TestMethods(const QObject *o, const MetaMethods &m) + : m_initTestCaseMethod(TestMethods::findMethod(o, "initTestCase()")) + , m_initTestCaseDataMethod(TestMethods::findMethod(o, "initTestCase_data()")) + , m_cleanupTestCaseMethod(TestMethods::findMethod(o, "cleanupTestCase()")) + , m_initMethod(TestMethods::findMethod(o, "init()")) + , m_cleanupMethod(TestMethods::findMethod(o, "cleanup()")) + , m_methods(m) +{ + if (m.empty()) { + const QMetaObject *metaObject = o->metaObject(); + const int count = metaObject->methodCount(); + m_methods.reserve(count); + for (int i = 0; i < count; ++i) { + const QMetaMethod me = metaObject->method(i); + if (isValidSlot(me)) + m_methods.push_back(me); } } +} - QMetaMethod TestMethods::findMethod(const QObject *obj, const char *signature) - { - const QMetaObject *metaObject = obj->metaObject(); - const int funcIndex = metaObject->indexOfMethod(signature); - return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); - } +QMetaMethod TestMethods::findMethod(const QObject *obj, const char *signature) +{ + const QMetaObject *metaObject = obj->metaObject(); + const int funcIndex = metaObject->indexOfMethod(signature); + return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); +} - static int keyDelay = -1; - static int mouseDelay = -1; - static int eventDelay = -1; +static int keyDelay = -1; +static int mouseDelay = -1; +static int eventDelay = -1; #if QT_CONFIG(thread) - static int timeout = -1; +static int timeout = -1; #endif - static bool noCrashHandler = false; +static bool noCrashHandler = false; /*! \internal Invoke a method of the object without generating warning if the method does not exist @@ -496,7 +496,7 @@ static void qPrintDataTags(FILE *stream) } } -static int qToInt(char *str) +static int qToInt(const char *str) { char *pEnd; int l = (int)strtol(str, &pEnd, 10); @@ -507,7 +507,7 @@ static int qToInt(char *str) return l; } -Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) +Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool qml) { QTestLog::LogMode logFormat = QTestLog::Plain; const char *logFilename = 0; @@ -811,9 +811,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) // we load the QML files. So just store the data for now. int colon = -1; int offset; - for (offset = 0; *(argv[i]+offset); ++offset) { - if (*(argv[i]+offset) == ':') { - if (*(argv[i]+offset+1) == ':') { + for (offset = 0; argv[i][offset]; ++offset) { + if (argv[i][offset] == ':') { + if (argv[i][offset + 1] == ':') { // "::" is used as a test name separator. // e.g. "ClickTests::test_click:row1". ++offset; @@ -845,6 +845,11 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTestLog::addLogger(logFormat, logFilename); } +// Temporary, backwards compatibility, until qtdeclarative's use of it is converted +Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) { + qtest_qParseArgs(argc, const_cast<const char *const *>(argv), qml); +} + QBenchmarkResult qMedian(const QVector<QBenchmarkResult> &container) { const int count = container.count(); @@ -1195,7 +1200,9 @@ char *formatString(const char *prefix, const char *suffix, size_t numArguments, Returns a pointer to a string that is the string \a ba represented as a space-separated sequence of hex characters. If the input is considered too long, it is truncated. A trucation is indicated in - the returned string as an ellipsis at the end. + the returned string as an ellipsis at the end. The caller has + ownership of the returned pointer and must ensure it is later passed + to operator delete[]. \a length is the length of the string \a ba. */ @@ -1813,8 +1820,6 @@ void QTest::qInit(QObject *testObject, int argc, char **argv) #endif QTestPrivate::parseBlackList(); - QTestPrivate::parseGpuBlackList(); - QTestResult::reset(); QTEST_ASSERT(testObject); |