access/qnetworkreplyfileimpl.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5QNetworkReplyFileImplPrivate::QNetworkReplyFileImplPrivate() -
6 : QNetworkReplyPrivate(), realFileSize(0) -
7{ -
8}
executed: }
Execution Count:29
29
9 -
10QNetworkReplyFileImpl::~QNetworkReplyFileImpl() -
11{ -
12} -
13 -
14QNetworkReplyFileImpl::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"))
evaluated: url.host() == QLatin1String("localhost")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:28
1-28
27 url.setHost(QString());
executed: url.setHost(QString());
Execution Count:1
1
28 -
29 -
30 -
31 if (!url.host().isEmpty()) {
evaluated: !url.host().isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:28
1-28
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: return;
Execution Count:1
1
39 } -
40 -
41 if (url.path().isEmpty())
evaluated: url.path().isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:27
1-27
42 url.setPath(QLatin1String("/"));
executed: url.setPath(QLatin1String("/"));
Execution Count:1
1
43 setUrl(url); -
44 -
45 -
46 QString fileName = url.toLocalFile(); -
47 if (fileName.isEmpty()) {
evaluated: fileName.isEmpty()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:26
2-26
48 if (url.scheme() == QLatin1String("qrc"))
partially evaluated: url.scheme() == QLatin1String("qrc")
TRUEFALSE
yes
Evaluation Count:2
no
Evaluation Count:0
0-2
49 fileName = QLatin1Char(':') + url.path();
executed: fileName = QLatin1Char(':') + url.path();
Execution Count:2
2
50 else -
51 fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
never executed: fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);
0
52 } -
53 -
54 QFileInfo fi(fileName); -
55 if (fi.isDir()) {
evaluated: fi.isDir()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:25
3-25
56 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString()); -
57 setError(QNetworkReply::ContentOperationNotPermittedError, msg); -
58 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, -
59 QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentOperationNotPermittedError)); -
60 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); -
61 return;
executed: return;
Execution Count:3
3
62 } -
63 -
64 d->realFile.setFileName(fileName); -
65 bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered); -
66 -
67 -
68 if (!opened) {
evaluated: !opened
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:22
3-22
69 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") -
70 .arg(d->realFile.fileName(), d->realFile.errorString()); -
71 -
72 if (d->realFile.exists()) {
evaluated: d->realFile.exists()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:1
1-2
73 setError(QNetworkReply::ContentAccessDenied, msg); -
74 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, -
75 QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentAccessDenied)); -
76 } else {
executed: }
Execution Count:2
2
77 setError(QNetworkReply::ContentNotFoundError, msg); -
78 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, -
79 QArgument<QNetworkReply::NetworkError >("QNetworkReply::NetworkError", QNetworkReply::ContentNotFoundError)); -
80 }
executed: }
Execution Count:1
1
81 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); -
82 return;
executed: return;
Execution Count:3
3
83 } -
84 -
85 setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); -
86 d->realFileSize = fi.size(); -
87 setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize); -
88 -
89 QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection); -
90 QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection, -
91 QArgument<qint64 >("qint64", d->realFileSize), QArgument<qint64 >("qint64", d->realFileSize)); -
92 QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection); -
93 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); -
94}
executed: }
Execution Count:22
22
95void QNetworkReplyFileImpl::close() -
96{ -
97 QNetworkReplyFileImplPrivate * const d = d_func(); -
98 QNetworkReply::close(); -
99 d->realFile.close(); -
100}
never executed: }
0
101 -
102void QNetworkReplyFileImpl::abort() -
103{ -
104 QNetworkReplyFileImplPrivate * const d = d_func(); -
105 QNetworkReply::close(); -
106 d->realFile.close(); -
107}
executed: }
Execution Count:1
1
108 -
109qint64 QNetworkReplyFileImpl::bytesAvailable() const -
110{ -
111 const QNetworkReplyFileImplPrivate * const d = d_func(); -
112 return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
executed: return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
Execution Count:193
193
113} -
114 -
115bool QNetworkReplyFileImpl::isSequential () const -
116{ -
117 return true;
executed: return true;
Execution Count:182
182
118} -
119 -
120qint64 QNetworkReplyFileImpl::size() const -
121{ -
122 const QNetworkReplyFileImplPrivate * const d = d_func(); -
123 return d->realFileSize;
never executed: return d->realFileSize;
0
124} -
125 -
126 -
127 -
128 -
129qint64 QNetworkReplyFileImpl::readData(char *data, qint64 maxlen) -
130{ -
131 QNetworkReplyFileImplPrivate * const d = d_func(); -
132 qint64 ret = d->realFile.read(data, maxlen); -
133 if (ret == 0 && bytesAvailable() == 0)
evaluated: ret == 0
TRUEFALSE
yes
Evaluation Count:176
yes
Evaluation Count:168
evaluated: bytesAvailable() == 0
TRUEFALSE
yes
Evaluation Count:31
yes
Evaluation Count:145
31-176
134 return -1;
executed: return -1;
Execution Count:31
31
135 else -
136 return ret;
executed: return ret;
Execution Count:313
313
137} -
138 -
139 -
140 -
141 -
142 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial