Skip to content

Commit

Permalink
Added a test for static_variant visitor call depth
Browse files Browse the repository at this point in the history
  • Loading branch information
pmconrad committed Oct 9, 2018
1 parent 70dbcc1 commit 72a8168
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/stacktrace_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#include <boost/test/unit_test.hpp>

#include <boost/algorithm/string.hpp>

#include <signal.h>

#include <fc/stacktrace.hpp>
#include <fc/static_variant.hpp>
#include <fc/thread/thread.hpp>

#include <iostream>

BOOST_AUTO_TEST_SUITE(fc_stacktrace)

BOOST_AUTO_TEST_CASE(stacktrace_test)
Expand Down Expand Up @@ -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<typename T>
std::string operator()( T i )const { return "Unexpected!"; }
};

BOOST_AUTO_TEST_CASE(static_variant_depth_test)
{
int64_t i = 1;
fc::static_variant<uint8_t,uint16_t,uint32_t,uint64_t,int8_t,int16_t,int32_t,int64_t> test(i);

std::string stacktrace = test.visit( _svdt_visitor() );
//std::cerr << stacktrace << "\n";
std::vector<std::string> 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

This comment has been minimized.

Copy link
@jmjatlanta

jmjatlanta Nov 10, 2018

@pmconrad this is failing for me, as count == 3. I have not looked too deeply to see what the value should be. I am compiling with boost 1.67 / Ubuntu 18.04

This comment has been minimized.

Copy link
@pmconrad

pmconrad Nov 14, 2018

Author

Can you remove the comments on line 70 and check what the stacktrace looks like?
I get count=0 because where i'd expect the _svdt_visitor lines it only gives me hex numbers.

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)
{
Expand Down

0 comments on commit 72a8168

Please sign in to comment.