diff options
Diffstat (limited to 'tests/auto/other')
21 files changed, 723 insertions, 539 deletions
diff --git a/tests/auto/other/compiler/tst_compiler.cpp b/tests/auto/other/compiler/tst_compiler.cpp index 121d731757..8b59f2758f 100644 --- a/tests/auto/other/compiler/tst_compiler.cpp +++ b/tests/auto/other/compiler/tst_compiler.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2017 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -802,7 +802,7 @@ void tst_Compiler::cxx11_auto_type() QSKIP("Compiler does not support C++11 feature"); #else auto i = 1; - auto x = qrand(); + auto x = QRandomGenerator::global()->generate(); auto l = 1L; auto s = QStringLiteral("Hello World"); @@ -851,8 +851,8 @@ void tst_Compiler::cxx11_decltype() #ifndef Q_COMPILER_DECLTYPE QSKIP("Compiler does not support C++11 feature"); #else - decltype(qrand()) i = 0; - QCOMPARE(i, 0); + decltype(QRandomGenerator::global()->generate()) i = 0; + QCOMPARE(i, 0U); #endif } @@ -1549,7 +1549,7 @@ void tst_Compiler::runtimeArrays() #if __cpp_runtime_arrays-0 < 201304 QSKIP("Compiler does not support this C++14 feature"); #else - int i[qrand() & 0x1f]; + int i[QRandomGenerator::global()->generate() & 0x1f]; Q_UNUSED(i); #endif } diff --git a/tests/auto/other/lancelot/scripts/gradientxform_device.qps b/tests/auto/other/lancelot/scripts/gradientxform_device.qps new file mode 100644 index 0000000000..82ebb536bb --- /dev/null +++ b/tests/auto/other/lancelot/scripts/gradientxform_device.qps @@ -0,0 +1,67 @@ +# Version: 1 +# CheckVsReference: 5% + +gradient_clearStops +gradient_appendStop 0 black +gradient_appendStop 0.4 yellow +gradient_appendStop 1 gray + +gradient_setSpread PadSpread + +gradient_setCoordinateMode StretchToDeviceMode + +# first run is dummy, make it offscreen +save +translate -500 -500 + +begin_block row +save + +setPen nopen +drawRect 50 0 100 100 + +setPen brush 30 +setBrush lightblue +drawRect 175 15 70 70 + +setFont "times" 110 99 +drawText 270 100 "X" + +restore +end_block row + +restore + +drawText 160 20 "PLAIN" +drawText 560 20 "BRUSH XFORM" +translate 0 20 + +begin_block block +save + +drawText 75 20 "Brush Fill" +drawText 176 20 "Pen Stroke" +drawText 277 20 "Text Stroke" +translate 0 30 +drawText 0 50 "Linear" +drawText 0 160 "Radial" +drawText 0 270 "Conical" + +gradient_setLinear 0.0 0.0 0.4 0.0 +repeat_block row + +translate 0 110 +gradient_setRadial 0.04 0.08 0.3 0.3 0.05 +repeat_block row + +translate 0 110 +gradient_setConical 0.25 0.1 45 +repeat_block row +restore +end_block block + +translate 400 0 +brushRotate 30.0 +brushScale 1.5 .5 +brushTranslate 0 -80 +repeat_block block diff --git a/tests/auto/other/lancelot/scripts/gradientxform_logical.qps b/tests/auto/other/lancelot/scripts/gradientxform_logical.qps new file mode 100644 index 0000000000..1bb157b635 --- /dev/null +++ b/tests/auto/other/lancelot/scripts/gradientxform_logical.qps @@ -0,0 +1,67 @@ +# Version: 1 +# CheckVsReference: 5% + +gradient_clearStops +gradient_appendStop 0 black +gradient_appendStop 0.4 yellow +gradient_appendStop 1 gray + +gradient_setSpread PadSpread + +gradient_setCoordinateMode LogicalMode + +# first run is dummy, make it offscreen +save +translate -500 -500 + +begin_block row +save + +setPen nopen +drawRect 50 0 100 100 + +setPen brush 30 +setBrush lightblue +drawRect 175 15 70 70 + +setFont "times" 110 99 +drawText 270 100 "X" + +restore +end_block row + +restore + +drawText 160 20 "PLAIN" +drawText 560 20 "BRUSH XFORM" +translate 0 20 + +begin_block block +save + +drawText 75 20 "Brush Fill" +drawText 176 20 "Pen Stroke" +drawText 277 20 "Text Stroke" +translate 0 30 +drawText 0 50 "Linear" +drawText 0 160 "Radial" +drawText 0 270 "Conical" + +gradient_setLinear 0 0 400 0 +repeat_block row + +translate 0 110 +gradient_setRadial 200 50 140 70 20 +repeat_block row + +translate 0 110 +gradient_setConical 220 60 45 +repeat_block row +restore +end_block block + +translate 400 0 +brushRotate 30.0 +brushScale 1.5 .5 +brushTranslate 0 -80 +repeat_block block diff --git a/tests/auto/other/lancelot/scripts/gradientxform_object.qps b/tests/auto/other/lancelot/scripts/gradientxform_object.qps new file mode 100644 index 0000000000..d785a008c0 --- /dev/null +++ b/tests/auto/other/lancelot/scripts/gradientxform_object.qps @@ -0,0 +1,68 @@ +# Version: 1 +# CheckVsReference: 5% + +gradient_clearStops +gradient_appendStop 0 black +gradient_appendStop 0.4 yellow +gradient_appendStop 1 gray + +gradient_setSpread PadSpread + +gradient_setCoordinateMode ObjectBoundingMode + +# first run is dummy, make it offscreen +save +translate -500 -500 + +begin_block row +save + +setPen nopen +drawRect 50 0 100 100 + +setPen brush 30 +setBrush lightblue +translate 110 0 +drawRect 65 15 70 70 + +translate 110 0 +setFont "times" 110 99 +drawText 50 100 "X" + +restore +end_block row + +restore + +drawText 160 20 "PLAIN" +drawText 560 20 "BRUSH XFORM" +translate 0 20 + +begin_block block +save + +drawText 75 20 "Brush Fill" +drawText 176 20 "Pen Stroke" +drawText 277 20 "Text Stroke" +translate 0 30 +drawText 0 50 "Linear" +drawText 0 160 "Radial" +drawText 0 270 "Conical" + +gradient_setLinear 0.1 0.0 0.5 0.0 +repeat_block row + +translate 0 110 +gradient_setRadial 0.3 0.2 0.5 0.4 0.5 +repeat_block row + +translate 0 110 +gradient_setConical 0.5 0.7 45 +repeat_block row +restore +end_block block + +translate 400 0 +brushRotate 30.0 +brushScale 1.5 .5 +repeat_block block diff --git a/tests/auto/other/macnativeevents/BLACKLIST b/tests/auto/other/macnativeevents/BLACKLIST index 3998eb616a..1bc530ecc8 100644 --- a/tests/auto/other/macnativeevents/BLACKLIST +++ b/tests/auto/other/macnativeevents/BLACKLIST @@ -21,22 +21,22 @@ osx osx [testMouseDragToNonClientArea] osx -# QTQAINFRA-1292 -[testPushButtonPressRelease] -osx-10.11 ci osx-10.12 ci -# QTQAINFRA-1292 +# The following key tests fail after switching to synchronous +# expose events, and we don't know why yet. QTBUG-62042 [testKeyPressOnToplevel] -osx-10.12 ci -# QTQAINFRA-1292 +osx [testModifierShift] -osx-10.12 ci -# QTQAINFRA-1292 +osx [testModifierAlt] -osx-10.12 ci -# QTQAINFRA-1292 +osx [testModifierCtrl] +osx +# QTQAINFRA-1292 +[testPushButtonPressRelease] +osx-10.11 ci osx-10.12 ci + # QTQAINFRA-1292 [testModifierCtrlWithDontSwapCtrlAndMeta] osx-10.12 ci diff --git a/tests/auto/other/macnativeevents/macnativeevents.pro b/tests/auto/other/macnativeevents/macnativeevents.pro index 48ad04bbff..0611377d0b 100644 --- a/tests/auto/other/macnativeevents/macnativeevents.pro +++ b/tests/auto/other/macnativeevents/macnativeevents.pro @@ -1,9 +1,8 @@ CONFIG += testcase TARGET = tst_macnativeevents -LIBS += -framework Carbon QT += widgets testlib HEADERS += qnativeevents.h nativeeventlist.h expectedeventlist.h -SOURCES += qnativeevents.cpp qnativeevents_mac.cpp +SOURCES += qnativeevents.cpp qnativeevents_mac.cpp SOURCES += expectedeventlist.cpp nativeeventlist.cpp SOURCES += tst_macnativeevents.cpp diff --git a/tests/auto/other/macnativeevents/qnativeevents.cpp b/tests/auto/other/macnativeevents/qnativeevents.cpp index 758c0a94b8..f04b33151a 100644 --- a/tests/auto/other/macnativeevents/qnativeevents.cpp +++ b/tests/auto/other/macnativeevents/qnativeevents.cpp @@ -72,7 +72,7 @@ void QNativeInput::nativeEvent(QNativeEvent *event) } } -Qt::Native::Status QNativeInput::sendNativeEvent(const QNativeEvent &event, int pid) +Qt::Native::Status QNativeInput::sendNativeEvent(const QNativeEvent &event) { switch (event.id()){ case QNativeMouseMoveEvent::eventId: @@ -84,7 +84,7 @@ Qt::Native::Status QNativeInput::sendNativeEvent(const QNativeEvent &event, int case QNativeMouseWheelEvent::eventId: return sendNativeMouseWheelEvent(static_cast<const QNativeMouseWheelEvent &>(event)); case QNativeKeyEvent::eventId: - return sendNativeKeyEvent(static_cast<const QNativeKeyEvent &>(event), pid); + return sendNativeKeyEvent(static_cast<const QNativeKeyEvent &>(event)); case QNativeModifierEvent::eventId: return sendNativeModifierEvent(static_cast<const QNativeModifierEvent &>(event)); case QNativeEvent::eventId: diff --git a/tests/auto/other/macnativeevents/qnativeevents.h b/tests/auto/other/macnativeevents/qnativeevents.h index 605d6d196e..2e30d849f2 100644 --- a/tests/auto/other/macnativeevents/qnativeevents.h +++ b/tests/auto/other/macnativeevents/qnativeevents.h @@ -204,10 +204,10 @@ class QNativeInput static Qt::Native::Status sendNativeMouseMoveEvent(const QNativeMouseMoveEvent &event); static Qt::Native::Status sendNativeMouseDragEvent(const QNativeMouseDragEvent &event); static Qt::Native::Status sendNativeMouseWheelEvent(const QNativeMouseWheelEvent &event); - static Qt::Native::Status sendNativeKeyEvent(const QNativeKeyEvent &event, int pid = 0); + static Qt::Native::Status sendNativeKeyEvent(const QNativeKeyEvent &event); static Qt::Native::Status sendNativeModifierEvent(const QNativeModifierEvent &event); // sendNativeEvent will NOT differ from OS to OS. - static Qt::Native::Status sendNativeEvent(const QNativeEvent &event, int pid = 0); + static Qt::Native::Status sendNativeEvent(const QNativeEvent &event); // The following methods will differ in implementation from OS to OS: Qt::Native::Status subscribeForNativeEvents(); diff --git a/tests/auto/other/macnativeevents/qnativeevents_mac.cpp b/tests/auto/other/macnativeevents/qnativeevents_mac.cpp index 6671813188..6d7fbbecc1 100644 --- a/tests/auto/other/macnativeevents/qnativeevents_mac.cpp +++ b/tests/auto/other/macnativeevents/qnativeevents_mac.cpp @@ -27,7 +27,7 @@ ****************************************************************************/ #include "qnativeevents.h" -#include <Carbon/Carbon.h> +#include <CoreGraphics/CoreGraphics.h> #include <QtCore> // ************************************************************ @@ -176,28 +176,18 @@ static CGEventRef EventHandler_Quartz(CGEventTapProxy proxy, CGEventType type, C return inEvent; } -Qt::Native::Status insertEventHandler_Quartz(QNativeInput *nativeInput, int pid = 0) +Qt::Native::Status insertEventHandler_Quartz(QNativeInput *nativeInput) { uid_t uid = geteuid(); if (uid != 0) qWarning("MacNativeEvents: You must be root to listen for key events!"); - CFMachPortRef port; - if (!pid){ - port = CGEventTapCreate(kCGHIDEventTap, - kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, - kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput); - } else { - ProcessSerialNumber psn; - GetProcessForPID(pid, &psn); - port = CGEventTapCreateForPSN(&psn, - kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, - kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput); - } + CFMachPortRef port = CGEventTapCreate(kCGHIDEventTap, + kCGHeadInsertEventTap, kCGEventTapOptionListenOnly, + kCGEventMaskForAllEvents, EventHandler_Quartz, nativeInput); CFRunLoopSourceRef eventSrc = CFMachPortCreateRunLoopSource(NULL, port, 0); - CFRunLoopAddSource((CFRunLoopRef) GetCFRunLoopFromEventLoop(GetMainEventLoop()), - eventSrc, kCFRunLoopCommonModes); + CFRunLoopAddSource(CFRunLoopGetMain(), eventSrc, kCFRunLoopCommonModes); return Qt::Native::Success; } @@ -207,19 +197,6 @@ Qt::Native::Status removeEventHandler_Quartz() return Qt::Native::Success; // ToDo: } -Qt::Native::Status sendNativeKeyEventToProcess_Quartz(const QNativeKeyEvent &event, int pid) -{ - ProcessSerialNumber psn; - GetProcessForPID(pid, &psn); - - CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, event.press); - setModifiersFromQNativeEvent(e, event); - SetFrontProcess(&psn); - CGEventPostToPSN(&psn, e); - CFRelease(e); - return Qt::Native::Success; -} - Qt::Native::Status sendNativeKeyEvent_Quartz(const QNativeKeyEvent &event) { CGEventRef e = CGEventCreateKeyboardEvent(0, (uint)event.nativeKeyCode, event.press); @@ -344,12 +321,9 @@ Qt::Native::Status QNativeInput::sendNativeMouseWheelEvent(const QNativeMouseWhe return sendNativeMouseWheelEvent_Quartz(event); } -Qt::Native::Status QNativeInput::sendNativeKeyEvent(const QNativeKeyEvent &event, int pid) +Qt::Native::Status QNativeInput::sendNativeKeyEvent(const QNativeKeyEvent &event) { - if (!pid) - return sendNativeKeyEvent_Quartz(event); - else - return sendNativeKeyEventToProcess_Quartz(event, pid); + return sendNativeKeyEvent_Quartz(event); } Qt::Native::Status QNativeInput::sendNativeModifierEvent(const QNativeModifierEvent &event) diff --git a/tests/auto/other/macnativeevents/tst_macnativeevents.cpp b/tests/auto/other/macnativeevents/tst_macnativeevents.cpp index 5edff7aabe..e8970e6f24 100644 --- a/tests/auto/other/macnativeevents/tst_macnativeevents.cpp +++ b/tests/auto/other/macnativeevents/tst_macnativeevents.cpp @@ -35,10 +35,14 @@ #include "qnativeevents.h" #include "nativeeventlist.h" #include "expectedeventlist.h" -#include <Carbon/Carbon.h> QT_USE_NAMESPACE +// Unicode code points for the glyphs associated with these keys +// Defined by Carbon headers but not anywhere in Cocoa +static const int kControlUnicode = 0x2303; +static const int kCommandUnicode = 0x2318; + class tst_MacNativeEvents : public QObject { Q_OBJECT diff --git a/tests/auto/other/modeltest/dynamictreemodel.cpp b/tests/auto/other/modeltest/dynamictreemodel.cpp index 1f6463db8a..fc979bce2d 100644 --- a/tests/auto/other/modeltest/dynamictreemodel.cpp +++ b/tests/auto/other/modeltest/dynamictreemodel.cpp @@ -33,9 +33,8 @@ #include <QtCore/QTimer> #include <QtCore/QDebug> - -DynamicTreeModel::DynamicTreeModel(QObject *parent) - : QAbstractItemModel(parent), +DynamicTreeModel::DynamicTreeModel(QObject *parent) : + QAbstractItemModel(parent), nextId(1) { } @@ -45,186 +44,172 @@ QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex &pare // if (column != 0) // return QModelIndex(); + if (column < 0 || row < 0) + return QModelIndex(); - if ( column < 0 || row < 0 ) - return QModelIndex(); - - QList<QList<qint64> > childIdColumns = m_childItems.value(parent.internalId()); + QList<QList<qint64> > childIdColumns = m_childItems.value(parent.internalId()); - const qint64 grandParent = findParentId(parent.internalId()); - if (grandParent >= 0) { - QList<QList<qint64> > parentTable = m_childItems.value(grandParent); - if (parent.column() >= parentTable.size()) - qFatal("%s: parent.column() must be less than parentTable.size()", Q_FUNC_INFO); - QList<qint64> parentSiblings = parentTable.at(parent.column()); - if (parent.row() >= parentSiblings.size()) - qFatal("%s: parent.row() must be less than parentSiblings.size()", Q_FUNC_INFO); - } - - if (childIdColumns.size() == 0) - return QModelIndex(); + const qint64 grandParent = findParentId(parent.internalId()); + if (grandParent >= 0) { + QList<QList<qint64> > parentTable = m_childItems.value(grandParent); + if (parent.column() >= parentTable.size()) + qFatal("%s: parent.column() must be less than parentTable.size()", Q_FUNC_INFO); + QList<qint64> parentSiblings = parentTable.at(parent.column()); + if (parent.row() >= parentSiblings.size()) + qFatal("%s: parent.row() must be less than parentSiblings.size()", Q_FUNC_INFO); + } - if (column >= childIdColumns.size()) - return QModelIndex(); + if (childIdColumns.size() == 0) + return QModelIndex(); - QList<qint64> rowIds = childIdColumns.at(column); + if (column >= childIdColumns.size()) + return QModelIndex(); - if ( row >= rowIds.size()) - return QModelIndex(); + QList<qint64> rowIds = childIdColumns.at(column); - qint64 id = rowIds.at(row); + if (row >= rowIds.size()) + return QModelIndex(); - return createIndex(row, column, reinterpret_cast<void *>(id)); + qint64 id = rowIds.at(row); + return createIndex(row, column, reinterpret_cast<void *>(id)); } qint64 DynamicTreeModel::findParentId(qint64 searchId) const { - if (searchId <= 0) - return -1; - - QHashIterator<qint64, QList<QList<qint64> > > i(m_childItems); - while (i.hasNext()) - { - i.next(); - QListIterator<QList<qint64> > j(i.value()); - while (j.hasNext()) - { - QList<qint64> l = j.next(); - if (l.contains(searchId)) - { - return i.key(); - } + if (searchId <= 0) + return -1; + + QHashIterator<qint64, QList<QList<qint64> > > i(m_childItems); + while (i.hasNext()) { + i.next(); + QListIterator<QList<qint64> > j(i.value()); + while (j.hasNext()) { + QList<qint64> l = j.next(); + if (l.contains(searchId)) + return i.key(); + } } - } - return -1; + return -1; } QModelIndex DynamicTreeModel::parent(const QModelIndex &index) const { - if (!index.isValid()) - return QModelIndex(); + if (!index.isValid()) + return QModelIndex(); - qint64 searchId = index.internalId(); - qint64 parentId = findParentId(searchId); - // Will never happen for valid index, but what the hey... - if (parentId <= 0) - return QModelIndex(); + qint64 searchId = index.internalId(); + qint64 parentId = findParentId(searchId); + // Will never happen for valid index, but what the hey... + if (parentId <= 0) + return QModelIndex(); - qint64 grandParentId = findParentId(parentId); - if (grandParentId < 0) - grandParentId = 0; + qint64 grandParentId = findParentId(parentId); + if (grandParentId < 0) + grandParentId = 0; - int column = 0; - QList<qint64> childList = m_childItems.value(grandParentId).at(column); + int column = 0; + QList<qint64> childList = m_childItems.value(grandParentId).at(column); - int row = childList.indexOf(parentId); - - return createIndex(row, column, reinterpret_cast<void *>(parentId)); + int row = childList.indexOf(parentId); + return createIndex(row, column, reinterpret_cast<void *>(parentId)); } -int DynamicTreeModel::rowCount(const QModelIndex &index ) const +int DynamicTreeModel::rowCount(const QModelIndex &index) const { - QList<QList<qint64> > cols = m_childItems.value(index.internalId()); + QList<QList<qint64> > cols = m_childItems.value(index.internalId()); - if (cols.size() == 0 ) - return 0; + if (cols.size() == 0) + return 0; - if (index.column() > 0) - return 0; + if (index.column() > 0) + return 0; - return cols.at(0).size(); + return cols.at(0).size(); } -int DynamicTreeModel::columnCount(const QModelIndex &index ) const +int DynamicTreeModel::columnCount(const QModelIndex &index) const { // Q_UNUSED(index); - return m_childItems.value(index.internalId()).size(); + return m_childItems.value(index.internalId()).size(); } QVariant DynamicTreeModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); + if (!index.isValid()) + return QVariant(); - if (Qt::DisplayRole == role) - { - return m_items.value(index.internalId()); - } - return QVariant(); + if (Qt::DisplayRole == role) + return m_items.value(index.internalId()); + return QVariant(); } void DynamicTreeModel::clear() { - beginResetModel(); - m_items.clear(); - m_childItems.clear(); - nextId = 1; - endResetModel(); + beginResetModel(); + m_items.clear(); + m_childItems.clear(); + nextId = 1; + endResetModel(); } - -ModelChangeCommand::ModelChangeCommand( DynamicTreeModel *model, QObject *parent ) - : QObject(parent), m_model(model), m_numCols(1), m_startRow(-1), m_endRow(-1) +ModelChangeCommand::ModelChangeCommand(DynamicTreeModel *model, QObject *parent) : + QObject(parent), + m_model(model), + m_numCols(1), + m_startRow(-1), + m_endRow(-1) { - } QModelIndex ModelChangeCommand::findIndex(QList<int> rows) { - const int col = 0; - QModelIndex parent = QModelIndex(); - QListIterator<int> i(rows); - while (i.hasNext()) - { - parent = m_model->index(i.next(), col, parent); - if (!parent.isValid()) - qFatal("%s: parent must be valid", Q_FUNC_INFO); - } - return parent; + const int col = 0; + QModelIndex parent = QModelIndex(); + QListIterator<int> i(rows); + while (i.hasNext()) { + parent = m_model->index(i.next(), col, parent); + if (!parent.isValid()) + qFatal("%s: parent must be valid", Q_FUNC_INFO); + } + return parent; } -ModelInsertCommand::ModelInsertCommand(DynamicTreeModel *model, QObject *parent ) - : ModelChangeCommand(model, parent) +ModelInsertCommand::ModelInsertCommand(DynamicTreeModel *model, QObject *parent) : + ModelChangeCommand(model, parent) { - } void ModelInsertCommand::doCommand() { - QModelIndex parent = findIndex(m_rowNumbers); - m_model->beginInsertRows(parent, m_startRow, m_endRow); - qint64 parentId = parent.internalId(); - for (int row = m_startRow; row <= m_endRow; row++) - { - for(int col = 0; col < m_numCols; col++ ) - { - if (m_model->m_childItems[parentId].size() <= col) - { - m_model->m_childItems[parentId].append(QList<qint64>()); - } + QModelIndex parent = findIndex(m_rowNumbers); + m_model->beginInsertRows(parent, m_startRow, m_endRow); + qint64 parentId = parent.internalId(); + for (int row = m_startRow; row <= m_endRow; row++) { + for (int col = 0; col < m_numCols; col++) { + if (m_model->m_childItems[parentId].size() <= col) + m_model->m_childItems[parentId].append(QList<qint64>()); // QString name = QUuid::createUuid().toString(); - qint64 id = m_model->newId(); - QString name = QString::number(id); - - m_model->m_items.insert(id, name); - m_model->m_childItems[parentId][col].insert(row, id); + qint64 id = m_model->newId(); + QString name = QString::number(id); + m_model->m_items.insert(id, name); + m_model->m_childItems[parentId][col].insert(row, id); + } } - } - m_model->endInsertRows(); + m_model->endInsertRows(); } - -ModelMoveCommand::ModelMoveCommand(DynamicTreeModel *model, QObject *parent) - : ModelChangeCommand(model, parent) +ModelMoveCommand::ModelMoveCommand(DynamicTreeModel *model, QObject *parent) : + ModelChangeCommand(model, parent) { - } -bool ModelMoveCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow) + +bool ModelMoveCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, + const QModelIndex &destParent, int destRow) { - return m_model->beginMoveRows(srcParent, srcStart, srcEnd, destParent, destRow); + return m_model->beginMoveRows(srcParent, srcStart, srcEnd, destParent, destRow); } void ModelMoveCommand::doCommand() @@ -233,33 +218,26 @@ void ModelMoveCommand::doCommand() QModelIndex destParent = findIndex(m_destRowNumbers); if (!emitPreSignal(srcParent, m_startRow, m_endRow, destParent, m_destRow)) - { return; - } - for (int column = 0; column < m_numCols; ++column) - { - QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid(m_startRow, m_endRow - m_startRow + 1 ); + for (int column = 0; column < m_numCols; ++column) { + QList<qint64> l = m_model->m_childItems.value(srcParent.internalId())[column].mid( + m_startRow, m_endRow - m_startRow + 1); - for (int i = m_startRow; i <= m_endRow ; i++) - { + for (int i = m_startRow; i <= m_endRow; i++) m_model->m_childItems[srcParent.internalId()][column].removeAt(m_startRow); - } int d; - if (m_destRow < m_startRow) + if (m_destRow < m_startRow) { d = m_destRow; - else - { + } else { if (srcParent == destParent) d = m_destRow - (m_endRow - m_startRow + 1); else d = m_destRow - (m_endRow - m_startRow) + 1; } - foreach(const qint64 id, l) - { + foreach (const qint64 id, l) m_model->m_childItems[destParent.internalId()][column].insert(d++, id); - } } emitPostSignal(); @@ -270,18 +248,17 @@ void ModelMoveCommand::emitPostSignal() m_model->endMoveRows(); } -ModelResetCommand::ModelResetCommand(DynamicTreeModel* model, QObject* parent) - : ModelMoveCommand(model, parent) +ModelResetCommand::ModelResetCommand(DynamicTreeModel *model, QObject *parent) : + ModelMoveCommand(model, parent) { - } ModelResetCommand::~ModelResetCommand() { - } -bool ModelResetCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow) +bool ModelResetCommand::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, + const QModelIndex &destParent, int destRow) { Q_UNUSED(srcParent); Q_UNUSED(srcStart); @@ -298,18 +275,17 @@ void ModelResetCommand::emitPostSignal() m_model->endResetModel(); } -ModelResetCommandFixed::ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent) - : ModelMoveCommand(model, parent) +ModelResetCommandFixed::ModelResetCommandFixed(DynamicTreeModel *model, QObject *parent) : + ModelMoveCommand(model, parent) { - } ModelResetCommandFixed::~ModelResetCommandFixed() { - } -bool ModelResetCommandFixed::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow) +bool ModelResetCommandFixed::emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, + const QModelIndex &destParent, int destRow) { Q_UNUSED(srcParent); Q_UNUSED(srcStart); @@ -326,10 +302,10 @@ void ModelResetCommandFixed::emitPostSignal() m_model->endResetModel(); } -ModelChangeChildrenLayoutsCommand::ModelChangeChildrenLayoutsCommand(DynamicTreeModel* model, QObject* parent) - : ModelChangeCommand(model, parent) +ModelChangeChildrenLayoutsCommand::ModelChangeChildrenLayoutsCommand(DynamicTreeModel *model, + QObject *parent) : + ModelChangeCommand(model, parent) { - } void ModelChangeChildrenLayoutsCommand::doCommand() @@ -346,17 +322,16 @@ void ModelChangeChildrenLayoutsCommand::doCommand() int rowSize1 = -1; int rowSize2 = -1; - for (int column = 0; column < m_numCols; ++column) - { + for (int column = 0; column < m_numCols; ++column) { { - QList<qint64> &l = m_model->m_childItems[parent1.internalId()][column]; - rowSize1 = l.size(); - l.prepend(l.takeLast()); + QList<qint64> &l = m_model->m_childItems[parent1.internalId()][column]; + rowSize1 = l.size(); + l.prepend(l.takeLast()); } { - QList<qint64> &l = m_model->m_childItems[parent2.internalId()][column]; - rowSize2 = l.size(); - l.append(l.takeFirst()); + QList<qint64> &l = m_model->m_childItems[parent2.internalId()][column]; + rowSize2 = l.size(); + l.append(l.takeFirst()); } } @@ -373,15 +348,23 @@ void ModelChangeChildrenLayoutsCommand::doCommand() foreach (const QModelIndex &idx, persistent) { if (idx.parent() == parent1) { if (idx.row() == rowSize1 - 1) { - m_model->changePersistentIndex(idx, m_model->createIndex(0, idx.column(), idx.internalPointer())); + m_model->changePersistentIndex(idx, + m_model->createIndex(0, idx.column(), + idx.internalPointer())); } else { - m_model->changePersistentIndex(idx, m_model->createIndex(idx.row() + 1, idx.column(), idx.internalPointer())); + m_model->changePersistentIndex(idx, + m_model->createIndex(idx.row() + 1, idx.column(), + idx.internalPointer())); } } else if (idx.parent() == parent2) { if (idx.row() == 0) { - m_model->changePersistentIndex(idx, m_model->createIndex(rowSize2 - 1, idx.column(), idx.internalPointer())); + m_model->changePersistentIndex(idx, + m_model->createIndex(rowSize2 - 1, idx.column(), + idx.internalPointer())); } else { - m_model->changePersistentIndex(idx, m_model->createIndex(idx.row() - 1, idx.column(), idx.internalPointer())); + m_model->changePersistentIndex(idx, + m_model->createIndex(idx.row() - 1, idx.column(), + idx.internalPointer())); } } } diff --git a/tests/auto/other/modeltest/dynamictreemodel.h b/tests/auto/other/modeltest/dynamictreemodel.h index e31c4569fd..709751dd27 100644 --- a/tests/auto/other/modeltest/dynamictreemodel.h +++ b/tests/auto/other/modeltest/dynamictreemodel.h @@ -34,119 +34,142 @@ #include <QtCore/QHash> #include <QtCore/QList> - class DynamicTreeModel : public QAbstractItemModel { - Q_OBJECT + Q_OBJECT public: - DynamicTreeModel(QObject *parent = 0); + DynamicTreeModel(QObject *parent = 0); - QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; - QModelIndex parent(const QModelIndex &index) const; - int rowCount(const QModelIndex &index = QModelIndex()) const; - int columnCount(const QModelIndex &index = QModelIndex()) const; + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex &index) const; + int rowCount(const QModelIndex &index = QModelIndex()) const; + int columnCount(const QModelIndex &index = QModelIndex()) const; - QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; - void clear(); + void clear(); protected slots: - /** - Finds the parent id of the string with id @p searchId. + /** + Finds the parent id of the string with id @p searchId. - Returns -1 if not found. - */ - qint64 findParentId(qint64 searchId) const; + Returns -1 if not found. + */ + qint64 findParentId(qint64 searchId) const; private: - QHash<qint64, QString> m_items; - QHash<qint64, QList<QList<qint64> > > m_childItems; - qint64 nextId; - qint64 newId() { return nextId++; }; - - QModelIndex m_nextParentIndex; - int m_nextRow; - - int m_depth; - int maxDepth; - - friend class ModelInsertCommand; - friend class ModelMoveCommand; - friend class ModelResetCommand; - friend class ModelResetCommandFixed; - friend class ModelChangeChildrenLayoutsCommand; - + QHash<qint64, QString> m_items; + QHash<qint64, QList<QList<qint64> > > m_childItems; + qint64 nextId; + qint64 newId() + { + return nextId++; + } + + QModelIndex m_nextParentIndex; + int m_nextRow; + + int m_depth; + int maxDepth; + + friend class ModelInsertCommand; + friend class ModelMoveCommand; + friend class ModelResetCommand; + friend class ModelResetCommandFixed; + friend class ModelChangeChildrenLayoutsCommand; }; - class ModelChangeCommand : public QObject { - Q_OBJECT + Q_OBJECT public: - ModelChangeCommand( DynamicTreeModel *model, QObject *parent = 0 ); + ModelChangeCommand(DynamicTreeModel *model, QObject *parent = 0); - virtual ~ModelChangeCommand() {} + virtual ~ModelChangeCommand() + { + } - void setAncestorRowNumbers(QList<int> rowNumbers) { m_rowNumbers = rowNumbers; } + void setAncestorRowNumbers(QList<int> rowNumbers) + { + m_rowNumbers = rowNumbers; + } - QModelIndex findIndex(QList<int> rows); + QModelIndex findIndex(QList<int> rows); - void setStartRow(int row) { m_startRow = row; } + void setStartRow(int row) + { + m_startRow = row; + } - void setEndRow(int row) { m_endRow = row; } + void setEndRow(int row) + { + m_endRow = row; + } - void setNumCols(int cols) { m_numCols = cols; } + void setNumCols(int cols) + { + m_numCols = cols; + } - virtual void doCommand() = 0; + virtual void doCommand() = 0; protected: - DynamicTreeModel* m_model; - QList<int> m_rowNumbers; - int m_numCols; - int m_startRow; - int m_endRow; - + DynamicTreeModel *m_model; + QList<int> m_rowNumbers; + int m_numCols; + int m_startRow; + int m_endRow; }; -typedef QList<ModelChangeCommand*> ModelChangeCommandList; +typedef QList<ModelChangeCommand *> ModelChangeCommandList; class ModelInsertCommand : public ModelChangeCommand { - Q_OBJECT + Q_OBJECT public: - ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0 ); - virtual ~ModelInsertCommand() {} + ModelInsertCommand(DynamicTreeModel *model, QObject *parent = 0); + virtual ~ModelInsertCommand() + { + } - virtual void doCommand(); + virtual void doCommand(); }; - class ModelMoveCommand : public ModelChangeCommand { - Q_OBJECT + Q_OBJECT public: - ModelMoveCommand(DynamicTreeModel *model, QObject *parent); + ModelMoveCommand(DynamicTreeModel *model, QObject *parent); - virtual ~ModelMoveCommand() {} + virtual ~ModelMoveCommand() + { + } - virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow); + virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, + const QModelIndex &destParent, int destRow); - virtual void doCommand(); + virtual void doCommand(); - virtual void emitPostSignal(); + virtual void emitPostSignal(); - void setDestAncestors( QList<int> rows ) { m_destRowNumbers = rows; } + void setDestAncestors(QList<int> rows) + { + m_destRowNumbers = rows; + } - void setDestRow(int row) { m_destRow = row; } + void setDestRow(int row) + { + m_destRow = row; + } protected: - QList<int> m_destRowNumbers; - int m_destRow; + QList<int> m_destRowNumbers; + int m_destRow; }; /** @@ -154,15 +177,15 @@ protected: */ class ModelResetCommand : public ModelMoveCommand { - Q_OBJECT + Q_OBJECT public: - ModelResetCommand(DynamicTreeModel* model, QObject* parent = 0); + ModelResetCommand(DynamicTreeModel *model, QObject *parent = 0); - virtual ~ModelResetCommand(); - - virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow); - virtual void emitPostSignal(); + virtual ~ModelResetCommand(); + virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, + const QModelIndex &destParent, int destRow); + virtual void emitPostSignal(); }; /** @@ -170,32 +193,37 @@ public: */ class ModelResetCommandFixed : public ModelMoveCommand { - Q_OBJECT + Q_OBJECT public: - ModelResetCommandFixed(DynamicTreeModel* model, QObject* parent = 0); - - virtual ~ModelResetCommandFixed(); + ModelResetCommandFixed(DynamicTreeModel *model, QObject *parent = 0); - virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, const QModelIndex &destParent, int destRow); - virtual void emitPostSignal(); + virtual ~ModelResetCommandFixed(); + virtual bool emitPreSignal(const QModelIndex &srcParent, int srcStart, int srcEnd, + const QModelIndex &destParent, int destRow); + virtual void emitPostSignal(); }; class ModelChangeChildrenLayoutsCommand : public ModelChangeCommand { - Q_OBJECT + Q_OBJECT public: - ModelChangeChildrenLayoutsCommand(DynamicTreeModel *model, QObject *parent); + ModelChangeChildrenLayoutsCommand(DynamicTreeModel *model, QObject *parent); - virtual ~ModelChangeChildrenLayoutsCommand() {} + virtual ~ModelChangeChildrenLayoutsCommand() + { + } - virtual void doCommand(); + virtual void doCommand(); - void setSecondAncestorRowNumbers( QList<int> rows ) { m_secondRowNumbers = rows; } + void setSecondAncestorRowNumbers(QList<int> rows) + { + m_secondRowNumbers = rows; + } protected: - QList<int> m_secondRowNumbers; - int m_destRow; + QList<int> m_secondRowNumbers; + int m_destRow; }; #endif diff --git a/tests/auto/other/modeltest/modeltest.cpp b/tests/auto/other/modeltest/modeltest.cpp index 4da00bda4d..611f9e904b 100644 --- a/tests/auto/other/modeltest/modeltest.cpp +++ b/tests/auto/other/modeltest/modeltest.cpp @@ -34,60 +34,62 @@ /*! Connect to all of the models signals. Whenever anything happens recheck everything. */ -ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false ) +ModelTest::ModelTest(QAbstractItemModel *_model, QObject *parent) : QObject(parent), + model(_model), + fetchingMore(false) { if (!model) qFatal("%s: model must not be null", Q_FUNC_INFO); connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(columnsInserted(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(columnsRemoved(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), - this, SLOT(runAllTests()) ); - connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(runAllTests()) ); - connect(model, SIGNAL(layoutChanged()), this, SLOT(runAllTests()) ); - connect(model, SIGNAL(modelReset()), this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); + connect(model, SIGNAL(layoutAboutToBeChanged()), this, SLOT(runAllTests())); + connect(model, SIGNAL(layoutChanged()), this, SLOT(runAllTests())); + connect(model, SIGNAL(modelReset()), this, SLOT(runAllTests())); connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(runAllTests()) ); + this, SLOT(runAllTests())); // Special checks for changes connect(model, SIGNAL(layoutAboutToBeChanged()), - this, SLOT(layoutAboutToBeChanged()) ); + this, SLOT(layoutAboutToBeChanged())); connect(model, SIGNAL(layoutChanged()), - this, SLOT(layoutChanged()) ); + this, SLOT(layoutChanged())); connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), - this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int)) ); + this, SLOT(rowsAboutToBeInserted(QModelIndex,int,int))); connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), - this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int)) ); + this, SLOT(rowsAboutToBeRemoved(QModelIndex,int,int))); connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)), - this, SLOT(rowsInserted(QModelIndex,int,int)) ); + this, SLOT(rowsInserted(QModelIndex,int,int))); connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(rowsRemoved(QModelIndex,int,int)) ); + this, SLOT(rowsRemoved(QModelIndex,int,int))); connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(dataChanged(QModelIndex,QModelIndex)) ); + this, SLOT(dataChanged(QModelIndex,QModelIndex))); connect(model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), - this, SLOT(headerDataChanged(Qt::Orientation,int,int)) ); + this, SLOT(headerDataChanged(Qt::Orientation,int,int))); runAllTests(); } void ModelTest::runAllTests() { - if ( fetchingMore ) + if (fetchingMore) return; nonDestructiveBasicTest(); rowCount(); @@ -105,31 +107,31 @@ void ModelTest::runAllTests() void ModelTest::nonDestructiveBasicTest() { QVERIFY(!model->buddy(QModelIndex()).isValid()); - model->canFetchMore ( QModelIndex() ); - QVERIFY( model->columnCount ( QModelIndex() ) >= 0 ); + model->canFetchMore(QModelIndex()); + QVERIFY(model->columnCount(QModelIndex()) >= 0); QCOMPARE(model->data(QModelIndex()), QVariant()); fetchingMore = true; - model->fetchMore ( QModelIndex() ); + model->fetchMore(QModelIndex()); fetchingMore = false; - Qt::ItemFlags flags = model->flags ( QModelIndex() ); - QVERIFY( flags == Qt::ItemIsDropEnabled || flags == 0 ); - model->hasChildren ( QModelIndex() ); - model->hasIndex ( 0, 0 ); - model->headerData ( 0, Qt::Horizontal ); - model->index ( 0, 0 ); - model->itemData ( QModelIndex() ); + Qt::ItemFlags flags = model->flags(QModelIndex()); + QVERIFY(flags == Qt::ItemIsDropEnabled || flags == 0); + model->hasChildren(QModelIndex()); + model->hasIndex(0, 0); + model->headerData(0, Qt::Horizontal); + model->index(0, 0); + model->itemData(QModelIndex()); QVariant cache; - model->match ( QModelIndex(), -1, cache ); + model->match(QModelIndex(), -1, cache); model->mimeTypes(); QVERIFY(!model->parent(QModelIndex()).isValid()); - QVERIFY( model->rowCount() >= 0 ); + QVERIFY(model->rowCount() >= 0); QVariant variant; - model->setData ( QModelIndex(), variant, -1 ); - model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); - model->setHeaderData ( 999999, Qt::Horizontal, QVariant() ); + model->setData(QModelIndex(), variant, -1); + model->setHeaderData(-1, Qt::Horizontal, QVariant()); + model->setHeaderData(999999, Qt::Horizontal, QVariant()); QMap<int, QVariant> roles; - model->sibling ( 0, 0, QModelIndex() ); - model->span ( QModelIndex() ); + model->sibling(0, 0, QModelIndex()); + model->span(QModelIndex()); model->supportedDropActions(); } @@ -142,19 +144,19 @@ void ModelTest::rowCount() { // qDebug() << "rc"; // check top row - QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); - int rows = model->rowCount ( topIndex ); - QVERIFY( rows >= 0 ); - if ( rows > 0 ) - QVERIFY( model->hasChildren ( topIndex ) ); - - QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex ); - if ( secondLevelIndex.isValid() ) { // not the top level + QModelIndex topIndex = model->index(0, 0, QModelIndex()); + int rows = model->rowCount(topIndex); + QVERIFY(rows >= 0); + if (rows > 0) + QVERIFY(model->hasChildren(topIndex)); + + QModelIndex secondLevelIndex = model->index(0, 0, topIndex); + if (secondLevelIndex.isValid()) { // not the top level // check a row count where parent is valid - rows = model->rowCount ( secondLevelIndex ); - QVERIFY( rows >= 0 ); - if ( rows > 0 ) - QVERIFY( model->hasChildren ( secondLevelIndex ) ); + rows = model->rowCount(secondLevelIndex); + QVERIFY(rows >= 0); + if (rows > 0) + QVERIFY(model->hasChildren(secondLevelIndex)); } // The models rowCount() is tested more extensively in checkChildren(), @@ -167,13 +169,13 @@ void ModelTest::rowCount() void ModelTest::columnCount() { // check top row - QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); - QVERIFY( model->columnCount ( topIndex ) >= 0 ); + QModelIndex topIndex = model->index(0, 0, QModelIndex()); + QVERIFY(model->columnCount(topIndex) >= 0); // check a column count where parent is valid - QModelIndex childIndex = model->index ( 0, 0, topIndex ); - if ( childIndex.isValid() ) - QVERIFY( model->columnCount ( childIndex ) >= 0 ); + QModelIndex childIndex = model->index(0, 0, topIndex); + if (childIndex.isValid()) + QVERIFY(model->columnCount(childIndex) >= 0); // columnCount() is tested more extensively in checkChildren(), // but this catches the big mistakes @@ -186,19 +188,19 @@ void ModelTest::hasIndex() { // qDebug() << "hi"; // Make sure that invalid values returns an invalid index - QVERIFY( !model->hasIndex ( -2, -2 ) ); - QVERIFY( !model->hasIndex ( -2, 0 ) ); - QVERIFY( !model->hasIndex ( 0, -2 ) ); + QVERIFY(!model->hasIndex(-2, -2)); + QVERIFY(!model->hasIndex(-2, 0)); + QVERIFY(!model->hasIndex(0, -2)); int rows = model->rowCount(); int columns = model->columnCount(); // check out of bounds - QVERIFY( !model->hasIndex ( rows, columns ) ); - QVERIFY( !model->hasIndex ( rows + 1, columns + 1 ) ); + QVERIFY(!model->hasIndex(rows, columns)); + QVERIFY(!model->hasIndex(rows + 1, columns + 1)); - if ( rows > 0 ) - QVERIFY( model->hasIndex ( 0, 0 ) ); + if (rows > 0) + QVERIFY(model->hasIndex(0, 0)); // hasIndex() is tested more extensively in checkChildren(), // but this catches the big mistakes @@ -218,7 +220,7 @@ void ModelTest::index() int rows = model->rowCount(); int columns = model->columnCount(); - if ( rows == 0 ) + if (rows == 0) return; // Catch off by one errors @@ -226,8 +228,8 @@ void ModelTest::index() QVERIFY(model->index(0, 0).isValid()); // Make sure that the same index is *always* returned - QModelIndex a = model->index ( 0, 0 ); - QModelIndex b = model->index ( 0, 0 ); + QModelIndex a = model->index(0, 0); + QModelIndex b = model->index(0, 0); QCOMPARE(a, b); // index() is tested more extensively in checkChildren(), @@ -244,7 +246,7 @@ void ModelTest::parent() // when asked for the parent of an invalid index. QVERIFY(!model->parent(QModelIndex()).isValid()); - if ( model->rowCount() == 0 ) + if (model->rowCount() == 0) return; // Column 0 | Column 1 | @@ -254,29 +256,29 @@ void ModelTest::parent() // Common error test #1, make sure that a top level index has a parent // that is a invalid QModelIndex. - QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); + QModelIndex topIndex = model->index(0, 0, QModelIndex()); QVERIFY(!model->parent(topIndex).isValid()); // Common error test #2, make sure that a second level index has a parent // that is the first level index. - if ( model->rowCount ( topIndex ) > 0 ) { - QModelIndex childIndex = model->index ( 0, 0, topIndex ); + if (model->rowCount(topIndex) > 0) { + QModelIndex childIndex = model->index(0, 0, topIndex); QCOMPARE(model->parent(childIndex), topIndex); } // Common error test #3, the second column should NOT have the same children // as the first column in a row. // Usually the second column shouldn't have children. - QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() ); - if ( model->rowCount ( topIndex1 ) > 0 ) { - QModelIndex childIndex = model->index ( 0, 0, topIndex ); - QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 ); - QVERIFY( childIndex != childIndex1 ); + QModelIndex topIndex1 = model->index(0, 1, QModelIndex()); + if (model->rowCount(topIndex1) > 0) { + QModelIndex childIndex = model->index(0, 0, topIndex); + QModelIndex childIndex1 = model->index(0, 0, topIndex1); + QVERIFY(childIndex != childIndex1); } // Full test, walk n levels deep through the model making sure that all // parent's children correctly specify their parent. - checkChildren ( QModelIndex() ); + checkChildren(QModelIndex()); } /*! @@ -293,73 +295,75 @@ void ModelTest::parent() found the basic bugs because it is easier to figure out the problem in those tests then this one. */ -void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) +void ModelTest::checkChildren(const QModelIndex &parent, int currentDepth) { // First just try walking back up the tree. QModelIndex p = parent; - while ( p.isValid() ) + while (p.isValid()) p = p.parent(); // For models that are dynamically populated - if ( model->canFetchMore ( parent ) ) { + if (model->canFetchMore(parent)) { fetchingMore = true; - model->fetchMore ( parent ); + model->fetchMore(parent); fetchingMore = false; } - int rows = model->rowCount ( parent ); - int columns = model->columnCount ( parent ); + int rows = model->rowCount(parent); + int columns = model->columnCount(parent); - if ( rows > 0 ) - QVERIFY( model->hasChildren ( parent ) ); + if (rows > 0) + QVERIFY(model->hasChildren(parent)); // Some further testing against rows(), columns(), and hasChildren() - QVERIFY( rows >= 0 ); - QVERIFY( columns >= 0 ); - if ( rows > 0 ) - QVERIFY( model->hasChildren ( parent ) ); + QVERIFY(rows >= 0); + QVERIFY(columns >= 0); + if (rows > 0) + QVERIFY(model->hasChildren(parent)); //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows // << "columns:" << columns << "parent column:" << parent.column(); - const QModelIndex topLeftChild = model->index( 0, 0, parent ); + const QModelIndex topLeftChild = model->index(0, 0, parent); - QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) ); - for ( int r = 0; r < rows; ++r ) { - if ( model->canFetchMore ( parent ) ) { + QVERIFY(!model->hasIndex(rows + 1, 0, parent)); + for (int r = 0; r < rows; ++r) { + if (model->canFetchMore(parent)) { fetchingMore = true; - model->fetchMore ( parent ); + model->fetchMore(parent); fetchingMore = false; } - QVERIFY( !model->hasIndex ( r, columns + 1, parent ) ); - for ( int c = 0; c < columns; ++c ) { - QVERIFY( model->hasIndex ( r, c, parent ) ); - QModelIndex index = model->index ( r, c, parent ); + QVERIFY(!model->hasIndex(r, columns + 1, parent)); + for (int c = 0; c < columns; ++c) { + QVERIFY(model->hasIndex(r, c, parent)); + QModelIndex index = model->index(r, c, parent); // rowCount() and columnCount() said that it existed... + if (!index.isValid()) + qWarning() << "Got invalid index at row=" << r << "col=" << c << "parent=" << parent; QVERIFY(index.isValid()); // index() should always return the same index when called twice in a row - QModelIndex modifiedIndex = model->index ( r, c, parent ); + QModelIndex modifiedIndex = model->index(r, c, parent); QCOMPARE(index, modifiedIndex); // Make sure we get the same index if we request it twice in a row - QModelIndex a = model->index ( r, c, parent ); - QModelIndex b = model->index ( r, c, parent ); + QModelIndex a = model->index(r, c, parent); + QModelIndex b = model->index(r, c, parent); QCOMPARE(a, b); { - const QModelIndex sibling = model->sibling( r, c, topLeftChild ); + const QModelIndex sibling = model->sibling(r, c, topLeftChild); QCOMPARE(index, sibling); } { - const QModelIndex sibling = topLeftChild.sibling( r, c ); + const QModelIndex sibling = topLeftChild.sibling(r, c); QCOMPARE(index, sibling); } // Some basic checking on the index that is returned QCOMPARE(index.model(), model); - QCOMPARE( index.row(), r ); - QCOMPARE( index.column(), c ); + QCOMPARE(index.row(), r); + QCOMPARE(index.column(), c); // While you can technically return a QVariant usually this is a sign // of a bug in data(). Disable if this really is ok in your model. // QVERIFY( model->data ( index, Qt::DisplayRole ).isValid() ); @@ -377,16 +381,16 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) } // Check that we can get back our real parent. - QCOMPARE( model->parent ( index ), parent ); + QCOMPARE(model->parent(index), parent); // recursively go down the children - if ( model->hasChildren ( index ) && currentDepth < 10 ) { + if (model->hasChildren(index) && currentDepth < 10) { //qDebug() << r << c << "has children" << model->rowCount(index); - checkChildren ( index, ++currentDepth ); + checkChildren(index, ++currentDepth); }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/ // make sure that after testing the children that the index doesn't change. - QModelIndex newerIndex = model->index ( r, c, parent ); + QModelIndex newerIndex = model->index(r, c, parent); QCOMPARE(index, newerIndex); } } @@ -398,68 +402,61 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth ) void ModelTest::data() { // Invalid index should return an invalid qvariant - QVERIFY( !model->data ( QModelIndex() ).isValid() ); + QVERIFY(!model->data(QModelIndex()).isValid()); - if ( model->rowCount() == 0 ) + if (model->rowCount() == 0) return; // A valid index should have a valid QVariant data - QVERIFY( model->index ( 0, 0 ).isValid() ); + QVERIFY(model->index(0, 0).isValid()); // shouldn't be able to set data on an invalid index - QVERIFY( !model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) ); + QVERIFY(!model->setData(QModelIndex(), QLatin1String("foo"), Qt::DisplayRole)); // General Purpose roles that should return a QString - QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole ); - if ( variant.isValid() ) { - QVERIFY( variant.canConvert<QString>() ); - } - variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); - if ( variant.isValid() ) { - QVERIFY( variant.canConvert<QString>() ); - } - variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); - if ( variant.isValid() ) { - QVERIFY( variant.canConvert<QString>() ); - } + QVariant variant = model->data(model->index(0, 0), Qt::ToolTipRole); + if (variant.isValid()) + QVERIFY(variant.canConvert<QString>()); + variant = model->data(model->index(0, 0), Qt::StatusTipRole); + if (variant.isValid()) + QVERIFY(variant.canConvert<QString>()); + variant = model->data(model->index(0, 0), Qt::WhatsThisRole); + if (variant.isValid()) + QVERIFY(variant.canConvert<QString>()); // General Purpose roles that should return a QSize - variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); - if ( variant.isValid() ) { - QVERIFY( variant.canConvert<QSize>() ); - } + variant = model->data(model->index(0, 0), Qt::SizeHintRole); + if (variant.isValid()) + QVERIFY(variant.canConvert<QSize>()); // General Purpose roles that should return a QFont - QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole ); - if ( fontVariant.isValid() ) { - QVERIFY( fontVariant.canConvert<QFont>() ); - } + QVariant fontVariant = model->data(model->index(0, 0), Qt::FontRole); + if (fontVariant.isValid()) + QVERIFY(fontVariant.canConvert<QFont>()); // Check that the alignment is one we know about - QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole ); - if ( textAlignmentVariant.isValid() ) { + QVariant textAlignmentVariant = model->data(model->index(0, 0), Qt::TextAlignmentRole); + if (textAlignmentVariant.isValid()) { Qt::Alignment alignment = textAlignmentVariant.value<Qt::Alignment>(); - QCOMPARE( alignment, ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) ); + QCOMPARE(alignment, (alignment & (Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask))); } // General Purpose roles that should return a QColor - QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); - if ( colorVariant.isValid() ) { - QVERIFY( colorVariant.canConvert<QColor>() ); - } + QVariant colorVariant = model->data(model->index(0, 0), Qt::BackgroundColorRole); + if (colorVariant.isValid()) + QVERIFY(colorVariant.canConvert<QColor>()); - colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); - if ( colorVariant.isValid() ) { - QVERIFY( colorVariant.canConvert<QColor>() ); - } + colorVariant = model->data(model->index(0, 0), Qt::TextColorRole); + if (colorVariant.isValid()) + QVERIFY(colorVariant.canConvert<QColor>()); // Check that the "check state" is one we know about. - QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole ); - if ( checkStateVariant.isValid() ) { + QVariant checkStateVariant = model->data(model->index(0, 0), Qt::CheckStateRole); + if (checkStateVariant.isValid()) { int state = checkStateVariant.toInt(); - QVERIFY( state == Qt::Unchecked || - state == Qt::PartiallyChecked || - state == Qt::Checked ); + QVERIFY(state == Qt::Unchecked + || state == Qt::PartiallyChecked + || state == Qt::Checked); } } @@ -468,7 +465,7 @@ void ModelTest::data() \sa rowsInserted() */ -void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int /* end */) +void ModelTest::rowsAboutToBeInserted(const QModelIndex &parent, int start, int /* end */) { // Q_UNUSED(end); // qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).toString() @@ -476,10 +473,10 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) ); Changing c; c.parent = parent; - c.oldSize = model->rowCount ( parent ); - c.last = model->data ( model->index ( start - 1, 0, parent ) ); - c.next = model->data ( model->index ( start, 0, parent ) ); - insert.push ( c ); + c.oldSize = model->rowCount(parent); + c.last = model->data(model->index(start - 1, 0, parent)); + c.next = model->data(model->index(start, 0, parent)); + insert.push(c); } /*! @@ -487,10 +484,10 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in \sa rowsAboutToBeInserted() */ -void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) +void ModelTest::rowsInserted(const QModelIndex &parent, int start, int end) { Changing c = insert.pop(); - QCOMPARE(c.parent, parent); + QCOMPARE(parent, c.parent); // qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize // << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent ); @@ -500,30 +497,30 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) // } // qDebug(); - QCOMPARE(c.oldSize + (end - start + 1), model->rowCount(parent)); - QCOMPARE(c.last, model->data(model->index(start - 1, 0, c.parent))); + QCOMPARE(model->rowCount(parent), c.oldSize + (end - start + 1)); + QCOMPARE(model->data(model->index(start - 1, 0, c.parent)), c.last); if (c.next != model->data(model->index(end + 1, 0, c.parent))) { qDebug() << start << end; - for (int i=0; i < model->rowCount(); ++i) + for (int i = 0; i < model->rowCount(); ++i) qDebug() << model->index(i, 0).data().toString(); qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); } - QCOMPARE(c.next, model->data(model->index(end + 1, 0, c.parent))); + QCOMPARE(model->data(model->index(end + 1, 0, c.parent)), c.next); } void ModelTest::layoutAboutToBeChanged() { - for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i ) - changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) ); + for (int i = 0; i < qBound(0, model->rowCount(), 100); ++i) + changing.append(QPersistentModelIndex(model->index(i, 0))); } void ModelTest::layoutChanged() { - for ( int i = 0; i < changing.count(); ++i ) { + for (int i = 0; i < changing.count(); ++i) { QPersistentModelIndex p = changing[i]; - QCOMPARE(QModelIndex(p), model->index(p.row(), p.column(), p.parent())); + QCOMPARE(model->index(p.row(), p.column(), p.parent()), QModelIndex(p)); } changing.clear(); } @@ -533,15 +530,15 @@ void ModelTest::layoutChanged() \sa rowsRemoved() */ -void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end ) +void ModelTest::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) { -qDebug() << "ratbr" << parent << start << end; + qDebug() << "ratbr" << parent << start << end; Changing c; c.parent = parent; - c.oldSize = model->rowCount ( parent ); - c.last = model->data ( model->index ( start - 1, 0, parent ) ); - c.next = model->data ( model->index ( end + 1, 0, parent ) ); - remove.push ( c ); + c.oldSize = model->rowCount(parent); + c.last = model->data(model->index(start - 1, 0, parent)); + c.next = model->data(model->index(end + 1, 0, parent)); + remove.push(c); } /*! @@ -549,14 +546,14 @@ qDebug() << "ratbr" << parent << start << end; \sa rowsAboutToBeRemoved() */ -void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end ) +void ModelTest::rowsRemoved(const QModelIndex &parent, int start, int end) { - qDebug() << "rr" << parent << start << end; + qDebug() << "rr" << parent << start << end; Changing c = remove.pop(); - QCOMPARE(c.parent, parent); - QCOMPARE(c.oldSize - (end - start + 1), model->rowCount(parent)); - QCOMPARE(c.last, model->data(model->index(start - 1, 0, c.parent))); - QCOMPARE(c.next, model->data(model->index(start, 0, c.parent))); + QCOMPARE(parent, c.parent); + QCOMPARE(model->rowCount(parent), c.oldSize - (end - start + 1)); + QCOMPARE(model->data(model->index(start - 1, 0, c.parent)), c.last); + QCOMPARE(model->data(model->index(start, 0, c.parent)), c.next); } void ModelTest::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) @@ -582,4 +579,3 @@ void ModelTest::headerDataChanged(Qt::Orientation orientation, int start, int en QVERIFY(start < itemCount); QVERIFY(end < itemCount); } - diff --git a/tests/auto/other/modeltest/modeltest.h b/tests/auto/other/modeltest/modeltest.h index 735a422729..4676bf4434 100644 --- a/tests/auto/other/modeltest/modeltest.h +++ b/tests/auto/other/modeltest/modeltest.h @@ -26,7 +26,6 @@ ** ****************************************************************************/ - #ifndef MODELTEST_H #define MODELTEST_H @@ -36,48 +35,48 @@ class ModelTest : public QObject { - Q_OBJECT + Q_OBJECT public: - ModelTest( QAbstractItemModel *model, QObject *parent = 0 ); + ModelTest(QAbstractItemModel *model, QObject *parent = 0); private Q_SLOTS: - void nonDestructiveBasicTest(); - void rowCount(); - void columnCount(); - void hasIndex(); - void index(); - void parent(); - void data(); + void nonDestructiveBasicTest(); + void rowCount(); + void columnCount(); + void hasIndex(); + void index(); + void parent(); + void data(); protected Q_SLOTS: - void runAllTests(); - void layoutAboutToBeChanged(); - void layoutChanged(); - void rowsAboutToBeInserted( const QModelIndex &parent, int start, int end ); - void rowsInserted( const QModelIndex & parent, int start, int end ); - void rowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ); - void rowsRemoved( const QModelIndex & parent, int start, int end ); - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); - void headerDataChanged(Qt::Orientation orientation, int start, int end); + void runAllTests(); + void layoutAboutToBeChanged(); + void layoutChanged(); + void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end); + void rowsInserted(const QModelIndex &parent, int start, int end); + void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); + void rowsRemoved(const QModelIndex &parent, int start, int end); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); + void headerDataChanged(Qt::Orientation orientation, int start, int end); private: - void checkChildren( const QModelIndex &parent, int currentDepth = 0 ); + void checkChildren(const QModelIndex &parent, int currentDepth = 0); - QAbstractItemModel *model; + QAbstractItemModel *model; - struct Changing { - QModelIndex parent; - int oldSize; - QVariant last; - QVariant next; - }; - QStack<Changing> insert; - QStack<Changing> remove; + struct Changing { + QModelIndex parent; + int oldSize; + QVariant last; + QVariant next; + }; + QStack<Changing> insert; + QStack<Changing> remove; - bool fetchingMore; + bool fetchingMore; - QList<QPersistentModelIndex> changing; + QList<QPersistentModelIndex> changing; }; #endif diff --git a/tests/auto/other/modeltest/tst_modeltest.cpp b/tests/auto/other/modeltest/tst_modeltest.cpp index f81fefe9d1..e2d002844b 100644 --- a/tests/auto/other/modeltest/tst_modeltest.cpp +++ b/tests/auto/other/modeltest/tst_modeltest.cpp @@ -26,7 +26,6 @@ ** ****************************************************************************/ - #include <QtTest/QtTest> #include <QtGui/QtGui> #include <QtWidgets/QtWidgets> @@ -34,7 +33,6 @@ #include "modeltest.h" #include "dynamictreemodel.h" - class tst_ModelTest : public QObject { Q_OBJECT @@ -63,7 +61,7 @@ void tst_ModelTest::stringListModel() proxy.setSourceModel(&model); model.setStringList(QStringList() << "2" << "3" << "1"); - model.setStringList(QStringList() << "a" << "e" << "plop" << "b" << "c" ); + model.setStringList(QStringList() << "a" << "e" << "plop" << "b" << "c"); proxy.setDynamicSortFilter(true); proxy.setFilterRegExp(QRegExp("[^b]")); @@ -76,9 +74,8 @@ void tst_ModelTest::treeWidgetModel() ModelTest t1(widget.model()); QTreeWidgetItem *root = new QTreeWidgetItem(&widget, QStringList("root")); - for (int i = 0; i < 20; ++i) { + for (int i = 0; i < 20; ++i) new QTreeWidgetItem(root, QStringList(QString::number(i))); - } QTreeWidgetItem *remove = root->child(2); root->removeChild(remove); QTreeWidgetItem *parent = new QTreeWidgetItem(&widget, QStringList("parent")); @@ -90,10 +87,9 @@ void tst_ModelTest::treeWidgetModel() void tst_ModelTest::standardItemModel() { - QStandardItemModel model(10,10); + QStandardItemModel model(10, 10); QSortFilterProxyModel proxy; - ModelTest t1(&model); ModelTest t2(&proxy); @@ -105,8 +101,8 @@ void tst_ModelTest::standardItemModel() model.insertColumns(2, 5); model.removeColumns(4, 5); - model.insertRows(0,5, model.index(1,1)); - model.insertColumns(0,5, model.index(1,3)); + model.insertRows(0, 5, model.index(1, 1)); + model.insertColumns(0, 5, model.index(1, 3)); } void tst_ModelTest::testInsertThroughProxy() @@ -148,7 +144,9 @@ class AccessibleProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - AccessibleProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {} + AccessibleProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) + { + } QModelIndexList persistent() { @@ -160,14 +158,16 @@ class ObservingObject : public QObject { Q_OBJECT public: - ObservingObject(AccessibleProxyModel *proxy, QObject *parent = 0) - : QObject(parent) - , m_proxy(proxy) - , storePersistentFailureCount(0) - , checkPersistentFailureCount(0) + ObservingObject(AccessibleProxyModel *proxy, QObject *parent = 0) : + QObject(parent), + m_proxy(proxy), + storePersistentFailureCount(0), + checkPersistentFailureCount(0) { - connect(m_proxy, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(storePersistent())); - connect(m_proxy, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), SLOT(checkPersistent())); + connect(m_proxy, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)), + SLOT(storePersistent())); + connect(m_proxy, SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)), + SLOT(checkPersistent())); } public slots: @@ -195,7 +195,7 @@ public slots: void storePersistent() { // This method is called from rowsAboutToBeMoved. Persistent indexes should be valid - foreach(const QModelIndex &idx, m_persistentProxyIndexes) + foreach (const QModelIndex &idx, m_persistentProxyIndexes) if (!idx.isValid()) { qWarning("%s: persistentProxyIndexes contains invalid index", Q_FUNC_INFO); ++storePersistentFailureCount; @@ -233,7 +233,7 @@ public slots: } private: - AccessibleProxyModel *m_proxy; + AccessibleProxyModel *m_proxy; QList<QPersistentModelIndex> m_persistentSourceIndexes; QList<QPersistentModelIndex> m_persistentProxyIndexes; public: @@ -296,6 +296,5 @@ void tst_ModelTest::testResetThroughProxy() QCOMPARE(observer.checkPersistentFailureCount, 0); } - QTEST_MAIN(tst_ModelTest) #include "tst_modeltest.moc" diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index 3b696604b5..dc353d2090 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -30,6 +30,7 @@ #include <QtNetwork/QtNetwork> #include <QtCore/QDateTime> #include <QtCore/QTextStream> +#include <QtCore/QRandomGenerator> #include <QtCore/QStandardPaths> #include <QtCore/private/qiodevice_p.h> @@ -538,7 +539,7 @@ void tst_NetworkSelfTest::imapServer() void tst_NetworkSelfTest::httpServer() { QByteArray uniqueExtension = QByteArray::number((qulonglong)this) + - QByteArray::number((qulonglong)qrand()) + + QByteArray::number((qulonglong)QRandomGenerator::global()->generate()) + QByteArray::number(QDateTime::currentSecsSinceEpoch()); netChat(80, QList<Chat>() diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index d98bbe28b7..29fbffa541 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -352,7 +352,7 @@ void tst_QAccessibility::customWidget() { QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz"); widget->show(); - QTest::qWaitForWindowExposed(widget); + QVERIFY(QTest::qWaitForWindowExposed(widget)); // By default we create QAccessibleWidget QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); QVERIFY(iface != 0); @@ -368,7 +368,7 @@ void tst_QAccessibility::customWidget() QAccessible::installFactory(QtTestAccessibleWidgetIface::ifaceFactory); QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz"); widget->show(); - QTest::qWaitForWindowExposed(widget); + QVERIFY(QTest::qWaitForWindowExposed(widget)); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); QVERIFY(iface != 0); QVERIFY(iface->isValid()); @@ -1749,7 +1749,7 @@ void tst_QAccessibility::textEditTest() } edit.show(); - QTest::qWaitForWindowExposed(&edit); + QVERIFY(QTest::qWaitForWindowExposed(&edit)); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&edit); QCOMPARE(iface->text(QAccessible::Value), edit.toPlainText()); QVERIFY(iface->state().focusable); @@ -2161,7 +2161,7 @@ void tst_QAccessibility::lineEditTest() QLineEdit le(QStringLiteral("My characters have geometries."), toplevel); // characterRect() le.show(); - QTest::qWaitForWindowExposed(&le); + QVERIFY(QTest::qWaitForWindowExposed(&le)); QAccessibleInterface *iface(QAccessible::queryAccessibleInterface(&le)); QAccessibleTextInterface* textIface = iface->textInterface(); QVERIFY(textIface); @@ -3071,7 +3071,7 @@ void tst_QAccessibility::tableTest() tableView->resize(600,600); tableView->show(); - QTest::qWaitForWindowExposed(tableView); + QVERIFY(QTest::qWaitForWindowExposed(tableView)); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(tableView); QCOMPARE(verifyHierarchy(iface), 0); @@ -3445,7 +3445,7 @@ void tst_QAccessibility::dockWidgetTest() mw->resize(600,400); mw->show(); - QTest::qWaitForWindowExposed(mw); + QVERIFY(QTest::qWaitForWindowExposed(mw)); QAccessibleInterface *accMainWindow = QAccessible::queryAccessibleInterface(mw); // 4 children: menu bar, dock1, dock2, and central widget @@ -3628,7 +3628,7 @@ void tst_QAccessibility::labelTest() window->resize(320, 200); window->show(); - QTest::qWaitForWindowExposed(window); + QVERIFY(QTest::qWaitForWindowExposed(window)); #if defined(Q_OS_UNIX) QCoreApplication::processEvents(); #endif diff --git a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp index d40f9130ba..2575f22309 100644 --- a/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp +++ b/tests/auto/other/qaccessibilitylinux/tst_qaccessibilitylinux.cpp @@ -63,7 +63,7 @@ public: { layout()->addWidget(widget); widget->show(); - QTest::qWaitForWindowExposed(widget); + QVERIFY(QTest::qWaitForWindowExposed(widget)); } void clearChildren() @@ -182,7 +182,7 @@ void tst_QAccessibilityLinux::initTestCase() m_window = new AccessibleTestWindow(); m_window->show(); - QTest::qWaitForWindowExposed(m_window); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); registerDbus(); } diff --git a/tests/auto/other/qaccessibilitymac/qaccessibilitymac.pro b/tests/auto/other/qaccessibilitymac/qaccessibilitymac.pro index ceed81c914..e55757775e 100644 --- a/tests/auto/other/qaccessibilitymac/qaccessibilitymac.pro +++ b/tests/auto/other/qaccessibilitymac/qaccessibilitymac.pro @@ -1,6 +1,5 @@ CONFIG += testcase TARGET = tst_qaccessibilitymac -# LIBS += -framework Carbon QT += widgets testlib HEADERS += tst_qaccessibilitymac_helpers.h diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp index 13c933aa14..ba0562f049 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp @@ -49,7 +49,7 @@ public: { layout()->addWidget(widget); widget->show(); - QTest::qWaitForWindowExposed(widget); + QVERIFY(QTest::qWaitForWindowExposed(widget)); } void clearChildren() @@ -84,7 +84,7 @@ void tst_QAccessibilityMac::init() m_window->show(); m_window->resize(400, 400); - QTest::qWaitForWindowExposed(m_window); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); } void tst_QAccessibilityMac::cleanup() diff --git a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp index 2e2945ee5d..35441010f7 100644 --- a/tests/auto/other/qfocusevent/tst_qfocusevent.cpp +++ b/tests/auto/other/qfocusevent/tst_qfocusevent.cpp @@ -287,7 +287,7 @@ void tst_QFocusEvent::checkReason_Shortcut() void tst_QFocusEvent::checkReason_focusWidget() { // This test checks that a widget doesn't loose - // its focuswidget just because the focuswidget looses focus. + // its focuswidget just because the focuswidget loses focus. QWidget window1; QWidget frame1; QWidget frame2; |