summaryrefslogtreecommitdiffstats
path: root/tests/auto/modeltest
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-04-12 14:53:36 +1000
committerJason McDonald <jason.mcdonald@nokia.com>2011-04-12 15:38:20 +1000
commit3475168550c1a804f04f2a4edfeb30c04cd36551 (patch)
treeec1587bdc87e6f554c31e09cb1a3a2e26f16b181 /tests/auto/modeltest
parent78722d6b6e9ba0f6de1a4eba232aad2f96a339f2 (diff)
Reduce usage of Q_ASSERT in autotests.
Using Q_ASSERT does nothing in release-mode builds, and in debug builds it causes tests to terminate prematurely. It is much better to use QVERIFY or QCOMPARE. Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern
Diffstat (limited to 'tests/auto/modeltest')
-rw-r--r--tests/auto/modeltest/modeltest.cpp139
1 files changed, 68 insertions, 71 deletions
diff --git a/tests/auto/modeltest/modeltest.cpp b/tests/auto/modeltest/modeltest.cpp
index 98d707c8da..5ef27f9558 100644
--- a/tests/auto/modeltest/modeltest.cpp
+++ b/tests/auto/modeltest/modeltest.cpp
@@ -45,8 +45,6 @@
#include "modeltest.h"
#include <QtTest/QtTest>
-#undef Q_ASSERT
-#define Q_ASSERT QVERIFY
Q_DECLARE_METATYPE ( QModelIndex )
@@ -118,15 +116,15 @@ void ModelTest::runAllTests()
*/
void ModelTest::nonDestructiveBasicTest()
{
- Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() );
+ QVERIFY( model->buddy ( QModelIndex() ) == QModelIndex() );
model->canFetchMore ( QModelIndex() );
- Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 );
- Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() );
+ QVERIFY( model->columnCount ( QModelIndex() ) >= 0 );
+ QVERIFY( model->data ( QModelIndex() ) == QVariant() );
fetchingMore = true;
model->fetchMore ( QModelIndex() );
fetchingMore = false;
Qt::ItemFlags flags = model->flags ( QModelIndex() );
- Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 );
+ QVERIFY( flags == Qt::ItemIsDropEnabled || flags == 0 );
model->hasChildren ( QModelIndex() );
model->hasIndex ( 0, 0 );
model->headerData ( 0, Qt::Horizontal );
@@ -135,8 +133,8 @@ void ModelTest::nonDestructiveBasicTest()
QVariant cache;
model->match ( QModelIndex(), -1, cache );
model->mimeTypes();
- Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() );
- Q_ASSERT ( model->rowCount() >= 0 );
+ QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
+ QVERIFY( model->rowCount() >= 0 );
QVariant variant;
model->setData ( QModelIndex(), variant, -1 );
model->setHeaderData ( -1, Qt::Horizontal, QVariant() );
@@ -158,17 +156,17 @@ void ModelTest::rowCount()
// check top row
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
int rows = model->rowCount ( topIndex );
- Q_ASSERT ( rows >= 0 );
+ QVERIFY( rows >= 0 );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( topIndex ) == true );
+ QVERIFY( model->hasChildren ( topIndex ) );
QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex );
if ( secondLevelIndex.isValid() ) { // not the top level
// check a row count where parent is valid
rows = model->rowCount ( secondLevelIndex );
- Q_ASSERT ( rows >= 0 );
+ QVERIFY( rows >= 0 );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true );
+ QVERIFY( model->hasChildren ( secondLevelIndex ) );
}
// The models rowCount() is tested more extensively in checkChildren(),
@@ -182,12 +180,12 @@ void ModelTest::columnCount()
{
// check top row
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
QModelIndex childIndex = model->index ( 0, 0, topIndex );
if ( childIndex.isValid() )
- Q_ASSERT ( model->columnCount ( childIndex ) >= 0 );
+ QVERIFY( model->columnCount ( childIndex ) >= 0 );
// columnCount() is tested more extensively in checkChildren(),
// but this catches the big mistakes
@@ -200,19 +198,19 @@ void ModelTest::hasIndex()
{
// qDebug() << "hi";
// Make sure that invalid values returns an invalid index
- Q_ASSERT ( model->hasIndex ( -2, -2 ) == false );
- Q_ASSERT ( model->hasIndex ( -2, 0 ) == false );
- Q_ASSERT ( model->hasIndex ( 0, -2 ) == false );
+ QVERIFY( !model->hasIndex ( -2, -2 ) );
+ QVERIFY( !model->hasIndex ( -2, 0 ) );
+ QVERIFY( !model->hasIndex ( 0, -2 ) );
int rows = model->rowCount();
int columns = model->columnCount();
// check out of bounds
- Q_ASSERT ( model->hasIndex ( rows, columns ) == false );
- Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false );
+ QVERIFY( !model->hasIndex ( rows, columns ) );
+ QVERIFY( !model->hasIndex ( rows + 1, columns + 1 ) );
if ( rows > 0 )
- Q_ASSERT ( model->hasIndex ( 0, 0 ) == true );
+ QVERIFY( model->hasIndex ( 0, 0 ) );
// hasIndex() is tested more extensively in checkChildren(),
// but this catches the big mistakes
@@ -225,9 +223,9 @@ void ModelTest::index()
{
// qDebug() << "i";
// Make sure that invalid values returns an invalid index
- Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() );
- Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() );
- Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() );
+ QVERIFY( model->index ( -2, -2 ) == QModelIndex() );
+ QVERIFY( model->index ( -2, 0 ) == QModelIndex() );
+ QVERIFY( model->index ( 0, -2 ) == QModelIndex() );
int rows = model->rowCount();
int columns = model->columnCount();
@@ -236,13 +234,13 @@ void ModelTest::index()
return;
// Catch off by one errors
- Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() );
- Q_ASSERT ( model->index ( 0, 0 ).isValid() == true );
+ QVERIFY( model->index ( rows, columns ) == QModelIndex() );
+ QVERIFY( model->index ( 0, 0 ).isValid() );
// Make sure that the same index is *always* returned
QModelIndex a = model->index ( 0, 0 );
QModelIndex b = model->index ( 0, 0 );
- Q_ASSERT ( a == b );
+ QVERIFY( a == b );
// index() is tested more extensively in checkChildren(),
// but this catches the big mistakes
@@ -256,7 +254,7 @@ void ModelTest::parent()
// qDebug() << "p";
// Make sure the model wont crash and will return an invalid QModelIndex
// when asked for the parent of an invalid index.
- Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() );
+ QVERIFY( model->parent ( QModelIndex() ) == QModelIndex() );
if ( model->rowCount() == 0 )
return;
@@ -269,13 +267,13 @@ void ModelTest::parent()
// Common error test #1, make sure that a top level index has a parent
// that is a invalid QModelIndex.
QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
- 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
// that is the first level index.
if ( model->rowCount ( topIndex ) > 0 ) {
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
@@ -285,7 +283,7 @@ void ModelTest::parent()
if ( model->rowCount ( topIndex1 ) > 0 ) {
QModelIndex childIndex = model->index ( 0, 0, topIndex );
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
@@ -325,47 +323,47 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
int columns = model->columnCount ( parent );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( parent ) );
+ QVERIFY( model->hasChildren ( parent ) );
// Some further testing against rows(), columns(), and hasChildren()
- Q_ASSERT ( rows >= 0 );
- Q_ASSERT ( columns >= 0 );
+ QVERIFY( rows >= 0 );
+ QVERIFY( columns >= 0 );
if ( rows > 0 )
- Q_ASSERT ( model->hasChildren ( parent ) == true );
+ QVERIFY( model->hasChildren ( parent ) );
//qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
// << "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 ) {
if ( model->canFetchMore ( parent ) ) {
fetchingMore = true;
model->fetchMore ( parent );
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 ) {
- Q_ASSERT ( model->hasIndex ( r, c, parent ) == true );
+ QVERIFY( model->hasIndex ( r, c, parent ) );
QModelIndex index = model->index ( r, c, parent );
// 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
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
QModelIndex a = 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
- Q_ASSERT ( index.model() == model );
- Q_ASSERT ( index.row() == r );
- Q_ASSERT ( index.column() == c );
+ QVERIFY( index.model() == model );
+ QCOMPARE( index.row(), r );
+ QCOMPARE( index.column(), c );
// 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.
-// Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true );
+ // of a bug in data(). Disable if this really is ok in your model.
+// QVERIFY( model->data ( index, Qt::DisplayRole ).isValid() );
// If the next test fails here is some somewhat useful debug you play with.
@@ -380,8 +378,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
}
// Check that we can get back our real parent.
-// qDebug() << model->parent ( index ) << parent ;
- Q_ASSERT ( model->parent ( index ) == parent );
+ QCOMPARE( model->parent ( index ), parent );
// recursively go down the children
if ( model->hasChildren ( index ) && currentDepth < 10 ) {
@@ -391,7 +388,7 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
// make sure that after testing the children that the index doesn't change.
QModelIndex newerIndex = model->index ( r, c, parent );
- Q_ASSERT ( index == newerIndex );
+ QVERIFY( index == newerIndex );
}
}
}
@@ -402,68 +399,68 @@ void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
void ModelTest::data()
{
// Invalid index should return an invalid qvariant
- Q_ASSERT ( !model->data ( QModelIndex() ).isValid() );
+ QVERIFY( !model->data ( QModelIndex() ).isValid() );
if ( model->rowCount() == 0 )
return;
// 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
- 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
QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
+ QVERIFY( qVariantCanConvert<QString> ( variant ) );
}
variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
+ QVERIFY( qVariantCanConvert<QString> ( variant ) );
}
variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
+ QVERIFY( qVariantCanConvert<QString> ( variant ) );
}
// General Purpose roles that should return a QSize
variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole );
if ( variant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QSize> ( variant ) );
+ QVERIFY( qVariantCanConvert<QSize> ( variant ) );
}
// General Purpose roles that should return a QFont
QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole );
if ( fontVariant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QFont> ( fontVariant ) );
+ QVERIFY( qVariantCanConvert<QFont> ( fontVariant ) );
}
// Check that the alignment is one we know about
QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole );
if ( textAlignmentVariant.isValid() ) {
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
QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole );
if ( colorVariant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) );
+ QVERIFY( qVariantCanConvert<QColor> ( colorVariant ) );
}
colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole );
if ( colorVariant.isValid() ) {
- Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) );
+ QVERIFY( qVariantCanConvert<QColor> ( colorVariant ) );
}
// Check that the "check state" is one we know about.
QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole );
if ( checkStateVariant.isValid() ) {
int state = checkStateVariant.toInt();
- Q_ASSERT ( state == Qt::Unchecked ||
- state == Qt::PartiallyChecked ||
- state == Qt::Checked );
+ QVERIFY( state == Qt::Unchecked ||
+ state == Qt::PartiallyChecked ||
+ state == Qt::Checked );
}
}
@@ -494,7 +491,7 @@ void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, in
void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
{
Changing c = insert.pop();
- Q_ASSERT ( c.parent == parent );
+ QVERIFY( c.parent == parent );
// qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
// << "parent=" << model->data ( parent ).toString() << "current rowcount of parent=" << model->rowCount ( parent );
@@ -504,8 +501,8 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
// }
// qDebug();
- Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) );
- Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
+ QVERIFY( c.oldSize + ( end - start + 1 ) == model->rowCount ( 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))) {
qDebug() << start << end;
@@ -514,7 +511,7 @@ void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
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()
@@ -527,7 +524,7 @@ void ModelTest::layoutChanged()
{
for ( int i = 0; i < changing.count(); ++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();
}
@@ -557,10 +554,10 @@ void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end )
{
qDebug() << "rr" << parent << start << end;
Changing c = remove.pop();
- Q_ASSERT ( c.parent == parent );
- Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
- Q_ASSERT ( 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.parent == parent );
+ QVERIFY( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
+ QVERIFY( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
+ QVERIFY( c.next == model->data ( model->index ( start, 0, c.parent ) ) );
}