summaryrefslogtreecommitdiff
path: root/icespider/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'icespider/unittests')
-rw-r--r--icespider/unittests/testAccept.cpp28
-rw-r--r--icespider/unittests/testPerf.cpp19
2 files changed, 33 insertions, 14 deletions
diff --git a/icespider/unittests/testAccept.cpp b/icespider/unittests/testAccept.cpp
index 91935fc..eb59bb3 100644
--- a/icespider/unittests/testAccept.cpp
+++ b/icespider/unittests/testAccept.cpp
@@ -46,10 +46,10 @@ BOOST_DATA_TEST_CASE(texthtml,
a)
{
auto front = parse(a).front();
- BOOST_REQUIRE(front->group);
- BOOST_REQUIRE_EQUAL(*front->group, "text");
- BOOST_REQUIRE(front->type);
- BOOST_REQUIRE_EQUAL(*front->type, "html");
+ BOOST_REQUIRE(front.group);
+ BOOST_REQUIRE_EQUAL(*front.group, "text");
+ BOOST_REQUIRE(front.type);
+ BOOST_REQUIRE_EQUAL(*front.type, "html");
}
BOOST_DATA_TEST_CASE(textany,
@@ -62,9 +62,9 @@ BOOST_DATA_TEST_CASE(textany,
a)
{
auto front = parse(a).front();
- BOOST_REQUIRE(front->group);
- BOOST_REQUIRE_EQUAL(*front->group, "text");
- BOOST_REQUIRE(!front->type);
+ BOOST_REQUIRE(front.group);
+ BOOST_REQUIRE_EQUAL(*front.group, "text");
+ BOOST_REQUIRE(!front.type);
}
BOOST_DATA_TEST_CASE(anyhtml,
@@ -78,9 +78,9 @@ BOOST_DATA_TEST_CASE(anyhtml,
a)
{
auto front = parse(a).front();
- BOOST_REQUIRE(front->group);
- BOOST_REQUIRE(front->type);
- BOOST_REQUIRE_EQUAL(*front->type, "html");
+ BOOST_REQUIRE(front.group);
+ BOOST_REQUIRE(front.type);
+ BOOST_REQUIRE_EQUAL(*front.type, "html");
}
BOOST_DATA_TEST_CASE(anyany,
@@ -93,8 +93,8 @@ BOOST_DATA_TEST_CASE(anyany,
a)
{
auto front = parse(a).front();
- BOOST_REQUIRE(!front->group);
- BOOST_REQUIRE(!front->type);
+ BOOST_REQUIRE(!front.group);
+ BOOST_REQUIRE(!front.type);
}
BOOST_DATA_TEST_CASE(q1,
@@ -107,8 +107,8 @@ BOOST_DATA_TEST_CASE(q1,
{
auto all = parse(a);
for (const auto & accept : all) {
- BOOST_TEST_CONTEXT(*accept) {
- BOOST_CHECK_CLOSE(accept->q, 1.0, 0.1);
+ BOOST_TEST_CONTEXT(accept) {
+ BOOST_CHECK_CLOSE(accept.q, 1.0, 0.1);
}
}
}
diff --git a/icespider/unittests/testPerf.cpp b/icespider/unittests/testPerf.cpp
index 1958525..5b82213 100644
--- a/icespider/unittests/testPerf.cpp
+++ b/icespider/unittests/testPerf.cpp
@@ -4,6 +4,8 @@
#include <definedDirs.h>
#include <fstream>
+#define BENCHMARK_CAPTURE_LITERAL(Name, Value) BENCHMARK_CAPTURE(Name, Value, Value);
+
class TestRequest : public IceSpider::CgiRequestBase {
public:
TestRequest(IceSpider::Core * c, char ** env) : IceSpider::CgiRequestBase(c, env)
@@ -109,4 +111,21 @@ BENCHMARK_F(CoreFixture, get_cookie_param)(benchmark::State & state)
}
}
+static void
+AcceptParse(benchmark::State & state, const std::string_view accept)
+{
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(IceSpider::IHttpRequest::parseAccept(accept));
+ }
+}
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "*/*");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "any/html");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "image/png, */*");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "image/png;q=0.1, */*");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "image/png;q=0.1, any/html");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "image/png;q=0.9, any/html;q=1.0, something/else;q=1.0");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "image/png;q=0.9, */*;q=1.0");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "text/*");
+BENCHMARK_CAPTURE_LITERAL(AcceptParse, "text/html");
+
BENCHMARK_MAIN();