From d3465d0d00edd302c9d6fc7672a9405921a6a7db Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 23 Dec 2016 15:22:30 +0000 Subject: Add basic icespider tests and check core pages with tidy --- gentoobrowse/Jamfile.jam | 1 + gentoobrowse/gentoobrowse-cgi | 2 +- gentoobrowse/src/Jamfile.jam | 40 +++++++++--- gentoobrowse/src/test.cpp | 126 ++++++++++++++++++++++++++++++++++++++ gentoobrowse/xslt/base.xslt | 42 ++++++------- gentoobrowse/xslt/categories.xslt | 3 +- gentoobrowse/xslt/category.xslt | 9 ++- gentoobrowse/xslt/home.xslt | 2 +- gentoobrowse/xslt/news.xslt | 1 + gentoobrowse/xslt/package.xslt | 22 +++---- gentoobrowse/xslt/popular.xslt | 3 +- gentoobrowse/xslt/search.xslt | 8 +-- gentoobrowse/xslt/use-detail.xslt | 2 +- gentoobrowse/xslt/use.xslt | 2 +- 14 files changed, 208 insertions(+), 55 deletions(-) create mode 100644 gentoobrowse/src/test.cpp diff --git a/gentoobrowse/Jamfile.jam b/gentoobrowse/Jamfile.jam index e69de29..038361f 100644 --- a/gentoobrowse/Jamfile.jam +++ b/gentoobrowse/Jamfile.jam @@ -0,0 +1 @@ +build-project src ; diff --git a/gentoobrowse/gentoobrowse-cgi b/gentoobrowse/gentoobrowse-cgi index 190d839..e9129f0 120000 --- a/gentoobrowse/gentoobrowse-cgi +++ b/gentoobrowse/gentoobrowse-cgi @@ -1 +1 @@ -src/bin/gcc-5.4.0/release/allow-ice-yes/slicer-yes/strip-on/gentoobrowse-cgi \ No newline at end of file +src/bin/gcc-5.4.0/debug/allow-ice-yes/gentoobrowse-cgi \ No newline at end of file diff --git a/gentoobrowse/src/Jamfile.jam b/gentoobrowse/src/Jamfile.jam index 96b77e5..1e070a1 100644 --- a/gentoobrowse/src/Jamfile.jam +++ b/gentoobrowse/src/Jamfile.jam @@ -1,22 +1,25 @@ import icespider ; +import testing ; +lib icespider-core ; lib icespider-common ; lib icespider-xslt : : : : ../..//libxmlpp ; lib icespider-fcgi ; lib icespider-filesessions ; +lib icespider-testing ; lib adhocutil ; lib Ice ; lib IceUtil ; lib pthread ; lib boost_system ; +lib boost_filesystem ; lib slicer ; lib slicer-json ; lib slicer-xml ; lib slicer-db ; +lib boost_unit_test_framework ; lib gentoobrowse-domain ; -lib gentoobrowse : : - gentoobrowse-api - : : +lib gentoobrowse-api : : : : /usr/share/gentoobrowse-api /usr/share/slicer/ice /usr/include/gentoobrowse-api @@ -34,7 +37,6 @@ lib icespider : : /usr/share/icespider/ice icespider-common icespider-xslt - icespider-fcgi icespider-filesessions adhocutil Ice @@ -45,15 +47,37 @@ lib icespider : : yes ; -exe gentoobrowse-cgi : - [ glob *.cpp *.ice *.json ] +lib gentoobrowse : + [ glob *.cpp *.ice *.json : test.cpp ] : release:-flto=3 release:-flto=3 yes . - icespider - gentoobrowse + gentoobrowse-api slicer-json slicer-xml + icespider + : : + icespider ; + +exe gentoobrowse-cgi : + gentoobrowse + : + gentoobrowse + icespider-fcgi + shared + ; + +path-constant me : . ; +run + test.cpp + : : : + BOOST_TEST_DYN_LINK + ROOT=\"$(me)\" + boost_filesystem + gentoobrowse + icespider-testing + boost_unit_test_framework + : gentoobrowse-test ; diff --git a/gentoobrowse/src/test.cpp b/gentoobrowse/src/test.cpp new file mode 100644 index 0000000..994a8df --- /dev/null +++ b/gentoobrowse/src/test.cpp @@ -0,0 +1,126 @@ +#define BOOST_TEST_MODULE TestGentooBrowse +#include + +#include +#include +#include +#include + +using namespace IceSpider; + +class ChromiumRequest : public TestRequest { + public: + ChromiumRequest(const Core * c, HttpMethod m, const std::string & p) : + 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"; + } + + void standardAssertions(const char * name) + { + 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) + { + char buf[BUFSIZ]; + sprintf(buf, "tidy --indent yes --wrap 0 -quiet -output %s/%s.html", + binDir.c_str(), name); + FILE * tidy = popen(buf, "w"); + while (fwrite(buf, output.readsome(buf, BUFSIZ), 1, tidy) > 0) ; + BOOST_REQUIRE_EQUAL(0, pclose(tidy)); + } +}; + +BOOST_AUTO_TEST_CASE( cd ) +{ + boost::filesystem::current_path(rootDir.parent_path()); +} + +BOOST_FIXTURE_TEST_SUITE(ta, CoreWithDefaultRouter); + +BOOST_AUTO_TEST_CASE( endpointCount ) +{ + BOOST_REQUIRE_EQUAL(22, AdHoc::PluginManager::getDefault()->getAll().size()); + BOOST_REQUIRE_EQUAL(5, routes.size()); +} + +BOOST_AUTO_TEST_CASE( home ) +{ + ChromiumRequest request(this, HttpMethod::GET, "/"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( news ) +{ + ChromiumRequest 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"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( packages ) +{ + ChromiumRequest 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"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( packages_virtual ) +{ + ChromiumRequest request(this, HttpMethod::GET, "/packages/virtual"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( packages_virtual_cron ) +{ + ChromiumRequest request(this, HttpMethod::GET, "/packages/virtual/cron"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( use ) +{ + ChromiumRequest 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"); + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_CASE( search_default ) +{ + ChromiumRequest request(this, HttpMethod::GET, "/search"); + request.qs["criteria"] = "default"; + process(&request); + request.standardAssertions(typeid(this).name()); +} + +BOOST_AUTO_TEST_SUITE_END(); + diff --git a/gentoobrowse/xslt/base.xslt b/gentoobrowse/xslt/base.xslt index 1efd644..b1474e0 100644 --- a/gentoobrowse/xslt/base.xslt +++ b/gentoobrowse/xslt/base.xslt @@ -73,9 +73,9 @@