From c6d486fe2128eb72d445de93ca31b5ed4b747b0e Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 28 Oct 2020 15:53:01 -0700 Subject: [PATCH] Option: Test Coverage Add unit tests for `auxiliary::Option` --- test/AuxiliaryTest.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/AuxiliaryTest.cpp b/test/AuxiliaryTest.cpp index dfc41a9b01..8a18fe1e39 100644 --- a/test/AuxiliaryTest.cpp +++ b/test/AuxiliaryTest.cpp @@ -9,6 +9,7 @@ #include "openPMD/backend/Container.hpp" #include "openPMD/auxiliary/DerefDynamicCast.hpp" #include "openPMD/auxiliary/Filesystem.hpp" +#include "openPMD/auxiliary/Option.hpp" #include "openPMD/auxiliary/StringManip.hpp" #include "openPMD/auxiliary/Variant.hpp" #include "openPMD/IO/AbstractIOHandler.hpp" @@ -43,6 +44,33 @@ struct TestHelper : public Attributable } // openPMD +TEST_CASE( "optional", "[auxiliary]" ) { + using namespace auxiliary; + + Option opt; + + REQUIRE_THROWS(opt.get()); + REQUIRE_THROWS(opt.get() = 42); + REQUIRE(!opt); + REQUIRE(!opt.has_value()); + + opt = 43; + REQUIRE(opt); + REQUIRE(opt.has_value()); + REQUIRE(opt.get() == 43); + + Option opt2{ opt }; + REQUIRE(opt2); + REQUIRE(opt2.has_value()); + REQUIRE(opt2.get() == 43); + + Option opt3 = makeOption( 3 ); + REQUIRE(opt3); + REQUIRE(opt3.has_value()); + REQUIRE(opt3.get() == 3); +} + + TEST_CASE( "deref_cast_test", "[auxiliary]" ) { using namespace auxiliary;