aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt4
-rw-r--r--test/CMakeLists.txt13
-rw-r--r--test/matcherbenchmark/matcherbenchmark.cpp51
-rw-r--r--test/matcherbenchmark/matcherbenchmark.h17
4 files changed, 81 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 622fb21..f75bba4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,11 +42,11 @@ add_subdirectory(src)
add_subdirectory(doc)
-if(CONFIG_TESTS)
+#if(CONFIG_TESTS)
enable_testing()
find_package(Qt5 COMPONENTS Test REQUIRED)
add_subdirectory(test)
-endif(CONFIG_TESTS)
+#endif(CONFIG_TESTS)
# Summarize
message(STATUS "=== Configuration summary ===")
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 6b740d7..4a802d1 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -2,6 +2,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
+# AdblockTest
add_executable(AdBlockTest
adblock/adblocktest.cpp
adblock/adblocktest.h
@@ -9,13 +10,21 @@ add_executable(AdBlockTest
target_include_directories(AdBlockTest PRIVATE ../lib/urlfilter)
target_link_libraries(AdBlockTest Qt5::Test urlfilter)
+add_test(NAME urlfilter-adblock COMMAND AdBlockTest WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
+# HostlistTest
add_executable(HostlistTest
hostlist/hostlisttest.cpp
hostlist/hostlisttest.h
)
target_include_directories(HostlistTest PRIVATE ../lib/urlfilter/)
target_link_libraries(HostlistTest Qt5::Test urlfilter)
-
-add_test(NAME urlfilter-adblock COMMAND AdBlockTest WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
add_test(NAME urlfilter-hostlist COMMAND HostlistTest WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
+
+# matching algorithm benchmark
+add_executable(MatcherBenchmark
+ matcherbenchmark/matcherbenchmark.cpp
+ matcherbenchmark/matcherbenchmark.h
+)
+target_link_libraries(MatcherBenchmark Qt5::Test)
+add_test(NAME matcher-benchmark COMMAND MatcherBenchmark WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
diff --git a/test/matcherbenchmark/matcherbenchmark.cpp b/test/matcherbenchmark/matcherbenchmark.cpp
new file mode 100644
index 0000000..cb4feb1
--- /dev/null
+++ b/test/matcherbenchmark/matcherbenchmark.cpp
@@ -0,0 +1,51 @@
+#include "matcherbenchmark.h"
+#include <QtTest/QTest>
+#include <QRegExp>
+#include <QRegularExpression>
+#include <QStringMatcher>
+
+void MatcherBenchmark::qstringcontains()
+{
+ const QString pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(request.contains(pattern), true);
+ QBENCHMARK {
+ request.contains(pattern);
+ }
+}
+
+void MatcherBenchmark::qstringmatcher()
+{
+ const QStringMatcher pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(pattern.indexIn(request) != -1, true);
+ QBENCHMARK {
+ pattern.indexIn(request);
+ }
+}
+
+void MatcherBenchmark::qregexp()
+{
+ const QRegExp pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(pattern.indexIn(request) != -1, true);
+ QBENCHMARK {
+ pattern.indexIn(request);
+ }
+}
+
+void MatcherBenchmark::qregularexpressionmatch()
+{
+ const QRegularExpression pattern("spamdomain");
+ const QString request("subdomain.spamdomain.com");
+
+ QCOMPARE(pattern.match(request).hasMatch(), true);
+ QBENCHMARK {
+ QCOMPARE(pattern.match(request).hasMatch(), true);
+ }
+}
+
+QTEST_GUILESS_MAIN(MatcherBenchmark)
diff --git a/test/matcherbenchmark/matcherbenchmark.h b/test/matcherbenchmark/matcherbenchmark.h
new file mode 100644
index 0000000..cdc77f6
--- /dev/null
+++ b/test/matcherbenchmark/matcherbenchmark.h
@@ -0,0 +1,17 @@
+#ifndef MATCHER_BENCHMARK
+#define MATCHER_BENCHMARK
+
+#include <QObject>
+
+class MatcherBenchmark : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void qstringcontains();
+ void qstringmatcher();
+ void qregexp();
+ void qregularexpressionmatch();
+};
+
+#endif