1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtTest/QtTest>
47 # include <sys/stat.h>
48 # include <sys/types.h>
53 class bench_QDir_10000 : public QObject{
57 QDir testdir = QDir::tempPath();
59 const QString subfolder_name = QLatin1String("test_speed");
60 QVERIFY(testdir.mkdir(subfolder_name));
61 QVERIFY(testdir.cd(subfolder_name));
63 for (uint i=0; i<10000; ++i) {
64 QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i));
65 file.open(QIODevice::WriteOnly);
68 void cleanupTestCase() {
70 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
71 testdir.setSorting(QDir::Unsorted);
72 testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
73 foreach (const QString &filename, testdir.entryList()) {
74 testdir.remove(filename);
77 const QDir temp = QDir(QDir::tempPath());
78 temp.rmdir(QLatin1String("test_speed"));
84 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
86 QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted);
87 foreach (const QFileInfo &fileInfo, fileInfoList) {
93 void sizeSpeedIterator() {
94 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
96 QDirIterator dit(testdir.path(), QDir::Files);
97 while (dit.hasNext()) {
99 dit.fileInfo().isDir();
100 dit.fileInfo().size();
105 void sizeSpeedWithoutFilter() {
106 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
108 QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted);
109 foreach (const QFileInfo &fileInfo, fileInfoList) {
114 void sizeSpeedWithoutFilterIterator() {
115 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
117 QDirIterator dit(testdir.path());
118 while (dit.hasNext()) {
120 dit.fileInfo().isDir();
121 dit.fileInfo().size();
126 void sizeSpeedWithoutFileInfoList() {
127 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
128 testdir.setSorting(QDir::Unsorted);
130 QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
131 foreach (const QString &filename, fileList) {
132 QFileInfo fileInfo(filename);
138 void iDontWantAnyStat() {
139 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
140 testdir.setSorting(QDir::Unsorted);
141 testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
143 QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
144 foreach (const QString &filename, fileList) {
149 void iDontWantAnyStatIterator() {
151 QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed"));
152 while (dit.hasNext()) {
158 void sorted_byTime() {
159 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
160 testdir.setSorting(QDir::Time);
161 testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
163 QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Time);
164 foreach (const QString &filename, fileList) {
170 void sizeSpeedWithoutFilterLowLevel() {
171 QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
173 const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16();
174 wchar_t appendedPath[MAX_PATH];
175 wcscpy(appendedPath, dirpath);
176 wcscat(appendedPath, L"\\*");
179 HANDLE hSearch = FindFirstFileW(appendedPath, &fd);
180 QVERIFY(hSearch != INVALID_HANDLE_VALUE);
185 } while (FindNextFile(hSearch, &fd));
189 DIR *dir = opendir(qPrintable(testdir.absolutePath()));
192 QVERIFY(!chdir(qPrintable(testdir.absolutePath())));
194 struct dirent *item = readdir(dir);
196 char *fileName = item->d_name;
198 struct stat fileStat;
199 QVERIFY(!stat(fileName, &fileStat));
209 QTEST_MAIN(bench_QDir_10000)
210 #include "bench_qdir_10000.moc"