summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/files/N.tar.gzbin0 -> 115 bytes
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/files/X1
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/files/t.c1
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/files/u.txt4
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/files/y1
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/files/zbin0 -> 132 bytes
-rw-r--r--tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp77
7 files changed, 84 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/N.tar.gz b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/N.tar.gz
new file mode 100644
index 0000000000..0a710447a5
--- /dev/null
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/N.tar.gz
Binary files differ
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/X b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/X
new file mode 100644
index 0000000000..a84546e5bc
--- /dev/null
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/X
@@ -0,0 +1 @@
+#include <math.h>
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/t.c b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/t.c
new file mode 100644
index 0000000000..3774c48f13
--- /dev/null
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/t.c
@@ -0,0 +1 @@
+void x();
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/u.txt b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/u.txt
new file mode 100644
index 0000000000..8d45724eff
--- /dev/null
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/u.txt
@@ -0,0 +1,4 @@
+foo
+bar
+-
+_
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/y b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/y
new file mode 100644
index 0000000000..399593b6ce
--- /dev/null
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/y
@@ -0,0 +1 @@
+diff --git a/plugins/patchreview/kdevpatchreview.json b/plugins/patchreview/kdevpatchreview.json
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/z b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/z
new file mode 100644
index 0000000000..d1ed8a45d1
--- /dev/null
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/files/z
Binary files differ
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp
index fb2a500982..959330f256 100644
--- a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp
+++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 Igor Kushnir <igorkuo@gmail.com>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -29,6 +30,36 @@
#include <QTest>
#include <QMimeDatabase>
+namespace {
+struct MatchModeInfo
+{
+ QMimeDatabase::MatchMode mode;
+ const char *name;
+};
+
+constexpr MatchModeInfo matchModes[] = { { QMimeDatabase::MatchDefault, "Default" },
+ { QMimeDatabase::MatchExtension, "Extension" },
+ { QMimeDatabase::MatchContent, "Content" } };
+
+void addFileRows(const char *tag, const QString &fileName, const QStringList &expectedMimeNames)
+{
+ QCOMPARE(static_cast<std::size_t>(expectedMimeNames.size()), std::size(matchModes));
+ for (int i = 0; i < expectedMimeNames.size(); ++i) {
+ QTest::addRow(qPrintable(tag + QStringLiteral(" - %s")), matchModes[i].name)
+ << fileName << matchModes[i].mode << expectedMimeNames[i];
+ }
+}
+
+void addExistentFileRows(const char *tag, const QString &fileName,
+ const QStringList &expectedMimeNames)
+{
+ const QString filePath = QFINDTESTDATA("files/" + fileName);
+ QVERIFY2(!filePath.isEmpty(),
+ qPrintable(QStringLiteral("Cannot find test file %1 in files/").arg(fileName)));
+ addFileRows(tag, filePath, expectedMimeNames);
+}
+}
+
class tst_QMimeDatabase: public QObject
{
@@ -37,6 +68,8 @@ class tst_QMimeDatabase: public QObject
private slots:
void inheritsPerformance();
void benchMimeTypeForName();
+ void benchMimeTypeForFile_data();
+ void benchMimeTypeForFile();
};
void tst_QMimeDatabase::inheritsPerformance()
@@ -82,6 +115,50 @@ void tst_QMimeDatabase::benchMimeTypeForName()
}
}
+void tst_QMimeDatabase::benchMimeTypeForFile_data()
+{
+ QTest::addColumn<QString>("fileName");
+ QTest::addColumn<QMimeDatabase::MatchMode>("mode");
+ QTest::addColumn<QString>("expectedMimeName");
+
+ addFileRows("archive", "a.tar.gz",
+ { "application/x-compressed-tar",
+ "application/x-compressed-tar",
+ "application/octet-stream" });
+ addFileRows("OpenDocument Text", "b.odt",
+ { "application/vnd.oasis.opendocument.text",
+ "application/vnd.oasis.opendocument.text",
+ "application/octet-stream" });
+
+ addExistentFileRows(
+ "existent archive with extension", "N.tar.gz",
+ { "application/x-compressed-tar", "application/x-compressed-tar", "application/gzip" });
+ addExistentFileRows("existent C with extension", "t.c",
+ { "text/x-csrc", "text/x-csrc", "text/plain" });
+ addExistentFileRows("existent text file with extension", "u.txt",
+ { "text/plain", "text/plain", "text/plain" });
+ addExistentFileRows("existent C w/o extension", "X",
+ { "text/x-csrc", "application/octet-stream", "text/x-csrc" });
+ addExistentFileRows("existent patch w/o extension", "y",
+ { "text/x-patch", "application/octet-stream", "text/x-patch" });
+ addExistentFileRows("existent archive w/o extension", "z",
+ { "application/gzip", "application/octet-stream", "application/gzip" });
+}
+
+void tst_QMimeDatabase::benchMimeTypeForFile()
+{
+ QFETCH(const QString, fileName);
+ QFETCH(const QMimeDatabase::MatchMode, mode);
+ QFETCH(const QString, expectedMimeName);
+
+ QMimeDatabase db;
+
+ QBENCHMARK {
+ const auto mimeType = db.mimeTypeForFile(fileName, mode);
+ QCOMPARE(mimeType.name(), expectedMimeName);
+ }
+}
+
QTEST_MAIN(tst_QMimeDatabase)
#include "tst_bench_qmimedatabase.moc"