| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkreplyfileimpl.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | QNetworkReplyFileImplPrivate::QNetworkReplyFileImplPrivate() | - | ||||||||||||
| 6 | : QNetworkReplyPrivate(), realFileSize(0) | - | ||||||||||||
| 7 | { | - | ||||||||||||
| 8 | } executed 30 times by 2 tests: end of blockExecuted by:
| 30 | ||||||||||||
| 9 | - | |||||||||||||
| 10 | QNetworkReplyFileImpl::~QNetworkReplyFileImpl() | - | ||||||||||||
| 11 | { | - | ||||||||||||
| 12 | } | - | ||||||||||||
| 13 | - | |||||||||||||
| 14 | QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op) | - | ||||||||||||
| 15 | : QNetworkReply(*new QNetworkReplyFileImplPrivate(), parent) | - | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | setRequest(req); | - | ||||||||||||
| 18 | setUrl(req.url()); | - | ||||||||||||
| 19 | setOperation(op); | - | ||||||||||||
| 20 | setFinished(true); | - | ||||||||||||
| 21 | QNetworkReply::open(QIODevice::ReadOnly); | - | ||||||||||||
| 22 | - | |||||||||||||
| 23 | QNetworkReplyFileImplPrivate *d = (QNetworkReplyFileImplPrivate*) d_func(); | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | QUrl url = req.url(); | - | ||||||||||||
| 26 | if (url.host() == QLatin1String("localhost")
| 1-29 | ||||||||||||
| 27 | url.setHost(QString()); executed 1 time by 1 test: url.setHost(QString());Executed by:
| 1 | ||||||||||||
| 28 | - | |||||||||||||
| 29 | - | |||||||||||||
| 30 | - | |||||||||||||
| 31 | if (!url.host().isEmpty()
| 1-29 | ||||||||||||
| 32 | - | |||||||||||||
| 33 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString()); | - | ||||||||||||
| 34 | setError(QNetworkReply::ProtocolInvalidOperationError, msg); | - | ||||||||||||
| 35 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
| 36 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ProtocolInvalidOperationError)); | - | ||||||||||||
| 37 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
| 38 | return; executed 1 time by 1 test: return;Executed by:
| 1 | ||||||||||||
| 39 | } | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | if (url.path().isEmpty()
| 1-28 | ||||||||||||
| 42 | url.setPath(QLatin1String("/")); executed 1 time by 1 test: url.setPath(QLatin1String("/"));Executed by:
| 1 | ||||||||||||
| 43 | setUrl(url); | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | - | |||||||||||||
| 46 | QString fileName = url.toLocalFile(); | - | ||||||||||||
| 47 | if (fileName.isEmpty()
| 2-27 | ||||||||||||
| 48 | const QString scheme = url.scheme(); | - | ||||||||||||
| 49 | if (scheme == QLatin1String("qrc")
| 0-2 | ||||||||||||
| 50 | fileName = QLatin1Char(':') + url.path(); | - | ||||||||||||
| 51 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||
| 52 | - | |||||||||||||
| 53 | - | |||||||||||||
| 54 | - | |||||||||||||
| 55 | - | |||||||||||||
| 56 | - | |||||||||||||
| 57 | fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); | - | ||||||||||||
| 58 | } never executed: end of block | 0 | ||||||||||||
| 59 | } | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | QFileInfo fi(fileName); | - | ||||||||||||
| 62 | if (fi.isDir()
| 3-26 | ||||||||||||
| 63 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString()); | - | ||||||||||||
| 64 | setError(QNetworkReply::ContentOperationNotPermittedError, msg); | - | ||||||||||||
| 65 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
| 66 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentOperationNotPermittedError)); | - | ||||||||||||
| 67 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
| 68 | return; executed 3 times by 1 test: return;Executed by:
| 3 | ||||||||||||
| 69 | } | - | ||||||||||||
| 70 | - | |||||||||||||
| 71 | d->realFile.setFileName(fileName); | - | ||||||||||||
| 72 | bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered); | - | ||||||||||||
| 73 | - | |||||||||||||
| 74 | - | |||||||||||||
| 75 | if (!opened
| 3-23 | ||||||||||||
| 76 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") | - | ||||||||||||
| 77 | .arg(d->realFile.fileName(), d->realFile.errorString()); | - | ||||||||||||
| 78 | - | |||||||||||||
| 79 | if (d->realFile.exists()
| 1-2 | ||||||||||||
| 80 | setError(QNetworkReply::ContentAccessDenied, msg); | - | ||||||||||||
| 81 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
| 82 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentAccessDenied)); | - | ||||||||||||
| 83 | } executed 2 times by 1 test: else {end of blockExecuted by:
| 2 | ||||||||||||
| 84 | setError(QNetworkReply::ContentNotFoundError, msg); | - | ||||||||||||
| 85 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
| 86 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentNotFoundError)); | - | ||||||||||||
| 87 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 88 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
| 89 | return; executed 3 times by 1 test: return;Executed by:
| 3 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); | - | ||||||||||||
| 93 | d->realFileSize = fi.size(); | - | ||||||||||||
| 94 | setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize); | - | ||||||||||||
| 95 | - | |||||||||||||
| 96 | QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); | - | ||||||||||||
| 97 | QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection, | - | ||||||||||||
| 98 | QArgument<qint64 >("qint64", d->realFileSize), QArgument<qint64 >("qint64", d->realFileSize)); | - | ||||||||||||
| 99 | QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); | - | ||||||||||||
| 100 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
| 101 | } executed 23 times by 2 tests: end of blockExecuted by:
| 23 | ||||||||||||
| 102 | - | |||||||||||||
| 103 | void QNetworkReplyFileImpl::close() | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
| 106 | QNetworkReply::close(); | - | ||||||||||||
| 107 | d->realFile.close(); | - | ||||||||||||
| 108 | } never executed: end of block | 0 | ||||||||||||
| 109 | - | |||||||||||||
| 110 | void QNetworkReplyFileImpl::abort() | - | ||||||||||||
| 111 | { | - | ||||||||||||
| 112 | QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
| 113 | QNetworkReply::close(); | - | ||||||||||||
| 114 | d->realFile.close(); | - | ||||||||||||
| 115 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | qint64 QNetworkReplyFileImpl::bytesAvailable() const | - | ||||||||||||
| 118 | { | - | ||||||||||||
| 119 | const QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
| 120 | if (!d->realFile.isOpen()
| 2-184 | ||||||||||||
| 121 | return executed 2 times by 1 test: QNetworkReply::bytesAvailable();return QNetworkReply::bytesAvailable();Executed by:
executed 2 times by 1 test: return QNetworkReply::bytesAvailable();Executed by:
| 2 | ||||||||||||
| 122 | return executed 184 times by 2 tests: QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();Executed by:
executed 184 times by 2 tests: return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();Executed by:
| 184 | ||||||||||||
| 123 | } | - | ||||||||||||
| 124 | - | |||||||||||||
| 125 | bool QNetworkReplyFileImpl::isSequential () const | - | ||||||||||||
| 126 | { | - | ||||||||||||
| 127 | return executed 183 times by 2 tests: true;return true;Executed by:
executed 183 times by 2 tests: return true;Executed by:
| 183 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | - | |||||||||||||
| 130 | qint64 QNetworkReplyFileImpl::size() const | - | ||||||||||||
| 131 | { | - | ||||||||||||
| 132 | const QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
| 133 | return never executed: d->realFileSize;return d->realFileSize;never executed: return d->realFileSize; | 0 | ||||||||||||
| 134 | } | - | ||||||||||||
| 135 | - | |||||||||||||
| 136 | - | |||||||||||||
| 137 | - | |||||||||||||
| 138 | - | |||||||||||||
| 139 | qint64 QNetworkReplyFileImpl::readData(char *data, qint64 maxlen) | - | ||||||||||||
| 140 | { | - | ||||||||||||
| 141 | QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
| 142 | if (!d->realFile.isOpen()
| 17-166 | ||||||||||||
| 143 | return executed 17 times by 1 test: -1;return -1;Executed by:
executed 17 times by 1 test: return -1;Executed by:
| 17 | ||||||||||||
| 144 | qint64 ret = d->realFile.read(data, maxlen); | - | ||||||||||||
| 145 | if (bytesAvailable() == 0
| 0-151 | ||||||||||||
| 146 | d->realFile.close(); executed 15 times by 1 test: d->realFile.close();Executed by:
| 15 | ||||||||||||
| 147 | if (ret == 0
| 1-163 | ||||||||||||
| 148 | return executed 2 times by 1 test: -1;return -1;Executed by:
executed 2 times by 1 test: return -1;Executed by:
| 2 | ||||||||||||
| 149 | else { | - | ||||||||||||
| 150 | setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); | - | ||||||||||||
| 151 | setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QLatin1String("OK")); | - | ||||||||||||
| 152 | return executed 164 times by 2 tests: ret;return ret;Executed by:
executed 164 times by 2 tests: return ret;Executed by:
| 164 | ||||||||||||
| 153 | } | - | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | - | |||||||||||||
| 157 | - | |||||||||||||
| 158 | - | |||||||||||||
| Switch to Source code | Preprocessed file |