summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBradley T. Hughes <bradley.hughes@nokia.com>2009-06-16 12:16:23 (GMT)
committerBradley T. Hughes <bradley.hughes@nokia.com>2009-06-16 12:16:23 (GMT)
commit714a62490fd30986dc86559e6f14194a34b3a5bc (patch)
treec5c189fb22eb2f20a6cf70c176f02dd348c83610 /tests
parentaa1120804708c44ac72e20e228d5ef383a1cd62a (diff)
parentc41591d57377cd7c520efc93d9c087ad34d2bb6f (diff)
downloadQt-714a62490fd30986dc86559e6f14194a34b3a5bc.zip
Qt-714a62490fd30986dc86559e6f14194a34b3a5bc.tar.gz
Qt-714a62490fd30986dc86559e6f14194a34b3a5bc.tar.bz2
Merge branch 'master' of git@scm.dev.nokia.troll.no:qt/qt
Conflicts: doc/src/qnamespace.qdoc doc/src/snippets/code/src_gui_qproxystyle.cpp src/3rdparty/webkit/VERSION src/3rdparty/webkit/WebKit/qt/ChangeLog src/gui/graphicsview/qgraphicsscene.cpp src/gui/kernel/qapplication.cpp src/gui/kernel/qapplication_x11.cpp src/gui/kernel/qt_x11_p.h src/gui/kernel/qwidget.cpp src/gui/styles/qproxystyle.cpp src/gui/styles/qstyle.cpp src/scripttools/debugging/qscriptdebugger.cpp src/scripttools/debugging/qscriptenginedebugger.cpp src/sql/drivers/odbc/qsql_odbc.cpp src/sql/kernel/qsqldatabase.cpp src/sql/kernel/qsqldriver.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qscriptable/tst_qscriptable.cpp18
-rw-r--r--tests/auto/qscriptcontext/tst_qscriptcontext.cpp18
-rw-r--r--tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp20
-rw-r--r--tests/auto/qscriptengine/tst_qscriptengine.cpp128
-rw-r--r--tests/auto/qscriptenginedebugger/tst_qscriptenginedebugger.cpp14
-rw-r--r--tests/auto/qscriptqobject/tst_qscriptqobject.cpp16
-rw-r--r--tests/auto/qscriptvalue/tst_qscriptvalue.cpp34
-rw-r--r--tests/auto/qtransform/tst_qtransform.cpp2
-rw-r--r--tests/benchmarks/qdir/qdir.pro8
-rw-r--r--tests/benchmarks/qdir/tst_qdir.cpp98
10 files changed, 353 insertions, 3 deletions
diff --git a/tests/auto/qscriptable/tst_qscriptable.cpp b/tests/auto/qscriptable/tst_qscriptable.cpp
index 5eabbee..1dd975a 100644
--- a/tests/auto/qscriptable/tst_qscriptable.cpp
+++ b/tests/auto/qscriptable/tst_qscriptable.cpp
@@ -49,7 +49,7 @@
//TESTED_CLASS=
//TESTED_FILES=
-class MyScriptable : public QObject, protected QScriptable
+class MyScriptable : public QObject, public QScriptable
{
Q_OBJECT
Q_PROPERTY(int baz READ baz WRITE setBaz)
@@ -87,6 +87,7 @@ public slots:
QObject *zab();
QObject *setZab(QObject *);
QScriptValue getArguments();
+ int getArgumentCount();
signals:
void sig(int);
@@ -128,6 +129,11 @@ QScriptValue MyScriptable::getArguments()
return context()->argumentsObject();
}
+int MyScriptable::getArgumentCount()
+{
+ return context()->argumentCount();
+}
+
void MyScriptable::foo()
{
m_lastEngine = engine();
@@ -224,6 +230,8 @@ void tst_QScriptable::cleanupTestCase()
void tst_QScriptable::engine()
{
+ QCOMPARE(m_scriptable.engine(), (QScriptEngine*)0);
+ QCOMPARE(m_scriptable.context(), (QScriptContext*)0);
QCOMPARE(m_scriptable.lastEngine(), (QScriptEngine *)0);
// reading property
@@ -360,6 +368,14 @@ void tst_QScriptable::arguments()
QVERIFY(args.property("1").strictlyEquals(QScriptValue(&m_engine, 20)));
QVERIFY(args.property("2").strictlyEquals(QScriptValue(&m_engine, 30)));
QVERIFY(args.property("3").strictlyEquals(QScriptValue(&m_engine, "hi")));
+
+ QScriptValue argc = m_engine.evaluate("scriptable.getArgumentCount(1, 2, 3)");
+ QVERIFY(argc.isNumber());
+ QCOMPARE(argc.toInt32(), 3);
+
+ QCOMPARE(m_scriptable.argumentCount(), -1);
+ QVERIFY(!m_scriptable.argument(-1).isValid());
+ QVERIFY(!m_scriptable.argument(0).isValid());
}
void tst_QScriptable::throwError()
diff --git a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
index bfcd6ee..e2eb8cf0 100644
--- a/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
+++ b/tests/auto/qscriptcontext/tst_qscriptcontext.cpp
@@ -72,6 +72,7 @@ private slots:
void scopeChain();
void pushAndPopScope();
void getSetActivationObject();
+ void toString();
};
tst_QScriptContext::tst_QScriptContext()
@@ -438,6 +439,7 @@ void tst_QScriptContext::pushAndPopContext()
QCOMPARE(ctx->isCalledAsConstructor(), false);
QCOMPARE(ctx->argumentCount(), 0);
QCOMPARE(ctx->argument(0).isUndefined(), true);
+ QVERIFY(!ctx->argument(-1).isValid());
QCOMPARE(ctx->argumentsObject().isObject(), true);
QCOMPARE(ctx->activationObject().isObject(), true);
QCOMPARE(ctx->callee().isValid(), false);
@@ -687,5 +689,21 @@ void tst_QScriptContext::getSetActivationObject()
}
}
+static QScriptValue parentContextToString(QScriptContext *ctx, QScriptEngine *)
+{
+ return ctx->parentContext()->toString();
+}
+
+void tst_QScriptContext::toString()
+{
+ QScriptEngine eng;
+ eng.globalObject().setProperty("parentContextToString", eng.newFunction(parentContextToString));
+ QScriptValue ret = eng.evaluate("function foo(first, second, third) {\n"
+ " return parentContextToString();\n"
+ "}; foo(1, 2, 3)", "script.qs");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("foo (first=1, second=2, third=3) at script.qs:2"));
+}
+
QTEST_MAIN(tst_QScriptContext)
#include "tst_qscriptcontext.moc"
diff --git a/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp b/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp
index df1e14f..82c66f8 100644
--- a/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp
+++ b/tests/auto/qscriptcontextinfo/tst_qscriptcontextinfo.cpp
@@ -95,6 +95,7 @@ private slots:
void builtinFunctionNames();
void nullContext();
void streaming();
+ void assignmentAndComparison();
};
tst_QScriptContextInfo::tst_QScriptContextInfo()
@@ -553,5 +554,24 @@ void tst_QScriptContextInfo::streaming()
}
}
+void tst_QScriptContextInfo::assignmentAndComparison()
+{
+ QScriptEngine eng;
+ eng.globalObject().setProperty("getContextInfoList", eng.newFunction(getContextInfoList));
+ QString fileName = "ciao.qs";
+ int lineNumber = 456;
+ QScriptValue ret = eng.evaluate("function bar(a, b, c) {\n return getContextInfoList();\n}\nbar()",
+ fileName, lineNumber);
+ QList<QScriptContextInfo> lst = qscriptvalue_cast<QList<QScriptContextInfo> >(ret);
+ QCOMPARE(lst.size(), 3);
+ QScriptContextInfo ci = lst.at(0);
+ QScriptContextInfo same = ci;
+ QVERIFY(ci == same);
+ QVERIFY(!(ci != same));
+ QScriptContextInfo other = lst.at(1);
+ QVERIFY(!(ci == other));
+ QVERIFY(ci != other);
+}
+
QTEST_MAIN(tst_QScriptContextInfo)
#include "tst_qscriptcontextinfo.moc"
diff --git a/tests/auto/qscriptengine/tst_qscriptengine.cpp b/tests/auto/qscriptengine/tst_qscriptengine.cpp
index fe60cd0..230f889 100644
--- a/tests/auto/qscriptengine/tst_qscriptengine.cpp
+++ b/tests/auto/qscriptengine/tst_qscriptengine.cpp
@@ -64,6 +64,7 @@ public:
virtual ~tst_QScriptEngine();
private slots:
+ void constructWithParent();
void currentContext();
void pushPopContext();
void getSetDefaultPrototype();
@@ -119,6 +120,7 @@ private slots:
void getSetAgent();
void reentrancy();
void incDecNonObjectProperty();
+ void installTranslatorFunctions();
};
tst_QScriptEngine::tst_QScriptEngine()
@@ -129,6 +131,17 @@ tst_QScriptEngine::~tst_QScriptEngine()
{
}
+void tst_QScriptEngine::constructWithParent()
+{
+ QPointer<QScriptEngine> ptr;
+ {
+ QObject obj;
+ QScriptEngine *engine = new QScriptEngine(&obj);
+ ptr = engine;
+ }
+ QVERIFY(ptr == 0);
+}
+
void tst_QScriptEngine::currentContext()
{
QScriptEngine eng;
@@ -945,6 +958,22 @@ void tst_QScriptEngine::checkSyntax()
QCOMPARE(result.errorLineNumber(), errorLineNumber);
QCOMPARE(result.errorColumnNumber(), errorColumnNumber);
QCOMPARE(result.errorMessage(), errorMessage);
+
+ // assignment
+ {
+ QScriptSyntaxCheckResult copy = result;
+ QCOMPARE(copy.state(), result.state());
+ QCOMPARE(copy.errorLineNumber(), result.errorLineNumber());
+ QCOMPARE(copy.errorColumnNumber(), result.errorColumnNumber());
+ QCOMPARE(copy.errorMessage(), result.errorMessage());
+ }
+ {
+ QScriptSyntaxCheckResult copy(result);
+ QCOMPARE(copy.state(), result.state());
+ QCOMPARE(copy.errorLineNumber(), result.errorLineNumber());
+ QCOMPARE(copy.errorColumnNumber(), result.errorColumnNumber());
+ QCOMPARE(copy.errorMessage(), result.errorMessage());
+ }
}
void tst_QScriptEngine::canEvaluate_data()
@@ -1467,6 +1496,61 @@ void tst_QScriptEngine::valueConversion()
Foo foo = qScriptValueToValue<Foo>(str);
QCOMPARE(foo.x, 123);
}
+
+ // more built-in types
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, uint(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, qulonglong(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, float(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, short(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, ushort(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, char(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QScriptValue val = qScriptValueFromValue(&eng, uchar(123));
+ QVERIFY(val.isNumber());
+ QCOMPARE(val.toInt32(), 123);
+ }
+ {
+ QDateTime in = QDateTime::currentDateTime();
+ QScriptValue val = qScriptValueFromValue(&eng, in);
+ QVERIFY(val.isDate());
+ QCOMPARE(val.toDateTime(), in);
+ }
+ {
+ QDate in = QDate::currentDate();
+ QScriptValue val = qScriptValueFromValue(&eng, in);
+ QVERIFY(val.isDate());
+ QCOMPARE(val.toDateTime().date(), in);
+ }
+ {
+ QRegExp in = QRegExp("foo");
+ QScriptValue val = qScriptValueFromValue(&eng, in);
+ QVERIFY(val.isRegExp());
+ QCOMPARE(val.toRegExp(), in);
+ }
}
static QScriptValue __import__(QScriptContext *ctx, QScriptEngine *eng)
@@ -3415,5 +3499,49 @@ void tst_QScriptEngine:: incDecNonObjectProperty()
}
}
+void tst_QScriptEngine::installTranslatorFunctions()
+{
+ QScriptEngine eng;
+ QScriptValue global = eng.globalObject();
+ QVERIFY(!global.property("qsTranslate").isValid());
+ QVERIFY(!global.property("QT_TRANSLATE_NOOP").isValid());
+ QVERIFY(!global.property("qsTr").isValid());
+ QVERIFY(!global.property("QT_TR_NOOP").isValid());
+ QVERIFY(!global.property("String").property("prototype").property("arg").isValid());
+
+ eng.installTranslatorFunctions();
+ QVERIFY(global.property("qsTranslate").isFunction());
+ QVERIFY(global.property("QT_TRANSLATE_NOOP").isFunction());
+ QVERIFY(global.property("qsTr").isFunction());
+ QVERIFY(global.property("QT_TR_NOOP").isFunction());
+ QVERIFY(global.property("String").property("prototype").property("arg").isFunction());
+
+ {
+ QScriptValue ret = eng.evaluate("qsTr('foo')");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("foo"));
+ }
+ {
+ QScriptValue ret = eng.evaluate("qsTranslate('foo', 'bar')");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("bar"));
+ }
+ {
+ QScriptValue ret = eng.evaluate("QT_TR_NOOP('foo')");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("foo"));
+ }
+ {
+ QScriptValue ret = eng.evaluate("QT_TRANSLATE_NOOP('foo', 'bar')");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("bar"));
+ }
+ {
+ QScriptValue ret = eng.evaluate("'foo%0'.arg('bar')");
+ QVERIFY(ret.isString());
+ QCOMPARE(ret.toString(), QString::fromLatin1("foobar"));
+ }
+}
+
QTEST_MAIN(tst_QScriptEngine)
#include "tst_qscriptengine.moc"
diff --git a/tests/auto/qscriptenginedebugger/tst_qscriptenginedebugger.cpp b/tests/auto/qscriptenginedebugger/tst_qscriptenginedebugger.cpp
index aa5da04..41e14ce 100644
--- a/tests/auto/qscriptenginedebugger/tst_qscriptenginedebugger.cpp
+++ b/tests/auto/qscriptenginedebugger/tst_qscriptenginedebugger.cpp
@@ -118,8 +118,22 @@ void tst_QScriptEngineDebugger::attachAndDetach()
{
QScriptEngineDebugger debugger;
QScriptEngine engine;
+ QScriptValue oldPrint = engine.globalObject().property("print");
+ QVERIFY(oldPrint.isFunction());
+ QVERIFY(!engine.globalObject().property("__FILE__").isValid());
+ QVERIFY(!engine.globalObject().property("__LINE__").isValid());
+
debugger.attachTo(&engine);
+ QVERIFY(engine.globalObject().property("__FILE__").isUndefined());
+ QVERIFY(engine.globalObject().property("__LINE__").isNumber());
+ QVERIFY(!engine.globalObject().property("print").strictlyEquals(oldPrint));
+
debugger.detach();
+ QEXPECT_FAIL("", "Task 256184", Continue);
+ QVERIFY(!engine.globalObject().property("print").isValid());
+ QEXPECT_FAIL("", "Task 256184", Continue);
+ QVERIFY(!engine.globalObject().property("__FILE__").isValid());
+// QVERIFY(!engine.globalObject().property("__LINE__").isValid());
}
{
QScriptEngineDebugger debugger;
diff --git a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp
index 2c47c49..24c283e 100644
--- a/tests/auto/qscriptqobject/tst_qscriptqobject.cpp
+++ b/tests/auto/qscriptqobject/tst_qscriptqobject.cpp
@@ -1906,6 +1906,22 @@ void tst_QScriptExtQObject::cppConnectAndDisconnect()
QVERIFY(qScriptDisconnect(m_myObject, SIGNAL(mySignal()), QScriptValue(), fun));
QCOMPARE(m_myObject->disconnectedSignal().constData(), SIGNAL(mySignal()));
}
+
+ // bad args
+ QVERIFY(!qScriptConnect(0, SIGNAL(foo()), QScriptValue(), fun));
+ QVERIFY(!qScriptConnect(&edit, 0, QScriptValue(), fun));
+ QVERIFY(!qScriptConnect(&edit, SIGNAL(foo()), QScriptValue(), fun));
+ QVERIFY(!qScriptConnect(&edit, SIGNAL(textChanged(QString)), QScriptValue(), QScriptValue()));
+ QVERIFY(!qScriptDisconnect(0, SIGNAL(foo()), QScriptValue(), fun));
+ QVERIFY(!qScriptDisconnect(&edit, 0, QScriptValue(), fun));
+ QVERIFY(!qScriptDisconnect(&edit, SIGNAL(foo()), QScriptValue(), fun));
+ QVERIFY(!qScriptDisconnect(&edit, SIGNAL(textChanged(QString)), QScriptValue(), QScriptValue()));
+ {
+ QScriptEngine eng2;
+ QScriptValue receiverInDifferentEngine = eng2.newObject();
+ QVERIFY(!qScriptConnect(&edit, SIGNAL(textChanged(QString)), receiverInDifferentEngine, fun));
+ QVERIFY(!qScriptDisconnect(&edit, SIGNAL(textChanged(QString)), receiverInDifferentEngine, fun));
+ }
}
void tst_QScriptExtQObject::classEnums()
diff --git a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
index ad1080a..7901b65 100644
--- a/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
+++ b/tests/auto/qscriptvalue/tst_qscriptvalue.cpp
@@ -1482,21 +1482,43 @@ void tst_QScriptValue::toObject()
{
QScriptValue undefined = QScriptValue(QScriptValue::UndefinedValue);
QVERIFY(!undefined.toObject().isValid());
+ QVERIFY(!eng.toObject(undefined).isValid());
QScriptValue null = QScriptValue(QScriptValue::NullValue);
QVERIFY(!null.toObject().isValid());
+ QVERIFY(!eng.toObject(null).isValid());
QScriptValue falskt = QScriptValue(false);
QVERIFY(!falskt.toObject().isValid());
+ {
+ QScriptValue tmp = eng.toObject(falskt);
+ QVERIFY(tmp.isObject());
+ QVERIFY(tmp.toBool());
+ }
QScriptValue sant = QScriptValue(true);
QVERIFY(!sant.toObject().isValid());
+ {
+ QScriptValue tmp = eng.toObject(sant);
+ QVERIFY(tmp.isObject());
+ QVERIFY(tmp.toBool());
+ }
QScriptValue number = QScriptValue(123.0);
QVERIFY(!number.toObject().isValid());
+ {
+ QScriptValue tmp = eng.toObject(number);
+ QVERIFY(tmp.isObject());
+ QCOMPARE(tmp.toInt32(), number.toInt32());
+ }
- QScriptValue str = QScriptValue(QString("ciao"));
+ QScriptValue str = QScriptValue(QString::fromLatin1("ciao"));
QVERIFY(!str.toObject().isValid());
+ {
+ QScriptValue tmp = eng.toObject(str);
+ QVERIFY(tmp.isObject());
+ QCOMPARE(tmp.toString(), QString::fromLatin1("ciao"));
+ }
}
}
@@ -2360,6 +2382,16 @@ void tst_QScriptValue::call()
QCOMPARE(qIsNaN(ret.toNumber()), true);
}
}
+ {
+ QScriptValue fun = eng.evaluate("Object");
+ QVERIFY(fun.isFunction());
+ QScriptEngine eng2;
+ QScriptValue objectInDifferentEngine = eng2.newObject();
+ QScriptValueList args;
+ args << objectInDifferentEngine;
+ QTest::ignoreMessage(QtWarningMsg, "QScriptValue::call() failed: cannot call function with argument created in a different engine");
+ fun.call(QScriptValue(), args);
+ }
// test that invalid return value is handled gracefully
{
diff --git a/tests/auto/qtransform/tst_qtransform.cpp b/tests/auto/qtransform/tst_qtransform.cpp
index 3b13a41..99a449a 100644
--- a/tests/auto/qtransform/tst_qtransform.cpp
+++ b/tests/auto/qtransform/tst_qtransform.cpp
@@ -654,7 +654,7 @@ void tst_QTransform::transform()
d.rotate(30);
e.shear(0.5, 0.5);
- QCOMPARE(t, e * d * c * b * a);
+ QVERIFY(qFuzzyCompare(t, e * d * c * b * a));
}
void tst_QTransform::mapEmptyPath()
diff --git a/tests/benchmarks/qdir/qdir.pro b/tests/benchmarks/qdir/qdir.pro
new file mode 100644
index 0000000..2cdebfd
--- /dev/null
+++ b/tests/benchmarks/qdir/qdir.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qdir
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += tst_qdir.cpp
diff --git a/tests/benchmarks/qdir/tst_qdir.cpp b/tests/benchmarks/qdir/tst_qdir.cpp
new file mode 100644
index 0000000..6405645
--- /dev/null
+++ b/tests/benchmarks/qdir/tst_qdir.cpp
@@ -0,0 +1,98 @@
+#include <QtTest/QtTest>
+
+#include<dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+class Test : public QObject{
+ Q_OBJECT
+public slots:
+ void initTestCase() {
+ QDir testdir = QDir::tempPath();
+
+ const QString subfolder_name = QLatin1String("test_speed");
+ QVERIFY(testdir.mkdir(subfolder_name));
+ QVERIFY(testdir.cd(subfolder_name));
+
+ for (uint i=0; i<10000; ++i) {
+ QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i));
+ file.open(QIODevice::WriteOnly);
+ }
+ }
+ void cleanupTestCase() {
+ {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+
+ foreach (const QString &filename, testdir.entryList()) {
+ testdir.remove(filename);
+ }
+ }
+ const QDir temp = QDir(QDir::tempPath());
+ temp.rmdir(QLatin1String("test_speed"));
+ }
+private slots:
+ void sizeSpeed() {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ QBENCHMARK {
+ QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted);
+ foreach (const QFileInfo &fileInfo, fileInfoList) {
+ fileInfo.isDir();
+ fileInfo.size();
+ }
+ }
+ }
+ void sizeSpeedWithoutFilter() {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ QBENCHMARK {
+ QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted);
+ foreach (const QFileInfo &fileInfo, fileInfoList) {
+ fileInfo.size();
+ }
+ }
+ }
+ void sizeSpeedWithoutFileInfoList() {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ testdir.setSorting(QDir::Unsorted);
+ QBENCHMARK {
+ QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
+ foreach (const QString &filename, fileList) {
+ QFileInfo fileInfo(filename);
+ fileInfo.size();
+ }
+ }
+ }
+ void iDontWantAnyStat() {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ testdir.setSorting(QDir::Unsorted);
+ testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
+ QBENCHMARK {
+ QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
+ foreach (const QString &filename, fileList) {
+
+ }
+ }
+ }
+#ifndef Q_OS_WIN
+ void testLowLevel() {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ DIR *dir = opendir(qPrintable(testdir.absolutePath()));
+ QVERIFY(!chdir(qPrintable(testdir.absolutePath())));
+ QBENCHMARK {
+ struct dirent *item = readdir(dir);
+ while (item) {
+ char *fileName = item->d_name;
+
+ struct stat fileStat;
+ QVERIFY(!stat(fileName, &fileStat));
+
+ item = readdir(dir);
+ }
+ }
+ closedir(dir);
+ }
+#endif
+};
+
+QTEST_MAIN(Test)
+#include "tst_qdir.moc"