forked from steemit/fc
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a test for static_variant visitor call depth
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pmconrad
Author
|
||
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) | ||
{ | ||
|
@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