diff options
Diffstat (limited to 'icespider/unittests')
-rw-r--r-- | icespider/unittests/base2.cpp | 5 | ||||
-rw-r--r-- | icespider/unittests/base2.h | 9 | ||||
-rw-r--r-- | icespider/unittests/string_view_support.h | 25 | ||||
-rw-r--r-- | icespider/unittests/test-api-impl.cpp | 1 | ||||
-rw-r--r-- | icespider/unittests/testAccept.cpp | 111 | ||||
-rw-r--r-- | icespider/unittests/testApp.cpp | 300 | ||||
-rw-r--r-- | icespider/unittests/testCompile.cpp | 29 | ||||
-rw-r--r-- | icespider/unittests/testFcgi.cpp | 331 | ||||
-rw-r--r-- | icespider/unittests/testFileSessions.cpp | 43 |
9 files changed, 429 insertions, 425 deletions
diff --git a/icespider/unittests/base2.cpp b/icespider/unittests/base2.cpp index 4f6d8ef..a64d46b 100644 --- a/icespider/unittests/base2.cpp +++ b/icespider/unittests/base2.cpp @@ -1,13 +1,10 @@ #include "base2.h" namespace common { - base2::base2(const IceSpider::Core *) - { - } + base2::base2(const IceSpider::Core *) { } void base2::testMutate(const IceSpider::IHttpRequest *, ::TestIceSpider::SomeModelPtr &) const { } } - diff --git a/icespider/unittests/base2.h b/icespider/unittests/base2.h index d89cf85..d0ad75c 100644 --- a/icespider/unittests/base2.h +++ b/icespider/unittests/base2.h @@ -2,8 +2,8 @@ #define ICESPIDER_TEST_BASE2_H // Standard headers. -#include <irouteHandler.h> #include <core.h> +#include <irouteHandler.h> // Interface headers. #include <test-api.h> @@ -12,12 +12,11 @@ namespace common { // Base classes. class DLL_PUBLIC base2 { - protected: - base2(const IceSpider::Core * core); + protected: + explicit base2(const IceSpider::Core * core); - void testMutate(const IceSpider::IHttpRequest *, TestIceSpider::SomeModelPtr &) const; + void testMutate(const IceSpider::IHttpRequest *, TestIceSpider::SomeModelPtr &) const; }; // base2 } // namespace common #endif - diff --git a/icespider/unittests/string_view_support.h b/icespider/unittests/string_view_support.h index ef9fb94..12d8077 100644 --- a/icespider/unittests/string_view_support.h +++ b/icespider/unittests/string_view_support.h @@ -1,32 +1,30 @@ #ifndef ICETRAY_STRING_VIEW_SUPPORT_H #define ICETRAY_STRING_VIEW_SUPPORT_H -#include <string_view> #include <Ice/OutputStream.h> #include <Ice/StreamHelpers.h> +#include <string_view> -namespace Ice -{ - template<> - struct StreamableTraits<std::string_view> - { +namespace Ice { + template<> struct StreamableTraits<std::string_view> { static const StreamHelperCategory helper = StreamHelperCategoryBuiltin; static const int minWireSize = 1; static const bool fixedLength = false; }; - template<> - struct StreamHelper<std::string_view, StreamHelperCategoryBuiltin> { - template<class S> static inline void - write(S * stream, const std::string_view& v) + template<> struct StreamHelper<std::string_view, StreamHelperCategoryBuiltin> { + template<class S> + static inline void + write(S * stream, const std::string_view & v) { stream->write(v.data(), v.size()); } - template<class S> static inline void - read(S * stream, std::string_view& v) + template<class S> + static inline void + read(S * stream, std::string_view & v) { - const char* vdata = 0; + const char * vdata = nullptr; size_t vsize = 0; stream->read(vdata, vsize); @@ -42,4 +40,3 @@ namespace Ice } #endif - diff --git a/icespider/unittests/test-api-impl.cpp b/icespider/unittests/test-api-impl.cpp index 7d5b556..bcf32ed 100644 --- a/icespider/unittests/test-api-impl.cpp +++ b/icespider/unittests/test-api-impl.cpp @@ -5,4 +5,3 @@ TestIceSpider::Ex::ice_print(std::ostream & s) const { s << message; } - diff --git a/icespider/unittests/testAccept.cpp b/icespider/unittests/testAccept.cpp index 2cabe5e..cc08f0a 100644 --- a/icespider/unittests/testAccept.cpp +++ b/icespider/unittests/testAccept.cpp @@ -1,46 +1,48 @@ #define BOOST_TEST_MODULE TestAccept -#include <boost/test/included/unit_test.hpp> #include <boost/test/data/test_case.hpp> +#include <boost/test/included/unit_test.hpp> -#include <ihttpRequest.h> #include <exceptions.h> +#include <ihttpRequest.h> auto parse = IceSpider::IHttpRequest::parseAccept; using namespace boost::unit_test::data; namespace std { - ostream & operator<<(ostream & s, const IceSpider::Accept & a) + ostream & + operator<<(ostream & s, const IceSpider::Accept & a) { - s << (a.group ? *a.group : "*") - << "/" - << (a.type ? *a.type : "*") - << ";q=" << a.q; + s << (a.group ? *a.group : "*") << "/" << (a.type ? *a.type : "*") << ";q=" << a.q; return s; } } -BOOST_TEST_DECORATOR(* boost::unit_test::timeout(1)) -BOOST_DATA_TEST_CASE(bad_requests, make({ - "", // Can't specify nothing - " ", // This is still nothing - " group ", - " ; ", - " / ", - " ^ ", - " * / plain ", - " text / plain ; q = 0.0 ", - " text / plain ; q = 1.1 ", -}), a) +BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1)) +BOOST_DATA_TEST_CASE(bad_requests, + make({ + "", // Can't specify nothing + " ", // This is still nothing + " group ", + " ; ", + " / ", + " ^ ", + " * / plain ", + " text / plain ; q = 0.0 ", + " text / plain ; q = 1.1 ", + }), + a) { BOOST_CHECK_THROW(parse(a), IceSpider::Http400_BadRequest); } -BOOST_DATA_TEST_CASE(texthtml, make({ - "text/html", - "image/png;q=0.1, text/html", - "image/png;q=0.9, text/html;q=1.0", - "image/png;q=0.9, text/html;q=1.0, something/else;q=1.0", -}), a) +BOOST_DATA_TEST_CASE(texthtml, + make({ + "text/html", + "image/png;q=0.1, text/html", + "image/png;q=0.9, text/html;q=1.0", + "image/png;q=0.9, text/html;q=1.0, something/else;q=1.0", + }), + a) { auto front = parse(a).front(); BOOST_REQUIRE(front->group); @@ -49,12 +51,14 @@ BOOST_DATA_TEST_CASE(texthtml, make({ BOOST_REQUIRE_EQUAL(*front->type, "html"); } -BOOST_DATA_TEST_CASE(textany, make({ - "text/*", - "image/png;q=0.1, text/*", - "image/png;q=0.9, text/*;q=1.0", - "image/png;q=0.9, text/*;q=1.0, something/else;q=1.0", -}), a) +BOOST_DATA_TEST_CASE(textany, + make({ + "text/*", + "image/png;q=0.1, text/*", + "image/png;q=0.9, text/*;q=1.0", + "image/png;q=0.9, text/*;q=1.0, something/else;q=1.0", + }), + a) { auto front = parse(a).front(); BOOST_REQUIRE(front->group); @@ -62,13 +66,15 @@ BOOST_DATA_TEST_CASE(textany, make({ BOOST_REQUIRE(!front->type); } -BOOST_DATA_TEST_CASE(anyhtml, make({ - "any/html", - "image/png;q=0.1, any/html", - "image/png;q=0.9, any/html;q=1.0", - "image/png;q=0.9, any/html;q=1.0, something/else;q=1.0", - " image / png ; q = 0.9 , any / html ; q = 1.0 , something / else ; q = 1.0", -}), a) +BOOST_DATA_TEST_CASE(anyhtml, + make({ + "any/html", + "image/png;q=0.1, any/html", + "image/png;q=0.9, any/html;q=1.0", + "image/png;q=0.9, any/html;q=1.0, something/else;q=1.0", + " image / png ; q = 0.9 , any / html ; q = 1.0 , something / else ; q = 1.0", + }), + a) { auto front = parse(a).front(); BOOST_REQUIRE(front->group); @@ -76,29 +82,32 @@ BOOST_DATA_TEST_CASE(anyhtml, make({ BOOST_REQUIRE_EQUAL(*front->type, "html"); } -BOOST_DATA_TEST_CASE(anyany, make({ - "*/*", - "image/png;q=0.1, */*", - "image/png;q=0.9, */*;q=1.0", - "image/png;q=0.9, */*;q=1.0, something/else;q=1.0", -}), a) +BOOST_DATA_TEST_CASE(anyany, + make({ + "*/*", + "image/png;q=0.1, */*", + "image/png;q=0.9, */*;q=1.0", + "image/png;q=0.9, */*;q=1.0, something/else;q=1.0", + }), + a) { auto front = parse(a).front(); BOOST_REQUIRE(!front->group); BOOST_REQUIRE(!front->type); } -BOOST_DATA_TEST_CASE(q1, make({ - "*/*", - "image/png, */*", - "image/png;q=1.0, */*", -}), a) +BOOST_DATA_TEST_CASE(q1, + make({ + "*/*", + "image/png, */*", + "image/png;q=1.0, */*", + }), + a) { auto all = parse(a); - for(const auto & accept : all) { + for (const auto & accept : all) { BOOST_TEST_CONTEXT(*accept) { BOOST_CHECK_CLOSE(accept->q, 1.0, 0.1); } } } - diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index cabcd0c..46fda40 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -1,88 +1,75 @@ #define BOOST_TEST_MODULE TestApp #include <boost/test/unit_test.hpp> -#include <safeMapFind.h> -#include <irouteHandler.h> -#include <core.h> -#include <exceptions.h> -#include <test-api.h> -#include <Ice/ObjectAdapter.h> #include <Ice/Initialize.h> -#include <boost/algorithm/string/split.hpp> +#include <Ice/ObjectAdapter.h> #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/predicate.hpp> -#include <filesystem> +#include <boost/algorithm/string/split.hpp> +#include <core.h> #include <definedDirs.h> -#include <slicer/slicer.h> -#include <xml/serializer.h> +#include <exceptions.h> +#include <factory.impl.h> +#include <filesystem> +#include <irouteHandler.h> #include <json/serializer.h> #include <libxml++/parsers/domparser.h> -#include <factory.impl.h> +#include <safeMapFind.h> +#include <slicer/slicer.h> +#include <test-api.h> #include <testRequest.h> +#include <xml/serializer.h> using namespace IceSpider; static void forceEarlyChangeDir() __attribute__((constructor(101))); -void forceEarlyChangeDir() +void +forceEarlyChangeDir() { std::filesystem::current_path(XSTR(ROOT)); } -BOOST_AUTO_TEST_CASE( testLoadConfiguration ) +BOOST_AUTO_TEST_CASE(testLoadConfiguration) { BOOST_REQUIRE_EQUAL(13, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); } class CoreWithProps : public CoreWithDefaultRouter { - public: - CoreWithProps() : - CoreWithDefaultRouter({ - "--Custom.Prop=value" - }) - { - } +public: + CoreWithProps() : CoreWithDefaultRouter({"--Custom.Prop=value"}) { } }; BOOST_FIXTURE_TEST_SUITE(props, CoreWithProps); -BOOST_AUTO_TEST_CASE( properties ) +BOOST_AUTO_TEST_CASE(properties) { - BOOST_REQUIRE_EQUAL("Test", - this->communicator->getProperties()->getProperty("TestIceSpider.TestApi")); - BOOST_REQUIRE_EQUAL("value", - this->communicator->getProperties()->getProperty("Custom.Prop")); + BOOST_REQUIRE_EQUAL("Test", this->communicator->getProperties()->getProperty("TestIceSpider.TestApi")); + BOOST_REQUIRE_EQUAL("value", this->communicator->getProperties()->getProperty("Custom.Prop")); } BOOST_AUTO_TEST_SUITE_END(); class CoreWithFileProps : public CoreWithDefaultRouter { - public: - CoreWithFileProps() : - CoreWithDefaultRouter({ - "--IceSpider.Config=config/custom.properties", - "--Custom.Prop=value" - }) - { - } +public: + CoreWithFileProps() : CoreWithDefaultRouter({"--IceSpider.Config=config/custom.properties", "--Custom.Prop=value"}) + { + } }; BOOST_FIXTURE_TEST_SUITE(fileProps, CoreWithFileProps); -BOOST_AUTO_TEST_CASE( properties ) +BOOST_AUTO_TEST_CASE(properties) { - BOOST_REQUIRE_EQUAL("", - this->communicator->getProperties()->getProperty("TestIceSpider.TestApi")); - BOOST_REQUIRE_EQUAL("something", - this->communicator->getProperties()->getProperty("InFile")); - BOOST_REQUIRE_EQUAL("value", - this->communicator->getProperties()->getProperty("Custom.Prop")); + BOOST_REQUIRE_EQUAL("", this->communicator->getProperties()->getProperty("TestIceSpider.TestApi")); + BOOST_REQUIRE_EQUAL("something", this->communicator->getProperties()->getProperty("InFile")); + BOOST_REQUIRE_EQUAL("value", this->communicator->getProperties()->getProperty("Custom.Prop")); } BOOST_AUTO_TEST_SUITE_END(); BOOST_FIXTURE_TEST_SUITE(defaultProps, CoreWithDefaultRouter); -BOOST_AUTO_TEST_CASE( testCoreSettings ) +BOOST_AUTO_TEST_CASE(testCoreSettings) { BOOST_REQUIRE_EQUAL(5, routes.size()); BOOST_REQUIRE_EQUAL(1, routes[0].size()); @@ -92,7 +79,7 @@ BOOST_AUTO_TEST_CASE( testCoreSettings ) BOOST_REQUIRE_EQUAL(2, routes[4].size()); } -BOOST_AUTO_TEST_CASE( testFindRoutes ) +BOOST_AUTO_TEST_CASE(testFindRoutes) { TestRequest requestGetIndex(this, HttpMethod::GET, "/"); BOOST_REQUIRE(findRoute(&requestGetIndex)); @@ -115,7 +102,8 @@ BOOST_AUTO_TEST_CASE( testFindRoutes ) TestRequest requestGetItemDefault(this, HttpMethod::GET, "/item/something"); BOOST_REQUIRE(findRoute(&requestGetItemDefault)); - TestRequest requestGetItemLong(this, HttpMethod::GET, "/view/something/something/extra/many/things/longer/than/longest/route"); + TestRequest requestGetItemLong( + this, HttpMethod::GET, "/view/something/something/extra/many/things/longer/than/longest/route"); BOOST_REQUIRE_THROW(findRoute(&requestGetItemLong), IceSpider::Http404_NotFound); TestRequest requestGetItemShort(this, HttpMethod::GET, "/view/missingSomething"); @@ -137,96 +125,102 @@ BOOST_AUTO_TEST_CASE( testFindRoutes ) BOOST_AUTO_TEST_SUITE_END(); class TestSerice : public TestIceSpider::TestApi { - public: - TestIceSpider::SomeModelPtr index(const Ice::Current &) override - { - return std::make_shared<TestIceSpider::SomeModel>("index"); +public: + TestIceSpider::SomeModelPtr + index(const Ice::Current &) override + { + return std::make_shared<TestIceSpider::SomeModel>("index"); + } + + TestIceSpider::SomeModelPtr + withParams(const std::string s, Ice::Int i, const Ice::Current &) override + { + BOOST_REQUIRE_EQUAL(s, "something"); + BOOST_REQUIRE_EQUAL(i, 1234); + return std::make_shared<TestIceSpider::SomeModel>("withParams"); + } + + void + returnNothing(const std::string_view s, const Ice::Current &) override + { + if (s == "error") { + throw TestIceSpider::Ex("test error"); } - - TestIceSpider::SomeModelPtr withParams(const std::string s, Ice::Int i, const Ice::Current &) override - { - BOOST_REQUIRE_EQUAL(s, "something"); - BOOST_REQUIRE_EQUAL(i, 1234); - return std::make_shared<TestIceSpider::SomeModel>("withParams"); - } - - void returnNothing(const std::string_view s, const Ice::Current &) override - { - if (s == "error") { - throw TestIceSpider::Ex("test error"); - } - else if (s.length() == 3) { - throw TestIceSpider::Ex(std::string(s)); - } - BOOST_REQUIRE_EQUAL(s, "some value"); - } - - void complexParam(const Ice::optional<std::string> s, const TestIceSpider::SomeModelPtr m, const Ice::Current &) override - { - BOOST_REQUIRE(s); - BOOST_REQUIRE_EQUAL("1234", *s); - BOOST_REQUIRE(m); - BOOST_REQUIRE_EQUAL("some value", m->value); - } - - Ice::Int simple(const Ice::Current &) override - { - return 1; - } - - std::string simplei(Ice::Int n, const Ice::Current &) override - { - return std::to_string(n); + else if (s.length() == 3) { + throw TestIceSpider::Ex(std::string(s)); } + BOOST_REQUIRE_EQUAL(s, "some value"); + } + + void + complexParam(const Ice::optional<std::string> s, const TestIceSpider::SomeModelPtr m, const Ice::Current &) override + { + BOOST_REQUIRE(s); + BOOST_REQUIRE_EQUAL("1234", *s); + BOOST_REQUIRE(m); + BOOST_REQUIRE_EQUAL("some value", m->value); + } + + Ice::Int + simple(const Ice::Current &) override + { + return 1; + } + + std::string + simplei(Ice::Int n, const Ice::Current &) override + { + return std::to_string(n); + } }; // NOLINTNEXTLINE(hicpp-special-member-functions) class TestApp : public CoreWithDefaultRouter { - public: - TestApp() : - adp(communicator->createObjectAdapterWithEndpoints("test", "default")) - { - adp->activate(); - adp->add(std::make_shared<TestSerice>(), Ice::stringToIdentity("Test")); - } - - ~TestApp() override - { - adp->deactivate(); - adp->destroy(); - } - - private: - Ice::ObjectAdapterPtr adp; +public: + TestApp() : adp(communicator->createObjectAdapterWithEndpoints("test", "default")) + { + adp->activate(); + adp->add(std::make_shared<TestSerice>(), Ice::stringToIdentity("Test")); + } + + ~TestApp() override + { + adp->deactivate(); + adp->destroy(); + } + +private: + Ice::ObjectAdapterPtr adp; }; class Dummy : public IceSpider::Plugin, TestIceSpider::DummyPlugin { - public: - Dummy(const Ice::CommunicatorPtr &, const Ice::PropertiesPtr &) { } +public: + Dummy(const Ice::CommunicatorPtr &, const Ice::PropertiesPtr &) { } }; NAMEDFACTORY("DummyPlugin", Dummy, IceSpider::PluginFactory); BOOST_FIXTURE_TEST_SUITE(ta, TestApp); -BOOST_AUTO_TEST_CASE( plugins ) +BOOST_AUTO_TEST_CASE(plugins) { auto prx = this->getProxy<TestIceSpider::DummyPlugin>(); BOOST_REQUIRE(prx); prx->ice_ping(); } -BOOST_AUTO_TEST_CASE( testCallIndex ) +BOOST_AUTO_TEST_CASE(testCallIndex) { TestRequest requestGetIndex(this, HttpMethod::GET, "/"); process(&requestGetIndex); auto h = requestGetIndex.getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/json"); - auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>(requestGetIndex.output); + auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>( + requestGetIndex.output); BOOST_REQUIRE_EQUAL(v->value, "index"); } -BOOST_AUTO_TEST_CASE( testCallMashS ) +BOOST_AUTO_TEST_CASE(testCallMashS) { TestRequest requestGetMashS(this, HttpMethod::GET, "/mashS/something/something/1234"); process(&requestGetMashS); @@ -238,7 +232,7 @@ BOOST_AUTO_TEST_CASE( testCallMashS ) BOOST_REQUIRE_EQUAL(v.b->value, "withParams"); } -BOOST_AUTO_TEST_CASE( testCallMashC ) +BOOST_AUTO_TEST_CASE(testCallMashC) { TestRequest requestGetMashC(this, HttpMethod::GET, "/mashC/something/something/1234"); process(&requestGetMashC); @@ -250,7 +244,7 @@ BOOST_AUTO_TEST_CASE( testCallMashC ) BOOST_REQUIRE_EQUAL(v->b->value, "withParams"); } -BOOST_AUTO_TEST_CASE( testCallViewSomething1234 ) +BOOST_AUTO_TEST_CASE(testCallViewSomething1234) { TestRequest requestGetItem(this, HttpMethod::GET, "/view/something/1234"); process(&requestGetItem); @@ -261,29 +255,31 @@ BOOST_AUTO_TEST_CASE( testCallViewSomething1234 ) BOOST_REQUIRE_EQUAL(v->value, "withParams"); } -BOOST_AUTO_TEST_CASE( testCallViewSomething1234_ ) +BOOST_AUTO_TEST_CASE(testCallViewSomething1234_) { TestRequest requestGetItemGiven(this, HttpMethod::GET, "/item/something/1234"); process(&requestGetItemGiven); auto h = requestGetItemGiven.getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/json"); - auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>(requestGetItemGiven.output); + auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>( + requestGetItemGiven.output); BOOST_REQUIRE_EQUAL(v->value, "withParams"); } -BOOST_AUTO_TEST_CASE( testCallViewSomething ) +BOOST_AUTO_TEST_CASE(testCallViewSomething) { TestRequest requestGetItemDefault(this, HttpMethod::GET, "/item/something"); process(&requestGetItemDefault); auto h = requestGetItemDefault.getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/json"); - auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>(requestGetItemDefault.output); + auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>( + requestGetItemDefault.output); BOOST_REQUIRE_EQUAL(v->value, "withParams"); } -BOOST_AUTO_TEST_CASE( testCallDeleteSomeValue ) +BOOST_AUTO_TEST_CASE(testCallDeleteSomeValue) { TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/some value"); process(&requestDeleteItem); @@ -293,7 +289,7 @@ BOOST_AUTO_TEST_CASE( testCallDeleteSomeValue ) BOOST_REQUIRE(requestDeleteItem.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallPost1234 ) +BOOST_AUTO_TEST_CASE(testCallPost1234) { TestRequest requestUpdateItem(this, HttpMethod::POST, "/1234"); requestUpdateItem.env["CONTENT_TYPE"] = "application/json"; @@ -305,7 +301,7 @@ BOOST_AUTO_TEST_CASE( testCallPost1234 ) BOOST_REQUIRE(requestUpdateItem.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallPost1234NoContentType ) +BOOST_AUTO_TEST_CASE(testCallPost1234NoContentType) { TestRequest requestUpdateItem(this, HttpMethod::POST, "/1234"); requestUpdateItem.input << R"({"value": "some value"})"; @@ -316,7 +312,7 @@ BOOST_AUTO_TEST_CASE( testCallPost1234NoContentType ) BOOST_REQUIRE(requestUpdateItem.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallPost1234UnsupportedMediaType ) +BOOST_AUTO_TEST_CASE(testCallPost1234UnsupportedMediaType) { TestRequest requestUpdateItem(this, HttpMethod::POST, "/1234"); requestUpdateItem.env["CONTENT_TYPE"] = "application/notathing"; @@ -328,7 +324,7 @@ BOOST_AUTO_TEST_CASE( testCallPost1234UnsupportedMediaType ) BOOST_REQUIRE(requestUpdateItem.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallIndexAcceptJson ) +BOOST_AUTO_TEST_CASE(testCallIndexAcceptJson) { TestRequest requestJson(this, HttpMethod::GET, "/"); requestJson.hdr["Accept"] = "application/json"; @@ -340,7 +336,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexAcceptJson ) BOOST_REQUIRE_EQUAL(v->value, "index"); } -BOOST_AUTO_TEST_CASE( testCallIndexAcceptAny ) +BOOST_AUTO_TEST_CASE(testCallIndexAcceptAny) { TestRequest requestAnyAny(this, HttpMethod::GET, "/"); requestAnyAny.hdr["Accept"] = "*/*"; @@ -351,7 +347,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexAcceptAny ) BOOST_REQUIRE_EQUAL(v->value, "index"); } -BOOST_AUTO_TEST_CASE( testCallIndexAcceptApplicationAny ) +BOOST_AUTO_TEST_CASE(testCallIndexAcceptApplicationAny) { TestRequest requestApplicationAny(this, HttpMethod::GET, "/"); requestApplicationAny.hdr["Accept"] = "application/*"; @@ -359,11 +355,12 @@ BOOST_AUTO_TEST_CASE( testCallIndexAcceptApplicationAny ) auto h = requestApplicationAny.getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE(boost::algorithm::starts_with(h["Content-Type"], "application/")); - auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>(requestApplicationAny.output); + auto v = Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>( + requestApplicationAny.output); BOOST_REQUIRE_EQUAL(v->value, "index"); } -BOOST_AUTO_TEST_CASE( testCallIndexAcceptXml ) +BOOST_AUTO_TEST_CASE(testCallIndexAcceptXml) { TestRequest requestXml(this, HttpMethod::GET, "/"); requestXml.hdr["Accept"] = "application/xml"; @@ -375,7 +372,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexAcceptXml ) BOOST_REQUIRE_EQUAL(v->value, "index"); } -BOOST_AUTO_TEST_CASE( testCallIndexAcceptTextHtml ) +BOOST_AUTO_TEST_CASE(testCallIndexAcceptTextHtml) { TestRequest requestHtml(this, HttpMethod::GET, "/"); requestHtml.hdr["Accept"] = "text/html"; @@ -388,7 +385,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexAcceptTextHtml ) BOOST_REQUIRE_EQUAL(d.get_document()->get_root_node()->get_name(), "html"); } -BOOST_AUTO_TEST_CASE( testCallViewSomethingAcceptHtml ) +BOOST_AUTO_TEST_CASE(testCallViewSomethingAcceptHtml) { TestRequest requestHtml(this, HttpMethod::GET, "/view/something/1234"); requestHtml.hdr["Accept"] = "text/html"; @@ -399,7 +396,7 @@ BOOST_AUTO_TEST_CASE( testCallViewSomethingAcceptHtml ) BOOST_REQUIRE(requestHtml.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallIndexAcceptNotSupported ) +BOOST_AUTO_TEST_CASE(testCallIndexAcceptNotSupported) { TestRequest requestBadAccept(this, HttpMethod::GET, "/"); requestBadAccept.hdr["Accept"] = "not/supported"; @@ -410,7 +407,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexAcceptNotSupported ) BOOST_REQUIRE(requestBadAccept.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallIndexComplexAccept ) +BOOST_AUTO_TEST_CASE(testCallIndexComplexAccept) { TestRequest requestChoice(this, HttpMethod::GET, "/"); requestChoice.hdr["Accept"] = "something/special ; q = 0.9, application/json ; q = 0.8, application/xml;q=1.0"; @@ -422,7 +419,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexComplexAccept ) BOOST_REQUIRE_EQUAL(v->value, "index"); } -BOOST_AUTO_TEST_CASE( testCall404 ) +BOOST_AUTO_TEST_CASE(testCall404) { TestRequest requestGetIndex(this, HttpMethod::GET, "/this/404"); process(&requestGetIndex); @@ -432,7 +429,7 @@ BOOST_AUTO_TEST_CASE( testCall404 ) BOOST_REQUIRE(requestGetIndex.output.eof()); } -BOOST_AUTO_TEST_CASE( testCall405 ) +BOOST_AUTO_TEST_CASE(testCall405) { TestRequest requestGetIndex(this, HttpMethod::GET, "/405"); process(&requestGetIndex); @@ -442,7 +439,7 @@ BOOST_AUTO_TEST_CASE( testCall405 ) BOOST_REQUIRE(requestGetIndex.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallSearch ) +BOOST_AUTO_TEST_CASE(testCallSearch) { TestRequest request(this, HttpMethod::GET, "/search"); request.qs["s"] = "something"; @@ -453,7 +450,7 @@ BOOST_AUTO_TEST_CASE( testCallSearch ) Slicer::DeserializeAny<Slicer::JsonStreamDeserializer, TestIceSpider::SomeModelPtr>(request.output); } -BOOST_AUTO_TEST_CASE( testCallSearchBadLexicalCast ) +BOOST_AUTO_TEST_CASE(testCallSearchBadLexicalCast) { TestRequest request(this, HttpMethod::GET, "/search"); request.qs["s"] = "something"; @@ -465,7 +462,7 @@ BOOST_AUTO_TEST_CASE( testCallSearchBadLexicalCast ) BOOST_REQUIRE(request.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallSearchMissingS ) +BOOST_AUTO_TEST_CASE(testCallSearchMissingS) { TestRequest request(this, HttpMethod::GET, "/search"); request.qs["i"] = "1234"; @@ -476,7 +473,7 @@ BOOST_AUTO_TEST_CASE( testCallSearchMissingS ) BOOST_REQUIRE(request.output.eof()); } -BOOST_AUTO_TEST_CASE( testCallSearchMissingI ) +BOOST_AUTO_TEST_CASE(testCallSearchMissingI) { TestRequest request(this, HttpMethod::GET, "/search"); request.qs["s"] = "something"; @@ -487,7 +484,7 @@ BOOST_AUTO_TEST_CASE( testCallSearchMissingI ) BOOST_REQUIRE(request.output.eof()); } -BOOST_AUTO_TEST_CASE( testCookies ) +BOOST_AUTO_TEST_CASE(testCookies) { TestRequest request(this, HttpMethod::GET, "/cookies"); request.cookies["mycookievar"] = "something"; @@ -498,30 +495,30 @@ BOOST_AUTO_TEST_CASE( testCookies ) } class DummyErrorHandler : public IceSpider::ErrorHandler { - public: - IceSpider::ErrorHandlerResult - handleError(IceSpider::IHttpRequest * request, const std::exception & ex) const override - { - if (const auto * tex = dynamic_cast<const TestIceSpider::Ex *>(&ex)) { - if (tex->message == "404") { - throw IceSpider::Http404_NotFound(); - } - if (tex->message == "304") { - request->getRequestPath().front() = "some value"; - return IceSpider::ErrorHandlerResult_Modified; - } - if (tex->message == "400") { - request->response(400, "Handled"); - return IceSpider::ErrorHandlerResult_Handled; - } +public: + IceSpider::ErrorHandlerResult + handleError(IceSpider::IHttpRequest * request, const std::exception & ex) const override + { + if (const auto * tex = dynamic_cast<const TestIceSpider::Ex *>(&ex)) { + if (tex->message == "404") { + throw IceSpider::Http404_NotFound(); + } + if (tex->message == "304") { + request->getRequestPath().front() = "some value"; + return IceSpider::ErrorHandlerResult_Modified; + } + if (tex->message == "400") { + request->response(400, "Handled"); + return IceSpider::ErrorHandlerResult_Handled; } - return IceSpider::ErrorHandlerResult_Unhandled; } + return IceSpider::ErrorHandlerResult_Unhandled; + } }; PLUGIN(DummyErrorHandler, IceSpider::ErrorHandler); -BOOST_AUTO_TEST_CASE( testErrorHandler_Unhandled ) +BOOST_AUTO_TEST_CASE(testErrorHandler_Unhandled) { TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/error"); process(&requestDeleteItem); @@ -533,7 +530,7 @@ BOOST_AUTO_TEST_CASE( testErrorHandler_Unhandled ) BOOST_REQUIRE_EQUAL(b, "Exception type: TestIceSpider::Ex\nDetail: test error\n"); } -BOOST_AUTO_TEST_CASE( testErrorHandler_Handled1 ) +BOOST_AUTO_TEST_CASE(testErrorHandler_Handled1) { TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/404"); process(&requestDeleteItem); @@ -543,7 +540,7 @@ BOOST_AUTO_TEST_CASE( testErrorHandler_Handled1 ) BOOST_REQUIRE(requestDeleteItem.output.eof()); } -BOOST_AUTO_TEST_CASE( testErrorHandler_Handled2 ) +BOOST_AUTO_TEST_CASE(testErrorHandler_Handled2) { TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/400"); process(&requestDeleteItem); @@ -553,7 +550,7 @@ BOOST_AUTO_TEST_CASE( testErrorHandler_Handled2 ) BOOST_REQUIRE(requestDeleteItem.output.eof()); } -BOOST_AUTO_TEST_CASE( testErrorHandler_Handled3 ) +BOOST_AUTO_TEST_CASE(testErrorHandler_Handled3) { TestRequest requestDeleteItem(this, HttpMethod::DELETE, "/304"); process(&requestDeleteItem); @@ -564,4 +561,3 @@ BOOST_AUTO_TEST_CASE( testErrorHandler_Handled3 ) } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp index 0135303..811de52 100644 --- a/icespider/unittests/testCompile.cpp +++ b/icespider/unittests/testCompile.cpp @@ -1,34 +1,34 @@ #define BOOST_TEST_MODULE TestCompile #include <boost/test/unit_test.hpp> -#include <definedDirs.h> -#include <plugins.h> -#include <dlfcn.h> #include "../compile/routeCompiler.h" #include "../core/irouteHandler.h" #include <boost/algorithm/string/join.hpp> +#include <definedDirs.h> +#include <dlfcn.h> +#include <plugins.h> #include <slicer/modelPartsTypes.h> using namespace IceSpider; static void forceEarlyChangeDir() __attribute__((constructor(101))); -void forceEarlyChangeDir() +void +forceEarlyChangeDir() { std::filesystem::current_path(XSTR(ROOT)); } class CoreFixture { - protected: - CoreFixture() : - modeDir(binDir.lexically_relative(rootDir / "bin" / "testCompile.test")) - { - } - // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) - const std::filesystem::path modeDir; +protected: + CoreFixture() : modeDir(binDir.lexically_relative(rootDir / "bin" / "testCompile.test")) { } + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + const std::filesystem::path modeDir; }; namespace std { - ostream & operator<<(ostream & s, const IceSpider::HttpMethod & m) { + ostream & + operator<<(ostream & s, const IceSpider::HttpMethod & m) + { s << Slicer::ModelPartForEnum<IceSpider::HttpMethod>::lookup(m); return s; } @@ -36,7 +36,7 @@ namespace std { BOOST_FIXTURE_TEST_SUITE(cf, CoreFixture) -BOOST_AUTO_TEST_CASE( testLoadConfiguration ) +BOOST_AUTO_TEST_CASE(testLoadConfiguration) { Compile::RouteCompiler rc; rc.searchPath.push_back(rootDir); @@ -71,7 +71,7 @@ BOOST_AUTO_TEST_CASE( testLoadConfiguration ) BOOST_REQUIRE_EQUAL("test-api.ice", cfg->slices[0]); } -BOOST_AUTO_TEST_CASE( testRouteCompile ) +BOOST_AUTO_TEST_CASE(testRouteCompile) { auto input = rootDir / "testRoutes.json"; auto outputc = binDir / "testRoutes.cpp"; @@ -82,4 +82,3 @@ BOOST_AUTO_TEST_CASE( testRouteCompile ) } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp index d8c1b0f..789e6fa 100644 --- a/icespider/unittests/testFcgi.cpp +++ b/icespider/unittests/testFcgi.cpp @@ -1,16 +1,18 @@ #define BOOST_TEST_MODULE TestApp #include <boost/test/unit_test.hpp> +#include <cgiRequestBase.h> #include <core.h> #include <definedDirs.h> -#include <cgiRequestBase.h> -#include <test-fcgi.h> #include <slicer/modelPartsTypes.h> +#include <test-fcgi.h> using namespace std::literals; namespace std { template<typename T> - ostream & operator<<(ostream & s, const std::optional<T> & o) { + ostream & + operator<<(ostream & s, const std::optional<T> & o) + { if (o) { s << *o; } @@ -19,89 +21,90 @@ namespace std { } namespace std { - ostream & operator<<(ostream & s, const IceSpider::HttpMethod & m) { + ostream & + operator<<(ostream & s, const IceSpider::HttpMethod & m) + { s << Slicer::ModelPartForEnum<IceSpider::HttpMethod>::lookup(m); return s; } } - class TestRequest : public IceSpider::CgiRequestBase { - public: - TestRequest(IceSpider::Core * c, char ** env) : IceSpider::CgiRequestBase(c, env) - { - initialize(); - } +public: + TestRequest(IceSpider::Core * c, char ** env) : IceSpider::CgiRequestBase(c, env) + { + initialize(); + } - std::ostream & getOutputStream() const override - { - return out; - } + std::ostream & + getOutputStream() const override + { + return out; + } - // LCOV_EXCL_START we never actually read or write anything here - std::istream & getInputStream() const override - { - return std::cin; - } - // LCOV_EXCL_STOP + // LCOV_EXCL_START we never actually read or write anything here + std::istream & + getInputStream() const override + { + return std::cin; + } + // LCOV_EXCL_STOP - // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) - mutable std::stringstream out; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + mutable std::stringstream out; }; class TestPayloadRequest : public TestRequest { - public: - TestPayloadRequest(IceSpider::Core * c, char ** env, std::istream & s) : - TestRequest(c, env), - in(s) - { - initialize(); - } +public: + TestPayloadRequest(IceSpider::Core * c, char ** env, std::istream & s) : TestRequest(c, env), in(s) + { + initialize(); + } - std::istream & getInputStream() const override - { - return in; - } + std::istream & + getInputStream() const override + { + return in; + } - private: - std::istream & in; +private: + std::istream & in; }; // NOLINTNEXTLINE(hicpp-special-member-functions) class CharPtrPtrArray : public std::vector<char *> { - public: - CharPtrPtrArray() - { - push_back(nullptr); - } +public: + CharPtrPtrArray() + { + push_back(nullptr); + } - explicit CharPtrPtrArray(const std::vector<std::string> & a) - { - for (const auto & e : a) { - push_back(strdup(e.c_str())); - } - push_back(nullptr); + explicit CharPtrPtrArray(const std::vector<std::string> & a) + { + for (const auto & e : a) { + push_back(strdup(e.c_str())); } + push_back(nullptr); + } - ~CharPtrPtrArray() - { - for (const auto & e : *this) { - // NOLINTNEXTLINE(hicpp-no-malloc) - free(e); - } + ~CharPtrPtrArray() + { + for (const auto & e : *this) { + // NOLINTNEXTLINE(hicpp-no-malloc) + free(e); } + } - // NOLINTNEXTLINE(hicpp-explicit-conversions) - operator char **() - { - return &front(); - } + // NOLINTNEXTLINE(hicpp-explicit-conversions) + operator char * *() + { + return &front(); + } }; namespace std { // LCOV_EXCL_START assert failure helper only - static - std::ostream & + static std::ostream & operator<<(std::ostream & s, const IceSpider::PathElements & pe) { for (const auto & e : pe) { @@ -112,73 +115,75 @@ namespace std { // LCOV_EXCL_STOP } -BOOST_FIXTURE_TEST_SUITE( CgiRequestBase, IceSpider::CoreWithDefaultRouter ); +BOOST_FIXTURE_TEST_SUITE(CgiRequestBase, IceSpider::CoreWithDefaultRouter); -BOOST_AUTO_TEST_CASE( NoEnvironment ) +BOOST_AUTO_TEST_CASE(NoEnvironment) { - BOOST_REQUIRE_THROW({ - CharPtrPtrArray env; - TestRequest r(this, env); - }, IceSpider::Http400_BadRequest); + BOOST_REQUIRE_THROW( + { + CharPtrPtrArray env; + TestRequest r(this, env); + }, + IceSpider::Http400_BadRequest); } -BOOST_AUTO_TEST_CASE( script_name_root ) +BOOST_AUTO_TEST_CASE(script_name_root) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/" }); + CharPtrPtrArray env({"SCRIPT_NAME=/"}); TestRequest r(this, env); BOOST_REQUIRE(r.getRequestPath().empty()); BOOST_CHECK(!r.isSecure()); } -BOOST_AUTO_TEST_CASE( script_name_root_https ) +BOOST_AUTO_TEST_CASE(script_name_root_https) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "HTTPS=on" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "HTTPS=on"}); TestRequest r(this, env); BOOST_REQUIRE(r.getRequestPath().empty()); BOOST_CHECK(r.isSecure()); } -BOOST_AUTO_TEST_CASE( redirect_uri_root ) +BOOST_AUTO_TEST_CASE(redirect_uri_root) { - CharPtrPtrArray env ({ "REDIRECT_URL=/" }); + CharPtrPtrArray env({"REDIRECT_URL=/"}); TestRequest r(this, env); BOOST_REQUIRE(r.getRequestPath().empty()); } -BOOST_AUTO_TEST_CASE( script_name_foobar ) +BOOST_AUTO_TEST_CASE(script_name_foobar) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar"}); TestRequest r(this, env); BOOST_REQUIRE_EQUAL(IceSpider::PathElements({"foo", "bar"}), r.getRequestPath()); } -BOOST_AUTO_TEST_CASE( query_string_empty ) +BOOST_AUTO_TEST_CASE(query_string_empty) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING="}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); } -BOOST_AUTO_TEST_CASE( query_string_one ) +BOOST_AUTO_TEST_CASE(query_string_one) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); BOOST_REQUIRE_EQUAL("1", *r.getQueryStringParam("one")); } -BOOST_AUTO_TEST_CASE( query_string_two ) +BOOST_AUTO_TEST_CASE(query_string_two) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two=2" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two=2"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); BOOST_REQUIRE_EQUAL("1", *r.getQueryStringParam("one")); BOOST_REQUIRE_EQUAL("2", *r.getQueryStringParam("two")); } -BOOST_AUTO_TEST_CASE( query_string_three ) +BOOST_AUTO_TEST_CASE(query_string_three) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two=2&three=3" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two=2&three=3"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); BOOST_REQUIRE_EQUAL("1", *r.getQueryStringParam("one")); @@ -186,18 +191,18 @@ BOOST_AUTO_TEST_CASE( query_string_three ) BOOST_REQUIRE_EQUAL("3", *r.getQueryStringParam("three")); } -BOOST_AUTO_TEST_CASE( query_string_urlencoding ) +BOOST_AUTO_TEST_CASE(query_string_urlencoding) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=url+%65ncoded=%53tring%2e" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING=url+%65ncoded=%53tring%2e"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); BOOST_REQUIRE(r.getQueryStringParam("url encoded")); BOOST_REQUIRE_EQUAL("String.", *r.getQueryStringParam("url encoded")); } -BOOST_AUTO_TEST_CASE( query_string_three_emptyVal ) +BOOST_AUTO_TEST_CASE(query_string_three_emptyVal) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two=&three=3" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two=&three=3"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); BOOST_REQUIRE_EQUAL("1", *r.getQueryStringParam("one")); @@ -205,9 +210,9 @@ BOOST_AUTO_TEST_CASE( query_string_three_emptyVal ) BOOST_REQUIRE_EQUAL("3", *r.getQueryStringParam("three")); } -BOOST_AUTO_TEST_CASE( query_string_three_noVal ) +BOOST_AUTO_TEST_CASE(query_string_three_noVal) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two&three=3" }); + CharPtrPtrArray env({"SCRIPT_NAME=/foo/bar", "QUERY_STRING=one=1&two&three=3"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getQueryStringParam("")); BOOST_REQUIRE_EQUAL("1", *r.getQueryStringParam("one")); @@ -215,109 +220,112 @@ BOOST_AUTO_TEST_CASE( query_string_three_noVal ) BOOST_REQUIRE_EQUAL("3", *r.getQueryStringParam("three")); } -BOOST_AUTO_TEST_CASE( requestmethod_get ) +BOOST_AUTO_TEST_CASE(requestmethod_get) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=GET" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=GET"}); TestRequest r(this, env); BOOST_REQUIRE_EQUAL(IceSpider::HttpMethod::GET, r.getRequestMethod()); } -BOOST_AUTO_TEST_CASE( requestmethod_post ) +BOOST_AUTO_TEST_CASE(requestmethod_post) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=POST" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=POST"}); TestRequest r(this, env); BOOST_REQUIRE_EQUAL(IceSpider::HttpMethod::POST, r.getRequestMethod()); } -BOOST_AUTO_TEST_CASE( requestmethod_bad ) +BOOST_AUTO_TEST_CASE(requestmethod_bad) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No"}); TestRequest r(this, env); - BOOST_REQUIRE_THROW(r.getRequestMethod(), IceSpider::Http405_MethodNotAllowed); + BOOST_REQUIRE_THROW((void)r.getRequestMethod(), IceSpider::Http405_MethodNotAllowed); } -BOOST_AUTO_TEST_CASE( requestmethod_missing ) +BOOST_AUTO_TEST_CASE(requestmethod_missing) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/" }); + CharPtrPtrArray env({"SCRIPT_NAME=/"}); TestRequest r(this, env); - BOOST_REQUIRE_THROW(r.getRequestMethod(), IceSpider::Http400_BadRequest); + BOOST_REQUIRE_THROW((void)r.getRequestMethod(), IceSpider::Http400_BadRequest); } -BOOST_AUTO_TEST_CASE( acceptheader ) +BOOST_AUTO_TEST_CASE(acceptheader) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "HTTP_ACCEPT=text/html" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "HTTP_ACCEPT=text/html"}); TestRequest r(this, env); BOOST_REQUIRE_EQUAL("text/html", *r.getHeaderParam("ACCEPT")); BOOST_REQUIRE_EQUAL("text/html", *r.getHeaderParam(IceSpider::H::ACCEPT)); } -BOOST_AUTO_TEST_CASE( missingheader ) +BOOST_AUTO_TEST_CASE(missingheader) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "HTTP_ACCEPT=text/html" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "HTTP_ACCEPT=text/html"}); TestRequest r(this, env); BOOST_REQUIRE(!r.getHeaderParam("ACCEPT_LANGUAGE")); } -BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_simple ) +BOOST_AUTO_TEST_CASE(postxwwwformurlencoded_simple) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded"}); std::stringstream f("value=314"); TestPayloadRequest r(this, env, f); auto n = r.getBody<int>(); BOOST_REQUIRE_EQUAL(314, n); } -BOOST_AUTO_TEST_CASE( reqParsePerf ) +BOOST_AUTO_TEST_CASE(reqParsePerf) { - CharPtrPtrArray env ({ - "CONTEXT_DOCUMENT_ROOT=/var/www/shared/vhosts/sys.randomdan.homeip.net", - "CONTEXT_PREFIX=", - "DOCUMENT_ROOT=/var/www/shared/vhosts/sys.randomdan.homeip.net", - "GATEWAY_INTERFACE=CGI/1.1", - "H2PUSH=on", - "H2_PUSH=on", - "H2_PUSHED=", - "H2_PUSHED_ON=", - "H2_STREAM_ID=1", - "H2_STREAM_TAG=137-1", - "HTTP2=on", - "HTTPS=on", - "HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3", - "HTTP_ACCEPT_ENCODING=gzip, deflate, br", - "HTTP_ACCEPT_LANGUAGE=en,en-GB;q=0.9", - "HTTP_HOST=sys.randomdan.homeip.net", - "HTTP_SEC_FETCH_SITE=none", - "HTTP_UPGRADE_INSECURE_REQUESTS=1", - "HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36", - "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", - "PWD=/var/www/shared/files/localhost", - "QUERY_STRING=", - "REMOTE_ADDR=10.10.0.189", - "REMOTE_PORT=44030", - "REQUEST_METHOD=GET", - "REQUEST_SCHEME=https", - "REQUEST_URI=/env.cgi", - "SCRIPT_FILENAME=/var/www/shared/vhosts/sys.randomdan.homeip.net/env.cgi", - "SCRIPT_NAME=/env.cgi", - "SERVER_ADDR=fdc7:602:e9c5:b8f0::3", - "SERVER_ADMIN=dan.goodliffe@randomdan.homeip.net", - "SERVER_NAME=sys.randomdan.homeip.net", - "SERVER_PORT=443", - "SERVER_PROTOCOL=HTTP/2.0", - "SERVER_SIGNATURE=<address>Apache/2.4.41 (Gentoo) mod_fcgid/2.3.9 PHP/7.2.23 OpenSSL/1.1.1d mod_perl/2.0.10 Perl/v5.30.0 Server at sys.randomdan.homeip.net Port 443</address>", - "SERVER_SOFTWARE=Apache/2.4.41 (Gentoo) mod_fcgid/2.3.9 PHP/7.2.23 OpenSSL/1.1.1d mod_perl/2.0.10 Perl/v5.30.0", - "SHLVL=0", - "SSL_TLS_SNI=sys.randomdan.homeip.net", + CharPtrPtrArray env({ + "CONTEXT_DOCUMENT_ROOT=/var/www/shared/vhosts/sys.randomdan.homeip.net", + "CONTEXT_PREFIX=", + "DOCUMENT_ROOT=/var/www/shared/vhosts/sys.randomdan.homeip.net", + "GATEWAY_INTERFACE=CGI/1.1", + "H2PUSH=on", + "H2_PUSH=on", + "H2_PUSHED=", + "H2_PUSHED_ON=", + "H2_STREAM_ID=1", + "H2_STREAM_TAG=137-1", + "HTTP2=on", + "HTTPS=on", + ("HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/" + "*;q=0.8,application/signed-exchange;v=b3"), + "HTTP_ACCEPT_ENCODING=gzip, deflate, br", + "HTTP_ACCEPT_LANGUAGE=en,en-GB;q=0.9", + "HTTP_HOST=sys.randomdan.homeip.net", + "HTTP_SEC_FETCH_SITE=none", + "HTTP_UPGRADE_INSECURE_REQUESTS=1", + ("HTTP_USER_AGENT=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " + "Chrome/77.0.3865.90 Safari/537.36"), + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "PWD=/var/www/shared/files/localhost", + "QUERY_STRING=", + "REMOTE_ADDR=10.10.0.189", + "REMOTE_PORT=44030", + "REQUEST_METHOD=GET", + "REQUEST_SCHEME=https", + "REQUEST_URI=/env.cgi", + "SCRIPT_FILENAME=/var/www/shared/vhosts/sys.randomdan.homeip.net/env.cgi", + "SCRIPT_NAME=/env.cgi", + "SERVER_ADDR=fdc7:602:e9c5:b8f0::3", + "SERVER_ADMIN=dan.goodliffe@randomdan.homeip.net", + "SERVER_NAME=sys.randomdan.homeip.net", + "SERVER_PORT=443", + "SERVER_PROTOCOL=HTTP/2.0", + ("SERVER_SIGNATURE=<address>Apache/2.4.41 (Gentoo) mod_fcgid/2.3.9 PHP/7.2.23 OpenSSL/1.1.1d " + "mod_perl/2.0.10 Perl/v5.30.0 Server at sys.randomdan.homeip.net Port 443</address>"), + ("SERVER_SOFTWARE=Apache/2.4.41 (Gentoo) mod_fcgid/2.3.9 PHP/7.2.23 OpenSSL/1.1.1d mod_perl/2.0.10 " + "Perl/v5.30.0"), + "SHLVL=0", + "SSL_TLS_SNI=sys.randomdan.homeip.net", }); - for (int x = 0; x < 10000; x +=1) { + for (int x = 0; x < 10000; x += 1) { TestRequest req(this, env); } } - -BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_dictionary ) +BOOST_AUTO_TEST_CASE(postxwwwformurlencoded_dictionary) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded"}); std::stringstream f("alpha=abcde&number=3.14&boolean=true&spaces=This+is+a%20string.&empty="); TestPayloadRequest r(this, env, f); auto n = *r.getBody<IceSpider::StringMap>(); @@ -329,9 +337,9 @@ BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_dictionary ) BOOST_REQUIRE_EQUAL("", n["empty"]); } -BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_complex ) +BOOST_AUTO_TEST_CASE(postxwwwformurlencoded_complex) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/x-www-form-urlencoded"}); std::stringstream f("alpha=abcde&number=3.14&boolean=true&empty=&spaces=This+is+a%20string."); TestPayloadRequest r(this, env, f); auto n = *r.getBody<TestFcgi::ComplexPtr>(); @@ -342,9 +350,9 @@ BOOST_AUTO_TEST_CASE( postxwwwformurlencoded_complex ) BOOST_REQUIRE_EQUAL("", n->empty); } -BOOST_AUTO_TEST_CASE( postjson_complex ) +BOOST_AUTO_TEST_CASE(postjson_complex) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json" }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json"}); std::stringstream f(R"J({"alpha":"abcde","number":3.14,"boolean":true,"empty":"","spaces":"This is a string."})J"); TestPayloadRequest r(this, env, f); auto n = *r.getBody<TestFcgi::ComplexPtr>(); @@ -355,10 +363,11 @@ BOOST_AUTO_TEST_CASE( postjson_complex ) BOOST_REQUIRE_EQUAL("", n->empty); } -BOOST_AUTO_TEST_CASE( postjson_dictionary ) +BOOST_AUTO_TEST_CASE(postjson_dictionary) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json" }); - std::stringstream f(R"J({"alpha":"abcde","number":"3.14","boolean":"true","empty":"","spaces":"This is a string."})J"); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json"}); + std::stringstream f( + R"J({"alpha":"abcde","number":"3.14","boolean":"true","empty":"","spaces":"This is a string."})J"); TestPayloadRequest r(this, env, f); auto n = *r.getBody<IceSpider::StringMap>(); BOOST_REQUIRE_EQUAL(5, n.size()); @@ -369,24 +378,26 @@ BOOST_AUTO_TEST_CASE( postjson_dictionary ) BOOST_REQUIRE_EQUAL("", n["empty"]); } -BOOST_AUTO_TEST_CASE( cookies ) +BOOST_AUTO_TEST_CASE(cookies) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json", "HTTP_COOKIE=valueA=1234; value+B=Something+with+spaces." }); + CharPtrPtrArray env({"SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json", + "HTTP_COOKIE=valueA=1234; value+B=Something+with+spaces."}); TestRequest r(this, env); BOOST_REQUIRE_EQUAL(1234, *r.IceSpider::IHttpRequest::getCookieParam<Ice::Int>("valueA")); BOOST_REQUIRE_EQUAL("Something with spaces.", *r.IceSpider::IHttpRequest::getCookieParam<std::string>("value B")); BOOST_REQUIRE(!r.IceSpider::IHttpRequest::getCookieParam<Ice::Int>("notAThing")); r.setCookie("some int.", 1234, "www.com"s, "/dir"s, true, 1476142378); - BOOST_REQUIRE_EQUAL("Set-Cookie: some+int%2e=1234; expires=Mon, 10 Oct 2016 23:32:58 GMT; domain=www.com; path=/dir; secure; samesite=strict\r\n", r.out.str()); + BOOST_REQUIRE_EQUAL("Set-Cookie: some+int%2e=1234; expires=Mon, 10 Oct 2016 23:32:58 GMT; domain=www.com; " + "path=/dir; secure; samesite=strict\r\n", + r.out.str()); } -BOOST_AUTO_TEST_CASE( response ) +BOOST_AUTO_TEST_CASE(response) { - CharPtrPtrArray env ({ "SCRIPT_NAME=/" }); + CharPtrPtrArray env({"SCRIPT_NAME=/"}); TestRequest r(this, env); r.response(200, "OK"); BOOST_REQUIRE_EQUAL("Status: 200 OK\r\n\r\n", r.out.str()); } BOOST_AUTO_TEST_SUITE_END(); - diff --git a/icespider/unittests/testFileSessions.cpp b/icespider/unittests/testFileSessions.cpp index 1ab75f7..3712d03 100644 --- a/icespider/unittests/testFileSessions.cpp +++ b/icespider/unittests/testFileSessions.cpp @@ -3,28 +3,26 @@ #include <Ice/Initialize.h> #include <Ice/Properties.h> -#include <session.h> #include <core.h> #include <definedDirs.h> +#include <session.h> BOOST_TEST_DONT_PRINT_LOG_VALUE(IceSpider::Variables); class TestCore : public IceSpider::CoreWithDefaultRouter { - public: - TestCore() : - IceSpider::CoreWithDefaultRouter({ - "--IceSpider.SessionManager=IceSpider-FileSessions", +public: + TestCore() : + IceSpider::CoreWithDefaultRouter({"--IceSpider.SessionManager=IceSpider-FileSessions", "--IceSpider.FileSessions.Path=" + (binDir / "test-sessions").string(), - "--IceSpider.FileSessions.Duration=0" - }), - root(communicator->getProperties()->getProperty("IceSpider.FileSessions.Path")) - { - } - // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) - const std::filesystem::path root; + "--IceSpider.FileSessions.Duration=0"}), + root(communicator->getProperties()->getProperty("IceSpider.FileSessions.Path")) + { + } + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) + const std::filesystem::path root; }; -BOOST_AUTO_TEST_CASE( clear ) +BOOST_AUTO_TEST_CASE(clear) { TestCore tc; if (std::filesystem::exists(tc.root)) { @@ -34,14 +32,14 @@ BOOST_AUTO_TEST_CASE( clear ) BOOST_FIXTURE_TEST_SUITE(Core, TestCore); -BOOST_AUTO_TEST_CASE( ping ) +BOOST_AUTO_TEST_CASE(ping) { auto prx = this->getProxy<IceSpider::SessionManager>(); BOOST_REQUIRE(prx); prx->ice_ping(); } -BOOST_AUTO_TEST_CASE( createAndDestroy ) +BOOST_AUTO_TEST_CASE(createAndDestroy) { auto prx = this->getProxy<IceSpider::SessionManager>(); auto s = prx->createSession(); @@ -52,7 +50,7 @@ BOOST_AUTO_TEST_CASE( createAndDestroy ) BOOST_REQUIRE(!std::filesystem::exists(root / s->id)); } -BOOST_AUTO_TEST_CASE( createAndChangeRestore ) +BOOST_AUTO_TEST_CASE(createAndChangeRestore) { auto prx = this->getProxy<IceSpider::SessionManager>(); auto s = prx->createSession(); @@ -66,7 +64,7 @@ BOOST_AUTO_TEST_CASE( createAndChangeRestore ) prx->destroySession(s->id); } -BOOST_AUTO_TEST_CASE( createAndExpire ) +BOOST_AUTO_TEST_CASE(createAndExpire) { auto prx = this->getProxy<IceSpider::SessionManager>(); auto s = prx->createSession(); @@ -79,35 +77,34 @@ BOOST_AUTO_TEST_CASE( createAndExpire ) BOOST_REQUIRE(!std::filesystem::exists(root / s->id)); } -BOOST_AUTO_TEST_CASE( missing ) +BOOST_AUTO_TEST_CASE(missing) { auto prx = this->getProxy<IceSpider::SessionManager>(); BOOST_REQUIRE(!prx->getSession("missing")); BOOST_REQUIRE(!std::filesystem::exists(root / "missing")); } -BOOST_AUTO_TEST_CASE( createAndLeave ) +BOOST_AUTO_TEST_CASE(createAndLeave) { auto prx = this->getProxy<IceSpider::SessionManager>(); auto s = prx->createSession(); BOOST_REQUIRE(std::filesystem::exists(root / s->id)); } -BOOST_AUTO_TEST_CASE( left ) +BOOST_AUTO_TEST_CASE(left) { BOOST_REQUIRE(!std::filesystem::is_empty(root)); } -BOOST_AUTO_TEST_CASE( expire ) +BOOST_AUTO_TEST_CASE(expire) { usleep(1001000); } BOOST_AUTO_TEST_SUITE_END(); -BOOST_AUTO_TEST_CASE( empty ) +BOOST_AUTO_TEST_CASE(empty) { TestCore tc; BOOST_REQUIRE(std::filesystem::is_empty(tc.root)); } - |