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 block Executed 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 | if (url.scheme() == QLatin1String("qrc")
| 0-2 | ||||||||||||
49 | fileName = QLatin1Char(':') + url.path(); | - | ||||||||||||
50 | } executed 2 times by 1 test: else {end of block Executed by:
| 2 | ||||||||||||
51 | - | |||||||||||||
52 | - | |||||||||||||
53 | - | |||||||||||||
54 | - | |||||||||||||
55 | - | |||||||||||||
56 | fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); | - | ||||||||||||
57 | } never executed: end of block | 0 | ||||||||||||
58 | } | - | ||||||||||||
59 | - | |||||||||||||
60 | QFileInfo fi(fileName); | - | ||||||||||||
61 | if (fi.isDir()
| 3-26 | ||||||||||||
62 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString()); | - | ||||||||||||
63 | setError(QNetworkReply::ContentOperationNotPermittedError, msg); | - | ||||||||||||
64 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
65 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentOperationNotPermittedError)); | - | ||||||||||||
66 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
67 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||
68 | } | - | ||||||||||||
69 | - | |||||||||||||
70 | d->realFile.setFileName(fileName); | - | ||||||||||||
71 | bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered); | - | ||||||||||||
72 | - | |||||||||||||
73 | - | |||||||||||||
74 | if (!opened
| 3-23 | ||||||||||||
75 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") | - | ||||||||||||
76 | .arg(d->realFile.fileName(), d->realFile.errorString()); | - | ||||||||||||
77 | - | |||||||||||||
78 | if (d->realFile.exists()
| 1-2 | ||||||||||||
79 | setError(QNetworkReply::ContentAccessDenied, msg); | - | ||||||||||||
80 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
81 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentAccessDenied)); | - | ||||||||||||
82 | } executed 2 times by 1 test: else {end of block Executed by:
| 2 | ||||||||||||
83 | setError(QNetworkReply::ContentNotFoundError, msg); | - | ||||||||||||
84 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||
85 | QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentNotFoundError)); | - | ||||||||||||
86 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
87 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
88 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||
89 | } | - | ||||||||||||
90 | - | |||||||||||||
91 | setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); | - | ||||||||||||
92 | d->realFileSize = fi.size(); | - | ||||||||||||
93 | setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize); | - | ||||||||||||
94 | - | |||||||||||||
95 | QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); | - | ||||||||||||
96 | QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection, | - | ||||||||||||
97 | QArgument<qint64 >("qint64", d->realFileSize), QArgument<qint64 >("qint64", d->realFileSize)); | - | ||||||||||||
98 | QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); | - | ||||||||||||
99 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||
100 | } executed 23 times by 2 tests: end of block Executed by:
| 23 | ||||||||||||
101 | - | |||||||||||||
102 | void QNetworkReplyFileImpl::close() | - | ||||||||||||
103 | { | - | ||||||||||||
104 | QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
105 | QNetworkReply::close(); | - | ||||||||||||
106 | d->realFile.close(); | - | ||||||||||||
107 | } never executed: end of block | 0 | ||||||||||||
108 | - | |||||||||||||
109 | void QNetworkReplyFileImpl::abort() | - | ||||||||||||
110 | { | - | ||||||||||||
111 | QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
112 | QNetworkReply::close(); | - | ||||||||||||
113 | d->realFile.close(); | - | ||||||||||||
114 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
115 | - | |||||||||||||
116 | qint64 QNetworkReplyFileImpl::bytesAvailable() const | - | ||||||||||||
117 | { | - | ||||||||||||
118 | const QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
119 | if (!d->realFile.isOpen()
| 2-184 | ||||||||||||
120 | 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 | ||||||||||||
121 | 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 | ||||||||||||
122 | } | - | ||||||||||||
123 | - | |||||||||||||
124 | bool QNetworkReplyFileImpl::isSequential () const | - | ||||||||||||
125 | { | - | ||||||||||||
126 | return executed 183 times by 2 tests: true;return true; Executed by:
executed 183 times by 2 tests: return true; Executed by:
| 183 | ||||||||||||
127 | } | - | ||||||||||||
128 | - | |||||||||||||
129 | qint64 QNetworkReplyFileImpl::size() const | - | ||||||||||||
130 | { | - | ||||||||||||
131 | const QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
132 | return never executed: d->realFileSize;return d->realFileSize; never executed: return d->realFileSize; | 0 | ||||||||||||
133 | } | - | ||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | - | |||||||||||||
137 | - | |||||||||||||
138 | qint64 QNetworkReplyFileImpl::readData(char *data, qint64 maxlen) | - | ||||||||||||
139 | { | - | ||||||||||||
140 | QNetworkReplyFileImplPrivate * const d = d_func(); | - | ||||||||||||
141 | if (!d->realFile.isOpen()
| 17-166 | ||||||||||||
142 | return executed 17 times by 1 test: -1;return -1; Executed by:
executed 17 times by 1 test: return -1; Executed by:
| 17 | ||||||||||||
143 | qint64 ret = d->realFile.read(data, maxlen); | - | ||||||||||||
144 | if (bytesAvailable() == 0
| 0-151 | ||||||||||||
145 | d->realFile.close(); executed 15 times by 1 test: d->realFile.close(); Executed by:
| 15 | ||||||||||||
146 | if (ret == 0
| 1-163 | ||||||||||||
147 | return executed 2 times by 1 test: -1;return -1; Executed by:
executed 2 times by 1 test: return -1; Executed by:
| 2 | ||||||||||||
148 | else { | - | ||||||||||||
149 | setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200); | - | ||||||||||||
150 | setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QLatin1String("OK")); | - | ||||||||||||
151 | return executed 164 times by 2 tests: ret;return ret; Executed by:
executed 164 times by 2 tests: return ret; Executed by:
| 164 | ||||||||||||
152 | } | - | ||||||||||||
153 | } | - | ||||||||||||
154 | - | |||||||||||||
155 | - | |||||||||||||
156 | - | |||||||||||||
157 | - | |||||||||||||
Switch to Source code | Preprocessed file |