io/qresource.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5 -
6class QStringSplitter -
7{ -
8public: -
9 QStringSplitter(const QString &s) -
10 : m_string(s), m_data(m_string.constData()), m_len(s.length()), m_pos(0) -
11 { -
12 m_splitChar = QLatin1Char('/'); -
13 }
executed: }
Execution Count:29554
29554
14 -
15 inline bool hasNext() { -
16 while (m_pos < m_len && m_data[m_pos] == m_splitChar)
evaluated: m_pos < m_len
TRUEFALSE
yes
Evaluation Count:155612
yes
Evaluation Count:12362
evaluated: m_data[m_pos] == m_splitChar
TRUEFALSE
yes
Evaluation Count:61722
yes
Evaluation Count:93890
12362-155612
17 ++m_pos;
executed: ++m_pos;
Execution Count:61722
61722
18 return m_pos < m_len;
executed: return m_pos < m_len;
Execution Count:106252
106252
19 } -
20 -
21 inline QStringRef next() { -
22 int start = m_pos; -
23 while (m_pos < m_len && m_data[m_pos] != m_splitChar)
evaluated: m_pos < m_len
TRUEFALSE
yes
Evaluation Count:618973
yes
Evaluation Count:8472
evaluated: m_data[m_pos] != m_splitChar
TRUEFALSE
yes
Evaluation Count:565723
yes
Evaluation Count:53250
8472-618973
24 ++m_pos;
executed: ++m_pos;
Execution Count:565723
565723
25 return QStringRef(&m_string, start, m_pos - start);
executed: return QStringRef(&m_string, start, m_pos - start);
Execution Count:61722
61722
26 } -
27 -
28 QString m_string; -
29 const QChar *m_data; -
30 QChar m_splitChar; -
31 int m_len; -
32 int m_pos; -
33}; -
34 -
35 -
36 -
37class QResourceRoot -
38{ -
39 enum Flags -
40 { -
41 Compressed = 0x01, -
42 Directory = 0x02 -
43 }; -
44 const uchar *tree, *names, *payloads; -
45 inline int findOffset(int node) const { return node * 14; }
executed: return node * 14;
Execution Count:264678
264678
46 uint hash(int node) const; -
47 QString name(int node) const; -
48 short flags(int node) const; -
49public: -
50 mutable QAtomicInt ref; -
51 -
52 inline QResourceRoot(): tree(0), names(0), payloads(0) {}
never executed: }
0
53 inline QResourceRoot(const uchar *t, const uchar *n, const uchar *d) { setSource(t, n, d); }
executed: }
Execution Count:183
183
54 virtual ~QResourceRoot() { } -
55 int findNode(const QString &path, const QLocale &locale=QLocale()) const; -
56 inline bool isContainer(int node) const { return flags(node) & Directory; }
executed: return flags(node) & Directory;
Execution Count:6252
6252
57 inline bool isCompressed(int node) const { return flags(node) & Compressed; }
executed: return flags(node) & Compressed;
Execution Count:6124
6124
58 const uchar *data(int node, qint64 *size) const; -
59 QStringList children(int node) const; -
60 virtual QString mappingRoot() const { return QString(); }
executed: return QString();
Execution Count:52892
52892
61 bool mappingRootSubdir(const QString &path, QString *match=0) const; -
62 inline bool operator==(const QResourceRoot &other) const -
63 { return tree == other.tree && names == other.names && payloads == other.payloads; }
executed: return tree == other.tree && names == other.names && payloads == other.payloads;
Execution Count:463
463
64 inline bool operator!=(const QResourceRoot &other) const -
65 { return !operator==(other); }
never executed: return !operator==(other);
0
66 enum ResourceRootType { Resource_Builtin, Resource_File, Resource_Buffer }; -
67 virtual ResourceRootType type() const { return Resource_Builtin; }
never executed: return Resource_Builtin;
0
68 -
69protected: -
70 inline void setSource(const uchar *t, const uchar *n, const uchar *d) { -
71 tree = t; -
72 names = n; -
73 payloads = d; -
74 }
executed: }
Execution Count:183
183
75}; -
76 -
77static QString cleanPath(const QString &_path) -
78{ -
79 QString path = QDir::cleanPath(_path); -
80 -
81 -
82 if (path.startsWith(QLatin1String("//")))
partially evaluated: path.startsWith(QLatin1String("//"))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9754
0-9754
83 path.remove(0, 1);
never executed: path.remove(0, 1);
0
84 return path;
executed: return path;
Execution Count:9754
9754
85} -
86 -
87template<> class QTypeInfo<QResourceRoot > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isLarge = (sizeof(QResourceRoot)>sizeof(void*)), isPointer = false, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QResourceRoot) }; static inline const char *name() { return "QResourceRoot"; } }; -
88 -
89static QMutex *resourceMutex() { static QGlobalStatic<QMutex > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QMutex *x = new QMutex (QMutex::Recursive); if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QMutex > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:10001
never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
partially evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10001
never evaluated: !thisGlobalStatic.destroyed
0-10001
90 -
91typedef QList<QResourceRoot*> ResourceList; -
92static ResourceList *resourceList() { static QGlobalStatic<ResourceList > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { ResourceList *x = new ResourceList; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<ResourceList > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:10893
never evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
partially evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:10893
never evaluated: !thisGlobalStatic.destroyed
0-10893
93 -
94static QStringList *resourceSearchPaths() { static QGlobalStatic<QStringList > thisGlobalStatic = { { (0) }, false }; if (!thisGlobalStatic.pointer.load() && !thisGlobalStatic.destroyed) { QStringList *x = new QStringList; if (!thisGlobalStatic.pointer.testAndSetOrdered(0, x)) delete x; else static QGlobalStaticDeleter<QStringList > cleanup(thisGlobalStatic); } return thisGlobalStatic.pointer.load(); }
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:80
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:76
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-80
95class QResourcePrivate { -
96public: -
97 inline QResourcePrivate(QResource *_q) : q_ptr(_q) { clear(); }
executed: }
Execution Count:8275
8275
98 inline ~QResourcePrivate() { clear(); }
executed: }
Execution Count:8275
8275
99 -
100 void ensureInitialized() const; -
101 void ensureChildren() const; -
102 -
103 bool load(const QString &file); -
104 void clear(); -
105 -
106 QLocale locale; -
107 QString fileName, absoluteFilePath; -
108 QList<QResourceRoot*> related; -
109 uint container : 1; -
110 mutable uint compressed : 1; -
111 mutable qint64 size; -
112 mutable const uchar *data; -
113 mutable QStringList children; -
114 -
115 QResource *q_ptr; -
116 inline QResource* q_func() { return static_cast<QResource *>(q_ptr); } inline const QResource* q_func() const { return static_cast<const QResource *>(q_ptr); } friend class QResource; -
117}; -
118 -
119void -
120QResourcePrivate::clear() -
121{ -
122 absoluteFilePath.clear(); -
123 compressed = 0; -
124 data = 0; -
125 size = 0; -
126 children.clear(); -
127 container = 0; -
128 for(int i = 0; i < related.size(); ++i) {
evaluated: i < related.size()
TRUEFALSE
yes
Evaluation Count:6252
yes
Evaluation Count:24822
6252-24822
129 QResourceRoot *root = related.at(i); -
130 if(!root->ref.deref())
partially evaluated: !root->ref.deref()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6252
0-6252
131 delete root;
never executed: delete root;
0
132 }
executed: }
Execution Count:6252
6252
133 related.clear(); -
134}
executed: }
Execution Count:24822
24822
135 -
136bool -
137QResourcePrivate::load(const QString &file) -
138{ -
139 related.clear(); -
140 QMutexLocker lock(resourceMutex()); -
141 const ResourceList *list = resourceList(); -
142 QString cleaned = cleanPath(file); -
143 for(int i = 0; i < list->size(); ++i) {
evaluated: i < list->size()
TRUEFALSE
yes
Evaluation Count:29554
yes
Evaluation Count:9738
9738-29554
144 QResourceRoot *res = list->at(i); -
145 const int node = res->findNode(cleaned, locale); -
146 if(node != -1) {
evaluated: node != -1
TRUEFALSE
yes
Evaluation Count:6252
yes
Evaluation Count:23302
6252-23302
147 if(related.isEmpty()) {
evaluated: related.isEmpty()
TRUEFALSE
yes
Evaluation Count:6245
yes
Evaluation Count:7
7-6245
148 container = res->isContainer(node); -
149 if(!container) {
evaluated: !container
TRUEFALSE
yes
Evaluation Count:6124
yes
Evaluation Count:121
121-6124
150 data = res->data(node, &size); -
151 compressed = res->isCompressed(node); -
152 } else {
executed: }
Execution Count:6124
6124
153 data = 0; -
154 size = 0; -
155 compressed = 0; -
156 }
executed: }
Execution Count:121
121
157 } else if(res->isContainer(node) != container) {
partially evaluated: res->isContainer(node) != container
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:7
0-7
158 QMessageLogger("io/qresource.cpp", 290, __PRETTY_FUNCTION__).warning("QResourceInfo: Resource [%s] has both data and children!", file.toLatin1().constData()); -
159 }
never executed: }
0
160 res->ref.ref(); -
161 related.append(res); -
162 } else if(res->mappingRootSubdir(file)) {
partially evaluated: res->mappingRootSubdir(file)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23302
executed: }
Execution Count:6252
0-23302
163 container = true; -
164 data = 0; -
165 size = 0; -
166 compressed = 0; -
167 res->ref.ref(); -
168 related.append(res); -
169 }
never executed: }
0
170 } -
171 return !related.isEmpty();
executed: return !related.isEmpty();
Execution Count:9738
9738
172} -
173 -
174void -
175QResourcePrivate::ensureInitialized() const -
176{ -
177 if(!related.isEmpty())
evaluated: !related.isEmpty()
TRUEFALSE
yes
Evaluation Count:238286
yes
Evaluation Count:9738
9738-238286
178 return;
executed: return;
Execution Count:238286
238286
179 QResourcePrivate *that = const_cast<QResourcePrivate *>(this); -
180 if(fileName == QLatin1String(":"))
evaluated: fileName == QLatin1String(":")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:9737
1-9737
181 that->fileName += QLatin1Char('/');
executed: that->fileName += QLatin1Char('/');
Execution Count:1
1
182 that->absoluteFilePath = fileName; -
183 if(!that->absoluteFilePath.startsWith(QLatin1Char(':')))
partially evaluated: !that->absoluteFilePath.startsWith(QLatin1Char(':'))
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9738
0-9738
184 that->absoluteFilePath.prepend(QLatin1Char(':'));
never executed: that->absoluteFilePath.prepend(QLatin1Char(':'));
0
185 -
186 QString path = fileName; -
187 if(path.startsWith(QLatin1Char(':')))
partially evaluated: path.startsWith(QLatin1Char(':'))
TRUEFALSE
yes
Evaluation Count:9738
no
Evaluation Count:0
0-9738
188 path = path.mid(1);
executed: path = path.mid(1);
Execution Count:9738
9738
189 -
190 if(path.startsWith(QLatin1Char('/'))) {
evaluated: path.startsWith(QLatin1Char('/'))
TRUEFALSE
yes
Evaluation Count:9658
yes
Evaluation Count:80
80-9658
191 that->load(path); -
192 } else {
executed: }
Execution Count:9658
9658
193 QMutexLocker lock(resourceMutex()); -
194 QStringList searchPaths = *resourceSearchPaths(); -
195 searchPaths << QLatin1String(""); -
196 for(int i = 0; i < searchPaths.size(); ++i) {
evaluated: i < searchPaths.size()
TRUEFALSE
yes
Evaluation Count:80
yes
Evaluation Count:4
4-80
197 const QString searchPath(searchPaths.at(i) + QLatin1Char('/') + path); -
198 if(that->load(searchPath)) {
evaluated: that->load(searchPath)
TRUEFALSE
yes
Evaluation Count:76
yes
Evaluation Count:4
4-76
199 that->absoluteFilePath = QLatin1Char(':') + searchPath; -
200 break;
executed: break;
Execution Count:76
76
201 } -
202 }
executed: }
Execution Count:4
4
203 }
executed: }
Execution Count:80
80
204} -
205 -
206void -
207QResourcePrivate::ensureChildren() const -
208{ -
209 ensureInitialized(); -
210 if(!children.isEmpty() || !container || related.isEmpty())
partially evaluated: !children.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
partially evaluated: !container
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
partially evaluated: related.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16
0-16
211 return;
never executed: return;
0
212 -
213 QString path = absoluteFilePath, k; -
214 if(path.startsWith(QLatin1Char(':')))
partially evaluated: path.startsWith(QLatin1Char(':'))
TRUEFALSE
yes
Evaluation Count:16
no
Evaluation Count:0
0-16
215 path = path.mid(1);
executed: path = path.mid(1);
Execution Count:16
16
216 QSet<QString> kids; -
217 QString cleaned = cleanPath(path); -
218 for(int i = 0; i < related.size(); ++i) {
evaluated: i < related.size()
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:16
16-18
219 QResourceRoot *res = related.at(i); -
220 if(res->mappingRootSubdir(path, &k) && !k.isEmpty()) {
partially evaluated: res->mappingRootSubdir(path, &k)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
never evaluated: !k.isEmpty()
0-18
221 if(!kids.contains(k)) {
never evaluated: !kids.contains(k)
0
222 children += k; -
223 kids.insert(k); -
224 }
never executed: }
0
225 } else {
never executed: }
0
226 const int node = res->findNode(cleaned); -
227 if(node != -1) {
partially evaluated: node != -1
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-18
228 QStringList related_children = res->children(node); -
229 for(int kid = 0; kid < related_children.size(); ++kid) {
evaluated: kid < related_children.size()
TRUEFALSE
yes
Evaluation Count:183
yes
Evaluation Count:18
18-183
230 k = related_children.at(kid); -
231 if(!kids.contains(k)) {
partially evaluated: !kids.contains(k)
TRUEFALSE
yes
Evaluation Count:183
no
Evaluation Count:0
0-183
232 children += k; -
233 kids.insert(k); -
234 }
executed: }
Execution Count:183
183
235 }
executed: }
Execution Count:183
183
236 }
executed: }
Execution Count:18
18
237 }
executed: }
Execution Count:18
18
238 } -
239}
executed: }
Execution Count:16
16
240QResource::QResource(const QString &file, const QLocale &locale) : d_ptr(new QResourcePrivate(this)) -
241{ -
242 QResourcePrivate * const d = d_func(); -
243 d->fileName = file; -
244 d->locale = locale; -
245}
executed: }
Execution Count:8275
8275
246 -
247 -
248 -
249 -
250QResource::~QResource() -
251{ -
252} -
253void QResource::setLocale(const QLocale &locale) -
254{ -
255 QResourcePrivate * const d = d_func(); -
256 d->clear(); -
257 d->locale = locale; -
258}
never executed: }
0
259 -
260 -
261 -
262 -
263 -
264QLocale QResource::locale() const -
265{ -
266 const QResourcePrivate * const d = d_func(); -
267 return d->locale;
never executed: return d->locale;
0
268} -
269void QResource::setFileName(const QString &file) -
270{ -
271 QResourcePrivate * const d = d_func(); -
272 d->clear(); -
273 d->fileName = file; -
274}
executed: }
Execution Count:8272
8272
275QString QResource::fileName() const -
276{ -
277 const QResourcePrivate * const d = d_func(); -
278 d->ensureInitialized(); -
279 return d->fileName;
executed: return d->fileName;
Execution Count:4134
4134
280} -
281QString QResource::absoluteFilePath() const -
282{ -
283 const QResourcePrivate * const d = d_func(); -
284 d->ensureInitialized(); -
285 return d->absoluteFilePath;
executed: return d->absoluteFilePath;
Execution Count:1879
1879
286} -
287 -
288 -
289 -
290 -
291 -
292 -
293 -
294bool QResource::isValid() const -
295{ -
296 const QResourcePrivate * const d = d_func(); -
297 d->ensureInitialized(); -
298 return !d->related.isEmpty();
executed: return !d->related.isEmpty();
Execution Count:79296
79296
299} -
300bool QResource::isCompressed() const -
301{ -
302 const QResourcePrivate * const d = d_func(); -
303 d->ensureInitialized(); -
304 return d->compressed;
executed: return d->compressed;
Execution Count:85163
85163
305} -
306 -
307 -
308 -
309 -
310 -
311 -
312 -
313qint64 QResource::size() const -
314{ -
315 const QResourcePrivate * const d = d_func(); -
316 d->ensureInitialized(); -
317 return d->size;
executed: return d->size;
Execution Count:73133
73133
318} -
319const uchar *QResource::data() const -
320{ -
321 const QResourcePrivate * const d = d_func(); -
322 d->ensureInitialized(); -
323 return d->data;
executed: return d->data;
Execution Count:2542
2542
324} -
325bool QResource::isDir() const -
326{ -
327 const QResourcePrivate * const d = d_func(); -
328 d->ensureInitialized(); -
329 return d->container;
executed: return d->container;
Execution Count:1861
1861
330} -
331QStringList QResource::children() const -
332{ -
333 const QResourcePrivate * const d = d_func(); -
334 d->ensureChildren(); -
335 return d->children;
executed: return d->children;
Execution Count:16
16
336} -
337void -
338QResource::addSearchPath(const QString &path) -
339{ -
340 if (!path.startsWith(QLatin1Char('/'))) {
never evaluated: !path.startsWith(QLatin1Char('/'))
0
341 QMessageLogger("io/qresource.cpp", 572, __PRETTY_FUNCTION__).warning("QResource::addResourceSearchPath: Search paths must be absolute (start with /) [%s]", -
342 path.toLocal8Bit().data()); -
343 return;
never executed: return;
0
344 } -
345 QMutexLocker lock(resourceMutex()); -
346 resourceSearchPaths()->prepend(path); -
347}
never executed: }
0
348QStringList -
349QResource::searchPaths() -
350{ -
351 QMutexLocker lock(resourceMutex()); -
352 return *resourceSearchPaths();
never executed: return *resourceSearchPaths();
0
353} -
354 -
355inline uint QResourceRoot::hash(int node) const -
356{ -
357 if(!node)
partially evaluated: !node
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:169137
0-169137
358 return 0;
never executed: return 0;
0
359 const int offset = findOffset(node); -
360 int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
361 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
362 name_offset += 2; -
363 return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) + 169137
364 (names[name_offset+2] << 8) + (names[name_offset+3] << 0);
executed: return (names[name_offset+0] << 24) + (names[name_offset+1] << 16) + (names[name_offset+2] << 8) + (names[name_offset+3] << 0);
Execution Count:169137
169137
365} -
366inline QString QResourceRoot::name(int node) const -
367{ -
368 if(!node)
partially evaluated: !node
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:38603
0-38603
369 return QString();
never executed: return QString();
0
370 const int offset = findOffset(node); -
371 -
372 QString ret; -
373 int name_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
374 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
375 const short name_length = (names[name_offset+0] << 8) + -
376 (names[name_offset+1] << 0); -
377 name_offset += 2; -
378 name_offset += 4; -
379 -
380 ret.resize(name_length); -
381 QChar *strData = ret.data(); -
382 for(int i = 0; i < name_length*2; i+=2) {
evaluated: i < name_length*2
TRUEFALSE
yes
Evaluation Count:412595
yes
Evaluation Count:38603
38603-412595
383 QChar c(names[name_offset+i+1], names[name_offset+i]); -
384 *strData = c; -
385 ++strData; -
386 }
executed: }
Execution Count:412595
412595
387 return ret;
executed: return ret;
Execution Count:38603
38603
388} -
389 -
390int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const -
391{ -
392 QString path = _path; -
393 { -
394 QString root = mappingRoot(); -
395 if(!root.isEmpty()) {
partially evaluated: !root.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:29572
0-29572
396 if(root == path) {
never evaluated: root == path
0
397 path = QLatin1Char('/'); -
398 } else {
never executed: }
0
399 if(!root.endsWith(QLatin1Char('/')))
never evaluated: !root.endsWith(QLatin1Char('/'))
0
400 root += QLatin1Char('/');
never executed: root += QLatin1Char('/');
0
401 if(path.size() >= root.size() && path.startsWith(root))
never evaluated: path.size() >= root.size()
never evaluated: path.startsWith(root)
0
402 path = path.mid(root.length()-1);
never executed: path = path.mid(root.length()-1);
0
403 if(path.isEmpty())
never evaluated: path.isEmpty()
0
404 path = QLatin1Char('/');
never executed: path = QLatin1Char('/');
0
405 }
never executed: }
0
406 } -
407 } -
408 -
409 -
410 -
411 -
412 if(path == QLatin1String("/"))
evaluated: path == QLatin1String("/")
TRUEFALSE
yes
Evaluation Count:18
yes
Evaluation Count:29554
18-29554
413 return 0;
executed: return 0;
Execution Count:18
18
414 -
415 -
416 int child_count = (tree[6] << 24) + (tree[7] << 16) + -
417 (tree[8] << 8) + (tree[9] << 0); -
418 int child = (tree[10] << 24) + (tree[11] << 16) + -
419 (tree[12] << 8) + (tree[13] << 0); -
420 -
421 -
422 int node = -1; -
423 -
424 QStringSplitter splitter(path); -
425 while (child_count && splitter.hasNext()) {
partially evaluated: child_count
TRUEFALSE
yes
Evaluation Count:67832
no
Evaluation Count:0
evaluated: splitter.hasNext()
TRUEFALSE
yes
Evaluation Count:61722
yes
Evaluation Count:6110
0-67832
426 QStringRef segment = splitter.next(); -
427 -
428 -
429 -
430 -
431 -
432 -
433 -
434 const uint h = qt_hash(segment.toString()); -
435 -
436 -
437 int l = 0, r = child_count-1; -
438 int sub_node = (l+r+1)/2; -
439 while(r != l) {
evaluated: r != l
TRUEFALSE
yes
Evaluation Count:55035
yes
Evaluation Count:53682
53682-55035
440 const uint sub_node_hash = hash(child+sub_node); -
441 if(h == sub_node_hash)
evaluated: h == sub_node_hash
TRUEFALSE
yes
Evaluation Count:8040
yes
Evaluation Count:46995
8040-46995
442 break;
executed: break;
Execution Count:8040
8040
443 else if(h < sub_node_hash)
evaluated: h < sub_node_hash
TRUEFALSE
yes
Evaluation Count:27640
yes
Evaluation Count:19355
19355-27640
444 r = sub_node - 1;
executed: r = sub_node - 1;
Execution Count:27640
27640
445 else -
446 l = sub_node;
executed: l = sub_node;
Execution Count:19355
19355
447 sub_node = (l + r + 1) / 2; -
448 }
executed: }
Execution Count:46995
46995
449 sub_node += child; -
450 -
451 -
452 bool found = false; -
453 if(hash(sub_node) == h) {
evaluated: hash(sub_node) == h
TRUEFALSE
yes
Evaluation Count:38420
yes
Evaluation Count:23302
23302-38420
454 while(sub_node > child && hash(sub_node-1) == h)
evaluated: sub_node > child
TRUEFALSE
yes
Evaluation Count:8040
yes
Evaluation Count:30380
partially evaluated: hash(sub_node-1) == h
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8040
0-30380
455 --sub_node;
never executed: --sub_node;
0
456 for(; sub_node < child+child_count && hash(sub_node) == h; ++sub_node) {
evaluated: sub_node < child+child_count
TRUEFALSE
yes
Evaluation Count:44340
yes
Evaluation Count:190
evaluated: hash(sub_node) == h
TRUEFALSE
yes
Evaluation Count:38420
yes
Evaluation Count:5920
190-44340
457 if(name(sub_node) == segment) {
partially evaluated: name(sub_node) == segment
TRUEFALSE
yes
Evaluation Count:38420
no
Evaluation Count:0
0-38420
458 found = true; -
459 int offset = findOffset(sub_node); -
460 -
461 -
462 -
463 offset += 4; -
464 -
465 const short flags = (tree[offset+0] << 8) + -
466 (tree[offset+1] << 0); -
467 offset += 2; -
468 -
469 if(!splitter.hasNext()) {
evaluated: !splitter.hasNext()
TRUEFALSE
yes
Evaluation Count:6252
yes
Evaluation Count:32168
6252-32168
470 if(!(flags & Directory)) {
evaluated: !(flags & Directory)
TRUEFALSE
yes
Evaluation Count:6124
yes
Evaluation Count:128
128-6124
471 const short country = (tree[offset+0] << 8) + -
472 (tree[offset+1] << 0); -
473 offset += 2; -
474 -
475 const short language = (tree[offset+0] << 8) + -
476 (tree[offset+1] << 0); -
477 offset += 2; -
478 -
479 -
480 -
481 if(country == locale.country() && language == locale.language()) {
evaluated: country == locale.country()
TRUEFALSE
yes
Evaluation Count:14
yes
Evaluation Count:6110
partially evaluated: language == locale.language()
TRUEFALSE
yes
Evaluation Count:14
no
Evaluation Count:0
0-6110
482 -
483 -
484 -
485 return sub_node;
executed: return sub_node;
Execution Count:14
14
486 } else if((country == QLocale::AnyCountry && language == locale.language()) ||
partially evaluated: country == QLocale::AnyCountry
TRUEFALSE
yes
Evaluation Count:6110
no
Evaluation Count:0
partially evaluated: language == locale.language()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6110
0-6110
487 (country == QLocale::AnyCountry && language == QLocale::C && node == -1)) {
partially evaluated: country == QLocale::AnyCountry
TRUEFALSE
yes
Evaluation Count:6110
no
Evaluation Count:0
partially evaluated: language == QLocale::C
TRUEFALSE
yes
Evaluation Count:6110
no
Evaluation Count:0
partially evaluated: node == -1
TRUEFALSE
yes
Evaluation Count:6110
no
Evaluation Count:0
0-6110
488 node = sub_node; -
489 }
executed: }
Execution Count:6110
6110
490 continue;
executed: continue;
Execution Count:6110
6110
491 } else { -
492 -
493 -
494 -
495 -
496 return sub_node;
executed: return sub_node;
Execution Count:128
128
497 } -
498 } -
499 -
500 if(!(flags & Directory))
partially evaluated: !(flags & Directory)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:32168
0-32168
501 return -1;
never executed: return -1;
0
502 -
503 child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
504 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
505 offset += 4; -
506 child = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
507 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
508 break;
executed: break;
Execution Count:32168
32168
509 } -
510 }
never executed: }
0
511 }
executed: }
Execution Count:38278
38278
512 if(!found)
evaluated: !found
TRUEFALSE
yes
Evaluation Count:23302
yes
Evaluation Count:38278
23302-38278
513 break;
executed: break;
Execution Count:23302
23302
514 }
executed: }
Execution Count:38278
38278
515 -
516 -
517 -
518 return node;
executed: return node;
Execution Count:29412
29412
519} -
520short QResourceRoot::flags(int node) const -
521{ -
522 if(node == -1)
partially evaluated: node == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:12376
0-12376
523 return 0;
never executed: return 0;
0
524 const int offset = findOffset(node) + 4; -
525 return (tree[offset+0] << 8) + (tree[offset+1] << 0);
executed: return (tree[offset+0] << 8) + (tree[offset+1] << 0);
Execution Count:12376
12376
526} -
527const uchar *QResourceRoot::data(int node, qint64 *size) const -
528{ -
529 if(node == -1) {
partially evaluated: node == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6124
0-6124
530 *size = 0; -
531 return 0;
never executed: return 0;
0
532 } -
533 int offset = findOffset(node) + 4; -
534 -
535 const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); -
536 offset += 2; -
537 -
538 offset += 4; -
539 -
540 if(!(flags & Directory)) {
partially evaluated: !(flags & Directory)
TRUEFALSE
yes
Evaluation Count:6124
no
Evaluation Count:0
0-6124
541 const int data_offset = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
542 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
543 const uint data_length = (payloads[data_offset+0] << 24) + (payloads[data_offset+1] << 16) + -
544 (payloads[data_offset+2] << 8) + (payloads[data_offset+3] << 0); -
545 const uchar *ret = payloads+data_offset+4; -
546 *size = data_length; -
547 return ret;
executed: return ret;
Execution Count:6124
6124
548 } -
549 *size = 0; -
550 return 0;
never executed: return 0;
0
551} -
552QStringList QResourceRoot::children(int node) const -
553{ -
554 if(node == -1)
partially evaluated: node == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:18
0-18
555 return QStringList();
never executed: return QStringList();
0
556 int offset = findOffset(node) + 4; -
557 -
558 const short flags = (tree[offset+0] << 8) + (tree[offset+1] << 0); -
559 offset += 2; -
560 -
561 QStringList ret; -
562 if(flags & Directory) {
partially evaluated: flags & Directory
TRUEFALSE
yes
Evaluation Count:18
no
Evaluation Count:0
0-18
563 const int child_count = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
564 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
565 offset += 4; -
566 const int child_off = (tree[offset+0] << 24) + (tree[offset+1] << 16) + -
567 (tree[offset+2] << 8) + (tree[offset+3] << 0); -
568 for(int i = child_off; i < child_off+child_count; ++i)
evaluated: i < child_off+child_count
TRUEFALSE
yes
Evaluation Count:183
yes
Evaluation Count:18
18-183
569 ret << name(i);
executed: ret << name(i);
Execution Count:183
183
570 }
executed: }
Execution Count:18
18
571 return ret;
executed: return ret;
Execution Count:18
18
572} -
573bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const -
574{ -
575 const QString root = mappingRoot(); -
576 if(!root.isEmpty()) {
partially evaluated: !root.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:23320
0-23320
577 const QStringList root_segments = root.split(QLatin1Char('/'), QString::SkipEmptyParts), -
578 path_segments = path.split(QLatin1Char('/'), QString::SkipEmptyParts); -
579 if(path_segments.size() <= root_segments.size()) {
never evaluated: path_segments.size() <= root_segments.size()
0
580 int matched = 0; -
581 for(int i = 0; i < path_segments.size(); ++i) {
never evaluated: i < path_segments.size()
0
582 if(root_segments[i] != path_segments[i])
never evaluated: root_segments[i] != path_segments[i]
0
583 break;
never executed: break;
0
584 ++matched; -
585 }
never executed: }
0
586 if(matched == path_segments.size()) {
never evaluated: matched == path_segments.size()
0
587 if(match && root_segments.size() > matched)
never evaluated: match
never evaluated: root_segments.size() > matched
0
588 *match = root_segments.at(matched);
never executed: *match = root_segments.at(matched);
0
589 return true;
never executed: return true;
0
590 } -
591 }
never executed: }
0
592 }
never executed: }
0
593 return false;
executed: return false;
Execution Count:23320
23320
594} -
595 -
596__attribute__((visibility("default"))) bool qRegisterResourceData(int version, const unsigned char *tree, -
597 const unsigned char *name, const unsigned char *data) -
598{ -
599 QMutexLocker lock(resourceMutex()); -
600 if(version == 0x01 && resourceList()) {
partially evaluated: version == 0x01
TRUEFALSE
yes
Evaluation Count:160
no
Evaluation Count:0
partially evaluated: resourceList()
TRUEFALSE
yes
Evaluation Count:160
no
Evaluation Count:0
0-160
601 bool found = false; -
602 QResourceRoot res(tree, name, data); -
603 for(int i = 0; i < resourceList()->size(); ++i) {
partially evaluated: i < resourceList()->size()
TRUEFALSE
yes
Evaluation Count:400
no
Evaluation Count:0
0-400
604 if(*resourceList()->at(i) == res) {
evaluated: *resourceList()->at(i) == res
TRUEFALSE
yes
Evaluation Count:160
yes
Evaluation Count:240
160-240
605 found = true; -
606 break;
executed: break;
Execution Count:160
160
607 } -
608 }
executed: }
Execution Count:240
240
609 if(!found) {
partially evaluated: !found
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:160
0-160
610 QResourceRoot *root = new QResourceRoot(tree, name, data); -
611 root->ref.ref(); -
612 resourceList()->append(root); -
613 }
never executed: }
0
614 return true;
executed: return true;
Execution Count:160
160
615 } -
616 return false;
never executed: return false;
0
617} -
618 -
619__attribute__((visibility("default"))) bool qUnregisterResourceData(int version, const unsigned char *tree, -
620 const unsigned char *name, const unsigned char *data) -
621{ -
622 QMutexLocker lock(resourceMutex()); -
623 if(version == 0x01 && resourceList()) {
partially evaluated: version == 0x01
TRUEFALSE
yes
Evaluation Count:23
no
Evaluation Count:0
partially evaluated: resourceList()
TRUEFALSE
yes
Evaluation Count:23
no
Evaluation Count:0
0-23
624 QResourceRoot res(tree, name, data); -
625 for(int i = 0; i < resourceList()->size(); ) {
evaluated: i < resourceList()->size()
TRUEFALSE
yes
Evaluation Count:63
yes
Evaluation Count:23
23-63
626 if(*resourceList()->at(i) == res) {
evaluated: *resourceList()->at(i) == res
TRUEFALSE
yes
Evaluation Count:23
yes
Evaluation Count:40
23-40
627 QResourceRoot *root = resourceList()->takeAt(i); -
628 if(!root->ref.deref())
partially evaluated: !root->ref.deref()
TRUEFALSE
yes
Evaluation Count:23
no
Evaluation Count:0
0-23
629 delete root;
executed: delete root;
Execution Count:23
23
630 } else {
executed: }
Execution Count:23
23
631 ++i; -
632 }
executed: }
Execution Count:40
40
633 } -
634 return true;
executed: return true;
Execution Count:23
23
635 } -
636 return false;
never executed: return false;
0
637} -
638 -
639 -
640 -
641class QDynamicBufferResourceRoot: public QResourceRoot -
642{ -
643 QString root; -
644 const uchar *buffer; -
645 -
646public: -
647 inline QDynamicBufferResourceRoot(const QString &_root) : root(_root), buffer(0) { }
never executed: }
0
648 inline ~QDynamicBufferResourceRoot() { } -
649 inline const uchar *mappingBuffer() const { return buffer; }
never executed: return buffer;
0
650 virtual QString mappingRoot() const { return root; }
never executed: return root;
0
651 virtual ResourceRootType type() const { return Resource_Buffer; }
never executed: return Resource_Buffer;
0
652 -
653 bool registerSelf(const uchar *b) { -
654 -
655 int offset = 0; -
656 -
657 -
658 if(b[offset+0] != 'q' || b[offset+1] != 'r' ||
never evaluated: b[offset+0] != 'q'
never evaluated: b[offset+1] != 'r'
0
659 b[offset+2] != 'e' || b[offset+3] != 's') {
never evaluated: b[offset+2] != 'e'
never evaluated: b[offset+3] != 's'
0
660 return false;
never executed: return false;
0
661 } -
662 offset += 4; -
663 -
664 const int version = (b[offset+0] << 24) + (b[offset+1] << 16) + -
665 (b[offset+2] << 8) + (b[offset+3] << 0); -
666 offset += 4; -
667 -
668 const int tree_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + -
669 (b[offset+2] << 8) + (b[offset+3] << 0); -
670 offset += 4; -
671 -
672 const int data_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + -
673 (b[offset+2] << 8) + (b[offset+3] << 0); -
674 offset += 4; -
675 -
676 const int name_offset = (b[offset+0] << 24) + (b[offset+1] << 16) + -
677 (b[offset+2] << 8) + (b[offset+3] << 0); -
678 offset += 4; -
679 -
680 if(version == 0x01) {
never evaluated: version == 0x01
0
681 buffer = b; -
682 setSource(b+tree_offset, b+name_offset, b+data_offset); -
683 return true;
never executed: return true;
0
684 } -
685 return false;
never executed: return false;
0
686 } -
687}; -
688 -
689 -
690 -
691 -
692 -
693 -
694class QDynamicFileResourceRoot: public QDynamicBufferResourceRoot -
695{ -
696 QString fileName; -
697 -
698 uchar *unmapPointer; -
699 unsigned int unmapLength; -
700 -
701public: -
702 inline QDynamicFileResourceRoot(const QString &_root) : QDynamicBufferResourceRoot(_root), unmapPointer(0), unmapLength(0) { }
never executed: }
0
703 ~QDynamicFileResourceRoot() { -
704 -
705 if (unmapPointer) {
never evaluated: unmapPointer
0
706 munmap((char*)unmapPointer, unmapLength); -
707 unmapPointer = 0; -
708 unmapLength = 0; -
709 } else
never executed: }
0
710 -
711 { -
712 delete [] (uchar *)mappingBuffer(); -
713 }
never executed: }
0
714 } -
715 QString mappingFile() const { return fileName; }
never executed: return fileName;
0
716 virtual ResourceRootType type() const { return Resource_File; }
never executed: return Resource_File;
0
717 -
718 bool registerSelf(const QString &f) { -
719 bool fromMM = false; -
720 uchar *data = 0; -
721 unsigned int data_len = 0; -
722 int fd = qt_safe_open(QFile::encodeName(f), 00, -
723 -
724 -
725 -
726 0666 -
727 -
728 ); -
729 if (fd >= 0) {
never evaluated: fd >= 0
0
730 struct stat64 st; -
731 if (!::fstat64(fd, &st)) {
never evaluated: !::fstat64(fd, &st)
0
732 uchar *ptr; -
733 ptr = reinterpret_cast<uchar *>( -
734 mmap(0, st.st_size, -
735 0x1, -
736 0 | 0x02, -
737 fd, 0)); -
738 if (ptr && ptr != reinterpret_cast<uchar *>(((void *) -1))) {
never evaluated: ptr
never evaluated: ptr != reinterpret_cast<uchar *>(((void *) -1))
0
739 data = ptr; -
740 data_len = st.st_size; -
741 fromMM = true; -
742 }
never executed: }
0
743 }
never executed: }
0
744 ::close(fd); -
745 }
never executed: }
0
746 -
747 if(!data) {
never evaluated: !data
0
748 QFile file(f); -
749 if (!file.exists())
never evaluated: !file.exists()
0
750 return false;
never executed: return false;
0
751 data_len = file.size(); -
752 data = new uchar[data_len]; -
753 -
754 bool ok = false; -
755 if (file.open(QIODevice::ReadOnly))
never evaluated: file.open(QIODevice::ReadOnly)
0
756 ok = (data_len == (uint)file.read((char*)data, data_len));
never executed: ok = (data_len == (uint)file.read((char*)data, data_len));
0
757 if (!ok) {
never evaluated: !ok
0
758 delete [] data; -
759 data = 0; -
760 data_len = 0; -
761 return false;
never executed: return false;
0
762 } -
763 fromMM = false; -
764 }
never executed: }
0
765 if(data && QDynamicBufferResourceRoot::registerSelf(data)) {
never evaluated: data
never evaluated: QDynamicBufferResourceRoot::registerSelf(data)
0
766 if(fromMM) {
never evaluated: fromMM
0
767 unmapPointer = data; -
768 unmapLength = data_len; -
769 }
never executed: }
0
770 fileName = f; -
771 return true;
never executed: return true;
0
772 } -
773 return false;
never executed: return false;
0
774 } -
775}; -
776 -
777static QString qt_resource_fixResourceRoot(QString r) { -
778 if(!r.isEmpty()) {
never evaluated: !r.isEmpty()
0
779 if(r.startsWith(QLatin1Char(':')))
never evaluated: r.startsWith(QLatin1Char(':'))
0
780 r = r.mid(1);
never executed: r = r.mid(1);
0
781 if(!r.isEmpty())
never evaluated: !r.isEmpty()
0
782 r = QDir::cleanPath(r);
never executed: r = QDir::cleanPath(r);
0
783 }
never executed: }
0
784 return r;
never executed: return r;
0
785} -
786bool -
787QResource::registerResource(const QString &rccFilename, const QString &resourceRoot) -
788{ -
789 QString r = qt_resource_fixResourceRoot(resourceRoot); -
790 if(!r.isEmpty() && r[0] != QLatin1Char('/')) {
never evaluated: !r.isEmpty()
never evaluated: r[0] != QLatin1Char('/')
0
791 QMessageLogger("io/qresource.cpp", 1067, __PRETTY_FUNCTION__).warning("QDir::registerResource: Registering a resource [%s] must be rooted in an absolute path (start with /) [%s]", -
792 rccFilename.toLocal8Bit().data(), resourceRoot.toLocal8Bit().data()); -
793 return false;
never executed: return false;
0
794 } -
795 -
796 QDynamicFileResourceRoot *root = new QDynamicFileResourceRoot(r); -
797 if(root->registerSelf(rccFilename)) {
never evaluated: root->registerSelf(rccFilename)
0
798 root->ref.ref(); -
799 QMutexLocker lock(resourceMutex()); -
800 resourceList()->append(root); -
801 return true;
never executed: return true;
0
802 } -
803 delete root; -
804 return false;
never executed: return false;
0
805} -
806bool -
807QResource::unregisterResource(const QString &rccFilename, const QString &resourceRoot) -
808{ -
809 QString r = qt_resource_fixResourceRoot(resourceRoot); -
810 -
811 QMutexLocker lock(resourceMutex()); -
812 ResourceList *list = resourceList(); -
813 for(int i = 0; i < list->size(); ++i) {
never evaluated: i < list->size()
0
814 QResourceRoot *res = list->at(i); -
815 if(res->type() == QResourceRoot::Resource_File) {
never evaluated: res->type() == QResourceRoot::Resource_File
0
816 QDynamicFileResourceRoot *root = reinterpret_cast<QDynamicFileResourceRoot*>(res); -
817 if(root->mappingFile() == rccFilename && root->mappingRoot() == r) {
never evaluated: root->mappingFile() == rccFilename
never evaluated: root->mappingRoot() == r
0
818 resourceList()->removeAt(i); -
819 if(!root->ref.deref()) {
never evaluated: !root->ref.deref()
0
820 delete root; -
821 return true;
never executed: return true;
0
822 } -
823 return false;
never executed: return false;
0
824 } -
825 }
never executed: }
0
826 }
never executed: }
0
827 return false;
never executed: return false;
0
828} -
829bool -
830QResource::registerResource(const uchar *rccData, const QString &resourceRoot) -
831{ -
832 QString r = qt_resource_fixResourceRoot(resourceRoot); -
833 if(!r.isEmpty() && r[0] != QLatin1Char('/')) {
never evaluated: !r.isEmpty()
never evaluated: r[0] != QLatin1Char('/')
0
834 QMessageLogger("io/qresource.cpp", 1138, __PRETTY_FUNCTION__).warning("QDir::registerResource: Registering a resource [%p] must be rooted in an absolute path (start with /) [%s]", -
835 rccData, resourceRoot.toLocal8Bit().data()); -
836 return false;
never executed: return false;
0
837 } -
838 -
839 QDynamicBufferResourceRoot *root = new QDynamicBufferResourceRoot(r); -
840 if(root->registerSelf(rccData)) {
never evaluated: root->registerSelf(rccData)
0
841 root->ref.ref(); -
842 QMutexLocker lock(resourceMutex()); -
843 resourceList()->append(root); -
844 return true;
never executed: return true;
0
845 } -
846 delete root; -
847 return false;
never executed: return false;
0
848} -
849bool -
850QResource::unregisterResource(const uchar *rccData, const QString &resourceRoot) -
851{ -
852 QString r = qt_resource_fixResourceRoot(resourceRoot); -
853 -
854 QMutexLocker lock(resourceMutex()); -
855 ResourceList *list = resourceList(); -
856 for(int i = 0; i < list->size(); ++i) {
never evaluated: i < list->size()
0
857 QResourceRoot *res = list->at(i); -
858 if(res->type() == QResourceRoot::Resource_Buffer) {
never evaluated: res->type() == QResourceRoot::Resource_Buffer
0
859 QDynamicBufferResourceRoot *root = reinterpret_cast<QDynamicBufferResourceRoot*>(res); -
860 if(root->mappingBuffer() == rccData && root->mappingRoot() == r) {
never evaluated: root->mappingBuffer() == rccData
never evaluated: root->mappingRoot() == r
0
861 resourceList()->removeAt(i); -
862 if(!root->ref.deref()) {
never evaluated: !root->ref.deref()
0
863 delete root; -
864 return true;
never executed: return true;
0
865 } -
866 return false;
never executed: return false;
0
867 } -
868 }
never executed: }
0
869 }
never executed: }
0
870 return false;
never executed: return false;
0
871} -
872 -
873 -
874class QResourceFileEnginePrivate : public QAbstractFileEnginePrivate -
875{ -
876protected: -
877 inline QResourceFileEngine* q_func() { return static_cast<QResourceFileEngine *>(q_ptr); } inline const QResourceFileEngine* q_func() const { return static_cast<const QResourceFileEngine *>(q_ptr); } friend class QResourceFileEngine; -
878private: -
879 uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags); -
880 bool unmap(uchar *ptr); -
881 qint64 offset; -
882 QResource resource; -
883 QByteArray uncompressed; -
884protected: -
885 QResourceFileEnginePrivate() : offset(0) { }
executed: }
Execution Count:8255
8255
886}; -
887 -
888bool QResourceFileEngine::mkdir(const QString &, bool) const -
889{ -
890 return false;
never executed: return false;
0
891} -
892 -
893bool QResourceFileEngine::rmdir(const QString &, bool) const -
894{ -
895 return false;
never executed: return false;
0
896} -
897 -
898bool QResourceFileEngine::setSize(qint64) -
899{ -
900 return false;
never executed: return false;
0
901} -
902 -
903QStringList QResourceFileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const -
904{ -
905 return QAbstractFileEngine::entryList(filters, filterNames);
never executed: return QAbstractFileEngine::entryList(filters, filterNames);
0
906} -
907 -
908bool QResourceFileEngine::caseSensitive() const -
909{ -
910 return true;
never executed: return true;
0
911} -
912 -
913QResourceFileEngine::QResourceFileEngine(const QString &file) : -
914 QAbstractFileEngine(*new QResourceFileEnginePrivate) -
915{ -
916 QResourceFileEnginePrivate * const d = d_func(); -
917 d->resource.setFileName(file); -
918 if(d->resource.isCompressed() && d->resource.size()) {
evaluated: d->resource.isCompressed()
TRUEFALSE
yes
Evaluation Count:629
yes
Evaluation Count:7626
partially evaluated: d->resource.size()
TRUEFALSE
yes
Evaluation Count:629
no
Evaluation Count:0
0-7626
919 -
920 d->uncompressed = qUncompress(d->resource.data(), d->resource.size()); -
921 -
922 -
923 -
924 }
executed: }
Execution Count:629
629
925}
executed: }
Execution Count:8255
8255
926 -
927QResourceFileEngine::~QResourceFileEngine() -
928{ -
929} -
930 -
931void QResourceFileEngine::setFileName(const QString &file) -
932{ -
933 QResourceFileEnginePrivate * const d = d_func(); -
934 d->resource.setFileName(file); -
935}
executed: }
Execution Count:17
17
936 -
937bool QResourceFileEngine::open(QIODevice::OpenMode flags) -
938{ -
939 QResourceFileEnginePrivate * const d = d_func(); -
940 if (d->resource.fileName().isEmpty()) {
partially evaluated: d->resource.fileName().isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1699
0-1699
941 QMessageLogger("io/qresource.cpp", 1257, __PRETTY_FUNCTION__).warning("QResourceFileEngine::open: Missing file name"); -
942 return false;
never executed: return false;
0
943 } -
944 if(flags & QIODevice::WriteOnly)
evaluated: flags & QIODevice::WriteOnly
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1696
3-1696
945 return false;
executed: return false;
Execution Count:3
3
946 if(!d->resource.isValid())
evaluated: !d->resource.isValid()
TRUEFALSE
yes
Evaluation Count:201
yes
Evaluation Count:1495
201-1495
947 return false;
executed: return false;
Execution Count:201
201
948 return true;
executed: return true;
Execution Count:1495
1495
949} -
950 -
951bool QResourceFileEngine::close() -
952{ -
953 QResourceFileEnginePrivate * const d = d_func(); -
954 d->offset = 0; -
955 d->uncompressed.clear(); -
956 return true;
executed: return true;
Execution Count:1495
1495
957} -
958 -
959bool QResourceFileEngine::flush() -
960{ -
961 return true;
executed: return true;
Execution Count:1495
1495
962} -
963 -
964qint64 QResourceFileEngine::read(char *data, qint64 len) -
965{ -
966 QResourceFileEnginePrivate * const d = d_func(); -
967 if(len > size()-d->offset)
evaluated: len > size()-d->offset
TRUEFALSE
yes
Evaluation Count:34336
yes
Evaluation Count:1421
1421-34336
968 len = size()-d->offset;
executed: len = size()-d->offset;
Execution Count:34336
34336
969 if(len <= 0)
evaluated: len <= 0
TRUEFALSE
yes
Evaluation Count:32873
yes
Evaluation Count:2884
2884-32873
970 return 0;
executed: return 0;
Execution Count:32873
32873
971 if(d->resource.isCompressed())
evaluated: d->resource.isCompressed()
TRUEFALSE
yes
Evaluation Count:977
yes
Evaluation Count:1907
977-1907
972 memcpy(data, d->uncompressed.constData()+d->offset, len);
executed: memcpy(data, d->uncompressed.constData()+d->offset, len);
Execution Count:977
977
973 else -
974 memcpy(data, d->resource.data()+d->offset, len);
executed: memcpy(data, d->resource.data()+d->offset, len);
Execution Count:1907
1907
975 d->offset += len; -
976 return len;
executed: return len;
Execution Count:2884
2884
977} -
978 -
979qint64 QResourceFileEngine::write(const char *, qint64) -
980{ -
981 return -1;
never executed: return -1;
0
982} -
983 -
984bool QResourceFileEngine::remove() -
985{ -
986 return false;
executed: return false;
Execution Count:1
1
987} -
988 -
989bool QResourceFileEngine::copy(const QString &) -
990{ -
991 return false;
executed: return false;
Execution Count:2
2
992} -
993 -
994bool QResourceFileEngine::rename(const QString &) -
995{ -
996 return false;
executed: return false;
Execution Count:1
1
997} -
998 -
999bool QResourceFileEngine::link(const QString &) -
1000{ -
1001 return false;
never executed: return false;
0
1002} -
1003 -
1004qint64 QResourceFileEngine::size() const -
1005{ -
1006 const QResourceFileEnginePrivate * const d = d_func(); -
1007 if(!d->resource.isValid())
evaluated: !d->resource.isValid()
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:74021
2-74021
1008 return 0;
executed: return 0;
Execution Count:2
2
1009 if(d->resource.isCompressed())
evaluated: d->resource.isCompressed()
TRUEFALSE
yes
Evaluation Count:2153
yes
Evaluation Count:71868
2153-71868
1010 return d->uncompressed.size();
executed: return d->uncompressed.size();
Execution Count:2153
2153
1011 return d->resource.size();
executed: return d->resource.size();
Execution Count:71868
71868
1012} -
1013 -
1014qint64 QResourceFileEngine::pos() const -
1015{ -
1016 const QResourceFileEnginePrivate * const d = d_func(); -
1017 return d->offset;
never executed: return d->offset;
0
1018} -
1019 -
1020bool QResourceFileEngine::atEnd() const -
1021{ -
1022 const QResourceFileEnginePrivate * const d = d_func(); -
1023 if(!d->resource.isValid())
never evaluated: !d->resource.isValid()
0
1024 return true;
never executed: return true;
0
1025 return d->offset == size();
never executed: return d->offset == size();
0
1026} -
1027 -
1028bool QResourceFileEngine::seek(qint64 pos) -
1029{ -
1030 QResourceFileEnginePrivate * const d = d_func(); -
1031 if(!d->resource.isValid())
partially evaluated: !d->resource.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:701
0-701
1032 return false;
never executed: return false;
0
1033 -
1034 if(d->offset > size())
partially evaluated: d->offset > size()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:701
0-701
1035 return false;
never executed: return false;
0
1036 d->offset = pos; -
1037 return true;
executed: return true;
Execution Count:701
701
1038} -
1039 -
1040bool QResourceFileEngine::isSequential() const -
1041{ -
1042 return false;
executed: return false;
Execution Count:3128
3128
1043} -
1044 -
1045QAbstractFileEngine::FileFlags QResourceFileEngine::fileFlags(QAbstractFileEngine::FileFlags type) const -
1046{ -
1047 const QResourceFileEnginePrivate * const d = d_func(); -
1048 QAbstractFileEngine::FileFlags ret = 0; -
1049 if(!d->resource.isValid())
evaluated: !d->resource.isValid()
TRUEFALSE
yes
Evaluation Count:959
yes
Evaluation Count:1893
959-1893
1050 return ret;
executed: return ret;
Execution Count:959
959
1051 -
1052 if(type & PermsMask)
evaluated: type & PermsMask
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:1882
11-1882
1053 ret |= QAbstractFileEngine::FileFlags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm);
executed: ret |= QAbstractFileEngine::FileFlags(ReadOwnerPerm|ReadUserPerm|ReadGroupPerm|ReadOtherPerm);
Execution Count:11
11
1054 if(type & TypesMask) {
evaluated: type & TypesMask
TRUEFALSE
yes
Evaluation Count:1861
yes
Evaluation Count:32
32-1861
1055 if(d->resource.isDir())
evaluated: d->resource.isDir()
TRUEFALSE
yes
Evaluation Count:17
yes
Evaluation Count:1844
17-1844
1056 ret |= DirectoryType;
executed: ret |= DirectoryType;
Execution Count:17
17
1057 else -
1058 ret |= FileType;
executed: ret |= FileType;
Execution Count:1844
1844
1059 } -
1060 if(type & FlagsMask) {
evaluated: type & FlagsMask
TRUEFALSE
yes
Evaluation Count:1878
yes
Evaluation Count:15
15-1878
1061 ret |= ExistsFlag; -
1062 if(d->resource.absoluteFilePath() == QLatin1String(":/"))
evaluated: d->resource.absoluteFilePath() == QLatin1String(":/")
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1877
1-1877
1063 ret |= RootFlag;
executed: ret |= RootFlag;
Execution Count:1
1
1064 }
executed: }
Execution Count:1878
1878
1065 return ret;
executed: return ret;
Execution Count:1893
1893
1066} -
1067 -
1068bool QResourceFileEngine::setPermissions(uint) -
1069{ -
1070 return false;
never executed: return false;
0
1071} -
1072 -
1073QString QResourceFileEngine::fileName(FileName file) const -
1074{ -
1075 const QResourceFileEnginePrivate * const d = d_func(); -
1076 if(file == BaseName) {
partially evaluated: file == BaseName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2436
0-2436
1077 int slash = d->resource.fileName().lastIndexOf(QLatin1Char('/')); -
1078 if (slash == -1)
never evaluated: slash == -1
0
1079 return d->resource.fileName();
never executed: return d->resource.fileName();
0
1080 return d->resource.fileName().mid(slash + 1);
never executed: return d->resource.fileName().mid(slash + 1);
0
1081 } else if(file == PathName || file == AbsolutePathName) {
partially evaluated: file == PathName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2436
partially evaluated: file == AbsolutePathName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2436
0-2436
1082 const QString path = (file == AbsolutePathName) ? d->resource.absoluteFilePath() : d->resource.fileName();
never evaluated: (file == AbsolutePathName)
0
1083 const int slash = path.lastIndexOf(QLatin1Char('/')); -
1084 if (slash == -1)
never evaluated: slash == -1
0
1085 return QLatin1String(":");
never executed: return QLatin1String(":");
0
1086 else if (slash <= 1)
never evaluated: slash <= 1
0
1087 return QLatin1String(":/");
never executed: return QLatin1String(":/");
0
1088 return path.left(slash);
never executed: return path.left(slash);
0
1089 -
1090 } else if(file == CanonicalName || file == CanonicalPathName) {
evaluated: file == CanonicalName
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2435
partially evaluated: file == CanonicalPathName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:2435
0-2435
1091 const QString absoluteFilePath = d->resource.absoluteFilePath(); -
1092 if(file == CanonicalPathName) {
partially evaluated: file == CanonicalPathName
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1
0-1
1093 const int slash = absoluteFilePath.lastIndexOf(QLatin1Char('/')); -
1094 if (slash != -1)
never evaluated: slash != -1
0
1095 return absoluteFilePath.left(slash);
never executed: return absoluteFilePath.left(slash);
0
1096 }
never executed: }
0
1097 return absoluteFilePath;
executed: return absoluteFilePath;
Execution Count:1
1
1098 } -
1099 return d->resource.fileName();
executed: return d->resource.fileName();
Execution Count:2435
2435
1100} -
1101 -
1102bool QResourceFileEngine::isRelativePath() const -
1103{ -
1104 return false;
executed: return false;
Execution Count:13
13
1105} -
1106 -
1107uint QResourceFileEngine::ownerId(FileOwner) const -
1108{ -
1109 static const uint nobodyID = (uint) -2; -
1110 return nobodyID;
never executed: return nobodyID;
0
1111} -
1112 -
1113QString QResourceFileEngine::owner(FileOwner) const -
1114{ -
1115 return QString();
never executed: return QString();
0
1116} -
1117 -
1118QDateTime QResourceFileEngine::fileTime(FileTime) const -
1119{ -
1120 return QDateTime();
executed: return QDateTime();
Execution Count:1658
1658
1121} -
1122 -
1123 -
1124 -
1125 -
1126QAbstractFileEngine::Iterator *QResourceFileEngine::beginEntryList(QDir::Filters filters, -
1127 const QStringList &filterNames) -
1128{ -
1129 return new QResourceFileEngineIterator(filters, filterNames);
executed: return new QResourceFileEngineIterator(filters, filterNames);
Execution Count:17
17
1130} -
1131 -
1132 -
1133 -
1134 -
1135QAbstractFileEngine::Iterator *QResourceFileEngine::endEntryList() -
1136{ -
1137 return 0;
never executed: return 0;
0
1138} -
1139 -
1140bool QResourceFileEngine::extension(Extension extension, const ExtensionOption *option, ExtensionReturn *output) -
1141{ -
1142 QResourceFileEnginePrivate * const d = d_func(); -
1143 if (extension == MapExtension) {
evaluated: extension == MapExtension
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:9
9-10
1144 const MapExtensionOption *options = (MapExtensionOption*)(option); -
1145 MapExtensionReturn *returnValue = static_cast<MapExtensionReturn*>(output); -
1146 returnValue->address = d->map(options->offset, options->size, options->flags); -
1147 return (returnValue->address != 0);
executed: return (returnValue->address != 0);
Execution Count:10
10
1148 } -
1149 if (extension == UnMapExtension) {
partially evaluated: extension == UnMapExtension
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
1150 UnMapExtensionOption *options = (UnMapExtensionOption*)option; -
1151 return d->unmap(options->address);
executed: return d->unmap(options->address);
Execution Count:9
9
1152 } -
1153 return false;
never executed: return false;
0
1154} -
1155 -
1156bool QResourceFileEngine::supportsExtension(Extension extension) const -
1157{ -
1158 return (extension == UnMapExtension || extension == MapExtension);
executed: return (extension == UnMapExtension || extension == MapExtension);
Execution Count:47
47
1159} -
1160 -
1161uchar *QResourceFileEnginePrivate::map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags) -
1162{ -
1163 QResourceFileEngine * const q = q_func(); -
1164 (void)flags;; -
1165 if (offset < 0 || size <= 0 || !resource.isValid() || offset + size > resource.size()) {
evaluated: offset < 0
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8
evaluated: size <= 0
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:4
evaluated: !resource.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:3
evaluated: offset + size > resource.size()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-8
1166 q->setError(QFile::UnspecifiedError, QString()); -
1167 return 0;
executed: return 0;
Execution Count:8
8
1168 } -
1169 uchar *address = const_cast<uchar *>(resource.data()); -
1170 return (address + offset);
executed: return (address + offset);
Execution Count:2
2
1171} -
1172 -
1173bool QResourceFileEnginePrivate::unmap(uchar *ptr) -
1174{ -
1175 (void)ptr;; -
1176 return true;
executed: return true;
Execution Count:9
9
1177} -
1178 -
1179 -
1180 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial