Qt 4.8
Classes | Enumerations | Functions | Variables
QTest Namespace Reference

The QTest namespace contains all the functions and declarations that are related to the QTestLib tool. More...

Classes

class  FatalSignalHandler
 
struct  IgnoreResultList
 
class  QBenchmarkIterationController
 The QBenchmarkIterationController class is used by the QBENCHMARK macro to drive the benchmarking loop. More...
 
struct  QTestDataSetter
 
class  QTouchEventSequence
 The QTouchEventSequence class is used to simulate a sequence of touch events. More...
 
struct  TestFuncCleanup
 
class  TestFunction
 

Enumerations

enum  { IndentSpacesCount = 4 }
 
enum  AttributeIndex {
  AI_Undefined = -1, AI_Name = 0, AI_Result = 1, AI_Tests = 2,
  AI_Failures = 3, AI_Errors = 4, AI_Type = 5, AI_Description = 6,
  AI_PropertyValue = 7, AI_QTestVersion = 8, AI_QtVersion = 9, AI_File = 10,
  AI_Line = 11, AI_Metric = 12, AI_Tag = 13, AI_Value = 14,
  AI_Iterations = 15
}
 This enum numbers the different tests. More...
 
enum  KeyAction { Press, Release, Click }
 This enum describes possible actions for key handling. More...
 
enum  LogElementType {
  LET_Undefined = -1, LET_Property = 0, LET_Properties = 1, LET_Failure = 2,
  LET_Error = 3, LET_TestCase = 4, LET_TestSuite = 5, LET_Benchmark = 6,
  LET_SystemError = 7
}
 The enum specifies the kinds of test log messages. More...
 
enum  MouseAction {
  MousePress, MouseRelease, MouseClick, MouseDClick,
  MouseMove
}
 This enum describes possible actions for mouse handling. More...
 
enum  QBenchmarkMetric {
  FramesPerSecond, BitsPerSecond, BytesPerSecond, WalltimeMilliseconds,
  CPUTicks, InstructionReads, Events
}
 This enum lists all the things that can be benchmarked. More...
 
enum  SkipMode { SkipSingle = 1, SkipAll = 2 }
 This enum describes the modes for skipping tests during execution of the test data. More...
 
enum  TestFailMode { Abort = 1, Continue = 2 }
 This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros. More...
 

Functions

template<typename T >
void addColumn (const char *name, T *=0)
 Adds a column with type T to the current test data. More...
 
Q_TESTLIB_EXPORT void addColumnInternal (int id, const char *name)
 
Q_TESTLIB_EXPORT Qt::Key asciiToKey (char ascii)
 Convert an ascii char key value to a Qt Key value. More...
 
Q_TESTLIB_EXPORT void beginBenchmarkMeasurement ()
 
const char * benchmarkMetricName (QBenchmarkMetric metric)
 
const char * benchmarkMetricUnit (QBenchmarkMetric metric)
 
static const char * benchmarkResult2String ()
 
static const char * benchmarkResultFormatString ()
 
Q_TESTLIB_EXPORT bool compare_helper (bool success, const char *msg, const char *file, int line)
 
Q_TESTLIB_EXPORT bool compare_helper (bool success, const char *msg, char *val1, char *val2, const char *expected, const char *actual, const char *file, int line)
 
bool compare_ptr_helper (const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line)
 
Q_TESTLIB_EXPORT bool compare_string_helper (const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T >
static int countSignificantDigits (T num)
 
Q_TESTLIB_EXPORT const char * currentAppName ()
 Returns the name of the binary that is currently executed. More...
 
Q_TESTLIB_EXPORT const char * currentDataTag ()
 Returns the name of the current test data. More...
 
Q_TESTLIB_EXPORT bool currentTestFailed ()
 Returns true if the current test function failed, otherwise false. More...
 
Q_TESTLIB_EXPORT const char * currentTestFunction ()
 Returns the name of the test function that is currently executed. More...
 
int defaultEventDelay ()
 
int Q_TESTLIB_EXPORT defaultKeyDelay ()
 
bool Q_TESTLIB_EXPORT defaultKeyVerbose ()
 
int Q_TESTLIB_EXPORT defaultMouseDelay ()
 
Q_TESTLIB_EXPORT quint64 endBenchmarkMeasurement ()
 
void * fetchData (QTestData *data, const char *tagName, int typeId)
 
void filter_unprintable (char *str)
 
template<typename T >
QString formatResult (T number, int significantDigits)
 
template<typename T >
int formatResult (char *buffer, int bufferSize, T number, int significantDigits)
 
static bool handleIgnoredMessage (QtMsgType type, const char *msg)
 
Q_TESTLIB_EXPORT void ignoreMessage (QtMsgType type, const char *message)
 Ignores messages created by qDebug() or qWarning(). More...
 
static const char * incidentFormatString (bool noDescription, bool noTag)
 
static const char * incidentType2String (QAbstractTestLogger::IncidentTypes type)
 
void initLogger ()
 
static void invokeMethod (QObject *obj, const char *methodName)
 
static bool isEmpty (const char *str)
 
static bool isValidSlot (const QMetaMethod &sl)
 
int iterationCount ()
 
static void keyClick (QWidget *widget, char key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyClick (QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyClicks (QWidget *widget, const QString &sequence, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 Simulates clicking a sequence of keys on a widget. More...
 
static void keyEvent (KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyEvent (KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyPress (QWidget *widget, char key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyPress (QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyRelease (QWidget *widget, char key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
static void keyRelease (QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
 
Q_TESTLIB_EXPORT char keyToAscii (Qt::Key key)
 Convert a Qt Key to an ascii char value. More...
 
static QByteArray memberName (const QMetaMethod &member)
 
static const char * messageFormatString (bool noDescription, bool noTag)
 
static void messageHandler (QtMsgType type, const char *msg)
 
static const char * messageType2String (QAbstractTestLogger::MessageTypes type)
 
void mouseClick (QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=0, QPoint pos=QPoint(), int delay=-1)
 Simulates clicking a mouse button with an optional modifier on a widget. More...
 
void mouseDClick (QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=0, QPoint pos=QPoint(), int delay=-1)
 Simulates double clicking a mouse button with an optional modifier on a widget. More...
 
static void mouseEvent (MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
 
void mouseMove (QWidget *widget, QPoint pos=QPoint(), int delay=-1)
 Moves the mouse pointer to a widget. More...
 
void mousePress (QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=0, QPoint pos=QPoint(), int delay=-1)
 Simulates pressing a mouse button with an optional modifier on a widget. More...
 
void mouseRelease (QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey=0, QPoint pos=QPoint(), int delay=-1)
 Simulates releasing a mouse button with an optional modifier on a widget. More...
 
Q_TESTLIB_EXPORT QTestDatanewRow (const char *dataTag)
 Appends a new row to the current test data. More...
 
static void outputMessage (const char *str)
 
static void printBenchmarkResult (const QBenchmarkResult &result)
 
static void printMessage (const char *type, const char *msg, const char *file=0, int line=0)
 
template<>
bool qCompare (QIcon const &t1, QIcon const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T >
bool qCompare (T const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (QLatin1String const &t1, QString const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T >
bool qCompare (QFlags< T > const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T1 , typename T2 >
bool qCompare (T1 const &, T2 const &, const char *, const char *, const char *, int)
 
template<typename T >
bool qCompare (QFlags< T > const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T >
bool qCompare (const T *t1, const T *t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T >
bool qCompare (T *t1, T *t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T1 , typename T2 >
bool qCompare (const T1 *t1, const T2 *t2, const char *actual, const char *expected, const char *file, int line)
 
template<typename T1 , typename T2 >
bool qCompare (T1 *t1, T2 *t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (const char *t1, char *t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare (bool const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare< char > (const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
bool qCompare< char > (char *t1, char *t2, const char *actual, const char *expected, const char *file, int line)
 
template<>
Q_TESTLIB_EXPORT bool qCompare< double > (double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int 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)
 
Q_TESTLIB_EXPORT void * qData (const char *tagName, int typeId)
 
Q_TESTLIB_EXPORT void * qElementData (const char *elementName, int metaTypeId)
 
Q_TESTLIB_EXPORT int qExec (QObject *testObject, int argc=0, char **argv=0)
 Executes tests declared in testObject. More...
 
Q_TESTLIB_EXPORT int qExec (QObject *testObject, const QStringList &arguments)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
Q_TESTLIB_EXPORT bool qExpectFail (const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line)
 
Q_TESTLIB_EXPORT void qFail (const char *statementStr, const char *file, int line)
 
Q_TESTLIB_EXPORT void * qGlobalData (const char *tagName, int typeId)
 
static bool qInvokeTestMethod (const char *slotName, const char *data=0)
 Call init(), slot_data(), slot(), slot(), slot(). More...
 
static void qInvokeTestMethodDataEntry (char *slot)
 
static void qInvokeTestMethods (QObject *testObject)
 
QBenchmarkResult qMedian (const QList< QBenchmarkResult > &container)
 
static void qPrintDataTags ()
 
static void qPrintMessage (const QByteArray &ba)
 
static void qPrintTestSlots ()
 
static void qSignalDumperCallback (QObject *caller, int method_index, void **argv)
 
static void qSignalDumperCallbackEndSignal (QObject *caller, int)
 
static void qSignalDumperCallbackSlot (QObject *caller, int method_index, void **argv)
 
Q_TESTLIB_EXPORT void qSkip (const char *message, SkipMode mode, const char *file, int line)
 
Q_TESTLIB_EXPORT void qSleep (int ms)
 Sleeps for ms milliseconds, blocking execution of the test. More...
 
int qt_asprintf (QTestCharBuffer *str, const char *format,...)
 
int Q_TESTLIB_EXPORT qt_snprintf (char *str, int size, const char *format,...)
 
template<class T >
bool qTest (const T &actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line)
 
Q_TESTLIB_EXPORT void qtest_qParseArgs (int argc, char *argv[], bool qml)
 
int qTestRandomSeed ()
 
static int qToInt (char *str)
 
Q_TESTLIB_EXPORT bool qVerify (bool statement, const char *statementStr, const char *description, const char *file, int line)
 
static void qWait (int ms)
 Waits for ms milliseconds. More...
 
static bool qWaitForWindowShown (QWidget *window)
 
Q_TESTLIB_EXPORT void qWarn (const char *message)
 
template<typename T >
static void randomizeList (T *array, int size)
 
void seedRandom ()
 
static void sendKeyEvent (KeyAction action, QWidget *widget, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1)
 
static void sendKeyEvent (KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
 
void Q_TESTLIB_EXPORT setBenchmarkResult (qreal result, QBenchmarkMetric metric)
 Sets the benchmark result for this test function to result. More...
 
void setIterationCount (int count)
 
void setIterationCountHint (int count)
 
static void simulateEvent (QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1)
 
template<typename T >
void swap (T *array, int pos, int otherPos)
 
Q_TESTLIB_EXPORT QObjecttestObject ()
 
char * toHexRepresentation (const char *ba, int length)
 Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex characters. More...
 
template<>
char * toString (const QLatin1String &str)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given string. More...
 
template<>
char * toString (const QString &str)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given string. More...
 
template<>
char * toString (const QByteArray &ba)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the byte array ba. More...
 
template<>
char * toString (const QTime &time)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given time. More...
 
template<>
char * toString (const QDate &date)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given date. More...
 
template<>
char * toString (const QDateTime &dateTime)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the date and time specified by dateTime. More...
 
template<>
char * toString (const QChar &c)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given character. More...
 
template<>
char * toString (const QPoint &p)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given point. More...
 
template<>
char * toString (const QSize &s)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given size. More...
 
template<typename T >
char * toString (const T &)
 Returns a textual representation of value. More...
 
template<>
char * toString (const QRect &s)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given rectangle. More...
 
template<>
char * toString (const QPointF &p)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given point. More...
 
Q_TESTLIB_EXPORT char * toString (const char *)
 
Q_TESTLIB_EXPORT char * toString (const void *)
 
template<>
char * toString (const QSizeF &s)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given size. More...
 
template<>
char * toString (const QRectF &s)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given rectangle. More...
 
template<>
char * toString (const QUrl &uri)
 
template<>
char * toString (const QVariant &v)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given variant. More...
 
QTouchEventSequence touchEvent (QWidget *widget=0, QTouchEvent::DeviceType deviceType=QTouchEvent::TouchScreen)
 Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget. More...
 
static const char * xmlIncidentType2String (QAbstractTestLogger::IncidentTypes type)
 
static const char * xmlMessageType2String (QAbstractTestLogger::MessageTypes type)
 

Variables

static const char * currentAppName = 0
 
static QTestDatacurrentGlobalTestData = 0
 
static QTestDatacurrentTestData = 0
 
static const char * currentTestFunc = 0
 
static QObjectcurrentTestObject = 0
 
static const char * currentTestObjectName = 0
 
static bool dataFailed = false
 
static int eventDelay = -1
 
static const char * expectFailComment = 0
 
static int expectFailMode = 0
 
static bool failed = false
 
static int fails = 0
 
static QTestLog::FlushMode flushMode = QTestLog::NoFlush
 
static int ignoreLevel = 0
 
static IgnoreResultListignoreResultList = 0
 
static int iLevel = 0
 
static int keyDelay = -1
 
static int keyVerbose = -1
 
static QTestResult::TestLocation location = QTestResult::NoWhere
 
static QTestLog::LogMode logMode = QTestLog::Plain
 
static int maxWarnings = 2002
 
static int mouseDelay = -1
 
static bool noCrashHandler = false
 
static QtMsgHandler oldMessageHandler
 
static const char * outFile = 0
 
static int passes = 0
 
Q_TESTLIB_EXPORT bool printAvailableFunctions = false
 
Q_TESTLIB_EXPORT bool printAvailableTags = false
 
static bool randomOrder = false
 
static unsigned int seed = 0
 
static bool seedSet = false
 
static bool skipCurrentTest = false
 
static int skips = 0
 
static FILE * stream = 0
 
static FILE * stream = 0
 
static FILE * stream = 0
 
static struct QTest::TestFuncCleanup testFuncCleaner
 
static int testFuncCount = 0
 
static TestFunctiontestFuncs = 0
 
Q_TESTLIB_EXPORT QStringList testFunctions
 
static QAbstractTestLoggertestLogger = 0
 
Q_TESTLIB_EXPORT QStringList testTags
 
static int verbosity = 0
 

Detailed Description

The QTest namespace contains all the functions and declarations that are related to the QTestLib tool.

Attention
Module: QtTest

Please refer to the QTestLib Manual documentation for information on how to write unit tests.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
IndentSpacesCount 

Definition at line 65 of file qsignaldumper.cpp.

◆ AttributeIndex

This enum numbers the different tests.

  • AI_Undefined
  • AI_Name
  • AI_Result
  • AI_Tests
  • AI_Failures
  • AI_Errors
  • AI_Type
  • AI_Description
  • AI_PropertyValue
  • AI_QTestVersion
  • AI_QtVersion
  • AI_File
  • AI_Line
  • AI_Metric
  • AI_Tag
  • AI_Value
  • AI_Iterations
Enumerator
AI_Undefined 
AI_Name 
AI_Result 
AI_Tests 
AI_Failures 
AI_Errors 
AI_Type 
AI_Description 
AI_PropertyValue 
AI_QTestVersion 
AI_QtVersion 
AI_File 
AI_Line 
AI_Metric 
AI_Tag 
AI_Value 
AI_Iterations 

Definition at line 55 of file qtestelementattribute.h.

◆ KeyAction

This enum describes possible actions for key handling.

  • Press The key is pressed.
  • Release The key is released.
  • Click The key is clicked (pressed and released).
Enumerator
Press 
Release 
Click 

Definition at line 68 of file qtestkeyboard.h.

◆ LogElementType

The enum specifies the kinds of test log messages.

  • LET_Undefined
  • LET_Property
  • LET_Properties
  • LET_Failure
  • LET_Error
  • LET_TestCase
  • LET_TestSuite
  • LET_Benchmark
  • LET_SystemError
Enumerator
LET_Undefined 
LET_Property 
LET_Properties 
LET_Failure 
LET_Error 
LET_TestCase 
LET_TestSuite 
LET_Benchmark 
LET_SystemError 

Definition at line 76 of file qtestelementattribute.h.

◆ MouseAction

This enum describes possible actions for mouse handling.

  • MousePress A mouse button is pressed.
  • MouseRelease A mouse button is released.
  • MouseClick A mouse button is clicked (pressed and released).
  • MouseDClick A mouse button is double clicked (pressed and released twice).
  • MouseMove The mouse pointer has moved.
Enumerator
MousePress 
MouseRelease 
MouseClick 
MouseDClick 
MouseMove 

Definition at line 69 of file qtestmouse.h.

◆ QBenchmarkMetric

This enum lists all the things that can be benchmarked.

Since
4.7
  • FramesPerSecond Frames per second
  • BitsPerSecond Bits per second
  • BytesPerSecond Bytes per second
  • WalltimeMilliseconds Clock time in milliseconds
  • CPUTicks CPU time
  • InstructionReads Instruction reads
  • Events Event count
See also
QTest::benchmarkMetricName(), QTest::benchmarkMetricUnit()
Enumerator
FramesPerSecond 
BitsPerSecond 
BytesPerSecond 
WalltimeMilliseconds 
CPUTicks 
InstructionReads 
Events 

Definition at line 55 of file qbenchmarkmetric.h.

◆ SkipMode

This enum describes the modes for skipping tests during execution of the test data.

  • SkipSingle Skips the current entry in the test table; continues execution of all the other entries in the table.
  • SkipAll Skips all the entries in the test table; the test won't be executed further.
See also
QSKIP()
Enumerator
SkipSingle 
SkipAll 

Definition at line 82 of file qtest_global.h.

◆ TestFailMode

This enum describes the modes for handling an expected failure of the QVERIFY() or QCOMPARE() macros.

  • Abort Aborts the execution of the test. Use this mode when it doesn't make sense to execute the test any further after the expected failure.
  • Continue Continues execution of the test after the expected failure.
See also
QEXPECT_FAIL()
Enumerator
Abort 
Continue 

Definition at line 83 of file qtest_global.h.

Function Documentation

◆ addColumn()

template<typename T >
void QTest::addColumn ( const char *  name,
T *  dummy = 0 
)
inline

Adds a column with type T to the current test data.

name is the name of the column. dummy is a workaround for buggy compilers and can be ignored.

To populate the column with values, newRow() can be used. Use QFETCH() to fetch the data in the actual test.

Example:

void myTestFunction_data() {
QTest::addColumn<int>("intval");
QTest::addColumn<QString>("str");
QTest::addColumn<double>("dbl");
QTest::newRow("row1") << 1 << "hello" << 1.5;
}

To add custom types to the testdata, the type must be registered with QMetaType via Q_DECLARE_METATYPE() .

Note: This macro can only be used in a test's data function that is invoked by the test framework.

See Chapter 2: Data Driven Testing for a more extensive example.

See also
QTest::newRow(), QFETCH(), QMetaType

Definition at line 168 of file qtestcase.h.

169  {
170  addColumnInternal(qMetaTypeId<T>(), name);
171  }
Q_TESTLIB_EXPORT void addColumnInternal(int id, const char *name)
Definition: qtestcase.cpp:2160
const char * name

◆ addColumnInternal()

void QTest::addColumnInternal ( int  id,
const char *  name 
)
Warning
This function is not part of the public interface.

Definition at line 2160 of file qtestcase.cpp.

Referenced by addColumn(), and toString().

2161 {
2163  QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot.");
2164 
2165  tbl->addColumn(id, name);
2166 }
const char * name
void addColumn(int elementType, const char *elementName)
Definition: qtesttable.cpp:157
static QTestTable * currentTestTable()
Definition: qtesttable.cpp:261
#define QTEST_ASSERT_X(cond, where, what)
Definition: qtestassert.h:55

◆ asciiToKey()

Qt::Key QTest::asciiToKey ( char  ascii)

Convert an ascii char key value to a Qt Key value.

Warning
This function is not part of the public interface.

If the key is unknown a 0 is returned.

Note: this may happen more than you like since not all known ascii keys are converted already. So feel free to add all the keys you need.

Definition at line 57 of file qasciikey.cpp.

Referenced by keyEvent(), and toString().

58 {
59  switch ((unsigned char)ascii) {
60  case 0x08: return Qt::Key_Backspace;
61  case 0x09: return Qt::Key_Tab;
62  case 0x0b: return Qt::Key_Backtab;
63  case 0x0d: return Qt::Key_Return;
64  case 0x1b: return Qt::Key_Escape;
65  case 0x20: return Qt::Key_Space;
66  case 0x21: return Qt::Key_Exclam;
67  case 0x22: return Qt::Key_QuoteDbl;
68  case 0x23: return Qt::Key_NumberSign;
69  case 0x24: return Qt::Key_Dollar;
70  case 0x25: return Qt::Key_Percent;
71  case 0x26: return Qt::Key_Ampersand;
72  case 0x27: return Qt::Key_Apostrophe;
73  case 0x28: return Qt::Key_ParenLeft;
74  case 0x29: return Qt::Key_ParenRight;
75  case 0x2a: return Qt::Key_Asterisk;
76  case 0x2b: return Qt::Key_Plus;
77  case 0x2c: return Qt::Key_Comma;
78  case 0x2d: return Qt::Key_Minus;
79  case 0x2e: return Qt::Key_Period;
80  case 0x2f: return Qt::Key_Slash;
81  case 0x30: return Qt::Key_0;
82  case 0x31: return Qt::Key_1;
83  case 0x32: return Qt::Key_2;
84  case 0x33: return Qt::Key_3;
85  case 0x34: return Qt::Key_4;
86  case 0x35: return Qt::Key_5;
87  case 0x36: return Qt::Key_6;
88  case 0x37: return Qt::Key_7;
89  case 0x38: return Qt::Key_8;
90  case 0x39: return Qt::Key_9;
91  case 0x3a: return Qt::Key_Colon;
92  case 0x3b: return Qt::Key_Semicolon;
93  case 0x3c: return Qt::Key_Less;
94  case 0x3d: return Qt::Key_Equal;
95  case 0x3e: return Qt::Key_Greater;
96  case 0x3f: return Qt::Key_Question;
97  case 0x40: return Qt::Key_At;
98  case 0x41: return Qt::Key_A;
99  case 0x42: return Qt::Key_B;
100  case 0x43: return Qt::Key_C;
101  case 0x44: return Qt::Key_D;
102  case 0x45: return Qt::Key_E;
103  case 0x46: return Qt::Key_F;
104  case 0x47: return Qt::Key_G;
105  case 0x48: return Qt::Key_H;
106  case 0x49: return Qt::Key_I;
107  case 0x4a: return Qt::Key_J;
108  case 0x4b: return Qt::Key_K;
109  case 0x4c: return Qt::Key_L;
110  case 0x4d: return Qt::Key_M;
111  case 0x4e: return Qt::Key_N;
112  case 0x4f: return Qt::Key_O;
113  case 0x50: return Qt::Key_P;
114  case 0x51: return Qt::Key_Q;
115  case 0x52: return Qt::Key_R;
116  case 0x53: return Qt::Key_S;
117  case 0x54: return Qt::Key_T;
118  case 0x55: return Qt::Key_U;
119  case 0x56: return Qt::Key_V;
120  case 0x57: return Qt::Key_W;
121  case 0x58: return Qt::Key_X;
122  case 0x59: return Qt::Key_Y;
123  case 0x5a: return Qt::Key_Z;
124  case 0x5b: return Qt::Key_BracketLeft;
125  case 0x5c: return Qt::Key_Backslash;
126  case 0x5d: return Qt::Key_BracketRight;
127  case 0x5e: return Qt::Key_AsciiCircum;
128  case 0x5f: return Qt::Key_Underscore;
129  case 0x60: return Qt::Key_QuoteLeft;
130  case 0x61: return Qt::Key_A;
131  case 0x62: return Qt::Key_B;
132  case 0x63: return Qt::Key_C;
133  case 0x64: return Qt::Key_D;
134  case 0x65: return Qt::Key_E;
135  case 0x66: return Qt::Key_F;
136  case 0x67: return Qt::Key_G;
137  case 0x68: return Qt::Key_H;
138  case 0x69: return Qt::Key_I;
139  case 0x6a: return Qt::Key_J;
140  case 0x6b: return Qt::Key_K;
141  case 0x6c: return Qt::Key_L;
142  case 0x6d: return Qt::Key_M;
143  case 0x6e: return Qt::Key_N;
144  case 0x6f: return Qt::Key_O;
145  case 0x70: return Qt::Key_P;
146  case 0x71: return Qt::Key_Q;
147  case 0x72: return Qt::Key_R;
148  case 0x73: return Qt::Key_S;
149  case 0x74: return Qt::Key_T;
150  case 0x75: return Qt::Key_U;
151  case 0x76: return Qt::Key_V;
152  case 0x77: return Qt::Key_W;
153  case 0x78: return Qt::Key_X;
154  case 0x79: return Qt::Key_Y;
155  case 0x7a: return Qt::Key_Z;
156  case 0x7b: return Qt::Key_BraceLeft;
157  case 0x7c: return Qt::Key_Bar;
158  case 0x7d: return Qt::Key_BraceRight;
159  case 0x7e: return Qt::Key_AsciiTilde;
160 
161  // Latin 1 codes adapted from X: keysymdef.h,v 1.21 94/08/28 16:17:06
162  case 0xa0: return Qt::Key_nobreakspace;
163  case 0xa1: return Qt::Key_exclamdown;
164  case 0xa2: return Qt::Key_cent;
165  case 0xa3: return Qt::Key_sterling;
166  case 0xa4: return Qt::Key_currency;
167  case 0xa5: return Qt::Key_yen;
168  case 0xa6: return Qt::Key_brokenbar;
169  case 0xa7: return Qt::Key_section;
170  case 0xa8: return Qt::Key_diaeresis;
171  case 0xa9: return Qt::Key_copyright;
172  case 0xaa: return Qt::Key_ordfeminine;
173  case 0xab: return Qt::Key_guillemotleft;
174  case 0xac: return Qt::Key_notsign;
175  case 0xad: return Qt::Key_hyphen;
176  case 0xae: return Qt::Key_registered;
177  case 0xaf: return Qt::Key_macron;
178  case 0xb0: return Qt::Key_degree;
179  case 0xb1: return Qt::Key_plusminus;
180  case 0xb2: return Qt::Key_twosuperior;
181  case 0xb3: return Qt::Key_threesuperior;
182  case 0xb4: return Qt::Key_acute;
183  case 0xb5: return Qt::Key_mu;
184  case 0xb6: return Qt::Key_paragraph;
185  case 0xb7: return Qt::Key_periodcentered;
186  case 0xb8: return Qt::Key_cedilla;
187  case 0xb9: return Qt::Key_onesuperior;
188  case 0xba: return Qt::Key_masculine;
189  case 0xbb: return Qt::Key_guillemotright;
190  case 0xbc: return Qt::Key_onequarter;
191  case 0xbd: return Qt::Key_onehalf;
192  case 0xbe: return Qt::Key_threequarters;
193  case 0xbf: return Qt::Key_questiondown;
194  case 0xc0: return Qt::Key_Agrave;
195  case 0xc1: return Qt::Key_Aacute;
196  case 0xc2: return Qt::Key_Acircumflex;
197  case 0xc3: return Qt::Key_Atilde;
198  case 0xc4: return Qt::Key_Adiaeresis;
199  case 0xc5: return Qt::Key_Aring;
200  case 0xc6: return Qt::Key_AE;
201  case 0xc7: return Qt::Key_Ccedilla;
202  case 0xc8: return Qt::Key_Egrave;
203  case 0xc9: return Qt::Key_Eacute;
204  case 0xca: return Qt::Key_Ecircumflex;
205  case 0xcb: return Qt::Key_Ediaeresis;
206  case 0xcc: return Qt::Key_Igrave;
207  case 0xcd: return Qt::Key_Iacute;
208  case 0xce: return Qt::Key_Icircumflex;
209  case 0xcf: return Qt::Key_Idiaeresis;
210  case 0xd0: return Qt::Key_ETH;
211  case 0xd1: return Qt::Key_Ntilde;
212  case 0xd2: return Qt::Key_Ograve;
213  case 0xd3: return Qt::Key_Oacute;
214  case 0xd4: return Qt::Key_Ocircumflex;
215  case 0xd5: return Qt::Key_Otilde;
216  case 0xd6: return Qt::Key_Odiaeresis;
217  case 0xd7: return Qt::Key_multiply;
218  case 0xd8: return Qt::Key_Ooblique;
219  case 0xd9: return Qt::Key_Ugrave;
220  case 0xda: return Qt::Key_Uacute;
221  case 0xdb: return Qt::Key_Ucircumflex;
222  case 0xdc: return Qt::Key_Udiaeresis;
223  case 0xdd: return Qt::Key_Yacute;
224  case 0xde: return Qt::Key_THORN;
225  case 0xdf: return Qt::Key_ssharp;
226  case 0xe5: return Qt::Key_Aring;
227  case 0xe6: return Qt::Key_AE;
228  case 0xf7: return Qt::Key_division;
229  case 0xf8: return Qt::Key_Ooblique;
230  case 0xff: return Qt::Key_ydiaeresis;
231  default: QTEST_ASSERT(false); return Qt::Key(0);
232  }
233 }
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53

◆ beginBenchmarkMeasurement()

void QTest::beginBenchmarkMeasurement ( )
Warning
This function is not part of the public interface.

Definition at line 260 of file qbenchmark.cpp.

Referenced by QTest::QBenchmarkIterationController::QBenchmarkIterationController().

261 {
263  // the clock is ticking after the line above, don't add code here.
264 }
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
virtual void start()=0
QBenchmarkMeasurerBase * measurer
Definition: qbenchmark_p.h:146

◆ benchmarkMetricName()

const char* QTest::benchmarkMetricName ( QBenchmarkMetric  metric)

◆ benchmarkMetricUnit()

const char* QTest::benchmarkMetricUnit ( QBenchmarkMetric  metric)

Referenced by printBenchmarkResult().

◆ benchmarkResult2String()

static const char* QTest::benchmarkResult2String ( )
static

Definition at line 125 of file qplaintestlogger.cpp.

Referenced by printBenchmarkResult().

126  {
127  static bool colored = (!qgetenv("QTEST_COLORED").isEmpty());
128  return COLORED_MSG(0, 36, "RESULT "); // cyan
129  }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
#define COLORED_MSG(prefix, color, msg)

◆ benchmarkResultFormatString()

static const char* QTest::benchmarkResultFormatString ( )
static

Definition at line 189 of file qxmltestlogger.cpp.

Referenced by QXmlTestLogger::addBenchmarkResult().

190 {
191  return "<BenchmarkResult metric=\"%s\" tag=\"%s\" value=\"%s\" iterations=\"%d\" />\n";
192 }

◆ compare_helper() [1/2]

bool QTest::compare_helper ( bool  success,
const char *  msg,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2290 of file qtestcase.cpp.

Referenced by compare_ptr_helper(), compare_string_helper(), qCompare(), qCompare< double >(), qCompare< float >(), and toString().

2291 {
2292  return QTestResult::compare(success, msg, file, line);
2293 }
static bool compare(bool success, const char *msg, const char *file, int line)

◆ compare_helper() [2/2]

bool QTest::compare_helper ( bool  success,
const char *  msg,
char *  val1,
char *  val2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2297 of file qtestcase.cpp.

2299 {
2300  return QTestResult::compare(success, msg, val1, val2, actual, expected, file, line);
2301 }
static bool compare(bool success, const char *msg, const char *file, int line)

◆ compare_ptr_helper()

bool QTest::compare_ptr_helper ( const void *  t1,
const void *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 193 of file qtestcase.h.

Referenced by qCompare().

195  {
196  return (t1 == t2)
197  ? compare_helper(true, "COMPARE()", file, line)
198  : compare_helper(false, "Compared pointers are not the same",
199  toString(t1), toString(t2), actual, expected, file, line);
200  }
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, char *val1, char *val2, const char *expected, const char *actual, const char *file, int line)
Definition: qtestcase.cpp:2297
static QString toString(Register *reg, int type, bool *ok=0)

◆ compare_string_helper()

bool QTest::compare_string_helper ( const char *  t1,
const char *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2376 of file qtestcase.cpp.

Referenced by compare_ptr_helper(), qCompare(), and qCompare< char >().

2378 {
2379  return (qstrcmp(t1, t2) == 0)
2380  ? compare_helper(true, "COMPARE()", file, line)
2381  : compare_helper(false, "Compared strings are not the same",
2382  toString(t1), toString(t2), actual, expected, file, line);
2383 }
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
static QString toString(Register *reg, int type, bool *ok=0)
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, const char *file, int line)
Definition: qtestcase.cpp:2290

◆ countSignificantDigits()

template<typename T >
static int QTest::countSignificantDigits ( num)
static

Definition at line 233 of file qplaintestlogger.cpp.

Referenced by printBenchmarkResult().

234  {
235  if (num <= 0)
236  return 0;
237 
238  int digits = 0;
239  qreal divisor = 1;
240 
241  while (num / divisor >= 1) {
242  divisor *= 10;
243  ++digits;
244  }
245 
246  return digits;
247  }
double qreal
Definition: qglobal.h:1193

◆ currentAppName()

const char * QTest::currentAppName ( )

Returns the name of the binary that is currently executed.

Definition at line 2218 of file qtestcase.cpp.

2219 {
2220  return QTestResult::currentAppName();
2221 }
static const char * currentAppName()

◆ currentDataTag()

const char * QTest::currentDataTag ( )

Returns the name of the current test data.

If the test doesn't have any assigned testdata, the function returns 0.

Definition at line 2239 of file qtestcase.cpp.

Referenced by toString().

2240 {
2241  return QTestResult::currentDataTag();
2242 }
static const char * currentDataTag()

◆ currentTestFailed()

bool QTest::currentTestFailed ( )

Returns true if the current test function failed, otherwise false.

Definition at line 2247 of file qtestcase.cpp.

Referenced by qInvokeTestMethods(), and toString().

2248 {
2250 }
static bool currentTestFailed()
Definition: qtestresult.cpp:98

◆ currentTestFunction()

const char * QTest::currentTestFunction ( )

Returns the name of the test function that is currently executed.

Example:

{
if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
// clean up all database connections
closeAllDatabases();
}
}

Definition at line 2230 of file qtestcase.cpp.

Referenced by toString().

2231 {
2233 }
static const char * currentTestFunction()

◆ defaultEventDelay()

int QTest::defaultEventDelay ( )

Definition at line 997 of file qtestcase.cpp.

Referenced by defaultKeyDelay(), and defaultMouseDelay().

998 {
999  if (eventDelay == -1) {
1000  if (qgetenv("QTEST_EVENT_DELAY").constData())
1001  eventDelay = atoi(qgetenv("QTEST_EVENT_DELAY"));
1002  else
1003  eventDelay = 0;
1004  }
1005  return eventDelay;
1006 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static int eventDelay
Definition: qtestcase.cpp:940

◆ defaultKeyDelay()

int Q_TESTLIB_EXPORT QTest::defaultKeyDelay ( )

Definition at line 1019 of file qtestcase.cpp.

Referenced by simulateEvent().

1020 {
1021  if (keyDelay == -1) {
1022  if (qgetenv("QTEST_KEYEVENT_DELAY").constData())
1023  keyDelay = atoi(qgetenv("QTEST_KEYEVENT_DELAY").constData());
1024  else
1026  }
1027  return keyDelay;
1028 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
int defaultEventDelay()
Definition: qtestcase.cpp:997
static int keyDelay
Definition: qtestcase.cpp:938

◆ defaultKeyVerbose()

bool Q_TESTLIB_EXPORT QTest::defaultKeyVerbose ( )

Definition at line 989 of file qtestcase.cpp.

990 {
991  if (keyVerbose == -1) {
992  keyVerbose = qgetenv("QTEST_KEYEVENT_VERBOSE").constData() ? 1 : 0;
993  }
994  return keyVerbose == 1;
995 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
static int keyVerbose
Definition: qtestcase.cpp:942
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ defaultMouseDelay()

int Q_TESTLIB_EXPORT QTest::defaultMouseDelay ( )

Definition at line 1008 of file qtestcase.cpp.

Referenced by mouseEvent().

1009 {
1010  if (mouseDelay == -1) {
1011  if (qgetenv("QTEST_MOUSEEVENT_DELAY").constData())
1012  mouseDelay = atoi((qgetenv("QTEST_MOUSEEVENT_DELAY")));
1013  else
1015  }
1016  return mouseDelay;
1017 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
int defaultEventDelay()
Definition: qtestcase.cpp:997
static int mouseDelay
Definition: qtestcase.cpp:939

◆ endBenchmarkMeasurement()

quint64 QTest::endBenchmarkMeasurement ( )
Warning
This function is not part of the public interface.

Definition at line 268 of file qbenchmark.cpp.

Referenced by QTest::QBenchmarkIterationController::~QBenchmarkIterationController().

269 {
270  // the clock is ticking before the line below, don't add code here.
272 }
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
QBenchmarkMeasurerBase * measurer
Definition: qbenchmark_p.h:146
virtual qint64 stop()=0

◆ fetchData()

void* QTest::fetchData ( QTestData data,
const char *  tagName,
int  typeId 
)

Definition at line 1635 of file qtestcase.cpp.

Referenced by QXmlInputSource::next(), qData(), and qGlobalData().

1636 {
1637  QTEST_ASSERT(typeId);
1638  QTEST_ASSERT_X(data, "QTest::fetchData()", "Test data requested, but no testdata available.");
1639  QTEST_ASSERT(data->parent());
1640 
1641  int idx = data->parent()->indexOf(tagName);
1642 
1643  if (idx == -1 || idx >= data->dataCount()) {
1644  qFatal("QFETCH: Requested testdata '%s' not available, check your _data function.",
1645  tagName);
1646  }
1647 
1648  if (typeId != data->parent()->elementTypeId(idx)) {
1649  qFatal("Requested type '%s' does not match available type '%s'.",
1650  QMetaType::typeName(typeId),
1651  QMetaType::typeName(data->parent()->elementTypeId(idx)));
1652  }
1653 
1654  return data->data(idx);
1655 }
QTestTable * parent() const
Definition: qtestdata.cpp:107
int elementTypeId(int index) const
Definition: qtesttable.cpp:212
void * data(int index) const
Definition: qtestdata.cpp:100
Q_CORE_EXPORT void qFatal(const char *,...)
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
int indexOf(const char *elementName) const
Definition: qtesttable.cpp:233
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
int dataCount() const
Definition: qtestdata.cpp:117
#define QTEST_ASSERT_X(cond, where, what)
Definition: qtestassert.h:55

◆ filter_unprintable()

void QTest::filter_unprintable ( char *  str)

Definition at line 949 of file qtestcase.cpp.

Referenced by qt_asprintf(), qt_snprintf(), and QAbstractTestLogger::stopLogging().

950 {
951  char *idx = str;
952  while (*idx) {
953  if (((*idx < 0x20 && *idx != '\n' && *idx != '\t') || *idx > 0x7e))
954  *idx = '?';
955  ++idx;
956  }
957 }

◆ formatResult() [1/2]

template<typename T >
QString QTest::formatResult ( number,
int  significantDigits 
)

Definition at line 250 of file qplaintestlogger.cpp.

Referenced by formatResult(), and printBenchmarkResult().

251  {
252  if (number < T(0))
253  return QLatin1String("NAN");
254  if (number == T(0))
255  return QLatin1String("0");
256 
257  QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0);
258  QString afterDecimalPoint = QString::number(number, 'f', 20);
259  afterDecimalPoint.remove(0, beforeDecimalPoint.count() + 1);
260 
261  int beforeUse = qMin(beforeDecimalPoint.count(), significantDigits);
262  int beforeRemove = beforeDecimalPoint.count() - beforeUse;
263 
264  // Replace insignificant digits before the decimal point with zeros.
265  beforeDecimalPoint.chop(beforeRemove);
266  for (int i = 0; i < beforeRemove; ++i) {
267  beforeDecimalPoint.append(QLatin1Char('0'));
268  }
269 
270  int afterUse = significantDigits - beforeUse;
271 
272  // leading zeroes after the decimal point does not count towards the digit use.
273  if (beforeDecimalPoint == QLatin1String("0") && afterDecimalPoint.isEmpty() == false) {
274  ++afterUse;
275 
276  int i = 0;
277  while (i < afterDecimalPoint.count() && afterDecimalPoint.at(i) == QLatin1Char('0')) {
278  ++i;
279  }
280 
281  afterUse += i;
282  }
283 
284  int afterRemove = afterDecimalPoint.count() - afterUse;
285  afterDecimalPoint.chop(afterRemove);
286 
287  QChar separator = QLatin1Char(',');
288  QChar decimalPoint = QLatin1Char('.');
289 
290  // insert thousands separators
291  int length = beforeDecimalPoint.length();
292  for (int i = beforeDecimalPoint.length() -1; i >= 1; --i) {
293  if ((length - i) % 3 == 0)
294  beforeDecimalPoint.insert(i, separator);
295  }
296 
297  QString print;
298  print = beforeDecimalPoint;
299  if (afterUse > 0)
300  print.append(decimalPoint);
301 
302  print += afterDecimalPoint;
303 
304 
305  return print;
306  }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
__int64 qint64
Definition: qglobal.h:942
int count() const
Definition: qstring.h:103
QString & append(QChar c)
Definition: qstring.cpp:1777
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
QString & insert(int i, QChar c)
Definition: qstring.cpp:1671
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ formatResult() [2/2]

template<typename T >
int QTest::formatResult ( char *  buffer,
int  bufferSize,
number,
int  significantDigits 
)

Definition at line 309 of file qplaintestlogger.cpp.

310  {
311  QString result = formatResult(number, significantDigits);
312  qstrncpy(buffer, result.toAscii().constData(), bufferSize);
313  int size = result.count();
314  return size;
315  }
The QString class provides a Unicode character string.
Definition: qstring.h:83
int count() const
Definition: qstring.h:103
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
int formatResult(char *buffer, int bufferSize, T number, int significantDigits)
char * qstrncpy(char *dst, const char *src, uint len)
A safe strncpy() function.
Definition: qbytearray.cpp:175

◆ handleIgnoredMessage()

static bool QTest::handleIgnoredMessage ( QtMsgType  type,
const char *  msg 
)
static

Definition at line 97 of file qtestlog.cpp.

Referenced by messageHandler().

98  {
99  IgnoreResultList *last = 0;
100  IgnoreResultList *list = ignoreResultList;
101  while (list) {
102  if (list->type == type && strcmp(msg, list->msg) == 0) {
103  // remove the item from the list
104  if (last)
105  last->next = list->next;
106  else if (list->next)
107  ignoreResultList = list->next;
108  else
109  ignoreResultList = 0;
110 
111  delete list;
112  return true;
113  }
114 
115  last = list;
116  list = list->next;
117  }
118  return false;
119  }
int type
Definition: qmetatype.cpp:239
static IgnoreResultList * ignoreResultList
Definition: qtestlog.cpp:85
IgnoreResultList * next
Definition: qtestlog.cpp:82

◆ ignoreMessage()

void QTest::ignoreMessage ( QtMsgType  type,
const char *  message 
)

Ignores messages created by qDebug() or qWarning().

If the message with the corresponding type is outputted, it will be removed from the test log. If the test finished and the message was not outputted, a test failure is appended to the test log.

Note: Invoking this function will only ignore one message. If the message you want to ignore is outputted twice, you have to call ignoreMessage() twice, too.

Example:

QDir dir;
QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
dir.mkdir("");

The example above tests that QDir::mkdir() outputs the right warning when invoked with an invalid file name.

Definition at line 2123 of file qtestcase.cpp.

Referenced by toString().

2124 {
2125  QTestResult::ignoreMessage(type, message);
2126 }
int type
Definition: qmetatype.cpp:239
static void ignoreMessage(QtMsgType type, const char *msg)

◆ incidentFormatString()

static const char* QTest::incidentFormatString ( bool  noDescription,
bool  noTag 
)
static

Definition at line 167 of file qxmltestlogger.cpp.

Referenced by QXmlTestLogger::addIncident().

168 {
169  if (noDescription) {
170  if (noTag)
171  return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
172  else
173  return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
174  " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
175  "</Incident>\n";
176  } else {
177  if (noTag)
178  return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
179  " <Description><![CDATA[%s%s%s%s]]></Description>\n"
180  "</Incident>\n";
181  else
182  return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
183  " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
184  " <Description><![CDATA[%s]]></Description>\n"
185  "</Incident>\n";
186  }
187 }

◆ incidentType2String()

static const char* QTest::incidentType2String ( QAbstractTestLogger::IncidentTypes  type)
static

Definition at line 109 of file qplaintestlogger.cpp.

Referenced by QPlainTestLogger::addIncident().

110  {
111  static bool colored = (!qgetenv("QTEST_COLORED").isEmpty());
112  switch (type) {
114  return COLORED_MSG(0, 32, "PASS "); //green
116  return COLORED_MSG(1, 32, "XFAIL "); //light green
118  return COLORED_MSG(0, 31, "FAIL! "); //red
120  return COLORED_MSG(0, 31, "XPASS "); //red, too
121  }
122  return "??????";
123  }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
int type
Definition: qmetatype.cpp:239
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
#define COLORED_MSG(prefix, color, msg)

◆ initLogger()

void QTest::initLogger ( )

Definition at line 171 of file qtestlog.cpp.

Referenced by QTestLog::startLogging().

172 {
173  switch (QTest::logMode) {
174  case QTestLog::Plain:
176  break;
177  case QTestLog::XML:{
180  else
182  break;
183  }case QTestLog::LightXML:{
186  else
188  break;
189  }case QTestLog::XunitXML:
191  }
192 }
static QTestLog::LogMode logMode
Definition: qtestlog.cpp:87
static QTestLog::FlushMode flushMode
Definition: qtestlog.cpp:88
static QAbstractTestLogger * testLogger
Definition: qtestlog.cpp:92

◆ invokeMethod()

static void QTest::invokeMethod ( QObject obj,
const char *  methodName 
)
static
Warning
This function is not part of the public interface. Invoke a method of the object without generating warning if the method does not exist

Definition at line 979 of file qtestcase.cpp.

Referenced by QAccessibleInterface::backgroundColor(), QAccessibleInterface::foregroundColor(), QMetaObject::invokeMethod(), qInvokeTestMethod(), qInvokeTestMethodDataEntry(), qInvokeTestMethods(), qPrintDataTags(), QAccessibleInterface::supportedMethods(), and QAccessibleInterface::~QAccessibleInterface().

980 {
981  const QMetaObject *metaObject = obj->metaObject();
982  int funcIndex = metaObject->indexOfMethod(methodName);
983  if (funcIndex >= 0) {
984  QMetaMethod method = metaObject->method(funcIndex);
985  method.invoke(obj, Qt::DirectConnection);
986  }
987 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
static QByteArray methodName(const char *signature, int nameLength)
Makes a deep copy of the first nameLength characters of the given method signature and returns the co...
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
bool invoke(QObject *object, Qt::ConnectionType connectionType, QGenericReturnArgument returnValue, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument()) const
Invokes this method on the object object.
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ isEmpty()

static bool QTest::isEmpty ( const char *  str)
inlinestatic

Definition at line 162 of file qxmltestlogger.cpp.

Referenced by QTimerInfoList::activateTimers(), QSvgStructureNode::addChild(), QPostEventList::addEvent(), QXmlTestLogger::addIncident(), QXmlTestLogger::addMessage(), QCopChannel::answer(), QSvgNode::appendStyleProperty(), QCoreApplication::applicationFilePath(), QPatternist::TypeChecker::applyFunctionConversion(), QAxWidget::clear(), QApplicationPrivate::closePopup(), QPainterPath::contains(), QString::count(), QPatternist::AbstractDuration::create(), QEglFSScreen::createAndSetPlatformContext(), QCoreApplicationPrivate::createEventDispatcher(), QThreadPrivate::createEventDispatcher(), createReadHandlerHelper(), QDeclarativeTypeData::dataReceived(), QETWidget::doDeferredMap(), QDeclarativeXmlQueryEngine::doSubQueryJob(), QTextLayout::draw(), QObject::dumpObjectInfo(), QAxBase::dynamicCallHelper(), QLinkedList< JSC::Identifier >::empty(), QList< QPostEvent >::empty(), QMap< int, QFrameInfo >::empty(), QHash< QExplicitlySharedDataPointer, QHash >::empty(), QLinkedList< JSC::Identifier >::endsWith(), QVector< QPoint >::endsWith(), QList< QPostEvent >::endsWith(), QProxyStylePrivate::ensureBaseStyle(), QNetworkDiskCache::expire(), QGestureManager::filterEventThroughContexts(), QContiguousCache< T >::first(), QLinkedList< JSC::Identifier >::first(), QVector< QPoint >::first(), QList< QPostEvent >::first(), QXcbWindowSurface::flush(), getFullPath(), QDockAreaLayout::getGrid(), if(), QDirectFBScreen::initDevice(), QAxBase::initialize(), QMacPasteboardMime::initialize(), QPainterPath::intersected(), QPainterPath::intersects(), QStateMachinePrivate::isAtomic(), QStateMachinePrivate::isCompound(), isEmptyHelper(), isNull(), QStyleSheetBorderData::isOpaque(), QIndexMapper::isValid(), QItemSelectionRange::isValid(), isValidUri(), isValidWildcardRestriction(), QPatternist::XsdSchemaHelper::isWildcardSubset(), QContiguousCache< T >::last(), QLinkedList< JSC::Identifier >::last(), QVector< QPoint >::last(), QList< QPostEvent >::last(), launchWebBrowser(), QDialogButtonBoxPrivate::layoutButtons(), QPainterPath::length(), QIconLoader::loadIcon(), macVersion(), QDeclarativeText::mousePressEvent(), QAccessibleGroupBox::navigate(), QCFString::operator QString(), QSqlRecord::operator!=(), QProcessEnvironment::operator!=(), QRegExp::operator!=(), QList< QPostEvent >::operator+=(), QStringList::operator<<(), QPatternist::GeneralComparison::optimizationPasses(), QDeclarativeStyledText::parse(), QXmlSimpleReaderPrivate::parseContent(), QPatternist::XsdSchemaParser::parseNotation(), QPainterPath::percentAtLength(), QVector< QPoint >::pop_back(), QVector< QPoint >::pop_front(), QGLEngineSelector::preferredPaintEngine(), QSQLiteResult::prepare(), QPrinter::printRange(), QEventDispatcherQWS::processEvents(), QXmlSimpleReaderPrivate::processReference(), qax_noSuchFunction(), qDBusGenerateMetaObjectXml(), qDBusInterfaceFromMetaObject(), QEventDispatcherGlibPrivate::QEventDispatcherGlibPrivate(), QRect::QRect(), QRuntimeGraphicsSystem::QRuntimeGraphicsSystem(), qt_bitmapToRegion(), qt_region_strictContains(), qt_try_modal(), QETWidget::raiseOnClick(), QDeclarativeBindingCompilerPrivate::registerString(), QHash< QExplicitlySharedDataPointer, QHash >::remove(), QLinkedList< JSC::Identifier >::removeFirst(), QList< QPostEvent >::removeFirst(), QLinkedList< JSC::Identifier >::removeLast(), QList< QPostEvent >::removeLast(), QKqueueFileSystemWatcherEngine::removePaths(), QPatternist::ReportContext::resolveURI(), QFileDialog::restoreState(), QSqlRelationalTableModel::selectStatement(), QLineControl::setCursorBlinkPeriod(), QDockAreaLayout::setGrid(), QFileSystemModel::setRootPath(), QApplicationPrivate::setScreenTransformation(), QApplication::setStyle(), QLabel::setText(), QMdiSubWindow::setWidget(), QSidebar::showContextMenu(), QPainterPath::simplified(), someId(), QCommonStyle::standardPixmap(), QLinkedList< JSC::Identifier >::startsWith(), QVector< QPoint >::startsWith(), QList< QPostEvent >::startsWith(), QApplication::style(), QPainterPath::subtracted(), QRegion::swap(), QPainterPath::swap(), QUrl::swap(), QByteArray::swap(), QHash< QExplicitlySharedDataPointer, QHash >::take(), QAccessibleDial::text(), QLineControl::timerEvent(), QDeclarativeError::toString(), QPainterPath::united(), QTimerInfoList::unregisterTimers(), QListView::updateGeometries(), QWorkspaceChild::updateMask(), QGtkStyleUpdateScheduler::updateTheme(), QTestAccessibility::verifyEvent(), QApplicationPrivate::x11_apply_settings(), and QPatternist::yyparse().

163 {
164  return !str || !str[0];
165 }

◆ isValidSlot()

static bool QTest::isValidSlot ( const QMetaMethod sl)
static

Definition at line 1067 of file qtestcase.cpp.

Referenced by qInvokeTestMethods(), qPrintDataTags(), qPrintTestSlots(), and qtest_qParseArgs().

1068 {
1069  if (sl.access() != QMetaMethod::Private || !sl.parameterTypes().isEmpty()
1070  || qstrlen(sl.typeName()) || sl.methodType() != QMetaMethod::Slot)
1071  return false;
1072  const char *sig = sl.signature();
1073  int len = qstrlen(sig);
1074  if (len < 2)
1075  return false;
1076  if (sig[len - 2] != '(' || sig[len - 1] != ')')
1077  return false;
1078  if (len > 7 && strcmp(sig + (len - 7), "_data()") == 0)
1079  return false;
1080  if (strcmp(sig, "initTestCase()") == 0 || strcmp(sig, "cleanupTestCase()") == 0
1081  || strcmp(sig, "cleanup()") == 0 || strcmp(sig, "init()") == 0)
1082  return false;
1083  return true;
1084 }
const char * typeName() const
Returns the return type of this method, or an empty string if the return type is void.
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
MethodType methodType() const
Returns the type of this method (signal, slot, or method).
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
uint qstrlen(const char *str)
Definition: qbytearray.h:79
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
Access access() const
Returns the access specification of this method (private, protected, or public).

◆ iterationCount()

int QTest::iterationCount ( )
Warning
This function is not part of the public interface.

Definition at line 238 of file qbenchmark.cpp.

Referenced by elapsed(), and QTest::QBenchmarkIterationController::isDone().

239 {
241 }
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167

◆ keyClick() [1/2]

static void QTest::keyClick ( QWidget widget,
char  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 179 of file qtestkeyboard.h.

180  { keyEvent(Click, widget, key, modifier, delay); }
int key
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)

◆ keyClick() [2/2]

static void QTest::keyClick ( QWidget widget,
Qt::Key  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 185 of file qtestkeyboard.h.

186  { keyEvent(Click, widget, key, modifier, delay); }
int key
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)

◆ keyClicks()

void QTest::keyClicks ( QWidget widget,
const QString sequence,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Simulates clicking a sequence of keys on a widget.

Optionally, a keyboard modifier can be specified as well as a delay (in milliseconds) of the test before each key click.

Example:

QTest::keyClicks(myWidget, "hello world");

The example above simulates clicking the sequence of keys representing "hello world" on myWidget without any keyboard modifiers and without delay of the test.

See also
QTest::keyClick()

Definition at line 168 of file qtestkeyboard.h.

Referenced by QTestEvent::~QTestEvent().

170  {
171  for (int i=0; i < sequence.length(); i++)
172  keyEvent(Click, widget, sequence.at(i).toLatin1(), modifier, delay);
173  }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
Definition: qchar.h:376

◆ keyEvent() [1/2]

static void QTest::keyEvent ( KeyAction  action,
QWidget widget,
char  ascii,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 161 of file qtestkeyboard.h.

Referenced by QCalendarPopup::event(), QMdiArea::eventFilter(), QBBInputContext::handleKeyboardEvent(), QVNCServer::hasClientCursor(), QmlJSDebugger::AbstractTool::inspector(), keyClick(), keyClicks(), keyPress(), keyRelease(), qt_dispatchKeyEvent(), qtKey2CocoaKey(), QVNCServer::setCursor(), QmlJSDebugger::AbstractViewInspector::slowDownFactor(), and QTestEvent::~QTestEvent().

163  { sendKeyEvent(action, widget, asciiToKey(ascii), ascii, modifier, delay); }
static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
Q_TESTLIB_EXPORT Qt::Key asciiToKey(char ascii)
Convert an ascii char key value to a Qt Key value.
Definition: qasciikey.cpp:57

◆ keyEvent() [2/2]

static void QTest::keyEvent ( KeyAction  action,
QWidget widget,
Qt::Key  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 164 of file qtestkeyboard.h.

166  { sendKeyEvent(action, widget, key, keyToAscii(key), modifier, delay); }
static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
int key
Q_TESTLIB_EXPORT char keyToAscii(Qt::Key key)
Convert a Qt Key to an ascii char value.
Definition: qasciikey.cpp:245

◆ keyPress() [1/2]

static void QTest::keyPress ( QWidget widget,
char  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 175 of file qtestkeyboard.h.

Referenced by QMdiArea::eventFilter().

176  { keyEvent(Press, widget, key, modifier, delay); }
int key
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)

◆ keyPress() [2/2]

static void QTest::keyPress ( QWidget widget,
Qt::Key  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 181 of file qtestkeyboard.h.

182  { keyEvent(Press, widget, key, modifier, delay); }
int key
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)

◆ keyRelease() [1/2]

static void QTest::keyRelease ( QWidget widget,
char  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 177 of file qtestkeyboard.h.

178  { keyEvent(Release, widget, key, modifier, delay); }
int key
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)

◆ keyRelease() [2/2]

static void QTest::keyRelease ( QWidget widget,
Qt::Key  key,
Qt::KeyboardModifiers  modifier = Qt::NoModifier,
int  delay = -1 
)
inlinestatic

Definition at line 183 of file qtestkeyboard.h.

184  { keyEvent(Release, widget, key, modifier, delay); }
int key
static void keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier=Qt::NoModifier, int delay=-1)

◆ keyToAscii()

char QTest::keyToAscii ( Qt::Key  key)

Convert a Qt Key to an ascii char value.

Warning
This function is not part of the public interface.

If the Qt key is unknown a 0 is returned.

Note: this may happen more than you like since not all known Qt keys are converted already. So feel free to add all the keys you need.

Definition at line 245 of file qasciikey.cpp.

Referenced by keyEvent(), and toString().

246 {
247  switch (key) {
248  case Qt::Key_Backspace: return 0x8; //BS
249  case Qt::Key_Tab: return 0x09; // HT
250  case Qt::Key_Backtab: return 0x0b; // VT
251  case Qt::Key_Enter:
252  case Qt::Key_Return: return 0x0d; // CR
253  case Qt::Key_Escape: return 0x1b; // ESC
254  case Qt::Key_Space: return 0x20; // 7 bit printable ASCII
255  case Qt::Key_Exclam: return 0x21;
256  case Qt::Key_QuoteDbl: return 0x22;
257  case Qt::Key_NumberSign: return 0x23;
258  case Qt::Key_Dollar: return 0x24;
259  case Qt::Key_Percent: return 0x25;
260  case Qt::Key_Ampersand: return 0x26;
261  case Qt::Key_Apostrophe: return 0x27;
262  case Qt::Key_ParenLeft: return 0x28;
263  case Qt::Key_ParenRight: return 0x29;
264  case Qt::Key_Asterisk: return 0x2a;
265  case Qt::Key_Plus: return 0x2b;
266  case Qt::Key_Comma: return 0x2c;
267  case Qt::Key_Minus: return 0x2d;
268  case Qt::Key_Period: return 0x2e;
269  case Qt::Key_Slash: return 0x2f;
270  case Qt::Key_0: return 0x30;
271  case Qt::Key_1: return 0x31;
272  case Qt::Key_2: return 0x32;
273  case Qt::Key_3: return 0x33;
274  case Qt::Key_4: return 0x34;
275  case Qt::Key_5: return 0x35;
276  case Qt::Key_6: return 0x36;
277  case Qt::Key_7: return 0x37;
278  case Qt::Key_8: return 0x38;
279  case Qt::Key_9: return 0x39;
280  case Qt::Key_Colon: return 0x3a;
281  case Qt::Key_Semicolon: return 0x3b;
282  case Qt::Key_Less: return 0x3c;
283  case Qt::Key_Equal: return 0x3d;
284  case Qt::Key_Greater: return 0x3e;
285  case Qt::Key_Question: return 0x3f;
286  case Qt::Key_At: return 0x40;
287  case Qt::Key_A: return 0x61; // 0x41 == 'A', 0x61 == 'a'
288  case Qt::Key_B: return 0x62;
289  case Qt::Key_C: return 0x63;
290  case Qt::Key_D: return 0x64;
291  case Qt::Key_E: return 0x65;
292  case Qt::Key_F: return 0x66;
293  case Qt::Key_G: return 0x67;
294  case Qt::Key_H: return 0x68;
295  case Qt::Key_I: return 0x69;
296  case Qt::Key_J: return 0x6a;
297  case Qt::Key_K: return 0x6b;
298  case Qt::Key_L: return 0x6c;
299  case Qt::Key_M: return 0x6d;
300  case Qt::Key_N: return 0x6e;
301  case Qt::Key_O: return 0x6f;
302  case Qt::Key_P: return 0x70;
303  case Qt::Key_Q: return 0x71;
304  case Qt::Key_R: return 0x72;
305  case Qt::Key_S: return 0x73;
306  case Qt::Key_T: return 0x74;
307  case Qt::Key_U: return 0x75;
308  case Qt::Key_V: return 0x76;
309  case Qt::Key_W: return 0x77;
310  case Qt::Key_X: return 0x78;
311  case Qt::Key_Y: return 0x79;
312  case Qt::Key_Z: return 0x7a;
313  case Qt::Key_BracketLeft: return 0x5b;
314  case Qt::Key_Backslash: return 0x5c;
315  case Qt::Key_BracketRight: return 0x5d;
316  case Qt::Key_AsciiCircum: return 0x5e;
317  case Qt::Key_Underscore: return 0x5f;
318  case Qt::Key_QuoteLeft: return 0x60;
319 
320  case Qt::Key_BraceLeft: return 0x7b;
321  case Qt::Key_Bar: return 0x7c;
322  case Qt::Key_BraceRight: return 0x7d;
323  case Qt::Key_AsciiTilde: return 0x7e;
324 
325  case Qt::Key_Delete: return 0;
326  case Qt::Key_Insert: return 0; // = 0x1006,
327  case Qt::Key_Pause: return 0; // = 0x1008,
328  case Qt::Key_Print: return 0; // = 0x1009,
329  case Qt::Key_SysReq: return 0; // = 0x100a,
330 
331  case Qt::Key_Clear: return 0; // = 0x100b,
332 
333  case Qt::Key_Home: return 0; // = 0x1010, // cursor movement
334  case Qt::Key_End: return 0; // = 0x1011,
335  case Qt::Key_Left: return 0; // = 0x1012,
336  case Qt::Key_Up: return 0; // = 0x1013,
337  case Qt::Key_Right: return 0; // = 0x1014,
338  case Qt::Key_Down: return 0; // = 0x1015,
339  case Qt::Key_PageUp: return 0; // = 0x1016,
340  case Qt::Key_PageDown: return 0; // = 0x1017,
341  case Qt::Key_Shift: return 0; // = 0x1020, // modifiers
342  case Qt::Key_Control: return 0; // = 0x1021,
343  case Qt::Key_Meta: return 0; // = 0x1022,
344  case Qt::Key_Alt: return 0; // = 0x1023,
345  case Qt::Key_CapsLock: return 0; // = 0x1024,
346  case Qt::Key_NumLock: return 0; // = 0x1025,
347  case Qt::Key_ScrollLock: return 0; // = 0x1026,
348  case Qt::Key_F1: return 0; // = 0x1030, // function keys
349  case Qt::Key_F2: return 0; // = 0x1031,
350  case Qt::Key_F3: return 0; // = 0x1032,
351  case Qt::Key_F4: return 0; // = 0x1033,
352  case Qt::Key_F5: return 0; // = 0x1034,
353  case Qt::Key_F6: return 0; // = 0x1035,
354  case Qt::Key_F7: return 0; // = 0x1036,
355  case Qt::Key_F8: return 0; // = 0x1037,
356  case Qt::Key_F9: return 0; // = 0x1038,
357  case Qt::Key_F10: return 0; // = 0x1039,
358  case Qt::Key_F11: return 0; // = 0x103a,
359  case Qt::Key_F12: return 0; // = 0x103b,
360  case Qt::Key_F13: return 0; // = 0x103c,
361  case Qt::Key_F14: return 0; // = 0x103d,
362  case Qt::Key_F15: return 0; // = 0x103e,
363  case Qt::Key_F16: return 0; // = 0x103f,
364  case Qt::Key_F17: return 0; // = 0x1040,
365  case Qt::Key_F18: return 0; // = 0x1041,
366  case Qt::Key_F19: return 0; // = 0x1042,
367  case Qt::Key_F20: return 0; // = 0x1043,
368  case Qt::Key_F21: return 0; // = 0x1044,
369  case Qt::Key_F22: return 0; // = 0x1045,
370  case Qt::Key_F23: return 0; // = 0x1046,
371  case Qt::Key_F24: return 0; // = 0x1047,
372  case Qt::Key_F25: return 0; // = 0x1048, // F25 .. F35 only on X11
373  case Qt::Key_F26: return 0; // = 0x1049,
374  case Qt::Key_F27: return 0; // = 0x104a,
375  case Qt::Key_F28: return 0; // = 0x104b,
376  case Qt::Key_F29: return 0; // = 0x104c,
377  case Qt::Key_F30: return 0; // = 0x104d,
378  case Qt::Key_F31: return 0; // = 0x104e,
379  case Qt::Key_F32: return 0; // = 0x104f,
380  case Qt::Key_F33: return 0; // = 0x1050,
381  case Qt::Key_F34: return 0; // = 0x1051,
382  case Qt::Key_F35: return 0; // = 0x1052,
383  case Qt::Key_Super_L: return 0; // = 0x1053, // extra keys
384  case Qt::Key_Super_R: return 0; // = 0x1054,
385  case Qt::Key_Menu: return 0; // = 0x1055,
386  case Qt::Key_Hyper_L: return 0; // = 0x1056,
387  case Qt::Key_Hyper_R: return 0; // = 0x1057,
388  case Qt::Key_Help: return 0; // = 0x1058,
389  case Qt::Key_Direction_L: return 0; // = 0x1059,
390  case Qt::Key_Direction_R: return 0; // = 0x1060,
391 
392  // Latin 1 codes adapted from X: keysymdef.h,v 1.21 94/08/28 16:17:06
393  case Qt::Key_nobreakspace: return char(0xa0);
394  case Qt::Key_exclamdown: return char(0xa1);
395  case Qt::Key_cent: return char(0xa2);
396  case Qt::Key_sterling: return char(0xa3);
397  case Qt::Key_currency: return char(0xa4);
398  case Qt::Key_yen: return char(0xa5);
399  case Qt::Key_brokenbar: return char(0xa6);
400  case Qt::Key_section: return char(0xa7);
401  case Qt::Key_diaeresis: return char(0xa8);
402  case Qt::Key_copyright: return char(0xa9);
403  case Qt::Key_ordfeminine: return char(0xaa);
404  case Qt::Key_guillemotleft: return char(0xab); // left angle quotation mar
405  case Qt::Key_notsign: return char(0xac);
406  case Qt::Key_hyphen: return char(0xad);
407  case Qt::Key_registered: return char(0xae);
408  case Qt::Key_macron: return char(0xaf);
409  case Qt::Key_degree: return char(0xb0);
410  case Qt::Key_plusminus: return char(0xb1);
411  case Qt::Key_twosuperior: return char(0xb2);
412  case Qt::Key_threesuperior: return char(0xb3);
413  case Qt::Key_acute: return char(0xb4);
414  case Qt::Key_mu: return char(0xb5);
415  case Qt::Key_paragraph: return char(0xb6);
416  case Qt::Key_periodcentered: return char(0xb7);
417  case Qt::Key_cedilla: return char(0xb8);
418  case Qt::Key_onesuperior: return char(0xb9);
419  case Qt::Key_masculine: return char(0xba);
420  case Qt::Key_guillemotright: return char(0xbb); // right angle quotation mar
421  case Qt::Key_onequarter: return char(0xbc);
422  case Qt::Key_onehalf: return char(0xbd);
423  case Qt::Key_threequarters: return char(0xbe);
424  case Qt::Key_questiondown: return char(0xbf);
425  case Qt::Key_Agrave: return char(0xc0);
426  case Qt::Key_Aacute: return char(0xc1);
427  case Qt::Key_Acircumflex: return char(0xc2);
428  case Qt::Key_Atilde: return char(0xc3);
429  case Qt::Key_Adiaeresis: return char(0xc4);
430  case Qt::Key_Aring: return char(0xe5);
431  case Qt::Key_AE: return char(0xe6);
432  case Qt::Key_Ccedilla: return char(0xc7);
433  case Qt::Key_Egrave: return char(0xc8);
434  case Qt::Key_Eacute: return char(0xc9);
435  case Qt::Key_Ecircumflex: return char(0xca);
436  case Qt::Key_Ediaeresis: return char(0xcb);
437  case Qt::Key_Igrave: return char(0xcc);
438  case Qt::Key_Iacute: return char(0xcd);
439  case Qt::Key_Icircumflex: return char(0xce);
440  case Qt::Key_Idiaeresis: return char(0xcf);
441  case Qt::Key_ETH: return char(0xd0);
442  case Qt::Key_Ntilde: return char(0xd1);
443  case Qt::Key_Ograve: return char(0xd2);
444  case Qt::Key_Oacute: return char(0xd3);
445  case Qt::Key_Ocircumflex: return char(0xd4);
446  case Qt::Key_Otilde: return char(0xd5);
447  case Qt::Key_Odiaeresis: return char(0xd6);
448  case Qt::Key_multiply: return char(0xd7);
449  case Qt::Key_Ooblique: return char(0xf8);
450  case Qt::Key_Ugrave: return char(0xd9);
451  case Qt::Key_Uacute: return char(0xda);
452  case Qt::Key_Ucircumflex: return char(0xdb);
453  case Qt::Key_Udiaeresis: return char(0xdc);
454  case Qt::Key_Yacute: return char(0xdd);
455  case Qt::Key_THORN: return char(0xde);
456  case Qt::Key_ssharp: return char(0xdf);
457  case Qt::Key_division: return char(0xf7);
458  case Qt::Key_ydiaeresis: return char(0xff);
459 
460  // multimedia/internet keys - ignored by default - see QKeyEvent c'tor
461 
462  case Qt::Key_Back : return 0; // = 0x1061,
463  case Qt::Key_Forward : return 0; // = 0x1062,
464  case Qt::Key_Stop : return 0; // = 0x1063,
465  case Qt::Key_Refresh : return 0; // = 0x1064,
466 
467  case Qt::Key_VolumeDown: return 0; // = 0x1070,
468  case Qt::Key_VolumeMute : return 0; // = 0x1071,
469  case Qt::Key_VolumeUp: return 0; // = 0x1072,
470  case Qt::Key_BassBoost: return 0; // = 0x1073,
471  case Qt::Key_BassUp: return 0; // = 0x1074,
472  case Qt::Key_BassDown: return 0; // = 0x1075,
473  case Qt::Key_TrebleUp: return 0; // = 0x1076,
474  case Qt::Key_TrebleDown: return 0; // = 0x1077,
475 
476  case Qt::Key_MediaPlay : return 0; // = 0x1080,
477  case Qt::Key_MediaStop : return 0; // = 0x1081,
478  case Qt::Key_MediaPrevious : return 0; // = 0x1082,
479  case Qt::Key_MediaNext : return 0; // = 0x1083,
480  case Qt::Key_MediaRecord: return 0; // = 0x1084,
481 
482  case Qt::Key_HomePage : return 0; // = 0x1090,
483  case Qt::Key_Favorites : return 0; // = 0x1091,
484  case Qt::Key_Search : return 0; // = 0x1092,
485  case Qt::Key_Standby: return 0; // = 0x1093,
486  case Qt::Key_OpenUrl: return 0; // = 0x1094,
487 
488  case Qt::Key_LaunchMail : return 0; // = 0x10a0,
489  case Qt::Key_LaunchMedia: return 0; // = 0x10a1,
490  case Qt::Key_Launch0 : return 0; // = 0x10a2,
491  case Qt::Key_Launch1 : return 0; // = 0x10a3,
492  case Qt::Key_Launch2 : return 0; // = 0x10a4,
493  case Qt::Key_Launch3 : return 0; // = 0x10a5,
494  case Qt::Key_Launch4 : return 0; // = 0x10a6,
495  case Qt::Key_Launch5 : return 0; // = 0x10a7,
496  case Qt::Key_Launch6 : return 0; // = 0x10a8,
497  case Qt::Key_Launch7 : return 0; // = 0x10a9,
498  case Qt::Key_Launch8 : return 0; // = 0x10aa,
499  case Qt::Key_Launch9 : return 0; // = 0x10ab,
500  case Qt::Key_LaunchA : return 0; // = 0x10ac,
501  case Qt::Key_LaunchB : return 0; // = 0x10ad,
502  case Qt::Key_LaunchC : return 0; // = 0x10ae,
503  case Qt::Key_LaunchD : return 0; // = 0x10af,
504  case Qt::Key_LaunchE : return 0; // = 0x10b0,
505  case Qt::Key_LaunchF : return 0; // = 0x10b1,
506 
507  default: QTEST_ASSERT(false); return 0;
508  }
509 }
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
int key

◆ memberName()

static QByteArray QTest::memberName ( const QMetaMethod member)
static

Definition at line 67 of file qsignaldumper.cpp.

Referenced by QDBusConnectionPrivate::activateCall(), qSignalDumperCallback(), and QDBusConnectionPrivate::relaySignal().

68 {
69  QByteArray ba = member.signature();
70  return ba.left(ba.indexOf('('));
71 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QByteArray left(int len) const
Returns a byte array that contains the leftmost len bytes of this byte array.
int indexOf(char c, int from=0) const
Returns the index position of the first occurrence of the character ch in the byte array...
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).

◆ messageFormatString()

static const char* QTest::messageFormatString ( bool  noDescription,
bool  noTag 
)
static

Definition at line 194 of file qxmltestlogger.cpp.

Referenced by QXmlTestLogger::addMessage().

195 {
196  if (noDescription) {
197  if (noTag)
198  return "<Message type=\"%s\" file=\"%s\" line=\"%d\" />\n";
199  else
200  return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
201  " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
202  "</Message>\n";
203  } else {
204  if (noTag)
205  return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
206  " <Description><![CDATA[%s%s%s%s]]></Description>\n"
207  "</Message>\n";
208  else
209  return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
210  " <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
211  " <Description><![CDATA[%s]]></Description>\n"
212  "</Message>\n";
213  }
214 }

◆ messageHandler()

static void QTest::messageHandler ( QtMsgType  type,
const char *  msg 
)
static

Definition at line 121 of file qtestlog.cpp.

Referenced by QScriptDebuggerConsoleCommandJob::QScriptDebuggerConsoleCommandJob(), and QTestLog::startLogging().

122  {
124 
125  if (!msg || !QTest::testLogger) {
126  // if this goes wrong, something is seriously broken.
128  QTEST_ASSERT(msg);
130  }
131 
132  if (handleIgnoredMessage(type, msg))
133  // the message is expected, so just swallow it.
134  return;
135 
136  if (type != QtFatalMsg) {
137  if (counter <= 0)
138  return;
139 
140  if (!counter.deref()) {
142  "Maximum amount of warnings exceeded. Use -maxwarnings to override.");
143  return;
144  }
145  }
146 
147  switch (type) {
148  case QtDebugMsg:
150  break;
151  case QtCriticalMsg:
153  break;
154  case QtWarningMsg:
156  break;
157  case QtFatalMsg:
159  /* Right now, we're inside the custom message handler and we're
160  * being qt_message_output in qglobal.cpp. After we return from
161  * this function, it will proceed with calling exit() and abort()
162  * and hence crash. Therefore, we call these logging functions such
163  * that we wrap up nicely, and in particular produce well-formed XML. */
164  QTestResult::addFailure("Received a fatal error.", "Unknown file", 0);
167  break;
168  }
169  }
int type
Definition: qmetatype.cpp:239
static void addFailure(const char *message, const char *file, int line)
#define Q_BASIC_ATOMIC_INITIALIZER(a)
Definition: qbasicatomic.h:218
static QAbstractTestLogger * testLogger
Definition: qtestlog.cpp:92
static bool handleIgnoredMessage(QtMsgType type, const char *msg)
Definition: qtestlog.cpp:97
static void stopLogging()
Definition: qtestlog.cpp:322
static QtMsgHandler oldMessageHandler
Definition: qtestlog.cpp:95
static int maxWarnings
Definition: qtestlog.cpp:90
QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
Definition: qglobal.cpp:2698
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
virtual void addMessage(MessageTypes type, const char *message, const char *file=0, int line=0)=0
static void leaveTestFunction()
Definition: qtestlog.cpp:228

◆ messageType2String()

static const char* QTest::messageType2String ( QAbstractTestLogger::MessageTypes  type)
static

Definition at line 131 of file qplaintestlogger.cpp.

Referenced by QPlainTestLogger::addMessage(), and QPlainTestLogger::enterTestFunction().

132  {
133 #ifdef Q_OS_WIN
134  static bool colored = (!qgetenv("QTEST_COLORED").isEmpty());
135 #else
136  static bool colored = ::getenv("QTEST_COLORED");
137 #endif
138  switch (type) {
140  return COLORED_MSG(0, 37, "SKIP "); //white
142  return COLORED_MSG(0, 33, "WARNING"); // yellow
144  return COLORED_MSG(1, 33, "QWARN ");
146  return COLORED_MSG(1, 33, "QDEBUG ");
148  return COLORED_MSG(1, 33, "QSYSTEM");
150  return COLORED_MSG(0, 31, "QFATAL "); // red
152  return "INFO "; // no coloring
153  }
154  return "??????";
155  }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
int type
Definition: qmetatype.cpp:239
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
#define COLORED_MSG(prefix, color, msg)

◆ mouseClick()

void QTest::mouseClick ( QWidget widget,
Qt::MouseButton  button,
Qt::KeyboardModifiers  modifier = 0,
QPoint  pos = QPoint(),
int  delay = -1 
)
inline

Simulates clicking a mouse button with an optional modifier on a widget.

The position of the click is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button.

See also
QTest::mousePress(), QTest::mouseRelease()

Definition at line 135 of file qtestmouse.h.

137  { mouseEvent(MouseClick, widget, button, stateKey, pos, delay); }
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71

◆ mouseDClick()

void QTest::mouseDClick ( QWidget widget,
Qt::MouseButton  button,
Qt::KeyboardModifiers  modifier = 0,
QPoint  pos = QPoint(),
int  delay = -1 
)
inline

Simulates double clicking a mouse button with an optional modifier on a widget.

The position of the click is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before each press and release.

See also
QTest::mouseClick()

Definition at line 138 of file qtestmouse.h.

140  { mouseEvent(MouseDClick, widget, button, stateKey, pos, delay); }
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71

◆ mouseEvent()

void QTest::mouseEvent ( MouseAction  action,
QWidget widget,
Qt::MouseButton  button,
Qt::KeyboardModifiers  stateKey,
QPoint  pos,
int  delay = -1 
)
static
Warning
This function is not part of the public interface.

Definition at line 71 of file qtestmouse.h.

Referenced by QStatusBar::event(), QGraphicsScene::event(), QWidget::event(), QMdiSubWindow::eventFilter(), mouseClick(), mouseDClick(), QGraphicsView::mouseDoubleClickEvent(), mouseMove(), QGraphicsViewPrivate::mouseMoveEventHandler(), mousePress(), QGraphicsView::mousePressEvent(), mouseRelease(), QGraphicsView::mouseReleaseEvent(), QGraphicsItemPrivate::remapItemPos(), QDeclarativePathView::sendMouseEvent(), QDeclarativeMouseArea::sendMouseEvent(), QDeclarativeFlickable::sendMouseEvent(), QDeclarativePinchArea::sendMouseEvent(), QDeclarativeTextInputPrivate::sendMouseEventToInputContext(), QGraphicsProxyWidgetPrivate::sendWidgetMouseEvent(), and QTestEvent::~QTestEvent().

73  {
74  QTEST_ASSERT(widget);
76 
77  if (delay == -1 || delay < defaultMouseDelay())
78  delay = defaultMouseDelay();
79  if(delay > 0)
80  QTest::qWait(delay);
81 
82  if (pos.isNull())
83  pos = widget->rect().center();
84 
85  if (action == MouseClick) {
86  mouseEvent(MousePress, widget, button, stateKey, pos);
87  mouseEvent(MouseRelease, widget, button, stateKey, pos);
88  return;
89  }
90 
91  QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask);
92  QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
93 
94  stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
95 
96  QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
97  switch (action)
98  {
99  case MousePress:
100  me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
101  break;
102  case MouseRelease:
103  me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, stateKey);
104  break;
105  case MouseDClick:
106  me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
107  break;
108  case MouseMove:
109  QCursor::setPos(widget->mapToGlobal(pos));
110 #ifdef QT_MAC_USE_COCOA
111  QTest::qWait(20);
112 #else
113  qApp->processEvents();
114 #endif
115  return;
116  default:
117  QTEST_ASSERT(false);
118  }
120  if (!qApp->notify(widget, &me)) {
121  static const char *mouseActionNames[] =
122  { "MousePress", "MouseRelease", "MouseClick", "MouseDClick", "MouseMove" };
123  QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
124  QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toAscii().data());
125  }
126 
127  }
#define Q_TESTLIB_EXPORT
Definition: qtest_global.h:56
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void setPos(int x, int y)
Moves the cursor (hot spot) to the global screen position (x, y).
Definition: qcursor_mac.mm:315
#define qApp
bool isNull() const
Returns true if both the x and y coordinates are set to 0, otherwise returns false.
Definition: qpoint.h:125
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
static void qWait(int ms)
Waits for ms milliseconds.
Definition: qtestsystem.h:62
Q_TESTLIB_EXPORT void qWarn(const char *message)
Definition: qtestcase.cpp:2102
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71
int Q_TESTLIB_EXPORT defaultMouseDelay()
Definition: qtestcase.cpp:1008
QPoint mapToGlobal(const QPoint &) const
Translates the widget coordinate pos to global screen coordinates.

◆ mouseMove()

void QTest::mouseMove ( QWidget widget,
QPoint  pos = QPoint(),
int  delay = -1 
)
inline

Moves the mouse pointer to a widget.

If pos is not specified, the mouse pointer moves to the center of the widget. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.

Definition at line 141 of file qtestmouse.h.

142  { mouseEvent(MouseMove, widget, Qt::NoButton, 0, pos, delay); }
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71

◆ mousePress()

void QTest::mousePress ( QWidget widget,
Qt::MouseButton  button,
Qt::KeyboardModifiers  modifier = 0,
QPoint  pos = QPoint(),
int  delay = -1 
)
inline

Simulates pressing a mouse button with an optional modifier on a widget.

The position is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before the press.

See also
QTest::mouseRelease(), QTest::mouseClick()

Definition at line 129 of file qtestmouse.h.

131  { mouseEvent(MousePress, widget, button, stateKey, pos, delay); }
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71

◆ mouseRelease()

void QTest::mouseRelease ( QWidget widget,
Qt::MouseButton  button,
Qt::KeyboardModifiers  modifier = 0,
QPoint  pos = QPoint(),
int  delay = -1 
)
inline

Simulates releasing a mouse button with an optional modifier on a widget.

The position of the release is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before releasing the button.

See also
QTest::mousePress(), QTest::mouseClick()

Definition at line 132 of file qtestmouse.h.

134  { mouseEvent(MouseRelease, widget, button, stateKey, pos, delay); }
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
Definition: qtestmouse.h:71

◆ newRow()

QTestData & QTest::newRow ( const char *  dataTag)

Appends a new row to the current test data.

dataTag is the name of the testdata that will appear in the test output. Returns a QTestData reference that can be used to stream in data.

Example:

void myTestFunction_data()
{
QTest::addColumn<QString>("aString");
QTest::newRow("just hello") << QString("hello");
QTest::newRow("a null string") << QString();
}

Note: This macro can only be used in a test's data function that is invoked by the test framework.

See Chapter 2: Data Driven Testing a more extensive example.

See also
addColumn(), QFETCH()

Definition at line 2183 of file qtestcase.cpp.

Referenced by addColumn(), QListModel::ensureSorted(), QTreeModel::ensureSorted(), QTableModel::ensureSorted(), QTextControlPrivate::gotoNextTableCell(), QTextControlPrivate::gotoPreviousTableCell(), QAbstractItemView::keyboardSearch(), QTableView::moveCursor(), and QTableModel::updateRowIndexes().

2184 {
2186  QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot.");
2187 
2188  return *tbl->newData(dataTag);
2189 }
QTestData * newData(const char *tag)
Definition: qtesttable.cpp:193
static QTestTable * currentTestTable()
Definition: qtesttable.cpp:261
#define QTEST_ASSERT_X(cond, where, what)
Definition: qtestassert.h:55

◆ outputMessage()

static void QTest::outputMessage ( const char *  str)
static

Definition at line 157 of file qplaintestlogger.cpp.

Referenced by printBenchmarkResult(), printMessage(), QPlainTestLogger::startLogging(), and QPlainTestLogger::stopLogging().

158  {
159 #if defined(Q_OS_WINCE)
160  QString strUtf16 = QString::fromLatin1(str);
161  const int maxOutputLength = 255;
162  do {
163  QString tmp = strUtf16.left(maxOutputLength);
164  OutputDebugString((wchar_t*)tmp.utf16());
165  strUtf16.remove(0, maxOutputLength);
166  } while (!strUtf16.isEmpty());
168 #elif defined(Q_OS_WIN)
169  EnterCriticalSection(&outputCriticalSection);
170  // OutputDebugString is not threadsafe
171  OutputDebugStringA(str);
172  LeaveCriticalSection(&outputCriticalSection);
173 #elif defined(Q_OS_SYMBIAN)
174  // RDebug::Print has a cap of 256 characters so break it up
175  TPtrC8 ptr(reinterpret_cast<const TUint8*>(str));
176  _LIT(format, "[QTestLib] %S");
177  const int maxBlockSize = 256 - ((const TDesC &)format).Length();
178  HBufC* hbuffer = HBufC::New(maxBlockSize);
179  if(hbuffer) {
180  for (int i = 0; i < ptr.Length(); i += maxBlockSize) {
181  int size = Min(maxBlockSize, ptr.Length() - i);
182  hbuffer->Des().Copy(ptr.Mid(i, size));
183  RDebug::Print(format, hbuffer);
184  }
185  delete hbuffer;
186  }
187  else {
188  // fast, no allocations, but truncates silently
189  RDebug::RawPrint(format);
190  TPtrC8 ptr(reinterpret_cast<const TUint8*>(str));
191  RDebug::RawPrint(ptr);
192  RDebug::RawPrint(_L8("\n"));
193  }
194 #endif
196  }
static void outputString(const char *msg)
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char * outputFileName()
Definition: qtestlog.cpp:389
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T * ptr(const T &t)
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define Q_OS_WIN
Definition: qglobal.h:270
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ printBenchmarkResult()

static void QTest::printBenchmarkResult ( const QBenchmarkResult result)
static

Definition at line 318 of file qplaintestlogger.cpp.

Referenced by QPlainTestLogger::addBenchmarkResult().

319  {
320  const char *bmtag = QTest::benchmarkResult2String();
321 
322  char buf1[1024];
324  buf1, sizeof(buf1), "%s: %s::%s",
325  bmtag,
327  result.context.slotName.toAscii().data());
328 
329  char bufTag[1024];
330  bufTag[0] = 0;
331  QByteArray tag = result.context.tag.toAscii();
332  if (tag.isEmpty() == false) {
333  QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data());
334  }
335 
336 
337  char fillFormat[8];
338  int fillLength = 5;
340  fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength);
341  char fill[1024];
342  QTest::qt_snprintf(fill, sizeof(fill), fillFormat, "");
343 
344  const char * unitText = QTest::benchmarkMetricUnit(result.metric);
345 
346  qreal valuePerIteration = qreal(result.value) / qreal(result.iterations);
347  char resultBuffer[100] = "";
348  formatResult(resultBuffer, 100, valuePerIteration, countSignificantDigits(result.value));
349 
350  char buf2[1024];
352  buf2, sizeof(buf2), "%s %s",
353  resultBuffer,
354  unitText);
355 
356  char buf2_[1024];
357  QByteArray iterationText = " per iteration";
358  Q_ASSERT(result.iterations > 0);
360  buf2_,
361  sizeof(buf2_), "%s",
362  iterationText.data());
363 
364  char buf3[1024];
365  Q_ASSERT(result.iterations > 0);
366  formatResult(resultBuffer, 100, result.value, countSignificantDigits(result.value));
368  buf3, sizeof(buf3), " (total: %s, iterations: %d)",
369  resultBuffer,
370  result.iterations);
371 
372  char buf[1024];
373 
374  if (result.setByMacro) {
376  buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3);
377  } else {
378  QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2);
379  }
380 
381  memcpy(buf, bmtag, strlen(bmtag));
382  outputMessage(buf);
383  }
QTest::QBenchmarkMetric metric
Definition: qbenchmark_p.h:100
static int countSignificantDigits(T num)
double qreal
Definition: qglobal.h:1193
const char * benchmarkMetricUnit(QBenchmarkMetric metric)
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static const char * benchmarkResult2String()
static const char * currentTestObjectName()
static void outputMessage(const char *str)
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
QByteArray toAscii() const Q_REQUIRED_RESULT
Returns an 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4014
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
int formatResult(char *buffer, int bufferSize, T number, int significantDigits)
QBenchmarkContext context
Definition: qbenchmark_p.h:97

◆ printMessage()

static void QTest::printMessage ( const char *  type,
const char *  msg,
const char *  file = 0,
int  line = 0 
)
static

Definition at line 198 of file qplaintestlogger.cpp.

Referenced by QPlainTestLogger::addIncident(), QPlainTestLogger::addMessage(), and QPlainTestLogger::enterTestFunction().

199  {
201  QTEST_ASSERT(msg);
202 
203  QTestCharBuffer buf;
204 
206  : "UnknownTestFunc";
207  const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : "";
208  const char *gtag = QTestResult::currentGlobalDataTag()
210  : "";
211  const char *filler = (tag[0] && gtag[0]) ? ":" : "";
212  if (file) {
213  QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n"
214 #ifdef Q_OS_WIN
215  "%s(%d) : failure location\n"
216 #else
217  " Loc: [%s(%d)]\n"
218 #endif
219  , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
220  msg[0] ? " " : "", msg, file, line);
221  } else {
222  QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n",
223  type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
224  msg[0] ? " " : "", msg);
225  }
226  // In colored mode, printf above stripped our nonprintable control characters.
227  // Put them back.
228  memcpy(buf.data(), type, strlen(type));
229  outputMessage(buf.data());
230  }
static const char * currentTestFunction()
int type
Definition: qmetatype.cpp:239
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
static const char * currentTestObjectName()
static void outputMessage(const char *str)
static const char * currentGlobalDataTag()
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
static const char * currentDataTag()
#define Q_OS_WIN
Definition: qglobal.h:270

◆ qCompare() [1/16]

template<>
bool QTest::qCompare ( QIcon const &  t1,
QIcon const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 78 of file qtest_gui.h.

80 {
81  QTEST_ASSERT(sizeof(QIcon) == sizeof(void *));
82  return qCompare<void *>(*reinterpret_cast<void * const *>(&t1),
83  *reinterpret_cast<void * const *>(&t2), actual, expected, file, line);
84 }
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60

◆ qCompare() [2/16]

template<>
bool QTest::qCompare ( QPixmap const &  t1,
QPixmap const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 87 of file qtest_gui.h.

89 {
90  return qCompare(t1.toImage(), t2.toImage(), actual, expected, file, line);
91 }
bool qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtest_gui.h:87

◆ qCompare() [3/16]

template<typename T >
bool QTest::qCompare ( T const &  t1,
T const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 175 of file qtestcase.h.

177  {
178  return (t1 == t2)
179  ? compare_helper(true, "COMPARE()", file, line)
180  : compare_helper(false, "Compared values are not the same",
181  toString<T>(t1), toString<T>(t2), actual, expected, file, line);
182  }
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, char *val1, char *val2, const char *expected, const char *actual, const char *file, int line)
Definition: qtestcase.cpp:2297
static QString toString(Register *reg, int type, bool *ok=0)

◆ qCompare() [4/16]

template<>
bool QTest::qCompare ( QString const &  t1,
QLatin1String const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 177 of file qtest.h.

Referenced by compare_ptr_helper(), qCompare(), qCompare< char >(), and qTest().

179 {
180  return qCompare<QString>(t1, QString(t2), actual, expected, file, line);
181 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ qCompare() [5/16]

template<>
bool QTest::qCompare ( QLatin1String const &  t1,
QString const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 185 of file qtest.h.

187 {
188  return qCompare<QString>(QString(t1), t2, actual, expected, file, line);
189 }
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ qCompare() [6/16]

template<>
bool QTest::qCompare ( QStringList const &  t1,
QStringList const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 192 of file qtest.h.

194 {
195  char msg[1024];
196  msg[0] = '\0';
197  bool isOk = true;
198  if (t1.count() != t2.count()) {
199  qt_snprintf(msg, 1024, "Compared QStringLists have different sizes.\n"
200  " Actual (%s) size : '%d'\n"
201  " Expected (%s) size: '%d'", actual, t1.count(), expected, t2.count());
202  isOk = false;
203  }
204  const int min = qMin(t1.count(), t2.count());
205  for (int i = 0; isOk && i < min; ++i) {
206  if (t1.at(i) != t2.at(i)) {
207  qt_snprintf(msg, 1024, "Compared QStringLists differ at index %d.\n"
208  " Actual (%s) : '%s'\n"
209  " Expected (%s) : '%s'", i, actual, t1.at(i).toLatin1().constData(),
210  expected, t2.at(i).toLatin1().constData());
211  isOk = false;
212  }
213  }
214  return compare_helper(isOk, msg, file, line);
215 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, const char *file, int line)
Definition: qtestcase.cpp:2290

◆ qCompare() [7/16]

template<typename T >
bool QTest::qCompare ( QFlags< T > const &  t1,
T const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 218 of file qtest.h.

220 {
221  return qCompare(int(t1), int(t2), actual, expected, file, line);
222 }
bool qCompare(QFlags< T > const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtest.h:225

◆ qCompare() [8/16]

template<typename T1 , typename T2 >
bool QTest::qCompare ( T1 const &  ,
T2 const &  ,
const char *  ,
const char *  ,
const char *  ,
int   
)
Warning
This function is not part of the public interface.

◆ qCompare() [9/16]

template<typename T >
bool QTest::qCompare ( QFlags< T > const &  t1,
int const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 225 of file qtest.h.

227 {
228  return qCompare(int(t1), t2, actual, expected, file, line);
229 }
bool qCompare(QFlags< T > const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtest.h:225

◆ qCompare() [10/16]

template<typename T >
bool QTest::qCompare ( const T *  t1,
const T *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 258 of file qtestcase.h.

260  {
261  return compare_ptr_helper(t1, t2, actual, expected, file, line);
262  }
bool compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.h:193

◆ qCompare() [11/16]

template<typename T >
bool QTest::qCompare ( T *  t1,
T *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 264 of file qtestcase.h.

266  {
267  return compare_ptr_helper(t1, t2, actual, expected, file, line);
268  }
bool compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.h:193

◆ qCompare() [12/16]

template<typename T1 , typename T2 >
bool QTest::qCompare ( const T1 *  t1,
const T2 *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 271 of file qtestcase.h.

273  {
274  return compare_ptr_helper(t1, static_cast<const T1 *>(t2), actual, expected, file, line);
275  }
bool compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.h:193

◆ qCompare() [13/16]

template<typename T1 , typename T2 >
bool QTest::qCompare ( T1 *  t1,
T2 *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 277 of file qtestcase.h.

279  {
280  return compare_ptr_helper(const_cast<const T1 *>(t1),
281  static_cast<const T1 *>(const_cast<const T2 *>(t2)), actual, expected, file, line);
282  }
bool compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.h:193

◆ qCompare() [14/16]

template<>
bool QTest::qCompare ( char *  t1,
const char *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 337 of file qtestcase.h.

339  {
340  return compare_string_helper(t1, t2, actual, expected, file, line);
341  }
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2376

◆ qCompare() [15/16]

template<>
bool QTest::qCompare ( const char *  t1,
char *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 345 of file qtestcase.h.

347  {
348  return compare_string_helper(t1, t2, actual, expected, file, line);
349  }
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2376

◆ qCompare() [16/16]

template<>
bool QTest::qCompare ( bool const &  t1,
int const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 355 of file qtestcase.h.

357  {
358  return qCompare<int>(int(t1), t2, actual, expected, file, line);
359  }

◆ qCompare< char >() [1/2]

template<>
bool QTest::qCompare< char > ( const char *  t1,
const char *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline

Definition at line 284 of file qtestcase.h.

286  {
287  return compare_string_helper(t1, t2, actual, expected, file, line);
288  }
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2376

◆ qCompare< char >() [2/2]

template<>
bool QTest::qCompare< char > ( char *  t1,
char *  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
inline

Definition at line 290 of file qtestcase.h.

292  {
293  return compare_string_helper(t1, t2, actual, expected, file, line);
294  }
Q_TESTLIB_EXPORT bool compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.cpp:2376

◆ qCompare< double >()

template<>
Q_TESTLIB_EXPORT bool QTest::qCompare< double > ( double const &  t1,
double const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2320 of file qtestcase.cpp.

Referenced by qCompare().

2322 {
2323  return qFuzzyCompare(t1, t2)
2324  ? compare_helper(true, "COMPARE()", file, line)
2325  : compare_helper(false, "Compared doubles are not the same (fuzzy compare)",
2326  toString(t1), toString(t2), actual, expected, file, line);
2327 }
static QString toString(Register *reg, int type, bool *ok=0)
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, const char *file, int line)
Definition: qtestcase.cpp:2290
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172

◆ qCompare< float >()

template<>
Q_TESTLIB_EXPORT bool QTest::qCompare< float > ( float const &  t1,
float const &  t2,
const char *  actual,
const char *  expected,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2307 of file qtestcase.cpp.

Referenced by compare_ptr_helper(), qCompare(), and qCompare< char >().

2309 {
2310  return qFuzzyCompare(t1, t2)
2311  ? compare_helper(true, "COMPARE()", file, line)
2312  : compare_helper(false, "Compared floats are not the same (fuzzy compare)",
2313  toString(t1), toString(t2), actual, expected, file, line);
2314 }
static QString toString(Register *reg, int type, bool *ok=0)
Q_TESTLIB_EXPORT bool compare_helper(bool success, const char *msg, const char *file, int line)
Definition: qtestcase.cpp:2290
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172

◆ qData()

void * QTest::qData ( const char *  tagName,
int  typeId 
)
Warning
This function is not part of the public interface.

Definition at line 2130 of file qtestcase.cpp.

Referenced by toString().

2131 {
2132  return fetchData(QTestResult::currentTestData(), tagName, typeId);
2133 }
static QTestData * currentTestData()
void * fetchData(QTestData *data, const char *tagName, int typeId)
Definition: qtestcase.cpp:1635

◆ qElementData()

void * QTest::qElementData ( const char *  tagName,
int  metaTypeId 
)
Warning
This function is not part of the public interface.

Definition at line 2144 of file qtestcase.cpp.

Referenced by qTest(), and toString().

2145 {
2146  QTEST_ASSERT(tagName);
2148  QTEST_ASSERT(data);
2149  QTEST_ASSERT(data->parent());
2150 
2151  int idx = data->parent()->indexOf(tagName);
2152  QTEST_ASSERT(idx != -1);
2153  QTEST_ASSERT(data->parent()->elementTypeId(idx) == metaTypeId);
2154 
2155  return data->data(data->parent()->indexOf(tagName));
2156 }
QTestTable * parent() const
Definition: qtestdata.cpp:107
static QTestData * currentTestData()
static const char * data(const QByteArray &arr)
int elementTypeId(int index) const
Definition: qtesttable.cpp:212
void * data(int index) const
Definition: qtestdata.cpp:100
int indexOf(const char *elementName) const
Definition: qtesttable.cpp:233
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53

◆ qExec() [1/2]

int QTest::qExec ( QObject testObject,
int  argc = 0,
char **  argv = 0 
)

Executes tests declared in testObject.

In addition, the private slots initTestCase(), cleanupTestCase(), init() and cleanup() are executed if they exist. See Creating a Test for more details.

Optionally, the command line arguments argc and argv can be provided. For a list of recognized arguments, read QTestLib Command Line Arguments.

For stand-alone tests, the convenience macro QTEST_MAIN() can be used to declare a main method that parses the command line arguments and executes the tests.

Returns 0 if all tests passed. Returns a value other than 0 if tests failed or in case of unhandled exceptions. The return value from this function is also the exit code of the test application when the QTEST_MAIN() macro is used.

The following example will run all tests in MyFirstTestObject and MySecondTestObject:

MyFirstTestObject test1;
QTest::qExec(&test1);
MySecondTestObject test2;
QTest::qExec(&test2);

Note: This function is not reentrant, only one test can run at a time. A test that was executed with qExec() can't run another test via qExec() and threads are not allowed to call qExec() simultaneously.

If you have programatically created the arguments, as opposed to getting them from the arguments in main(), it is likely of interest to use QTest::qExec(QObject *, const QStringList &) since it is Unicode safe.

See also
QTEST_MAIN()

Definition at line 1913 of file qtestcase.cpp.

Referenced by qExec(), and toString().

1914 {
1915  QBenchmarkGlobalData benchmarkData;
1916  QBenchmarkGlobalData::current = &benchmarkData;
1917 
1918 #ifdef QTESTLIB_USE_VALGRIND
1919  int callgrindChildExitCode = 0;
1920 #endif
1921 
1922 #ifdef Q_WS_MAC
1923  bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0);
1924 #ifdef QT_MAC_USE_COCOA
1925  IOPMAssertionID powerID;
1926 #endif
1927 #endif
1928 #ifndef QT_NO_EXCEPTIONS
1929  try {
1930 #endif
1931 
1932  #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
1933  SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX);
1934  #endif
1935 
1936 #ifdef Q_WS_MAC
1937  // Starting with Qt 4.4, applications launched from the command line
1938  // no longer get focus automatically. Since some tests might depend
1939  // on this, call SetFrontProcess here to get the pre 4.4 behavior.
1940  if (macNeedsActivate) {
1941  ProcessSerialNumber psn = { 0, kCurrentProcess };
1942  SetFrontProcess(&psn);
1943 # ifdef QT_MAC_USE_COCOA
1944  IOReturn ok = IOPMAssertionCreate(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, &powerID);
1945  if (ok != kIOReturnSuccess)
1946  macNeedsActivate = false; // no need to release the assertion on exit.
1947 # else
1948  UpdateSystemActivity(1); // Wake the display.
1949 # endif
1950  }
1951 #endif
1952 
1953 #if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
1954  // Delay execution of tests in Symbian emulator.
1955  // Needed to allow worst of other higher priority apps and services launched by emulator
1956  // to get out of the way before we run our test. Otherwise some of the timing sensitive tests
1957  // will not work properly.
1958  qSleep(3000);
1959 #endif
1960 
1962 
1963  QTEST_ASSERT(testObject);
1966 
1967  const QMetaObject *metaObject = testObject->metaObject();
1968  QTEST_ASSERT(metaObject);
1969 
1971  if (argc > 0)
1973 
1974  qtest_qParseArgs(argc, argv, false);
1975  if (QTest::randomOrder) {
1976  seedRandom();
1977  }
1978 #ifdef QTESTLIB_USE_VALGRIND
1980  const QStringList origAppArgs(QCoreApplication::arguments());
1981  if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode))
1982  return -1;
1983 
1985 
1986  } else
1987 #endif
1988  {
1989 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1991  if (!noCrashHandler)
1992  handler.reset(new FatalSignalHandler);
1993 #endif
1994  qInvokeTestMethods(testObject);
1995  }
1996 
1997 #ifndef QT_NO_EXCEPTIONS
1998  } catch (...) {
1999  QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__);
2003  }
2004 
2006 #ifdef QT_MAC_USE_COCOA
2007  if (macNeedsActivate) {
2008  IOPMAssertionRelease(powerID);
2009  }
2010 #endif
2011  currentTestObject = 0;
2012 
2013  // Rethrow exception to make debugging easier.
2014  throw;
2015  return 1;
2016  }
2017 # endif
2018 
2019  currentTestObject = 0;
2020 #ifdef QT_MAC_USE_COCOA
2021  if (macNeedsActivate) {
2022  IOPMAssertionRelease(powerID);
2023  }
2024 #endif
2025 
2026 #if defined(QTEST_NOEXITCODE)
2027  return 0;
2028 #else
2029 
2030 #ifdef QTESTLIB_USE_VALGRIND
2032  return callgrindChildExitCode;
2033 #endif
2034  // make sure our exit code is never going above 127
2035  // since that could wrap and indicate 0 test fails
2036  return qMin(QTestResult::failCount(), 127);
2037 
2038 #endif
2039 }
static bool rerunThroughCallgrind(const QStringList &origAppArgs, int &exitCode)
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static const char * currentTestFunction()
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_TESTLIB_EXPORT QObject * testObject()
Definition: qtestcase.cpp:2283
static int failCount()
static QObject * currentTestObject
Definition: qtestcase.cpp:903
static bool randomOrder
Definition: qtestcase.cpp:941
static void setCurrentTestFunction(const char *func)
static void addFailure(const char *message, const char *file, int line)
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
static void finishedCurrentTestFunction()
#define qApp
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static bool noCrashHandler
Definition: qtestcase.cpp:946
static void reset()
Definition: qtestresult.cpp:75
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
#define SetErrorMode(a)
void seedRandom()
Definition: qtestcase.cpp:1030
static void stopLogging()
Definition: qtestlog.cpp:322
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
static void setCurrentAppName(const char *appName)
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static void qInvokeTestMethods(QObject *testObject)
Definition: qtestcase.cpp:1724
static QStringList arguments()
Returns the list of command-line arguments.
QImageIOHandler * handler
static void setCurrentTestObject(const char *name)
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
Definition: qtestcase.cpp:1170
Q_TESTLIB_EXPORT void qSleep(int ms)
Sleeps for ms milliseconds, blocking execution of the test.
Definition: qtestcase.cpp:2269

◆ qExec() [2/2]

int QTest::qExec ( QObject testObject,
const QStringList arguments 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.4

Behaves identically to qExec(QObject *, int, char**) but takes a QStringList of arguments instead of a char** list.

Definition at line 2048 of file qtestcase.cpp.

2049 {
2050  const int argc = arguments.count();
2051  QVarLengthArray<char *> argv(argc);
2052 
2053  QVector<QByteArray> args;
2054  args.reserve(argc);
2055 
2056  for(int i = 0; i < argc; ++i)
2057  {
2058  args.append(arguments.at(i).toLocal8Bit().constData());
2059  argv[i] = args.last().data();
2060  }
2061 
2062  return qExec(testObject, argc, argv.data());
2063 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
Q_TESTLIB_EXPORT int qExec(QObject *testObject, int argc=0, char **argv=0)
Executes tests declared in testObject.
Definition: qtestcase.cpp:1913
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
T & last()
Returns a reference to the last item in the vector.
Definition: qvector.h:262
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339

◆ qExpectFail()

bool QTest::qExpectFail ( const char *  dataIndex,
const char *  comment,
QTest::TestFailMode  mode,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2094 of file qtestcase.cpp.

Referenced by toString().

2096 {
2097  return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line);
2098 }
static bool expectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line)
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114

◆ qFail()

void QTest::qFail ( const char *  statementStr,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2067 of file qtestcase.cpp.

Referenced by toString().

2068 {
2069  QTestResult::addFailure(statementStr, file, line);
2070 }
static void addFailure(const char *message, const char *file, int line)

◆ qGlobalData()

void * QTest::qGlobalData ( const char *  tagName,
int  typeId 
)
Warning
This function is not part of the public interface.

Definition at line 2137 of file qtestcase.cpp.

Referenced by toString().

2138 {
2139  return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId);
2140 }
static QTestData * currentGlobalTestData()
void * fetchData(QTestData *data, const char *tagName, int typeId)
Definition: qtestcase.cpp:1635

◆ qInvokeTestMethod()

static bool QTest::qInvokeTestMethod ( const char *  slotName,
const char *  data = 0 
)
static

Call init(), slot_data(), slot(), slot(), slot().

Warning
This function is not part of the public interface.

.., cleanup() If data is set then it is the only test that is performed

If the function was successfully called, true is returned, otherwise false.

Definition at line 1540 of file qtestcase.cpp.

Referenced by qInvokeTestMethods().

1541 {
1542  QTEST_ASSERT(slotName);
1543 
1544  QBenchmarkTestMethodData benchmarkData;
1545  QBenchmarkTestMethodData::current = &benchmarkData;
1546 
1548 
1549  char member[512];
1550  QTestTable table;
1551 
1552  char *slot = qstrdup(slotName);
1553  slot[strlen(slot) - 2] = '\0';
1555 
1556  const QTestTable *gTable = QTestTable::globalTestTable();
1557  const int globalDataCount = gTable->dataCount();
1558  int curGlobalDataIndex = 0;
1559 
1560  /* For each test function that has a *_data() table/function, do: */
1561  do {
1562  if (!gTable->isEmpty())
1563  QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex));
1564 
1565  if (curGlobalDataIndex == 0) {
1567  QTest::qt_snprintf(member, 512, "%s_data()", slot);
1569 
1570  // if we encounter a SkipAll in the _data slot, we skip the whole
1571  // testfunction, no matter how much global data exists
1574  break;
1575  }
1576  }
1577 
1578  bool foundFunction = false;
1580  int curDataIndex = 0;
1581  const int dataCount = table.dataCount();
1583 
1584  // Data tag requested but none available?
1585  if (data && !dataCount) {
1586  // Let empty data tag through.
1587  if (!*data)
1588  data = 0;
1589  else {
1590  printf("Unknown testdata for function %s: '%s'\n", slotName, data);
1591  printf("Function has no testdata.\n");
1592  return false;
1593  }
1594  }
1595 
1596  /* For each entry in the data table, do: */
1597  do {
1598  if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
1599  foundFunction = true;
1600  QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
1601  : table.testData(curDataIndex));
1602 
1604 
1606  // check whether SkipAll was requested
1607  break;
1608  if (data)
1609  break;
1610  }
1611  ++curDataIndex;
1612  } while (curDataIndex < dataCount);
1613  }
1614 
1615  if (data && !foundFunction) {
1616  printf("Unknown testdata for function %s: '%s'\n", slotName, data);
1617  printf("Available testdata:\n");
1618  for(int i = 0; i < table.dataCount(); ++i)
1619  printf("%s\n", table.testData(i)->dataTag());
1620  return false;
1621  }
1622 
1624  ++curGlobalDataIndex;
1625  } while (curGlobalDataIndex < globalDataCount);
1626 
1630  delete[] slot;
1631 
1632  return true;
1633 }
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
QTestData * testData(int index) const
Definition: qtesttable.cpp:228
static void invokeMethod(QObject *obj, const char *methodName)
Definition: qtestcase.cpp:979
static void setCurrentTestLocation(TestLocation loc)
static QObject * currentTestObject
Definition: qtestcase.cpp:903
const char * dataTag() const
Definition: qtestdata.cpp:112
static void setCurrentTestFunction(const char *func)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void qInvokeTestMethodDataEntry(char *slot)
Definition: qtestcase.cpp:1463
int qstrcmp(const char *str1, const char *str2)
A safe strcmp() function.
Definition: qbytearray.cpp:231
static void finishedCurrentTestFunction()
int dataCount() const
Definition: qtesttable.cpp:177
static const char * data(const QByteArray &arr)
static QTestTable * globalTestTable()
Definition: qtesttable.cpp:248
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
static void setCurrentGlobalTestData(QTestData *data)
static void setCurrentTestData(QTestData *data)
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
static void setSkipCurrentTest(bool value)
static bool skipCurrentTest()
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167
QBenchmarkContext context
Definition: qbenchmark_p.h:147
bool isEmpty() const
Definition: qtesttable.cpp:188

◆ qInvokeTestMethodDataEntry()

static void QTest::qInvokeTestMethodDataEntry ( char *  slot)
static

Definition at line 1463 of file qtestcase.cpp.

Referenced by qInvokeTestMethod().

1464 {
1465  /* Benchmarking: for each median iteration*/
1466 
1468 
1469  QList<QBenchmarkResult> results;
1470  do {
1472 
1473  /* Benchmarking: for each accumulation iteration*/
1474  bool invokeOk;
1475  do {
1479  break;
1480 
1482 
1485 
1487  QLatin1String(
1489  ? QTestResult::currentDataTag() : "");
1490 
1493  if (!invokeOk)
1494  QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__);
1495 
1497  invokeMethod(QTest::currentTestObject, "cleanup()");
1499 
1500  // If this test method has a benchmark, repeat until all measurements are
1501  // acceptable.
1502  // The QBENCHMARK macro increases the number of iterations for each run until
1503  // this happens.
1504  } while (invokeOk
1505  && QBenchmarkTestMethodData::current->isBenchmark()
1506  && QBenchmarkTestMethodData::current->resultsAccepted() == false);
1507 
1509  if (i > -1) // iteration -1 is the warmup iteration.
1510  results.append(QBenchmarkTestMethodData::current->result);
1511 
1512  if (QBenchmarkTestMethodData::current->isBenchmark() &&
1513  QBenchmarkGlobalData::current->verboseOutput) {
1514  if (i == -1) {
1515  qDebug() << "warmup stage result :" << QBenchmarkTestMethodData::current->result.value;
1516  } else {
1517  qDebug() << "accumulation stage result:" << QBenchmarkTestMethodData::current->result.value;
1518  }
1519  }
1520  } while (QBenchmarkTestMethodData::current->isBenchmark()
1521  && (++i < QBenchmarkGlobalData::current->adjustMedianIterationCount()));
1522 
1523  if (QBenchmarkTestMethodData::current->isBenchmark()
1524  && QBenchmarkTestMethodData::current->resultsAccepted())
1526 }
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
static void addBenchmarkResult(const QBenchmarkResult &result)
Definition: qtestlog.cpp:299
QBenchmarkResult result
Definition: qbenchmark_p.h:181
static void invokeMethod(QObject *obj, const char *methodName)
Definition: qtestcase.cpp:979
static void setCurrentTestLocation(TestLocation loc)
static QObject * currentTestObject
Definition: qtestcase.cpp:903
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static void addFailure(const char *message, const char *file, int line)
QBenchmarkMeasurerBase * measurer
Definition: qbenchmark_p.h:146
Q_CORE_EXPORT void qDebug(const char *,...)
QBenchmarkResult qMedian(const QList< QBenchmarkResult > &container)
Definition: qtestcase.cpp:1433
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static const char * currentDataTag()
static bool skipCurrentTest()
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167
QBenchmarkContext context
Definition: qbenchmark_p.h:147
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ qInvokeTestMethods()

static void QTest::qInvokeTestMethods ( QObject testObject)
static

Definition at line 1724 of file qtestcase.cpp.

Referenced by qExec().

1725 {
1726  const QMetaObject *metaObject = testObject->metaObject();
1727  QTEST_ASSERT(metaObject);
1728  if (QTest::randomOrder) {
1730  } else {
1732  }
1733  QTestResult::setCurrentTestFunction("initTestCase");
1736  invokeMethod(testObject, "initTestCase_data()");
1737 
1740  invokeMethod(testObject, "initTestCase()");
1741 
1742  // finishedCurrentTestFunction() resets QTestResult::testFailed(), so use a local copy.
1743  const bool previousFailed = QTestResult::testFailed();
1745 
1746  if(!QTestResult::skipCurrentTest() && !previousFailed) {
1747 
1748  if (QTest::testFuncs) {
1749  if (QTest::randomOrder)
1751  for (int i = 0; i != QTest::testFuncCount; i++) {
1752  if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i].function()).signature(),
1753  QTest::testFuncs[i].data())) {
1754  break;
1755  }
1756  }
1758  } else {
1759  int methodCount = metaObject->methodCount();
1760  QMetaMethod *testMethods = new QMetaMethod[methodCount];
1761  for (int i = 0; i != methodCount; i++)
1762  testMethods[i] = metaObject->method(i);
1763  if (QTest::randomOrder)
1764  randomizeList(testMethods, methodCount);
1765  for (int i = 0; i != methodCount; i++) {
1766  if (!isValidSlot(testMethods[i]))
1767  continue;
1768  if (!qInvokeTestMethod(testMethods[i].signature()))
1769  break;
1770  }
1771  delete[] testMethods;
1772  testMethods = 0;
1773  }
1774  }
1775 
1777  QTestResult::setCurrentTestFunction("cleanupTestCase");
1778  invokeMethod(testObject, "cleanupTestCase()");
1779  }
1783 
1785 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static TestFunction * testFuncs
Definition: qtestcase.cpp:922
static bool testFailed()
static void invokeMethod(QObject *obj, const char *methodName)
Definition: qtestcase.cpp:979
static void setCurrentTestLocation(TestLocation loc)
static bool randomOrder
Definition: qtestcase.cpp:941
static bool isValidSlot(const QMetaMethod &sl)
Definition: qtestcase.cpp:1067
static void clearGlobalTestTable()
Definition: qtesttable.cpp:255
static void setCurrentTestFunction(const char *func)
char * data() const
Definition: qtestcase.cpp:909
static struct QTest::TestFuncCleanup testFuncCleaner
static int testFuncCount
Definition: qtestcase.cpp:923
static void finishedCurrentTestFunction()
int function() const
Definition: qtestcase.cpp:910
static QTestTable * globalTestTable()
Definition: qtesttable.cpp:248
static void startLogging()
Definition: qtestlog.cpp:314
static void stopLogging()
Definition: qtestlog.cpp:322
static bool qInvokeTestMethod(const char *slotName, const char *data=0)
Call init(), slot_data(), slot(), slot(), slot().
Definition: qtestcase.cpp:1540
static unsigned int seed
Definition: qtestcase.cpp:943
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
static void setSkipCurrentTest(bool value)
static bool skipCurrentTest()
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
Q_TESTLIB_EXPORT bool currentTestFailed()
Returns true if the current test function failed, otherwise false.
Definition: qtestcase.cpp:2247
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
static void randomizeList(T *array, int size)
Definition: qtestcase.cpp:1059

◆ qMedian()

QBenchmarkResult QTest::qMedian ( const QList< QBenchmarkResult > &  container)

Definition at line 1433 of file qtestcase.cpp.

Referenced by qInvokeTestMethodDataEntry().

1434 {
1435  const int count = container.count();
1436  if (count == 0)
1437  return QBenchmarkResult();
1438 
1439  if (count == 1)
1440  return container.at(0);
1441 
1442  QList<QBenchmarkResult> containerCopy = container;
1443  qSort(containerCopy);
1444 
1445  const int middle = count / 2;
1446 
1447  // ### handle even-sized containers here by doing an aritmetic mean of the two middle items.
1448  return containerCopy.at(middle);
1449 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ qPrintDataTags()

static void QTest::qPrintDataTags ( )
static

Definition at line 1100 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

1101 {
1102  // Get global data tags:
1104  invokeMethod(QTest::currentTestObject, "initTestCase_data()");
1105  const QTestTable *gTable = QTestTable::globalTestTable();
1106 
1107  const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject();
1108 
1109  // Process test functions:
1110  for (int i = 0; i < currTestMetaObj->methodCount(); ++i) {
1111  QMetaMethod tf = currTestMetaObj->method(i);
1112  if (isValidSlot(tf)) {
1113  // Retrieve local tags:
1114  QStringList localTags;
1115  QTestTable table;
1116  char member[512];
1117  char *slot = qstrdup(tf.signature());
1118  slot[strlen(slot) - 2] = '\0';
1119  QTest::qt_snprintf(member, 512, "%s_data()", slot);
1121  for (int j = 0; j < table.dataCount(); ++j)
1122  localTags << QLatin1String(table.testData(j)->dataTag());
1123 
1124  // Print all tag combinations:
1125  if (gTable->dataCount() == 0) {
1126  if (localTags.count() == 0) {
1127  // No tags at all, so just print the test function:
1128  printf("%s %s\n", currTestMetaObj->className(), slot);
1129  } else {
1130  // Only local tags, so print each of them:
1131  for (int k = 0; k < localTags.size(); ++k)
1132  printf(
1133  "%s %s %s\n",
1134  currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());
1135  }
1136  } else {
1137  for (int j = 0; j < gTable->dataCount(); ++j) {
1138  if (localTags.count() == 0) {
1139  // Only global tags, so print the current one:
1140  printf(
1141  "%s %s __global__ %s\n",
1142  currTestMetaObj->className(), slot, gTable->testData(j)->dataTag());
1143  } else {
1144  // Local and global tags, so print each of the local ones and
1145  // the current global one:
1146  for (int k = 0; k < localTags.size(); ++k)
1147  printf(
1148  "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot,
1149  localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());
1150  }
1151  }
1152  }
1153 
1154  delete[] slot;
1155  }
1156  }
1157 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QTestData * testData(int index) const
Definition: qtesttable.cpp:228
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
static void invokeMethod(QObject *obj, const char *methodName)
Definition: qtestcase.cpp:979
static QObject * currentTestObject
Definition: qtestcase.cpp:903
const char * dataTag() const
Definition: qtestdata.cpp:112
static bool isValidSlot(const QMetaMethod &sl)
Definition: qtestcase.cpp:1067
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int dataCount() const
Definition: qtesttable.cpp:177
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static QTestTable * globalTestTable()
Definition: qtesttable.cpp:248
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ qPrintMessage()

static void QTest::qPrintMessage ( const QByteArray ba)
inlinestatic

Definition at line 57 of file qsignaldumper.cpp.

Referenced by qSignalDumperCallback(), and qSignalDumperCallbackSlot().

58 {
59  QTestLog::info(ba.constData(), 0, 0);
60 }
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static void info(const char *msg, const char *file, int line)
Definition: qtestlog.cpp:340

◆ qPrintTestSlots()

static void QTest::qPrintTestSlots ( )
static

Definition at line 1091 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

1092 {
1093  for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
1095  if (isValidSlot(sl))
1096  printf("%s\n", sl.signature());
1097  }
1098 }
static QObject * currentTestObject
Definition: qtestcase.cpp:903
static bool isValidSlot(const QMetaMethod &sl)
Definition: qtestcase.cpp:1067
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
int methodCount() const
Returns the number of methods known to the meta-object system in this class, including the number of ...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ qSignalDumperCallback()

static void QTest::qSignalDumperCallback ( QObject caller,
int  method_index,
void **  argv 
)
static

Definition at line 73 of file qsignaldumper.cpp.

Referenced by QSignalDumper::startDump().

74 {
75  Q_ASSERT(caller); Q_ASSERT(argv); Q_UNUSED(argv);
76  const QMetaObject *mo = caller->metaObject();
77  Q_ASSERT(mo);
78  QMetaMethod member = mo->method(method_index);
79  Q_ASSERT(member.signature());
80 
81  if (QTest::ignoreClasses() && QTest::ignoreClasses()->contains(mo->className())) {
83  return;
84  }
85 
86  QByteArray str;
88  str += "Signal: ";
89  str += mo->className();
90  str += '(';
91 
92  QString objname = caller->objectName();
93  str += objname.toLocal8Bit();
94  if (!objname.isEmpty())
95  str += ' ';
96  str += QByteArray::number(quintptr(caller), 16);
97 
98  str += ") ";
99  str += QTest::memberName(member);
100  str += " (";
101 
102  QList<QByteArray> args = member.parameterTypes();
103  for (int i = 0; i < args.count(); ++i) {
104  const QByteArray &arg = args.at(i);
105  int typeId = QMetaType::type(args.at(i).constData());
106  if (arg.endsWith('*') || arg.endsWith('&')) {
107  str += '(';
108  str += arg;
109  str += ')';
110  if (arg.endsWith('&'))
111  str += '@';
112 
113  quintptr addr = quintptr(*reinterpret_cast<void **>(argv[i + 1]));
114  str.append(QByteArray::number(addr, 16));
115  } else if (typeId != QMetaType::Void) {
116  str.append(arg)
117  .append('(')
118  .append(QVariant(typeId, argv[i + 1]).toString().toLocal8Bit())
119  .append(')');
120  }
121  str.append(", ");
122  }
123  if (str.endsWith(", "))
124  str.chop(2);
125  str.append(')');
126  qPrintMessage(str);
127 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
void chop(int n)
Removes n bytes from the end of the byte array.
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
QByteArray & fill(char c, int size=-1)
Sets every byte in the byte array to character ch.
QByteArray & append(char c)
Appends the character ch to this byte array.
QString objectName
the name of this object
Definition: qobject.h:114
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static void qPrintMessage(const QByteArray &ba)
static int iLevel
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QString toString(Register *reg, int type, bool *ok=0)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static int ignoreLevel
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QList< QByteArray > parameterTypes() const
Returns a list of parameter types.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
static QByteArray memberName(const QMetaMethod &member)
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
bool endsWith(const QByteArray &a) const
Returns true if this byte array ends with byte array ba; otherwise returns false. ...

◆ qSignalDumperCallbackEndSignal()

static void QTest::qSignalDumperCallbackEndSignal ( QObject caller,
int   
)
static

Definition at line 159 of file qsignaldumper.cpp.

Referenced by QSignalDumper::startDump().

160 {
161  Q_ASSERT(caller); Q_ASSERT(caller->metaObject());
162  if (QTest::ignoreClasses()
163  && QTest::ignoreClasses()->contains(caller->metaObject()->className())) {
166  return;
167  }
168  --QTest::iLevel;
169  Q_ASSERT(QTest::iLevel >= 0);
170 }
static int iLevel
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static int ignoreLevel
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ qSignalDumperCallbackSlot()

static void QTest::qSignalDumperCallbackSlot ( QObject caller,
int  method_index,
void **  argv 
)
static

Definition at line 129 of file qsignaldumper.cpp.

Referenced by QSignalDumper::startDump().

130 {
131  Q_ASSERT(caller); Q_ASSERT(argv); Q_UNUSED(argv);
132  const QMetaObject *mo = caller->metaObject();
133  Q_ASSERT(mo);
134  QMetaMethod member = mo->method(method_index);
135  if (!member.signature())
136  return;
137 
138  if (QTest::ignoreLevel ||
139  (QTest::ignoreClasses() && QTest::ignoreClasses()->contains(mo->className())))
140  return;
141 
142  QByteArray str;
144  str += "Slot: ";
145  str += mo->className();
146  str += '(';
147 
148  QString objname = caller->objectName();
149  str += objname.toLocal8Bit();
150  if (!objname.isEmpty())
151  str += ' ';
152  str += QByteArray::number(quintptr(caller), 16);
153 
154  str += ") ";
155  str += member.signature();
156  qPrintMessage(str);
157 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
QByteArray & fill(char c, int size=-1)
Sets every byte in the byte array to character ch.
QString objectName
the name of this object
Definition: qobject.h:114
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static void qPrintMessage(const QByteArray &ba)
static int iLevel
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static int ignoreLevel
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
const char * signature() const
Returns the signature of this method (e.g., setValue(double)).
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ qSkip()

void QTest::qSkip ( const char *  message,
QTest::SkipMode  mode,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2083 of file qtestcase.cpp.

Referenced by toString().

2085 {
2086  QTestResult::addSkip(message, mode, file, line);
2087  if (mode == QTest::SkipAll)
2089 }
static void addSkip(const char *message, QTest::SkipMode mode, const char *file, int line)
static void setSkipCurrentTest(bool value)

◆ qSleep()

void QTest::qSleep ( int  ms)

Sleeps for ms milliseconds, blocking execution of the test.

qSleep() will not do any event processing and leave your test unresponsive. Network communication might time out while sleeping. Use qWait() to do non-blocking sleeping.

ms must be greater than 0.

Note: The qSleep() function calls either nanosleep() on unix or Sleep() on windows, so the accuracy of time spent in qSleep() depends on the operating system.

Example:

See also
qWait()

Definition at line 2269 of file qtestcase.cpp.

Referenced by qExec(), qWait(), and toString().

2270 {
2271  QTEST_ASSERT(ms > 0);
2272 
2273 #ifdef Q_OS_WIN
2274  Sleep(uint(ms));
2275 #else
2276  struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
2277  nanosleep(&ts, NULL);
2278 #endif
2279 }
unsigned int uint
Definition: qglobal.h:996
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53

◆ qt_asprintf()

int QTest::qt_asprintf ( QTestCharBuffer str,
const char *  format,
  ... 
)
Warning
This function is not part of the public interface.

Definition at line 129 of file qabstracttestlogger.cpp.

Referenced by QXmlTestLogger::addBenchmarkResult(), QXmlTestLogger::addIncident(), QXmlTestLogger::addMessage(), QTestLogger::addTag(), QXmlTestLogger::enterTestFunction(), QTestXunitStreamer::formatAfterAttributes(), QTestXunitStreamer::formatAttributes(), QTestLightXmlStreamer::formatBeforeAttributes(), QTestXunitStreamer::formatEnd(), QTestXmlStreamer::formatEnd(), QTestLightXmlStreamer::formatEnd(), QTestXunitStreamer::formatStart(), QTestXmlStreamer::formatStart(), QTestLightXmlStreamer::formatStart(), QTestLightXmlStreamer::output(), QTestXmlStreamer::output(), printMessage(), and QXmlTestLogger::startLogging().

130 {
131  static const int MAXSIZE = 1024*1024*2;
132 
133  Q_ASSERT(str);
134 
135  int size = str->size();
136 
137  va_list ap;
138  int res = 0;
139 
140  for (;;) {
141  va_start(ap, format);
142  res = qvsnprintf(str->data(), size, format, ap);
143  va_end(ap);
144  str->data()[size - 1] = '\0';
145  if (res >= 0 && res < size) {
146  // We succeeded
147  break;
148  }
149  // buffer wasn't big enough, try again.
150  // Note, we're assuming that a result of -1 is always due to running out of space.
151  size *= 2;
152  if (size > MAXSIZE) {
153  break;
154  }
155  if (!str->reset(size))
156  break; // out of memory - take what we have
157  }
158 
159  filter_unprintable(str->data());
160 
161  return res;
162 }
void filter_unprintable(char *str)
Definition: qtestcase.cpp:949
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
A portable vsnprintf() function.
Definition: qvsnprintf.cpp:78

◆ qt_snprintf()

int QTest::qt_snprintf ( char *  str,
int  size,
const char *  format,
  ... 
)
Warning
This function is not part of the public interface.

Definition at line 961 of file qtestcase.cpp.

Referenced by QTestLogger::addBenchmarkResult(), QTestLogger::addIncident(), QTestLogger::addMessage(), QTestResult::compare(), QTestLogger::enterTestFunction(), QTestFileLogger::init(), printBenchmarkResult(), QTestLog::printUnhandledIgnoreMessages(), qCompare(), qInvokeTestMethod(), qPrintDataTags(), qtest_qParseArgs(), QPlainTestLogger::startLogging(), QPlainTestLogger::stopLogging(), QTestLogger::stopLogging(), toString(), and QTestResult::verify().

962 {
963  va_list ap;
964  int res = 0;
965 
966  va_start(ap, format);
967  qvsnprintf(str, size, format, ap);
968  va_end(ap);
969  str[size - 1] = '\0';
970 
971  filter_unprintable(str);
972 
973  return res;
974 }
void filter_unprintable(char *str)
Definition: qtestcase.cpp:949
int qvsnprintf(char *str, size_t n, const char *fmt, va_list ap)
A portable vsnprintf() function.
Definition: qvsnprintf.cpp:78

◆ qTest()

template<class T >
bool QTest::qTest ( const T &  actual,
const char *  elementName,
const char *  actualStr,
const char *  expected,
const char *  file,
int  line 
)
inline
Warning
This function is not part of the public interface.

Definition at line 363 of file qtestcase.h.

365  {
366  return qCompare(actual, *static_cast<const T *>(QTest::qElementData(elementName,
367  qMetaTypeId<T>())), actualStr, expected, file, line);
368  }
Q_TESTLIB_EXPORT void * qElementData(const char *elementName, int metaTypeId)
Definition: qtestcase.cpp:2144
bool qCompare(bool const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line)
Definition: qtestcase.h:355

◆ qtest_qParseArgs()

Q_TESTLIB_EXPORT void QTest::qtest_qParseArgs ( int  argc,
char *  argv[],
bool  qml 
)

Definition at line 1170 of file qtestcase.cpp.

Referenced by qExec().

1171 {
1172  const char *testOptions =
1173  " options:\n"
1174  " -functions : Returns a list of current testfunctions\n"
1175  " -datatags : Returns a list of current data tags.\n"
1176  " A global data tag is preceded by ' __global__ '.\n"
1177  " -xunitxml : Outputs results as XML XUnit document\n"
1178  " -xml : Outputs results as XML document\n"
1179  " -lightxml : Outputs results as stream of XML tags\n"
1180  " -flush : Flushes the results\n"
1181  " -o filename: Writes all output into a file\n"
1182  " -silent : Only outputs warnings and failures\n"
1183  " -v1 : Print enter messages for each testfunction\n"
1184  " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n"
1185  " -vs : Print every signal emitted\n"
1186  " -random : Run testcases within each test in random order\n"
1187  " -seed n : Positive integer to be used as seed for -random. If not specified,\n"
1188  " the current time will be used as seed.\n"
1189  " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n"
1190  " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n"
1191  " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n"
1192  " -keyevent-verbose : Turn on verbose messages for keyboard simulation\n"
1193  " -maxwarnings n : Sets the maximum amount of messages to output.\n"
1194  " 0 means unlimited, default: 2000\n"
1195 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1196  " -nocrashhandler : Disables the crash handler\n"
1197 #endif
1198  "\n"
1199  " Benchmark related options:\n"
1200 #ifdef QTESTLIB_USE_VALGRIND
1201  " -callgrind : Use callgrind to time benchmarks\n"
1202 #endif
1203 #ifdef HAVE_TICK_COUNTER
1204  " -tickcounter : Use CPU tick counters to time benchmarks\n"
1205 #endif
1206  " -eventcounter : Counts events received during benchmarks\n"
1207  " -minimumvalue n : Sets the minimum acceptable measurement value\n"
1208  " -iterations n : Sets the number of accumulation iterations.\n"
1209  " -median n : Sets the number of median iterations.\n"
1210  " -vb : Print out verbose benchmarking information.\n"
1211  "\n"
1212  " -help : This help\n";
1213 
1214  for (int i = 1; i < argc; ++i) {
1215  if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0
1216  || strcmp(argv[i], "/?") == 0) {
1217  printf(" Usage: %s [options] [testfunction[:testdata]]...\n"
1218  " By default, all testfunctions will be run.\n\n"
1219  "%s", argv[0], testOptions);
1220  exit(0);
1221  } else if (strcmp(argv[i], "-functions") == 0) {
1222  if (qml) {
1224  } else {
1225  qPrintTestSlots();
1226  exit(0);
1227  }
1228  } else if (strcmp(argv[i], "-datatags") == 0) {
1230  if (!qml) {
1231  qPrintDataTags();
1232  exit(0);
1233  }
1234  } else if(strcmp(argv[i], "-xunitxml") == 0){
1236  } else if (strcmp(argv[i], "-xml") == 0) {
1238  } else if (strcmp(argv[i], "-lightxml") == 0) {
1240  }else if(strcmp(argv[i], "-flush") == 0){
1242  } else if (strcmp(argv[i], "-silent") == 0) {
1244  } else if (strcmp(argv[i], "-v1") == 0) {
1246  } else if (strcmp(argv[i], "-v2") == 0) {
1248  } else if (strcmp(argv[i], "-vs") == 0) {
1250  } else if (strcmp(argv[i], "-o") == 0) {
1251  if (i + 1 >= argc) {
1252  printf("-o needs an extra parameter specifying the filename\n");
1253  exit(1);
1254  } else {
1255  QTestLog::redirectOutput(argv[++i]);
1256  }
1257  } else if (strcmp(argv[i], "-eventdelay") == 0) {
1258  if (i + 1 >= argc) {
1259  printf("-eventdelay needs an extra parameter to indicate the delay(ms)\n");
1260  exit(1);
1261  } else {
1262  QTest::eventDelay = qToInt(argv[++i]);
1263  }
1264  } else if (strcmp(argv[i], "-keydelay") == 0) {
1265  if (i + 1 >= argc) {
1266  printf("-keydelay needs an extra parameter to indicate the delay(ms)\n");
1267  exit(1);
1268  } else {
1269  QTest::keyDelay = qToInt(argv[++i]);
1270  }
1271  } else if (strcmp(argv[i], "-mousedelay") == 0) {
1272  if (i + 1 >= argc) {
1273  printf("-mousedelay needs an extra parameter to indicate the delay(ms)\n");
1274  exit(1);
1275  } else {
1276  QTest::mouseDelay = qToInt(argv[++i]);
1277  }
1278  } else if (strcmp(argv[i], "-maxwarnings") == 0) {
1279  if (i + 1 >= argc) {
1280  printf("-maxwarnings needs an extra parameter with the amount of warnings\n");
1281  exit(1);
1282  } else {
1283  QTestLog::setMaxWarnings(qToInt(argv[++i]));
1284  }
1285 #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
1286  } else if (strcmp(argv[i], "-nocrashhandler") == 0) {
1287  QTest::noCrashHandler = true;
1288 #endif
1289  } else if (strcmp(argv[i], "-keyevent-verbose") == 0) {
1290  QTest::keyVerbose = 1;
1291 #ifdef QTESTLIB_USE_VALGRIND
1292  } else if (strcmp(argv[i], "-callgrind") == 0) {
1294  if (QFileInfo(QDir::currentPath()).isWritable()) {
1296  } else {
1297  printf("WARNING: Current directory not writable. Using the walltime measurer.\n");
1298  }
1299  else {
1300  printf("WARNING: Valgrind not found or too old. Make sure it is installed and in your path. "
1301  "Using the walltime measurer.\n");
1302  }
1303  } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option
1307 #endif
1308 #ifdef HAVE_TICK_COUNTER
1309  } else if (strcmp(argv[i], "-tickcounter") == 0) {
1311 #endif
1312  } else if (strcmp(argv[i], "-eventcounter") == 0) {
1314  } else if (strcmp(argv[i], "-random") == 0) {
1315  QTest::randomOrder = true;
1316  } else if (strcmp(argv[i], "-seed") == 0) {
1317  bool argumentOk = false;
1318  if (i + 1 < argc) {
1319  char * endpt = 0;
1320  long longSeed = strtol(argv[++i], &endpt, 10);
1321  argumentOk = (*endpt == '\0' && longSeed >= 0);
1322  QTest::seed = longSeed;
1323  }
1324  if (!argumentOk) {
1325  printf("-seed needs an extra positive integer parameter to specify the seed\n");
1326  exit(1);
1327  } else {
1328  QTest::seedSet = true;
1329  }
1330  } else if (strcmp(argv[i], "-minimumvalue") == 0) {
1331  if (i + 1 >= argc) {
1332  printf("-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n");
1333  exit(1);
1334  } else {
1336  }
1337  } else if (strcmp(argv[i], "-iterations") == 0) {
1338  if (i + 1 >= argc) {
1339  printf("-iterations needs an extra parameter to indicate the number of iterations\n");
1340  exit(1);
1341  } else {
1343  }
1344  } else if (strcmp(argv[i], "-median") == 0) {
1345  if (i + 1 >= argc) {
1346  printf("-median needs an extra parameter to indicate the number of median iterations\n");
1347  exit(1);
1348  } else {
1350  }
1351 
1352  } else if (strcmp(argv[i], "-vb") == 0) {
1354  } else if (strcmp(argv[i], "-chart") == 0) {
1355  fprintf(stderr, "Warning: `-chart' option is not available\n");
1356  } else if (strcmp(argv[i], "-qws") == 0) {
1357  // do nothing
1358  } else if (strcmp(argv[i], "-graphicssystem") == 0) {
1359  // do nothing
1360  if (i + 1 >= argc) {
1361  printf("-graphicssystem needs an extra parameter specifying the graphics system\n");
1362  exit(1);
1363  } else {
1364  ++i;
1365  }
1366  } else if (argv[i][0] == '-') {
1367  printf("Unknown option: '%s'\n\n%s", argv[i], testOptions);
1368  exit(1);
1369  } else if (qml) {
1370  // We can't check the availability of test functions until
1371  // we load the QML files. So just store the data for now.
1372  int colon = -1;
1373  int offset;
1374  for(offset = 0; *(argv[i]+offset); ++offset) {
1375  if (*(argv[i]+offset) == ':') {
1376  if (*(argv[i]+offset+1) == ':') {
1377  // "::" is used as a test name separator.
1378  // e.g. "ClickTests::test_click:row1".
1379  ++offset;
1380  } else {
1381  colon = offset;
1382  break;
1383  }
1384  }
1385  }
1386  if (colon == -1) {
1388  QTest::testTags += QString();
1389  } else {
1391  QString::fromLatin1(argv[i], colon);
1392  QTest::testTags +=
1393  QString::fromLatin1(argv[i] + colon + 1);
1394  }
1395  } else {
1396  if (!QTest::testFuncs) {
1398  }
1399 
1400  int colon = -1;
1401  char buf[512], *data=0;
1402  int off;
1403  for(off = 0; *(argv[i]+off); ++off) {
1404  if (*(argv[i]+off) == ':') {
1405  colon = off;
1406  break;
1407  }
1408  }
1409  if(colon != -1) {
1410  data = qstrdup(argv[i]+colon+1);
1411  }
1412  QTest::qt_snprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf
1413  QTest::qt_snprintf(buf + off, qMin(512 - off, 3), "()"); // append "()"
1415  if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) {
1416  printf("Unknown testfunction: '%s'\n", buf);
1417  printf("Available testfunctions:\n");
1418  qPrintTestSlots();
1419  exit(1);
1420  }
1421  testFuncs[testFuncCount].set(idx, data);
1422  testFuncCount++;
1424  }
1425  }
1426 
1428  printf("-seed requires -random\n");
1429  exit(1);
1430  }
1431 }
static void setMaxWarnings(int max)
Definition: qtestlog.cpp:394
static QString outFileBase(qint64 pid=-1)
static QBenchmarkGlobalData * current
Definition: qbenchmark_p.h:136
static int keyVerbose
Definition: qtestcase.cpp:942
static TestFunction * testFuncs
Definition: qtestcase.cpp:922
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
static int eventDelay
Definition: qtestcase.cpp:940
static QObject * currentTestObject
Definition: qtestcase.cpp:903
static bool randomOrder
Definition: qtestcase.cpp:941
static void startDump()
static bool isValidSlot(const QMetaMethod &sl)
Definition: qtestcase.cpp:1067
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
static void redirectOutput(const char *fileName)
Definition: qtestlog.cpp:382
static void qPrintTestSlots()
Definition: qtestcase.cpp:1091
static int keyDelay
Definition: qtestcase.cpp:938
static bool seedSet
Definition: qtestcase.cpp:944
static int testFuncCount
Definition: qtestcase.cpp:923
QString callgrindOutFileBase
Definition: qbenchmark_p.h:153
static void qPrintDataTags()
Definition: qtestcase.cpp:1100
void set(int function, char *data)
Definition: qtestcase.cpp:908
static const char * data(const QByteArray &arr)
static bool noCrashHandler
Definition: qtestcase.cpp:946
static void setFlushMode(FlushMode mode)
Definition: qtestlog.cpp:399
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961
void setMode(Mode mode)
Definition: qbenchmark.cpp:77
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
Q_TESTLIB_EXPORT bool printAvailableTags
Definition: qtestcase.cpp:1087
static unsigned int seed
Definition: qtestcase.cpp:943
int indexOfMethod(const char *method) const
Finds method and returns its index; otherwise returns -1.
static int qToInt(char *str)
Definition: qtestcase.cpp:1159
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
Q_TESTLIB_EXPORT bool printAvailableFunctions
Definition: qtestcase.cpp:1086
Q_TESTLIB_EXPORT QStringList testTags
Definition: qtestcase.cpp:1089
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
static void setVerboseLevel(int level)
Definition: qtestlog.cpp:358
Q_TESTLIB_EXPORT QStringList testFunctions
Definition: qtestcase.cpp:1088
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
static int mouseDelay
Definition: qtestcase.cpp:939
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
static void setLogMode(LogMode mode)
Definition: qtestlog.cpp:348

◆ qTestRandomSeed()

int QTest::qTestRandomSeed ( )

Definition at line 1044 of file qtestcase.cpp.

1045 {
1047  return QTest::seed;
1048 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static bool seedSet
Definition: qtestcase.cpp:944
static unsigned int seed
Definition: qtestcase.cpp:943

◆ qToInt()

static int QTest::qToInt ( char *  str)
static

Definition at line 1159 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

1160 {
1161  char *pEnd;
1162  int l = (int)strtol(str, &pEnd, 10);
1163  if (*pEnd != 0) {
1164  printf("Invalid numeric parameter: '%s'\n", str);
1165  exit(1);
1166  }
1167  return l;
1168 }
QFactoryLoader * l

◆ qVerify()

bool QTest::qVerify ( bool  statement,
const char *  statementStr,
const char *  description,
const char *  file,
int  line 
)
Warning
This function is not part of the public interface.

Definition at line 2074 of file qtestcase.cpp.

Referenced by toString().

2076 {
2077  return QTestResult::verify(statement, statementStr, description, file, line);
2078 }
static bool verify(bool statement, const char *statementStr, const char *extraInfo, const char *file, int line)

◆ qWait()

void QTest::qWait ( int  ms)
inlinestatic

Waits for ms milliseconds.

While waiting, events will be processed and your test will stay responsive to user interface events or network communication.

Example:

int i = 0;
while (myNetworkServerNotResponding() && i++ < 50)

The code above will wait until the network server is responding for a maximum of about 12.5 seconds.

See also
QTest::qSleep()

Definition at line 62 of file qtestsystem.h.

Referenced by mouseEvent(), qWaitForWindowShown(), QTestDelayEvent::simulate(), and simulateEvent().

63  {
65 
67  timer.start();
68  do {
70  QTest::qSleep(10);
71  } while (timer.elapsed() < ms);
72  }
EventLoopTimerRef timer
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
qint64 elapsed() const
Returns the number of milliseconds since this QElapsedTimer was last started.
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
void start()
Starts this timer.
Q_TESTLIB_EXPORT void qSleep(int ms)
Sleeps for ms milliseconds, blocking execution of the test.
Definition: qtestcase.cpp:2269

◆ qWaitForWindowShown()

bool QTest::qWaitForWindowShown ( QWidget window)
inlinestatic
Since
4.6

Waits until the window is shown in the screen. This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen. Returns true.

Example:

Definition at line 74 of file qtestsystem.h.

75  {
76 #if defined(Q_WS_X11)
79 #elif defined(Q_WS_QWS)
80  Q_UNUSED(window);
81  qWait(100);
82 #else
83  Q_UNUSED(window);
84  qWait(50);
85 #endif
86  return true;
87  }
static void processEvents(QEventLoop::ProcessEventsFlags flags=QEventLoop::AllEvents)
Processes all pending events for the calling thread according to the specified flags until there are ...
static void qWait(int ms)
Waits for ms milliseconds.
Definition: qtestsystem.h:62
void qt_x11_wait_for_window_manager(QWidget *w)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qWarn()

void QTest::qWarn ( const char *  message)
Warning
This function is not part of the public interface.

Definition at line 2102 of file qtestcase.cpp.

Referenced by mouseEvent(), simulateEvent(), and toString().

2103 {
2104  QTestLog::warn(message);
2105 }
static void warn(const char *msg)
Definition: qtestlog.cpp:332

◆ randomizeList()

template<typename T >
static void QTest::randomizeList ( T *  array,
int  size 
)
static

Definition at line 1059 of file qtestcase.cpp.

Referenced by qInvokeTestMethods().

1060 {
1061  for (int i = 0; i != size; i++) {
1062  int pos = qrand() % size;
1063  swap(array, pos, i);
1064  }
1065 }
Q_CORE_EXPORT int qrand()
void swap(T *array, int pos, int otherPos)
Definition: qtestcase.cpp:1051

◆ seedRandom()

void QTest::seedRandom ( )

Definition at line 1030 of file qtestcase.cpp.

Referenced by qExec().

1031 {
1032  static bool randomSeeded = false;
1033  if (!randomSeeded) {
1034  if (!QTest::seedSet) {
1036  timer.start();
1037  QTest::seed = timer.msecsSinceReference();
1038  }
1040  randomSeeded = true;
1041  }
1042 }
EventLoopTimerRef timer
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
static bool seedSet
Definition: qtestcase.cpp:944
static unsigned int seed
Definition: qtestcase.cpp:943
qint64 msecsSinceReference() const
Returns the number of milliseconds between last time this QElapsedTimer object was started and its re...
Q_CORE_EXPORT void qsrand(uint seed)
void start()
Starts this timer.

◆ sendKeyEvent() [1/2]

static void QTest::sendKeyEvent ( KeyAction  action,
QWidget widget,
Qt::Key  code,
QString  text,
Qt::KeyboardModifiers  modifier,
int  delay = -1 
)
static

Definition at line 87 of file qtestkeyboard.h.

Referenced by keyEvent(), and sendKeyEvent().

89  {
91 
92  if (!widget)
93  widget = QWidget::keyboardGrabber();
94  if (!widget) {
96  widget = apw->focusWidget() ? apw->focusWidget() : apw;
97  else
98  widget = QApplication::focusWidget();
99  }
100  if (!widget)
101  widget = QApplication::activeWindow();
102 
103  QTEST_ASSERT(widget);
104 
105  if (action == Click) {
106  QPointer<QWidget> ptr(widget);
107  sendKeyEvent(Press, widget, code, text, modifier, delay);
108  if (!ptr) {
109  // if we send key-events to embedded widgets, they might be destroyed
110  // when the user presses Return
111  return;
112  }
113  sendKeyEvent(Release, widget, code, text, modifier, delay);
114  return;
115  }
116 
117  bool repeat = false;
118 
119  if (action == Press) {
120  if (modifier & Qt::ShiftModifier)
121  simulateEvent(widget, true, Qt::Key_Shift, 0, QString(), false, delay);
122 
123  if (modifier & Qt::ControlModifier)
124  simulateEvent(widget, true, Qt::Key_Control, modifier & Qt::ShiftModifier, QString(), false, delay);
125 
126  if (modifier & Qt::AltModifier)
127  simulateEvent(widget, true, Qt::Key_Alt,
128  modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay);
129  if (modifier & Qt::MetaModifier)
130  simulateEvent(widget, true, Qt::Key_Meta, modifier & (Qt::ShiftModifier
131  | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay);
132  simulateEvent(widget, true, code, modifier, text, repeat, delay);
133  } else if (action == Release) {
134  simulateEvent(widget, false, code, modifier, text, repeat, delay);
135 
136  if (modifier & Qt::MetaModifier)
137  simulateEvent(widget, false, Qt::Key_Meta, modifier, QString(), false, delay);
138  if (modifier & Qt::AltModifier)
139  simulateEvent(widget, false, Qt::Key_Alt, modifier &
140  (Qt::ShiftModifier | Qt::ControlModifier | Qt::AltModifier), QString(), false, delay);
141 
142  if (modifier & Qt::ControlModifier)
143  simulateEvent(widget, false, Qt::Key_Control,
144  modifier & (Qt::ShiftModifier | Qt::ControlModifier), QString(), false, delay);
145 
146  if (modifier & Qt::ShiftModifier)
147  simulateEvent(widget, false, Qt::Key_Shift, modifier & Qt::ShiftModifier, QString(), false, delay);
148  }
149  }
QWidget * focusWidget() const
Returns the last child of this widget that setFocus had been called on.
Definition: qwidget.cpp:6863
static QWidget * activeWindow()
Returns the application top-level window that has the keyboard input focus, or 0 if no application wi...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
#define qApp
const T * ptr(const T &t)
static QWidget * activePopupWidget()
Returns the active popup widget.
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
static QWidget * keyboardGrabber()
Returns the widget that is currently grabbing the keyboard input.
static void simulateEvent(QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1)
Definition: qtestkeyboard.h:70
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...

◆ sendKeyEvent() [2/2]

static void QTest::sendKeyEvent ( KeyAction  action,
QWidget widget,
Qt::Key  code,
char  ascii,
Qt::KeyboardModifiers  modifier,
int  delay = -1 
)
static

Definition at line 152 of file qtestkeyboard.h.

154  {
155  QString text;
156  if (ascii)
157  text = QString(QChar::fromLatin1(ascii));
158  sendKeyEvent(action, widget, code, text, modifier, delay);
159  }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1)
static QChar fromLatin1(char c)
Converts the Latin-1 character c to its equivalent QChar.
Definition: qchar.h:378
#define text
Definition: qobjectdefs.h:80

◆ setBenchmarkResult()

void QTest::setBenchmarkResult ( qreal  result,
QTest::QBenchmarkMetric  metric 
)

Sets the benchmark result for this test function to result.

Use this function if you want to report benchmark results without using the QBENCHMARK macro. Use metric to specify how QTestLib should interpret the results.

The context for the result will be the test function name and any data tag from the _data function. This function can only be called once in each test function, subsequent calls will replace the earlier reported results.

Note that the -iterations command line argument has no effect on test functions without the QBENCHMARK macro.

Since
4.7

Definition at line 291 of file qbenchmark.cpp.

292 {
293  QBenchmarkTestMethodData::current->setResult(result, metric, false);
294 }
void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro=true)
Definition: qbenchmark.cpp:152
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167

◆ setIterationCount()

void QTest::setIterationCount ( int  count)
Warning
This function is not part of the public interface.

Definition at line 252 of file qbenchmark.cpp.

◆ setIterationCountHint()

void QTest::setIterationCountHint ( int  count)
Warning
This function is not part of the public interface.

Definition at line 245 of file qbenchmark.cpp.

246 {
248 }
int adjustIterationCount(int suggestion)
Definition: qbenchmark.cpp:140
static QBenchmarkTestMethodData * current
Definition: qbenchmark_p.h:167

◆ simulateEvent()

void QTest::simulateEvent ( QWidget widget,
bool  press,
int  code,
Qt::KeyboardModifiers  modifier,
QString  text,
bool  repeat,
int  delay = -1 
)
static
Warning
This function is not part of the public interface.

Definition at line 70 of file qtestkeyboard.h.

Referenced by sendKeyEvent().

72  {
73  QTEST_ASSERT(widget);
74  extern int Q_TESTLIB_EXPORT defaultKeyDelay();
75 
76  if (delay == -1 || delay < defaultKeyDelay())
77  delay = defaultKeyDelay();
78  if(delay > 0)
79  QTest::qWait(delay);
80 
81  QKeyEvent a(press ? QEvent::KeyPress : QEvent::KeyRelease, code, modifier, text, repeat);
83  if (!qApp->notify(widget, &a))
84  QTest::qWarn("Keyboard event not accepted by receiving widget");
85  }
#define Q_TESTLIB_EXPORT
Definition: qtest_global.h:56
The QKeyEvent class describes a key event.
Definition: qevent.h:224
long ASN1_INTEGER_get ASN1_INTEGER * a
#define qApp
static void qWait(int ms)
Waits for ms milliseconds.
Definition: qtestsystem.h:62
Q_TESTLIB_EXPORT void qWarn(const char *message)
Definition: qtestcase.cpp:2102
#define QTEST_ASSERT(cond)
Definition: qtestassert.h:53
int Q_TESTLIB_EXPORT defaultKeyDelay()
Definition: qtestcase.cpp:1019

◆ swap()

template<typename T >
void QTest::swap ( T *  array,
int  pos,
int  otherPos 
)

Definition at line 1051 of file qtestcase.cpp.

Referenced by randomizeList().

1052 {
1053  T tmp = array[pos];
1054  array[pos] = array[otherPos];
1055  array[otherPos] = tmp;
1056 }

◆ testObject()

QObject * QTest::testObject ( )
Warning
This function is not part of the public interface.

Definition at line 2283 of file qtestcase.cpp.

Referenced by qExec(), and toString().

2284 {
2285  return currentTestObject;
2286 }
static QObject * currentTestObject
Definition: qtestcase.cpp:903

◆ toHexRepresentation()

Q_TESTLIB_EXPORT char * QTest::toHexRepresentation ( const char *  ba,
int  length 
)

Returns a pointer to a string that is the string 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.

length is the length of the string ba.

Definition at line 1667 of file qtestcase.cpp.

Referenced by toString().

1668 {
1669  if(length == 0)
1670  return qstrdup("");
1671 
1672  /* We output at maximum about maxLen characters in order to avoid
1673  * running out of memory and flooding things when the byte array
1674  * is large.
1675  *
1676  * maxLen can't be for example 200 because QTestLib is sprinkled with fixed
1677  * size char arrays.
1678  * */
1679  const int maxLen = 50;
1680  const int len = qMin(maxLen, length);
1681  char *result = 0;
1682 
1683  if(length > maxLen) {
1684  const int size = len * 3 + 4;
1685  result = new char[size];
1686 
1687  char *const forElipsis = result + size - 5;
1688  forElipsis[0] = ' ';
1689  forElipsis[1] = '.';
1690  forElipsis[2] = '.';
1691  forElipsis[3] = '.';
1692  result[size - 1] = '\0';
1693  }
1694  else {
1695  const int size = len * 3;
1696  result = new char[size];
1697  result[size - 1] = '\0';
1698  }
1699 
1700  const char toHex[] = "0123456789ABCDEF";
1701  int i = 0;
1702  int o = 0;
1703 
1704  while(true) {
1705  const char at = ba[i];
1706 
1707  result[o] = toHex[(at >> 4) & 0x0F];
1708  ++o;
1709  result[o] = toHex[at & 0x0F];
1710 
1711  ++i;
1712  ++o;
1713  if(i == len)
1714  break;
1715  else {
1716  result[o] = ' ';
1717  ++o;
1718  }
1719  }
1720 
1721  return result;
1722 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
#define at(className, varName)
static char toHex(quint8 c)
Definition: qurl.cpp:4440
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114

◆ toString() [1/18]

template<>
char * QTest::toString ( const QLatin1String str)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given string.

Definition at line 73 of file qtest.h.

Referenced by compare_ptr_helper(), compare_string_helper(), qCompare< double >(), qCompare< float >(), qSignalDumperCallback(), and toString().

74 {
75  return qstrdup(str.latin1());
76 }
const char * latin1() const
Returns the Latin-1 string stored in this object.
Definition: qstring.h:661
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114

◆ toString() [2/18]

template<>
char * QTest::toString ( const QString str)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given string.

Definition at line 78 of file qtest.h.

79 {
80  return qstrdup(str.toLatin1().constData());
81 }
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114

◆ toString() [3/18]

template<>
char * QTest::toString ( const QByteArray ba)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the byte array ba.

See also
QTest::toHexRepresentation()

Definition at line 83 of file qtest.h.

84 {
85  return QTest::toHexRepresentation(ba.constData(), ba.length());
86 }
char * toHexRepresentation(const char *ba, int length)
Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex ...
Definition: qtestcase.cpp:1667
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ toString() [4/18]

template<>
char * QTest::toString ( const QTime time)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given time.

Definition at line 88 of file qtest.h.

89 {
90  return time.isValid()
91  ? qstrdup(time.toString(QLatin1String("hh:mm:ss.zzz")).toLatin1().constData())
92  : qstrdup("Invalid QTime");
93 }
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the time as a string.
Definition: qdatetime.cpp:1653
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
bool isValid() const
Returns true if the time is valid; otherwise returns false.
Definition: qdatetime.cpp:1566

◆ toString() [5/18]

template<>
char * QTest::toString ( const QDate date)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given date.

Definition at line 95 of file qtest.h.

96 {
97  return date.isValid()
98  ? qstrdup(date.toString(QLatin1String("yyyy/MM/dd")).toLatin1().constData())
99  : qstrdup("Invalid QDate");
100 }
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the date as a string.
Definition: qdatetime.cpp:823

◆ toString() [6/18]

template<>
char * QTest::toString ( const QDateTime dateTime)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the date and time specified by dateTime.

Definition at line 102 of file qtest.h.

103 {
104  return dateTime.isValid()
105  ? qstrdup((dateTime.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")) +
106  (dateTime.timeSpec() == Qt::LocalTime ? QLatin1String("[local time]") : QLatin1String("[UTC]"))).toLatin1().constData())
107  : qstrdup("Invalid QDateTime");
108 }
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
Qt::TimeSpec timeSpec() const
Returns the time specification of the datetime.
Definition: qdatetime.cpp:2379
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114

◆ toString() [7/18]

template<>
char * QTest::toString ( const QChar c)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given character.

Definition at line 110 of file qtest.h.

111 {
112  return qstrdup(QString::fromLatin1("QChar: '%1' (0x%2)").arg(c).arg(QString::number(static_cast<int>(c.unicode()), 16)).toLatin1().constData());
113 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [8/18]

template<>
char * QTest::toString ( const QPoint p)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given point.

Definition at line 115 of file qtest.h.

116 {
117  return qstrdup(QString::fromLatin1("QPoint(%1,%2)").arg(p.x()).arg(p.y()).toLatin1().constData());
118 }
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [9/18]

template<>
char * QTest::toString ( const QSize s)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given size.

Definition at line 120 of file qtest.h.

121 {
122  return qstrdup(QString::fromLatin1("QSize(%1x%2)").arg(s.width()).arg(s.height()).toLatin1().constData());
123 }
int width() const
Returns the width.
Definition: qsize.h:126
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
int height() const
Returns the height.
Definition: qsize.h:129
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [10/18]

template<typename T >
char * QTest::toString ( const T &  value)
inline

Returns a textual representation of value.

This function is used by QCOMPARE() to output verbose information in case of a test failure.

You can add specializations of this function to your test to enable verbose output.

Note: The caller of toString() must delete the returned data using delete[]. Your implementation should return a string created with new[] or qstrdup().

Example:

namespace QTest {
template<>
char *toString(const MyPoint &point)
{
QByteArray ba = "MyPoint(";
ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
ba += ")";
return qstrdup(ba.data());
}
}

The example above defines a toString() specialization for a class called MyPoint. Whenever a comparison of two instances of MyPoint fails, QCOMPARE() will call this function to output the contents of MyPoint to the test log.

See also
QCOMPARE()

Definition at line 123 of file qtestcase.h.

124  {
125  return 0;
126  }

◆ toString() [11/18]

template<>
char * QTest::toString ( const QRect s)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given rectangle.

Definition at line 125 of file qtest.h.

126 {
127  return qstrdup(QString::fromLatin1("QRect(%1,%2 %5x%6) (bottomright %3,%4)").arg(s.left()).arg(s.top()).arg(s.right()).arg(s.bottom()).arg(s.width()).arg(s.height()).toLatin1().constData());
128 }
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [12/18]

template<>
char * QTest::toString ( const QPointF p)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given point.

Definition at line 130 of file qtest.h.

131 {
132  return qstrdup(QString::fromLatin1("QPointF(%1,%2)").arg(p.x()).arg(p.y()).toLatin1().constData());
133 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [13/18]

char * QTest::toString ( const char *  str)
Warning
This function is not part of the public interface.

Definition at line 2357 of file qtestcase.cpp.

2358 {
2359  if (!str)
2360  return 0;
2361  char *msg = new char[strlen(str) + 1];
2362  return qstrcpy(msg, str);
2363 }
char * qstrcpy(char *dst, const char *src)
Copies all the characters up to and including the &#39;\0&#39; from src into dst and returns a pointer to dst...
Definition: qbytearray.cpp:137

◆ toString() [14/18]

char * QTest::toString ( const void *  p)
Warning
This function is not part of the public interface.

Definition at line 2367 of file qtestcase.cpp.

2368 {
2369  char *msg = new char[128];
2370  qt_snprintf(msg, 128, "%p", p);
2371  return msg;
2372 }
int Q_TESTLIB_EXPORT qt_snprintf(char *str, int size, const char *format,...)
Definition: qtestcase.cpp:961

◆ toString() [15/18]

template<>
char * QTest::toString ( const QSizeF s)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given size.

Definition at line 135 of file qtest.h.

136 {
137  return qstrdup(QString::fromLatin1("QSizeF(%1x%2)").arg(s.width()).arg(s.height()).toLatin1().constData());
138 }
qreal width() const
Returns the width.
Definition: qsize.h:284
qreal height() const
Returns the height.
Definition: qsize.h:287
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [16/18]

template<>
char * QTest::toString ( const QRectF s)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given rectangle.

Definition at line 140 of file qtest.h.

141 {
142  return qstrdup(QString::fromLatin1("QRectF(%1,%2 %5x%6) (bottomright %3,%4)").arg(s.left()).arg(s.top()).arg(s.right()).arg(s.bottom()).arg(s.width()).arg(s.height()).toLatin1().constData());
143 }
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712

◆ toString() [17/18]

template<>
char * QTest::toString ( const QUrl url)
inline
Since
4.4 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns a textual representation of the given url.

Definition at line 145 of file qtest.h.

146 {
147  return qstrdup(uri.toEncoded().constData());
148 }
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114

◆ toString() [18/18]

template<>
char * QTest::toString ( const QVariant v)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns a textual representation of the given variant.

Definition at line 150 of file qtest.h.

151 {
152  QByteArray vstring("QVariant(");
153  if (v.isValid()) {
154  QByteArray type(v.typeName());
155  if (type.isEmpty()) {
157  }
158  vstring.append(type);
159  if (!v.isNull()) {
160  vstring.append(',');
161  if (v.canConvert(QVariant::String)) {
162  vstring.append(qvariant_cast<QString>(v).toLatin1());
163  }
164  else {
165  vstring.append("<value not representable as string>");
166  }
167  }
168  }
169  vstring.append(')');
170 
171  return qstrdup(vstring.constData());
172 }
int type
Definition: qmetatype.cpp:239
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
char * qstrdup(const char *src)
Returns a duplicate string.
Definition: qbytearray.cpp:114
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...

◆ touchEvent()

QTouchEventSequence QTest::touchEvent ( QWidget widget = 0,
QTouchEvent::DeviceType  deviceType = QTouchEvent::TouchScreen 
)
inline

Creates and returns a QTouchEventSequence for the device deviceType to simulate events for widget.

When adding touch events to the sequence, widget will also be used to translate the position provided to screen coordinates, unless another widget is provided in the respective calls to press(), move() etc.

The touch events are committed to the event system when the destructor of the QTouchEventSequence is called (ie when the object returned runs out of scope).

Definition at line 141 of file qtesttouch.h.

Referenced by QWidget::event(), QApplication::notify(), QApplicationPrivate::translateRawTouchEvent(), and QGraphicsView::viewportEvent().

143  {
144  return QTouchEventSequence(widget, deviceType);
145  }

◆ xmlIncidentType2String()

static const char* QTest::xmlIncidentType2String ( QAbstractTestLogger::IncidentTypes  type)
static

Definition at line 77 of file qxmltestlogger.cpp.

Referenced by QXmlTestLogger::addIncident().

78  {
79  switch (type) {
81  return "pass";
83  return "xfail";
85  return "fail";
87  return "xpass";
88  }
89  return "??????";
90  }
int type
Definition: qmetatype.cpp:239

◆ xmlMessageType2String()

static const char* QTest::xmlMessageType2String ( QAbstractTestLogger::MessageTypes  type)
static

Definition at line 56 of file qxmltestlogger.cpp.

Referenced by QXmlTestLogger::addMessage().

57  {
58  switch (type) {
60  return "warn";
62  return "system";
64  return "qdebug";
66  return "qwarn";
68  return "qfatal";
70  return "skip";
72  return "info";
73  }
74  return "??????";
75  }
int type
Definition: qmetatype.cpp:239

Variable Documentation

◆ currentAppName

const char* QTest::currentAppName = 0
static

◆ currentGlobalTestData

QTestData* QTest::currentGlobalTestData = 0
static

◆ currentTestData

QTestData* QTest::currentTestData = 0
static

◆ currentTestFunc

const char* QTest::currentTestFunc = 0
static

◆ currentTestObject

QObject* QTest::currentTestObject = 0
static

◆ currentTestObjectName

const char* QTest::currentTestObjectName = 0
static

◆ dataFailed

bool QTest::dataFailed = false
static

◆ eventDelay

int QTest::eventDelay = -1
static

Definition at line 940 of file qtestcase.cpp.

Referenced by defaultEventDelay(), and qtest_qParseArgs().

◆ expectFailComment

const char* QTest::expectFailComment = 0
static

◆ expectFailMode

int QTest::expectFailMode = 0
static

◆ failed

bool QTest::failed = false
static

◆ fails

int QTest::fails = 0
static

◆ flushMode

QTestLog::FlushMode QTest::flushMode = QTestLog::NoFlush
static

Definition at line 88 of file qtestlog.cpp.

Referenced by initLogger(), and QTestLog::setFlushMode().

◆ ignoreLevel

int QTest::ignoreLevel = 0
static

◆ ignoreResultList

IgnoreResultList* QTest::ignoreResultList = 0
static

◆ iLevel

int QTest::iLevel = 0
static

◆ keyDelay

int QTest::keyDelay = -1
static

Definition at line 938 of file qtestcase.cpp.

Referenced by defaultKeyDelay(), and qtest_qParseArgs().

◆ keyVerbose

int QTest::keyVerbose = -1
static

Definition at line 942 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

◆ location

Definition at line 63 of file qtestresult.cpp.

Referenced by QUnixPrintWidgetPrivate::_q_printerChanged(), QPatternist::XsdSchemaResolver::addAlternativeType(), QPatternist::XsdSchemaResolver::addAttributeType(), QPatternist::XsdSchemaResolver::addComplexBaseType(), QPatternist::XsdSchemaResolver::addElementType(), QPatternist::XsdSchemaResolver::addKeyReference(), QPatternist::XsdSchemaResolver::addSimpleListType(), QPatternist::XsdSchemaResolver::addSimpleRestrictionBase(), QPatternist::XsdSchemaResolver::addSimpleUnionTypes(), QPatternist::XsdSchemaResolver::addSubstitutionGroupAffiliation(), QGLShaderProgram::bindAttributeLocation(), QPatternist::CastingPlatform< UntypedAtomicConverter, true >::CastingPlatform(), QPatternist::XsdSchemaChecker::checkBasicCircularInheritances(), QPatternist::XsdSchemaChecker::checkBasicComplexTypeConstraints(), QPatternist::XsdSchemaChecker::checkBasicSimpleTypeConstraints(), QPatternist::XsdSchemaChecker::checkCircularInheritances(), QPatternist::XsdSchemaChecker::checkComplexTypeConstraints(), QPatternist::XsdSchemaChecker::checkInheritanceRestrictions(), QPatternist::XsdSchemaChecker::checkSimpleDerivationRestrictions(), QPatternist::XsdSchemaChecker::checkSimpleTypeConstraints(), QPatternist::GenericPredicate::create(), QPatternist::XsdSchemaParser::currentSourceLocation(), QTestResult::currentTestLocation(), QGL2PaintEngineExPrivate::drawPixmapFragments(), extract_location(), QGLEngineSharedShaders::findProgramInCache(), QTestResult::finishedCurrentTestFunction(), QTestXmlStreamer::formatStart(), getLocations(), QPatternist::ColoringMessageHandler::handleMessage(), QPatternist::AccelTreeResourceLoader::load(), QPatternist::XsdValidatingInstanceReader::loadSchema(), QPatternist::CastingPlatform< UntypedAtomicConverter, true >::locateCaster(), QLibraryInfo::location(), QScriptNewBreakpointWidget::onOkClicked(), QEventDispatcherMacPrivate::postedEventsSourcePerformCallback(), qt_mac_constructQIconFromIconRef(), QGLMaskTextureCache::quadtreeClear(), QGLMaskTextureCache::quadtreeInsert(), QGLMaskTextureCache::quadtreeLocation(), QTestResult::reset(), QDeclarativeTypeData::resolveTypes(), QGLShaderProgram::setAttributeValue(), QTestResult::setCurrentTestFunction(), QTestResult::setCurrentTestLocation(), QPatternist::XsdReference::setSourceLocation(), QPatternist::XsdAttributeReference::setSourceLocation(), QPatternist::XsdSchemaChecker::sourceLocation(), QPatternist::XsdSchemaResolver::sourceLocation(), QPatternist::StaticContext::StaticContext(), QOpenGLPaintEnginePrivate::updateFragmentProgramData(), writeIncludeFile(), and QMenuPrivate::QMenuScroller::~QMenuScroller().

◆ logMode

QTestLog::LogMode QTest::logMode = QTestLog::Plain
static

Definition at line 87 of file qtestlog.cpp.

Referenced by initLogger(), QTestLog::logMode(), and QTestLog::setLogMode().

◆ maxWarnings

int QTest::maxWarnings = 2002
static

Definition at line 90 of file qtestlog.cpp.

Referenced by messageHandler(), and QTestLog::setMaxWarnings().

◆ mouseDelay

int QTest::mouseDelay = -1
static

Definition at line 939 of file qtestcase.cpp.

Referenced by defaultMouseDelay(), and qtest_qParseArgs().

◆ noCrashHandler

bool QTest::noCrashHandler = false
static

Definition at line 946 of file qtestcase.cpp.

Referenced by qExec(), and qtest_qParseArgs().

◆ oldMessageHandler

QtMsgHandler QTest::oldMessageHandler
static

Definition at line 95 of file qtestlog.cpp.

Referenced by QTestLog::startLogging(), and QTestLog::stopLogging().

◆ outFile

const char* QTest::outFile = 0
static

◆ passes

int QTest::passes = 0
static

◆ printAvailableFunctions

Q_TESTLIB_EXPORT bool QTest::printAvailableFunctions = false

Definition at line 1086 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

◆ printAvailableTags

Q_TESTLIB_EXPORT bool QTest::printAvailableTags = false

◆ randomOrder

bool QTest::randomOrder = false
static

Definition at line 941 of file qtestcase.cpp.

Referenced by qExec(), qInvokeTestMethods(), and qtest_qParseArgs().

◆ seed

unsigned int QTest::seed = 0
static

◆ seedSet

bool QTest::seedSet = false
static

Definition at line 944 of file qtestcase.cpp.

Referenced by qtest_qParseArgs(), qTestRandomSeed(), and seedRandom().

◆ skipCurrentTest

bool QTest::skipCurrentTest = false
static

◆ skips

int QTest::skips = 0
static

◆ stream [1/3]

FILE* QTest::stream = 0
static

Definition at line 56 of file qtestfilelogger.cpp.

◆ stream [2/3]

FILE* QTest::stream = 0
static

Definition at line 60 of file qabstracttestlogger.cpp.

Referenced by QFontDatabasePrivate::addFont(), QCopChannel::answer(), QTextStream::bin(), QTextStream::bom(), QTextStream::center(), QMacPasteboardMimeVCard::convertFromMime(), QTextStream::dec(), deflate(), QSvgPaintEngine::drawImage(), QSvgPaintEngine::drawPolygon(), QAbstractItemModel::dropMimeData(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QStandardItemModel::dropMimeData(), QTextStream::fixed(), QTestFileLogger::flush(), QTextStream::flush(), QTextStream::forcepoint(), QTextStream::forcesign(), QTextStream::hex(), inflate(), QTestFileLogger::init(), QCss::Parser::init(), QTestBasicStreamer::isTtyOutput(), QAbstractTestLogger::isTtyOutput(), QStandardItemModelPrivate::itemFromIndex(), launchWebBrowser(), QTextStream::left(), QScriptDebuggerConsolePrivate::loadScriptedCommands(), QTextStream::lowercasebase(), QTextStream::lowercasedigits(), QDebug::maybeSpace(), QDeclarativeDebugTrace::messageReceived(), QAbstractItemModel::mimeData(), QStandardItemModel::mimeData(), QTextStream::noforcepoint(), QTextStream::noforcesign(), QTextStream::noshowbase(), QDebug::nospace(), QTextStream::oct(), QDebug::operator<<(), operator<<(), QLine::operator<<(), QLineF::operator<<(), QDebug::operator=(), QmlJSDebugger::operator>>(), operator>>(), QLine::operator>>(), QLineF::operator>>(), QTestBasicStreamer::outputString(), QAbstractTestLogger::outputString(), QDeclarativeDirParser::parse(), QDeclarativeScriptParser::parse(), qax_generateDocumentation(), QDebug::QDebug(), QPolygon::QPolygon(), QXmlInputSource::QXmlInputSource(), QTextStream::reset(), QWidget::restoreGeometry(), QSplitter::restoreState(), QFileDialog::restoreState(), QMainWindowLayoutState::restoreState(), QHeaderView::restoreState(), QMainWindow::restoreState(), QTextStream::right(), QWidget::saveGeometry(), QSplitter::saveState(), QFileDialog::saveState(), QHeaderView::saveState(), QMainWindow::saveState(), QTextStream::scientific(), QTextStream::showbase(), QAbstractItemModel::sibling(), QDebug::space(), QAbstractTestLogger::startLogging(), QTestBasicStreamer::startStreaming(), QAbstractTestLogger::stopLogging(), QTestBasicStreamer::stopStreaming(), QSettingsPrivate::stringToVariant(), QWSInputContext::translateIMEvent(), QSvgPaintEngine::updateState(), QTextStream::uppercasebase(), QTextStream::uppercasedigits(), QTextStream::ws(), QDebug::~QDebug(), and QTestFileLogger::~QTestFileLogger().

◆ stream [3/3]

FILE* QTest::stream = 0
static

Definition at line 60 of file qtestbasicstreamer.cpp.

◆ testFuncCleaner

struct QTest::TestFuncCleanup QTest::testFuncCleaner
static

◆ testFuncCount

int QTest::testFuncCount = 0
static

Definition at line 923 of file qtestcase.cpp.

Referenced by qInvokeTestMethods(), and qtest_qParseArgs().

◆ testFuncs

TestFunction* QTest::testFuncs = 0
static

Contains the list of test functions that was supplied on the command line, if any. Hence, if not empty, those functions should be run instead of all appearing in the test case.

Definition at line 922 of file qtestcase.cpp.

Referenced by QTest::TestFuncCleanup::cleanup(), qInvokeTestMethods(), and qtest_qParseArgs().

◆ testFunctions

Q_TESTLIB_EXPORT QStringList QTest::testFunctions

Definition at line 1088 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

◆ testLogger

QAbstractTestLogger* QTest::testLogger = 0
static

◆ testTags

Q_TESTLIB_EXPORT QStringList QTest::testTags

Definition at line 1089 of file qtestcase.cpp.

Referenced by qtest_qParseArgs().

◆ verbosity

int QTest::verbosity = 0
static

Definition at line 89 of file qtestlog.cpp.

Referenced by QTestLog::setVerboseLevel(), and QTestLog::verboseLevel().