Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-staging

* 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-staging: (84 commits)
  Reduce usage of Q_ASSERT in autotests.
  Fixed license header.
  Remove Q_ASSERT's from qsharedmemory autotest
  Remove Q_ASSERT's from QNetworkReply autotest
  Remove Q_ASSERT from QXmlStream autotest
  Remove Q_ASSERT's from QXmlStream autotest
  Remove Q_ASSERT from QItemModel autotest
  Remove Q_ASSERT's from QXmlStream autotest
  Remove Q_ASSERT from QVariant autotest
  Remove Q_ASSERT's from QTreeView autotest
  Remove Q_ASSERT from qtesselator autotest
  Remove unused function from qtessellator autotest
  Remove Q_ASSERT's from qreadwritelock autotest
  Remove Q_ASSERT's from QObject autotest
  Remove Q_ASSERT's from QObject autotest
  Remove Q_ASSERT's from QNetworkReply autotest
  Remove Q_ASSERT from qitemmodel autotest
  Remove Q_ASSERT's from QMutex autotest
  Remove Q_ASSERT from QMetaType autotest
  Remove Q_ASSERT's in qitemview autotest
  ...
This commit is contained in:
Qt Continuous Integration System 2011-05-18 11:03:00 +10:00
commit aabda9f5c6
73 changed files with 882 additions and 838 deletions

View File

@ -60,7 +60,7 @@ QT_USE_NAMESPACE
#include "3rdparty/memcheck.h" #include "3rdparty/memcheck.h"
#endif #endif
class tst_ExceptionSafetyObjects: public QObject class tst_ExceptionSafety_Objects: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -156,7 +156,7 @@ struct DirCreator : public AbstractTester
} }
}; };
void tst_ExceptionSafetyObjects::objects_data() void tst_ExceptionSafety_Objects::objects_data()
{ {
QTest::addColumn<AbstractTester *>("objectCreator"); QTest::addColumn<AbstractTester *>("objectCreator");
@ -164,12 +164,12 @@ void tst_ExceptionSafetyObjects::objects_data()
NEWROW(QObject); NEWROW(QObject);
NEWROW(QBuffer); NEWROW(QBuffer);
NEWROW(QFile); NEWROW(QFile);
NEWROW(QFSFileEngine);
NEWROW(QProcess); NEWROW(QProcess);
NEWROW(QSettings); NEWROW(QSettings);
NEWROW(QThread); NEWROW(QThread);
NEWROW(QThreadPool); NEWROW(QThreadPool);
NEWROW(QTranslator); NEWROW(QTranslator);
NEWROW(QFSFileEngine);
#define NEWROW2(T, CREATOR) QTest::newRow(#T) << static_cast<AbstractTester *>(new CREATOR) #define NEWROW2(T, CREATOR) QTest::newRow(#T) << static_cast<AbstractTester *>(new CREATOR)
NEWROW2(QBitArray, BitArrayCreator); NEWROW2(QBitArray, BitArrayCreator);
@ -177,7 +177,6 @@ void tst_ExceptionSafetyObjects::objects_data()
NEWROW2(QCryptographicHash, CryptographicHashCreator); NEWROW2(QCryptographicHash, CryptographicHashCreator);
NEWROW2(QDataStream, DataStreamCreator); NEWROW2(QDataStream, DataStreamCreator);
NEWROW2(QDir, DirCreator); NEWROW2(QDir, DirCreator);
} }
// create and destructs an object, and lets each and every allocation // create and destructs an object, and lets each and every allocation
@ -274,9 +273,9 @@ public:
} }
}; };
QtMsgHandler tst_ExceptionSafetyObjects::testMessageHandler; QtMsgHandler tst_ExceptionSafety_Objects::testMessageHandler;
void tst_ExceptionSafetyObjects::safeMessageHandler(QtMsgType type, const char *msg) void tst_ExceptionSafety_Objects::safeMessageHandler(QtMsgType type, const char *msg)
{ {
// this temporarily suspends OOM testing while handling a message // this temporarily suspends OOM testing while handling a message
int currentIndex = mallocFailIndex; int currentIndex = mallocFailIndex;
@ -301,7 +300,7 @@ void debugUnexpected()
(*defaultUnexpected)(); (*defaultUnexpected)();
} }
void tst_ExceptionSafetyObjects::initTestCase() void tst_ExceptionSafety_Objects::initTestCase()
{ {
// set handlers for bad exception cases, you might want to step in and breakpoint the default handlers too // set handlers for bad exception cases, you might want to step in and breakpoint the default handlers too
defaultTerminate = std::set_terminate(&debugTerminate); defaultTerminate = std::set_terminate(&debugTerminate);
@ -345,13 +344,21 @@ void tst_ExceptionSafetyObjects::initTestCase()
QCOMPARE(malloc2Failed, 1); QCOMPARE(malloc2Failed, 1);
} }
void tst_ExceptionSafetyObjects::cleanupTestCase() void tst_ExceptionSafety_Objects::cleanupTestCase()
{ {
qInstallMsgHandler(testMessageHandler); qInstallMsgHandler(testMessageHandler);
} }
void tst_ExceptionSafetyObjects::objects() void tst_ExceptionSafety_Objects::objects()
{ {
QLatin1String tag = QLatin1String(QTest::currentDataTag());
if (tag == QLatin1String("QFile")
|| tag == QLatin1String("QProcess")
|| tag == QLatin1String("QSettings")
|| tag == QLatin1String("QThread")
|| tag == QLatin1String("QThreadPool"))
QSKIP("This type of object is not currently strongly exception safe", SkipSingle);
QFETCH(AbstractTester *, objectCreator); QFETCH(AbstractTester *, objectCreator);
doOOMTest(*objectCreator, 0); doOOMTest(*objectCreator, 0);
@ -364,7 +371,8 @@ struct WidgetCreator : public AbstractTester
{ {
void operator()(QObject *parent) void operator()(QObject *parent)
{ {
Q_ASSERT(!parent || parent->isWidgetType()); if (parent && !parent->isWidgetType())
qFatal("%s: parent must be either null or a widget type", Q_FUNC_INFO);
QScopedPointer<T> ptr(parent ? new T(static_cast<QWidget *>(parent)) : new T); QScopedPointer<T> ptr(parent ? new T(static_cast<QWidget *>(parent)) : new T);
} }
}; };
@ -374,7 +382,8 @@ template <> struct WidgetCreator<QSizeGrip> : public AbstractTester
{ {
void operator()(QObject *parent) void operator()(QObject *parent)
{ {
Q_ASSERT(!parent || parent->isWidgetType()); if (parent && !parent->isWidgetType())
qFatal("%s: parent must be either null or a widget type", Q_FUNC_INFO);
QScopedPointer<QSizeGrip> ptr(new QSizeGrip(static_cast<QWidget *>(parent))); QScopedPointer<QSizeGrip> ptr(new QSizeGrip(static_cast<QWidget *>(parent)));
} }
}; };
@ -384,11 +393,12 @@ template <> struct WidgetCreator<QDesktopWidget> : public AbstractTester
{ {
void operator()(QObject *parent) void operator()(QObject *parent)
{ {
Q_ASSERT(!parent || parent->isWidgetType()); if (parent && !parent->isWidgetType())
qFatal("%s: parent must be either null or a widget type", Q_FUNC_INFO);
QScopedPointer<QDesktopWidget> ptr(new QDesktopWidget()); QScopedPointer<QDesktopWidget> ptr(new QDesktopWidget());
} }
}; };
void tst_ExceptionSafetyObjects::widgets_data() void tst_ExceptionSafety_Objects::widgets_data()
{ {
#ifdef Q_OS_SYMBIAN #ifdef Q_OS_SYMBIAN
// Initialise the S60 rasteriser, which crashes if started while out of memory // Initialise the S60 rasteriser, which crashes if started while out of memory
@ -405,23 +415,27 @@ void tst_ExceptionSafetyObjects::widgets_data()
NEWROW(QWidget); NEWROW(QWidget);
NEWROW(QButtonGroup); NEWROW(QButtonGroup);
NEWROW(QDesktopWidget);
NEWROW(QCheckBox); NEWROW(QCheckBox);
NEWROW(QColumnView);
NEWROW(QComboBox); NEWROW(QComboBox);
NEWROW(QCommandLinkButton); NEWROW(QCommandLinkButton);
NEWROW(QDateEdit); NEWROW(QDateEdit);
NEWROW(QDateTimeEdit); NEWROW(QDateTimeEdit);
NEWROW(QDesktopWidget);
NEWROW(QDial); NEWROW(QDial);
NEWROW(QDoubleSpinBox); NEWROW(QDoubleSpinBox);
NEWROW(QFocusFrame); NEWROW(QFocusFrame);
NEWROW(QFontComboBox); NEWROW(QFontComboBox);
NEWROW(QFrame); NEWROW(QFrame);
NEWROW(QGroupBox); NEWROW(QGroupBox);
NEWROW(QLCDNumber);
NEWROW(QLabel); NEWROW(QLabel);
NEWROW(QLCDNumber); NEWROW(QLCDNumber);
NEWROW(QLineEdit); NEWROW(QLineEdit);
NEWROW(QListView);
NEWROW(QListWidget);
NEWROW(QMainWindow);
NEWROW(QMenu); NEWROW(QMenu);
NEWROW(QMenuBar);
NEWROW(QPlainTextEdit); NEWROW(QPlainTextEdit);
NEWROW(QProgressBar); NEWROW(QProgressBar);
NEWROW(QPushButton); NEWROW(QPushButton);
@ -435,28 +449,58 @@ void tst_ExceptionSafetyObjects::widgets_data()
NEWROW(QStackedWidget); NEWROW(QStackedWidget);
NEWROW(QStatusBar); NEWROW(QStatusBar);
NEWROW(QTabBar); NEWROW(QTabBar);
NEWROW(QTableView);
NEWROW(QTableWidget);
NEWROW(QTabWidget); NEWROW(QTabWidget);
NEWROW(QTextBrowser); NEWROW(QTextBrowser);
NEWROW(QTextEdit); NEWROW(QTextEdit);
NEWROW(QTimeEdit); NEWROW(QTimeEdit);
NEWROW(QToolBar);
NEWROW(QToolBox); NEWROW(QToolBox);
NEWROW(QToolButton); NEWROW(QToolButton);
NEWROW(QStatusBar);
NEWROW(QToolBar);
NEWROW(QMenuBar);
NEWROW(QMainWindow);
NEWROW(QWorkspace);
NEWROW(QColumnView);
NEWROW(QListView);
NEWROW(QListWidget);
NEWROW(QTableView);
NEWROW(QTableWidget);
NEWROW(QTreeView); NEWROW(QTreeView);
NEWROW(QTreeWidget); NEWROW(QTreeWidget);
NEWROW(QWorkspace);
} }
void tst_ExceptionSafetyObjects::widgets() void tst_ExceptionSafety_Objects::widgets()
{ {
QLatin1String tag = QLatin1String(QTest::currentDataTag());
if (tag == QLatin1String("QColumnView")
|| tag == QLatin1String("QComboBox")
|| tag == QLatin1String("QCommandLinkButton")
|| tag == QLatin1String("QDateEdit")
|| tag == QLatin1String("QDateTimeEdit")
|| tag == QLatin1String("QDesktopWidget")
|| tag == QLatin1String("QDoubleSpinBox")
|| tag == QLatin1String("QFontComboBox")
|| tag == QLatin1String("QGroupBox")
|| tag == QLatin1String("QLineEdit")
|| tag == QLatin1String("QListView")
|| tag == QLatin1String("QListWidget")
|| tag == QLatin1String("QMainWindow")
|| tag == QLatin1String("QMenu")
|| tag == QLatin1String("QMenuBar")
|| tag == QLatin1String("QPlainTextEdit")
|| tag == QLatin1String("QProgressBar")
|| tag == QLatin1String("QPushButton")
|| tag == QLatin1String("QScrollArea")
|| tag == QLatin1String("QSpinBox")
|| tag == QLatin1String("QStackedWidget")
|| tag == QLatin1String("QStatusBar")
|| tag == QLatin1String("QTableView")
|| tag == QLatin1String("QTableWidget")
|| tag == QLatin1String("QTabWidget")
|| tag == QLatin1String("QTextBrowser")
|| tag == QLatin1String("QTextEdit")
|| tag == QLatin1String("QTimeEdit")
|| tag == QLatin1String("QToolBar")
|| tag == QLatin1String("QToolBox")
|| tag == QLatin1String("QTreeView")
|| tag == QLatin1String("QTreeWidget")
|| tag == QLatin1String("QWorkspace"))
QSKIP("This type of widget is not currently strongly exception safe", SkipSingle);
QFETCH(AbstractTester *, widgetCreator); QFETCH(AbstractTester *, widgetCreator);
doOOMTest(*widgetCreator, 0, 00000); doOOMTest(*widgetCreator, 0, 00000);
@ -547,7 +591,9 @@ struct IntegerMoveable
}; };
int IntegerMoveable::instanceCount = 0; int IntegerMoveable::instanceCount = 0;
QT_BEGIN_NAMESPACE
Q_DECLARE_TYPEINFO(IntegerMoveable, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(IntegerMoveable, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
template <typename T, template<typename> class Container> template <typename T, template<typename> class Container>
void containerInsertTest(QObject*) void containerInsertTest(QObject*)
@ -720,12 +766,12 @@ static void containerData()
QTest::newRow("erase moveable") << static_cast<TestFunction>(containerEraseTest<IntegerMoveable, Container>); QTest::newRow("erase moveable") << static_cast<TestFunction>(containerEraseTest<IntegerMoveable, Container>);
} }
void tst_ExceptionSafetyObjects::vector_data() void tst_ExceptionSafety_Objects::vector_data()
{ {
containerData<QVector>(); containerData<QVector>();
} }
void tst_ExceptionSafetyObjects::vector() void tst_ExceptionSafety_Objects::vector()
{ {
QFETCH(TestFunction, testFunction); QFETCH(TestFunction, testFunction);
@ -736,30 +782,30 @@ void tst_ExceptionSafetyObjects::vector()
doOOMTest(testFunction, 0); doOOMTest(testFunction, 0);
} }
void tst_ExceptionSafetyObjects::list_data() void tst_ExceptionSafety_Objects::list_data()
{ {
containerData<QList>(); containerData<QList>();
} }
void tst_ExceptionSafetyObjects::list() void tst_ExceptionSafety_Objects::list()
{ {
QFETCH(TestFunction, testFunction); QFETCH(TestFunction, testFunction);
doOOMTest(testFunction, 0); doOOMTest(testFunction, 0);
} }
void tst_ExceptionSafetyObjects::linkedList_data() void tst_ExceptionSafety_Objects::linkedList_data()
{ {
containerData<QLinkedList>(); containerData<QLinkedList>();
} }
void tst_ExceptionSafetyObjects::linkedList() void tst_ExceptionSafety_Objects::linkedList()
{ {
QFETCH(TestFunction, testFunction); QFETCH(TestFunction, testFunction);
doOOMTest(testFunction, 0); doOOMTest(testFunction, 0);
} }
QTEST_MAIN(tst_ExceptionSafetyObjects) QTEST_MAIN(tst_ExceptionSafety_Objects)
#include "tst_exceptionsafety_objects.moc" #include "tst_exceptionsafety_objects.moc"
#endif // QT_NO_EXCEPTIONS #endif // QT_NO_EXCEPTIONS

View File

@ -280,7 +280,7 @@ protected:
eventsPtr->canceled << g->gestureType(); eventsPtr->canceled << g->gestureType();
break; break;
default: default:
Q_ASSERT(false); qWarning() << "Unknown GestureState enum value:" << static_cast<int>(g->state());
} }
} }
} else if (event->type() == CustomEvent::EventType) { } else if (event->type() == CustomEvent::EventType) {
@ -823,7 +823,7 @@ public:
emit gestureCanceled(e->type(), g); emit gestureCanceled(e->type(), g);
break; break;
default: default:
Q_ASSERT(false); qWarning() << "Unknown GestureState enum value:" << static_cast<int>(g->state());
} }
} }
} else if (event->type() == CustomEvent::EventType) { } else if (event->type() == CustomEvent::EventType) {
@ -1518,17 +1518,20 @@ void tst_Gestures::autoCancelGestures()
{ {
class MockWidget : public GestureWidget { class MockWidget : public GestureWidget {
public: public:
MockWidget(const char *name) : GestureWidget(name) { } MockWidget(const char *name) : GestureWidget(name), badGestureEvents(0) { }
bool event(QEvent *event) bool event(QEvent *event)
{ {
if (event->type() == QEvent::Gesture) { if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event); QGestureEvent *ge = static_cast<QGestureEvent*>(event);
Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... if (ge->gestures().count() != 1)
++badGestureEvents; // event should contain exactly one gesture
ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
} }
return GestureWidget::event(event); return GestureWidget::event(event);
} }
int badGestureEvents;
}; };
const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer); const Qt::GestureType secondGesture = QGestureRecognizer::registerRecognizer(new CustomGestureRecognizer);
@ -1563,22 +1566,26 @@ void tst_Gestures::autoCancelGestures()
event.serial = CustomGesture::SerialFinishedThreshold; event.serial = CustomGesture::SerialFinishedThreshold;
QApplication::sendEvent(child, &event); QApplication::sendEvent(child, &event);
QCOMPARE(parent.events.all.count(), 2); QCOMPARE(parent.events.all.count(), 2);
QCOMPARE(parent.badGestureEvents, 0);
} }
void tst_Gestures::autoCancelGestures2() void tst_Gestures::autoCancelGestures2()
{ {
class MockItem : public GestureItem { class MockItem : public GestureItem {
public: public:
MockItem(const char *name) : GestureItem(name) { } MockItem(const char *name) : GestureItem(name), badGestureEvents(0) { }
bool event(QEvent *event) { bool event(QEvent *event) {
if (event->type() == QEvent::Gesture) { if (event->type() == QEvent::Gesture) {
QGestureEvent *ge = static_cast<QGestureEvent*>(event); QGestureEvent *ge = static_cast<QGestureEvent*>(event);
Q_ASSERT(ge->gestures().count() == 1); // can't use QCOMPARE here... if (ge->gestures().count() != 1)
++badGestureEvents; // event should contain exactly one gesture
ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext); ge->gestures().first()->setGestureCancelPolicy(QGesture::CancelAllInContext);
} }
return GestureItem::event(event); return GestureItem::event(event);
} }
int badGestureEvents;
}; };
const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer); const Qt::GestureType secondGesture = QGestureRecognizer ::registerRecognizer(new CustomGestureRecognizer);
@ -1614,6 +1621,7 @@ void tst_Gestures::autoCancelGestures2()
event.serial = CustomGesture::SerialFinishedThreshold; event.serial = CustomGesture::SerialFinishedThreshold;
scene.sendEvent(child, &event); scene.sendEvent(child, &event);
QCOMPARE(parent->events.all.count(), 2); QCOMPARE(parent->events.all.count(), 2);
QCOMPARE(parent->badGestureEvents, 0);
} }
void tst_Gestures::graphicsViewParentPropagation() void tst_Gestures::graphicsViewParentPropagation()

View File

@ -44,6 +44,7 @@
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QList> #include <QtCore/QList>
#include <QtCore/QTimer> #include <QtCore/QTimer>
#include <QtCore/QDebug>
DynamicTreeModel::DynamicTreeModel(QObject *parent) DynamicTreeModel::DynamicTreeModel(QObject *parent)
@ -66,9 +67,11 @@ QModelIndex DynamicTreeModel::index(int row, int column, const QModelIndex &pare
const qint64 grandParent = findParentId(parent.internalId()); const qint64 grandParent = findParentId(parent.internalId());
if (grandParent >= 0) { if (grandParent >= 0) {
QList<QList<qint64> > parentTable = m_childItems.value(grandParent); QList<QList<qint64> > parentTable = m_childItems.value(grandParent);
Q_ASSERT(parent.column() < parentTable.size()); 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()); QList<qint64> parentSiblings = parentTable.at(parent.column());
Q_ASSERT(parent.row() < parentSiblings.size()); if (parent.row() >= parentSiblings.size())
qFatal("%s: parent.row() must be less than parentSiblings.size()", Q_FUNC_INFO);
} }
if (childIdColumns.size() == 0) if (childIdColumns.size() == 0)
@ -189,7 +192,8 @@ QModelIndex ModelChangeCommand::findIndex(QList<int> rows)
while (i.hasNext()) while (i.hasNext())
{ {
parent = m_model->index(i.next(), col, parent); parent = m_model->index(i.next(), col, parent);
Q_ASSERT(parent.isValid()); if (!parent.isValid())
qFatal("%s: parent must be valid", Q_FUNC_INFO);
} }
return parent; return parent;
} }

View File

@ -45,8 +45,6 @@
#include "modeltest.h" #include "modeltest.h"
#include <QtTest/QtTest> #include <QtTest/QtTest>
#undef Q_ASSERT
#define Q_ASSERT QVERIFY
Q_DECLARE_METATYPE ( QModelIndex ) Q_DECLARE_METATYPE ( QModelIndex )
@ -55,7 +53,8 @@ Q_DECLARE_METATYPE ( QModelIndex )
*/ */
ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false ) ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false )
{ {
Q_ASSERT ( model ); if (!model)
qFatal("%s: model must not be null", Q_FUNC_INFO);
connect ( model, SIGNAL ( columnsAboutToBeInserted ( const QModelIndex &, int, int ) ), connect ( model, SIGNAL ( columnsAboutToBeInserted ( const QModelIndex &, int, int ) ),
this, SLOT ( runAllTests() ) ); this, SLOT ( runAllTests() ) );
@ -118,15 +117,15 @@ void ModelTest::runAllTests()
*/ */
void ModelTest::nonDestructiveBasicTest() void ModelTest::nonDestructiveBasicTest()
{ {
Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() ); QVERIFY( model->buddy ( QModelIndex() ) == QModelIndex() );
model->canFetchMore ( QModelIndex() ); model->canFetchMore ( QModelIndex() );
Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 ); QVERIFY( model->columnCount ( QModelIndex() ) >= 0 );
Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() ); QVERIFY( model->data ( QModelIndex() ) == QVariant() );
fetchingMore = true; fetchingMore = true;
model->fetchMore ( QModelIndex() ); model->fetchMore ( QModelIndex() );
fetchingMore = false; fetchingMore = false;
Qt::ItemFlags flags = model->flags ( QModelIndex() ); Qt::ItemFlags flags = model->flags ( QModelIndex() );
Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 ); QVERIFY( flags == Qt::ItemIsDropEnabled || flags == 0 );
model->hasChildren ( QModelIndex() ); model->hasChildren ( QModelIndex() );
model->hasIndex ( 0, 0 ); model->hasIndex ( 0, 0 );
model->headerData ( 0, Qt::Horizontal ); model->headerData ( 0, Qt::Horizontal );
@ -135,8 +134,8 @@ void ModelTest::nonDestructiveBasicTest()
QVariant cache; QVariant cache;
model->match ( QModelIndex(), -1, cache ); model->match ( QModelIndex(), -1, cache );
model->mimeTypes(); model->mimeTypes();
Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
Q_ASSERT ( model->rowCount() >= 0 ); QVERIFY( model->rowCount() >= 0 );
QVariant variant; QVariant variant;
model->setData ( QModelIndex(), variant, -1 ); model->setData ( QModelIndex(), variant, -1 );
model->setHeaderData ( -1, Qt::Horizontal, QVariant() ); model->setHeaderData ( -1, Qt::Horizontal, QVariant() );
@ -158,17 +157,17 @@ void ModelTest::rowCount()
// check top row // check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
int rows = model->rowCount ( topIndex ); int rows = model->rowCount ( topIndex );
Q_ASSERT ( rows >= 0 ); QVERIFY( rows >= 0 );
if ( rows > 0 ) if ( rows > 0 )
Q_ASSERT ( model->hasChildren ( topIndex ) == true ); QVERIFY( model->hasChildren ( topIndex ) );
QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex ); QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex );
if ( secondLevelIndex.isValid() ) { // not the top level if ( secondLevelIndex.isValid() ) { // not the top level
// check a row count where parent is valid // check a row count where parent is valid
rows = model->rowCount ( secondLevelIndex ); rows = model->rowCount ( secondLevelIndex );
Q_ASSERT ( rows >= 0 ); QVERIFY( rows >= 0 );
if ( rows > 0 ) if ( rows > 0 )
Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true ); QVERIFY( model->hasChildren ( secondLevelIndex ) );
} }
// The models rowCount() is tested more extensively in checkChildren(), // The models rowCount() is tested more extensively in checkChildren(),
@ -182,12 +181,12 @@ void ModelTest::columnCount()
{ {
// check top row // check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
Q_ASSERT ( model->columnCount ( topIndex ) >= 0 ); QVERIFY( model->columnCount ( topIndex ) >= 0 );
// check a column count where parent is valid // check a column count where parent is valid
QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex = model->index ( 0, 0, topIndex );
if ( childIndex.isValid() ) if ( childIndex.isValid() )
Q_ASSERT ( model->columnCount ( childIndex ) >= 0 ); QVERIFY( model->columnCount ( childIndex ) >= 0 );
// columnCount() is tested more extensively in checkChildren(), // columnCount() is tested more extensively in checkChildren(),
// but this catches the big mistakes // but this catches the big mistakes
@ -200,19 +199,19 @@ void ModelTest::hasIndex()
{ {
// qDebug() << "hi"; // qDebug() << "hi";
// Make sure that invalid values returns an invalid index // Make sure that invalid values returns an invalid index
Q_ASSERT ( model->hasIndex ( -2, -2 ) == false ); QVERIFY( !model->hasIndex ( -2, -2 ) );
Q_ASSERT ( model->hasIndex ( -2, 0 ) == false ); QVERIFY( !model->hasIndex ( -2, 0 ) );
Q_ASSERT ( model->hasIndex ( 0, -2 ) == false ); QVERIFY( !model->hasIndex ( 0, -2 ) );
int rows = model->rowCount(); int rows = model->rowCount();
int columns = model->columnCount(); int columns = model->columnCount();
// check out of bounds // check out of bounds
Q_ASSERT ( model->hasIndex ( rows, columns ) == false ); QVERIFY( !model->hasIndex ( rows, columns ) );
Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false ); QVERIFY( !model->hasIndex ( rows + 1, columns + 1 ) );
if ( rows > 0 ) if ( rows > 0 )
Q_ASSERT ( model->hasIndex ( 0, 0 ) == true ); QVERIFY( model->hasIndex ( 0, 0 ) );
// hasIndex() is tested more extensively in checkChildren(), // hasIndex() is tested more extensively in checkChildren(),
// but this catches the big mistakes // but this catches the big mistakes
@ -225,9 +224,9 @@ void ModelTest::index()
{ {
// qDebug() << "i"; // qDebug() << "i";
// Make sure that invalid values returns an invalid index // Make sure that invalid values returns an invalid index
Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() ); QVERIFY( model->index ( -2, -2 ) == QModelIndex() );
Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() ); QVERIFY( model->index ( -2, 0 ) == QModelIndex() );
Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() ); QVERIFY( model->index ( 0, -2 ) == QModelIndex() );
int rows = model->rowCount(); int rows = model->rowCount();
int columns = model->columnCount(); int columns = model->columnCount();
@ -236,13 +235,13 @@ void ModelTest::index()
return; return;
// Catch off by one errors // Catch off by one errors
Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() ); QVERIFY( model->index ( rows, columns ) == QModelIndex() );
Q_ASSERT ( model->index ( 0, 0 ).isValid() == true ); QVERIFY( model->index ( 0, 0 ).isValid() );
// Make sure that the same index is *always* returned // Make sure that the same index is *always* returned
QModelIndex a = model->index ( 0, 0 ); QModelIndex a = model->index ( 0, 0 );
QModelIndex b = model->index ( 0, 0 ); QModelIndex b = model->index ( 0, 0 );
Q_ASSERT ( a == b ); QVERIFY( a == b );
// index() is tested more extensively in checkChildren(), // index() is tested more extensively in checkChildren(),
// but this catches the big mistakes // but this catches the big mistakes
@ -256,7 +255,7 @@ void ModelTest::parent()
// qDebug() << "p"; // qDebug() << "p";
// Make sure the model wont crash and will return an invalid QModelIndex // Make sure the model wont crash and will return an invalid QModelIndex
// when asked for the parent of an invalid index. // when asked for the parent of an invalid index.
Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() ); QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
if ( model->rowCount() == 0 ) if ( model->rowCount() == 0 )
return; return;
@ -269,13 +268,13 @@ void ModelTest::parent()
// Common error test #1, make sure that a top level index has a parent // Common error test #1, make sure that a top level index has a parent
// that is a invalid QModelIndex. // that is a invalid QModelIndex.
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() ); QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
Q_ASSERT ( model->parent ( topIndex ) == QModelIndex() ); QVERIFY( model->parent ( topIndex ) == QModelIndex() );
// Common error test #2, make sure that a second level index has a parent // Common error test #2, make sure that a second level index has a parent
// that is the first level index. // that is the first level index.
if ( model->rowCount ( topIndex ) > 0 ) { if ( model->rowCount ( topIndex ) > 0 ) {
QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex = model->index ( 0, 0, topIndex );
Q_ASSERT ( model->parent ( childIndex ) == topIndex ); QVERIFY( model->parent ( childIndex ) == topIndex );
} }
// Common error test #3, the second column should NOT have the same children // Common error test #3, the second column should NOT have the same children
@ -285,7 +284,7 @@ void ModelTest::parent()
if ( model->rowCount ( topIndex1 ) > 0 ) { if ( model->rowCount ( topIndex1 ) > 0 ) {
QModelIndex childIndex = model->index ( 0, 0, topIndex ); QModelIndex childIndex = model->index ( 0, 0, topIndex );
QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 ); QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 );
Q_ASSERT ( childIndex != childIndex1 ); QVERIFY( childIndex != childIndex1 );
} }
// Full test, walk n levels deep through the model making sure that all // Full test, walk n levels deep through the model making sure that all
@ -325,47 +324,47 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
int columns = model->columnCount ( parent ); int columns = model->columnCount ( parent );
if ( rows > 0 ) if ( rows > 0 )
Q_ASSERT ( model->hasChildren ( parent ) ); QVERIFY( model->hasChildren ( parent ) );
// Some further testing against rows(), columns(), and hasChildren() // Some further testing against rows(), columns(), and hasChildren()
Q_ASSERT ( rows >= 0 ); QVERIFY( rows >= 0 );
Q_ASSERT ( columns >= 0 ); QVERIFY( columns >= 0 );
if ( rows > 0 ) if ( rows > 0 )
Q_ASSERT ( model->hasChildren ( parent ) == true ); QVERIFY( model->hasChildren ( parent ) );
//qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
// << "columns:" << columns << "parent column:" << parent.column(); // << "columns:" << columns << "parent column:" << parent.column();
Q_ASSERT ( model->hasIndex ( rows + 1, 0, parent ) == false ); QVERIFY( !model->hasIndex ( rows + 1, 0, parent ) );
for ( int r = 0; r < rows; ++r ) { for ( int r = 0; r < rows; ++r ) {
if ( model->canFetchMore ( parent ) ) { if ( model->canFetchMore ( parent ) ) {
fetchingMore = true; fetchingMore = true;
model->fetchMore ( parent ); model->fetchMore ( parent );
fetchingMore = false; fetchingMore = false;
} }
Q_ASSERT ( model->hasIndex ( r, columns + 1, parent ) == false ); QVERIFY( !model->hasIndex ( r, columns + 1, parent ) );
for ( int c = 0; c < columns; ++c ) { for ( int c = 0; c < columns; ++c ) {
Q_ASSERT ( model->hasIndex ( r, c, parent ) == true ); QVERIFY( model->hasIndex ( r, c, parent ) );
QModelIndex index = model->index ( r, c, parent ); QModelIndex index = model->index ( r, c, parent );
// rowCount() and columnCount() said that it existed... // rowCount() and columnCount() said that it existed...
Q_ASSERT ( index.isValid() == true ); QVERIFY( index.isValid() );
// index() should always return the same index when called twice in a row // 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 );
Q_ASSERT ( index == modifiedIndex ); QVERIFY( index == modifiedIndex );
// Make sure we get the same index if we request it twice in a row // Make sure we get the same index if we request it twice in a row
QModelIndex a = model->index ( r, c, parent ); QModelIndex a = model->index ( r, c, parent );
QModelIndex b = model->index ( r, c, parent ); QModelIndex b = model->index ( r, c, parent );
Q_ASSERT ( a == b ); QVERIFY( a == b );
// Some basic checking on the index that is returned // Some basic checking on the index that is returned
Q_ASSERT ( index.model() == model ); QVERIFY( index.model() == model );
Q_ASSERT ( index.row() == r ); QCOMPARE( index.row(), r );
Q_ASSERT ( index.column() == c ); QCOMPARE( index.column(), c );
// While you can technically return a QVariant usually this is a sign // While you can technically return a QVariant usually this is a sign
// of an bug in data() Disable if this really is ok in your model. // of a bug in data(). Disable if this really is ok in your model.
// Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true ); // QVERIFY( model->data ( index, Qt::DisplayRole ).isValid() );
// If the next test fails here is some somewhat useful debug you play with. // If the next test fails here is some somewhat useful debug you play with.
@ -380,8 +379,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
} }
// Check that we can get back our real parent. // Check that we can get back our real parent.
// qDebug() << model->parent ( index ) << parent ; QCOMPARE( model->parent ( index ), parent );
Q_ASSERT ( model->parent ( index ) == parent );
// recursively go down the children // recursively go down the children
if ( model->hasChildren ( index ) && currentDepth < 10 ) { if ( model->hasChildren ( index ) && currentDepth < 10 ) {
@ -391,7 +389,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
// make sure that after testing the children that the index doesn't change. // 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 );
Q_ASSERT ( index == newerIndex ); QVERIFY( index == newerIndex );
} }
} }
} }
@ -402,66 +400,66 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
void ModelTest::data() void ModelTest::data()
{ {
// Invalid index should return an invalid qvariant // Invalid index should return an invalid qvariant
Q_ASSERT ( !model->data ( QModelIndex() ).isValid() ); QVERIFY( !model->data ( QModelIndex() ).isValid() );
if ( model->rowCount() == 0 ) if ( model->rowCount() == 0 )
return; return;
// A valid index should have a valid QVariant data // A valid index should have a valid QVariant data
Q_ASSERT ( model->index ( 0, 0 ).isValid() ); QVERIFY( model->index ( 0, 0 ).isValid() );
// shouldn't be able to set data on an invalid index // shouldn't be able to set data on an invalid index
Q_ASSERT ( model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) == false ); QVERIFY( !model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) );
// General Purpose roles that should return a QString // General Purpose roles that should return a QString
QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole ); QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole );
if ( variant.isValid() ) { if ( variant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QString> ( variant ) ); QVERIFY( qVariantCanConvert<QString> ( variant ) );
} }
variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole ); variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole );
if ( variant.isValid() ) { if ( variant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QString> ( variant ) ); QVERIFY( qVariantCanConvert<QString> ( variant ) );
} }
variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole ); variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole );
if ( variant.isValid() ) { if ( variant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QString> ( variant ) ); QVERIFY( qVariantCanConvert<QString> ( variant ) );
} }
// General Purpose roles that should return a QSize // General Purpose roles that should return a QSize
variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole ); variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole );
if ( variant.isValid() ) { if ( variant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QSize> ( variant ) ); QVERIFY( qVariantCanConvert<QSize> ( variant ) );
} }
// General Purpose roles that should return a QFont // General Purpose roles that should return a QFont
QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole ); QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole );
if ( fontVariant.isValid() ) { if ( fontVariant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QFont> ( fontVariant ) ); QVERIFY( qVariantCanConvert<QFont> ( fontVariant ) );
} }
// Check that the alignment is one we know about // Check that the alignment is one we know about
QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole ); QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole );
if ( textAlignmentVariant.isValid() ) { if ( textAlignmentVariant.isValid() ) {
int alignment = textAlignmentVariant.toInt(); int alignment = textAlignmentVariant.toInt();
Q_ASSERT ( 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 // General Purpose roles that should return a QColor
QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole ); QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole );
if ( colorVariant.isValid() ) { if ( colorVariant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) ); QVERIFY( qVariantCanConvert<QColor> ( colorVariant ) );
} }
colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole ); colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole );
if ( colorVariant.isValid() ) { if ( colorVariant.isValid() ) {
Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) ); QVERIFY( qVariantCanConvert<QColor> ( colorVariant ) );
} }
// Check that the "check state" is one we know about. // Check that the "check state" is one we know about.
QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole ); QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole );
if ( checkStateVariant.isValid() ) { if ( checkStateVariant.isValid() ) {
int state = checkStateVariant.toInt(); int state = checkStateVariant.toInt();
Q_ASSERT ( state == Qt::Unchecked || QVERIFY( state == Qt::Unchecked ||
state == Qt::PartiallyChecked || state == Qt::PartiallyChecked ||
state == Qt::Checked ); state == Qt::Checked );
} }
@ -494,7 +492,7 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in
void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end ) void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
{ {
Changing c = insert.pop(); Changing c = insert.pop();
Q_ASSERT ( c.parent == parent ); QVERIFY( c.parent == parent );
// qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize // qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
// << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent ); // << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent );
@ -504,8 +502,8 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
// } // }
// qDebug(); // qDebug();
Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) ); QVERIFY( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) );
Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
if (c.next != model->data(model->index(end + 1, 0, c.parent))) { if (c.next != model->data(model->index(end + 1, 0, c.parent))) {
qDebug() << start << end; qDebug() << start << end;
@ -514,7 +512,7 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent)); qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent));
} }
Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) ); QVERIFY( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
} }
void ModelTest::layoutAboutToBeChanged() void ModelTest::layoutAboutToBeChanged()
@ -527,7 +525,7 @@ void ModelTest::layoutChanged()
{ {
for ( int i = 0; i < changing.count(); ++i ) { for ( int i = 0; i < changing.count(); ++i ) {
QPersistentModelIndex p = changing[i]; QPersistentModelIndex p = changing[i];
Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) ); QVERIFY( p == model->index ( p.row(), p.column(), p.parent() ) );
} }
changing.clear(); changing.clear();
} }
@ -557,10 +555,10 @@ void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end )
{ {
qDebug() << "rr" << parent << start << end; qDebug() << "rr" << parent << start << end;
Changing c = remove.pop(); Changing c = remove.pop();
Q_ASSERT ( c.parent == parent ); QVERIFY( c.parent == parent );
Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) ); QVERIFY( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) ); QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
Q_ASSERT ( c.next == model->data ( model->index ( start, 0, c.parent ) ) ); QVERIFY( c.next == model->data ( model->index ( start, 0, c.parent ) ) );
} }

View File

@ -201,8 +201,10 @@ class ObservingObject : public QObject
Q_OBJECT Q_OBJECT
public: public:
ObservingObject(AccessibleProxyModel *proxy, QObject *parent = 0) ObservingObject(AccessibleProxyModel *proxy, QObject *parent = 0)
: QObject(parent), : QObject(parent)
m_proxy(proxy) , m_proxy(proxy)
, storePersistentFailureCount(0)
, checkPersistentFailureCount(0)
{ {
connect(m_proxy, SIGNAL(layoutAboutToBeChanged()), SLOT(storePersistent())); connect(m_proxy, SIGNAL(layoutAboutToBeChanged()), SLOT(storePersistent()));
connect(m_proxy, SIGNAL(layoutChanged()), SLOT(checkPersistent())); connect(m_proxy, SIGNAL(layoutChanged()), SLOT(checkPersistent()));
@ -215,8 +217,14 @@ public slots:
for (int row = 0; row < m_proxy->rowCount(parent); ++row) { for (int row = 0; row < m_proxy->rowCount(parent); ++row) {
QModelIndex proxyIndex = m_proxy->index(row, 0, parent); QModelIndex proxyIndex = m_proxy->index(row, 0, parent);
QModelIndex sourceIndex = m_proxy->mapToSource(proxyIndex); QModelIndex sourceIndex = m_proxy->mapToSource(proxyIndex);
Q_ASSERT(proxyIndex.isValid()); if (!proxyIndex.isValid()) {
Q_ASSERT(sourceIndex.isValid()); qWarning("%s: Invalid proxy index", Q_FUNC_INFO);
++storePersistentFailureCount;
}
if (!sourceIndex.isValid()) {
qWarning("%s: invalid source index", Q_FUNC_INFO);
++storePersistentFailureCount;
}
m_persistentSourceIndexes.append(sourceIndex); m_persistentSourceIndexes.append(sourceIndex);
m_persistentProxyIndexes.append(proxyIndex); m_persistentProxyIndexes.append(proxyIndex);
if (m_proxy->hasChildren(proxyIndex)) if (m_proxy->hasChildren(proxyIndex))
@ -226,12 +234,24 @@ public slots:
void storePersistent() void storePersistent()
{ {
// This method is called from layoutAboutToBeChanged. Persistent indexes should be valid
foreach(const QModelIndex &idx, m_persistentProxyIndexes) foreach(const QModelIndex &idx, m_persistentProxyIndexes)
Q_ASSERT(idx.isValid()); // This is called from layoutAboutToBeChanged. Persistent indexes should be valid if (!idx.isValid()) {
qWarning("%s: persistentProxyIndexes contains invalid index", Q_FUNC_INFO);
++storePersistentFailureCount;
}
Q_ASSERT(m_proxy->persistent().isEmpty()); if (!m_proxy->persistent().isEmpty()) {
qWarning("%s: proxy should have no persistent indexes when storePersistent called",
Q_FUNC_INFO);
++storePersistentFailureCount;
}
storePersistent(QModelIndex()); storePersistent(QModelIndex());
Q_ASSERT(!m_proxy->persistent().isEmpty()); if (m_proxy->persistent().isEmpty()) {
qWarning("%s: proxy should have persistent index after storePersistent called",
Q_FUNC_INFO);
++storePersistentFailureCount;
}
} }
void checkPersistent() void checkPersistent()
@ -243,7 +263,10 @@ public slots:
for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) { for (int row = 0; row < m_persistentProxyIndexes.size(); ++row) {
QModelIndex updatedProxy = m_persistentProxyIndexes.at(row); QModelIndex updatedProxy = m_persistentProxyIndexes.at(row);
QModelIndex updatedSource = m_persistentSourceIndexes.at(row); QModelIndex updatedSource = m_persistentSourceIndexes.at(row);
QCOMPARE(m_proxy->mapToSource(updatedProxy), updatedSource); if (m_proxy->mapToSource(updatedProxy) != updatedSource) {
qWarning("%s: check failed at row %d", Q_FUNC_INFO, row);
++checkPersistentFailureCount;
}
} }
m_persistentSourceIndexes.clear(); m_persistentSourceIndexes.clear();
m_persistentProxyIndexes.clear(); m_persistentProxyIndexes.clear();
@ -253,6 +276,9 @@ private:
AccessibleProxyModel *m_proxy; AccessibleProxyModel *m_proxy;
QList<QPersistentModelIndex> m_persistentSourceIndexes; QList<QPersistentModelIndex> m_persistentSourceIndexes;
QList<QPersistentModelIndex> m_persistentProxyIndexes; QList<QPersistentModelIndex> m_persistentProxyIndexes;
public:
int storePersistentFailureCount;
int checkPersistentFailureCount;
}; };
void tst_ModelTest::moveSourceItems() void tst_ModelTest::moveSourceItems()
@ -280,6 +306,9 @@ void tst_ModelTest::moveSourceItems()
moveCommand->setDestAncestors(QList<int>() << 1); moveCommand->setDestAncestors(QList<int>() << 1);
moveCommand->setDestRow(0); moveCommand->setDestRow(0);
moveCommand->doCommand(); moveCommand->doCommand();
QCOMPARE(observer.storePersistentFailureCount, 0);
QCOMPARE(observer.checkPersistentFailureCount, 0);
} }
void tst_ModelTest::testResetThroughProxy() void tst_ModelTest::testResetThroughProxy()
@ -302,6 +331,9 @@ void tst_ModelTest::testResetThroughProxy()
ModelResetCommand *resetCommand = new ModelResetCommand(model, this); ModelResetCommand *resetCommand = new ModelResetCommand(model, this);
resetCommand->setNumCols(0); resetCommand->setNumCols(0);
resetCommand->doCommand(); resetCommand->doCommand();
QCOMPARE(observer.storePersistentFailureCount, 0);
QCOMPARE(observer.checkPersistentFailureCount, 0);
} }

View File

@ -3,10 +3,8 @@
TEMPLATE=subdirs TEMPLATE=subdirs
SUBDIRS=\ SUBDIRS=\
# exceptionsafety_objects \ shouldn't enable it
# baselineexample \ Just an example demonstrating qbaselinetest usage # baselineexample \ Just an example demonstrating qbaselinetest usage
lancelot \ lancelot \
qaccessibility \
qalgorithms \ qalgorithms \
qcombobox \ qcombobox \
qcssparser \ qcssparser \
@ -37,6 +35,8 @@ SUBDIRS=\
windowsmobile \ windowsmobile \
nativeimagehandleprovider nativeimagehandleprovider
contains(QT_CONFIG, accessibility):SUBDIRS += qaccessibility
contains(QT_CONFIG, OdfWriter):SUBDIRS += qzip qtextodfwriter contains(QT_CONFIG, OdfWriter):SUBDIRS += qzip qtextodfwriter
mac: { mac: {
SUBDIRS += macgui \ SUBDIRS += macgui \
@ -56,6 +56,8 @@ symbian {
qs60mainapplication qs60mainapplication
} }
!win32-msvc*:!wince*:SUBDIRS += exceptionsafety_objects
# Following tests depends on private API # Following tests depends on private API
!contains(QT_CONFIG, private_tests): SUBDIRS -= \ !contains(QT_CONFIG, private_tests): SUBDIRS -= \
qcombobox \ qcombobox \

View File

@ -83,8 +83,12 @@ public:
bool open(QIODevice::OpenMode openMode) bool open(QIODevice::OpenMode openMode)
{ {
Q_ASSERT(!openForRead_); if (openForRead_ || openForWrite_) {
Q_ASSERT(!openForWrite_); qWarning("%s: file is already open for %s",
Q_FUNC_INFO,
(openForRead_ ? "reading" : "writing"));
return false;
}
openFile_ = resolveFile(openMode & QIODevice::WriteOnly); openFile_ = resolveFile(openMode & QIODevice::WriteOnly);
if (!openFile_) if (!openFile_)
@ -132,13 +136,19 @@ public:
qint64 pos() const qint64 pos() const
{ {
Q_ASSERT(openForRead_ || openForWrite_); if (!openForRead_ && !openForWrite_) {
qWarning("%s: file is not open", Q_FUNC_INFO);
return -1;
}
return position_; return position_;
} }
bool seek(qint64 pos) bool seek(qint64 pos)
{ {
Q_ASSERT(openForRead_ || openForWrite_); if (!openForRead_ && !openForWrite_) {
qWarning("%s: file is not open", Q_FUNC_INFO);
return false;
}
if (pos >= 0) { if (pos >= 0) {
position_ = pos; position_ = pos;
@ -150,7 +160,11 @@ public:
bool flush() bool flush()
{ {
Q_ASSERT(openForRead_ || openForWrite_); if (!openForRead_ && !openForWrite_) {
qWarning("%s: file is not open", Q_FUNC_INFO);
return false;
}
return true; return true;
} }
@ -346,9 +360,9 @@ public:
void setFileName(const QString &file) void setFileName(const QString &file)
{ {
Q_ASSERT(!openForRead_); if (openForRead_ || openForWrite_)
Q_ASSERT(!openForWrite_); qWarning("%s: Can't set file name while file is open", Q_FUNC_INFO);
else
fileName_ = file; fileName_ = file;
} }
@ -368,9 +382,16 @@ public:
qint64 read(char *data, qint64 maxLen) qint64 read(char *data, qint64 maxLen)
{ {
Q_ASSERT(openForRead_); if (!openForRead_) {
qWarning("%s: file must be open for reading", Q_FUNC_INFO);
return -1;
}
if (openFile_.isNull()) {
qWarning("%s: file must not be null", Q_FUNC_INFO);
return -1;
}
Q_ASSERT(!openFile_.isNull());
QMutexLocker lock(&openFile_->mutex); QMutexLocker lock(&openFile_->mutex);
qint64 readSize = qMin(openFile_->content.size() - position_, maxLen); qint64 readSize = qMin(openFile_->content.size() - position_, maxLen);
if (readSize < 0) if (readSize < 0)
@ -384,12 +405,19 @@ public:
qint64 write(const char *data, qint64 length) qint64 write(const char *data, qint64 length)
{ {
Q_ASSERT(openForWrite_); if (!openForWrite_) {
qWarning("%s: file must be open for writing", Q_FUNC_INFO);
return -1;
}
if (openFile_.isNull()) {
qWarning("%s: file must not be null", Q_FUNC_INFO);
return -1;
}
if (length < 0) if (length < 0)
return -1; return -1;
Q_ASSERT(!openFile_.isNull());
QMutexLocker lock(&openFile_->mutex); QMutexLocker lock(&openFile_->mutex);
if (openFile_->content.size() == position_) if (openFile_->content.size() == position_)
openFile_->content.append(data, length); openFile_->content.append(data, length);
@ -434,7 +462,8 @@ protected:
QSharedPointer<File> resolveFile(bool create) const QSharedPointer<File> resolveFile(bool create) const
{ {
if (openForRead_ || openForWrite_) { if (openForRead_ || openForWrite_) {
Q_ASSERT(openFile_); if (!openFile_)
qWarning("%s: file should not be null", Q_FUNC_INFO);
return openFile_; return openFile_;
} }

View File

@ -1,4 +1,5 @@
load(qttest_p4) load(qttest_p4)
requires(contains(QT_CONFIG,accessibility))
SOURCES += tst_qaccessibility.cpp SOURCES += tst_qaccessibility.cpp
unix:!mac:LIBS+=-lm unix:!mac:LIBS+=-lm

View File

@ -326,69 +326,16 @@ QString eventName(const int ev)
} }
} }
static QString stateNames(int state)
{
QString stateString;
if (state == 0x00000000) stateString += " Normal";
if (state & 0x00000001) stateString += " Unavailable";
if (state & 0x00000002) stateString += " Selected";
if (state & 0x00000004) stateString += " Focused";
if (state & 0x00000008) stateString += " Pressed";
if (state & 0x00000010) stateString += " Checked";
if (state & 0x00000020) stateString += " Mixed";
if (state & 0x00000040) stateString += " ReadOnly";
if (state & 0x00000080) stateString += " HotTracked";
if (state & 0x00000100) stateString += " DefaultButton";
if (state & 0x00000200) stateString += " Expanded";
if (state & 0x00000400) stateString += " Collapsed";
if (state & 0x00000800) stateString += " Busy";
if (state & 0x00001000) stateString += " Floating";
if (state & 0x00002000) stateString += " Marqueed";
if (state & 0x00004000) stateString += " Animated";
if (state & 0x00008000) stateString += " Invisible";
if (state & 0x00010000) stateString += " Offscreen";
if (state & 0x00020000) stateString += " Sizeable";
if (state & 0x00040000) stateString += " Moveable";
if (state & 0x00080000) stateString += " SelfVoicing";
if (state & 0x00100000) stateString += " Focusable";
if (state & 0x00200000) stateString += " Selectable";
if (state & 0x00400000) stateString += " Linked";
if (state & 0x00800000) stateString += " Traversed";
if (state & 0x01000000) stateString += " MultiSelectable";
if (state & 0x02000000) stateString += " ExtSelectable";
if (state & 0x04000000) stateString += " AlertLow";
if (state & 0x08000000) stateString += " AlertMedium";
if (state & 0x10000000) stateString += " AlertHigh";
if (state & 0x20000000) stateString += " Protected";
if (state & 0x3fffffff) stateString += " Valid";
if (stateString.isEmpty())
stateString = "Unknown state " + QString::number(state);
return stateString;
}
QAccessible::State state(QWidget * const widget) QAccessible::State state(QWidget * const widget)
{ {
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget);
Q_ASSERT(iface); if (!iface)
QAccessible::State state = iface->state(0); qWarning() << "Cannot get QAccessibleInterface for widget";
QAccessible::State state = (iface ? iface->state(0) : static_cast<QAccessible::State>(0));
delete iface; delete iface;
return state; return state;
} }
void printState(QWidget * const widget)
{
qDebug() << "State for" << widget->metaObject()->className() << stateNames(state(widget));
}
void printState(QAccessibleInterface * const iface, const int child = 0)
{
qDebug() << "State for" << iface->object()->metaObject()->className() << "child" << child
<< iface->text(QAccessible::Name, child) << stateNames(iface->state(child));
}
class QtTestAccessibleWidget: public QWidget class QtTestAccessibleWidget: public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -403,7 +350,6 @@ public:
} }
}; };
#ifdef QTEST_ACCESSIBILITY
class QtTestAccessibleWidgetIface: public QAccessibleWidget class QtTestAccessibleWidgetIface: public QAccessibleWidget
{ {
public: public:
@ -421,7 +367,6 @@ public:
return 0; return 0;
} }
}; };
#endif
tst_QAccessibility::tst_QAccessibility() tst_QAccessibility::tst_QAccessibility()
{ {
@ -433,17 +378,13 @@ tst_QAccessibility::~tst_QAccessibility()
void tst_QAccessibility::initTestCase() void tst_QAccessibility::initTestCase()
{ {
#ifdef QTEST_ACCESSIBILITY
QTestAccessibility::initialize(); QTestAccessibility::initialize();
QAccessible::installFactory(QtTestAccessibleWidgetIface::ifaceFactory); QAccessible::installFactory(QtTestAccessibleWidgetIface::ifaceFactory);
#endif
} }
void tst_QAccessibility::cleanupTestCase() void tst_QAccessibility::cleanupTestCase()
{ {
#ifdef QTEST_ACCESSIBILITY
QTestAccessibility::cleanup(); QTestAccessibility::cleanup();
#endif
} }
void tst_QAccessibility::init() void tst_QAccessibility::init()
@ -453,7 +394,6 @@ void tst_QAccessibility::init()
void tst_QAccessibility::cleanup() void tst_QAccessibility::cleanup()
{ {
#ifdef QTEST_ACCESSIBILITY
const EventList list = QTestAccessibility::events(); const EventList list = QTestAccessibility::events();
if (!list.isEmpty()) { if (!list.isEmpty()) {
qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(), qWarning("%d accessibility event(s) were not handled in testfunction '%s':", list.count(),
@ -463,14 +403,10 @@ void tst_QAccessibility::cleanup()
eventName(list.at(i).event).toAscii().constData(), list.at(i).event, list.at(i).child); eventName(list.at(i).event).toAscii().constData(), list.at(i).event, list.at(i).child);
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::eventTest() void tst_QAccessibility::eventTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QPushButton* button = new QPushButton(0); QPushButton* button = new QPushButton(0);
button->setObjectName(QString("Olaf")); button->setObjectName(QString("Olaf"));
@ -491,14 +427,10 @@ void tst_QAccessibility::eventTest()
QVERIFY_EVENT(button, 0, QAccessible::ObjectHide); QVERIFY_EVENT(button, 0, QAccessible::ObjectHide);
delete button; delete button;
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::customWidget() void tst_QAccessibility::customWidget()
{ {
#ifdef QTEST_ACCESSIBILITY
QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz"); QtTestAccessibleWidget* widget = new QtTestAccessibleWidget(0, "Heinz");
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget);
@ -510,14 +442,10 @@ void tst_QAccessibility::customWidget()
delete iface; delete iface;
delete widget; delete widget;
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::deletedWidget() void tst_QAccessibility::deletedWidget()
{ {
#ifdef QTEST_ACCESSIBILITY
QtTestAccessibleWidget *widget = new QtTestAccessibleWidget(0, "Ralf"); QtTestAccessibleWidget *widget = new QtTestAccessibleWidget(0, "Ralf");
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(widget);
QVERIFY(iface != 0); QVERIFY(iface != 0);
@ -528,9 +456,6 @@ void tst_QAccessibility::deletedWidget()
widget = 0; widget = 0;
QVERIFY(!iface->isValid()); QVERIFY(!iface->isValid());
delete iface; delete iface;
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
QWidget *tst_QAccessibility::createGUI() QWidget *tst_QAccessibility::createGUI()
@ -539,7 +464,6 @@ QWidget *tst_QAccessibility::createGUI()
qWarning( "Should never get here without Qt3Support"); qWarning( "Should never get here without Qt3Support");
return 0; return 0;
#else #else
# ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint); QWidget *toplevel = new QWidget(0, Qt::X11BypassWindowManagerHint);
QGridLayout *grid = new QGridLayout(toplevel, 2, 2); QGridLayout *grid = new QGridLayout(toplevel, 2, 2);
@ -611,10 +535,6 @@ QWidget *tst_QAccessibility::createGUI()
radioAM->setFocus(); radioAM->setFocus();
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
return toplevel; return toplevel;
# else
Q_ASSERT(0); // this function cannot be called without accessibility support
return 0;
# endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
@ -623,7 +543,6 @@ void tst_QAccessibility::childAt()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = createGUI(); QWidget *toplevel = createGUI();
QAccessibleInterface *acc_toplevel = QAccessible::queryAccessibleInterface(toplevel); QAccessibleInterface *acc_toplevel = QAccessible::queryAccessibleInterface(toplevel);
QVERIFY(acc_toplevel); QVERIFY(acc_toplevel);
@ -655,9 +574,6 @@ void tst_QAccessibility::childAt()
delete acc_toplevel; delete acc_toplevel;
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
@ -666,7 +582,6 @@ void tst_QAccessibility::childCount()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = createGUI(); QWidget *toplevel = createGUI();
QObject *topLeft = toplevel->child("topLeft"); QObject *topLeft = toplevel->child("topLeft");
QObject *topRight = toplevel->child("topRight"); QObject *topRight = toplevel->child("topRight");
@ -699,9 +614,6 @@ void tst_QAccessibility::childCount()
delete acc_bottomRight; delete acc_bottomRight;
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
@ -710,7 +622,6 @@ void tst_QAccessibility::relationTo()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = createGUI(); QWidget *toplevel = createGUI();
toplevel->resize(400,300); toplevel->resize(400,300);
QObject *topLeft = toplevel->child("topLeft"); QObject *topLeft = toplevel->child("topLeft");
@ -916,15 +827,11 @@ void tst_QAccessibility::relationTo()
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
void tst_QAccessibility::navigateGeometric() void tst_QAccessibility::navigateGeometric()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
static const int skip = 20; //speed the test up significantly static const int skip = 20; //speed the test up significantly
static const double step = Q_PI / 180; static const double step = Q_PI / 180;
@ -1020,14 +927,10 @@ void tst_QAccessibility::navigateGeometric()
delete w; delete w;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::navigateSlider() void tst_QAccessibility::navigateSlider()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QSlider *slider = new QSlider(0); QSlider *slider = new QSlider(0);
slider->setObjectName(QString("Slidy")); slider->setObjectName(QString("Slidy"));
@ -1054,14 +957,10 @@ void tst_QAccessibility::navigateSlider()
delete slider; delete slider;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::navigateCovered() void tst_QAccessibility::navigateCovered()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QWidget *w = new QWidget(0); QWidget *w = new QWidget(0);
w->setObjectName(QString("Harry")); w->setObjectName(QString("Harry"));
@ -1164,14 +1063,10 @@ void tst_QAccessibility::navigateCovered()
delete w; delete w;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::navigateHierarchy() void tst_QAccessibility::navigateHierarchy()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QWidget *w = new QWidget(0); QWidget *w = new QWidget(0);
w->setObjectName(QString("Hans")); w->setObjectName(QString("Hans"));
@ -1267,9 +1162,6 @@ void tst_QAccessibility::navigateHierarchy()
delete w; delete w;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
#define QSETCOMPARE(thetypename, elements, otherelements) \ #define QSETCOMPARE(thetypename, elements, otherelements) \
@ -1280,7 +1172,6 @@ void tst_QAccessibility::navigateControllers()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
{ {
Q3VBox vbox; Q3VBox vbox;
QSlider slider(&vbox); QSlider slider(&vbox);
@ -1363,9 +1254,6 @@ void tst_QAccessibility::navigateControllers()
delete acc_slider; delete acc_slider;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
@ -1374,7 +1262,6 @@ void tst_QAccessibility::navigateLabels()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
{ {
Q3VBox vbox; Q3VBox vbox;
Q3HBox hbox(&vbox); Q3HBox hbox(&vbox);
@ -1496,9 +1383,6 @@ void tst_QAccessibility::navigateLabels()
delete acc_lineedit3; delete acc_lineedit3;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
@ -1550,7 +1434,6 @@ static QWidget *createWidgets()
void tst_QAccessibility::accessibleName() void tst_QAccessibility::accessibleName()
{ {
#ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = createWidgets(); QWidget *toplevel = createWidgets();
toplevel->show(); toplevel->show();
#if defined(Q_WS_X11) #if defined(Q_WS_X11)
@ -1575,9 +1458,6 @@ void tst_QAccessibility::accessibleName()
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::text() void tst_QAccessibility::text()
@ -1585,7 +1465,6 @@ void tst_QAccessibility::text()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = createGUI(); QWidget *toplevel = createGUI();
toplevel->show(); toplevel->show();
#if defined(Q_WS_X11) #if defined(Q_WS_X11)
@ -1681,10 +1560,6 @@ void tst_QAccessibility::text()
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // !QT3_SUPPORT #endif // !QT3_SUPPORT
} }
@ -1693,7 +1568,6 @@ void tst_QAccessibility::setText()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
QWidget *toplevel = createGUI(); QWidget *toplevel = createGUI();
toplevel->show(); toplevel->show();
QObject *bottomLeft = toplevel->findChild<QObject *>("bottomLeft"); QObject *bottomLeft = toplevel->findChild<QObject *>("bottomLeft");
@ -1717,16 +1591,11 @@ void tst_QAccessibility::setText()
delete acc_lineedit; delete acc_lineedit;
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif //QT3_SUPPORT #endif //QT3_SUPPORT
} }
void tst_QAccessibility::hideShowTest() void tst_QAccessibility::hideShowTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QWidget * const window = new QWidget(); QWidget * const window = new QWidget();
QWidget * const child = new QWidget(window); QWidget * const child = new QWidget(window);
@ -1753,14 +1622,10 @@ void tst_QAccessibility::hideShowTest()
delete window; delete window;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::userActionCount() void tst_QAccessibility::userActionCount()
{ {
#ifdef QTEST_ACCESSIBILITY
QWidget widget; QWidget widget;
QAccessibleInterface *test = QAccessible::queryAccessibleInterface(&widget); QAccessibleInterface *test = QAccessible::queryAccessibleInterface(&widget);
@ -1790,18 +1655,14 @@ void tst_QAccessibility::userActionCount()
QCOMPARE(test->userActionCount(1), 0); QCOMPARE(test->userActionCount(1), 0);
QCOMPARE(test->userActionCount(-1), 0); QCOMPARE(test->userActionCount(-1), 0);
delete test; test = 0; delete test; test = 0;
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::actionText() void tst_QAccessibility::actionText()
{ {
#ifdef QTEST_ACCESSIBILITY QWidget *widget = new QWidget;
QWidget widget; widget->show();
widget.show();
QAccessibleInterface *test = QAccessible::queryAccessibleInterface(&widget); QAccessibleInterface *test = QAccessible::queryAccessibleInterface(widget);
QVERIFY(test); QVERIFY(test);
QVERIFY(test->isValid()); QVERIFY(test->isValid());
@ -1813,20 +1674,15 @@ void tst_QAccessibility::actionText()
QCOMPARE(test->actionText(QAccessible::DefaultAction, QAccessible::Name, 0), QString("SetFocus")); QCOMPARE(test->actionText(QAccessible::DefaultAction, QAccessible::Name, 0), QString("SetFocus"));
QCOMPARE(test->actionText(QAccessible::SetFocus, QAccessible::Name, 0), QString("SetFocus")); QCOMPARE(test->actionText(QAccessible::SetFocus, QAccessible::Name, 0), QString("SetFocus"));
delete test; test = 0; delete test;
delete widget;
#else QTestAccessibility::clearEvents();
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::doAction() void tst_QAccessibility::doAction()
{ {
#ifdef QTEST_ACCESSIBILITY
QSKIP("TODO: Implement me", SkipAll); QSKIP("TODO: Implement me", SkipAll);
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::applicationTest() void tst_QAccessibility::applicationTest()
@ -1881,7 +1737,6 @@ public Q_SLOTS:
void tst_QAccessibility::buttonTest() void tst_QAccessibility::buttonTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QWidget window; QWidget window;
window.setLayout(new QVBoxLayout); window.setLayout(new QVBoxLayout);
@ -2070,10 +1925,6 @@ void tst_QAccessibility::buttonTest()
// test->release(); // test->release();
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::sliderTest() void tst_QAccessibility::sliderTest()
@ -2081,20 +1932,19 @@ void tst_QAccessibility::sliderTest()
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
QSKIP("This test needs Qt3Support", SkipAll); QSKIP("This test needs Qt3Support", SkipAll);
#else #else
#ifdef QTEST_ACCESSIBILITY
QAccessibleInterface *test = 0; QAccessibleInterface *test = 0;
Q3VBox vbox; Q3VBox *vbox = new Q3VBox;
QLabel labelHorizontal("Horizontal", &vbox); QLabel *labelHorizontal = new QLabel("Horizontal", vbox);
QSlider sliderHorizontal(Qt::Horizontal, &vbox); QSlider *sliderHorizontal = new QSlider(Qt::Horizontal, vbox);
labelHorizontal.setBuddy(&sliderHorizontal); labelHorizontal->setBuddy(sliderHorizontal);
QLabel labelVertical("Vertical", &vbox); QLabel *labelVertical = new QLabel("Vertical", vbox);
QSlider sliderVertical(Qt::Vertical, &vbox); QSlider *sliderVertical = new QSlider(Qt::Vertical, vbox);
labelVertical.setBuddy(&sliderVertical); labelVertical->setBuddy(sliderVertical);
vbox.show(); vbox->show();
// test horizontal slider // test horizontal slider
test = QAccessible::queryAccessibleInterface(&sliderHorizontal); test = QAccessible::queryAccessibleInterface(sliderHorizontal);
QVERIFY(test); QVERIFY(test);
QCOMPARE(test->childCount(), 3); QCOMPARE(test->childCount(), 3);
QCOMPARE(test->role(0), QAccessible::Slider); QCOMPARE(test->role(0), QAccessible::Slider);
@ -2102,15 +1952,15 @@ void tst_QAccessibility::sliderTest()
QCOMPARE(test->role(2), QAccessible::Indicator); QCOMPARE(test->role(2), QAccessible::Indicator);
QCOMPARE(test->role(3), QAccessible::PushButton); QCOMPARE(test->role(3), QAccessible::PushButton);
QCOMPARE(test->text(QAccessible::Name, 0), labelHorizontal.text()); QCOMPARE(test->text(QAccessible::Name, 0), labelHorizontal->text());
QCOMPARE(test->text(QAccessible::Name, 1), QSlider::tr("Page left")); QCOMPARE(test->text(QAccessible::Name, 1), QSlider::tr("Page left"));
QCOMPARE(test->text(QAccessible::Name, 2), QSlider::tr("Position")); QCOMPARE(test->text(QAccessible::Name, 2), QSlider::tr("Position"));
QCOMPARE(test->text(QAccessible::Name, 3), QSlider::tr("Page right")); QCOMPARE(test->text(QAccessible::Name, 3), QSlider::tr("Page right"));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.value())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal->value()));
QCOMPARE(test->text(QAccessible::Value, 1), QString()); QCOMPARE(test->text(QAccessible::Value, 1), QString());
QCOMPARE(test->text(QAccessible::Value, 2), QString::number(sliderHorizontal.value())); QCOMPARE(test->text(QAccessible::Value, 2), QString::number(sliderHorizontal->value()));
QCOMPARE(test->text(QAccessible::Value, 3), QString()); QCOMPARE(test->text(QAccessible::Value, 3), QString());
// Skip acton tests. // Skip action tests.
#if 0 #if 0
QCOMPARE(test->defaultAction(0), QAccessible::SetFocus); QCOMPARE(test->defaultAction(0), QAccessible::SetFocus);
QCOMPARE(test->defaultAction(1), QAccessible::Press); QCOMPARE(test->defaultAction(1), QAccessible::Press);
@ -2122,26 +1972,26 @@ void tst_QAccessibility::sliderTest()
QCOMPARE(test->actionText(QAccessible::Decrease, QAccessible::Name, 2), QSlider::tr("Decrease")); QCOMPARE(test->actionText(QAccessible::Decrease, QAccessible::Name, 2), QSlider::tr("Decrease"));
QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 3), QSlider::tr("Press")); QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 3), QSlider::tr("Press"));
QVERIFY(test->doAction(QAccessible::Press, 3)); QVERIFY(test->doAction(QAccessible::Press, 3));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.pageStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal->pageStep()));
QVERIFY(test->doAction(QAccessible::Press, 3)); QVERIFY(test->doAction(QAccessible::Press, 3));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderHorizontal.pageStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderHorizontal->pageStep()));
QVERIFY(test->doAction(QAccessible::Press, 1)); QVERIFY(test->doAction(QAccessible::Press, 1));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.pageStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal->pageStep()));
QVERIFY(test->doAction(QAccessible::Press, 1)); QVERIFY(test->doAction(QAccessible::Press, 1));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0));
QVERIFY(test->doAction(QAccessible::Increase, 2)); QVERIFY(test->doAction(QAccessible::Increase, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.lineStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal->lineStep()));
QVERIFY(test->doAction(QAccessible::Increase, 2)); QVERIFY(test->doAction(QAccessible::Increase, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderHorizontal.lineStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderHorizontal->lineStep()));
QVERIFY(test->doAction(QAccessible::Decrease, 2)); QVERIFY(test->doAction(QAccessible::Decrease, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal.lineStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderHorizontal->lineStep()));
QVERIFY(test->doAction(QAccessible::Decrease, 2)); QVERIFY(test->doAction(QAccessible::Decrease, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0));
#endif #endif
delete test; delete test;
// test vertical slider // test vertical slider
test = QAccessible::queryAccessibleInterface(&sliderVertical); test = QAccessible::queryAccessibleInterface(sliderVertical);
QVERIFY(test); QVERIFY(test);
QCOMPARE(test->childCount(), 3); QCOMPARE(test->childCount(), 3);
QCOMPARE(test->role(0), QAccessible::Slider); QCOMPARE(test->role(0), QAccessible::Slider);
@ -2149,15 +1999,15 @@ void tst_QAccessibility::sliderTest()
QCOMPARE(test->role(2), QAccessible::Indicator); QCOMPARE(test->role(2), QAccessible::Indicator);
QCOMPARE(test->role(3), QAccessible::PushButton); QCOMPARE(test->role(3), QAccessible::PushButton);
QCOMPARE(test->text(QAccessible::Name, 0), labelVertical.text()); QCOMPARE(test->text(QAccessible::Name, 0), labelVertical->text());
QCOMPARE(test->text(QAccessible::Name, 1), QSlider::tr("Page up")); QCOMPARE(test->text(QAccessible::Name, 1), QSlider::tr("Page up"));
QCOMPARE(test->text(QAccessible::Name, 2), QSlider::tr("Position")); QCOMPARE(test->text(QAccessible::Name, 2), QSlider::tr("Position"));
QCOMPARE(test->text(QAccessible::Name, 3), QSlider::tr("Page down")); QCOMPARE(test->text(QAccessible::Name, 3), QSlider::tr("Page down"));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.value())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical->value()));
QCOMPARE(test->text(QAccessible::Value, 1), QString()); QCOMPARE(test->text(QAccessible::Value, 1), QString());
QCOMPARE(test->text(QAccessible::Value, 2), QString::number(sliderVertical.value())); QCOMPARE(test->text(QAccessible::Value, 2), QString::number(sliderVertical->value()));
QCOMPARE(test->text(QAccessible::Value, 3), QString()); QCOMPARE(test->text(QAccessible::Value, 3), QString());
// Skip acton tests. // Skip action tests.
#if 0 #if 0
QCOMPARE(test->defaultAction(0), QAccessible::SetFocus); QCOMPARE(test->defaultAction(0), QAccessible::SetFocus);
QCOMPARE(test->defaultAction(1), QAccessible::Press); QCOMPARE(test->defaultAction(1), QAccessible::Press);
@ -2169,23 +2019,28 @@ void tst_QAccessibility::sliderTest()
QCOMPARE(test->actionText(QAccessible::Decrease, QAccessible::Name, 2), QSlider::tr("Decrease")); QCOMPARE(test->actionText(QAccessible::Decrease, QAccessible::Name, 2), QSlider::tr("Decrease"));
QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 3), QSlider::tr("Press")); QCOMPARE(test->actionText(QAccessible::Press, QAccessible::Name, 3), QSlider::tr("Press"));
QVERIFY(test->doAction(QAccessible::Press, 3)); QVERIFY(test->doAction(QAccessible::Press, 3));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.pageStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical->pageStep()));
QVERIFY(test->doAction(QAccessible::Press, 3)); QVERIFY(test->doAction(QAccessible::Press, 3));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderVertical.pageStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderVertical->pageStep()));
QVERIFY(test->doAction(QAccessible::Press, 1)); QVERIFY(test->doAction(QAccessible::Press, 1));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.pageStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical->pageStep()));
QVERIFY(test->doAction(QAccessible::Press, 1)); QVERIFY(test->doAction(QAccessible::Press, 1));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0));
QVERIFY(test->doAction(QAccessible::Increase, 2)); QVERIFY(test->doAction(QAccessible::Increase, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.lineStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical->lineStep()));
QVERIFY(test->doAction(QAccessible::Increase, 2)); QVERIFY(test->doAction(QAccessible::Increase, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderVertical.lineStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(2*sliderVertical->lineStep()));
QVERIFY(test->doAction(QAccessible::Decrease, 2)); QVERIFY(test->doAction(QAccessible::Decrease, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical.lineStep())); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(sliderVertical->lineStep()));
QVERIFY(test->doAction(QAccessible::Decrease, 2)); QVERIFY(test->doAction(QAccessible::Decrease, 2));
QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0)); QCOMPARE(test->text(QAccessible::Value, 0), QString::number(0));
#endif #endif
delete test; delete test;
delete sliderHorizontal;
delete sliderVertical;
delete labelHorizontal;
delete labelVertical;
delete vbox;
// Test that when we hide() a slider, the PageLeft, Indicator, and PageRight also gets the // Test that when we hide() a slider, the PageLeft, Indicator, and PageRight also gets the
// Invisible state bit set. // Invisible state bit set.
@ -2268,17 +2123,12 @@ void tst_QAccessibility::sliderTest()
delete sliderInterface; delete sliderInterface;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif //!QT3_SUPPORT #endif //!QT3_SUPPORT
} }
void tst_QAccessibility::scrollBarTest() void tst_QAccessibility::scrollBarTest()
{ {
#ifdef QTEST_ACCESSIBILITY
// Test that when we hide() a slider, the PageLeft, Indicator, and PageRight also gets the // Test that when we hide() a slider, the PageLeft, Indicator, and PageRight also gets the
// Invisible state bit set. // Invisible state bit set.
enum SubControls { LineUp = 1, enum SubControls { LineUp = 1,
@ -2368,15 +2218,10 @@ void tst_QAccessibility::scrollBarTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::tabTest() void tst_QAccessibility::tabTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QTabBar *tabBar = new QTabBar(); QTabBar *tabBar = new QTabBar();
tabBar->show(); tabBar->show();
@ -2412,9 +2257,6 @@ void tst_QAccessibility::tabTest()
delete tabBar; delete tabBar;
delete interface; delete interface;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::tabWidgetTest() void tst_QAccessibility::tabWidgetTest()
@ -2512,7 +2354,6 @@ void tst_QAccessibility::tabWidgetTest()
void tst_QAccessibility::menuTest() void tst_QAccessibility::menuTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QMainWindow mw; QMainWindow mw;
mw.resize(300, 200); mw.resize(300, 200);
@ -2758,14 +2599,10 @@ void tst_QAccessibility::menuTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs Qt >= 0x040000 and accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::spinBoxTest() void tst_QAccessibility::spinBoxTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QSpinBox * const spinBox = new QSpinBox(); QSpinBox * const spinBox = new QSpinBox();
spinBox->show(); spinBox->show();
@ -2792,14 +2629,10 @@ void tst_QAccessibility::spinBoxTest()
QVERIFY(events.contains(expectedEvent)); QVERIFY(events.contains(expectedEvent));
delete spinBox; delete spinBox;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::doubleSpinBoxTest() void tst_QAccessibility::doubleSpinBoxTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QDoubleSpinBox *doubleSpinBox = new QDoubleSpinBox; QDoubleSpinBox *doubleSpinBox = new QDoubleSpinBox;
doubleSpinBox->show(); doubleSpinBox->show();
@ -2819,14 +2652,10 @@ void tst_QAccessibility::doubleSpinBoxTest()
delete doubleSpinBox; delete doubleSpinBox;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::textEditTest() void tst_QAccessibility::textEditTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QTextEdit edit; QTextEdit edit;
QString text = "hello world\nhow are you today?\n"; QString text = "hello world\nhow are you today?\n";
@ -2846,14 +2675,10 @@ void tst_QAccessibility::textEditTest()
QCOMPARE(iface->textInterface()->characterRect(6, QAccessible2::RelativeToParent).size(), QSize(fm.width("w"), fm.height())); QCOMPARE(iface->textInterface()->characterRect(6, QAccessible2::RelativeToParent).size(), QSize(fm.width("w"), fm.height()));
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::textBrowserTest() void tst_QAccessibility::textBrowserTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QTextBrowser textBrowser; QTextBrowser textBrowser;
QString text = QLatin1String("Hello world\nhow are you today?\n"); QString text = QLatin1String("Hello world\nhow are you today?\n");
@ -2870,14 +2695,10 @@ void tst_QAccessibility::textBrowserTest()
QCOMPARE(interface->text(QAccessible::Value, 6), QString()); QCOMPARE(interface->text(QAccessible::Value, 6), QString());
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::listViewTest() void tst_QAccessibility::listViewTest()
{ {
#if 1 //def QTEST_ACCESSIBILITY
{ {
QListView listView; QListView listView;
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&listView); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(&listView);
@ -2943,15 +2764,11 @@ void tst_QAccessibility::listViewTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::mdiAreaTest() void tst_QAccessibility::mdiAreaTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QMdiArea mdiArea; QMdiArea mdiArea;
mdiArea.resize(400,300); mdiArea.resize(400,300);
@ -3000,14 +2817,10 @@ void tst_QAccessibility::mdiAreaTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::mdiSubWindowTest() void tst_QAccessibility::mdiSubWindowTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QMdiArea mdiArea; QMdiArea mdiArea;
mdiArea.show(); mdiArea.show();
@ -3130,14 +2943,10 @@ void tst_QAccessibility::mdiSubWindowTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::lineEditTest() void tst_QAccessibility::lineEditTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QLineEdit *le = new QLineEdit; QLineEdit *le = new QLineEdit;
QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(le); QAccessibleInterface *iface = QAccessible::queryAccessibleInterface(le);
QVERIFY(iface); QVERIFY(iface);
@ -3195,14 +3004,10 @@ void tst_QAccessibility::lineEditTest()
delete le2; delete le2;
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::workspaceTest() void tst_QAccessibility::workspaceTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QWorkspace workspace; QWorkspace workspace;
workspace.resize(400,300); workspace.resize(400,300);
@ -3256,14 +3061,10 @@ void tst_QAccessibility::workspaceTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::dialogButtonBoxTest() void tst_QAccessibility::dialogButtonBoxTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QDialogButtonBox box(QDialogButtonBox::Reset | QDialogButtonBox box(QDialogButtonBox::Reset |
QDialogButtonBox::Help | QDialogButtonBox::Help |
@ -3376,14 +3177,10 @@ void tst_QAccessibility::dialogButtonBoxTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::dialTest() void tst_QAccessibility::dialTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QDial dial; QDial dial;
dial.setValue(20); dial.setValue(20);
@ -3425,28 +3222,20 @@ void tst_QAccessibility::dialTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::rubberBandTest() void tst_QAccessibility::rubberBandTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QRubberBand rubberBand(QRubberBand::Rectangle); QRubberBand rubberBand(QRubberBand::Rectangle);
QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&rubberBand); QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(&rubberBand);
QVERIFY(interface); QVERIFY(interface);
QCOMPARE(interface->role(0), QAccessible::Border); QCOMPARE(interface->role(0), QAccessible::Border);
delete interface; delete interface;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::abstractScrollAreaTest() void tst_QAccessibility::abstractScrollAreaTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QAbstractScrollArea abstractScrollArea; QAbstractScrollArea abstractScrollArea;
@ -3604,14 +3393,10 @@ void tst_QAccessibility::abstractScrollAreaTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::scrollAreaTest() void tst_QAccessibility::scrollAreaTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QScrollArea scrollArea; QScrollArea scrollArea;
scrollArea.show(); scrollArea.show();
@ -3625,14 +3410,10 @@ void tst_QAccessibility::scrollAreaTest()
delete interface; delete interface;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::tableWidgetTest() void tst_QAccessibility::tableWidgetTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QWidget *topLevel = new QWidget; QWidget *topLevel = new QWidget;
QTableWidget *w = new QTableWidget(8,4,topLevel); QTableWidget *w = new QTableWidget(8,4,topLevel);
@ -3672,10 +3453,6 @@ void tst_QAccessibility::tableWidgetTest()
delete topLevel; delete topLevel;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
class QtTestTableModel: public QAbstractTableModel class QtTestTableModel: public QAbstractTableModel
@ -3758,7 +3535,6 @@ public:
void tst_QAccessibility::tableViewTest() void tst_QAccessibility::tableViewTest()
{ {
#ifdef QTEST_ACCESSIBILITY
{ {
QtTestTableModel *model = new QtTestTableModel(3, 4); QtTestTableModel *model = new QtTestTableModel(3, 4);
QTableView *w = new QTableView(); QTableView *w = new QTableView();
@ -3838,15 +3614,11 @@ void tst_QAccessibility::tableViewTest()
delete model; delete model;
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::calendarWidgetTest() void tst_QAccessibility::calendarWidgetTest()
{ {
#ifndef QT_NO_CALENDARWIDGET #ifndef QT_NO_CALENDARWIDGET
#ifdef QTEST_ACCESSIBILITY
{ {
QCalendarWidget calendarWidget; QCalendarWidget calendarWidget;
@ -3939,17 +3711,12 @@ void tst_QAccessibility::calendarWidgetTest()
} }
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // QT_NO_CALENDARWIDGET #endif // QT_NO_CALENDARWIDGET
} }
void tst_QAccessibility::dockWidgetTest() void tst_QAccessibility::dockWidgetTest()
{ {
#ifndef QT_NO_DOCKWIDGET #ifndef QT_NO_DOCKWIDGET
#ifdef QTEST_ACCESSIBILITY
// Set up a proper main window with two dock widgets // Set up a proper main window with two dock widgets
QMainWindow *mw = new QMainWindow(); QMainWindow *mw = new QMainWindow();
QFrame *central = new QFrame(mw); QFrame *central = new QFrame(mw);
@ -4017,19 +3784,14 @@ void tst_QAccessibility::dockWidgetTest()
delete dock2; delete dock2;
delete mw; delete mw;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif // QT_NO_DOCKWIDGET #endif // QT_NO_DOCKWIDGET
} }
void tst_QAccessibility::pushButtonTest() void tst_QAccessibility::pushButtonTest()
{ {
#if !defined(QT3_SUPPORT) #if !defined(QT3_SUPPORT)
qWarning( "Should never get here without Qt3Support"); QSKIP( "Should never get here without Qt3Support", SkipAll);
return ;
#else #else
#ifdef QTEST_ACCESSIBILITY
// Set up a proper main window with two dock widgets // Set up a proper main window with two dock widgets
QWidget *toplevel = createGUI(); QWidget *toplevel = createGUI();
QObject *topRight = toplevel->findChild<QObject *>("topRight"); QObject *topRight = toplevel->findChild<QObject *>("topRight");
@ -4063,15 +3825,11 @@ void tst_QAccessibility::pushButtonTest()
delete accToplevel; delete accToplevel;
delete toplevel; delete toplevel;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
#endif //QT3_SUPPORT #endif //QT3_SUPPORT
} }
void tst_QAccessibility::comboBoxTest() void tst_QAccessibility::comboBoxTest()
{ {
#ifdef QTEST_ACCESSIBILITY
#if defined(Q_OS_WINCE) #if defined(Q_OS_WINCE)
if (!IsValidCEPlatform()) { if (!IsValidCEPlatform()) {
QSKIP("Test skipped on Windows Mobile test hardware", SkipAll); QSKIP("Test skipped on Windows Mobile test hardware", SkipAll);
@ -4109,15 +3867,10 @@ void tst_QAccessibility::comboBoxTest()
delete w; delete w;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::treeWidgetTest() void tst_QAccessibility::treeWidgetTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QWidget *w = new QWidget; QWidget *w = new QWidget;
QTreeWidget *tree = new QTreeWidget(w); QTreeWidget *tree = new QTreeWidget(w);
QHBoxLayout *l = new QHBoxLayout(w); QHBoxLayout *l = new QHBoxLayout(w);
@ -4175,14 +3928,10 @@ void tst_QAccessibility::treeWidgetTest()
delete w; delete w;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::labelTest() void tst_QAccessibility::labelTest()
{ {
#ifdef QTEST_ACCESSIBILITY
QString text = "Hello World"; QString text = "Hello World";
QLabel *label = new QLabel(text); QLabel *label = new QLabel(text);
label->show(); label->show();
@ -4221,14 +3970,10 @@ void tst_QAccessibility::labelTest()
delete acc_label; delete acc_label;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs accessibility support.", SkipAll);
#endif
} }
void tst_QAccessibility::accelerators() void tst_QAccessibility::accelerators()
{ {
#ifdef QTEST_ACCESSIBILITY
QWidget *window = new QWidget; QWidget *window = new QWidget;
QHBoxLayout *lay = new QHBoxLayout(window); QHBoxLayout *lay = new QHBoxLayout(window);
QLabel *label = new QLabel(tr("&Line edit"), window); QLabel *label = new QLabel(tr("&Line edit"), window);
@ -4252,6 +3997,10 @@ void tst_QAccessibility::accelerators()
QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + QLatin1String("A")); QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + QLatin1String("A"));
label->setText(tr("Q &&A")); label->setText(tr("Q &&A"));
QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString()); QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QString());
#if !defined(QT_NO_DEBUG) && !defined(Q_WS_MAC)
QTest::ignoreMessage(QtWarningMsg, "QKeySequence::mnemonic: \"Q &A&B\" contains multiple occurrences of '&'");
#endif
label->setText(tr("Q &A&B")); label->setText(tr("Q &A&B"));
QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + QLatin1String("A")); QCOMPARE(accLineEdit->text(QAccessible::Accelerator, 0), QKeySequence(Qt::ALT).toString(QKeySequence::NativeText) + QLatin1String("A"));
@ -4261,9 +4010,6 @@ void tst_QAccessibility::accelerators()
QTest::qWait(100); QTest::qWait(100);
delete window; delete window;
QTestAccessibility::clearEvents(); QTestAccessibility::clearEvents();
#else
QSKIP("Test needs Qt >= 0x040000 and accessibility support.", SkipAll);
#endif
} }

View File

@ -241,7 +241,8 @@ QList<ResultSet> testAlgorithm(Algorithm &algorithm, QStringList dataSetTypes,
foreach(QString dataSetType, dataSetTypes) { foreach(QString dataSetType, dataSetTypes) {
QVector<DataType> container = generateData<DataType>(dataSetType, size); QVector<DataType> container = generateData<DataType>(dataSetType, size);
results.append(testRun(container, algorithm, time)); results.append(testRun(container, algorithm, time));
Q_ASSERT(isSorted(container)); if (!isSorted(container))
qWarning("%s: container is not sorted after test", Q_FUNC_INFO);
} }
return results; return results;
} }

View File

@ -116,8 +116,7 @@ tst_QAtomicInt::~tst_QAtomicInt()
void tst_QAtomicInt::warningFreeHelper() void tst_QAtomicInt::warningFreeHelper()
{ {
Q_ASSERT(false); qFatal("This code is bogus, and shouldn't be run. We're looking for compiler warnings only.");
// The code below is bogus, and shouldn't be run. We're looking for warnings, only.
QBasicAtomicInt i = Q_BASIC_ATOMIC_INITIALIZER(0); QBasicAtomicInt i = Q_BASIC_ATOMIC_INITIALIZER(0);

View File

@ -98,8 +98,7 @@ struct WFHC
void tst_QAtomicPointer::warningFreeHelper() void tst_QAtomicPointer::warningFreeHelper()
{ {
Q_ASSERT(false); qFatal("This code is bogus, and shouldn't be run. We're looking for compiler warnings only.");
// The code below is bogus, and shouldn't be run. We're looking for warnings, only.
QBasicAtomicPointer<WFHC> p = Q_BASIC_ATOMIC_INITIALIZER(0); QBasicAtomicPointer<WFHC> p = Q_BASIC_ATOMIC_INITIALIZER(0);

View File

@ -309,8 +309,7 @@ void tst_QBuffer::seekTest()
// (see Task 184730) // (see Task 184730)
{ {
char c; char c;
const int offset = 1; const int offset = 1; // any positive integer will do
Q_ASSERT(offset > 0); // any positive integer will do
const qint64 pos = buf.size() + offset; const qint64 pos = buf.size() + offset;
QVERIFY(buf.seek(pos)); QVERIFY(buf.seek(pos));
QCOMPARE(buf.pos(), pos); QCOMPARE(buf.pos(), pos);

View File

@ -548,14 +548,14 @@ void tst_QChar::normalization_data()
QList<QByteArray> l = line.split(';'); QList<QByteArray> l = line.split(';');
Q_ASSERT(l.size() == 5); QCOMPARE(l.size(), 5);
QStringList columns; QStringList columns;
for (int i = 0; i < 5; ++i) { for (int i = 0; i < 5; ++i) {
columns.append(QString()); columns.append(QString());
QList<QByteArray> c = l.at(i).split(' '); QList<QByteArray> c = l.at(i).split(' ');
Q_ASSERT(!c.isEmpty()); QVERIFY(!c.isEmpty());
for (int j = 0; j < c.size(); ++j) { for (int j = 0; j < c.size(); ++j) {
bool ok; bool ok;

View File

@ -277,7 +277,9 @@ retry:
case 'L': row = completer->completionCount() - 1; break; case 'L': row = completer->completionCount() - 1; break;
case 'F': row = 0; break; case 'F': row = 0; break;
default: default:
Q_ASSERT(false); QFAIL(qPrintable(QString(
"Problem with 'step' value in test data: %1 (only P, N, L and F are allowed)."
).arg(step[i])));
} }
completer->setCurrentRow(row); completer->setCurrentRow(row);
} }
@ -1248,9 +1250,7 @@ public:
void tst_QCompleter::task189564_omitNonSelectableItems() void tst_QCompleter::task189564_omitNonSelectableItems()
{ {
const QString prefix("a"); const QString prefix("a");
Q_ASSERT(!prefix.isEmpty());
const int n = 5; const int n = 5;
Q_ASSERT(n > 0);
QStringList strings; QStringList strings;
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i)
@ -1278,11 +1278,12 @@ public:
{ {
setEditable(true); setEditable(true);
setInsertPolicy(NoInsert); setInsertPolicy(NoInsert);
Q_ASSERT(completer()); if (completer()) {
completer()->setCompletionMode(QCompleter::PopupCompletion); completer()->setCompletionMode(QCompleter::PopupCompletion);
completer()->setCompletionRole(Qt::DisplayRole); completer()->setCompletionRole(Qt::DisplayRole);
connect(lineEdit(), SIGNAL(editingFinished()), SLOT(setCompletionPrefix())); connect(lineEdit(), SIGNAL(editingFinished()), SLOT(setCompletionPrefix()));
} }
}
private slots: private slots:
void setCompletionPrefix() { completer()->setCompletionPrefix(lineEdit()->text()); } void setCompletionPrefix() { completer()->setCompletionPrefix(lineEdit()->text()); }
}; };
@ -1290,6 +1291,7 @@ private slots:
void tst_QCompleter::task246056_setCompletionPrefix() void tst_QCompleter::task246056_setCompletionPrefix()
{ {
task246056_ComboBox *comboBox = new task246056_ComboBox; task246056_ComboBox *comboBox = new task246056_ComboBox;
QVERIFY(comboBox->completer());
comboBox->addItem(""); comboBox->addItem("");
comboBox->addItem("a1"); comboBox->addItem("a1");
comboBox->addItem("a2"); comboBox->addItem("a2");

View File

@ -49,7 +49,11 @@ int main(int argc, char** argv)
#ifdef Q_WS_QWS #ifdef Q_WS_QWS
QApplication app(argc, argv); QApplication app(argc, argv);
QStringList args = app.arguments(); QStringList args = app.arguments();
Q_ASSERT(args.count() == 3 || args.count() == 4); if (args.count() != 3 && args.count() != 4) {
fprintf(stdout,qPrintable(QString("Usage: %1 channel message [data]").arg(args.at(0))));
fflush(stdout);
return 1;
}
QString channelName = args.at(1); QString channelName = args.at(1);
QString msg = args.at(2); QString msg = args.at(2);
QByteArray data; QByteArray data;

View File

@ -2701,17 +2701,10 @@ void tst_QDateTimeEdit::task98554()
QCOMPARE(testWidget->time(), QTime(0, 0, 10, 0)); QCOMPARE(testWidget->time(), QTime(0, 0, 10, 0));
} }
static QList<int> makeList(int val1, int val2 = -1, int val3 = -1, int val4 = -1, int val5 = -1, int val6 = -1, int val7 = -1) static QList<int> makeList(int val1, int val2, int val3)
{ {
QList<int> ret; QList<int> ret;
Q_ASSERT(val1 >= 0); ret << val1 << val2 << val3;
ret << val1;
if (val2 < 0) {return ret;} else {ret << val2;}
if (val3 < 0) {return ret;} else {ret << val3;}
if (val4 < 0) {return ret;} else {ret << val4;}
if (val5 < 0) {return ret;} else {ret << val5;}
if (val6 < 0) {return ret;} else {ret << val6;}
if (val7 >= 0) {ret << val2;}
return ret; return ret;
} }
@ -2753,7 +2746,7 @@ void tst_QDateTimeEdit::setCurrentSection()
QFETCH(QList<int>, setCurrentSections); QFETCH(QList<int>, setCurrentSections);
QFETCH(QList<int>, expectedCursorPositions); QFETCH(QList<int>, expectedCursorPositions);
Q_ASSERT(setCurrentSections.size() == expectedCursorPositions.size()); QCOMPARE(setCurrentSections.size(), expectedCursorPositions.size());
testWidget->setDisplayFormat(format); testWidget->setDisplayFormat(format);
testWidget->setDateTime(dateTime); testWidget->setDateTime(dateTime);
#ifdef Q_WS_MAC #ifdef Q_WS_MAC

View File

@ -592,7 +592,7 @@ void tst_QDBusThreading::callbackInAnotherAuxThread()
// wait for the event loop // wait for the event loop
sem1.release(); sem1.release();
sem2.acquire(); sem2.acquire();
Q_ASSERT(loop); QVERIFY(loop);
// create the second thread // create the second thread
new Thread; new Thread;

View File

@ -641,10 +641,10 @@ void tst_QDirModel::filter()
QDirModel model; QDirModel model;
model.setNameFilters(QStringList() << "*.nada"); model.setNameFilters(QStringList() << "*.nada");
QModelIndex index = model.index(SRCDIR "test"); QModelIndex index = model.index(SRCDIR "test");
Q_ASSERT(model.rowCount(index) == 0); QCOMPARE(model.rowCount(index), 0);
QModelIndex index2 = model.index(SRCDIR "test/file01.tst"); QModelIndex index2 = model.index(SRCDIR "test/file01.tst");
Q_ASSERT(!index2.isValid()); QVERIFY(!index2.isValid());
Q_ASSERT(model.rowCount(index) == 0); QCOMPARE(model.rowCount(index), 0);
} }
void tst_QDirModel::task244669_remove() void tst_QDirModel::task244669_remove()

View File

@ -137,7 +137,6 @@ private slots:
private: private:
static QDomDocument generateRequest(); static QDomDocument generateRequest();
static QDomDocument doc(const QString &title, const QByteArray &ba);
static int hasAttributesHelper( const QDomNode& node ); static int hasAttributesHelper( const QDomNode& node );
static bool compareDocuments( const QDomDocument &doc1, const QDomDocument &doc2 ); static bool compareDocuments( const QDomDocument &doc1, const QDomDocument &doc2 );
static bool compareNodes( const QDomNode &node1, const QDomNode &node2, bool deep ); static bool compareNodes( const QDomNode &node1, const QDomNode &node2, bool deep );
@ -1591,14 +1590,6 @@ void tst_QDom::reportDuplicateAttributes() const
QVERIFY2(!isSuccess, "Duplicate attributes are well-formedness errors, and should be reported as such."); QVERIFY2(!isSuccess, "Duplicate attributes are well-formedness errors, and should be reported as such.");
} }
QDomDocument tst_QDom::doc(const QString &title, const QByteArray &ba)
{
QDomDocument doc(title);
const bool ret = doc.setContent(ba, true);
Q_ASSERT(ret);
return doc;
}
void tst_QDom::namespacedAttributes() const void tst_QDom::namespacedAttributes() const
{ {
static const char *const xml = static const char *const xml =
@ -1611,8 +1602,13 @@ void tst_QDom::namespacedAttributes() const
" <Title displayLabel='Title' >>>> SIMPLE BASIC OP - SEND - DUT AS SINK</Title>\n" " <Title displayLabel='Title' >>>> SIMPLE BASIC OP - SEND - DUT AS SINK</Title>\n"
"</xan:td>\n"; "</xan:td>\n";
QDomDocument one = doc("document", xml); QDomDocument one("document");
QDomDocument two = doc("document2", one.toByteArray(2)); QString error;
bool docParsed = one.setContent(QByteArray(xml), true, &error);
QVERIFY2(docParsed, qPrintable(error));
QDomDocument two("document2");
docParsed = two.setContent(one.toByteArray(2), true, &error);
QVERIFY2(docParsed, qPrintable(error));
QVERIFY(isDeepEqual(one, two)); QVERIFY(isDeepEqual(one, two));
} }

View File

@ -160,13 +160,10 @@ static inline void appendRaw(QByteArray &array, T data)
*/ */
static inline void topUpWith(QByteArray &array, QByteArray filler, int size) static inline void topUpWith(QByteArray &array, QByteArray filler, int size)
{ {
Q_ASSERT(filler.size() > 0);
for (int i = (size - array.size()) / filler.size(); i > 0; --i) for (int i = (size - array.size()) / filler.size(); i > 0; --i)
array.append(filler); array.append(filler);
if (array.size() < size) { if (array.size() < size) {
Q_ASSERT(size - array.size() < filler.size());
array.append(filler.left(size - array.size())); array.append(filler.left(size - array.size()));
} }
} }
@ -206,15 +203,12 @@ static inline QByteArray generateDataBlock(int blockSize, QString text, qint64 u
QByteArray filler("0123456789"); QByteArray filler("0123456789");
block.append(filler.right(10 - block.size() % 10)); block.append(filler.right(10 - block.size() % 10));
topUpWith(block, filler, blockSize - 2 * sizeof(qint64)); topUpWith(block, filler, blockSize - 3 * sizeof(qint64));
appendRaw(block, counter); appendRaw(block, counter);
appendRaw(block, userBits); appendRaw(block, userBits);
appendRaw(block, randomBits); appendRaw(block, randomBits);
Q_ASSERT( block.size() >= blockSize );
block.resize(blockSize);
++counter; ++counter;
return block; return block;
} }

View File

@ -812,7 +812,7 @@ void tst_QFileDialog2::task239706_editableFilterCombo()
break; break;
} }
} }
Q_ASSERT(filterCombo); QVERIFY(filterCombo);
filterCombo->setEditable(true); filterCombo->setEditable(true);
QTest::mouseClick(filterCombo, Qt::LeftButton); QTest::mouseClick(filterCombo, Qt::LeftButton);
QTest::keyPress(filterCombo, Qt::Key_X); QTest::keyPress(filterCombo, Qt::Key_X);

View File

@ -132,33 +132,32 @@ static void setAnchor(QGraphicsAnchorLayout *l,
anchor->setSpacing(spacing); anchor->setSpacing(spacing);
} }
static bool checkReverseDirection(QGraphicsWidget *w) static bool checkReverseDirection(QGraphicsWidget *widget)
{ {
QGraphicsLayout *l = w->layout(); QGraphicsLayout *layout = widget->layout();
Q_ASSERT(l);
qreal left, top, right, bottom; qreal left, top, right, bottom;
l->getContentsMargins(&left, &top, &right, &bottom); layout->getContentsMargins(&left, &top, &right, &bottom);
w->setLayoutDirection(Qt::LeftToRight); widget->setLayoutDirection(Qt::LeftToRight);
QApplication::processEvents(); QApplication::processEvents();
const QRectF lg = l->geometry(); const QRectF layoutGeometry = layout->geometry();
QMap<QGraphicsLayoutItem *, QRectF> geometries; QMap<QGraphicsLayoutItem *, QRectF> geometries;
for (int i = 0; i < l->count(); ++i) { for (int i = 0; i < layout->count(); ++i) {
QGraphicsLayoutItem *w = l->itemAt(i); QGraphicsLayoutItem *item = layout->itemAt(i);
geometries.insert(w, w->geometry()); geometries.insert(item, item->geometry());
} }
w->setLayoutDirection(Qt::RightToLeft); widget->setLayoutDirection(Qt::RightToLeft);
QApplication::processEvents(); QApplication::processEvents();
lg.adjusted(+right, +top, -left, -bottom); layoutGeometry.adjusted(+right, +top, -left, -bottom);
for (int i = 0; i < l->count(); ++i) { for (int i = 0; i < layout->count(); ++i) {
QGraphicsLayoutItem *w = l->itemAt(i); QGraphicsLayoutItem *item = layout->itemAt(i);
const QRectF rtlGeom = w->geometry(); const QRectF rightToLeftGeometry = item->geometry();
const QRectF ltrGeom = geometries.value(w); const QRectF leftToRightGeometry = geometries.value(item);
QRectF expectedGeom = ltrGeom; QRectF expectedGeometry = leftToRightGeometry;
expectedGeom.moveRight(lg.right() - (0 + ltrGeom.left())); expectedGeometry.moveRight(layoutGeometry.right() - leftToRightGeometry.left());
if (expectedGeom != rtlGeom) { if (expectedGeometry != rightToLeftGeometry) {
qDebug() << "layout->geometry():" << lg qDebug() << "layout->geometry():" << layoutGeometry
<< "expected:" << expectedGeom << "expected:" << expectedGeometry
<< "actual:" << rtlGeom; << "actual:" << rightToLeftGeometry;
return false; return false;
} }
} }
@ -345,6 +344,7 @@ void tst_QGraphicsAnchorLayout::layoutDirection()
p->show(); p->show();
view->show(); view->show();
QVERIFY(p->layout());
QCOMPARE(checkReverseDirection(p), true); QCOMPARE(checkReverseDirection(p), true);
if (hasSimplification) { if (hasSimplification) {
@ -445,6 +445,7 @@ void tst_QGraphicsAnchorLayout::diagonal()
QVERIFY(!usedSimplex(l, Qt::Vertical)); QVERIFY(!usedSimplex(l, Qt::Vertical));
} }
QVERIFY(p.layout());
QCOMPARE(checkReverseDirection(&p), true); QCOMPARE(checkReverseDirection(&p), true);
c->setMinimumWidth(300); c->setMinimumWidth(300);
@ -735,6 +736,7 @@ void tst_QGraphicsAnchorLayout::snakeOppositeDirections()
QCOMPARE(c->geometry(), QRectF(90.0, 200.0, 100.0, 100.0)); QCOMPARE(c->geometry(), QRectF(90.0, 200.0, 100.0, 100.0));
QCOMPARE(p.size(), layoutMaximumSize); QCOMPARE(p.size(), layoutMaximumSize);
QVERIFY(p.layout());
QCOMPARE(checkReverseDirection(&p), true); QCOMPARE(checkReverseDirection(&p), true);
} }

View File

@ -2585,15 +2585,11 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution_data()
sizeHints1.insert( Qt::MinimumSize, 30 ); sizeHints1.insert( Qt::MinimumSize, 30 );
sizeHints1.insert( Qt::PreferredSize, 35 ); sizeHints1.insert( Qt::PreferredSize, 35 );
sizeHints1.insert( Qt::MaximumSize, 40 ); sizeHints1.insert( Qt::MaximumSize, 40 );
Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
SizeHintArray sizeHints2; SizeHintArray sizeHints2;
sizeHints2.insert( Qt::MinimumSize, 5 ); sizeHints2.insert( Qt::MinimumSize, 5 );
sizeHints2.insert( Qt::PreferredSize, 35 ); sizeHints2.insert( Qt::PreferredSize, 35 );
sizeHints2.insert( Qt::MaximumSize, 300 ); sizeHints2.insert( Qt::MaximumSize, 300 );
Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
const qreal width1 = 35; const qreal width1 = 35;
const qreal width2 = 100-10-10-10-width1; const qreal width2 = 100-10-10-10-width1;
@ -2605,15 +2601,11 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution_data()
sizeHints1.insert( Qt::MinimumSize, 0 ); sizeHints1.insert( Qt::MinimumSize, 0 );
sizeHints1.insert( Qt::PreferredSize, 20 ); sizeHints1.insert( Qt::PreferredSize, 20 );
sizeHints1.insert( Qt::MaximumSize, 100 ); sizeHints1.insert( Qt::MaximumSize, 100 );
Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
SizeHintArray sizeHints2; SizeHintArray sizeHints2;
sizeHints2.insert( Qt::MinimumSize, 0 ); sizeHints2.insert( Qt::MinimumSize, 0 );
sizeHints2.insert( Qt::PreferredSize, 50 ); sizeHints2.insert( Qt::PreferredSize, 50 );
sizeHints2.insert( Qt::MaximumSize, 100 ); sizeHints2.insert( Qt::MaximumSize, 100 );
Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
const qreal width1 = 20; const qreal width1 = 20;
const qreal width2 = 100-10-10-10-width1; const qreal width2 = 100-10-10-10-width1;
@ -2625,15 +2617,11 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution_data()
sizeHints1.insert( Qt::MinimumSize, 0 ); sizeHints1.insert( Qt::MinimumSize, 0 );
sizeHints1.insert( Qt::PreferredSize, 40 ); sizeHints1.insert( Qt::PreferredSize, 40 );
sizeHints1.insert( Qt::MaximumSize, 100 ); sizeHints1.insert( Qt::MaximumSize, 100 );
Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
SizeHintArray sizeHints2; SizeHintArray sizeHints2;
sizeHints2.insert( Qt::MinimumSize, 0 ); sizeHints2.insert( Qt::MinimumSize, 0 );
sizeHints2.insert( Qt::PreferredSize, 60 ); sizeHints2.insert( Qt::PreferredSize, 60 );
sizeHints2.insert( Qt::MaximumSize, 100 ); sizeHints2.insert( Qt::MaximumSize, 100 );
Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
const qreal width1 = 28; // got from manual calculation const qreal width1 = 28; // got from manual calculation
const qreal width2 = 100-10-10-10-width1; const qreal width2 = 100-10-10-10-width1;
@ -2645,15 +2633,11 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution_data()
sizeHints1.insert( Qt::MinimumSize, 0 ); sizeHints1.insert( Qt::MinimumSize, 0 );
sizeHints1.insert( Qt::PreferredSize, 10 ); sizeHints1.insert( Qt::PreferredSize, 10 );
sizeHints1.insert( Qt::MaximumSize, 100 ); sizeHints1.insert( Qt::MaximumSize, 100 );
Q_ASSERT( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
SizeHintArray sizeHints2; SizeHintArray sizeHints2;
sizeHints2.insert( Qt::MinimumSize, 0 ); sizeHints2.insert( Qt::MinimumSize, 0 );
sizeHints2.insert( Qt::PreferredSize, 40 ); sizeHints2.insert( Qt::PreferredSize, 40 );
sizeHints2.insert( Qt::MaximumSize, 100 ); sizeHints2.insert( Qt::MaximumSize, 100 );
Q_ASSERT( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
Q_ASSERT( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
const qreal width1 = 22; // got from manual calculation const qreal width1 = 22; // got from manual calculation
const qreal width2 = 100-10-10-10-width1; const qreal width2 = 100-10-10-10-width1;
@ -2669,6 +2653,12 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution()
QFETCH(qreal, width1); QFETCH(qreal, width1);
QFETCH(qreal, width2); QFETCH(qreal, width2);
// sanity-check the test data - MinimumSize <= PreferredSize <= MaximumSize
QVERIFY( sizeHints1.value( Qt::MinimumSize ) <= sizeHints1.value( Qt::PreferredSize ) );
QVERIFY( sizeHints1.value( Qt::PreferredSize ) <= sizeHints1.value( Qt::MaximumSize ) );
QVERIFY( sizeHints2.value( Qt::MinimumSize ) <= sizeHints2.value( Qt::PreferredSize ) );
QVERIFY( sizeHints2.value( Qt::PreferredSize ) <= sizeHints2.value( Qt::MaximumSize ) );
// create objects // create objects
QGraphicsWidget widget; QGraphicsWidget widget;
TheAnchorLayout *layout = new TheAnchorLayout; TheAnchorLayout *layout = new TheAnchorLayout;

View File

@ -3018,39 +3018,6 @@ static QSizeF wfh(Qt::SizeHint /*which*/, const QSizeF &constraint)
return result; return result;
} }
static qreal growthFactorBelowPreferredSize(qreal desired, qreal sumAvailable, qreal sumDesired)
{
Q_ASSERT(sumDesired != 0.0);
return desired * qPow(sumAvailable / sumDesired, desired / sumDesired);
}
static void expectedWidth(qreal minSize1, qreal prefSize1,
qreal minSize2, qreal prefSize2,
qreal targetSize, qreal *width1, qreal *width2)
{
qreal sumAvail,factor1,factor2;
// stretch behaviour is different below and above preferred size...
if (targetSize < prefSize1 + prefSize2) {
sumAvail = targetSize - minSize1 - minSize2;
const qreal desired1 = prefSize1 - minSize1;
const qreal desired2 = prefSize2 - minSize2;
const qreal sumDesired = desired1 + desired2;
factor1 = growthFactorBelowPreferredSize(desired1, sumAvail, sumDesired);
factor2 = growthFactorBelowPreferredSize(desired2, sumAvail, sumDesired);
const qreal sumFactors = factor1 + factor2;
*width1 = sumAvail*factor1/sumFactors + minSize1;
*width2 = sumAvail*factor2/sumFactors + minSize2;
} else {
sumAvail = targetSize - prefSize1 - prefSize2;
factor1 = prefSize1;
factor2 = prefSize2;
const qreal sumFactors = factor1 + factor2;
*width1 = sumAvail*factor1/sumFactors + prefSize1;
*width2 = sumAvail*factor2/sumFactors + prefSize2;
}
}
bool qFuzzyCompare(const QSizeF &a, const QSizeF &b) bool qFuzzyCompare(const QSizeF &a, const QSizeF &b)
{ {
return qFuzzyCompare(a.width(), b.width()) && qFuzzyCompare(a.height(), b.height()); return qFuzzyCompare(a.width(), b.width()) && qFuzzyCompare(a.height(), b.height());

View File

@ -10732,7 +10732,7 @@ void tst_QGraphicsItem::deviceCoordinateCache_simpleRotations()
QTRY_VERIFY(view.repaints > 0); QTRY_VERIFY(view.repaints > 0);
QGraphicsItemCache *itemCache = QGraphicsItemPrivate::get(item)->extraItemCache(); QGraphicsItemCache *itemCache = QGraphicsItemPrivate::get(item)->extraItemCache();
Q_ASSERT(itemCache); QVERIFY(itemCache);
QPixmapCache::Key currentKey = itemCache->deviceData.value(view.viewport()).key; QPixmapCache::Key currentKey = itemCache->deviceData.value(view.viewport()).key;
// Trigger an update and verify that the cache is unchanged. // Trigger an update and verify that the cache is unchanged.

View File

@ -3594,7 +3594,7 @@ void tst_QGraphicsScene::task160653_selectionChanged()
item->flags() | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); item->flags() | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable);
item->setSelected(true); item->setSelected(true);
} }
Q_ASSERT(scene.items().size() > 1); QVERIFY(scene.items().size() > 1);
QCOMPARE(scene.items().size(), scene.selectedItems().size()); QCOMPARE(scene.items().size(), scene.selectedItems().size());
QSignalSpy spy(&scene, SIGNAL(selectionChanged())); QSignalSpy spy(&scene, SIGNAL(selectionChanged()));

View File

@ -1106,7 +1106,7 @@ void tst_QHeaderView::moveAndInsertSection()
void tst_QHeaderView::resizeMode() void tst_QHeaderView::resizeMode()
{ {
// Q_ASSERT's when resizeMode is called with an invalid index // resizeMode must not be called with an invalid index
int last = view->count() - 1; int last = view->count() - 1;
view->setResizeMode(QHeaderView::Interactive); view->setResizeMode(QHeaderView::Interactive);
QCOMPARE(view->resizeMode(last), QHeaderView::Interactive); QCOMPARE(view->resizeMode(last), QHeaderView::Interactive);

View File

@ -193,12 +193,12 @@ void testGetNumeric(QInputDialog *dialog, SpinBoxType * = 0, ValueType * = 0)
void testGetText(QInputDialog *dialog) void testGetText(QInputDialog *dialog)
{ {
QLineEdit *ledit = qFindChild<QLineEdit *>(dialog); QLineEdit *ledit = qFindChild<QLineEdit *>(dialog);
Q_ASSERT(ledit); QVERIFY(ledit);
QDialogButtonBox *bbox = qFindChild<QDialogButtonBox *>(dialog); QDialogButtonBox *bbox = qFindChild<QDialogButtonBox *>(dialog);
Q_ASSERT(bbox); QVERIFY(bbox);
QPushButton *okButton = bbox->button(QDialogButtonBox::Ok); QPushButton *okButton = bbox->button(QDialogButtonBox::Ok);
Q_ASSERT(okButton); QVERIFY(okButton);
QVERIFY(ledit->hasAcceptableInput()); QVERIFY(ledit->hasAcceptableInput());
QCOMPARE(ledit->selectedText(), ledit->text()); QCOMPARE(ledit->selectedText(), ledit->text());
@ -211,12 +211,12 @@ void testGetText(QInputDialog *dialog)
void testGetItem(QInputDialog *dialog) void testGetItem(QInputDialog *dialog)
{ {
QComboBox *cbox = qFindChild<QComboBox *>(dialog); QComboBox *cbox = qFindChild<QComboBox *>(dialog);
Q_ASSERT(cbox); QVERIFY(cbox);
QDialogButtonBox *bbox = qFindChild<QDialogButtonBox *>(dialog); QDialogButtonBox *bbox = qFindChild<QDialogButtonBox *>(dialog);
Q_ASSERT(bbox); QVERIFY(bbox);
QPushButton *okButton = bbox->button(QDialogButtonBox::Ok); QPushButton *okButton = bbox->button(QDialogButtonBox::Ok);
Q_ASSERT(okButton); QVERIFY(okButton);
QVERIFY(okButton->isEnabled()); QVERIFY(okButton->isEnabled());
const int origIndex = cbox->currentIndex(); const int origIndex = cbox->currentIndex();
@ -249,7 +249,7 @@ void tst_QInputDialog::timerEvent(QTimerEvent *event)
{ {
killTimer(event->timerId()); killTimer(event->timerId());
QInputDialog *dialog = qFindChild<QInputDialog *>(parent); QInputDialog *dialog = qFindChild<QInputDialog *>(parent);
Q_ASSERT(dialog); QVERIFY(dialog);
if (testFunc) if (testFunc)
testFunc(dialog); testFunc(dialog);
dialog->done(doneCode); // cause static function call to return dialog->done(doneCode); // cause static function call to return
@ -270,7 +270,7 @@ void tst_QInputDialog::getInteger()
{ {
QFETCH(int, min); QFETCH(int, min);
QFETCH(int, max); QFETCH(int, max);
Q_ASSERT(min < max); QVERIFY(min < max);
parent = new QWidget; parent = new QWidget;
doneCode = QDialog::Accepted; doneCode = QDialog::Accepted;
testFunc = &tst_QInputDialog::testFuncGetInteger; testFunc = &tst_QInputDialog::testFuncGetInteger;
@ -310,7 +310,7 @@ void tst_QInputDialog::getDouble()
QFETCH(double, min); QFETCH(double, min);
QFETCH(double, max); QFETCH(double, max);
QFETCH(int, decimals); QFETCH(int, decimals);
Q_ASSERT(min < max && decimals >= 0 && decimals <= 13); QVERIFY(min < max && decimals >= 0 && decimals <= 13);
parent = new QWidget; parent = new QWidget;
doneCode = QDialog::Accepted; doneCode = QDialog::Accepted;
testFunc = &tst_QInputDialog::testFuncGetDouble; testFunc = &tst_QInputDialog::testFuncGetDouble;

View File

@ -227,7 +227,6 @@ QAbstractItemModel *ModelsToTest::createModel(const QString &modelType)
return widget->model(); return widget->model();
} }
Q_ASSERT(false);
return 0; return 0;
} }
@ -309,15 +308,23 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
*/ */
} }
QModelIndex returnIndex = model->index(0,0); QModelIndex returnIndex = model->index(0,0);
Q_ASSERT(returnIndex.isValid()); if (!returnIndex.isValid())
qFatal("%s: model index to be returned is invalid", Q_FUNC_INFO);
return returnIndex; return returnIndex;
} }
if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) { if (QDirModel *dirModel = qobject_cast<QDirModel *>(model)) {
// Don't risk somthing bad happening, assert if this fails if (!QDir::current().mkdir("test"))
Q_ASSERT(QDir(QDir::currentPath()).mkdir("test")); qFatal("%s: cannot create directory %s",
for (int i = 0; i < 26; ++i) Q_FUNC_INFO,
Q_ASSERT(QDir(QDir::currentPath()).mkdir(QString("test/foo_%1").arg(i))); qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/test")));
for (int i = 0; i < 26; ++i) {
QString subdir = QString("test/foo_%1").arg(i);
if (!QDir::current().mkdir(subdir))
qFatal("%s: cannot create directory %s",
Q_FUNC_INFO,
qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/"+subdir)));
}
return dirModel->index(QDir::currentPath()+"/test"); return dirModel->index(QDir::currentPath()+"/test");
} }
@ -373,7 +380,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model)
return QModelIndex(); return QModelIndex();
} }
Q_ASSERT(false); qFatal("%s: unknown type of model", Q_FUNC_INFO);
return QModelIndex(); return QModelIndex();
} }
@ -387,9 +394,17 @@ void ModelsToTest::cleanupTestArea(QAbstractItemModel *model)
{ {
if (QDir(QDir::currentPath()+"/test").exists()) if (QDir(QDir::currentPath()+"/test").exists())
{ {
for (int i = 0; i < 26; ++i) for (int i = 0; i < 26; ++i) {
QDir::current().rmdir(QString("test/foo_%1").arg(i)); QString subdir(QString("test/foo_%1").arg(i));
Q_ASSERT(QDir::current().rmdir("test")); if (!QDir::current().rmdir(subdir))
qFatal("%s: cannot remove directory %s",
Q_FUNC_INFO,
qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/"+subdir)));
}
if (!QDir::current().rmdir("test"))
qFatal("%s: cannot remove directory %s",
Q_FUNC_INFO,
qPrintable(QDir::toNativeSeparators(QDir::currentPath()+"/test")));
} }
} else if (qobject_cast<QSqlQueryModel *>(model)) { } else if (qobject_cast<QSqlQueryModel *>(model)) {
QSqlQuery q("DROP TABLE test"); QSqlQuery q("DROP TABLE test");

View File

@ -199,6 +199,7 @@ void tst_QItemModel::nonDestructiveBasicTest()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QCOMPARE(currentModel->buddy(QModelIndex()), QModelIndex()); QCOMPARE(currentModel->buddy(QModelIndex()), QModelIndex());
currentModel->canFetchMore(QModelIndex()); currentModel->canFetchMore(QModelIndex());
@ -244,6 +245,7 @@ void tst_QItemModel::rowCount()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QFETCH(bool, isEmpty); QFETCH(bool, isEmpty);
if (isEmpty) { if (isEmpty) {
@ -291,6 +293,7 @@ void tst_QItemModel::columnCount()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QFETCH(bool, isEmpty); QFETCH(bool, isEmpty);
if (isEmpty) { if (isEmpty) {
@ -325,6 +328,7 @@ void tst_QItemModel::hasIndex()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
// Make sure that invalid values returns an invalid index // Make sure that invalid values returns an invalid index
QCOMPARE(currentModel->hasIndex(-2, -2), false); QCOMPARE(currentModel->hasIndex(-2, -2), false);
@ -359,6 +363,7 @@ void tst_QItemModel::index()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
// Make sure that invalid values returns an invalid index // Make sure that invalid values returns an invalid index
QCOMPARE(currentModel->index(-2, -2), QModelIndex()); QCOMPARE(currentModel->index(-2, -2), QModelIndex());
@ -489,6 +494,7 @@ void tst_QItemModel::parent()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
// Make sure the model wont crash and will return an invalid QModelIndex // Make sure the model wont crash and will return an invalid QModelIndex
// when asked for the parent of an invalid index. // when asked for the parent of an invalid index.
@ -538,6 +544,7 @@ void tst_QItemModel::data()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
// Invalid index should return an invalid qvariant // Invalid index should return an invalid qvariant
QVERIFY(!currentModel->data(QModelIndex()).isValid()); QVERIFY(!currentModel->data(QModelIndex()).isValid());
@ -618,6 +625,7 @@ void tst_QItemModel::setData()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
qRegisterMetaType<QModelIndex>("QModelIndex"); qRegisterMetaType<QModelIndex>("QModelIndex");
QSignalSpy spy(currentModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &))); QSignalSpy spy(currentModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)));
QCOMPARE(currentModel->setData(QModelIndex(), QVariant()), false); QCOMPARE(currentModel->setData(QModelIndex(), QVariant()), false);
@ -660,6 +668,7 @@ void tst_QItemModel::setHeaderData()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QCOMPARE(currentModel->setHeaderData(-1, Qt::Horizontal, QVariant()), false); QCOMPARE(currentModel->setHeaderData(-1, Qt::Horizontal, QVariant()), false);
QCOMPARE(currentModel->setHeaderData(-1, Qt::Vertical, QVariant()), false); QCOMPARE(currentModel->setHeaderData(-1, Qt::Vertical, QVariant()), false);
@ -708,6 +717,7 @@ void tst_QItemModel::sort()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QFETCH(bool, isEmpty); QFETCH(bool, isEmpty);
if (isEmpty) if (isEmpty)
@ -819,6 +829,7 @@ void tst_QItemModel::remove()
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QFETCH(bool, readOnly); QFETCH(bool, readOnly);
if (readOnly) if (readOnly)
@ -1160,6 +1171,7 @@ void tst_QItemModel::insert()
{ {
QFETCH(QString, modelType); QFETCH(QString, modelType);
currentModel = testModels->createModel(modelType); currentModel = testModels->createModel(modelType);
QVERIFY(currentModel);
QFETCH(bool, readOnly); QFETCH(bool, readOnly);
if (readOnly) if (readOnly)

View File

@ -148,12 +148,18 @@ public:
CheckerModel() : QStandardItemModel() {}; CheckerModel() : QStandardItemModel() {};
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const { QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const {
Q_ASSERT(index.isValid()); if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return QVariant();
}
return QStandardItemModel::data(index, role); return QStandardItemModel::data(index, role);
}; };
Qt::ItemFlags flags(const QModelIndex & index) const { Qt::ItemFlags flags(const QModelIndex & index) const {
Q_ASSERT(index.isValid()); if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return Qt::ItemFlags();
}
if (index.row() == 2 || index.row() == rowCount() - 3 if (index.row() == 2 || index.row() == rowCount() - 3
|| index.column() == 2 || index.column() == columnCount() - 3) { || index.column() == 2 || index.column() == columnCount() - 3) {
Qt::ItemFlags f = QStandardItemModel::flags(index); Qt::ItemFlags f = QStandardItemModel::flags(index);
@ -164,14 +170,26 @@ public:
}; };
QModelIndex parent ( const QModelIndex & child ) const { QModelIndex parent ( const QModelIndex & child ) const {
Q_ASSERT(child.isValid()); if (!child.isValid()) {
qWarning("%s: child index is not valid", Q_FUNC_INFO);
return QModelIndex();
}
return QStandardItemModel::parent(child); return QStandardItemModel::parent(child);
}; };
QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const { QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const {
Q_ASSERT(section >= 0); if (orientation == Qt::Horizontal
if (orientation == Qt::Horizontal) { Q_ASSERT(section <= columnCount());}; && (section < 0 || section > columnCount())) {
if (orientation == Qt::Vertical) { Q_ASSERT(section <= rowCount());}; qWarning("%s: invalid section %d, must be in range 0..%d",
Q_FUNC_INFO, section, columnCount());
return QVariant();
}
if (orientation == Qt::Vertical
&& (section < 0 || section > rowCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
Q_FUNC_INFO, section, rowCount());
return QVariant();
}
return QStandardItemModel::headerData(section, orientation, role); return QStandardItemModel::headerData(section, orientation, role);
} }
@ -180,23 +198,46 @@ public:
}; };
bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) { bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) {
Q_ASSERT(index.isValid()); if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return false;
}
return QStandardItemModel::setData(index, value, role); return QStandardItemModel::setData(index, value, role);
} }
void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) { void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) {
Q_ASSERT(column >= 0 && column <= columnCount()); if (column < 0 || column > columnCount())
qWarning("%s: invalid column %d, must be in range 0..%d",
Q_FUNC_INFO, column, columnCount());
else
QStandardItemModel::sort(column, order); QStandardItemModel::sort(column, order);
}; };
QModelIndexList match ( const QModelIndex & start, int role, const QVariant & value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const { QModelIndexList match ( const QModelIndex & start, int role, const QVariant & value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const {
Q_ASSERT(hits > 0); if (hits <= 0) {
Q_ASSERT(value.isValid()); qWarning("%s: hits must be greater than zero", Q_FUNC_INFO);
return QModelIndexList();
}
if (!value.isValid()) {
qWarning("%s: value is not valid", Q_FUNC_INFO);
return QModelIndexList();
}
return QAbstractItemModel::match(start, role, value, hits, flags); return QAbstractItemModel::match(start, role, value, hits, flags);
}; };
bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole ) { bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole ) {
Q_ASSERT(section >= 0); if (orientation == Qt::Horizontal
&& (section < 0 || section > columnCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
Q_FUNC_INFO, section, columnCount());
return false;
}
if (orientation == Qt::Vertical
&& (section < 0 || section > rowCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
Q_FUNC_INFO, section, rowCount());
return false;
}
return QAbstractItemModel::setHeaderData(section, orientation, value, role); return QAbstractItemModel::setHeaderData(section, orientation, value, role);
}; };
}; };
@ -297,9 +338,11 @@ void tst_QItemView::nonDestructiveBasicTest()
#endif #endif
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType);
QFETCH(int, vscroll); QFETCH(int, vscroll);
QFETCH(int, hscroll); QFETCH(int, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll); view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
@ -454,9 +497,11 @@ void tst_QItemView::spider()
QSKIP("This test takes too long to execute on IRIX", SkipAll); QSKIP("This test takes too long to execute on IRIX", SkipAll);
#endif #endif
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType);
QFETCH(int, vscroll); QFETCH(int, vscroll);
QFETCH(int, hscroll); QFETCH(int, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll); view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
view->setModel(treeModel); view->setModel(treeModel);
@ -489,9 +534,11 @@ void tst_QItemView::resize()
// This test needs to be re-thought out, it takes too long and // This test needs to be re-thought out, it takes too long and
// doesn't really catch theproblem. // doesn't really catch theproblem.
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType);
QFETCH(int, vscroll); QFETCH(int, vscroll);
QFETCH(int, hscroll); QFETCH(int, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll); view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
view->setModel(treeModel); view->setModel(treeModel);
@ -517,9 +564,11 @@ void tst_QItemView::visualRect()
QSKIP("This test takes too long to execute on IRIX", SkipAll); QSKIP("This test takes too long to execute on IRIX", SkipAll);
#endif #endif
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType);
QFETCH(int, vscroll); QFETCH(int, vscroll);
QFETCH(int, hscroll); QFETCH(int, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll); view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
QCOMPARE(view->visualRect(QModelIndex()), QRect()); QCOMPARE(view->visualRect(QModelIndex()), QRect());
@ -651,9 +700,11 @@ void tst_QItemView::indexAt()
QSKIP("This test takes too long to execute on IRIX", SkipAll); QSKIP("This test takes too long to execute on IRIX", SkipAll);
#endif #endif
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType);
QFETCH(int, vscroll); QFETCH(int, vscroll);
QFETCH(int, hscroll); QFETCH(int, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll); view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
view->show(); view->show();
@ -685,9 +736,11 @@ void tst_QItemView::scrollTo()
QSKIP("This test takes too long to execute on IRIX", SkipAll); QSKIP("This test takes too long to execute on IRIX", SkipAll);
#endif #endif
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType);
QFETCH(int, vscroll); QFETCH(int, vscroll);
QFETCH(int, hscroll); QFETCH(int, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll); view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll); view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
view->setModel(treeModel); view->setModel(treeModel);
@ -735,6 +788,7 @@ void tst_QItemView::moveCursor()
#endif #endif
QFETCH(QString, viewType); QFETCH(QString, viewType);
view = testViews->createView(viewType); view = testViews->createView(viewType);
QVERIFY(view);
if (view->objectName() == "QHeaderView") if (view->objectName() == "QHeaderView")
return; return;

View File

@ -141,7 +141,6 @@ QAbstractItemView *ViewsToTest::createView(const QString &viewType)
view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); view->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
view->setSelectionBehavior(QAbstractItemView::SelectItems); view->setSelectionBehavior(QAbstractItemView::SelectItems);
} }
Q_ASSERT(view);
return view; return view;
} }

View File

@ -468,7 +468,7 @@ void tst_QLibrary::errorString()
} }
break;} break;}
default: default:
Q_ASSERT(0); QFAIL(qPrintable(QString("Unknown operation: %1").arg(operation)));
break; break;
} }
QRegExp re(errorString); QRegExp re(errorString);

View File

@ -326,7 +326,7 @@ void tst_QLocale::ctor()
TEST_CTOR("en-GB", English, UnitedKingdom) TEST_CTOR("en-GB", English, UnitedKingdom)
TEST_CTOR("en-GB@bla", English, UnitedKingdom) TEST_CTOR("en-GB@bla", English, UnitedKingdom)
Q_ASSERT(QLocale::Norwegian == QLocale::NorwegianBokmal); QVERIFY(QLocale::Norwegian == QLocale::NorwegianBokmal);
TEST_CTOR("no", Norwegian, Norway) TEST_CTOR("no", Norwegian, Norway)
TEST_CTOR("nb", Norwegian, Norway) TEST_CTOR("nb", Norwegian, Norway)
TEST_CTOR("nn", NorwegianNynorsk, Norway) TEST_CTOR("nn", NorwegianNynorsk, Norway)
@ -431,7 +431,7 @@ void tst_QLocale::emptyCtor()
TEST_CTOR("en_GB@bla", "en_GB") TEST_CTOR("en_GB@bla", "en_GB")
TEST_CTOR("de", "de_DE") TEST_CTOR("de", "de_DE")
Q_ASSERT(QLocale::Norwegian == QLocale::NorwegianBokmal); QVERIFY(QLocale::Norwegian == QLocale::NorwegianBokmal);
TEST_CTOR("no", "nb_NO") TEST_CTOR("no", "nb_NO")
TEST_CTOR("nb", "nb_NO") TEST_CTOR("nb", "nb_NO")
TEST_CTOR("nn", "nn_NO") TEST_CTOR("nn", "nn_NO")

View File

@ -1,3 +1,45 @@
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
int main(int,char**) int main(int,char**)
{ {
} }

View File

@ -789,7 +789,7 @@ void tst_QMenu::task250673_activeMultiColumnSubMenuPosition()
while (main.columnCount() < 2) { while (main.columnCount() < 2) {
main.addAction(QString("Item %1").arg(i)); main.addAction(QString("Item %1").arg(i));
++i; ++i;
Q_ASSERT(i<1000); QVERIFY(i<1000);
} }
main.setActiveAction(menuAction); main.setActiveAction(menuAction);
sub.setActiveAction(subAction); sub.setActiveAction(subAction);

View File

@ -609,48 +609,43 @@ void tst_QMessageBox::testSymbols()
button = QMessageBox::FlagMask; button = QMessageBox::FlagMask;
mb1.setText("Foo"); mb1.setText("Foo");
QString text = mb1.text(); QCOMPARE(mb1.text(), "Foo");
Q_ASSERT(text == "Foo");
icon = mb1.icon(); icon = mb1.icon();
Q_ASSERT(icon == QMessageBox::NoIcon); QVERIFY(icon == QMessageBox::NoIcon);
mb1.setIcon(QMessageBox::Question); mb1.setIcon(QMessageBox::Question);
Q_ASSERT(mb1.icon() == QMessageBox::Question); QVERIFY(mb1.icon() == QMessageBox::Question);
QPixmap iconPixmap = mb1.iconPixmap(); QPixmap iconPixmap = mb1.iconPixmap();
mb1.setIconPixmap(iconPixmap); mb1.setIconPixmap(iconPixmap);
Q_ASSERT(mb1.icon() == QMessageBox::NoIcon); QVERIFY(mb1.icon() == QMessageBox::NoIcon);
QString bt0 = mb1.buttonText(QMessageBox::Ok); QCOMPARE(mb1.buttonText(QMessageBox::Ok), "OK");
QString bt1 = mb1.buttonText(QMessageBox::Cancel); QCOMPARE(mb1.buttonText(QMessageBox::Cancel), QString());
QString bt2 = mb1.buttonText(QMessageBox::Ok | QMessageBox::Default); QCOMPARE(mb1.buttonText(QMessageBox::Ok | QMessageBox::Default), QString());
Q_ASSERT(bt0 == "OK");
Q_ASSERT(bt1.isEmpty());
Q_ASSERT(bt2.isEmpty());
mb2.setButtonText(QMessageBox::Cancel, "Foo"); mb2.setButtonText(QMessageBox::Cancel, "Foo");
mb2.setButtonText(QMessageBox::Ok, "Bar"); mb2.setButtonText(QMessageBox::Ok, "Bar");
mb2.setButtonText(QMessageBox::Ok | QMessageBox::Default, "Baz"); mb2.setButtonText(QMessageBox::Ok | QMessageBox::Default, "Baz");
Q_ASSERT(mb2.buttonText(QMessageBox::Cancel).isEmpty()); QCOMPARE(mb2.buttonText(QMessageBox::Cancel), QString());
Q_ASSERT(mb2.buttonText(QMessageBox::Ok) == "Bar"); QCOMPARE(mb2.buttonText(QMessageBox::Ok), "Bar");
Q_ASSERT(mb3b.buttonText(QMessageBox::Yes).endsWith("Yes")); QVERIFY(mb3b.buttonText(QMessageBox::Yes).endsWith("Yes"));
Q_ASSERT(mb3b.buttonText(QMessageBox::YesAll).isEmpty()); QCOMPARE(mb3b.buttonText(QMessageBox::YesAll), QString());
Q_ASSERT(mb3b.buttonText(QMessageBox::Ok).isEmpty()); QCOMPARE(mb3b.buttonText(QMessageBox::Ok), QString());
mb3b.setButtonText(QMessageBox::Yes, "Blah"); mb3b.setButtonText(QMessageBox::Yes, "Blah");
mb3b.setButtonText(QMessageBox::YesAll, "Zoo"); mb3b.setButtonText(QMessageBox::YesAll, "Zoo");
mb3b.setButtonText(QMessageBox::Ok, "Zoo"); mb3b.setButtonText(QMessageBox::Ok, "Zoo");
Q_ASSERT(mb3b.buttonText(QMessageBox::Yes) == "Blah"); QCOMPARE(mb3b.buttonText(QMessageBox::Yes), "Blah");
Q_ASSERT(mb3b.buttonText(QMessageBox::YesAll).isEmpty()); QCOMPARE(mb3b.buttonText(QMessageBox::YesAll), QString());
Q_ASSERT(mb3b.buttonText(QMessageBox::Ok).isEmpty()); QCOMPARE(mb3b.buttonText(QMessageBox::Ok), QString());
Q_ASSERT(mb1.textFormat() == Qt::AutoText); QCOMPARE(mb1.textFormat(), Qt::AutoText);
mb1.setTextFormat(Qt::PlainText); mb1.setTextFormat(Qt::PlainText);
Q_ASSERT(mb1.textFormat() == Qt::PlainText); QCOMPARE(mb1.textFormat(), Qt::PlainText);
CONVENIENCE_FUNC_SYMS(information); CONVENIENCE_FUNC_SYMS(information);
CONVENIENCE_FUNC_SYMS_EXTRA(information); CONVENIENCE_FUNC_SYMS_EXTRA(information);
@ -660,7 +655,7 @@ void tst_QMessageBox::testSymbols()
CONVENIENCE_FUNC_SYMS(critical); CONVENIENCE_FUNC_SYMS(critical);
QSize sizeHint = mb1.sizeHint(); QSize sizeHint = mb1.sizeHint();
Q_ASSERT(sizeHint.width() > 20 && sizeHint.height() > 20); QVERIFY(sizeHint.width() > 20 && sizeHint.height() > 20);
#ifdef QT3_SUPPORT #ifdef QT3_SUPPORT
//test QT3_SUPPORT stuff //test QT3_SUPPORT stuff
@ -672,8 +667,8 @@ void tst_QMessageBox::testSymbols()
QPixmap pm = QMessageBox::standardIcon(QMessageBox::Question, Qt::GUIStyle(1)); QPixmap pm = QMessageBox::standardIcon(QMessageBox::Question, Qt::GUIStyle(1));
QPixmap pm2 = QMessageBox::standardIcon(QMessageBox::Question); QPixmap pm2 = QMessageBox::standardIcon(QMessageBox::Question);
Q_ASSERT(pm.toImage() == iconPixmap.toImage()); QVERIFY(pm.toImage() == iconPixmap.toImage());
Q_ASSERT(pm2.toImage() == iconPixmap.toImage()); QVERIFY(pm2.toImage() == iconPixmap.toImage());
int ret1 = QMessageBox::message("title", "text"); int ret1 = QMessageBox::message("title", "text");
int ret2 = QMessageBox::message("title", "text", "OK"); int ret2 = QMessageBox::message("title", "text", "OK");
@ -692,10 +687,10 @@ void tst_QMessageBox::testSymbols()
Q_UNUSED(ret5); Q_UNUSED(ret5);
QPixmap pm3 = QMessageBox::standardIcon(QMessageBox::NoIcon); QPixmap pm3 = QMessageBox::standardIcon(QMessageBox::NoIcon);
Q_ASSERT(pm3.isNull()); QVERIFY(pm3.isNull());
pm3 = QMessageBox::standardIcon(QMessageBox::Information); pm3 = QMessageBox::standardIcon(QMessageBox::Information);
Q_ASSERT(!pm3.isNull()); QVERIFY(!pm3.isNull());
#endif //QT3_SUPPORT #endif //QT3_SUPPORT
QMessageBox::about(&mb1, "title", "text"); QMessageBox::about(&mb1, "title", "text");

View File

@ -244,7 +244,12 @@ public:
QObject *child; QObject *child;
public slots: public slots:
void on_child1_destroyed(QObject *obj = 0) { ++invokeCount1; Q_ASSERT(obj && obj == child); } void on_child1_destroyed(QObject *obj = 0)
{
++invokeCount1;
if (!obj || obj != child)
qWarning() << "on_child1_destroyed invoked with wrong child object";
}
void on_child2_destroyed() { ++invokeCount2; } void on_child2_destroyed() { ++invokeCount2; }
}; };
@ -268,7 +273,12 @@ public:
} }
private slots: private slots:
void on_child1_destroyed(QObject *obj) { ++invokeCount1; Q_ASSERT(obj && obj == child); } void on_child1_destroyed(QObject *obj)
{
++invokeCount1;
if (!obj || obj != child)
qWarning() << "on_child1_destroyed invoked with wrong child object";
}
void on_child1_destroyed() { ++invokeCount2; } void on_child1_destroyed() { ++invokeCount2; }
}; };

View File

@ -96,10 +96,18 @@ struct Bar
Bar() Bar()
{ {
// check re-entrancy // check re-entrancy
Q_ASSERT(QMetaType::isRegistered(qRegisterMetaType<Foo>("Foo"))); if (!QMetaType::isRegistered(qRegisterMetaType<Foo>("Foo"))) {
qWarning("%s: re-entrancy test failed", Q_FUNC_INFO);
++failureCount;
} }
}
public:
static int failureCount;
}; };
int Bar::failureCount = 0;
class MetaTypeTorturer: public QThread class MetaTypeTorturer: public QThread
{ {
Q_OBJECT Q_OBJECT
@ -113,17 +121,35 @@ protected:
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
pthread_yield(); pthread_yield();
#endif #endif
Q_ASSERT(QMetaType::isRegistered(tp)); if (!QMetaType::isRegistered(tp)) {
Q_ASSERT(QMetaType::type(nm) == tp); ++failureCount;
Q_ASSERT(QMetaType::typeName(tp) == name); qWarning() << name << "is not a registered metatype";
}
if (QMetaType::type(nm) != tp) {
++failureCount;
qWarning() << "Wrong metatype returned for" << name;
}
if (QMetaType::typeName(tp) != name) {
++failureCount;
qWarning() << "Wrong typeName returned for" << tp;
}
void *buf = QMetaType::construct(tp, 0); void *buf = QMetaType::construct(tp, 0);
void *buf2 = QMetaType::construct(tp, buf); void *buf2 = QMetaType::construct(tp, buf);
Q_ASSERT(buf); if (!buf) {
Q_ASSERT(buf2); ++failureCount;
qWarning() << "Null buffer returned by QMetaType::construct(tp, 0)";
}
if (!buf2) {
++failureCount;
qWarning() << "Null buffer returned by QMetaType::construct(tp, buf)";
}
QMetaType::destroy(tp, buf); QMetaType::destroy(tp, buf);
QMetaType::destroy(tp, buf2); QMetaType::destroy(tp, buf2);
} }
} }
public:
MetaTypeTorturer() : failureCount(0) { }
int failureCount;
}; };
void tst_QMetaType::threadSafety() void tst_QMetaType::threadSafety()
@ -139,6 +165,11 @@ void tst_QMetaType::threadSafety()
QVERIFY(t1.wait()); QVERIFY(t1.wait());
QVERIFY(t2.wait()); QVERIFY(t2.wait());
QVERIFY(t3.wait()); QVERIFY(t3.wait());
QCOMPARE(t1.failureCount, 0);
QCOMPARE(t2.failureCount, 0);
QCOMPARE(t3.failureCount, 0);
QCOMPARE(Bar::failureCount, 0);
} }
namespace TestSpace namespace TestSpace

View File

@ -462,6 +462,7 @@ public:
static QBasicAtomicInt lockCount; static QBasicAtomicInt lockCount;
static QBasicAtomicInt sentinel; static QBasicAtomicInt sentinel;
static QMutex mutex; static QMutex mutex;
static int errorCount;
void start() void start()
{ {
t.start(); t.start();
@ -471,13 +472,13 @@ public:
{ {
while (t.elapsed() < one_minute) { while (t.elapsed() < one_minute) {
mutex.lock(); mutex.lock();
Q_ASSERT(!sentinel.ref()); if (sentinel.ref()) ++errorCount;
Q_ASSERT(sentinel.deref()); if (!sentinel.deref()) ++errorCount;
lockCount.ref(); lockCount.ref();
mutex.unlock(); mutex.unlock();
if (mutex.tryLock()) { if (mutex.tryLock()) {
Q_ASSERT(!sentinel.ref()); if (sentinel.ref()) ++errorCount;
Q_ASSERT(sentinel.deref()); if (!sentinel.deref()) ++errorCount;
lockCount.ref(); lockCount.ref();
mutex.unlock(); mutex.unlock();
} }
@ -487,6 +488,7 @@ public:
QMutex StressTestThread::mutex; QMutex StressTestThread::mutex;
QBasicAtomicInt StressTestThread::lockCount = Q_BASIC_ATOMIC_INITIALIZER(0); QBasicAtomicInt StressTestThread::lockCount = Q_BASIC_ATOMIC_INITIALIZER(0);
QBasicAtomicInt StressTestThread::sentinel = Q_BASIC_ATOMIC_INITIALIZER(-1); QBasicAtomicInt StressTestThread::sentinel = Q_BASIC_ATOMIC_INITIALIZER(-1);
int StressTestThread::errorCount = 0;
void tst_QMutex::stressTest() void tst_QMutex::stressTest()
{ {
@ -496,6 +498,7 @@ void tst_QMutex::stressTest()
QVERIFY(threads[0].wait(one_minute + 10000)); QVERIFY(threads[0].wait(one_minute + 10000));
for (int i = 1; i < threadCount; ++i) for (int i = 1; i < threadCount; ++i)
QVERIFY(threads[i].wait(10000)); QVERIFY(threads[i].wait(10000));
QCOMPARE(StressTestThread::errorCount, 0);
qDebug("locked %d times", int(StressTestThread::lockCount)); qDebug("locked %d times", int(StressTestThread::lockCount));
} }
@ -534,7 +537,12 @@ void tst_QMutex::tryLockRace()
TryLockRaceThread::mutex.unlock(); TryLockRaceThread::mutex.unlock();
} }
// Variable that will be protected by the mutex. Volatile so that the
// the optimiser doesn't mess with it based on the increment-then-decrement
// usage pattern.
static volatile int qtbug16115_trylock_counter; static volatile int qtbug16115_trylock_counter;
// Counter for how many times the protected variable has an incorrect value.
static int qtbug16115_failure_count = 0;
void tst_QMutex::qtbug16115_trylock() void tst_QMutex::qtbug16115_trylock()
{ {
@ -545,8 +553,10 @@ void tst_QMutex::qtbug16115_trylock()
void run() { void run() {
for (int i = 0; i < 1000000; ++i) { for (int i = 0; i < 1000000; ++i) {
if (mut.tryLock(0)) { if (mut.tryLock(0)) {
Q_ASSERT((++qtbug16115_trylock_counter) == 1); if ((++qtbug16115_trylock_counter) != 1)
Q_ASSERT((--qtbug16115_trylock_counter) == 0); ++qtbug16115_failure_count;
if ((--qtbug16115_trylock_counter) != 0)
++qtbug16115_failure_count;
mut.unlock(); mut.unlock();
} }
} }
@ -562,13 +572,16 @@ void tst_QMutex::qtbug16115_trylock()
for (int i = 0; i < 1000000; ++i) { for (int i = 0; i < 1000000; ++i) {
mut.lock(); mut.lock();
Q_ASSERT((++qtbug16115_trylock_counter) == 1); if ((++qtbug16115_trylock_counter) != 1)
Q_ASSERT((--qtbug16115_trylock_counter) == 0); ++qtbug16115_failure_count;
if ((--qtbug16115_trylock_counter) != 0)
++qtbug16115_failure_count;
mut.unlock(); mut.unlock();
} }
t1.wait(); t1.wait();
t2.wait(); t2.wait();
t3.wait(); t3.wait();
QCOMPARE(qtbug16115_failure_count, 0);
} }
QTEST_MAIN(tst_QMutex) QTEST_MAIN(tst_QMutex)

View File

@ -622,9 +622,14 @@ public:
} }
QIODevice *prepare(const QNetworkCacheMetaData &) QIODevice *prepare(const QNetworkCacheMetaData &)
{ Q_ASSERT(0 && "Should not have tried to add to the cache"); return 0; } {
qFatal("%s: Should not have tried to add to the cache", Q_FUNC_INFO);
return 0;
}
void insert(QIODevice *) void insert(QIODevice *)
{ Q_ASSERT(0 && "Should not have tried to add to the cache"); } {
qFatal("%s: Should not have tried to add to the cache", Q_FUNC_INFO);
}
void clear() { cache.clear(); } void clear() { cache.clear(); }
}; };
@ -774,7 +779,9 @@ public:
QTcpSocket* waitForNextConnectionSocket() { QTcpSocket* waitForNextConnectionSocket() {
waitForNewConnection(-1); waitForNewConnection(-1);
if (doSsl) { if (doSsl) {
Q_ASSERT(sslSocket); if (!sslSocket)
qFatal("%s: sslSocket should not be null after calling waitForNewConnection()",
Q_FUNC_INFO);
return sslSocket; return sslSocket;
} else { } else {
//qDebug() << "returning nextPendingConnection"; //qDebug() << "returning nextPendingConnection";
@ -946,7 +953,8 @@ protected:
while (dataIndex < wantedSize) { while (dataIndex < wantedSize) {
const int remainingBytes = wantedSize - measuredSentBytes; const int remainingBytes = wantedSize - measuredSentBytes;
const int bytesToWrite = qMin(remainingBytes, static_cast<int>(BlockSize)); const int bytesToWrite = qMin(remainingBytes, static_cast<int>(BlockSize));
Q_ASSERT(bytesToWrite); if (bytesToWrite <= 0)
qFatal("%s: attempt to write %d bytes", Q_FUNC_INFO, bytesToWrite);
measuredSentBytes += writeNextData(client, bytesToWrite); measuredSentBytes += writeNextData(client, bytesToWrite);
while (client->bytesToWrite() > 0) { while (client->bytesToWrite() > 0) {
@ -1005,7 +1013,8 @@ public:
// Wait for data to be readyRead // Wait for data to be readyRead
bool ok = connect(&senderObj, SIGNAL(dataReady()), this, SLOT(slotDataReady())); bool ok = connect(&senderObj, SIGNAL(dataReady()), this, SLOT(slotDataReady()));
Q_ASSERT(ok); if (!ok)
qFatal("%s: Cannot connect dataReady signal", Q_FUNC_INFO);
} }
void wrapUp() void wrapUp()
@ -1028,9 +1037,9 @@ protected:
void timerEvent(QTimerEvent *) void timerEvent(QTimerEvent *)
{ {
//qDebug() << "RateControlledReader: timerEvent bytesAvailable=" << device->bytesAvailable(); //qDebug() << "RateControlledReader: timerEvent bytesAvailable=" << device->bytesAvailable();
if (readBufferSize > 0) { if (readBufferSize > 0 && device->bytesAvailable() > readBufferSize) {
// This asserts passes all the time, except in the final flush. // This passes all the time, except in the final flush.
//Q_ASSERT(device->bytesAvailable() <= readBufferSize); //qFatal("%s: Too many bytes available", Q_FUNC_INFO);
} }
qint64 bytesRead = 0; qint64 bytesRead = 0;
@ -1189,7 +1198,7 @@ QString tst_QNetworkReply::runSimpleRequest(QNetworkAccessManager::Operation op,
break; break;
default: default:
Q_ASSERT_X(false, "tst_QNetworkReply", "Invalid/unknown operation requested"); qFatal("%s: Invalid/unknown operation requested", Q_FUNC_INFO);
} }
reply->setParent(this); reply->setParent(this);

View File

@ -69,7 +69,8 @@ void Receiver::received ()
::Step++; ::Step++;
const int stepCopy = ::Step; const int stepCopy = ::Step;
TRACE (stepCopy, "Receiver::received()"); TRACE (stepCopy, "Receiver::received()");
Q_ASSERT (::Step == 2 || ::Step == 4); if (::Step != 2 && ::Step != 4)
qFatal("%s: Incorrect Step: %d (should be 2 or 4)", Q_FUNC_INFO, ::Step);
if (::Step == 2) if (::Step == 2)
s->fire (); s->fire ();
@ -91,7 +92,8 @@ void Disconnector::received ()
::Step++; ::Step++;
const int stepCopy = ::Step; const int stepCopy = ::Step;
TRACE (stepCopy, "Disconnector::received()"); TRACE (stepCopy, "Disconnector::received()");
Q_ASSERT (::Step == 5 || ::Step == 6); if (::Step != 5 && ::Step != 6)
qFatal("%s: Incorrect Step: %d (should be 5 or 6)", Q_FUNC_INFO, ::Step);
fprintf (stderr, "Disconnector<%s>::received() sender=%s\n", fprintf (stderr, "Disconnector<%s>::received() sender=%s\n",
(const char *) objectName ().toAscii (), sender ()->metaObject()->className()); (const char *) objectName ().toAscii (), sender ()->metaObject()->className());
@ -124,7 +126,8 @@ void Sender::fire ()
::Step++; ::Step++;
const int stepCopy = ::Step; const int stepCopy = ::Step;
TRACE (stepCopy, "Sender::fire()"); TRACE (stepCopy, "Sender::fire()");
Q_ASSERT (::Step == 1 || ::Step == 3); if (::Step != 1 && ::Step != 3)
qFatal("%s: Incorrect Step: %d (should be 1 or 3)", Q_FUNC_INFO, ::Step);
emit fired (); emit fired ();
TRACE (stepCopy, "ends Sender::fire()"); TRACE (stepCopy, "ends Sender::fire()");

View File

@ -403,6 +403,8 @@ public:
} }
void reset() { void reset() {
called_slot10 = 0;
called_slot9 = 0;
called_slot8 = 0; called_slot8 = 0;
called_slot7 = 0; called_slot7 = 0;
called_slot6 = 0; called_slot6 = 0;
@ -421,6 +423,8 @@ public:
int called_slot6; int called_slot6;
int called_slot7; int called_slot7;
int called_slot8; int called_slot8;
int called_slot9;
int called_slot10;
bool called(int slot) { bool called(int slot) {
switch (slot) { switch (slot) {
@ -432,6 +436,8 @@ public:
case 6: return called_slot6; case 6: return called_slot6;
case 7: return called_slot7; case 7: return called_slot7;
case 8: return called_slot8; case 8: return called_slot8;
case 9: return called_slot9;
case 10: return called_slot10;
default: return false; default: return false;
} }
} }
@ -449,8 +455,8 @@ public slots:
void slotLoopBack() { ++called_slot8; } void slotLoopBack() { ++called_slot8; }
protected slots: protected slots:
void o() { Q_ASSERT(0); } void o() { ++called_slot9; }
void on() { Q_ASSERT(0); } void on() { ++called_slot10; }
signals: signals:
void on_Sender_signalLoopBack(); void on_Sender_signalLoopBack();
@ -473,6 +479,8 @@ void tst_QObject::connectByName()
QCOMPARE(receiver.called(6), false); QCOMPARE(receiver.called(6), false);
QCOMPARE(receiver.called(7), false); QCOMPARE(receiver.called(7), false);
QCOMPARE(receiver.called(8), false); QCOMPARE(receiver.called(8), false);
QCOMPARE(receiver.called(9), false);
QCOMPARE(receiver.called(10), false);
receiver.reset(); receiver.reset();
sender.emitSignalWithParams(0); sender.emitSignalWithParams(0);
@ -484,6 +492,8 @@ void tst_QObject::connectByName()
QCOMPARE(receiver.called(6), false); QCOMPARE(receiver.called(6), false);
QCOMPARE(receiver.called(7), false); QCOMPARE(receiver.called(7), false);
QCOMPARE(receiver.called(8), false); QCOMPARE(receiver.called(8), false);
QCOMPARE(receiver.called(9), false);
QCOMPARE(receiver.called(10), false);
receiver.reset(); receiver.reset();
sender.emitSignalWithParams(0, "string"); sender.emitSignalWithParams(0, "string");
@ -495,6 +505,8 @@ void tst_QObject::connectByName()
QCOMPARE(receiver.called(6), false); QCOMPARE(receiver.called(6), false);
QCOMPARE(receiver.called(7), false); QCOMPARE(receiver.called(7), false);
QCOMPARE(receiver.called(8), false); QCOMPARE(receiver.called(8), false);
QCOMPARE(receiver.called(9), false);
QCOMPARE(receiver.called(10), false);
receiver.reset(); receiver.reset();
sender.emitSignalManyParams(1, 2, 3, "string", true); sender.emitSignalManyParams(1, 2, 3, "string", true);
@ -506,6 +518,8 @@ void tst_QObject::connectByName()
QCOMPARE(receiver.called(6), false); QCOMPARE(receiver.called(6), false);
QCOMPARE(receiver.called(7), false); QCOMPARE(receiver.called(7), false);
QCOMPARE(receiver.called(8), false); QCOMPARE(receiver.called(8), false);
QCOMPARE(receiver.called(9), false);
QCOMPARE(receiver.called(10), false);
receiver.reset(); receiver.reset();
sender.emitSignalManyParams2(1, 2, 3, "string", true); sender.emitSignalManyParams2(1, 2, 3, "string", true);
@ -517,6 +531,8 @@ void tst_QObject::connectByName()
QCOMPARE(receiver.called(6), false); QCOMPARE(receiver.called(6), false);
QCOMPARE(receiver.called(7), true); QCOMPARE(receiver.called(7), true);
QCOMPARE(receiver.called(8), false); QCOMPARE(receiver.called(8), false);
QCOMPARE(receiver.called(9), false);
QCOMPARE(receiver.called(10), false);
receiver.reset(); receiver.reset();
sender.emitSignalLoopBack(); sender.emitSignalLoopBack();
@ -528,6 +544,8 @@ void tst_QObject::connectByName()
QCOMPARE(receiver.called(6), false); QCOMPARE(receiver.called(6), false);
QCOMPARE(receiver.called(7), false); QCOMPARE(receiver.called(7), false);
QCOMPARE(receiver.called(8), true); QCOMPARE(receiver.called(8), true);
QCOMPARE(receiver.called(9), false);
QCOMPARE(receiver.called(10), false);
receiver.reset(); receiver.reset();
} }
@ -1312,14 +1330,16 @@ public:
void customEvent(QEvent *) void customEvent(QEvent *)
{ {
Q_ASSERT(customEventThread == 0); if (customEventThread)
qFatal("%s: customEventThread should be null", Q_FUNC_INFO);
customEventThread = QThread::currentThread(); customEventThread = QThread::currentThread();
emit theSignal(); emit theSignal();
} }
void timerEvent(QTimerEvent *) void timerEvent(QTimerEvent *)
{ {
Q_ASSERT(timerEventThread == 0); if (timerEventThread)
qFatal("%s: timerEventThread should be null", Q_FUNC_INFO);
timerEventThread = QThread::currentThread(); timerEventThread = QThread::currentThread();
emit theSignal(); emit theSignal();
} }
@ -1327,7 +1347,8 @@ public:
public slots: public slots:
void theSlot() void theSlot()
{ {
Q_ASSERT(slotThread == 0); if (slotThread)
qFatal("%s: slotThread should be null", Q_FUNC_INFO);
slotThread = QThread::currentThread(); slotThread = QThread::currentThread();
emit theSignal(); emit theSignal();
} }

View File

@ -1697,8 +1697,8 @@ void tst_QPixmap::fromImageReaderAnimatedGif()
QImageReader referenceReader(path); QImageReader referenceReader(path);
QImageReader pixmapReader(path); QImageReader pixmapReader(path);
Q_ASSERT(referenceReader.canRead()); QVERIFY(referenceReader.canRead());
Q_ASSERT(referenceReader.imageCount() > 1); QVERIFY(referenceReader.imageCount() > 1);
for (int i = 0; i < referenceReader.imageCount(); ++i) { for (int i = 0; i < referenceReader.imageCount(); ++i) {
QImage refImage = referenceReader.read(); QImage refImage = referenceReader.read();

View File

@ -668,7 +668,7 @@ void tst_QProcess::exitStatus()
QSKIP("This test opens a crash dialog on Windows", SkipSingle); QSKIP("This test opens a crash dialog on Windows", SkipSingle);
#endif #endif
Q_ASSERT(processList.count() == exitStatus.count()); QCOMPARE(exitStatus.count(), processList.count());
for (int i = 0; i < processList.count(); ++i) { for (int i = 0; i < processList.count(); ++i) {
process->start(processList.at(i)); process->start(processList.at(i));
QVERIFY(process->waitForStarted(5000)); QVERIFY(process->waitForStarted(5000));

View File

@ -362,34 +362,45 @@ void tst_QReadWriteLock::tryWriteLock()
class Thread : public QThread class Thread : public QThread
{ {
public: public:
Thread() : failureCount(0) { }
void run() void run()
{ {
testsTurn.release(); testsTurn.release();
threadsTurn.acquire(); threadsTurn.acquire();
Q_ASSERT(!readWriteLock.tryLockForWrite()); if (readWriteLock.tryLockForWrite())
failureCount++;
testsTurn.release(); testsTurn.release();
threadsTurn.acquire(); threadsTurn.acquire();
Q_ASSERT(readWriteLock.tryLockForWrite()); if (!readWriteLock.tryLockForWrite())
Q_ASSERT(lockCount.testAndSetRelaxed(0, 1)); failureCount++;
Q_ASSERT(lockCount.testAndSetRelaxed(1, 0)); if (!lockCount.testAndSetRelaxed(0, 1))
failureCount++;
if (!lockCount.testAndSetRelaxed(1, 0))
failureCount++;
readWriteLock.unlock(); readWriteLock.unlock();
testsTurn.release(); testsTurn.release();
threadsTurn.acquire(); threadsTurn.acquire();
Q_ASSERT(!readWriteLock.tryLockForWrite(1000)); if (readWriteLock.tryLockForWrite(1000))
failureCount++;
testsTurn.release(); testsTurn.release();
threadsTurn.acquire(); threadsTurn.acquire();
Q_ASSERT(readWriteLock.tryLockForWrite(1000)); if (!readWriteLock.tryLockForWrite(1000))
Q_ASSERT(lockCount.testAndSetRelaxed(0, 1)); failureCount++;
Q_ASSERT(lockCount.testAndSetRelaxed(1, 0)); if (!lockCount.testAndSetRelaxed(0, 1))
failureCount++;
if (!lockCount.testAndSetRelaxed(1, 0))
failureCount++;
readWriteLock.unlock(); readWriteLock.unlock();
testsTurn.release(); testsTurn.release();
threadsTurn.acquire(); threadsTurn.acquire();
} }
int failureCount;
}; };
Thread thread; Thread thread;
@ -419,6 +430,8 @@ void tst_QReadWriteLock::tryWriteLock()
testsTurn.acquire(); testsTurn.acquire();
threadsTurn.release(); threadsTurn.release();
thread.wait(); thread.wait();
QCOMPARE(thread.failureCount, 0);
} }
} }

View File

@ -50,6 +50,7 @@
#include <QtCore/QDir> #include <QtCore/QDir>
#include <QtCore/QDirIterator> #include <QtCore/QDirIterator>
#include <QtCore/QDateTime> #include <QtCore/QDateTime>
#include <QtCore/QDebug>
#ifdef Q_OS_SYMBIAN #ifdef Q_OS_SYMBIAN
#define DEFAULT_MAKESPEC "X:/STLsupport/mkspecs/symbian-abld/" #define DEFAULT_MAKESPEC "X:/STLsupport/mkspecs/symbian-abld/"
@ -342,7 +343,8 @@ namespace QTest {
void QExternalTestPrivate::removeTemporaryDirectory() void QExternalTestPrivate::removeTemporaryDirectory()
{ {
Q_ASSERT(!temporaryDir.isEmpty()); if (temporaryDir.isEmpty())
qWarning() << "Temporary directory is expected to be non-empty";
removeRecursive(temporaryDir); removeRecursive(temporaryDir);
temporaryDir.clear(); temporaryDir.clear();
} }
@ -487,7 +489,8 @@ namespace QTest {
bool QExternalTestPrivate::createProjectFile() bool QExternalTestPrivate::createProjectFile()
{ {
Q_ASSERT(!temporaryDir.isEmpty()); if (temporaryDir.isEmpty())
qWarning() << "Temporary directory is expected to be non-empty";
QFile projectFile(temporaryDir + QLatin1String("/project.pro")); QFile projectFile(temporaryDir + QLatin1String("/project.pro"));
if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) { if (!projectFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
@ -599,7 +602,9 @@ namespace QTest {
bool QExternalTestPrivate::runQmake() bool QExternalTestPrivate::runQmake()
{ {
Q_ASSERT(!temporaryDir.isEmpty()); if (temporaryDir.isEmpty())
qWarning() << "Temporary directory is expected to be non-empty";
if (!createProjectFile()) if (!createProjectFile())
return false; return false;
@ -633,7 +638,8 @@ namespace QTest {
bool QExternalTestPrivate::runMake(Target target) bool QExternalTestPrivate::runMake(Target target)
{ {
Q_ASSERT(!temporaryDir.isEmpty()); if (temporaryDir.isEmpty())
qWarning() << "Temporary directory is expected to be non-empty";
QExternalProcess make; QExternalProcess make;
make.setWorkingDirectory(temporaryDir); make.setWorkingDirectory(temporaryDir);

View File

@ -139,7 +139,8 @@ public:
virtual ~Data() virtual ~Data()
{ {
Q_ASSERT_X(generation > 0, "tst_QSharedPointer", "Double deletion!"); if (generation <= 0)
qFatal("tst_qsharedpointer: Double deletion!");
generation = 0; generation = 0;
++destructorCounter; ++destructorCounter;
} }
@ -283,8 +284,8 @@ void tst_QSharedPointer::operators()
QSharedPointer<char> p1; QSharedPointer<char> p1;
QSharedPointer<char> p2(new char); QSharedPointer<char> p2(new char);
qptrdiff diff = p2.data() - p1.data(); qptrdiff diff = p2.data() - p1.data();
Q_ASSERT(p1.data() != p2.data()); QVERIFY(p1.data() != p2.data());
Q_ASSERT(diff != 0); QVERIFY(diff != 0);
// operator- // operator-
QCOMPARE(p2 - p1.data(), diff); QCOMPARE(p2 - p1.data(), diff);
@ -867,8 +868,8 @@ void tst_QSharedPointer::differentPointers()
{ {
DiffPtrDerivedData *aData = new DiffPtrDerivedData; DiffPtrDerivedData *aData = new DiffPtrDerivedData;
Data *aBase = aData; Data *aBase = aData;
Q_ASSERT(aData == aBase); QVERIFY(aData == aBase);
Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase)); QVERIFY(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
QSharedPointer<Data> baseptr = QSharedPointer<Data>(aData); QSharedPointer<Data> baseptr = QSharedPointer<Data>(aData);
QSharedPointer<DiffPtrDerivedData> ptr = qSharedPointerCast<DiffPtrDerivedData>(baseptr); QSharedPointer<DiffPtrDerivedData> ptr = qSharedPointerCast<DiffPtrDerivedData>(baseptr);
@ -885,8 +886,8 @@ void tst_QSharedPointer::differentPointers()
{ {
DiffPtrDerivedData *aData = new DiffPtrDerivedData; DiffPtrDerivedData *aData = new DiffPtrDerivedData;
Data *aBase = aData; Data *aBase = aData;
Q_ASSERT(aData == aBase); QVERIFY(aData == aBase);
Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase)); QVERIFY(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
QSharedPointer<DiffPtrDerivedData> ptr = QSharedPointer<DiffPtrDerivedData>(aData); QSharedPointer<DiffPtrDerivedData> ptr = QSharedPointer<DiffPtrDerivedData>(aData);
QSharedPointer<Data> baseptr = ptr; QSharedPointer<Data> baseptr = ptr;
@ -908,8 +909,8 @@ void tst_QSharedPointer::virtualBaseDifferentPointers()
{ {
VirtualDerived *aData = new VirtualDerived; VirtualDerived *aData = new VirtualDerived;
Data *aBase = aData; Data *aBase = aData;
Q_ASSERT(aData == aBase); QVERIFY(aData == aBase);
Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase)); QVERIFY(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData); QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData);
QSharedPointer<Data> baseptr = qSharedPointerCast<Data>(ptr); QSharedPointer<Data> baseptr = qSharedPointerCast<Data>(ptr);
@ -928,8 +929,8 @@ void tst_QSharedPointer::virtualBaseDifferentPointers()
{ {
VirtualDerived *aData = new VirtualDerived; VirtualDerived *aData = new VirtualDerived;
Data *aBase = aData; Data *aBase = aData;
Q_ASSERT(aData == aBase); QVERIFY(aData == aBase);
Q_ASSERT(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase)); QVERIFY(*reinterpret_cast<quintptr *>(&aData) != *reinterpret_cast<quintptr *>(&aBase));
QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData); QSharedPointer<VirtualDerived> ptr = QSharedPointer<VirtualDerived>(aData);
QSharedPointer<Data> baseptr = ptr; QSharedPointer<Data> baseptr = ptr;
@ -1605,7 +1606,7 @@ void hashAndMapTest()
QVERIFY(it != c.find(Key())); QVERIFY(it != c.find(Key()));
if (Ordered) { if (Ordered) {
Q_ASSERT(k0 < k1); QVERIFY(k0 < k1);
it = c.begin(); it = c.begin();
QCOMPARE(it.key(), k0); QCOMPARE(it.key(), k0);

View File

@ -1340,14 +1340,14 @@ void tst_QSplitter::task187373_addAbstractScrollAreas()
QFETCH(QString, className); QFETCH(QString, className);
QFETCH(bool, addInConstructor); QFETCH(bool, addInConstructor);
QFETCH(bool, addOutsideConstructor); QFETCH(bool, addOutsideConstructor);
Q_ASSERT(addInConstructor || addOutsideConstructor); QVERIFY(addInConstructor || addOutsideConstructor);
QSplitter *splitter = new QSplitter; QSplitter *splitter = new QSplitter;
splitter->show(); splitter->show();
Q_ASSERT(splitter->isVisible()); QVERIFY(splitter->isVisible());
QAbstractScrollArea *w = task187373_createScrollArea(splitter, className, addInConstructor); QAbstractScrollArea *w = task187373_createScrollArea(splitter, className, addInConstructor);
Q_ASSERT(w); QVERIFY(w);
if (addOutsideConstructor) if (addOutsideConstructor)
splitter->addWidget(w); splitter->addWidget(w);

View File

@ -767,7 +767,7 @@ void tst_QSqlDatabase::checkValues(const FieldDef fieldDefs[], QSqlDatabase db)
Q3SqlCursor cur(qTableName("qtestfields", __FILE__), true, db); Q3SqlCursor cur(qTableName("qtestfields", __FILE__), true, db);
QVERIFY_SQL(cur, select()); QVERIFY_SQL(cur, select());
QSqlRecord* rec = cur.primeInsert(); QSqlRecord* rec = cur.primeInsert();
Q_ASSERT(rec); QVERIFY(rec);
rec->setValue("id", pkey++); rec->setValue("id", pkey++);
int i = 0; int i = 0;
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) {
@ -828,7 +828,7 @@ void tst_QSqlDatabase::checkNullValues(const FieldDef fieldDefs[], QSqlDatabase
Q3SqlCursor cur(qTableName("qtestfields", __FILE__), true, db); Q3SqlCursor cur(qTableName("qtestfields", __FILE__), true, db);
QVERIFY_SQL(cur, select()); QVERIFY_SQL(cur, select());
QSqlRecord* rec = cur.primeInsert(); QSqlRecord* rec = cur.primeInsert();
Q_ASSERT(rec); QVERIFY(rec);
rec->setValue("id", pkey++); rec->setValue("id", pkey++);
int i = 0; int i = 0;
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) { for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) {

View File

@ -1565,8 +1565,8 @@ protected:
// delayed start of encryption // delayed start of encryption
QTest::qSleep(100); QTest::qSleep(100);
QSslSocket *socket = server.socket; QSslSocket *socket = server.socket;
QVERIFY(socket); if (!socket || !socket->isValid())
QVERIFY(socket->isValid()); return; // error
socket->ignoreSslErrors(); socket->ignoreSslErrors();
socket->startServerEncryption(); socket->startServerEncryption();
if (!socket->waitForEncrypted(2000)) if (!socket->waitForEncrypted(2000))

View File

@ -3429,9 +3429,9 @@ void tst_QString::fromLatin1Roundtrip()
QFETCH(QString, unicode); QFETCH(QString, unicode);
// QtTest safety check: // QtTest safety check:
Q_ASSERT(latin1.isNull() == unicode.isNull()); QCOMPARE(latin1.isNull(), unicode.isNull());
Q_ASSERT(latin1.isEmpty() == unicode.isEmpty()); QCOMPARE(latin1.isEmpty(), unicode.isEmpty());
Q_ASSERT(latin1.length() == unicode.length()); QCOMPARE(latin1.length(), unicode.length());
if (!latin1.isEmpty()) if (!latin1.isEmpty())
while (latin1.length() < 128) { while (latin1.length() < 128) {
@ -3484,12 +3484,12 @@ void tst_QString::toLatin1Roundtrip()
QFETCH(QString, unicodedst); QFETCH(QString, unicodedst);
// QtTest safety check: // QtTest safety check:
Q_ASSERT(latin1.isNull() == unicodesrc.isNull()); QCOMPARE(latin1.isNull(), unicodesrc.isNull());
Q_ASSERT(latin1.isEmpty() == unicodesrc.isEmpty()); QCOMPARE(latin1.isEmpty(), unicodesrc.isEmpty());
Q_ASSERT(latin1.length() == unicodesrc.length()); QCOMPARE(latin1.length(), unicodesrc.length());
Q_ASSERT(latin1.isNull() == unicodedst.isNull()); QCOMPARE(latin1.isNull(), unicodedst.isNull());
Q_ASSERT(latin1.isEmpty() == unicodedst.isEmpty()); QCOMPARE(latin1.isEmpty(), unicodedst.isEmpty());
Q_ASSERT(latin1.length() == unicodedst.length()); QCOMPARE(latin1.length(), unicodedst.length());
if (!latin1.isEmpty()) if (!latin1.isEmpty())
while (latin1.length() < 128) { while (latin1.length() < 128) {
@ -3519,12 +3519,12 @@ void tst_QString::stringRef_toLatin1Roundtrip()
QFETCH(QString, unicodedst); QFETCH(QString, unicodedst);
// QtTest safety check: // QtTest safety check:
Q_ASSERT(latin1.isNull() == unicodesrc.isNull()); QCOMPARE(latin1.isNull(), unicodesrc.isNull());
Q_ASSERT(latin1.isEmpty() == unicodesrc.isEmpty()); QCOMPARE(latin1.isEmpty(), unicodesrc.isEmpty());
Q_ASSERT(latin1.length() == unicodesrc.length()); QCOMPARE(latin1.length(), unicodesrc.length());
Q_ASSERT(latin1.isNull() == unicodedst.isNull()); QCOMPARE(latin1.isNull(), unicodedst.isNull());
Q_ASSERT(latin1.isEmpty() == unicodedst.isEmpty()); QCOMPARE(latin1.isEmpty(), unicodedst.isEmpty());
Q_ASSERT(latin1.length() == unicodedst.length()); QCOMPARE(latin1.length(), unicodedst.length());
if (!latin1.isEmpty()) if (!latin1.isEmpty())
while (latin1.length() < 128) { while (latin1.length() < 128) {

View File

@ -3028,7 +3028,7 @@ void tst_QTableView::spans_data()
<< 1 << 1
<< 2; << 2;
QTest::newRow("QTBUG-6004: No failing Q_ASSERT, then it passes.") QTest::newRow("QTBUG-6004: No failing assertion, then it passes.")
<< 5 << 5 << 5 << 5
<< (SpanList() << QRect(0, 0, 2, 2) << QRect(0, 0, 1, 1)) << (SpanList() << QRect(0, 0, 2, 2) << QRect(0, 0, 1, 1))
<< false << false
@ -3036,7 +3036,7 @@ void tst_QTableView::spans_data()
<< 1 << 1
<< 1; << 1;
QTest::newRow("QTBUG-6004 (follow-up): No failing Q_ASSERT, then it passes.") QTest::newRow("QTBUG-6004 (follow-up): No failing assertion, then it passes.")
<< 10 << 10 << 10 << 10
<< (SpanList() << QRect(2, 2, 1, 3) << QRect(2, 2, 1, 1)) << (SpanList() << QRect(2, 2, 1, 3) << QRect(2, 2, 1, 1))
<< false << false

View File

@ -98,8 +98,12 @@ static QList<QPointF> parsePoints(const QByteArray &line)
QList<qreal> nums = parseNumbersList(it); QList<qreal> nums = parseNumbersList(it);
QList<qreal>::const_iterator nitr; QList<qreal>::const_iterator nitr;
for (nitr = nums.begin(); nitr != nums.end(); ++nitr) { for (nitr = nums.begin(); nitr != nums.end(); ++nitr) {
qreal x = *nitr; ++nitr; qreal x = *nitr;
Q_ASSERT(nitr != nums.end()); ++nitr;
if (nitr == nums.end()) {
qWarning() << "parsePoints: Even number of co-ordinates required, odd number found: skipping last point";
break;
}
qreal y = *nitr; qreal y = *nitr;
res.append(QPointF(x, y)); res.append(QPointF(x, y));
} }

View File

@ -80,19 +80,6 @@ struct QEdge {
horizontal = p1.y == p2.y; horizontal = p1.y == p2.y;
} }
inline qreal xAt(const qreal &y) const
{
Q_ASSERT(p1.y != p2.y);
XFixed yf = XDoubleToFixed(y);
if (yf == p1.y)
return XFixedToDouble(p1.x);
else if (yf == p2.y)
return XFixedToDouble(p2.x);
return (!vertical) ? (((y - b)*im)) : pf1.x();
}
QPointF pf1, pf2; QPointF pf1, pf2;
XPointFixed p1, p2; XPointFixed p1, p2;
qreal m; qreal m;
@ -218,7 +205,8 @@ void old_tesselate_polygon(QVector<XTrapezoid> *traps, const QPointF *pg, int pg
qreal ymax(INT_MIN/256); qreal ymax(INT_MIN/256);
//painter.begin(pg, pgSize); //painter.begin(pg, pgSize);
Q_ASSERT(pg[0] == pg[pgSize-1]); if (pg[0] != pg[pgSize-1])
qWarning() << Q_FUNC_INFO << "Malformed polygon (first and last points must be identical)";
// generate edge table // generate edge table
// qDebug() << "POINTS:"; // qDebug() << "POINTS:";
for (int x = 0; x < pgSize-1; ++x) { for (int x = 0; x < pgSize-1; ++x) {
@ -383,7 +371,8 @@ void old_tesselate_polygon(QVector<XTrapezoid> *traps, const QPointF *pg, int pg
isects[i].edge = edge; isects[i].edge = edge;
} }
Q_ASSERT(isects.size()%2 == 1); if (isects.size()%2 != 1)
qFatal("%s: number of intersection points must be odd", Q_FUNC_INFO);
// sort intersection points // sort intersection points
qSort(&isects[0], &isects[isects.size()-1], compareIntersections); qSort(&isects[0], &isects[isects.size()-1], compareIntersections);

View File

@ -42,6 +42,7 @@
#include <private/qtessellator_p.h> #include <private/qtessellator_p.h>
#include "math.h" #include "math.h"
#include <QtCore/QDebug>
class TestTessellator : public QTessellator class TestTessellator : public QTessellator
{ {
@ -91,7 +92,8 @@ void test_tessellate_polygon_rect(QVector<XTrapezoid> *traps, const QPointF *poi
bool winding) bool winding)
{ {
// 5 points per rect // 5 points per rect
Q_ASSERT(nPoints % 5 == 0); if (nPoints % 5 != 0)
qWarning() << Q_FUNC_INFO << "multiples of 5 points expected";
TestTessellator t; TestTessellator t;
t.traps = traps; t.traps = traps;

View File

@ -123,14 +123,14 @@ void tst_QTextBoundaryFinder::graphemeBoundaries()
if (test.at(pos).unicode() == 0xf7) if (test.at(pos).unicode() == 0xf7)
breakPositions.append(strPos); breakPositions.append(strPos);
else else
Q_ASSERT(test.at(pos).unicode() == 0xd7); QVERIFY(test.at(pos).unicode() == 0xd7);
++pos; ++pos;
if (pos < test.length()) { if (pos < test.length()) {
Q_ASSERT(pos < test.length() - 4); QVERIFY(pos < test.length() - 4);
QString hex = test.mid(pos, 4); QString hex = test.mid(pos, 4);
bool ok = true; bool ok = true;
testString.append(QChar(hex.toInt(&ok, 16))); testString.append(QChar(hex.toInt(&ok, 16)));
Q_ASSERT(ok); QVERIFY(ok);
pos += 4; pos += 4;
} }
++strPos; ++strPos;
@ -176,14 +176,14 @@ void tst_QTextBoundaryFinder::wordBoundaries()
if (test.at(pos).unicode() == 0xf7) if (test.at(pos).unicode() == 0xf7)
breakPositions.append(strPos); breakPositions.append(strPos);
else else
Q_ASSERT(test.at(pos).unicode() == 0xd7); QVERIFY(test.at(pos).unicode() == 0xd7);
++pos; ++pos;
if (pos < test.length()) { if (pos < test.length()) {
Q_ASSERT(pos < test.length() - 4); QVERIFY(pos < test.length() - 4);
QString hex = test.mid(pos, 4); QString hex = test.mid(pos, 4);
bool ok = true; bool ok = true;
testString.append(QChar(hex.toInt(&ok, 16))); testString.append(QChar(hex.toInt(&ok, 16)));
Q_ASSERT(ok); QVERIFY(ok);
pos += 4; pos += 4;
} }
++strPos; ++strPos;
@ -228,14 +228,14 @@ void tst_QTextBoundaryFinder::sentenceBoundaries()
if (test.at(pos).unicode() == 0xf7) if (test.at(pos).unicode() == 0xf7)
breakPositions.append(strPos); breakPositions.append(strPos);
else else
Q_ASSERT(test.at(pos).unicode() == 0xd7); QVERIFY(test.at(pos).unicode() == 0xd7);
++pos; ++pos;
if (pos < test.length()) { if (pos < test.length()) {
Q_ASSERT(pos < test.length() - 4); QVERIFY(pos < test.length() - 4);
QString hex = test.mid(pos, 4); QString hex = test.mid(pos, 4);
bool ok = true; bool ok = true;
testString.append(QChar(hex.toInt(&ok, 16))); testString.append(QChar(hex.toInt(&ok, 16)));
Q_ASSERT(ok); QVERIFY(ok);
pos += 4; pos += 4;
} }
++strPos; ++strPos;

View File

@ -428,7 +428,7 @@ void tst_QTextCodec::flagCodepointFFFF() const
QString input(ch); QString input(ch);
QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
Q_ASSERT(codec); QVERIFY(codec);
const QByteArray asDecoded(codec->fromUnicode(input)); const QByteArray asDecoded(codec->fromUnicode(input));
QCOMPARE(asDecoded, QByteArray("?")); QCOMPARE(asDecoded, QByteArray("?"));
@ -465,7 +465,7 @@ void tst_QTextCodec::flagF7808080() const
QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
Q_ASSERT(codec); QVERIFY(codec);
//QVERIFY(!codec->canEncode(QChar(0x1C0000))); //QVERIFY(!codec->canEncode(QChar(0x1C0000)));
@ -482,7 +482,7 @@ void tst_QTextCodec::flagEFBFBF() const
invalidInput[2] = char(0xBF); invalidInput[2] = char(0xBF);
const QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 const QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
Q_ASSERT(codec); QVERIFY(codec);
{ {
//QVERIFY(!codec->canEncode(QChar(0xFFFF))); //QVERIFY(!codec->canEncode(QChar(0xFFFF)));
@ -1627,7 +1627,7 @@ void tst_QTextCodec::utf8bom()
QFETCH(QString, result); QFETCH(QString, result);
QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8 QTextCodec *const codec = QTextCodec::codecForMib(106); // UTF-8
Q_ASSERT(codec); QVERIFY(codec);
QCOMPARE(codec->toUnicode(data.constData(), data.length(), 0), result); QCOMPARE(codec->toUnicode(data.constData(), data.length(), 0), result);

View File

@ -317,7 +317,7 @@ void tst_QTextEdit::getSetCheck()
// void QTextEdit::setFontPointSize(qreal) // void QTextEdit::setFontPointSize(qreal)
obj1.setFontPointSize(qreal(1.1)); obj1.setFontPointSize(qreal(1.1));
QCOMPARE(qreal(1.1), obj1.fontPointSize()); QCOMPARE(qreal(1.1), obj1.fontPointSize());
// we currently Q_ASSERT_X in QFont::setPointSizeF for that // we currently assert in QFont::setPointSizeF for that
//obj1.setFontPointSize(0.0); //obj1.setFontPointSize(0.0);
//QCOMPARE(1.1, obj1.fontPointSize()); // Should not accept 0.0 => keep old //QCOMPARE(1.1, obj1.fontPointSize()); // Should not accept 0.0 => keep old
@ -327,7 +327,7 @@ void tst_QTextEdit::getSetCheck()
QCOMPARE(1, obj1.fontWeight()); // Range<1, 99> QCOMPARE(1, obj1.fontWeight()); // Range<1, 99>
obj1.setFontWeight(99); obj1.setFontWeight(99);
QCOMPARE(99, obj1.fontWeight()); // Range<1, 99> QCOMPARE(99, obj1.fontWeight()); // Range<1, 99>
/* Q_ASSERT_X in qfont.cpp /* assertion in qfont.cpp
obj1.setFontWeight(INT_MIN); obj1.setFontWeight(INT_MIN);
QCOMPARE(1, obj1.fontWeight()); // Range<1, 99> QCOMPARE(1, obj1.fontWeight()); // Range<1, 99>
obj1.setFontWeight(INT_MAX); obj1.setFontWeight(INT_MAX);
@ -2064,7 +2064,7 @@ void tst_QTextEdit::compareWidgetAndImage(QTextEdit &widget, const QString &imag
QCOMPARE(original.isNull(), false); QCOMPARE(original.isNull(), false);
QCOMPARE(original.size(), image.size()); QCOMPARE(original.size(), image.size());
Q_ASSERT(image.depth() == 32); QCOMPARE(image.depth(), 32);
QCOMPARE(original.depth(), image.depth()); QCOMPARE(original.depth(), image.depth());
const int bytesPerLine = image.bytesPerLine(); const int bytesPerLine = image.bytesPerLine();

View File

@ -114,11 +114,14 @@ QString tst_QTextOdfWriter::getContentFromXml()
xmlWriter->writeEndDocument(); xmlWriter->writeEndDocument();
buffer->close(); buffer->close();
QString stringContent = QString::fromUtf8(buffer->data()); QString stringContent = QString::fromUtf8(buffer->data());
QString ret;
int index = stringContent.indexOf("<dummy"); int index = stringContent.indexOf("<dummy");
Q_ASSERT(index); if (index > 0) {
index = stringContent.indexOf('>', index); index = stringContent.indexOf('>', index);
stringContent = stringContent.mid(index+1, stringContent.length() - index - 10); if (index > 0)
return stringContent; ret = stringContent.mid(index+1, stringContent.length() - index - 10);
}
return ret;
} }
void tst_QTextOdfWriter::testWriteParagraph_data() void tst_QTextOdfWriter::testWriteParagraph_data()

View File

@ -209,7 +209,7 @@ public:
cond.wait(&mutex, five_minutes); cond.wait(&mutex, five_minutes);
} }
setTerminationEnabled(true); setTerminationEnabled(true);
Q_ASSERT_X(false, "tst_QThread", "test case hung"); qFatal("tst_QThread: test case hung");
} }
}; };

View File

@ -207,7 +207,8 @@ bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op,
if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) {
if (op == Unlock) { if (op == Unlock) {
--lockCount; --lockCount;
Q_ASSERT(lockCount >= 0); if (lockCount < 0)
qFatal("%s: lockCount must not be negative", Q_FUNC_INFO);
if (lockCount > 0) if (lockCount > 0)
return true; return true;
} }

View File

@ -157,7 +157,8 @@ bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op,
if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) {
if (op == Unlock) { if (op == Unlock) {
--lockCount; --lockCount;
Q_ASSERT(lockCount >= 0); if (lockCount < 0)
qFatal("%s: lockCount must not be negative", Q_FUNC_INFO);
if (lockCount > 0) if (lockCount > 0)
return true; return true;
} }

View File

@ -277,7 +277,8 @@ public:
} }
int rowCount(const QModelIndex& parent = QModelIndex()) const { int rowCount(const QModelIndex& parent = QModelIndex()) const {
Q_ASSERT(fetched); if (!fetched)
qFatal("%s: rowCount should not be called before fetching", Q_FUNC_INFO);
if ((parent.column() > 0) || (level(parent) > levels)) if ((parent.column() > 0) || (level(parent) > levels))
return 0; return 0;
return rows; return rows;
@ -2536,7 +2537,7 @@ void tst_QTreeView::sortByColumn()
/* /*
This is a model that every time kill() is called it will completely change This is a model that every time kill() is called it will completely change
all of its nodes for new nodes. It then asserts if you later use a dead node. all of its nodes for new nodes. It then qFatal's if you later use a dead node.
*/ */
class EvilModel: public QAbstractItemModel class EvilModel: public QAbstractItemModel
{ {
@ -2567,7 +2568,8 @@ public:
} }
} }
if (parent == 0) { if (parent == 0) {
Q_ASSERT(children.isEmpty()); if (!children.isEmpty())
qFatal("%s: children should be empty when parent is null", Q_FUNC_INFO);
populate(); populate();
} else { } else {
isDead = true; isDead = true;
@ -2624,7 +2626,8 @@ public:
Node *parentNode = root; Node *parentNode = root;
if (parent.isValid()) { if (parent.isValid()) {
parentNode = static_cast<Node*>(parent.internalPointer()); parentNode = static_cast<Node*>(parent.internalPointer());
Q_ASSERT(!parentNode->isDead); if (parentNode->isDead)
qFatal("%s: parentNode is dead!", Q_FUNC_INFO);
} }
return parentNode->children.count(); return parentNode->children.count();
} }
@ -2639,9 +2642,11 @@ public:
Node *grandparentNode = static_cast<Node*>(parent.internalPointer()); Node *grandparentNode = static_cast<Node*>(parent.internalPointer());
Node *parentNode = root; Node *parentNode = root;
if (parent.isValid()) { if (parent.isValid()) {
Q_ASSERT(!grandparentNode->isDead); if (grandparentNode->isDead)
qFatal("%s: grandparentNode is dead!", Q_FUNC_INFO);
parentNode = grandparentNode->children[parent.row()]; parentNode = grandparentNode->children[parent.row()];
Q_ASSERT(!parentNode->isDead); if (parentNode->isDead)
qFatal("%s: grandparentNode is dead!", Q_FUNC_INFO);
} }
return createIndex(row, column, parentNode); return createIndex(row, column, parentNode);
} }
@ -2661,7 +2666,8 @@ public:
Node *parentNode = root; Node *parentNode = root;
if (idx.isValid()) { if (idx.isValid()) {
parentNode = static_cast<Node*>(idx.internalPointer()); parentNode = static_cast<Node*>(idx.internalPointer());
Q_ASSERT(!parentNode->isDead); if (parentNode->isDead)
qFatal("%s: grandparentNode is dead!", Q_FUNC_INFO);
} }
return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()) return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column())
.arg(parentNode->isDead ? "dead" : "alive"); .arg(parentNode->isDead ? "dead" : "alive");

View File

@ -3239,18 +3239,24 @@ struct MyData
{ {
void *ptr; void *ptr;
MyData() : ptr(this) {} MyData() : ptr(this) {}
~MyData() { Q_ASSERT(ptr == this); } ~MyData()
MyData(const MyData& o) : ptr(this) { Q_ASSERT(o.ptr == &o); } {
if (ptr != this) qWarning("%s: object has moved", Q_FUNC_INFO);
}
MyData(const MyData& o) : ptr(this)
{
if (o.ptr != &o) qWarning("%s: other object has moved", Q_FUNC_INFO);
}
MyData &operator=(const MyData &o) MyData &operator=(const MyData &o)
{ {
Q_ASSERT(ptr == this); if (ptr != this) qWarning("%s: object has moved", Q_FUNC_INFO);
Q_ASSERT(o.ptr == &o); if (o.ptr != &o) qWarning("%s: other object has moved", Q_FUNC_INFO);
return *this; return *this;
} }
bool operator==(const MyData &o) const bool operator==(const MyData &o) const
{ {
Q_ASSERT(ptr == this); if (ptr != this) qWarning("%s: object has moved", Q_FUNC_INFO);
Q_ASSERT(o.ptr == &o); if (o.ptr != &o) qWarning("%s: other object has moved", Q_FUNC_INFO);
return true; return true;
} }
}; };

View File

@ -7234,8 +7234,7 @@ void tst_QWidget::render_systemClip2()
QFETCH(bool, usePaintEvent); QFETCH(bool, usePaintEvent);
QFETCH(QColor, expectedColor); QFETCH(QColor, expectedColor);
Q_ASSERT_X(expectedColor != QColor(Qt::red), Q_FUNC_INFO, QVERIFY2(expectedColor != QColor(Qt::red), "Qt::red is the reference color for the image, pick another color");
"Qt::red is the reference color for the image, pick another color");
class MyWidget : public QWidget class MyWidget : public QWidget
{ {
@ -10422,7 +10421,7 @@ void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy()
w.setFocusProxy(fp); w.setFocusProxy(fp);
QWidget::setTabOrder(&w, fp); QWidget::setTabOrder(&w, fp);
// No Q_ASSERT, then it's allright. // In debug mode, no assertion failure means it's alright.
} }
void tst_QWidget::movedAndResizedAttributes() void tst_QWidget::movedAndResizedAttributes()

View File

@ -854,25 +854,26 @@ struct MyPage2 : public QWizardPage
public: public:
MyPage2() : init(0), cleanup(0), validate(0) {} MyPage2() : init(0), cleanup(0), validate(0) {}
void initializePage() { ++init; QWizardPage::initializePage(); checkInvariant(); } void initializePage() { ++init; QWizardPage::initializePage(); }
void cleanupPage() { ++cleanup; QWizardPage::cleanupPage(); checkInvariant(); } void cleanupPage() { ++cleanup; QWizardPage::cleanupPage(); }
bool validatePage() { ++validate; return QWizardPage::validatePage(); } bool validatePage() { ++validate; return QWizardPage::validatePage(); }
void check(int init, int cleanup) bool check(int init, int cleanup)
{ Q_ASSERT(init == this->init && cleanup == this->cleanup); Q_UNUSED(init); Q_UNUSED(cleanup); } {
return init == this->init
&& cleanup == this->cleanup
&& (this->init == this->cleanup || this->init - 1 == this->cleanup);
}
int init; int init;
int cleanup; int cleanup;
int validate; int validate;
private:
void checkInvariant() { Q_ASSERT(init == cleanup || init - 1 == cleanup); }
}; };
#define CHECK_PAGE_INIT(i0, c0, i1, c1, i2, c2) \ #define CHECK_PAGE_INIT(i0, c0, i1, c1, i2, c2) \
page0->check((i0), (c0)); \ QVERIFY(page0->check((i0), (c0))); \
page1->check((i1), (c1)); \ QVERIFY(page1->check((i1), (c1))); \
page2->check((i2), (c2)); QVERIFY(page2->check((i2), (c2)));
void tst_QWizard::setOption_IndependentPages() void tst_QWizard::setOption_IndependentPages()
{ {

View File

@ -181,9 +181,7 @@ private slots:
{ {
if(bodyLength == -1) if(bodyLength == -1)
{ {
Q_ASSERT_X(false, Q_FUNC_INFO, qFatal("No length was specified in the header.");
"No length was specified in the header.");
return;
} }
QDomDocument domDoc; QDomDocument domDoc;

View File

@ -165,7 +165,7 @@ class tst_QXmlSimpleReader : public QObject
void roundtripWithNamespaces() const; void roundtripWithNamespaces() const;
private: private:
static QDomDocument fromByteArray(const QString &title, const QByteArray &ba); static QDomDocument fromByteArray(const QString &title, const QByteArray &ba, bool *ok);
XmlServer *server; XmlServer *server;
}; };
@ -730,25 +730,27 @@ void tst_QXmlSimpleReader::reportNamespace_data() const
<< QString("http://example.com/"); << QString("http://example.com/");
} }
QDomDocument tst_QXmlSimpleReader::fromByteArray(const QString &title, const QByteArray &ba) QDomDocument tst_QXmlSimpleReader::fromByteArray(const QString &title, const QByteArray &ba, bool *ok)
{ {
QDomDocument doc(title); QDomDocument doc(title);
const bool ret = doc.setContent(ba, true); *ok = doc.setContent(ba, true);
Q_ASSERT(ret);
return doc; return doc;
} }
void tst_QXmlSimpleReader::roundtripWithNamespaces() const void tst_QXmlSimpleReader::roundtripWithNamespaces() const
{ {
QEXPECT_FAIL("", "Known problem, see 154573. The fix happens to break uic.", Abort);
const char *const expected = "<element b:attr=\"value\" xmlns:a=\"http://www.example.com/A\" xmlns:b=\"http://www.example.com/B\" />\n"; const char *const expected = "<element b:attr=\"value\" xmlns:a=\"http://www.example.com/A\" xmlns:b=\"http://www.example.com/B\" />\n";
bool ok;
{ {
const char *const xml = "<element xmlns:b=\"http://www.example.com/B\" b:attr=\"value\" xmlns:a=\"http://www.example.com/A\"/>"; const char *const xml = "<element xmlns:b=\"http://www.example.com/B\" b:attr=\"value\" xmlns:a=\"http://www.example.com/A\"/>";
const QDomDocument one(fromByteArray("document", xml)); const QDomDocument one(fromByteArray("document", xml, &ok));
const QDomDocument two(fromByteArray("document2", one.toByteArray(2))); QVERIFY(ok);
const QDomDocument two(fromByteArray("document2", one.toByteArray(2), &ok));
QVERIFY(ok);
QEXPECT_FAIL("", "Known problem, see 154573. The fix happens to break uic.", Abort);
QCOMPARE(expected, one.toByteArray().constData()); QCOMPARE(expected, one.toByteArray().constData());
QCOMPARE(one.toByteArray(2).constData(), two.toByteArray(2).constData()); QCOMPARE(one.toByteArray(2).constData(), two.toByteArray(2).constData());
@ -758,8 +760,10 @@ void tst_QXmlSimpleReader::roundtripWithNamespaces() const
{ {
const char *const xml = "<element b:attr=\"value\" xmlns:b=\"http://www.example.com/B\" xmlns:a=\"http://www.example.com/A\"/>"; const char *const xml = "<element b:attr=\"value\" xmlns:b=\"http://www.example.com/B\" xmlns:a=\"http://www.example.com/A\"/>";
const QDomDocument one(fromByteArray("document", xml)); const QDomDocument one(fromByteArray("document", xml, &ok));
const QDomDocument two(fromByteArray("document2", one.toByteArray(2))); QVERIFY(ok);
const QDomDocument two(fromByteArray("document2", one.toByteArray(2), &ok));
QVERIFY(ok);
QCOMPARE(expected, one.toByteArray().constData()); QCOMPARE(expected, one.toByteArray().constData());
QCOMPARE(one.toByteArray(2).constData(), two.toByteArray(2).constData()); QCOMPARE(one.toByteArray(2).constData(), two.toByteArray(2).constData());

View File

@ -47,17 +47,9 @@ QT_FORWARD_DECLARE_CLASS(QString)
class QC14N class QC14N
{ {
public: public:
enum Option
{
IgnoreProcessingInstruction,
IgnoreComments
};
typedef QFlags<Option> Options;
static bool isEqual(QIODevice *const firstDocument, static bool isEqual(QIODevice *const firstDocument,
QIODevice *const secondDocument, QIODevice *const secondDocument,
QString *const message = 0, QString *const message = 0);
const Options options = Options());
private: private:
static bool isDifferent(const QXmlStreamReader &r1, static bool isDifferent(const QXmlStreamReader &r1,
@ -76,20 +68,17 @@ private:
*/ */
bool QC14N::isEqual(QIODevice *const firstDocument, bool QC14N::isEqual(QIODevice *const firstDocument,
QIODevice *const secondDocument, QIODevice *const secondDocument,
QString *const message, QString *const message)
const Options options)
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
Q_ASSERT_X(firstDocument, Q_FUNC_INFO, if (!firstDocument)
"A valid QIODevice pointer must be supplied"); qFatal("%s: A valid firstDocument QIODevice pointer must be supplied", Q_FUNC_INFO);
Q_ASSERT_X(secondDocument, Q_FUNC_INFO, if (!secondDocument)
"A valid QIODevice pointer must be supplied"); qFatal("%s: A valid secondDocument QIODevice pointer must be supplied", Q_FUNC_INFO);
Q_ASSERT_X(firstDocument->isReadable(), Q_FUNC_INFO, "The device must be readable."); if (!firstDocument->isReadable())
Q_ASSERT_X(secondDocument->isReadable(), Q_FUNC_INFO, "The device must be readable."); qFatal("%s: The firstDocument device must be readable.", Q_FUNC_INFO);
if (!secondDocument->isReadable())
Q_ASSERT_X(options == Options(), Q_FUNC_INFO, qFatal("%s: The secondDocument device must be readable.", Q_FUNC_INFO);
"Not yet implemented.");
Q_UNUSED(options);
QXmlStreamReader r1(firstDocument); QXmlStreamReader r1(firstDocument);
QXmlStreamReader r2(secondDocument); QXmlStreamReader r2(secondDocument);
@ -202,9 +191,9 @@ bool QC14N::isDifferent(const QXmlStreamReader &r1,
r2.processingInstructionData() == r2.processingInstructionData(); r2.processingInstructionData() == r2.processingInstructionData();
} }
} default:
qFatal("%s: Unknown tokenType: %d", Q_FUNC_INFO, static_cast<int>(r1.tokenType()));
Q_ASSERT_X(false, Q_FUNC_INFO, "This line should never be reached");
return false; return false;
}
} }

View File

@ -221,8 +221,7 @@ static QString documentElement(const QByteArray &document)
reader.readNext(); reader.readNext();
} }
Q_ASSERT_X(false, Q_FUNC_INFO, qFatal("The input %s didn't contain an element", document.constData());
qPrintable(QString::fromLatin1("The input %1 didn't contain an element.").arg(QString::fromUtf8(document.constData()))));
return QString(); return QString();
} }
@ -265,7 +264,8 @@ public:
expected(aExpected), expected(aExpected),
output(aOutput) output(aOutput)
{ {
Q_ASSERT(!aId.isEmpty()); if (aId.isEmpty())
qFatal("%s: aId must not be an empty string", Q_FUNC_INFO);
} }
QString id; QString id;
@ -289,7 +289,8 @@ public:
TestSuiteHandler(const QUrl &baseURI) : runCount(0), TestSuiteHandler(const QUrl &baseURI) : runCount(0),
skipCount(0) skipCount(0)
{ {
Q_ASSERT(baseURI.isValid()); if (!baseURI.isValid())
qFatal("%s: baseURI must be valid", Q_FUNC_INFO);
m_baseURI.push(baseURI); m_baseURI.push(baseURI);
} }
@ -461,7 +462,7 @@ public:
} }
else else
{ {
Q_ASSERT_X(false, Q_FUNC_INFO, "The input catalog is invalid."); qFatal("The input catalog is invalid.");
return false; return false;
} }
} }
@ -481,9 +482,12 @@ public:
static bool isWellformed(QIODevice *const inputFile, const ParseMode mode) static bool isWellformed(QIODevice *const inputFile, const ParseMode mode)
{ {
Q_ASSERT(inputFile); if (!inputFile)
Q_ASSERT_X(inputFile->isOpen(), Q_FUNC_INFO, "The caller is responsible for opening the device."); qFatal("%s: inputFile must be a valid QIODevice pointer", Q_FUNC_INFO);
Q_ASSERT(mode == ParseIncrementally || mode == ParseSinglePass); if (!inputFile->isOpen())
qFatal("%s: inputFile must be opened by the caller", Q_FUNC_INFO);
if (mode != ParseIncrementally && mode != ParseSinglePass)
qFatal("%s: mode must be either ParseIncrementally or ParseSinglePass", Q_FUNC_INFO);
if(mode == ParseIncrementally) if(mode == ParseIncrementally)
{ {

View File

@ -78,7 +78,8 @@ private:
QTestAlivePinger::QTestAlivePinger(QObject *receiver, QObject *parent) QTestAlivePinger::QTestAlivePinger(QObject *receiver, QObject *parent)
: QObject(parent), rec(receiver), currentSequenceId(0), lastSequenceId(0) : QObject(parent), rec(receiver), currentSequenceId(0), lastSequenceId(0)
{ {
Q_ASSERT(rec); if (!rec)
qFatal("Null receiver object passed to QTestAlivePinger::QTestAlivePinger()");
timerId = startTimer(850); timerId = startTimer(850);
} }
@ -147,8 +148,8 @@ bool QTestAlive::event(QEvent *e)
void QTestAlive::run() void QTestAlive::run()
{ {
Q_ASSERT_X(QCoreApplication::instance(), "QTestAlive::run()", if (!QCoreApplication::instance())
"Cannot start QTestAlive without a QCoreApplication instance."); qFatal("QTestAlive::run(): Cannot start QTestAlive without a QCoreApplication instance.");
QTestAlivePinger p(this); QTestAlivePinger p(this);
pinger = &p; pinger = &p;