summaryrefslogtreecommitdiffstats
path: root/tests/auto/qabstractfileengine
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-05-05 14:40:40 +1000
committerRohan McGovern <rohan.mcgovern@nokia.com>2011-05-18 10:46:45 +1000
commit8e9644a67ed4d3acd85b45e86033baaf57d5e5d2 (patch)
tree7068aed1006dff5cb341d1d5fcbf9da04b7666cc /tests/auto/qabstractfileengine
parent6aca191e108bb518f0b9debf78707577664bf71c (diff)
Remove Q_ASSERT's from QAbstractFileEngine autotest
Rather than aborting in debug builds and ignoring failures in release builds, report meaningful warnings into the test output and return sentinel values that will cause QVERIFY/QCOMPARE of the returned values to fail the test. Change-Id: I2c5a820637337d0762c71db10a4f270d36b31662 Task-number: QTBUG-17582 Reviewed-by: Rohan McGovern (cherry picked from commit 524bd6b7120f70a178b03bc6d337e08abd327076)
Diffstat (limited to 'tests/auto/qabstractfileengine')
-rw-r--r--tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp49
1 files changed, 39 insertions, 10 deletions
diff --git a/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp b/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp
index 1178169ab1..fc4835a331 100644
--- a/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp
+++ b/tests/auto/qabstractfileengine/tst_qabstractfileengine.cpp
@@ -83,8 +83,12 @@ public:
bool open(QIODevice::OpenMode openMode)
{
- Q_ASSERT(!openForRead_);
- Q_ASSERT(!openForWrite_);
+ if (openForRead_ || openForWrite_) {
+ qWarning("%s: file is already open for %s",
+ Q_FUNC_INFO,
+ (openForRead_ ? "reading" : "writing"));
+ return false;
+ }
openFile_ = resolveFile(openMode & QIODevice::WriteOnly);
if (!openFile_)
@@ -132,13 +136,19 @@ public:
qint64 pos() const
{
- Q_ASSERT(openForRead_ || openForWrite_);
+ if (!openForRead_ && !openForWrite_) {
+ qWarning("%s: file is not open", Q_FUNC_INFO);
+ return -1;
+ }
return position_;
}
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) {
position_ = pos;
@@ -150,7 +160,11 @@ public:
bool flush()
{
- Q_ASSERT(openForRead_ || openForWrite_);
+ if (!openForRead_ && !openForWrite_) {
+ qWarning("%s: file is not open", Q_FUNC_INFO);
+ return false;
+ }
+
return true;
}
@@ -368,9 +382,16 @@ public:
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);
qint64 readSize = qMin(openFile_->content.size() - position_, maxLen);
if (readSize < 0)
@@ -384,12 +405,19 @@ public:
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)
return -1;
- Q_ASSERT(!openFile_.isNull());
QMutexLocker lock(&openFile_->mutex);
if (openFile_->content.size() == position_)
openFile_->content.append(data, length);
@@ -434,7 +462,8 @@ protected:
QSharedPointer<File> resolveFile(bool create) const
{
if (openForRead_ || openForWrite_) {
- Q_ASSERT(openFile_);
+ if (!openFile_)
+ qWarning("%s: file should not be null", Q_FUNC_INFO);
return openFile_;
}