diff options
-rw-r--r-- | gentoobrowse/src/base.cpp | 16 | ||||
-rw-r--r-- | gentoobrowse/src/mash.ice | 1 | ||||
-rw-r--r-- | gentoobrowse/src/test.cpp | 80 | ||||
-rw-r--r-- | gentoobrowse/src/use.json | 3 |
4 files changed, 83 insertions, 17 deletions
diff --git a/gentoobrowse/src/base.cpp b/gentoobrowse/src/base.cpp index 9656a1f..5ed5114 100644 --- a/gentoobrowse/src/base.cpp +++ b/gentoobrowse/src/base.cpp @@ -4,6 +4,8 @@ #include <icespider-routes-base.h> #include <mash.h> #include <algorithm> +#include <core.h> +#include <exceptions.h> namespace GentooBrowse { ::Gentoo::UserPtr @@ -61,7 +63,21 @@ namespace GentooBrowse { return ids.find(package->packageid) == ids.end(); }), packages.end()); } + + class SlicerNoRowsHandler : public IceSpider::ErrorHandler { + public: + IceSpider::ErrorHandlerResult + handleError(IceSpider::IHttpRequest *, const std::exception & ex) const + { + if (dynamic_cast<const Slicer::NoRowsReturned *>(&ex)) { + throw IceSpider::Http404_NotFound(); + } + return IceSpider::ErrorHandlerResult_Unhandled; + } + }; } +PLUGIN(GentooBrowse::SlicerNoRowsHandler, IceSpider::ErrorHandler); + #endif diff --git a/gentoobrowse/src/mash.ice b/gentoobrowse/src/mash.ice index 6440d80..ff3f5f9 100644 --- a/gentoobrowse/src/mash.ice +++ b/gentoobrowse/src/mash.ice @@ -99,6 +99,7 @@ module GentooBrowse { Gentoo::Categories categories; Gentoo::Uses usage; Gentoo::Packages packages; + Gentoo::Use use; }; ["slicer:root:gentoo"] diff --git a/gentoobrowse/src/test.cpp b/gentoobrowse/src/test.cpp index 1841721..a3fff0e 100644 --- a/gentoobrowse/src/test.cpp +++ b/gentoobrowse/src/test.cpp @@ -20,21 +20,27 @@ class ChromiumRequest : public TestRequest { TestRequest(c, m, p) { hdr["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.21 Safari/537.36"; - hdr["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; hdr["Accept-Encoding"] = "gzip, deflate, sdch"; hdr["Accept-Language"] = "en-GB,en;q=0.8"; } - virtual void standardAssertions(const char * name) + virtual void standardAssertions(const char * name) = 0; +}; + +class ChromiumRequestHtml : public ChromiumRequest { + public: + ChromiumRequestHtml(const Core * c, HttpMethod m, const std::string & p) : + ChromiumRequest(c, m, p) + { + hdr["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; + } + + virtual void standardAssertions(const char * name) override { auto h = getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "text/html"); - validateHtml(name); - } - void validateHtml(const char * name) - { TidyDoc tdoc = tidyCreate(); TidyInputSource tis{ &output, &streamGet, &streamUnget, &streamEof }; BOOST_REQUIRE_EQUAL(1, tidyOptSetBool(tdoc, TidyIndentContent, yes)); @@ -48,6 +54,18 @@ class ChromiumRequest : public TestRequest { } }; +class ChromiumRequest404 : public ChromiumRequest { + public: + ChromiumRequest404(const Core * c, HttpMethod m, const std::string & p) : + ChromiumRequest(c, m, p) { } + + virtual void standardAssertions(const char *) override + { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "404 Not found"); + } +}; + class ChromiumRequestXml : public ChromiumRequest { public: ChromiumRequestXml(const Core * c, HttpMethod m, const std::string & p) : @@ -99,70 +117,98 @@ BOOST_AUTO_TEST_CASE( endpointCount ) BOOST_AUTO_TEST_CASE( home ) { - ChromiumRequest request(this, HttpMethod::GET, "/"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( news ) { - ChromiumRequest request(this, HttpMethod::GET, "/news"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/news"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( news_ruby_20_removal ) { - ChromiumRequest request(this, HttpMethod::GET, "/news/2016-12-06-ruby-20-removal"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/news/2016-12-06-ruby-20-removal"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( news_404 ) +{ + ChromiumRequest404 request(this, HttpMethod::GET, "/news/404"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( packages ) { - ChromiumRequest request(this, HttpMethod::GET, "/packages"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/packages"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( packages_popular ) { - ChromiumRequest request(this, HttpMethod::GET, "/packages/popular"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/packages/popular"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( packages_virtual ) { - ChromiumRequest request(this, HttpMethod::GET, "/packages/virtual"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/packages/virtual"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( packages_404 ) +{ + ChromiumRequest404 request(this, HttpMethod::GET, "/packages/404"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( packages_virtual_cron ) { - ChromiumRequest request(this, HttpMethod::GET, "/packages/virtual/cron"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/packages/virtual/cron"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( packages_virtual_404 ) +{ + ChromiumRequest404 request(this, HttpMethod::GET, "/packages/virtual/404"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( use ) { - ChromiumRequest request(this, HttpMethod::GET, "/use"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/use"); process(&request); request.standardAssertions(typeid(this).name()); } BOOST_AUTO_TEST_CASE( use_gles ) { - ChromiumRequest request(this, HttpMethod::GET, "/use/gles"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/use/gles"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( use_404 ) +{ + ChromiumRequest404 request(this, HttpMethod::GET, "/use/404"); process(&request); request.standardAssertions(typeid(this).name()); } -BOOST_AUTO_TEST_CASE( search_default ) +BOOST_AUTO_TEST_CASE( search_default ) { - ChromiumRequest request(this, HttpMethod::GET, "/search"); + ChromiumRequestHtml request(this, HttpMethod::GET, "/search"); request.qs["criteria"] = "default"; process(&request); request.standardAssertions(typeid(this).name()); diff --git a/gentoobrowse/src/use.json b/gentoobrowse/src/use.json index 63a9161..a0bd57d 100644 --- a/gentoobrowse/src/use.json +++ b/gentoobrowse/src/use.json @@ -36,6 +36,9 @@ "packages": { "operation": "Gentoo.Portage.getUsePackages" }, + "use": { + "operation": "Gentoo.Portage.getUse" + }, "usage": { "operation": "Gentoo.Portage.getUseUsage" } |