Fix unit test structure, CPP17 check, relates #478, #448

This commit is contained in:
Shane Grant 2018-03-17 15:43:38 -07:00
parent 3d4fea5bdb
commit 487c3375e1
3 changed files with 12 additions and 75 deletions

View File

@ -24,8 +24,8 @@
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_TEST_OPTIONAL_H_
#define CEREAL_TEST_OPTIONAL_H_
#ifndef CEREAL_TEST_CPP17_OPTIONAL_H_
#define CEREAL_TEST_CPP17_OPTIONAL_H_
#include "../common.hpp"
#ifdef CEREAL_HAS_CPP17
@ -89,4 +89,4 @@ void test_std_optional()
}
#endif // CEREAL_HAS_CPP17
#endif // CEREAL_TEST_OPTIONAL_H_
#endif // CEREAL_TEST_CPP17_OPTIONAL_H_

View File

@ -26,49 +26,9 @@
*/
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "variant.hpp"
#include "../common.hpp"
#if __cplusplus >= 201703L
#include <cereal/types/variant.hpp>
template <class IArchive, class OArchive> inline
void test_std_variant()
{
std::random_device rd;
std::mt19937 gen(rd());
std::variant<int, double, std::string> o_bv1 = random_value<int>(gen);
std::variant<int, double, std::string> o_bv2 = random_value<double>(gen);
std::variant<int, double, std::string> o_bv3 = random_basic_string<char>(gen);
std::ostringstream os;
{
OArchive oar(os);
oar(o_bv1);
oar(o_bv2);
oar(o_bv3);
}
decltype(o_bv1) i_bv1;
decltype(o_bv2) i_bv2;
decltype(o_bv3) i_bv3;
std::istringstream is(os.str());
{
IArchive iar(is);
iar(i_bv1);
iar(i_bv2);
iar(i_bv3);
}
CHECK_EQ( std::get<int>(i_bv1), std::get<int>(o_bv1) );
CHECK_EQ( std::get<double>(i_bv2), doctest::Approx(std::get<double>(o_bv2)).epsilon(1e-5) );
CHECK_EQ( std::get<std::string>(i_bv3), std::get<std::string>(o_bv3) );
}
#ifdef CEREAL_HAS_CPP17
TEST_SUITE("std_variant");
@ -94,4 +54,4 @@ TEST_CASE("json_std_variant")
TEST_SUITE_END();
#endif // is c++17
#endif // CEREAL_HAS_CPP17

View File

@ -25,11 +25,11 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#ifndef CEREAL_TEST_CPP17_VARIANT_H_
#define CEREAL_TEST_CPP17_VARIANT_H_
#include "../common.hpp"
#include "common.hpp"
#if __cplusplus >= 201703L
#ifdef CEREAL_HAS_CPP17
#include <cereal/types/variant.hpp>
@ -70,28 +70,5 @@ void test_std_variant()
CHECK_EQ( std::get<std::string>(i_bv3), std::get<std::string>(o_bv3) );
}
TEST_SUITE("std_variant");
TEST_CASE("binary_std_variant")
{
test_std_variant<cereal::BinaryInputArchive, cereal::BinaryOutputArchive>();
}
TEST_CASE("portable_binary_std_variant")
{
test_std_variant<cereal::PortableBinaryInputArchive, cereal::PortableBinaryOutputArchive>();
}
TEST_CASE("xml_std_variant")
{
test_std_variant<cereal::XMLInputArchive, cereal::XMLOutputArchive>();
}
TEST_CASE("json_std_variant")
{
test_std_variant<cereal::JSONInputArchive, cereal::JSONOutputArchive>();
}
TEST_SUITE_END();
#endif // is c++17
#endif // CEREAL_HAS_CPP17
#endif // CEREAL_TEST_CPP17_VARIANT_H_