diff options
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/3rdparty/cycle_p.h | 19 | ||||
-rw-r--r-- | src/testlib/qbenchmark.cpp | 1 | ||||
-rw-r--r-- | src/testlib/qplaintestlogger.cpp | 20 | ||||
-rw-r--r-- | src/testlib/qtest.h | 7 | ||||
-rw-r--r-- | src/testlib/qtest_global.h | 5 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 32 | ||||
-rw-r--r-- | src/testlib/qtestcase.h | 37 | ||||
-rw-r--r-- | src/testlib/testlib.pro | 4 |
8 files changed, 110 insertions, 15 deletions
diff --git a/src/testlib/3rdparty/cycle_p.h b/src/testlib/3rdparty/cycle_p.h index b4b6876..a292423 100644 --- a/src/testlib/3rdparty/cycle_p.h +++ b/src/testlib/3rdparty/cycle_p.h @@ -190,6 +190,7 @@ INLINE_ELAPSED(__inline__) #endif /* Visual C++ -- thanks to Morten Nissov for his help with this */ +#if defined(_MSC_VER) #if _MSC_VER >= 1200 && (_M_IX86 >= 500 || (defined(_WIN32_WCE) && defined(_X86_))) && !defined(HAVE_TICK_COUNTER) #include <windows.h> typedef LARGE_INTEGER CycleCounterTicks; @@ -215,6 +216,7 @@ static __inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0) #define HAVE_TICK_COUNTER #define TIME_MIN 5000.0 /* unreliable pentium IV cycle counter */ #endif +#endif #if _MSC_VER >= 1400 && defined(_WIN32_WCE) && !defined(HAVE_TICK_COUNTER) #include <windows.h> @@ -491,4 +493,21 @@ INLINE_ELAPSED(inline) #define HAVE_TICK_COUNTER #endif +/*----------------------------------------------------------------*/ +/* Symbian */ +#if defined(__SYMBIAN32__) && !defined(HAVE_TICK_COUNTER) +#include <e32std.h> + +typedef TUint32 CycleCounterTicks; + +static inline CycleCounterTicks getticks(void) +{ + return User::FastCounter(); +} + +INLINE_ELAPSED(inline) + +#define HAVE_TICK_COUNTER +#endif + #endif // QBENCHLIB_CYCLE_H diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp index 60e393d..4ccfc88 100644 --- a/src/testlib/qbenchmark.cpp +++ b/src/testlib/qbenchmark.cpp @@ -240,6 +240,7 @@ void QTest::setIterationCountHint(int count) { QBenchmarkTestMethodData::current->adjustIterationCount(count); } + /*! \internal */ void QTest::setIterationCount(int count) diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 23ecce6..692cab5 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -54,6 +54,10 @@ #include "windows.h" #endif +#if defined(Q_OS_SYMBIAN) +#include <e32debug.h> +#endif + #ifdef Q_OS_WINCE #include <QtCore/QString> #endif @@ -125,7 +129,11 @@ namespace QTest { static const char *messageType2String(QAbstractTestLogger::MessageTypes type) { +#ifdef Q_OS_WIN static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); +#else + static bool colored = ::getenv("QTEST_COLORED"); +#endif switch (type) { case QAbstractTestLogger::Skip: return COLORED_MSG(0, 37, "SKIP "); //white @@ -161,6 +169,18 @@ namespace QTest { // OutputDebugString is not threadsafe OutputDebugStringA(str); LeaveCriticalSection(&outputCriticalSection); +#elif defined(Q_OS_SYMBIAN) + TPtrC8 ptr(reinterpret_cast<const TUint8*>(str)); + HBufC* hbuffer = HBufC::New(ptr.Length()); + if (hbuffer) { + hbuffer->Des().Copy(ptr); + RDebug::Print(_L("[QTestLib Message] %S"), hbuffer); + delete hbuffer; + } else { + TBuf<256> tmp; + tmp.Copy(ptr.Left(Min(256, ptr.Length()))); + RDebug::Print(_L("[QTestLib Message] %S"), &tmp); + } #endif QAbstractTestLogger::outputString(str); } diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index 0f3626e..0a02b03 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -251,10 +251,17 @@ int main(int argc, char *argv[]) \ #include <QtTest/qtest_gui.h> +#ifdef QT_KEYPAD_NAVIGATION +# define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setKeypadNavigationEnabled(false); +#else +# define QTEST_DISABLE_KEYPAD_NAVIGATION +#endif + #define QTEST_MAIN(TestObject) \ int main(int argc, char *argv[]) \ { \ QApplication app(argc, argv); \ + QTEST_DISABLE_KEYPAD_NAVIGATION \ TestObject tc; \ return QTest::qExec(&tc, argc, argv); \ } diff --git a/src/testlib/qtest_global.h b/src/testlib/qtest_global.h index f8dfbef..931a60b 100644 --- a/src/testlib/qtest_global.h +++ b/src/testlib/qtest_global.h @@ -52,7 +52,7 @@ QT_MODULE(Test) #ifdef QTEST_EMBED # define Q_TESTLIB_EXPORT -#elif !defined(QT_SHARED) +#elif !defined(QT_SHARED) && !(defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)) # define Q_TESTLIB_EXPORT #else # ifdef QTESTLIB_MAKEDLL @@ -62,10 +62,11 @@ QT_MODULE(Test) # endif #endif -#if (defined (Q_CC_MSVC) && _MSC_VER < 1310) || defined (Q_CC_SUN) || defined (Q_CC_XLC) || (defined (Q_CC_GNU) && (__GNUC__ - 0 < 3)) +#if (defined (Q_CC_MSVC) && _MSC_VER < 1310) || defined (Q_CC_SUN) || defined (Q_CC_XLC) || (defined (Q_CC_GNU) && (__GNUC__ - 0 < 3)) || defined (Q_CC_NOKIAX86) # define QTEST_NO_SPECIALIZATIONS #endif + #if (defined Q_CC_HPACC) && (defined __ia64) # ifdef Q_TESTLIB_EXPORT # undef Q_TESTLIB_EXPORT diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index a144923..a7aa81b 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -303,10 +303,15 @@ QT_BEGIN_NAMESPACE the \a TestClass, and executes all tests in the order they were defined. Use this macro to build stand-alone executables. + \bold {Note:} On platforms that have keypad navigation enabled by default (eg: Symbian), + this macro will forcfully disable it to simplify the usage of key events when writing + autotests. If you wish to write a test case that uses keypad navigation, you should + enable it either in the \c {initTestCase()} or \c {init()} functions of your test case. + Example: \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 11 - \sa QTEST_APPLESS_MAIN(), QTest::qExec() + \sa QTEST_APPLESS_MAIN(), QTest::qExec(), QApplication::setKeypadNavigationEnabled() */ /*! \macro QTEST_APPLESS_MAIN(TestClass) @@ -1453,7 +1458,7 @@ static void qInvokeTestMethods(QObject *testObject) QTestLog::stopLogging(); } -#ifdef Q_OS_UNIX +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) class FatalSignalHandler { public: @@ -1602,6 +1607,11 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) } #endif +#ifdef Q_OS_SYMBIAN +//### FIX THIS temporary hack to delay execution of symbian os tests. Used to get emulator to stable state before running testcase + qSleep(3000); +#endif + QTestResult::reset(); QTEST_ASSERT(testObject); @@ -1624,13 +1634,13 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) } else #endif { -#ifdef Q_OS_UNIX +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) FatalSignalHandler handler; #endif qInvokeTestMethods(testObject); } - #ifndef QT_NO_EXCEPTIONS +#ifndef QT_NO_EXCEPTIONS } catch (...) { QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__); if (QTestResult::currentTestFunction()) { @@ -1644,13 +1654,13 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) IOPMAssertionRelease(powerID); } #endif - #ifdef Q_OS_WIN +//# ifdef Q_OS_WIN // rethrow exception to make debugging easier throw; - #endif - return -1; +//# endif + return 1; } - #endif +# endif currentTestObject = 0; #ifdef QT_MAC_USE_COCOA @@ -1953,7 +1963,7 @@ bool QTest::compare_helper(bool success, const char *msg, char *val1, char *val2 \internal */ template <> -bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, +Q_TESTLIB_EXPORT bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) { return qFuzzyCompare(t1, t2) @@ -1966,7 +1976,7 @@ bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual \internal */ template <> -bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected, +Q_TESTLIB_EXPORT bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) { return qFuzzyCompare(t1, t2) @@ -1976,7 +1986,7 @@ bool QTest::qCompare<double>(double const &t1, double const &t2, const char *act } #define COMPARE_IMPL2(TYPE, FORMAT) \ -template <> char *QTest::toString<TYPE >(const TYPE &t) \ +template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ { \ char *msg = new char[128]; \ qt_snprintf(msg, 128, #FORMAT, t); \ diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 746dbb1..641d231 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -125,6 +125,7 @@ namespace QTest return 0; } + Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, int length); Q_TESTLIB_EXPORT char *toString(const char *); Q_TESTLIB_EXPORT char *toString(const void *); @@ -178,6 +179,7 @@ namespace QTest toString<T>(t1), toString<T>(t2), actual, expected, file, line); } + template <> Q_TESTLIB_EXPORT bool qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line); @@ -233,7 +235,7 @@ namespace QTest return qCompare<qreal>(qreal(t1), t2, actual, expected, file, line); } -#elif defined(QT_COORD_TYPE) || defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE) +#elif defined(QT_COORD_TYPE) || defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN) template <> inline bool qCompare<qreal, double>(qreal const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) @@ -289,6 +291,28 @@ namespace QTest return compare_string_helper(t1, t2, actual, expected, file, line); } #else /* QTEST_NO_SPECIALIZATIONS */ + +// In Symbian we have QTEST_NO_SPECIALIZATIONS defined, but still float related specialization +// should be used. If QTEST_NO_SPECIALIZATIONS is enabled we get ambiguous overload errors. +#if defined(QT_ARCH_SYMBIAN) + template <typename T1, typename T2> + bool qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int); + + template <> + inline bool qCompare<qreal, double>(qreal const &t1, double const &t2, const char *actual, + const char *expected, const char *file, int line) + { + return qCompare<float>(float(t1), float(t2), actual, expected, file, line); + } + + template <> + inline bool qCompare<double, qreal>(double const &t1, qreal const &t2, const char *actual, + const char *expected, const char *file, int line) + { + return qCompare<float>(float(t1), float(t2), actual, expected, file, line); + } +#endif + inline bool qCompare(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) { @@ -322,6 +346,17 @@ namespace QTest return compare_string_helper(t1, t2, actual, expected, file, line); } + // NokiaX86 and RVCT do not like implicitly comparing bool with int +#ifndef QTEST_NO_SPECIALIZATIONS + template <> +#endif + inline bool qCompare(bool const &t1, int const &t2, + const char *actual, const char *expected, const char *file, int line) + { + return qCompare<int>(int(t1), t2, actual, expected, file, line); + } + + template <class T> inline bool qTest(const T& actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line) diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index 9740c21..00780b4 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -44,7 +44,7 @@ SOURCES = qtestcase.cpp \ qtestlightxmlstreamer.cpp \ qtestlogger.cpp \ qtestfilelogger.cpp -DEFINES += QT_NO_CAST_TO_ASCII \ +DEFINES *= QT_NO_CAST_TO_ASCII \ QT_NO_CAST_FROM_ASCII \ QTESTLIB_MAKEDLL \ QT_NO_DATASTREAM @@ -67,3 +67,5 @@ QMAKE_TARGET_DESCRIPTION = Qt \ Unit \ Testing \ Library + +symbian:TARGET.UID3=0x2001B2DF |