Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | QNetworkAccessBackend * | - |
6 | QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, | - |
7 | const QNetworkRequest &request) const | - |
8 | { | - |
9 | | - |
10 | switch (op) { | - |
11 | case QNetworkAccessManager::GetOperation: | - |
12 | case QNetworkAccessManager::PutOperation: | - |
13 | break; executed: break; Execution Count:47 | 47 |
14 | | - |
15 | default: | - |
16 | | - |
17 | return 0; never executed: return 0; | 0 |
18 | } | - |
19 | | - |
20 | QUrl url = request.url(); | - |
21 | if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0 || url.isLocalFile()) { partially evaluated: url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0 no Evaluation Count:0 | yes Evaluation Count:47 |
evaluated: url.isLocalFile() yes Evaluation Count:39 | yes Evaluation Count:8 |
| 0-47 |
22 | return new QNetworkAccessFileBackend; executed: return new QNetworkAccessFileBackend; Execution Count:39 | 39 |
23 | } else if (!url.scheme().isEmpty() && url.authority().isEmpty() && (url.scheme().length() > 1)) { evaluated: !url.scheme().isEmpty() yes Evaluation Count:5 | yes Evaluation Count:3 |
evaluated: url.authority().isEmpty() yes Evaluation Count:4 | yes Evaluation Count:1 |
partially evaluated: (url.scheme().length() > 1) yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-5 |
24 | | - |
25 | | - |
26 | | - |
27 | | - |
28 | | - |
29 | | - |
30 | QFileInfo fi(url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery)); | - |
31 | if (fi.exists() || (op == QNetworkAccessManager::PutOperation && fi.dir().exists())) partially evaluated: fi.exists() yes Evaluation Count:4 | no Evaluation Count:0 |
never evaluated: op == QNetworkAccessManager::PutOperation never evaluated: fi.dir().exists() | 0-4 |
32 | return new QNetworkAccessFileBackend; executed: return new QNetworkAccessFileBackend; Execution Count:4 | 4 |
33 | } | 0 |
34 | | - |
35 | return 0; executed: return 0; Execution Count:4 | 4 |
36 | } | - |
37 | | - |
38 | QNetworkAccessFileBackend::QNetworkAccessFileBackend() | - |
39 | : uploadByteDevice(0), totalBytes(0), hasUploadFinished(false) | - |
40 | { | - |
41 | } executed: } Execution Count:43 | 43 |
42 | | - |
43 | QNetworkAccessFileBackend::~QNetworkAccessFileBackend() | - |
44 | { | - |
45 | } | - |
46 | | - |
47 | void QNetworkAccessFileBackend::open() | - |
48 | { | - |
49 | QUrl url = this->url(); | - |
50 | | - |
51 | if (url.host() == QLatin1String("localhost")) partially evaluated: url.host() == QLatin1String("localhost") no Evaluation Count:0 | yes Evaluation Count:43 |
| 0-43 |
52 | url.setHost(QString()); never executed: url.setHost(QString()); | 0 |
53 | | - |
54 | | - |
55 | if (!url.host().isEmpty()) { partially evaluated: !url.host().isEmpty() no Evaluation Count:0 | yes Evaluation Count:43 |
| 0-43 |
56 | | - |
57 | error(QNetworkReply::ProtocolInvalidOperationError, | - |
58 | QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString())); | - |
59 | finished(); | - |
60 | return; | 0 |
61 | } | - |
62 | | - |
63 | if (url.path().isEmpty()) partially evaluated: url.path().isEmpty() no Evaluation Count:0 | yes Evaluation Count:43 |
| 0-43 |
64 | url.setPath(QLatin1String("/")); never executed: url.setPath(QLatin1String("/")); | 0 |
65 | setUrl(url); | - |
66 | | - |
67 | QString fileName = url.toLocalFile(); | - |
68 | if (fileName.isEmpty()) { evaluated: fileName.isEmpty() yes Evaluation Count:4 | yes Evaluation Count:39 |
| 4-39 |
69 | if (url.scheme() == QLatin1String("qrc")) partially evaluated: url.scheme() == QLatin1String("qrc") no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
70 | fileName = QLatin1Char(':') + url.path(); never executed: fileName = QLatin1Char(':') + url.path(); | 0 |
71 | else | - |
72 | fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); executed: fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); Execution Count:4 | 4 |
73 | } | - |
74 | file.setFileName(fileName); | - |
75 | | - |
76 | if (operation() == QNetworkAccessManager::GetOperation) { evaluated: operation() == QNetworkAccessManager::GetOperation yes Evaluation Count:4 | yes Evaluation Count:39 |
| 4-39 |
77 | if (!loadFileInfo()) partially evaluated: !loadFileInfo() no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
78 | return; | 0 |
79 | } executed: } Execution Count:4 | 4 |
80 | | - |
81 | QIODevice::OpenMode mode; | - |
82 | switch (operation()) { | - |
83 | case QNetworkAccessManager::GetOperation: | - |
84 | mode = QIODevice::ReadOnly; | - |
85 | break; executed: break; Execution Count:4 | 4 |
86 | case QNetworkAccessManager::PutOperation: | - |
87 | mode = QIODevice::WriteOnly | QIODevice::Truncate; | - |
88 | uploadByteDevice = createUploadByteDevice(); | - |
89 | QObject::connect(uploadByteDevice, "2""readyRead()", this, "1""uploadReadyReadSlot()"); | - |
90 | QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection); | - |
91 | break; executed: break; Execution Count:39 | 39 |
92 | default: | - |
93 | qt_noop(); | - |
94 | | - |
95 | return; | 0 |
96 | } | - |
97 | | - |
98 | mode |= QIODevice::Unbuffered; | - |
99 | bool opened = file.open(mode); | - |
100 | | - |
101 | | - |
102 | if (!opened) { partially evaluated: !opened no Evaluation Count:0 | yes Evaluation Count:43 |
| 0-43 |
103 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") | - |
104 | .arg(this->url().toString(), file.errorString()); | - |
105 | | - |
106 | | - |
107 | | - |
108 | | - |
109 | if (file.exists() || operation() == QNetworkAccessManager::PutOperation) never evaluated: file.exists() never evaluated: operation() == QNetworkAccessManager::PutOperation | 0 |
110 | error(QNetworkReply::ContentAccessDenied, msg); never executed: error(QNetworkReply::ContentAccessDenied, msg); | 0 |
111 | else | - |
112 | error(QNetworkReply::ContentNotFoundError, msg); never executed: error(QNetworkReply::ContentNotFoundError, msg); | 0 |
113 | finished(); | - |
114 | } | 0 |
115 | } executed: } Execution Count:43 | 43 |
116 | | - |
117 | void QNetworkAccessFileBackend::uploadReadyReadSlot() | - |
118 | { | - |
119 | if (hasUploadFinished) evaluated: hasUploadFinished yes Evaluation Count:2 | yes Evaluation Count:148 |
| 2-148 |
120 | return; executed: return; Execution Count:2 | 2 |
121 | | - |
122 | for(;;) { | - |
123 | qint64 haveRead; | - |
124 | const char *readPointer = uploadByteDevice->readPointer(-1, haveRead); | - |
125 | if (haveRead == -1) { evaluated: haveRead == -1 yes Evaluation Count:39 | yes Evaluation Count:692 |
| 39-692 |
126 | | - |
127 | hasUploadFinished = true; | - |
128 | file.flush(); | - |
129 | file.close(); | - |
130 | finished(); | - |
131 | break; executed: break; Execution Count:39 | 39 |
132 | } else if (haveRead == 0 || readPointer == 0) { evaluated: haveRead == 0 yes Evaluation Count:109 | yes Evaluation Count:583 |
partially evaluated: readPointer == 0 no Evaluation Count:0 | yes Evaluation Count:583 |
| 0-583 |
133 | | - |
134 | break; executed: break; Execution Count:109 | 109 |
135 | } else { | - |
136 | qint64 haveWritten; | - |
137 | haveWritten = file.write(readPointer, haveRead); | - |
138 | | - |
139 | if (haveWritten < 0) { partially evaluated: haveWritten < 0 no Evaluation Count:0 | yes Evaluation Count:583 |
| 0-583 |
140 | | - |
141 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2") | - |
142 | .arg(url().toString(), file.errorString()); | - |
143 | error(QNetworkReply::ProtocolFailure, msg); | - |
144 | | - |
145 | finished(); | - |
146 | return; | 0 |
147 | } else { | - |
148 | uploadByteDevice->advanceReadPointer(haveWritten); | - |
149 | } executed: } Execution Count:583 | 583 |
150 | | - |
151 | | - |
152 | file.flush(); | - |
153 | } executed: } Execution Count:583 | 583 |
154 | } | - |
155 | } executed: } Execution Count:148 | 148 |
156 | | - |
157 | void QNetworkAccessFileBackend::closeDownstreamChannel() | - |
158 | { | - |
159 | if (operation() == QNetworkAccessManager::GetOperation) { never evaluated: operation() == QNetworkAccessManager::GetOperation | 0 |
160 | file.close(); | - |
161 | } | 0 |
162 | } | 0 |
163 | | - |
164 | void QNetworkAccessFileBackend::downstreamReadyWrite() | - |
165 | { | - |
166 | qt_noop(); | - |
167 | | - |
168 | | - |
169 | readMoreFromFile(); | - |
170 | } executed: } Execution Count:4 | 4 |
171 | | - |
172 | bool QNetworkAccessFileBackend::loadFileInfo() | - |
173 | { | - |
174 | QFileInfo fi(file); | - |
175 | setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); | - |
176 | setHeader(QNetworkRequest::ContentLengthHeader, fi.size()); | - |
177 | | - |
178 | | - |
179 | metaDataChanged(); | - |
180 | | - |
181 | if (fi.isDir()) { partially evaluated: fi.isDir() no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
182 | error(QNetworkReply::ContentOperationNotPermittedError, | - |
183 | QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url().toString())); | - |
184 | finished(); | - |
185 | return false; never executed: return false; | 0 |
186 | } | - |
187 | | - |
188 | return true; executed: return true; Execution Count:4 | 4 |
189 | } | - |
190 | | - |
191 | bool QNetworkAccessFileBackend::readMoreFromFile() | - |
192 | { | - |
193 | qint64 wantToRead; | - |
194 | while ((wantToRead = nextDownstreamBlockSize()) > 0) { partially evaluated: (wantToRead = nextDownstreamBlockSize()) > 0 yes Evaluation Count:38 | no Evaluation Count:0 |
| 0-38 |
195 | | - |
196 | | - |
197 | | - |
198 | QByteArray data; | - |
199 | data.reserve(wantToRead); | - |
200 | qint64 actuallyRead = file.read(data.data(), wantToRead); | - |
201 | if (actuallyRead <= 0) { evaluated: actuallyRead <= 0 yes Evaluation Count:4 | yes Evaluation Count:34 |
| 4-34 |
202 | | - |
203 | if (file.error() != QFile::NoError) { partially evaluated: file.error() != QFile::NoError no Evaluation Count:0 | yes Evaluation Count:4 |
| 0-4 |
204 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Read error reading from %1: %2") | - |
205 | .arg(url().toString(), file.errorString()); | - |
206 | error(QNetworkReply::ProtocolFailure, msg); | - |
207 | | - |
208 | finished(); | - |
209 | return false; never executed: return false; | 0 |
210 | } | - |
211 | | - |
212 | finished(); | - |
213 | return true; executed: return true; Execution Count:4 | 4 |
214 | } | - |
215 | | - |
216 | data.resize(actuallyRead); | - |
217 | totalBytes += actuallyRead; | - |
218 | | - |
219 | QByteDataBuffer list; | - |
220 | list.append(data); | - |
221 | data.clear(); | - |
222 | writeDownstreamData(list); | - |
223 | } executed: } Execution Count:34 | 34 |
224 | return true; never executed: return true; | 0 |
225 | } | - |
226 | | - |
227 | | - |
228 | | - |
| | |