24 #ifndef UNIT_TEST_UTILS__H 25 #define UNIT_TEST_UTILS__H 27 #include <boost/test/unit_test.hpp> 34 #include <wx/gdicmn.h> 44 #if BOOST_VERSION >= 105900 45 #define HAVE_EXPECTED_FAILURES 60 #if BOOST_VERSION < 105900 69 #define BOOST_TEST_INFO( A ) BOOST_TEST_MESSAGE( A ) 79 #define BOOST_TEST_CONTEXT( A ) BOOST_TEST_MESSAGE( A ); 96 #if BOOST_VERSION >= 105900 97 #define BOOST_TEST_PRINT_NAMESPACE_OPEN \ 100 namespace test_tools \ 103 #define BOOST_TEST_PRINT_NAMESPACE_CLOSE }} 105 #define BOOST_TEST_PRINT_NAMESPACE_OPEN \ 109 #define BOOST_TEST_PRINT_NAMESPACE_CLOSE } 118 #if BOOST_VERSION < 106400 123 struct print_log_value<
std::nullptr_t>
125 inline void operator()( std::ostream& os, std::nullptr_t
const& p )
142 template <
typename T>
143 struct print_log_value<
std::vector<T>>
145 inline void operator()( std::ostream& os, std::vector<T>
const& aVec )
147 os <<
"std::vector size " << aVec.size() <<
"[";
149 for(
const auto& i : aVec )
152 print_log_value<T>()( os, i );
164 struct print_log_value<wxPoint>
166 void operator()( std::ostream& os, wxPoint
const& aVec );
175 template <
typename EXP_CONT>
using EXP_OBJ =
typename EXP_CONT::value_type;
176 template <
typename FOUND_CONT>
using FOUND_OBJ =
typename FOUND_CONT::value_type;
194 template <
typename EXP_OBJ,
typename FOUND_OBJ>
231 template <
typename EXP_CONT,
typename FOUND_CONT,
typename MATCH_PRED>
233 const EXP_CONT& aExpected,
const FOUND_CONT& aFound,
MATCH_PRED aMatchPredicate )
235 using EXP_OBJ =
typename EXP_CONT::value_type;
238 std::set<const EXP_OBJ*> matched;
241 for(
const auto& found : aFound )
243 for(
const auto& expected : aExpected )
245 if( aMatchPredicate( expected, found ) )
247 matched.insert( &expected );
254 for(
const EXP_OBJ& exp : aExpected )
256 BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0,
"Expected item was not found. Expected: \n" 261 for(
const EXP_OBJ* found : matched )
263 const bool was_expected =
264 std::find_if( aExpected.begin(), aExpected.end(),
265 [found](
const EXP_OBJ& aObj ) {
return &aObj == found; } )
268 BOOST_CHECK_MESSAGE( was_expected,
"Found item was not expected. Found: \n" << *found );
276 template <
typename T>
279 T sorted = aCollection;
280 std::sort( sorted.begin(), sorted.end() );
282 return std::adjacent_find( sorted.begin(), sorted.end() ) == sorted.end();
293 #define CHECK_WX_ASSERT( STATEMENT ) BOOST_CHECK_THROW( STATEMENT, KI_TEST::WX_ASSERT_ERROR ); 295 #define CHECK_WX_ASSERT( STATEMENT ) 300 #endif // UNIT_TEST_UTILS__H Before Boost 1.64, nullptr_t wasn't handled.
void operator()(std::ostream &os, std::nullptr_t const &p)
typename FOUND_CONT::value_type FOUND_OBJ
std::function< bool(const EXP_OBJ &, const FOUND_OBJ &)> MATCH_PRED
A match predicate: check that a "found" object is equivalent to or represents an "expected" object,...
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE
void CheckUnorderedMatches(const EXP_CONT &aExpected, const FOUND_CONT &aFound, MATCH_PRED aMatchPredicate)
Check that a container of "found" objects matches a container of "expected" objects.
bool CollectionHasNoDuplicates(const T &aCollection)
Predicate to check a collection has no duplicate elements.
void operator()(std::ostream &os, std::vector< T > const &aVec)
typename EXP_CONT::value_type EXP_OBJ