From 62d506c24aaf543f84c82e2850a05b1387e4990d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 9 Jan 2021 13:58:38 +0000 Subject: Clang format --- site/custom.cpp | 39 +++++++++++------------ site/test.cpp | 99 ++++++++++++++++++++++++++++----------------------------- 2 files changed, 67 insertions(+), 71 deletions(-) (limited to 'site') diff --git a/site/custom.cpp b/site/custom.cpp index 5d955a2..00dcb6a 100644 --- a/site/custom.cpp +++ b/site/custom.cpp @@ -7,27 +7,27 @@ namespace MirrorSearch { // Route name: download // path: /download/{filename} class download : public IceSpider::IRouteHandler { - public: - download(const IceSpider::Core * core) : - IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/download/{filename}"), - prx0(core->getProxy()), - _pi_filename(1) - { + public: + download(const IceSpider::Core * core) : + IceSpider::IRouteHandler(IceSpider::HttpMethod::GET, "/download/{filename}"), + prx0(core->getProxy()), _pi_filename(1) + { + } + + void + execute(IceSpider::IHttpRequest * request) const + { + auto _p_filename(request->getURLParam<::std::string>(_pi_filename)); + auto _responseModel = prx0->feelingLucky(_p_filename, request->getContext()); + if (_responseModel) { + request->responseRedirect(*_responseModel, "Mirror found"s); } + request->response(404, "No mirror found"); + } - void execute(IceSpider::IHttpRequest * request) const - { - auto _p_filename(request->getURLParam<::std::string>(_pi_filename)); - auto _responseModel = prx0->feelingLucky(_p_filename, request->getContext()); - if (_responseModel) { - request->responseRedirect(*_responseModel, "Mirror found"s); - } - request->response(404, "No mirror found"); - } - - private: - const MirrorSearch::SearchPrxPtr prx0; - const unsigned int _pi_filename; + private: + const MirrorSearch::SearchPrxPtr prx0; + const unsigned int _pi_filename; }; } // namespace MirrorSearch @@ -36,4 +36,3 @@ namespace MirrorSearch { FACTORY(MirrorSearch::download, IceSpider::RouteHandlerFactory); // End generated code. - diff --git a/site/test.cpp b/site/test.cpp index 4cd9763..bcff64b 100644 --- a/site/test.cpp +++ b/site/test.cpp @@ -1,68 +1,66 @@ #define BOOST_TEST_MODULE mirrorsearchsite #include -#include -#include #include +#include +#include -#include #include +#include using namespace IceSpider; using namespace MirrorSearch; class TestSerice : public Search { - public: - virtual SearchServices getServices(const ::Ice::Current& = ::Ice::Current()) override - { - return {}; +public: + virtual SearchServices + getServices(const ::Ice::Current & = ::Ice::Current()) override + { + return {}; + } + virtual SearchHits + getMatches(const ::std::string fn, const ::Ice::Current & = ::Ice::Current()) override + { + BOOST_TEST_INFO(fn); + if (fn == "good.txt") { + return {std::make_shared(1, 1, "file:///some/file/path"), + std::make_shared(1, 1, "file:///some/other/path")}; } - virtual SearchHits getMatches(const ::std::string fn, const ::Ice::Current& = ::Ice::Current()) override - { - BOOST_TEST_INFO(fn); - if (fn == "good.txt") { - return { - std::make_shared(1, 1, "file:///some/file/path"), - std::make_shared(1, 1, "file:///some/other/path") - }; - } - return {}; - } - virtual ::Ice::optional<::std::string> feelingLucky(const ::std::string fn, const ::Ice::Current & c = ::Ice::Current()) override - { - auto ms = getMatches(fn, c); - if (ms.empty()) { - return IceUtil::None; - - } - return ms.front()->url; + return {}; + } + virtual ::Ice::optional<::std::string> + feelingLucky(const ::std::string fn, const ::Ice::Current & c = ::Ice::Current()) override + { + auto ms = getMatches(fn, c); + if (ms.empty()) { + return IceUtil::None; } + return ms.front()->url; + } }; class TestApp : public CoreWithDefaultRouter { - public: - TestApp() : - CoreWithDefaultRouter({ - "--MirrorSearch.Search=Search" - }), - adp(communicator->createObjectAdapterWithEndpoints("test", "default")) - { - adp->activate(); - adp->add(std::make_shared(), Ice::stringToIdentity("Search")); - } - - ~TestApp() - { - adp->deactivate(); - adp->destroy(); - } - - Ice::ObjectAdapterPtr adp; +public: + TestApp() : + CoreWithDefaultRouter({"--MirrorSearch.Search=Search"}), + adp(communicator->createObjectAdapterWithEndpoints("test", "default")) + { + adp->activate(); + adp->add(std::make_shared(), Ice::stringToIdentity("Search")); + } + + ~TestApp() + { + adp->deactivate(); + adp->destroy(); + } + + Ice::ObjectAdapterPtr adp; }; BOOST_FIXTURE_TEST_SUITE(ta, TestApp); -BOOST_AUTO_TEST_CASE( testCallIndexNoFile ) +BOOST_AUTO_TEST_CASE(testCallIndexNoFile) { TestRequest requestGetIndex(this, HttpMethod::GET, "/list"); process(&requestGetIndex); @@ -70,7 +68,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexNoFile ) BOOST_CHECK_EQUAL(h["Status"], "404 Not found"); } -BOOST_AUTO_TEST_CASE( testCallServiceList ) +BOOST_AUTO_TEST_CASE(testCallServiceList) { TestRequest requestGetIndex(this, HttpMethod::GET, "/services"); process(&requestGetIndex); @@ -79,7 +77,7 @@ BOOST_AUTO_TEST_CASE( testCallServiceList ) BOOST_CHECK_EQUAL(h["Content-Type"], "application/json"); } -BOOST_AUTO_TEST_CASE( testCallIndex ) +BOOST_AUTO_TEST_CASE(testCallIndex) { TestRequest requestGetIndex(this, HttpMethod::GET, "/list/somefile.txt"); process(&requestGetIndex); @@ -88,7 +86,7 @@ BOOST_AUTO_TEST_CASE( testCallIndex ) BOOST_CHECK_EQUAL(h["Content-Type"], "application/json"); } -BOOST_AUTO_TEST_CASE( testCallDownloadNotFile ) +BOOST_AUTO_TEST_CASE(testCallDownloadNotFile) { TestRequest requestGetIndex(this, HttpMethod::GET, "/download"); process(&requestGetIndex); @@ -96,7 +94,7 @@ BOOST_AUTO_TEST_CASE( testCallDownloadNotFile ) BOOST_CHECK_EQUAL(h["Status"], "404 Not found"); } -BOOST_AUTO_TEST_CASE( testCallDownloadBad ) +BOOST_AUTO_TEST_CASE(testCallDownloadBad) { TestRequest requestGetIndex(this, HttpMethod::GET, "/download/bad.txt"); process(&requestGetIndex); @@ -104,7 +102,7 @@ BOOST_AUTO_TEST_CASE( testCallDownloadBad ) BOOST_CHECK_EQUAL(h["Status"], "404 No mirror found"); } -BOOST_AUTO_TEST_CASE( testCallDownloadGood ) +BOOST_AUTO_TEST_CASE(testCallDownloadGood) { TestRequest requestGetIndex(this, HttpMethod::GET, "/download/good.txt"); process(&requestGetIndex); @@ -114,4 +112,3 @@ BOOST_AUTO_TEST_CASE( testCallDownloadGood ) } BOOST_AUTO_TEST_SUITE_END(); - -- cgit v1.2.3