From f859ab10715a3cb69aa3f03574a046c886d34b44 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Fri, 6 May 2011 14:16:48 +1000 Subject: Remove Q_ASSERT from qabstractxmlnodemodel test If new "axis" enum values are added in the future, the test should report a meaningful warning in the test output rather than aborting with a meaningless message in debug builds and failing silently in release builds. Change-Id: Ifdc7a9492c3ee196d7f0e6958eec34693efd244f Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index 2ce9466..052c781 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -173,10 +173,10 @@ QXmlNodeModelIndex LoadingModel::nextFromSimpleAxis(QAbstractXmlNodeModel::Simpl return internal->precedingSibling ? createIndex(internal->precedingSibling) : QXmlNodeModelIndex(); case NextSibling: return internal->followingSibling ? createIndex(internal->followingSibling) : QXmlNodeModelIndex(); + default: + qWarning("%s: unknown axis enum value %d", Q_FUNC_INFO, static_cast(axis)); + return QXmlNodeModelIndex(); } - - Q_ASSERT(false); - return QXmlNodeModelIndex(); } QVector LoadingModel::attributes(const QXmlNodeModelIndex &ni) const -- cgit v0.12 From 6e3fcd6ff50e6435fd90629ed695196d25312ffc Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 10 May 2011 11:33:37 +1000 Subject: Remove Q_ASSERT's from QXmlStream autotest Report fatal errors rather than ignoring them in non-debug builds. Change-Id: Ieafc58f3603fa953f4a963394039e613dcd442fb Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qxmlstream/qc14n.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/auto/qxmlstream/qc14n.h b/tests/auto/qxmlstream/qc14n.h index 99432f3..c7d3a7d 100644 --- a/tests/auto/qxmlstream/qc14n.h +++ b/tests/auto/qxmlstream/qc14n.h @@ -71,12 +71,14 @@ bool QC14N::isEqual(QIODevice *const firstDocument, QString *const message) { qDebug() << Q_FUNC_INFO; - Q_ASSERT_X(firstDocument, Q_FUNC_INFO, - "A valid QIODevice pointer must be supplied"); - Q_ASSERT_X(secondDocument, Q_FUNC_INFO, - "A valid QIODevice pointer must be supplied"); - Q_ASSERT_X(firstDocument->isReadable(), Q_FUNC_INFO, "The device must be readable."); - Q_ASSERT_X(secondDocument->isReadable(), Q_FUNC_INFO, "The device must be readable."); + if (!firstDocument) + qFatal("%s: A valid firstDocument QIODevice pointer must be supplied", Q_FUNC_INFO); + if (!secondDocument) + qFatal("%s: A valid secondDocument QIODevice pointer must be supplied", Q_FUNC_INFO); + if (!firstDocument->isReadable()) + qFatal("%s: The firstDocument device must be readable.", Q_FUNC_INFO); + if (!secondDocument->isReadable()) + qFatal("%s: The secondDocument device must be readable.", Q_FUNC_INFO); QXmlStreamReader r1(firstDocument); QXmlStreamReader r2(secondDocument); -- cgit v0.12 From b841d30f25a87f8aafc4624fe09a3503ddc6ccda Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 18:21:18 +1000 Subject: Remove Q_ASSERT from qxmlquery autotest Make stream validity check part of the regular test logic rather than aborting in debug builds and ignoring the error in release builds. Change-Id: I07dcba079eecd88bf16672c6019a8d6f5a829fee Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qxmlquery/PushBaseliner.h | 7 ++++++- tests/auto/qxmlquery/tst_qxmlquery.cpp | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/auto/qxmlquery/PushBaseliner.h b/tests/auto/qxmlquery/PushBaseliner.h index 0648c90..8478a6a 100644 --- a/tests/auto/qxmlquery/PushBaseliner.h +++ b/tests/auto/qxmlquery/PushBaseliner.h @@ -65,9 +65,9 @@ public: const QXmlNamePool &namePool) : m_out(out) , m_namePool(namePool) { - Q_ASSERT(m_out.codec()); } + bool isValid() const; virtual void startElement(const QXmlName&); virtual void endElement(); virtual void attribute(const QXmlName&, const QStringRef&); @@ -86,6 +86,11 @@ private: const QXmlNamePool m_namePool; }; +bool PushBaseliner::isValid() const +{ + return m_out.codec(); +} + void PushBaseliner::startElement(const QXmlName &name) { m_out << "startElement(" << name.toClarkName(m_namePool) << ')'<< endl; diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index e3c97d2..e22f528 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -967,6 +967,7 @@ void tst_QXmlQuery::evaluateToReceiver() QString produced; QTextStream stream(&produced, QIODevice::WriteOnly); PushBaseliner push(stream, query.namePool()); + QVERIFY(push.isValid()); query.evaluateTo(&push); const QString baselineName(inputFile(QLatin1String(SRCDIR "pushBaselines/") + inputQuery.left(inputQuery.length() - 2) + QString::fromLatin1("ref"))); @@ -1685,6 +1686,7 @@ void tst_QXmlQuery::constCorrectness() const QString dummyString; QTextStream dummyStream(&dummyString); PushBaseliner dummy(dummyStream, query.namePool()); + QVERIFY(dummy.isValid()); query.evaluateTo(&dummy); } } -- cgit v0.12 From 1acca025082bad566e5fe7078aa41f73316cd40b Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 17:45:52 +1000 Subject: Remove Q_ASSERT's from qxmlquery autotest Make url validity check part of the regular test logic rather than aborting in debug builds and ignoring the error in release builds. Change-Id: Ic00610c04ee596f519b9d461748b401719cf41c0 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qxmlquery/NetworkOverrider.h | 13 +++++++++---- tests/auto/qxmlquery/tst_qxmlquery.cpp | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/auto/qxmlquery/NetworkOverrider.h b/tests/auto/qxmlquery/NetworkOverrider.h index 10a85c1..2f227ea 100644 --- a/tests/auto/qxmlquery/NetworkOverrider.h +++ b/tests/auto/qxmlquery/NetworkOverrider.h @@ -70,6 +70,7 @@ public: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData); + bool isValid() const; private: const QUrl m_rewriteFrom; @@ -77,11 +78,10 @@ private: }; NetworkOverrider::NetworkOverrider(const QUrl &rewriteFrom, - const QUrl &rewriteTo) : m_rewriteFrom(rewriteFrom) - , m_rewriteTo(rewriteTo) + const QUrl &rewriteTo) + : m_rewriteFrom(rewriteFrom) + , m_rewriteTo(rewriteTo) { - Q_ASSERT(m_rewriteFrom.isValid()); - Q_ASSERT(m_rewriteTo.isValid()); } QNetworkReply *NetworkOverrider::createRequest(Operation op, @@ -95,4 +95,9 @@ QNetworkReply *NetworkOverrider::createRequest(Operation op, return QNetworkAccessManager::createRequest(op, newReq, outgoingData); } + +bool NetworkOverrider::isValid() const +{ + return m_rewriteFrom.isValid() && m_rewriteTo.isValid(); +} #endif diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index e22f528..c002f83 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -3080,6 +3080,7 @@ void tst_QXmlQuery::setNetworkAccessManager() const { NetworkOverrider networkOverrider(QUrl(QLatin1String("tag:example.com:DOESNOTEXIST")), QUrl(inputFileAsURI(QLatin1String(XMLPATTERNSDIR "/queries/simpleDocument.xml")))); + QVERIFY(networkOverrider.isValid()); QXmlQuery query; query.setNetworkAccessManager(&networkOverrider); @@ -3096,6 +3097,7 @@ void tst_QXmlQuery::setNetworkAccessManager() const { NetworkOverrider networkOverrider(QUrl(QLatin1String("tag:example.com:DOESNOTEXIST")), QUrl(inputFileAsURI(QLatin1String(XMLPATTERNSDIR "/queries/concat.xq")))); + QVERIFY(networkOverrider.isValid()); QXmlQuery query; query.setNetworkAccessManager(&networkOverrider); -- cgit v0.12 From 984a72a8bbf853059f0eb7e1054538b48d5f3bc8 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 10 May 2011 11:48:36 +1000 Subject: Remove Q_ASSERT from QItemModel autotest If populateTestData() would return an invalid model index, report a meaningful fatal error rather than failing silently in a release build and aborting with an uninformative error message in a debug build. Change-Id: I96820429a25ce5c4eb375d50e7e1f672851e26e6 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qitemmodel/modelstotest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/auto/qitemmodel/modelstotest.cpp b/tests/auto/qitemmodel/modelstotest.cpp index 7ebf2c7..df06c95 100644 --- a/tests/auto/qitemmodel/modelstotest.cpp +++ b/tests/auto/qitemmodel/modelstotest.cpp @@ -308,7 +308,8 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) */ } 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; } -- cgit v0.12 From 4793c3bd1dfddcc98eae12e5caf29ff6aabd31b2 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 10 May 2011 11:43:08 +1000 Subject: Remove Q_ASSERT's from QXmlStream autotest Report fatal errors rather than ignoring them in non-debug builds. Change-Id: I62dd177e2f391e64c12314bf224f8952ed6f3144 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qxmlstream/tst_qxmlstream.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/auto/qxmlstream/tst_qxmlstream.cpp b/tests/auto/qxmlstream/tst_qxmlstream.cpp index 5324264..946a19a 100644 --- a/tests/auto/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/qxmlstream/tst_qxmlstream.cpp @@ -264,7 +264,8 @@ public: expected(aExpected), output(aOutput) { - Q_ASSERT(!aId.isEmpty()); + if (aId.isEmpty()) + qFatal("%s: aId must not be an empty string", Q_FUNC_INFO); } QString id; @@ -288,7 +289,8 @@ public: TestSuiteHandler(const QUrl &baseURI) : runCount(0), skipCount(0) { - Q_ASSERT(baseURI.isValid()); + if (!baseURI.isValid()) + qFatal("%s: baseURI must be valid", Q_FUNC_INFO); m_baseURI.push(baseURI); } @@ -480,9 +482,12 @@ public: static bool isWellformed(QIODevice *const inputFile, const ParseMode mode) { - Q_ASSERT(inputFile); - Q_ASSERT_X(inputFile->isOpen(), Q_FUNC_INFO, "The caller is responsible for opening the device."); - Q_ASSERT(mode == ParseIncrementally || mode == ParseSinglePass); + if (!inputFile) + qFatal("%s: inputFile must be a valid QIODevice pointer", Q_FUNC_INFO); + 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) { -- cgit v0.12 From cb84f3d1a1499485d4c5314b6e94745c6def6888 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Mon, 9 May 2011 17:40:30 +1000 Subject: Remove Q_ASSERT from qxmlquery autotest Report fatal error in all builds not just debug builds. Change-Id: I6c64435d0382a160ac3602e5243fad9d9585f057 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qxmlquery/MessageValidator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/auto/qxmlquery/MessageValidator.cpp b/tests/auto/qxmlquery/MessageValidator.cpp index 58b2b31..99a115e 100644 --- a/tests/auto/qxmlquery/MessageValidator.cpp +++ b/tests/auto/qxmlquery/MessageValidator.cpp @@ -51,9 +51,8 @@ MessageValidator::MessageValidator() : m_success(false) MessageValidator::~MessageValidator() { - Q_ASSERT_X(m_hasChecked, - Q_FUNC_INFO, - "You must call success()."); + if (!m_hasChecked) + qFatal("%s: You must call success().", Q_FUNC_INFO); } void MessageValidator::handleMessage(QtMsgType type, -- cgit v0.12 From 1c85fc559ee456a165527d23cb1b7dc237f5504b Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 10 May 2011 13:19:25 +1000 Subject: Remove Q_ASSERT from QXmlStream autotest Report a meaningful fatal error if an unknown token type is encountered rather than ignoring the error in non-debug builds and reporting an uninformative message in debug builds. Change-Id: Id219f3c7cbd4ba3e9875cb81f833720d5d153132 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qxmlstream/qc14n.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/qxmlstream/qc14n.h b/tests/auto/qxmlstream/qc14n.h index c7d3a7d..661ddee 100644 --- a/tests/auto/qxmlstream/qc14n.h +++ b/tests/auto/qxmlstream/qc14n.h @@ -191,9 +191,9 @@ bool QC14N::isDifferent(const QXmlStreamReader &r1, r2.processingInstructionData() == r2.processingInstructionData(); } + default: + qFatal("%s: Unknown tokenType: %d", Q_FUNC_INFO, static_cast(r1.tokenType())); + return false; } - - Q_ASSERT_X(false, Q_FUNC_INFO, "This line should never be reached"); - return false; } -- cgit v0.12 From 6f5751c45868a6dde51647462a331d49f848f2f0 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 10 May 2011 13:30:56 +1000 Subject: Remove Q_ASSERT's from qabstractxmlnodemodel test Report fatal errors rather than ignoring the errors in non-debug builds. Change-Id: I5d2f20113cbca11e272cf8fc2591e38b94d6853b Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern --- tests/auto/qabstractxmlnodemodel/LoadingModel.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp index 052c781..bb8538c 100644 --- a/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp +++ b/tests/auto/qabstractxmlnodemodel/LoadingModel.cpp @@ -84,13 +84,14 @@ QXmlNodeModelIndex LoadingModel::createIndex(const Node *const internal) const QUrl LoadingModel::documentUri(const QXmlNodeModelIndex &) const { - Q_ASSERT(false); + qFatal("%s: This method should not be called during the test", Q_FUNC_INFO); return QUrl(); } QXmlNodeModelIndex::NodeKind LoadingModel::kind(const QXmlNodeModelIndex &ni) const { - Q_ASSERT(!ni.isNull()); + if (ni.isNull()) + qFatal("%s: node model index should not be null", Q_FUNC_INFO); return toInternal(ni)->kind; } @@ -332,13 +333,11 @@ void Loader::load() break; } case QXmlStreamReader::DTD: - /* Fallthrough. */ + qFatal("%s: QXmlStreamReader::DTD token is not supported", Q_FUNC_INFO); + break; case QXmlStreamReader::EntityReference: - { - Q_ASSERT_X(false, Q_FUNC_INFO, - "We don't support this."); - /* Fallthrough. */ - } + qFatal("%s: QXmlStreamReader::EntityReference token is not supported", Q_FUNC_INFO); + break; case QXmlStreamReader::NoToken: /* Fallthrough. */ case QXmlStreamReader::Invalid: -- cgit v0.12