|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <QtTest/QTest> |
|
43 |
|
44 #include <QDirIterator> |
|
45 #include <QFile> |
|
46 #include <QString> |
|
47 #include <QStack> |
|
48 |
|
49 #include "../../../../../shared/filesystem.h" |
|
50 |
|
51 class bench_QDir_tree |
|
52 : public QObject |
|
53 { |
|
54 Q_OBJECT |
|
55 |
|
56 public: |
|
57 bench_QDir_tree() |
|
58 : prefix("./test-tree/") |
|
59 { |
|
60 } |
|
61 |
|
62 private: |
|
63 QByteArray prefix; |
|
64 |
|
65 private slots: |
|
66 void initTestCase() |
|
67 { |
|
68 QFile list(":/4.6.0-list.txt"); |
|
69 QVERIFY(list.open(QIODevice::ReadOnly | QIODevice::Text)); |
|
70 |
|
71 QVERIFY(fs.createDirectory(prefix)); |
|
72 |
|
73 QStack<QByteArray> stack; |
|
74 QByteArray line; |
|
75 Q_FOREVER { |
|
76 char ch; |
|
77 if (!list.getChar(&ch)) |
|
78 break; |
|
79 if (ch != ' ') { |
|
80 line.append(ch); |
|
81 continue; |
|
82 } |
|
83 |
|
84 int pop = 1; |
|
85 if (!line.isEmpty()) |
|
86 pop = line.toInt(); |
|
87 |
|
88 while (pop) { |
|
89 stack.pop(); |
|
90 --pop; |
|
91 } |
|
92 |
|
93 line = list.readLine(); |
|
94 line.chop(1); |
|
95 stack.push(line); |
|
96 |
|
97 line = prefix; |
|
98 Q_FOREACH(const QByteArray &pathElement, stack) |
|
99 line += pathElement; |
|
100 |
|
101 if (line.endsWith('/')) |
|
102 QVERIFY(fs.createDirectory(line)); |
|
103 else |
|
104 QVERIFY(fs.createFile(line)); |
|
105 |
|
106 line.clear(); |
|
107 } |
|
108 } |
|
109 |
|
110 void fileSearch_data() const |
|
111 { |
|
112 QTest::addColumn<QStringList>("nameFilters"); |
|
113 QTest::addColumn<int>("filter"); |
|
114 QTest::addColumn<int>("entryCount"); |
|
115 |
|
116 QTest::newRow("*.cpp") << QStringList("*.cpp") |
|
117 << int(QDir::Files) |
|
118 << 3813; |
|
119 |
|
120 QTest::newRow("executables") << QStringList("*") |
|
121 << int(QDir::Executable | QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot) |
|
122 << 543; |
|
123 } |
|
124 |
|
125 void fileSearch() const |
|
126 { |
|
127 QFETCH(QStringList, nameFilters); |
|
128 QFETCH(int, filter); |
|
129 QFETCH(int, entryCount); |
|
130 |
|
131 int count = 0; |
|
132 QBENCHMARK { |
|
133 // Recursive directory iteration |
|
134 QDirIterator iterator(prefix, nameFilters, QDir::Filter(filter), |
|
135 QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); |
|
136 |
|
137 count = 0; |
|
138 while (iterator.hasNext()) { |
|
139 iterator.next(); |
|
140 ++count; |
|
141 } |
|
142 |
|
143 QCOMPARE(count, entryCount); |
|
144 } |
|
145 |
|
146 QCOMPARE(count, entryCount); |
|
147 } |
|
148 |
|
149 void traverseDirectory() const |
|
150 { |
|
151 int count = 0; |
|
152 QBENCHMARK { |
|
153 QDirIterator iterator(prefix, |
|
154 QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, |
|
155 QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); |
|
156 |
|
157 while (iterator.hasNext()) { |
|
158 iterator.next(); |
|
159 ++count; |
|
160 } |
|
161 |
|
162 QCOMPARE(count, 11963); |
|
163 } |
|
164 |
|
165 QCOMPARE(count, 11963); |
|
166 } |
|
167 |
|
168 private: |
|
169 FileSystem fs; |
|
170 }; |
|
171 |
|
172 QTEST_MAIN(bench_QDir_tree) |
|
173 #include "bench_qdir_tree.moc" |