summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-05-06 16:22:25 +1000
committerRohan McGovern <rohan.mcgovern@nokia.com>2011-05-18 10:46:46 +1000
commit175bb0eac6dff4911393593c363c61b7ebbb0851 (patch)
tree88ca101bd066d429e68ecf9d638ac817f527abd5 /tests
parent6354d890f39127df44f3db77c2d7d2be854ea752 (diff)
Remove Q_ASSERT's in qitemview autotest
Rather than aborting in debug builds and failing silently in release builds, report a meaningful warning message and return an appropriate value to indicate the error. Change-Id: I0ceb0a0bfaef34cc6127d768cc75ecfc5a24e3c9 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern (cherry picked from commit 7cb0a3baeb361c9909e8ab2caf436e8e44b6a3b6)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qitemview/tst_qitemview.cpp65
1 files changed, 53 insertions, 12 deletions
diff --git a/tests/auto/qitemview/tst_qitemview.cpp b/tests/auto/qitemview/tst_qitemview.cpp
index c987c8f267..fa8367e145 100644
--- a/tests/auto/qitemview/tst_qitemview.cpp
+++ b/tests/auto/qitemview/tst_qitemview.cpp
@@ -148,12 +148,18 @@ public:
CheckerModel() : QStandardItemModel() {};
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);
};
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
|| index.column() == 2 || index.column() == columnCount() - 3) {
Qt::ItemFlags f = QStandardItemModel::flags(index);
@@ -164,14 +170,26 @@ public:
};
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);
};
QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const {
- Q_ASSERT(section >= 0);
- if (orientation == Qt::Horizontal) { Q_ASSERT(section <= columnCount());};
- if (orientation == Qt::Vertical) { Q_ASSERT(section <= rowCount());};
+ 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 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);
}
@@ -180,23 +198,46 @@ public:
};
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);
}
void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) {
- Q_ASSERT(column >= 0 && column <= columnCount());
- QStandardItemModel::sort(column, order);
+ 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);
};
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);
- Q_ASSERT(value.isValid());
+ if (hits <= 0) {
+ 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);
};
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);
};
};