qnetworkaccessfilebackend.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessfilebackend.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5QStringList QNetworkAccessFileBackendFactory::supportedSchemes() const-
6{-
7 QStringList schemes;-
8 schemes << ([]() -> QString { enum { Size = sizeof(u"" "file")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "file" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}())
0
9 << ([]() -> QString { enum { Size = sizeof(u"" "qrc")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qrc" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return
never executed: return qstring_literal_temp;
qstring_literal_temp;
never executed: return qstring_literal_temp;
}());
0
10-
11-
12-
13 return
never executed: return schemes;
schemes;
never executed: return schemes;
0
14}-
15-
16QNetworkAccessBackend *-
17QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op,-
18 const QNetworkRequest &request) const-
19{-
20-
21 switch (op) {-
22 case
executed 8 times by 1 test: case QNetworkAccessManager::GetOperation:
Executed by:
  • tst_QNetworkReply
QNetworkAccessManager::GetOperation:
executed 8 times by 1 test: case QNetworkAccessManager::GetOperation:
Executed by:
  • tst_QNetworkReply
8
23 case
executed 39 times by 1 test: case QNetworkAccessManager::PutOperation:
Executed by:
  • tst_QNetworkReply
QNetworkAccessManager::PutOperation:
executed 39 times by 1 test: case QNetworkAccessManager::PutOperation:
Executed by:
  • tst_QNetworkReply
39
24 break;
executed 47 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
47
25-
26 default
never executed: default:
:
never executed: default:
0
27-
28 return
never executed: return 0;
0;
never executed: return 0;
0
29 }-
30-
31 QUrl url = request.url();-
32 if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0
url.scheme().c...ensitive) == 0Description
TRUEnever evaluated
FALSEevaluated 47 times by 1 test
Evaluated by:
  • tst_QNetworkReply
0-47
33-
34-
35-
36 || url.isLocalFile()
url.isLocalFile()Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
8-39
37 return
executed 39 times by 1 test: return new QNetworkAccessFileBackend;
Executed by:
  • tst_QNetworkReply
new QNetworkAccessFileBackend;
executed 39 times by 1 test: return new QNetworkAccessFileBackend;
Executed by:
  • tst_QNetworkReply
39
38 } else if (!url.scheme().isEmpty()
!url.scheme().isEmpty()Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkReply
&& url.authority().isEmpty()
url.authority().isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
&& (
(url.scheme().length() > 1)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
url.scheme().length() > 1)
(url.scheme().length() > 1)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
) {
0-5
39-
40-
41-
42-
43-
44-
45 QFileInfo fi(url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery));-
46 if (fi.exists()
fi.exists()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
|| (op == QNetworkAccessManager::PutOperation
op == QNetwork...::PutOperationDescription
TRUEnever evaluated
FALSEnever evaluated
&& fi.dir().exists()
fi.dir().exists()Description
TRUEnever evaluated
FALSEnever evaluated
))
0-4
47 return
executed 4 times by 1 test: return new QNetworkAccessFileBackend;
Executed by:
  • tst_QNetworkReply
new QNetworkAccessFileBackend;
executed 4 times by 1 test: return new QNetworkAccessFileBackend;
Executed by:
  • tst_QNetworkReply
4
48 }
never executed: end of block
0
49-
50 return
executed 4 times by 1 test: return 0;
Executed by:
  • tst_QNetworkReply
0;
executed 4 times by 1 test: return 0;
Executed by:
  • tst_QNetworkReply
4
51}-
52-
53QNetworkAccessFileBackend::QNetworkAccessFileBackend()-
54 : uploadByteDevice(0), totalBytes(0), hasUploadFinished(false)-
55{-
56}
executed 43 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
43
57-
58QNetworkAccessFileBackend::~QNetworkAccessFileBackend()-
59{-
60}-
61-
62void QNetworkAccessFileBackend::open()-
63{-
64 QUrl url = this->url();-
65-
66 if (url.host() == QLatin1String("localhost")
url.host() == ...g("localhost")Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
0-43
67 url.setHost(QString());
never executed: url.setHost(QString());
0
68-
69-
70 if (!url.host().isEmpty()
!url.host().isEmpty()Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-43
71-
72 error(QNetworkReply::ProtocolInvalidOperationError,-
73 QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString()));-
74 finished();-
75 return;
never executed: return;
0
76 }-
77-
78 if (url.path().isEmpty()
url.path().isEmpty()Description
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
0-43
79 url.setPath(QLatin1String("/"));
never executed: url.setPath(QLatin1String("/"));
0
80 setUrl(url);-
81-
82 QString fileName = url.toLocalFile();-
83 if (fileName.isEmpty()
fileName.isEmpty()Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
4-39
84 if (url.scheme() == QLatin1String("qrc")
url.scheme() =...1String("qrc")Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-4
85 fileName = QLatin1Char(':') + url.path();-
86 }
never executed: end of block
else {
0
87-
88-
89-
90-
91-
92 fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);-
93 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
4
94 }-
95 file.setFileName(fileName);-
96-
97 if (operation() == QNetworkAccessManager::GetOperation
operation() ==...::GetOperationDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
4-39
98 if (!loadFileInfo()
!loadFileInfo()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
0-4
99 return;
never executed: return;
0
100 }
executed 4 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
4
101-
102 QIODevice::OpenMode mode;-
103 switch (operation()) {-
104 case
executed 4 times by 1 test: case QNetworkAccessManager::GetOperation:
Executed by:
  • tst_QNetworkReply
QNetworkAccessManager::GetOperation:
executed 4 times by 1 test: case QNetworkAccessManager::GetOperation:
Executed by:
  • tst_QNetworkReply
4
105 mode = QIODevice::ReadOnly;-
106 break;
executed 4 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
4
107 case
executed 39 times by 1 test: case QNetworkAccessManager::PutOperation:
Executed by:
  • tst_QNetworkReply
QNetworkAccessManager::PutOperation:
executed 39 times by 1 test: case QNetworkAccessManager::PutOperation:
Executed by:
  • tst_QNetworkReply
39
108 mode = QIODevice::WriteOnly | QIODevice::Truncate;-
109 uploadByteDevice = createUploadByteDevice();-
110 QObject::connect(uploadByteDevice, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "155"), this, qFlagLocation("1""uploadReadyReadSlot()" "\0" __FILE__ ":" "155"));-
111 QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection);-
112 break;
executed 39 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
39
113 default
never executed: default:
:
never executed: default:
0
114 ((!(false)) ? qt_assert_x("QNetworkAccessFileBackend::open", "Got a request operation I cannot handle!!",-
115 __FILE__-
116 ,-
117 160-
118 ) : qt_noop())-
119 ;-
120 return;
never executed: return;
0
121 }-
122-
123 mode |= QIODevice::Unbuffered;-
124 bool opened = file.open(mode);-
125-
126-
127 if (!opened
!openedDescription
TRUEnever evaluated
FALSEevaluated 43 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-43
128 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")-
129 .arg(this->url().toString(), file.errorString());-
130-
131-
132-
133-
134 if (file.exists()
file.exists()Description
TRUEnever evaluated
FALSEnever evaluated
|| operation() == QNetworkAccessManager::PutOperation
operation() ==...::PutOperationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
135 error(QNetworkReply::ContentAccessDenied, msg);
never executed: error(QNetworkReply::ContentAccessDenied, msg);
0
136 else-
137 error(QNetworkReply::ContentNotFoundError, msg);
never executed: error(QNetworkReply::ContentNotFoundError, msg);
0
138 finished();-
139 }
never executed: end of block
0
140}
executed 43 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
43
141-
142void QNetworkAccessFileBackend::uploadReadyReadSlot()-
143{-
144 if (hasUploadFinished
hasUploadFinishedDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 124 times by 1 test
Evaluated by:
  • tst_QNetworkReply
)
2-124
145 return;
executed 2 times by 1 test: return;
Executed by:
  • tst_QNetworkReply
2
146-
147 for(;;) {-
148 qint64 haveRead;-
149 const char *readPointer = uploadByteDevice->readPointer(-1, haveRead);-
150 if (haveRead == -1
haveRead == -1Description
TRUEevaluated 39 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 672 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
39-672
151-
152 hasUploadFinished = true;-
153 file.flush();-
154 file.close();-
155 finished();-
156 break;
executed 39 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
39
157 } else if (haveRead == 0
haveRead == 0Description
TRUEevaluated 85 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 587 times by 1 test
Evaluated by:
  • tst_QNetworkReply
|| readPointer == 0
readPointer == 0Description
TRUEnever evaluated
FALSEevaluated 587 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-587
158-
159 break;
executed 85 times by 1 test: break;
Executed by:
  • tst_QNetworkReply
85
160 } else {-
161 qint64 haveWritten;-
162 haveWritten = file.write(readPointer, haveRead);-
163-
164 if (haveWritten < 0
haveWritten < 0Description
TRUEnever evaluated
FALSEevaluated 587 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-587
165-
166 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2")-
167 .arg(url().toString(), file.errorString());-
168 error(QNetworkReply::ProtocolFailure, msg);-
169-
170 finished();-
171 return;
never executed: return;
0
172 } else {-
173 uploadByteDevice->advanceReadPointer(haveWritten);-
174 }
executed 587 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
587
175-
176-
177 file.flush();-
178 }
executed 587 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
587
179 }-
180}
executed 124 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
124
181-
182void QNetworkAccessFileBackend::closeDownstreamChannel()-
183{-
184 if (operation() == QNetworkAccessManager::GetOperation
operation() ==...::GetOperationDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
185 file.close();-
186 }
never executed: end of block
0
187}
never executed: end of block
0
188-
189void QNetworkAccessFileBackend::downstreamReadyWrite()-
190{-
191 ((!(operation() == QNetworkAccessManager::GetOperation)) ? qt_assert_x("QNetworkAccessFileBackend", "We're being told to download data but operation isn't GET!",-
192 __FILE__-
193 ,-
194 233-
195 ) : qt_noop())-
196 ;-
197-
198 readMoreFromFile();-
199}
executed 4 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
4
200-
201bool QNetworkAccessFileBackend::loadFileInfo()-
202{-
203 QFileInfo fi(file);-
204 setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());-
205 setHeader(QNetworkRequest::ContentLengthHeader, fi.size());-
206-
207-
208 metaDataChanged();-
209-
210 if (fi.isDir()
fi.isDir()Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-4
211 error(QNetworkReply::ContentOperationNotPermittedError,-
212 QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url().toString()));-
213 finished();-
214 return
never executed: return false;
false;
never executed: return false;
0
215 }-
216-
217 return
executed 4 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
4
218}-
219-
220bool QNetworkAccessFileBackend::readMoreFromFile()-
221{-
222 qint64 wantToRead;-
223 while ((
(wantToRead = ...ockSize()) > 0Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
wantToRead = nextDownstreamBlockSize()) > 0
(wantToRead = ...ockSize()) > 0Description
TRUEevaluated 38 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
) {
0-38
224-
225-
226-
227 QByteArray data;-
228 data.reserve(wantToRead);-
229 qint64 actuallyRead = file.read(data.data(), wantToRead);-
230 if (actuallyRead <= 0
actuallyRead <= 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 34 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
4-34
231-
232 if (file.error() != QFile::NoError
file.error() != QFile::NoErrorDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QNetworkReply
) {
0-4
233 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Read error reading from %1: %2")-
234 .arg(url().toString(), file.errorString());-
235 error(QNetworkReply::ProtocolFailure, msg);-
236-
237 finished();-
238 return
never executed: return false;
false;
never executed: return false;
0
239 }-
240-
241 finished();-
242 return
executed 4 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_QNetworkReply
4
243 }-
244-
245 data.resize(actuallyRead);-
246 totalBytes += actuallyRead;-
247-
248 QByteDataBuffer list;-
249 list.append(data);-
250 data.clear();-
251 writeDownstreamData(list);-
252 }
executed 34 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
34
253 return
never executed: return true;
true;
never executed: return true;
0
254}-
255-
256-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9