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>
55#define KI_CHECK_OPT_EQUAL( lhs, rhs ) \
56 BOOST_CHECK_EQUAL( PRINTABLE_OPT( lhs ), PRINTABLE_OPT( rhs ) )
62 if( aOptional.
m_Opt.has_value() )
63 aOs << *aOptional.
m_Opt;
71template <
class L,
class R>
74 if( !aLhs.
m_Opt.has_value() && !aRhs.
m_Opt.has_value() )
81template <
class L,
class R>
84 return !( aLhs == aRhs );
98 os <<
"std::vector size " << aVec.size() <<
" [";
100 for(
const auto& i : aVec )
112template <
typename K,
typename V>
115 os <<
"std::map size " << aMap.size() <<
" [";
117 for(
const auto& [key, value] : aMap )
119 os <<
"\n " << key <<
" = " << value;
129template <
typename K,
typename V>
132 os <<
"[" << aPair.first <<
", " << aPair.second <<
"]";
149template <
typename EXP_CONT>
using EXP_OBJ =
typename EXP_CONT::value_type;
150template <
typename FOUND_CONT>
using FOUND_OBJ =
typename FOUND_CONT::value_type;
168template <
typename EXP_OBJ,
typename FOUND_OBJ>
205template <
typename EXP_CONT,
typename FOUND_CONT,
typename MATCH_PRED>
209 using EXP_OBJ =
typename EXP_CONT::value_type;
212 std::set<const EXP_OBJ*> matched;
215 for(
const auto& found : aFound )
217 for(
const auto&
expected : aExpected )
219 if( aMatchPredicate(
expected, found ) )
228 for(
const EXP_OBJ& exp : aExpected )
230 BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0,
"Expected item was not found. Expected: \n"
235 for(
const EXP_OBJ* found : matched )
237 const bool was_expected = std::find_if( aExpected.begin(), aExpected.end(),
240 return &aObj == found;
241 } ) != aExpected.end();
243 BOOST_CHECK_MESSAGE( was_expected,
"Found item was not expected. Found: \n" << *found );
254 T sorted = aCollection;
255 std::sort( sorted.begin(), sorted.end() );
257 return std::adjacent_find( sorted.begin(), sorted.end() ) == sorted.end();
268#define CHECK_WX_ASSERT( STATEMENT ) BOOST_CHECK_THROW( STATEMENT, KI_TEST::WX_ASSERT_ERROR );
270#define CHECK_WX_ASSERT( STATEMENT )
std::ostream & operator<<(std::ostream &aStream, const EDA_TEXT &aText)
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
std::ostream & boost_test_print_type(std::ostream &os, std::vector< T > const &aVec)
Boost print helper for generic vectors.
PRINTABLE_OPT(const T &aVal)
PRINTABLE_OPT(const std::optional< T > &aOpt)
VECTOR3I expected(15, 30, 45)
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 & boost_test_print_type(std::ostream &os, wxPoint const &aVec)
Boost print helper for wxPoint.