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>
49#if BOOST_VERSION >= 105900
50#define HAVE_EXPECTED_FAILURES
65#if BOOST_VERSION < 105900
74#define BOOST_TEST_INFO( A ) BOOST_TEST_MESSAGE( A )
84#define BOOST_TEST_CONTEXT( A ) BOOST_TEST_MESSAGE( A );
101#if BOOST_VERSION >= 105900
102#define BOOST_TEST_PRINT_NAMESPACE_OPEN \
105 namespace test_tools \
108#define BOOST_TEST_PRINT_NAMESPACE_CLOSE }}
110#define BOOST_TEST_PRINT_NAMESPACE_OPEN \
114#define BOOST_TEST_PRINT_NAMESPACE_CLOSE }
123#if BOOST_VERSION < 106400
128struct print_log_value<
std::nullptr_t>
130 inline void operator()( std::ostream& os, std::nullptr_t
const& p )
154#define KI_CHECK_OPT_EQUAL( lhs, rhs ) \
155 BOOST_CHECK_EQUAL( PRINTABLE_OPT( lhs ), PRINTABLE_OPT( rhs ) )
161 if( aOptional.
m_Opt.has_value() )
162 aOs << *aOptional.
m_Opt;
170template <
class L,
class R>
173 if( !aLhs.
m_Opt.has_value() && !aRhs.
m_Opt.has_value() )
180template <
class L,
class R>
183 return !( aLhs == aRhs );
194struct print_log_value<
std::vector<T>>
196 inline void operator()( std::ostream& os, std::vector<T>
const& aVec )
198 os <<
"std::vector size " << aVec.size() <<
" [";
200 for(
const auto& i : aVec )
203 print_log_value<T>()( os, i );
213template <
typename K,
typename V>
214struct print_log_value<
std::map<K, V>>
216 inline void operator()( std::ostream& os, std::map<K, V>
const& aMap )
218 os <<
"std::map size " << aMap.size() <<
" [";
220 for(
const auto& [key, value] : aMap )
223 print_log_value<K>()( os, key );
225 print_log_value<K>()( os, value );
235template <
typename K,
typename V>
236struct print_log_value<
std::pair<K, V>>
238 inline void operator()( std::ostream& os, std::pair<K, V>
const& aPair )
241 print_log_value<K>()( os, aPair.first );
243 print_log_value<K>()( os, aPair.second );
253struct print_log_value<wxPoint>
255 void operator()( std::ostream& os, wxPoint
const& aVec );
265template <
typename EXP_CONT>
using EXP_OBJ =
typename EXP_CONT::value_type;
266template <
typename FOUND_CONT>
using FOUND_OBJ =
typename FOUND_CONT::value_type;
284template <
typename EXP_OBJ,
typename FOUND_OBJ>
321template <
typename EXP_CONT,
typename FOUND_CONT,
typename MATCH_PRED>
325 using EXP_OBJ =
typename EXP_CONT::value_type;
328 std::set<const EXP_OBJ*> matched;
331 for(
const auto& found : aFound )
333 for(
const auto&
expected : aExpected )
335 if( aMatchPredicate(
expected, found ) )
344 for(
const EXP_OBJ& exp : aExpected )
346 BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0,
"Expected item was not found. Expected: \n"
351 for(
const EXP_OBJ* found : matched )
353 const bool was_expected = std::find_if( aExpected.begin(), aExpected.end(),
356 return &aObj == found;
357 } ) != aExpected.end();
359 BOOST_CHECK_MESSAGE( was_expected,
"Found item was not expected. Found: \n" << *found );
370 T sorted = aCollection;
371 std::sort( sorted.begin(), sorted.end() );
373 return std::adjacent_find( sorted.begin(), sorted.end() ) == sorted.end();
384#define CHECK_WX_ASSERT( STATEMENT ) BOOST_CHECK_THROW( STATEMENT, KI_TEST::WX_ASSERT_ERROR );
386#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.
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
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::map< K, V > const &aMap)
void operator()(std::ostream &os, std::nullptr_t const &p)
void operator()(std::ostream &os, std::pair< K, V > const &aPair)
void operator()(std::ostream &os, std::vector< T > const &aVec)
PRINTABLE_OPT(const T &aVal)
PRINTABLE_OPT(const std::optional< T > &aOpt)
VECTOR3I expected(15, 30, 45)
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE
bool operator!=(const PRINTABLE_OPT< L > &aLhs, const PRINTABLE_OPT< R > &aRhs)
bool operator==(const PRINTABLE_OPT< L > &aLhs, const PRINTABLE_OPT< R > &aRhs)
std::ostream & operator<<(std::ostream &aOs, const PRINTABLE_OPT< T > &aOptional)