From 72a8168b2b7370ef7dfc9c1180b518cd127e489d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 9 Oct 2018 16:17:34 +0200 Subject: [PATCH] Added a test for static_variant visitor call depth --- tests/stacktrace_test.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/stacktrace_test.cpp b/tests/stacktrace_test.cpp index baafa7669..bc710a5c1 100644 --- a/tests/stacktrace_test.cpp +++ b/tests/stacktrace_test.cpp @@ -1,9 +1,15 @@ #include +#include + #include + #include +#include #include +#include + BOOST_AUTO_TEST_SUITE(fc_stacktrace) BOOST_AUTO_TEST_CASE(stacktrace_test) @@ -40,6 +46,38 @@ BOOST_AUTO_TEST_CASE(threaded_stacktrace_test) #endif } +#if BOOST_VERSION / 100000 >= 1 && ((BOOST_VERSION / 100) % 1000) >= 65 +class _svdt_visitor +{ +public: + typedef std::string result_type; + std::string operator()( int64_t i )const + { + std::stringstream ss; + fc::print_stacktrace(ss); + return ss.str(); + } + template + std::string operator()( T i )const { return "Unexpected!"; } +}; + +BOOST_AUTO_TEST_CASE(static_variant_depth_test) +{ + int64_t i = 1; + fc::static_variant test(i); + + std::string stacktrace = test.visit( _svdt_visitor() ); + //std::cerr << stacktrace << "\n"; + std::vector lines; + boost::split( lines, stacktrace, boost::is_any_of("\n") ); + int count = 0; + for( const auto& line : lines ) + if( line.find("_svdt_visitor") != std::string::npos ) count++; + BOOST_CHECK_LT( 3, count ); // test.visit(), static_variant::visit, function object, visitor + BOOST_CHECK_GT( 8, count ); // some is implementation-dependent +} +#endif + /* this test causes a segfault on purpose to test the event handler BOOST_AUTO_TEST_CASE(cause_segfault) {