From 06a5b6fe71abac44286adf9c9f439ad5a2e3a519 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 31 Dec 2022 13:45:31 +0100 Subject: Added tests --- tests/Makefile | 1 + tests/test-environment.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test-webserver.cpp | 38 +++++++++--------------------------- 3 files changed, 58 insertions(+), 29 deletions(-) create mode 100644 tests/test-environment.cpp (limited to 'tests') diff --git a/tests/Makefile b/tests/Makefile index 1785e09..5903b52 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -20,6 +20,7 @@ LIBS=\ LDFLAGS+=-pie -L../libcommon TESTSRC=\ + test-environment.cpp \ test-webserver.cpp \ $(PROGSRC) diff --git a/tests/test-environment.cpp b/tests/test-environment.cpp new file mode 100644 index 0000000..da8e4e0 --- /dev/null +++ b/tests/test-environment.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#include +#include + +#include +#include + +using namespace std::string_literals; +namespace pt = boost::property_tree; + +// test ptree construction and xml serialization +BOOST_AUTO_TEST_CASE(property_tree_put) +{ + pt::ptree p; + pt::ptree list; + + pt::ptree entry; + + entry.put_value("name1.txt"); + entry.put(".type", "file1"); + + list.push_back(pt::ptree::value_type("listentry", entry)); + + entry.put_value("name2.txt"); + entry.put(".type", "file2"); + + list.push_back(pt::ptree::value_type("listentry", entry)); + + p.push_back(pt::ptree::value_type("list", list)); + + std::stringstream ss; + + pt::xml_parser::write_xml(ss, p /*, pt::xml_parser::xml_writer_make_settings(' ', 1)*/); + + BOOST_CHECK_EQUAL(ss.str(), "\nname1.txtname2.txt"); +} + +// test std::stoul for negative numbers +BOOST_AUTO_TEST_CASE(string_stoul) +{ + unsigned long l = std::stoul("-1"); + + BOOST_CHECK_EQUAL(l, std::numeric_limits::max()); +} diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp index 7683b93..1668c60 100644 --- a/tests/test-webserver.cpp +++ b/tests/test-webserver.cpp @@ -1,6 +1,8 @@ +// Main unit test compilation unit +// boost mandates that exactly one compilation unit contains the following two lines: #define BOOST_TEST_MODULE webserver_test - #include + #include #include #include @@ -14,35 +16,13 @@ using namespace std::string_literals; namespace pt = boost::property_tree; -BOOST_AUTO_TEST_CASE(property_tree_put) +class Fixture { - pt::ptree p; - pt::ptree list; - - pt::ptree entry; - - entry.put_value("name1.txt"); - entry.put(".type", "file1"); - - list.push_back(pt::ptree::value_type("listentry", entry)); - - entry.put_value("name2.txt"); - entry.put(".type", "file2"); - - list.push_back(pt::ptree::value_type("listentry", entry)); - - p.push_back(pt::ptree::value_type("list", list)); +public: + Fixture(){} + ~Fixture(){} +}; - std::stringstream ss; - - pt::xml_parser::write_xml(ss, p /*, pt::xml_parser::xml_writer_make_settings(' ', 1)*/); - - BOOST_CHECK_EQUAL(ss.str(), "\nname1.txtname2.txt"); -} - -BOOST_AUTO_TEST_CASE(string_stoul) +BOOST_FIXTURE_TEST_CASE(http_download, Fixture) { - unsigned long l = std::stoul("-1"); - - BOOST_CHECK_EQUAL(l, std::numeric_limits::max()); } -- cgit v1.2.3