From cc387b9da6b3e884e8e69296293bd30413247a32 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 5 Aug 2023 16:24:58 +0100 Subject: Modernize XML specific tests --- slicer/xml/testSpecifics.cpp | 81 +++++++++++++++++++++++++++----------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/slicer/xml/testSpecifics.cpp b/slicer/xml/testSpecifics.cpp index 24edf78..6f94ed4 100644 --- a/slicer/xml/testSpecifics.cpp +++ b/slicer/xml/testSpecifics.cpp @@ -1,4 +1,5 @@ #define BOOST_TEST_MODULE xml_specifics +#include #include #include "serializer.h" @@ -20,47 +21,63 @@ // IWYU pragma: no_forward_declare Slicer::BadBooleanValue // IWYU pragma: no_forward_declare Slicer::XmlDocumentDeserializer -template -T -BoostThrowWrapperHelper(P &&... p) +template +const auto BoostThrowWrapperHelper + = Slicer::DeserializeAny; + +template using data = std::tuple; +BOOST_FIXTURE_TEST_SUITE(doc, xmlpp::DomParser) + +BOOST_DATA_TEST_CASE(good_boolean_values, + boost::unit_test::data::make>({ + {"true", true}, + {"false", false}, + }), + in, exp) +{ + parse_memory(in); + BOOST_CHECK_EQUAL(exp, BoostThrowWrapperHelper(get_document())); +} + +BOOST_DATA_TEST_CASE(bad_boolean_values, + boost::unit_test::data::make({ + "nonsense", + " ", + "", + }), + in) { - return Slicer::DeserializeAny(std::forward

(p)...); + parse_memory(in); + BOOST_CHECK_THROW(BoostThrowWrapperHelper(get_document()), Slicer::BadBooleanValue); } -BOOST_AUTO_TEST_CASE(boolean_values) +BOOST_DATA_TEST_CASE(good_integer_values, + boost::unit_test::data::make>({ + {"13", 13}, + {"84", 84}, + {"0", 0}, + {"-4", -4}, + }), + in, exp) { - xmlpp::DomParser doc; - doc.parse_memory("true"); - BOOST_REQUIRE_EQUAL(true, BoostThrowWrapperHelper(doc.get_document())); - doc.parse_memory("false"); - BOOST_REQUIRE_EQUAL(false, BoostThrowWrapperHelper(doc.get_document())); - doc.parse_memory("nonsense"); - BOOST_REQUIRE_THROW(BoostThrowWrapperHelper(doc.get_document()), Slicer::BadBooleanValue); - doc.parse_memory(" "); - BOOST_REQUIRE_THROW(BoostThrowWrapperHelper(doc.get_document()), Slicer::BadBooleanValue); - doc.parse_memory(""); - BOOST_REQUIRE_THROW(BoostThrowWrapperHelper(doc.get_document()), Slicer::BadBooleanValue); + parse_memory(in); + BOOST_CHECK_EQUAL(exp, BoostThrowWrapperHelper(get_document())); } -BOOST_AUTO_TEST_CASE(int_values) +BOOST_DATA_TEST_CASE(bad_integer_values, + boost::unit_test::data::make({ + " ", + "notanint", + "", + }), + in) { - xmlpp::DomParser doc; - doc.parse_memory("13"); - BOOST_REQUIRE_EQUAL(13, BoostThrowWrapperHelper(doc.get_document())); - doc.parse_memory("84"); - BOOST_REQUIRE_EQUAL(84, BoostThrowWrapperHelper(doc.get_document())); - doc.parse_memory("0"); - BOOST_REQUIRE_EQUAL(0, BoostThrowWrapperHelper(doc.get_document())); - doc.parse_memory("-4"); - BOOST_REQUIRE_EQUAL(-4, BoostThrowWrapperHelper(doc.get_document())); - doc.parse_memory(" "); - BOOST_REQUIRE_THROW(BoostThrowWrapperHelper(doc.get_document()), Slicer::BadNumericValue); - doc.parse_memory("notanint"); - BOOST_REQUIRE_THROW(BoostThrowWrapperHelper(doc.get_document()), Slicer::BadNumericValue); - doc.parse_memory(""); - BOOST_REQUIRE_THROW(BoostThrowWrapperHelper(doc.get_document()), Slicer::BadNumericValue); + parse_memory(in); + BOOST_CHECK_THROW(BoostThrowWrapperHelper(get_document()), Slicer::BadNumericValue); } +BOOST_AUTO_TEST_SUITE_END() + BOOST_AUTO_TEST_CASE(factories) { BOOST_REQUIRE(Slicer::FileSerializerFactory::createNew(".xml", "/some.xml")); -- cgit v1.2.3