Browse Source

QA: Use modern Boost test print customisation point

Since Boost 1.64, you can use the boost_test_print_type
customisation point to provide test printing for types.
Move all test printing functions to this, and scrap the
fiddly Boost version handling to deal with older Boosts
(KiCad is now at minver 1.71).
jobs
John Beard 1 year ago
parent
commit
5b772dde13
  1. 5
      qa/qa_utils/include/qa_utils/geometry/geometry.h
  2. 102
      qa/qa_utils/include/qa_utils/wx_utils/unit_test_utils.h
  3. 10
      qa/qa_utils/wx_utils/unit_test_utils.cpp
  4. 4
      qa/tests/common/test_array_options.cpp
  5. 4
      qa/tests/common/test_coroutine.cpp
  6. 7
      qa/tests/common/wximage_test_utils.cpp
  7. 10
      qa/tests/common/wximage_test_utils.h
  8. 24
      qa/tests/eeschema/lib_field_test_utils.h
  9. 1
      qa/tests/libs/kimath/CMakeLists.txt
  10. 17
      qa/tests/libs/kimath/geometry/geom_test_utils.cpp
  11. 20
      qa/tests/libs/kimath/geometry/geom_test_utils.h
  12. 17
      qa/tests/libs/sexpr/sexpr_test_utils.h
  13. 2
      qa/tests/pcbnew/drc/drc_test_utils.cpp
  14. 9
      qa/tests/pcbnew/drc/drc_test_utils.h

5
qa/qa_utils/include/qa_utils/geometry/geometry.h

@ -33,10 +33,9 @@
/**
* Define a stream function for logging this type.
*
* TODO: convert to boost_test_print_type when Boost minver > 1.64
*/
inline std::ostream& operator<<( std::ostream& os, const BOX2I& aBox )
template <typename T>
std::ostream& boost_test_print_type( std::ostream& os, const BOX2<T>& aBox )
{
os << "BOX[ " << aBox.GetOrigin() << " + " << aBox.GetSize() << " ]";
return os;

102
qa/qa_utils/include/qa_utils/wx_utils/unit_test_utils.h

@ -38,35 +38,6 @@
#include <wx/gdicmn.h>
/*
* Boost hides the configuration point for print_log_value in different
* namespaces between < 1.59 and >= 1.59.
*
* The macros can be used to open and close the right level of namespacing
* based on the version.
*
* We could just use a conditionally defined namespace alias, but that
* doesn't work in GCC <7 (GCC bug #56480)
*
* From Boost 1.64, this should be done with boost_test_print_type,
* and these defines can be removed once all logging functions use that.
*/
#if BOOST_VERSION >= 105900
#define BOOST_TEST_PRINT_NAMESPACE_OPEN \
boost \
{ \
namespace test_tools \
{ \
namespace tt_detail
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE }}
#else
#define BOOST_TEST_PRINT_NAMESPACE_OPEN \
boost \
{ \
namespace test_tools
#define BOOST_TEST_PRINT_NAMESPACE_CLOSE }
#endif
template<class T>
struct PRINTABLE_OPT
@ -114,79 +85,62 @@ inline bool operator!=( const PRINTABLE_OPT<L>& aLhs, const PRINTABLE_OPT<R>& aR
}
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
// boost_test_print_type has to be in the same namespace as the printed type
namespace std
{
/**
* Boost print helper for generic vectors
*/
template <typename T>
struct print_log_value<std::vector<T>>
std::ostream& boost_test_print_type( std::ostream& os, std::vector<T> const& aVec )
{
inline void operator()( std::ostream& os, std::vector<T> const& aVec )
{
os << "std::vector size " << aVec.size() << " [";
os << "std::vector size " << aVec.size() << " [";
for( const auto& i : aVec )
{
os << "\n ";
print_log_value<T>()( os, i );
}
os << "]";
for( const auto& i : aVec )
{
os << "\n " << i;
}
};
os << "]";
return os;
}
/**
* Boost print helper for generic maps
*/
template <typename K, typename V>
struct print_log_value<std::map<K, V>>
std::ostream& boost_test_print_type( std::ostream& os, std::map<K, V> const& aMap )
{
inline void operator()( std::ostream& os, std::map<K, V> const& aMap )
{
os << "std::map size " << aMap.size() << " [";
os << "std::map size " << aMap.size() << " [";
for( const auto& [key, value] : aMap )
{
os << "\n ";
print_log_value<K>()( os, key );
os << " = ";
print_log_value<K>()( os, value );
}
os << "]";
for( const auto& [key, value] : aMap )
{
os << "\n " << key << " = " << value;
}
};
os << "]";
return os;
}
/**
* Boost print helper for generic pairs
*/
template <typename K, typename V>
struct print_log_value<std::pair<K, V>>
std::ostream& boost_test_print_type( std::ostream& os, std::pair<K, V> const& aPair )
{
inline void operator()( std::ostream& os, std::pair<K, V> const& aPair )
{
os << "[";
print_log_value<K>()( os, aPair.first );
os << ", ";
print_log_value<K>()( os, aPair.second );
os << "]";
}
};
os << "[" << aPair.first << ", " << aPair.second << "]";
return os;
}
} // namespace std
/**
* Boost print helper for wxPoint. Note operator<< for this type doesn't
* exist in non-DEBUG builds.
*/
template <>
struct print_log_value<wxPoint>
{
void operator()( std::ostream& os, wxPoint const& aVec );
};
}
BOOST_TEST_PRINT_NAMESPACE_CLOSE
std::ostream& boost_test_print_type( std::ostream& os, wxPoint const& aVec );
namespace KI_TEST

10
qa/qa_utils/wx_utils/unit_test_utils.cpp

@ -23,18 +23,12 @@
#include <qa_utils/wx_utils/unit_test_utils.h>
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
{
void print_log_value<wxPoint>::operator()( std::ostream& os, wxPoint const& aPt )
std::ostream& boost_test_print_type( std::ostream& os, wxPoint const& aPt )
{
os << "WXPOINT[ x=\"" << aPt.x << "\" y=\"" << aPt.y << "\" ]";
return os;
}
}
BOOST_TEST_PRINT_NAMESPACE_CLOSE
#ifndef QA_EESCHEMA_DATA_LOCATION
#define QA_EESCHEMA_DATA_LOCATION "???"

4
qa/tests/common/test_array_options.cpp

@ -36,10 +36,8 @@
/**
* Define a stream function for logging this type.
*
* TODO: convert to boost_test_print_type when Boost minver > 1.64
*/
std::ostream& operator<<( std::ostream& os, const ARRAY_OPTIONS::TRANSFORM& aObj )
std::ostream& boost_test_print_type( std::ostream& os, const ARRAY_OPTIONS::TRANSFORM& aObj )
{
os << "TRANSFORM[ " << aObj.m_offset << " r " << aObj.m_rotation.AsDegrees() << "deg"
<< " ]";

4
qa/tests/common/test_coroutine.cpp

@ -67,10 +67,8 @@ struct COROUTINE_TEST_EVENT
/**
* Define a stream function for logging this type.
*
* TODO: convert to boost_test_print_type when Boost minver > 1.64
*/
std::ostream& operator<<( std::ostream& os, const COROUTINE_TEST_EVENT& aObj )
std::ostream& boost_test_print_type( std::ostream& os, const COROUTINE_TEST_EVENT& aObj )
{
os << "COROUTINE_TEST_EVENT[ type: " << (int) aObj.m_type << ", value: " << aObj.m_value
<< " ]";

7
qa/tests/common/wximage_test_utils.cpp

@ -67,12 +67,9 @@ bool IsImagePixelOfColor( const wxImage& aImage, int aX, int aY, const KIGFX::CO
} // namespace KI_TEST
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
{
void print_log_value<wxImage>::operator()( std::ostream& os, wxImage const& aImage )
std::ostream& boost_test_print_type( std::ostream& os, wxImage const& aImage )
{
const wxSize size = aImage.GetSize();
os << "wxImage[" << size.x << "x" << size.y << "]";
return os;
}
} // namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
BOOST_TEST_PRINT_NAMESPACE_CLOSE

10
qa/tests/common/wximage_test_utils.h

@ -46,14 +46,6 @@ bool IsImagePixelOfColor( const wxImage& aImage, int aX, int aY, const KIGFX::CO
} // namespace KI_TEST
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
{
template <>
struct print_log_value<wxImage>
{
void operator()( std::ostream& os, wxImage const& aImage );
};
} // namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
BOOST_TEST_PRINT_NAMESPACE_CLOSE
std::ostream& boost_test_print_type( std::ostream& os, wxImage const& aImage );
#endif

24
qa/tests/eeschema/lib_field_test_utils.h

@ -35,27 +35,17 @@
#include <sch_field.h>
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
std::ostream& boost_test_print_type( std::ostream& os, SCH_FIELD const& f )
{
template <>
struct print_log_value<SCH_FIELD>
{
inline void operator()( std::ostream& os, SCH_FIELD const& f )
{
os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
}
};
os << "SCH_FIELD[ " << f.GetCanonicalName() << " ]";
return os;
}
template <>
struct print_log_value<std::vector<SCH_FIELD>>
std::ostream& boost_test_print_type( std::ostream& os, std::vector<SCH_FIELD> const& f )
{
inline void operator()( std::ostream& os, std::vector<SCH_FIELD> const& f )
{
os << "SCH_FIELDS[ " << f.size() << " ]";
}
};
os << "SCH_FIELDS[ " << f.size() << " ]";
return os;
}
BOOST_TEST_PRINT_NAMESPACE_CLOSE
namespace KI_TEST

1
qa/tests/libs/kimath/CMakeLists.txt

@ -27,6 +27,7 @@ set( QA_KIMATH_SRCS
test_kimath.cpp
geometry/geom_test_utils.cpp
geometry/test_chamfer.cpp
geometry/test_distribute.cpp
geometry/test_dogbone.cpp

17
qa/tests/libs/kimath/geometry/geom_test_utils.cpp

@ -0,0 +1,17 @@
#include "geom_test_utils.h"
std::ostream& boost_test_print_type( std::ostream& os, const SHAPE_LINE_CHAIN& c )
{
os << "SHAPE_LINE_CHAIN: " << c.PointCount() << " points: [\n";
for( int i = 0; i < c.PointCount(); ++i )
{
os << " " << i << ": " << c.CPoint( i ) << "\n";
}
os << "]";
return os;
}

20
qa/tests/libs/kimath/geometry/geom_test_utils.h

@ -347,26 +347,10 @@ inline bool SegmentsHaveSameEndPoints( const SEG& aSeg1, const SEG& aSeg2 )
} // namespace GEOM_TEST
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
{
template <>
struct print_log_value<SHAPE_LINE_CHAIN>
{
inline void operator()( std::ostream& os, const SHAPE_LINE_CHAIN& c )
{
os << "SHAPE_LINE_CHAIN: " << c.PointCount() << " points: [\n";
for( int i = 0; i < c.PointCount(); ++i )
{
os << " " << i << ": " << c.CPoint( i ) << "\n";
}
// Stream printing for geometry types
os << "]";
}
};
}
BOOST_TEST_PRINT_NAMESPACE_CLOSE
std::ostream& boost_test_print_type( std::ostream& os, const SHAPE_LINE_CHAIN& c );
#endif // GEOM_TEST_UTILS_H

17
qa/tests/libs/sexpr/sexpr_test_utils.h

@ -224,21 +224,18 @@ inline bool SexprConvertsToString( const SEXPR::SEXPR& aSexpr, const std::string
} // namespace KI_TEST
namespace BOOST_TEST_PRINT_NAMESPACE_OPEN
{
namespace SEXPR
{
/**
* Boost print helper for SEXPR objects
*/
template <>
struct print_log_value<SEXPR::SEXPR>
inline std::ostream& boost_test_print_type( std::ostream& os, const SEXPR& aSexpr )
{
inline void operator()( std::ostream& os, const SEXPR::SEXPR& aSexpr )
{
os << "SEXPR [ " << KI_TEST::GetSexprDebugType( aSexpr ) << " ]\n " << aSexpr.AsString();
}
};
os << "SEXPR [ " << KI_TEST::GetSexprDebugType( aSexpr ) << " ]\n " << aSexpr.AsString();
return os;
}
BOOST_TEST_PRINT_NAMESPACE_CLOSE
} // namespace SEXPR
#endif // TEST_SEXPR_TEST_UTILS__H

2
qa/tests/pcbnew/drc/drc_test_utils.cpp

@ -24,7 +24,7 @@
#include "drc_test_utils.h"
std::ostream& operator<<( std::ostream& os, const PCB_MARKER& aMarker )
std::ostream& boost_test_print_type( std::ostream& os, const PCB_MARKER& aMarker )
{
const auto& reporter = aMarker.GetRCItem();
os << "PCB_MARKER[\n";

9
qa/tests/pcbnew/drc/drc_test_utils.h

@ -37,15 +37,8 @@
* Define a stream function for logging #PCB_MARKER test assertions.
*
* This has to be in the same namespace as #PCB_MARKER
*
* Note: this assumes there is not a operator<< for this type in the main
* Pcbnew library. If one is introduced there, this one should be removed.
*
* TODO: convert to boost_test_print_type when Boost minver > 1.64. This
* will keep testing logging and application-level operator<< implementations
* separate, as they should be.
*/
std::ostream& operator<<( std::ostream& os, const PCB_MARKER& aMarker );
std::ostream& boost_test_print_type( std::ostream& os, const PCB_MARKER& aMarker );
namespace KI_TEST

Loading…
Cancel
Save