24#ifndef UNIT_TEST_UTILS__H
25#define UNIT_TEST_UTILS__H
27#define BOOST_NO_AUTO_PTR
29#include <boost/test/unit_test.hpp>
30#include <turtle/mock.hpp>
47#if BOOST_VERSION >= 105900
48#define HAVE_EXPECTED_FAILURES
63#if BOOST_VERSION < 105900
72#define BOOST_TEST_INFO( A ) BOOST_TEST_MESSAGE( A )
82#define BOOST_TEST_CONTEXT( A ) BOOST_TEST_MESSAGE( A );
99#if BOOST_VERSION >= 105900
100#define BOOST_TEST_PRINT_NAMESPACE_OPEN \
103 namespace test_tools \
106#define BOOST_TEST_PRINT_NAMESPACE_CLOSE }}
108#define BOOST_TEST_PRINT_NAMESPACE_OPEN \
112#define BOOST_TEST_PRINT_NAMESPACE_CLOSE }
121#if BOOST_VERSION < 106400
126struct print_log_value<
std::nullptr_t>
128 inline void operator()( std::ostream& os, std::nullptr_t
const& p )
146struct print_log_value<
std::vector<T>>
148 inline void operator()( std::ostream& os, std::vector<T>
const& aVec )
150 os <<
"std::vector size " << aVec.size() <<
"[";
152 for(
const auto& i : aVec )
155 print_log_value<T>()( os, i );
167struct print_log_value<wxPoint>
169 void operator()( std::ostream& os, wxPoint
const& aVec );
178template <
typename EXP_CONT>
using EXP_OBJ =
typename EXP_CONT::value_type;
179template <
typename FOUND_CONT>
using FOUND_OBJ =
typename FOUND_CONT::value_type;
197template <
typename EXP_OBJ,
typename FOUND_OBJ>
234template <
typename EXP_CONT,
typename FOUND_CONT,
typename MATCH_PRED>
238 using EXP_OBJ =
typename EXP_CONT::value_type;
241 std::set<const EXP_OBJ*> matched;
244 for(
const auto& found : aFound )
246 for(
const auto&
expected : aExpected )
248 if( aMatchPredicate(
expected, found ) )
257 for(
const EXP_OBJ& exp : aExpected )
259 BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0,
"Expected item was not found. Expected: \n"
264 for(
const EXP_OBJ* found : matched )
266 const bool was_expected = std::find_if( aExpected.begin(), aExpected.end(),
269 return &aObj == found;
270 } ) != aExpected.end();
272 BOOST_CHECK_MESSAGE( was_expected,
"Found item was not expected. Found: \n" << *found );
283 T sorted = aCollection;
284 std::sort( sorted.begin(), sorted.end() );
286 return std::adjacent_find( sorted.begin(), sorted.end() ) == sorted.end();
297#define CHECK_WX_ASSERT( STATEMENT ) BOOST_CHECK_THROW( STATEMENT, KI_TEST::WX_ASSERT_ERROR );
299#define CHECK_WX_ASSERT( STATEMENT )
Before Boost 1.64, nullptr_t wasn't handled.
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.
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,...
typename FOUND_CONT::value_type FOUND_OBJ
typename EXP_CONT::value_type EXP_OBJ
void operator()(std::ostream &os, std::nullptr_t const &p)
void operator()(std::ostream &os, std::vector< T > const &aVec)
VECTOR3I expected(15, 30, 45)
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE