KiCad PCB EDA Suite
KI_TEST Namespace Reference

Classes

class  BOARD_DUMPER
 A helper that contains logic to assist in dumping boards to disk depending on some environment variables. More...
 
class  COMBINED_UTILITY
 Class that handles delegation of command lines to one of a number of "sub-utilities". More...
 
struct  CommonTestData
 Common data for some of the SHAPE_POLY_SET tests: More...
 
struct  UTILITY_PROGRAM
 Description of a "utility program", which is a program that takes some command line and does "something". More...
 
class  WX_ASSERT_ERROR
 An exception class to represent a WX assertion. More...
 

Typedefs

template<typename EXP_CONT >
using EXP_OBJ = typename EXP_CONT::value_type
 
template<typename FOUND_CONT >
using FOUND_OBJ = typename FOUND_CONT::value_type
 
template<typename EXP_OBJ , typename FOUND_OBJ >
using MATCH_PRED = std::function< bool(const EXP_OBJ &, const FOUND_OBJ &)>
 A match predicate: check that a "found" object is equivalent to or represents an "expected" object, perhaps of a different type. More...
 

Enumerations

enum  RET_CODES { OK = 0, BAD_CMDLINE = 1, UNKNOWN_TOOL = 2, TOOL_SPECIFIC = 10 }
 Return codes for tools. More...
 

Functions

bool IsColorNear (const KIGFX::COLOR4D &aCol, const KIGFX::COLOR4D aOther, double aTol)
 Checks if a COLOR4D is close enough to another. More...
 
bool IsColorNearHex (const KIGFX::COLOR4D &aCol, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
 Checks if a COLOR4D is close enough to a given RGB char value. More...
 
bool IsImagePixelOfColor (const wxImage &aImage, int aX, int aY, const KIGFX::COLOR4D &aColor)
 Predicate to check an image pixel matches color and alpha. More...
 
wxFileName GetEeschemaTestDataDir ()
 Get the configured location of Eeschema test data. More...
 
bool FieldNameIdMatches (const LIB_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
 Predicate to check a field name is as expected. More...
 
bool AreDefaultFieldsCorrect (const LIB_FIELDS &aFields)
 Predicate to check that the mandatory fields in a LIB_FIELDS object look sensible. More...
 
bool IsUUID (const std::string &aStr)
 Check if the string between the iterators looks like a UUID. More...
 
bool IsUUIDPathWithLevels (const std::string &aStr, unsigned aLevels)
 Predicate to check a string is a UUID path format. More...
 
SEXPR::SEXPR_TYPE getType (const SEXPR::SEXPR &aSexpr)
 Get the type of the s-expression. More...
 
std::string getDebugType (SEXPR::SEXPR_TYPE aType)
 Get a debug-friendly string for a given s-expr type. More...
 
std::string GetSexprDebugType (const SEXPR::SEXPR &aSexpr)
 
bool IsSexprOfType (const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)
 
template<typename VAL_T >
bool IsSexprValueEqual (const VAL_T &aGot, const VAL_T &aExpected)
 Predicate to check two s-expr values (of the same type) are equal. More...
 
bool SexprIsSymbol (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a symbol? More...
 
bool SexprIsSymbolWithValue (const SEXPR::SEXPR &aSexpr, const std::string &aVal)
 Test predicate: is the s-expression a symbol with the given value? More...
 
bool SexprIsString (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a string? More...
 
bool SexprIsStringWithValue (const SEXPR::SEXPR &aSexpr, const std::string &aVal)
 Test predicate: is the s-expression a string with the given value? More...
 
bool SexprIsInteger (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression an integer? More...
 
bool SexprIsIntegerWithValue (const SEXPR::SEXPR &aSexpr, std::int64_t aVal)
 Test predicate: is the s-expression an integer with the given value? More...
 
bool SexprIsDouble (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a double? More...
 
bool SexprIsDoubleWithValue (const SEXPR::SEXPR &aSexpr, double aVal)
 Test predicate: is the s-expression a double with the given value? More...
 
bool SexprIsList (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a double? More...
 
bool SexprIsListOfLength (const SEXPR::SEXPR &aSexpr, size_t aExpectedLength)
 Test predicate: is the s-expression a list with the given length? More...
 
bool SexprConvertsToString (const SEXPR::SEXPR &aSexpr, const std::string &aExpStr)
 Predicate to check an SEXPR object converts to the expected string. More...
 
bool IsDrcMarkerOfType (const MARKER_PCB &aMarker, int aErrorCode)
 Predicate for testing the type of a DRC marker. More...
 
void DrawSegment (MODULE &aMod, const SEG &aSeg, int aWidth, PCB_LAYER_ID aLayer)
 Draw a segment in the given module. More...
 
void DrawPolyline (MODULE &aMod, const std::vector< VECTOR2I > &aPts, int aWidth, PCB_LAYER_ID aLayer)
 Draw a polyline - a set of linked segments. More...
 
void DrawArc (MODULE &aMod, const VECTOR2I &aCentre, const VECTOR2I &aStart, double aAngle, int aWidth, PCB_LAYER_ID aLayer)
 Draw an arc on a module. More...
 
void DrawRect (MODULE &aMod, const VECTOR2I &aPos, const VECTOR2I &aSize, int aRadius, int aWidth, PCB_LAYER_ID aLayer)
 Draw a rectangle on a module. More...
 
void DumpBoardToFile (BOARD &aBoard, const std::string &aFilename)
 Utility function to simply write a Board out to a file. More...
 
std::unique_ptr< BOARD_ITEMReadBoardItemFromFile (const std::string &aFilename)
 
std::unique_ptr< BOARD_ITEMReadBoardItemFromStream (std::istream &aStream)
 Utility function to read a BOARD_ITEM (probably a MODULE or a BOARD) from a file. More...
 
std::unique_ptr< BOARDReadBoardFromFileOrStream (const std::string &aFilename, std::istream &aFallback=std::cin)
 Read a board from a file, or another stream, as appropriate. More...
 
template<typename ITEM >
std::unique_ptr< ITEM > ReadItemFromStream (std::istream &aStream)
 Read a specific kind of BOARD_ITEM from a stream. More...
 
SHAPE_LINE_CHAIN BuildRectChain (const VECTOR2I &aSize, const VECTOR2I &aCentre={ 0, 0 })
 Builds a rectangular SHAPE_LINE_CHAIN of a certain size at a certain centre. More...
 
SHAPE_LINE_CHAIN BuildSquareChain (int aSize, const VECTOR2I &aCentre={ 0, 0 })
 Builds a square SHAPE_LINE_CHAIN of a certain size at a certain centre. More...
 
SHAPE_POLY_SET BuildPolyset (const std::vector< SHAPE_LINE_CHAIN > &aOutlines)
 Construct a SHAPE_POLY_SET from a list of points for each of outlines (no holes) More...
 
SHAPE_POLY_SET BuildHollowSquare (int aOuterSize, int aInnerSize, const VECTOR2I &aCentre={ 0, 0 })
 Build a SHAPE_POLY_SET in the shape of a square outline, with a square hole, both centred at the given point. More...
 
SEG BuildHSeg (const VECTOR2I &aStart, int aLength)
 Build a horizontal segment from a point with a length. More...
 
SEG BuildVSeg (const VECTOR2I &aStart, int aLength)
 Build a vertical segment from a point with a length. More...
 
template<typename VEC >
bool IsVecWithinTol (const VEC &aVec, const VEC &aExp, typename VEC::coord_type aTol)
 Check that both x and y of a vector are within expected error. More...
 
template<typename BOX >
bool IsBoxWithinTol (const BOX &aBox, const BOX &aExp, typename BOX::coord_type aTol)
 Check that a box is close enough to another box. More...
 
template<typename T >
bool IsWithinWrapped (T aValue, T aNominal, T aWrap, T aError)
 Check if a value is within a tolerance of a nominal value, wrapping to a given val. More...
 
template<typename T >
bool IsWithin (T aValue, T aNominal, T aError)
 Check if a value is within a tolerance of a nominal value. More...
 
template<typename T >
bool IsWithinBounds (T aValue, T aNominal, T aErrorAbove, T aErrorBelow)
 Check if a value is within a tolerance of a nominal value, with different allowances for errors above and below. More...
 
template<typename T >
bool IsWithinAndBelow (T aValue, T aNominal, T aErrorBelow)
 value is in range [aNominal - aErrorBelow, aNominal] More...
 
template<typename T >
bool IsWithinAndAbove (T aValue, T aNominal, T aErrorAbove)
 value is in range [aNominal, aNominal + aErrorAbove] More...
 
template<typename EXP_CONT , typename FOUND_CONT , typename MATCH_PRED >
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. More...
 
template<typename T >
bool CollectionHasNoDuplicates (const T &aCollection)
 Predicate to check a collection has no duplicate elements. More...
 

Typedef Documentation

◆ EXP_OBJ

template<typename EXP_CONT >
using KI_TEST::EXP_OBJ = typedef typename EXP_CONT::value_type

Definition at line 175 of file unit_test_utils.h.

◆ FOUND_OBJ

template<typename FOUND_CONT >
using KI_TEST::FOUND_OBJ = typedef typename FOUND_CONT::value_type

Definition at line 176 of file unit_test_utils.h.

◆ MATCH_PRED

template<typename EXP_OBJ , typename FOUND_OBJ >
using KI_TEST::MATCH_PRED = typedef std::function<bool( const EXP_OBJ&, const FOUND_OBJ& )>

A match predicate: check that a "found" object is equivalent to or represents an "expected" object, perhaps of a different type.

Exactly what "equivalent to" means depends heavily on the context and what is care about. For example, if you only care about a MODULE's refdes, std::string is sufficient to indicate a "match".

This can be used, for example, for checking a set of results without having to instantiate a full result object for checking by equality.

Template Parameters
EXP_OBJthe "expected" object type
FOUND_OBJthe "found" object type
Returns
true if the "found" object represents the "expected" object

Definition at line 195 of file unit_test_utils.h.

Enumeration Type Documentation

◆ RET_CODES

Return codes for tools.

Enumerator
OK 

Tool exited OK.

BAD_CMDLINE 

The command line was not correct for the tool.

UNKNOWN_TOOL 

The tool asked for was not found.

TOOL_SPECIFIC 

Tools can define their own statuses from here onwards.

Definition at line 38 of file utility_program.h.

39 {
41  OK = 0,
42 
44  BAD_CMDLINE = 1,
45 
47  UNKNOWN_TOOL = 2,
48 
50  TOOL_SPECIFIC = 10,
51 };
Tools can define their own statuses from here onwards.
The command line was not correct for the tool.
Tool exited OK.
The tool asked for was not found.

Function Documentation

◆ AreDefaultFieldsCorrect()

bool KI_TEST::AreDefaultFieldsCorrect ( const LIB_FIELDS aFields)

Predicate to check that the mandatory fields in a LIB_FIELDS object look sensible.

Parameters
aFieldsthe fields to check
Returns
true if valid

Definition at line 99 of file lib_field_test_utils.h.

100 {
101  const unsigned expectedCount = NumFieldType::MANDATORY_FIELDS;
102  if( aFields.size() < expectedCount )
103  {
105  "Expected at least " << expectedCount << " fields, got " << aFields.size() );
106  return false;
107  }
108 
109  bool ok = true;
110 
111  ok &= FieldNameIdMatches( aFields[0], "Reference", NumFieldType::REFERENCE );
112  ok &= FieldNameIdMatches( aFields[1], "Value", NumFieldType::VALUE );
113  ok &= FieldNameIdMatches( aFields[2], "Footprint", NumFieldType::FOOTPRINT );
114  ok &= FieldNameIdMatches( aFields[3], "Datasheet", NumFieldType::DATASHEET );
115 
116  return ok;
117 }
name of datasheet
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
Field Value of part, i.e. "3.3K".
bool FieldNameIdMatches(const LIB_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
Predicate to check a field name is as expected.
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO, DATASHEET, FieldNameIdMatches(), FOOTPRINT, MANDATORY_FIELDS, REFERENCE, and VALUE.

Referenced by BOOST_AUTO_TEST_CASE().

◆ BuildHollowSquare()

SHAPE_POLY_SET KI_TEST::BuildHollowSquare ( int  aOuterSize,
int  aInnerSize,
const VECTOR2I aCentre = { 0, 0 } 
)

Build a SHAPE_POLY_SET in the shape of a square outline, with a square hole, both centred at the given point.

Parameters
aOuterSizethe size (x and y) of the outer square
aInnerSizethe size (x and y) of the hole
aCentrethe centre point of both squares (default: origin)
Returns
a SHAPE_POLY_SET of the desired shape

Definition at line 44 of file poly_set_construction.cpp.

45 {
46  SHAPE_POLY_SET polyset;
47 
48  polyset.AddOutline( BuildRectChain( { aOuterSize, aOuterSize }, aCentre ) );
49  polyset.AddHole( BuildRectChain( { aInnerSize, aInnerSize }, aCentre ) );
50 
51  return polyset;
52 }
SHAPE_LINE_CHAIN BuildRectChain(const VECTOR2I &aSize, const VECTOR2I &aCentre)
Builds a rectangular SHAPE_LINE_CHAIN of a certain size at a certain centre.
SHAPE_POLY_SET.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Adds a new hole to the given outline (default: last) and returns its index
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index

References SHAPE_POLY_SET::AddHole(), SHAPE_POLY_SET::AddOutline(), and BuildRectChain().

Referenced by GetSPSSegDistCases().

◆ BuildHSeg()

SEG KI_TEST::BuildHSeg ( const VECTOR2I aStart,
int  aLength 
)

Build a horizontal segment from a point with a length.

Parameters
aStartthe starting point
aLengththe segment length
Returns
the resulting segment

Definition at line 29 of file seg_construction.cpp.

30 {
31  return SEG{ { aStart.x, aStart.y }, { aStart.x + aLength, aStart.y } };
32 }
Definition: seg.h:39

References VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by GetSPSSegDistCases().

◆ BuildPolyset()

SHAPE_POLY_SET KI_TEST::BuildPolyset ( const std::vector< SHAPE_LINE_CHAIN > &  aOutlines)

Construct a SHAPE_POLY_SET from a list of points for each of outlines (no holes)

Definition at line 31 of file poly_set_construction.cpp.

32 {
33  SHAPE_POLY_SET polyset;
34 
35  for( const auto& outline : aOutlines )
36  {
37  polyset.AddOutline( outline );
38  }
39 
40  return polyset;
41 }
SHAPE_POLY_SET.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new outline to the set and returns its index

References SHAPE_POLY_SET::AddOutline().

Referenced by GetSPSSegDistCases().

◆ BuildRectChain()

SHAPE_LINE_CHAIN KI_TEST::BuildRectChain ( const VECTOR2I aSize,
const VECTOR2I aCentre = { 0, 0 } 
)

Builds a rectangular SHAPE_LINE_CHAIN of a certain size at a certain centre.

Parameters
aSizethe rectangle size
aCentrecentre of the rectangle
Returns
a closed line chain of the rectangle

Definition at line 29 of file line_chain_construction.cpp.

30 {
31  const std::vector<VECTOR2I> pts = {
32  { aCentre.x - aSize.x / 2, aCentre.y - aSize.y / 2 },
33  { aCentre.x - aSize.x / 2, aCentre.y + aSize.y / 2 },
34  { aCentre.x + aSize.x / 2, aCentre.y + aSize.y / 2 },
35  { aCentre.x + aSize.x / 2, aCentre.y - aSize.y / 2 },
36  };
37 
38  SHAPE_LINE_CHAIN chain( pts );
39  chain.SetClosed( true );
40 
41  return chain;
42 }
SHAPE_LINE_CHAIN.

References SHAPE_LINE_CHAIN::SetClosed(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by BuildHollowSquare(), and BuildSquareChain().

◆ BuildSquareChain()

SHAPE_LINE_CHAIN KI_TEST::BuildSquareChain ( int  aSize,
const VECTOR2I aCentre = { 0, 0 } 
)

Builds a square SHAPE_LINE_CHAIN of a certain size at a certain centre.

Parameters
aSizethe square size (x == y)
aCentrecentre of the square
Returns
a closed line chain of the square

Definition at line 44 of file line_chain_construction.cpp.

45 {
46  return BuildRectChain( { aSize, aSize }, aCentre );
47 }
SHAPE_LINE_CHAIN BuildRectChain(const VECTOR2I &aSize, const VECTOR2I &aCentre)
Builds a rectangular SHAPE_LINE_CHAIN of a certain size at a certain centre.

References BuildRectChain().

Referenced by GetSPSSegDistCases().

◆ BuildVSeg()

SEG KI_TEST::BuildVSeg ( const VECTOR2I aStart,
int  aLength 
)

Build a vertical segment from a point with a length.

Parameters
aStartthe starting point
aLengththe segment length
Returns
the resulting segment

Definition at line 34 of file seg_construction.cpp.

35 {
36  return SEG{ { aStart.x, aStart.y }, { aStart.x, aStart.y + aLength } };
37 }
Definition: seg.h:39

References VECTOR2< T >::x, and VECTOR2< T >::y.

◆ CheckUnorderedMatches()

template<typename EXP_CONT , typename FOUND_CONT , typename MATCH_PRED >
void KI_TEST::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.

This means that:

  • Every "expected" object is "found"
  • Every "found" object is "expected"

This is a very generic function: all you need are two containers of any type and a function to check if a given "found" object corresponds to a given "expected object". Conditions:

  • The expected object type needs operator<< (for logging)
  • The expected object container does not contain multiple references to the same object.
  • Identical values are also can't be present as the predicate can't tell which one to match up.

Not needed:

  • Equality or ordering operators

This is a slightly more complex way of doing it that, say, sorting both lists and checking element-by-element matches. However, it can tell you exactly which objects are problematic, as well as a simple go/no-go.

When you have two containers of identical types (or you have a suitable operator==) and ordering is important, you can use BOOST_CHECK_EQUAL_COLLECTIONS

Parameters
aExpecteda container of "expected" items, usually from a test case
aMatcheda container of "found" items, usually the result of some routine under test
aMatchPredicatea predicate that determines if a given "found" object matches a given "expected" object.

Definition at line 232 of file unit_test_utils.h.

234 {
235  using EXP_OBJ = typename EXP_CONT::value_type;
236 
237  // set of object we've already found
238  std::set<const EXP_OBJ*> matched;
239 
240  // fill the set of object that match
241  for( const auto& found : aFound )
242  {
243  for( const auto& expected : aExpected )
244  {
245  if( aMatchPredicate( expected, found ) )
246  {
247  matched.insert( &expected );
248  break;
249  }
250  }
251  }
252 
253  // first check every expected object was "found"
254  for( const EXP_OBJ& exp : aExpected )
255  {
256  BOOST_CHECK_MESSAGE( matched.count( &exp ) > 0, "Expected item was not found. Expected: \n"
257  << exp );
258  }
259 
260  // check every "found" object was expected
261  for( const EXP_OBJ* found : matched )
262  {
263  const bool was_expected =
264  std::find_if( aExpected.begin(), aExpected.end(),
265  [found]( const EXP_OBJ& aObj ) { return &aObj == found; } )
266  != aExpected.end();
267 
268  BOOST_CHECK_MESSAGE( was_expected, "Found item was not expected. Found: \n" << *found );
269  }
270 }
typename EXP_CONT::value_type EXP_OBJ

Referenced by CheckCollisionsMatchExpected(), and CheckInvalidsMatchExpected().

◆ CollectionHasNoDuplicates()

template<typename T >
bool KI_TEST::CollectionHasNoDuplicates ( const T &  aCollection)

Predicate to check a collection has no duplicate elements.

Definition at line 277 of file unit_test_utils.h.

278 {
279  T sorted = aCollection;
280  std::sort( sorted.begin(), sorted.end() );
281 
282  return std::adjacent_find( sorted.begin(), sorted.end() ) == sorted.end();
283 }
T
enum T contains all this lexer's tokens.

Referenced by BOOST_AUTO_TEST_CASE().

◆ DrawArc()

void KI_TEST::DrawArc ( MODULE aMod,
const VECTOR2I aCentre,
const VECTOR2I aStart,
double  aAngle,
int  aWidth,
PCB_LAYER_ID  aLayer 
)

Draw an arc on a module.

Parameters
aModThe module to add the segment to
aCentreThe arc centre
aStartThe arc start point
aAngleThe arc angle (degrees, NOT deci-degrees)
aWidthThe width of the arc segment
aLayerThe layer to draw on

Definition at line 61 of file board_construction_utils.cpp.

63 {
64  auto seg = std::make_unique<EDGE_MODULE>( &aMod, STROKE_T::S_ARC );
65 
66  seg->SetStart0( (wxPoint) aCentre );
67  seg->SetEnd0( (wxPoint) aStart );
68  seg->SetAngle( aAngle * 10 );
69 
70  seg->SetWidth( aWidth );
71  seg->SetLayer( aLayer );
72 
73  aMod.Add( seg.release() );
74 }
Arcs (with rounded ends)
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override

References MODULE::Add(), and S_ARC.

Referenced by DrawRect().

◆ DrawPolyline()

void KI_TEST::DrawPolyline ( MODULE aMod,
const std::vector< VECTOR2I > &  aPts,
int  aWidth,
PCB_LAYER_ID  aLayer 
)

Draw a polyline - a set of linked segments.

Parameters
aModThe module to add the segment to
aPtsThe polyline points
aWidthThe width of the segments
aLayerThe layer to draw on

Definition at line 51 of file board_construction_utils.cpp.

53 {
54  for( unsigned i = 0; i < aPts.size() - 1; ++i )
55  {
56  DrawSegment( aMod, { aPts[i], aPts[i + 1] }, aWidth, aLayer );
57  }
58 }
void DrawSegment(MODULE &aMod, const SEG &aSeg, int aWidth, PCB_LAYER_ID aLayer)
Draw a segment in the given module.

References DrawSegment().

◆ DrawRect()

void KI_TEST::DrawRect ( MODULE aMod,
const VECTOR2I aPos,
const VECTOR2I aSize,
int  aRadius,
int  aWidth,
PCB_LAYER_ID  aLayer 
)

Draw a rectangle on a module.

Parameters
aModThe module to add the rectangle to
aPosRectangle centre point
aSizeRectangle size (x, y)
aRadiusCorner radius (0 for a normal rect)
aWidthLine width
aLayerLayer to draw on

Definition at line 77 of file board_construction_utils.cpp.

79 {
80  const auto x_r = aPos.x + aSize.x / 2;
81  const auto x_l = aPos.x - aSize.x / 2;
82  const auto y_t = aPos.y + aSize.y / 2;
83  const auto y_b = aPos.y - aSize.y / 2;
84 
85  const auto xin_r = x_r - aRadius;
86  const auto xin_l = x_l + aRadius;
87  const auto yin_t = y_t - aRadius;
88  const auto yin_b = y_b + aRadius;
89 
90  // If non-zero (could be zero if it's a stadium shape)
91  if( xin_l != xin_r )
92  {
93  DrawSegment( aMod, { { xin_l, y_t }, { xin_r, y_t } }, aWidth, aLayer );
94  DrawSegment( aMod, { { xin_l, y_b }, { xin_r, y_b } }, aWidth, aLayer );
95  }
96 
97  if( yin_b != yin_t )
98  {
99  DrawSegment( aMod, { { x_l, yin_b }, { x_l, yin_t } }, aWidth, aLayer );
100  DrawSegment( aMod, { { x_r, yin_b }, { x_r, yin_t } }, aWidth, aLayer );
101  }
102 
103  if( aRadius > 0 )
104  {
105  DrawArc( aMod, { xin_r, yin_t }, { x_r, yin_t }, 90, aWidth, aLayer );
106  DrawArc( aMod, { xin_l, yin_t }, { xin_l, y_t }, 90, aWidth, aLayer );
107  DrawArc( aMod, { xin_l, yin_b }, { x_l, yin_b }, 90, aWidth, aLayer );
108  DrawArc( aMod, { xin_r, yin_b }, { xin_r, y_b }, 90, aWidth, aLayer );
109  }
110 }
void DrawArc(MODULE &aMod, const VECTOR2I &aCentre, const VECTOR2I &aStart, double aAngle, int aWidth, PCB_LAYER_ID aLayer)
Draw an arc on a module.
void DrawSegment(MODULE &aMod, const SEG &aSeg, int aWidth, PCB_LAYER_ID aLayer)
Draw a segment in the given module.

References DrawArc(), DrawSegment(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by AddRectCourtyard().

◆ DrawSegment()

void KI_TEST::DrawSegment ( MODULE aMod,
const SEG aSeg,
int  aWidth,
PCB_LAYER_ID  aLayer 
)

Draw a segment in the given module.

Parameters
aModThe module to add the segment to
aSegThe segment geometry
aWidthThe width of the segment
aLayerThe layer to draw on

Definition at line 37 of file board_construction_utils.cpp.

38 {
39  auto seg = std::make_unique<EDGE_MODULE>( &aMod, STROKE_T::S_SEGMENT );
40 
41  seg->SetStart0( (wxPoint) aSeg.A );
42  seg->SetEnd0( (wxPoint) aSeg.B );
43 
44  seg->SetWidth( aWidth );
45  seg->SetLayer( aLayer );
46 
47  aMod.Add( seg.release() );
48 }
usual segment : line with rounded ends
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
VECTOR2I A
Definition: seg.h:47
VECTOR2I B
Definition: seg.h:48

References SEG::A, MODULE::Add(), SEG::B, and S_SEGMENT.

Referenced by DrawPolyline(), DrawRect(), and MakeInvalidCourtyardTestModule().

◆ DumpBoardToFile()

void KI_TEST::DumpBoardToFile ( BOARD aBoard,
const std::string &  aFilename 
)

Utility function to simply write a Board out to a file.

Helps debug tests and utility programs by making it easy to quickly write to disk without directly using the PCB_IO API.

Note: The aBoard param is non-const because PCB_IO::Save demands it and I am not confident a const_cast will be a true assurance.

Parameters
aBoardthe board to write out
aFilenamethe filename to write to

Definition at line 38 of file board_file_utils.cpp.

39 {
40  PCB_IO io;
41  io.Save( aFilename, &board );
42 }
PCB_IO is a PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
virtual void Save(const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL) override
Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows a...

References PCB_IO::Save().

Referenced by KI_TEST::BOARD_DUMPER::DumpBoardToFile().

◆ FieldNameIdMatches()

bool KI_TEST::FieldNameIdMatches ( const LIB_FIELD aField,
const std::string &  aExpectedName,
int  aExpectedId 
)

Predicate to check a field name is as expected.

Parameters
aFieldLIB_FIELD to check the name
aExpectedNamethe expected field name
aExpectedIdthe expected field id
Returns
true if match

Definition at line 71 of file lib_field_test_utils.h.

73 {
74  bool ok = true;
75  const auto gotName = aField.GetCanonicalName();
76 
77  if( gotName != aExpectedName )
78  {
79  BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
80  ok = false;
81  }
82 
83  const int gotId = aField.GetId();
84 
85  if( gotId != aExpectedId )
86  {
87  BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
88  ok = false;
89  }
90 
91  return ok;
92 }
int GetId() const
Definition: lib_field.h:138
wxString GetCanonicalName() const
Get a non-language-specific name for a field which can be used for storage, variable look-up,...
Definition: lib_field.cpp:375
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO, LIB_FIELD::GetCanonicalName(), and LIB_FIELD::GetId().

Referenced by AreDefaultFieldsCorrect(), and BOOST_AUTO_TEST_CASE().

◆ getDebugType()

std::string KI_TEST::getDebugType ( SEXPR::SEXPR_TYPE  aType)
inline

Get a debug-friendly string for a given s-expr type.

Definition at line 57 of file sexpr_test_utils.h.

58 {
59  switch( aType )
60  {
62  return "List";
64  return "Symbol";
66  return "String";
68  return "Double";
70  return "Integer";
71  }
72 
73  return "<Unknown S-Expression Type!>";
74 }

References SEXPR::SEXPR_TYPE_ATOM_DOUBLE, SEXPR::SEXPR_TYPE_ATOM_INTEGER, SEXPR::SEXPR_TYPE_ATOM_STRING, SEXPR::SEXPR_TYPE_ATOM_SYMBOL, and SEXPR::SEXPR_TYPE_LIST.

Referenced by GetSexprDebugType(), and IsSexprOfType().

◆ GetEeschemaTestDataDir()

wxFileName KI_TEST::GetEeschemaTestDataDir ( )

Get the configured location of Eeschema test data.

By default, this is the test data in the source tree, but can be overriden by the KICAD_TEST_EESCHEMA_DATA_DIR environment variable.

Returns
a filename referring to the test data dir to use.

Definition at line 28 of file eeschema_test_utils.cpp.

29 {
30  const char* env = std::getenv( "KICAD_TEST_EESCHEMA_DATA_DIR" );
31  wxString fn;
32 
33  if( !env )
34  {
35  // Use the compiled-in location of the data dir
36  // (i.e. where the files were at build time)
37  fn << QA_EESCHEMA_DATA_LOCATION;
38  }
39  else
40  {
41  // Use whatever was given in the env var
42  fn << env;
43  }
44 
45  // Ensure the string ends in / to force a directory interpretation
46  fn << "/";
47 
48  return wxFileName{ fn };
49 }

Referenced by getEagleTestSchematic(), and getSchematicFile().

◆ GetSexprDebugType()

std::string KI_TEST::GetSexprDebugType ( const SEXPR::SEXPR aSexpr)
inline

Definition at line 76 of file sexpr_test_utils.h.

77 {
78  return getDebugType( getType( aSexpr ) );
79 }
std::string getDebugType(SEXPR::SEXPR_TYPE aType)
Get a debug-friendly string for a given s-expr type.
SEXPR::SEXPR_TYPE getType(const SEXPR::SEXPR &aSexpr)
Get the type of the s-expression.

References getDebugType(), and getType().

Referenced by BOOST_TEST_PRINT_NAMESPACE_OPEN::print_log_value< SEXPR::SEXPR >::operator()().

◆ getType()

SEXPR::SEXPR_TYPE KI_TEST::getType ( const SEXPR::SEXPR aSexpr)
inline

◆ IsBoxWithinTol()

template<typename BOX >
bool KI_TEST::IsBoxWithinTol ( const BOX &  aBox,
const BOX &  aExp,
typename BOX::coord_type  aTol 
)

Check that a box is close enough to another box.

Definition at line 62 of file geometry.h.

63 {
65  return IsVecWithinTol<VEC>( aBox.GetPosition(), aExp.GetPosition(), aTol )
66  && IsVecWithinTol<VEC>( aBox.GetSize(), aExp.GetSize(), aTol * 2 );
67 }
VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61

◆ IsColorNear()

bool KI_TEST::IsColorNear ( const KIGFX::COLOR4D aCol,
const KIGFX::COLOR4D  aOther,
double  aTol 
)
inline

Checks if a COLOR4D is close enough to another.

Definition at line 41 of file color4d_test_utils.h.

42 {
43  return KI_TEST::IsWithin<double>( aCol.r, aOther.r, aTol )
44  && KI_TEST::IsWithin<double>( aCol.g, aOther.g, aTol )
45  && KI_TEST::IsWithin<double>( aCol.b, aOther.b, aTol )
46  && KI_TEST::IsWithin<double>( aCol.a, aOther.a, aTol );
47 }
double g
Green component.
Definition: color4d.h:367
double b
Blue component.
Definition: color4d.h:368
double a
Alpha component.
Definition: color4d.h:369
double r
Red component.
Definition: color4d.h:366

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::COLOR4D::g, and KIGFX::COLOR4D::r.

◆ IsColorNearHex()

bool KI_TEST::IsColorNearHex ( const KIGFX::COLOR4D aCol,
unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  a 
)
inline

Checks if a COLOR4D is close enough to a given RGB char value.

Definition at line 52 of file color4d_test_utils.h.

54 {
55  const double tol = 0.5 / 255.0; // One bit of quantised error
56 
57  return KI_TEST::IsWithin<double>( aCol.r, r / 255.0, tol )
58  && KI_TEST::IsWithin<double>( aCol.g, g / 255.0, tol )
59  && KI_TEST::IsWithin<double>( aCol.b, b / 255.0, tol )
60  && KI_TEST::IsWithin<double>( aCol.a, a / 255.0, tol );
61 }
double g
Green component.
Definition: color4d.h:367
double b
Blue component.
Definition: color4d.h:368
double a
Alpha component.
Definition: color4d.h:369
double r
Red component.
Definition: color4d.h:366

References KIGFX::COLOR4D::a, KIGFX::COLOR4D::b, KIGFX::COLOR4D::g, and KIGFX::COLOR4D::r.

Referenced by BOOST_AUTO_TEST_CASE(), and IsImagePixelOfColor().

◆ IsDrcMarkerOfType()

bool KI_TEST::IsDrcMarkerOfType ( const MARKER_PCB aMarker,
int  aErrorCode 
)

Predicate for testing the type of a DRC marker.

Parameters
aMarkerthe marker to test
aErrorCodethe expected DRC violation code
Returns
true if the marker has this code

Definition at line 41 of file drc_test_utils.cpp.

42 {
43  return aMarker.GetRCItem()->GetErrorCode() == aErrorCode;
44 }
RC_ITEM * GetRCItem()
Function GetReporter returns the DRC_ITEM held within this MARKER so that its interface may be used.
Definition: marker_base.h:117
int GetErrorCode() const
Definition: rc_item.h:156

References RC_ITEM::GetErrorCode(), and MARKER_BASE::GetRCItem().

Referenced by CheckCollisionsMatchExpected().

◆ IsImagePixelOfColor()

bool KI_TEST::IsImagePixelOfColor ( const wxImage &  aImage,
int  aX,
int  aY,
const KIGFX::COLOR4D aColor 
)

Predicate to check an image pixel matches color and alpha.

Parameters
aImagethe image to check
aXpixel x-coordinate
aYpixel y-coordinate
aColorexpected color (alpha is 1.0 if image doesn't support alpha)
Returns
true if colour match

Definition at line 40 of file wximage_test_utils.cpp.

41 {
42  const wxSize imageSize = aImage.GetSize();
43 
44  if( imageSize.x < aX || imageSize.y < aY )
45  {
46  BOOST_TEST_INFO( "Pixel (" << aX << ", " << aY << "is not in image of size (" << imageSize.x
47  << ", " << imageSize.y << ")" );
48  return false;
49  }
50 
51  const int r = aImage.GetRed( aX, aY );
52  const int g = aImage.GetGreen( aX, aY );
53  const int b = aImage.GetBlue( aX, aY );
54 
55  const int a = aImage.HasAlpha() ? aImage.GetAlpha( aX, aY ) : 255;
56 
57  if( !KI_TEST::IsColorNearHex( aColor, r, g, b, a ) )
58  {
59  BOOST_TEST_INFO( "Colour doesn't match: got rgba(" << r << ", " << g << ", " << b << ", "
60  << a << "), expected " << aColor );
61  return false;
62  }
63 
64  return true;
65 }
bool IsColorNearHex(const KIGFX::COLOR4D &aCol, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Checks if a COLOR4D is close enough to a given RGB char value.
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO, and IsColorNearHex().

Referenced by BOOST_AUTO_TEST_CASE().

◆ IsSexprOfType()

bool KI_TEST::IsSexprOfType ( const SEXPR::SEXPR aSexpr,
SEXPR::SEXPR_TYPE  aType 
)
inline

Definition at line 81 of file sexpr_test_utils.h.

82 {
83  if( getType( aSexpr ) != aType )
84  {
85  BOOST_TEST_MESSAGE( "Sexpr is not of type: " << getDebugType( aType ) );
86  return false;
87  }
88 
89  return true;
90 }
std::string getDebugType(SEXPR::SEXPR_TYPE aType)
Get a debug-friendly string for a given s-expr type.
SEXPR::SEXPR_TYPE getType(const SEXPR::SEXPR &aSexpr)
Get the type of the s-expression.

References getDebugType(), and getType().

Referenced by SexprIsDouble(), SexprIsDoubleWithValue(), SexprIsInteger(), SexprIsIntegerWithValue(), SexprIsList(), SexprIsListOfLength(), SexprIsString(), SexprIsStringWithValue(), SexprIsSymbol(), and SexprIsSymbolWithValue().

◆ IsSexprValueEqual()

template<typename VAL_T >
bool KI_TEST::IsSexprValueEqual ( const VAL_T &  aGot,
const VAL_T &  aExpected 
)

Predicate to check two s-expr values (of the same type) are equal.

Returns
false if not equal (and output logging)

Definition at line 98 of file sexpr_test_utils.h.

99 {
100  if( aGot != aExpected )
101  {
102  BOOST_TEST_MESSAGE( "Sexpr value not equal: got " << aGot << ", expected " << aExpected );
103  return false;
104  }
105 
106  return true;
107 }

Referenced by SexprIsDoubleWithValue(), SexprIsIntegerWithValue(), SexprIsStringWithValue(), and SexprIsSymbolWithValue().

◆ IsUUID()

bool KI_TEST::IsUUID ( const std::string &  aStr)

Check if the string between the iterators looks like a UUID.

Definition at line 31 of file uuid_test_utils.cpp.

32 {
33  std::regex uuid( "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" );
34  std::smatch match;
35 
36  return std::regex_match( aStr, match, uuid );
37 }

Referenced by IsUUIDPathWithLevels().

◆ IsUUIDPathWithLevels()

bool KI_TEST::IsUUIDPathWithLevels ( const std::string &  aStr,
unsigned  aLevels 
)

Predicate to check a string is a UUID path format.

Eg. levels=2: /1d33ca6f-67e8-41ae-a0aa-49d857ab38d5/1d33ca6f-67e8-41ae-a0aa-49d857ab38d5/

Parameters
aStrcandidate string
levelsexpected levels
Returns
true if format matches

Definition at line 40 of file uuid_test_utils.cpp.

41 {
42  // A UUID is formated as 8-4-4-4-12
43  const unsigned tsLen = 36;
44  const unsigned levelLen = tsLen + 1; // add the /
45 
46  if( aStr.size() != aLevels * levelLen + 1 )
47  {
48  BOOST_TEST_INFO( "String is the wrong length for " << aLevels << " levels." );
49  return false;
50  }
51 
52  if( aStr[0] != '/' )
53  {
54  BOOST_TEST_INFO( "Doesn't start with '/'" );
55  return false;
56  }
57 
58  auto tsBegin = aStr.begin() + 1;
59 
60  for( unsigned i = 0; i < aLevels; i++ )
61  {
62  if( !IsUUID( std::string( tsBegin, tsBegin + tsLen ) ) )
63  {
64  BOOST_TEST_INFO( "Not a UUID at level "
65  << i << ": " << std::string( tsBegin, tsBegin + tsLen ) );
66  return false;
67  }
68 
69  if( *( tsBegin + tsLen ) != '/' )
70  {
71  BOOST_TEST_INFO( "level doesn't end in '/'" );
72  return false;
73  }
74 
75  tsBegin += levelLen;
76  }
77 
78  return true;
79 }
bool IsUUID(const std::string &aStr)
Check if the string between the iterators looks like a UUID.
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References BOOST_TEST_INFO, and IsUUID().

Referenced by BOOST_AUTO_TEST_CASE().

◆ IsVecWithinTol()

template<typename VEC >
bool KI_TEST::IsVecWithinTol ( const VEC &  aVec,
const VEC &  aExp,
typename VEC::coord_type  aTol 
)

Check that both x and y of a vector are within expected error.

Definition at line 52 of file geometry.h.

53 {
54  return IsWithin<typename VEC::coord_type>( aVec.x, aExp.x, aTol )
55  && IsWithin<typename VEC::coord_type>( aVec.y, aExp.y, aTol );
56 }

◆ IsWithin()

template<typename T >
bool KI_TEST::IsWithin ( aValue,
aNominal,
aError 
)

Check if a value is within a tolerance of a nominal value.

Returns
value is in [aNominal - aError, aNominal + aError]

Definition at line 57 of file numeric.h.

58 {
59  return ( aValue >= aNominal - aError ) && ( aValue <= aNominal + aError );
60 }

Referenced by GEOM_TEST::ArePerpendicular(), and GEOM_TEST::IsPointAtDistance().

◆ IsWithinAndAbove()

template<typename T >
bool KI_TEST::IsWithinAndAbove ( aValue,
aNominal,
aErrorAbove 
)

value is in range [aNominal, aNominal + aErrorAbove]

Definition at line 84 of file numeric.h.

85 {
86  return IsWithinBounds( aValue, aNominal, aErrorAbove, 0 );
87 }
bool IsWithinBounds(T aValue, T aNominal, T aErrorAbove, T aErrorBelow)
Check if a value is within a tolerance of a nominal value, with different allowances for errors above...
Definition: numeric.h:68

References IsWithinBounds().

◆ IsWithinAndBelow()

template<typename T >
bool KI_TEST::IsWithinAndBelow ( aValue,
aNominal,
aErrorBelow 
)

value is in range [aNominal - aErrorBelow, aNominal]

Definition at line 76 of file numeric.h.

77 {
78  return IsWithinBounds( aValue, aNominal, 0, aErrorBelow );
79 }
bool IsWithinBounds(T aValue, T aNominal, T aErrorAbove, T aErrorBelow)
Check if a value is within a tolerance of a nominal value, with different allowances for errors above...
Definition: numeric.h:68

References IsWithinBounds().

◆ IsWithinBounds()

template<typename T >
bool KI_TEST::IsWithinBounds ( aValue,
aNominal,
aErrorAbove,
aErrorBelow 
)

Check if a value is within a tolerance of a nominal value, with different allowances for errors above and below.

Returns
value is in [aNominal - aErrorBelow, aNominal + aErrorAbove]

Definition at line 68 of file numeric.h.

69 {
70  return ( aValue >= aNominal - aErrorBelow ) && ( aValue <= aNominal + aErrorAbove );
71 }

Referenced by IsWithinAndAbove(), and IsWithinAndBelow().

◆ IsWithinWrapped()

template<typename T >
bool KI_TEST::IsWithinWrapped ( aValue,
aNominal,
aWrap,
aError 
)

Check if a value is within a tolerance of a nominal value, wrapping to a given val.

Returns
value is in [( aNominal - aError ) % aWrap, ( aNominal + aError ) % aWrap]

Definition at line 42 of file numeric.h.

43 {
44  double diff = std::fmod( aNominal - aValue + aWrap / 2.0, aWrap );
45 
46  if( diff < 0 )
47  diff += aWrap;
48 
49  return diff - aWrap / 2.0 <= aError;
50 }

◆ ReadBoardFromFileOrStream()

std::unique_ptr< BOARD > KI_TEST::ReadBoardFromFileOrStream ( const std::string &  aFilename,
std::istream &  aFallback = std::cin 
)

Read a board from a file, or another stream, as appropriate.

Parameters
aFilenameThe file to read, or the fallback if empty
aFallbackthe fallback stream
Returns
a BOARD, if successful

Definition at line 81 of file board_file_utils.cpp.

83 {
84  std::istream* in_stream = nullptr;
85  std::ifstream file_stream;
86 
87  if( aFilename.empty() )
88  {
89  // no file, read stdin
90  in_stream = &aFallback;
91  }
92  else
93  {
94  file_stream.open( aFilename );
95  in_stream = &file_stream;
96  }
97 
98  return ReadItemFromStream<BOARD>( *in_stream );
99 }

Referenced by drc_main_func(), main(), polygon_gererator_main(), and polygon_triangulation_main().

◆ ReadBoardItemFromFile()

std::unique_ptr<BOARD_ITEM> KI_TEST::ReadBoardItemFromFile ( const std::string &  aFilename)

Definition at line 45 of file board_file_utils.cpp.

46 {
47  FILE_LINE_READER reader( aFilename );
48 
49  PCB_PARSER parser;
50  parser.SetLineReader( &reader );
51 
52  return std::unique_ptr<BOARD_ITEM>( parser.Parse() );
53 }
PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD...
Definition: pcb_parser.h:69
FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:337

References PCB_PARSER::Parse(), and PCB_PARSER::SetLineReader().

◆ ReadBoardItemFromStream()

std::unique_ptr< BOARD_ITEM > KI_TEST::ReadBoardItemFromStream ( std::istream &  aStream)

Utility function to read a BOARD_ITEM (probably a MODULE or a BOARD) from a file.

Helps when writing tests or utilities that can be fed an external file.

Parameters
aFilenamethe file to read in
Returns
a new BOARD_ITEM, which is nullptr if the read or parse failed.

Definition at line 56 of file board_file_utils.cpp.

57 {
58  // Take input from stdin
60  reader.SetStream( aStream );
61 
62  PCB_PARSER parser;
63 
64  parser.SetLineReader( &reader );
65 
66  std::unique_ptr<BOARD_ITEM> board;
67 
68  try
69  {
70  board.reset( parser.Parse() );
71  }
72  catch( const IO_ERROR& parse_error )
73  {
74  std::cerr << parse_error.Problem() << std::endl;
75  std::cerr << parse_error.Where() << std::endl;
76  }
77 
78  return board;
79 }
PCB_PARSER reads a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD...
Definition: pcb_parser.h:69
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:45
virtual const wxString Where() const
where did the Problem() occur?
Definition: exceptions.cpp:39
void SetStream(std::istream &aStream)
Set the stream for this line reader.
LINE_READER that wraps a given std::istream instance.
BOARD_ITEM * Parse()
Definition: pcb_parser.cpp:481
LINE_READER * SetLineReader(LINE_READER *aReader)
Function SetLineReader sets aLineReader into the parser, and returns the previous one,...
Definition: pcb_parser.h:337
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:76

References PCB_PARSER::Parse(), IO_ERROR::Problem(), PCB_PARSER::SetLineReader(), STDISTREAM_LINE_READER::SetStream(), and IO_ERROR::Where().

Referenced by ReadItemFromStream().

◆ ReadItemFromStream()

template<typename ITEM >
std::unique_ptr<ITEM> KI_TEST::ReadItemFromStream ( std::istream &  aStream)

Read a specific kind of BOARD_ITEM from a stream.

Template Parameters
ITEMthe item type to return (probably a MODULE or BOARD)
Parameters
aStreamthe stream to read from.

Definition at line 72 of file board_file_utils.h.

73 {
74  auto bi_ptr = ReadBoardItemFromStream( aStream );
75  std::unique_ptr<ITEM> downcast_ptr;
76 
77  // if it's the right type, downcast and "steal" (and we'll return ownership)
78  ITEM* const tmp = dynamic_cast<ITEM*>( bi_ptr.get() );
79  if( tmp != nullptr )
80  {
81  bi_ptr.release();
82  downcast_ptr.reset( tmp );
83  }
84 
85  return downcast_ptr;
86 }
std::unique_ptr< BOARD_ITEM > ReadBoardItemFromStream(std::istream &aStream)
Utility function to read a BOARD_ITEM (probably a MODULE or a BOARD) from a file.

References ReadBoardItemFromStream().

◆ SexprConvertsToString()

bool KI_TEST::SexprConvertsToString ( const SEXPR::SEXPR aSexpr,
const std::string &  aExpStr 
)
inline

Predicate to check an SEXPR object converts to the expected string.

Parameters
aSexprs-expression
aExpStrexpected string
Returns
true if match

Definition at line 209 of file sexpr_test_utils.h.

210 {
211  const std::string converted = aSexpr.AsString();
212 
213  bool ok = true;
214 
215  if( converted != aExpStr )
216  {
217  BOOST_TEST_INFO( "Sexpr string conversion mismatch: got '" << converted << "', expected '"
218  << aExpStr << "'" );
219  ok = false;
220  }
221 
222  return ok;
223 }
std::string AsString(size_t aLevel=0) const
Definition: sexpr.cpp:151
#define BOOST_TEST_INFO(A)
If HAVE_EXPECTED_FAILURES is defined, this means that boost::unit_test::expected_failures is availabl...

References SEXPR::SEXPR::AsString(), and BOOST_TEST_INFO.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SexprIsDouble()

bool KI_TEST::SexprIsDouble ( const SEXPR::SEXPR aSexpr)
inline

Test predicate: is the s-expression a double?

Definition at line 163 of file sexpr_test_utils.h.

164 {
166 }
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)

References IsSexprOfType(), and SEXPR::SEXPR_TYPE_ATOM_DOUBLE.

◆ SexprIsDoubleWithValue()

bool KI_TEST::SexprIsDoubleWithValue ( const SEXPR::SEXPR aSexpr,
double  aVal 
)
inline

Test predicate: is the s-expression a double with the given value?

Definition at line 171 of file sexpr_test_utils.h.

172 {
174  && IsSexprValueEqual( aSexpr.GetDouble(), aVal );
175 }
double GetDouble() const
Definition: sexpr.cpp:105
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)
bool IsSexprValueEqual(const VAL_T &aGot, const VAL_T &aExpected)
Predicate to check two s-expr values (of the same type) are equal.

References SEXPR::SEXPR::GetDouble(), IsSexprOfType(), IsSexprValueEqual(), and SEXPR::SEXPR_TYPE_ATOM_DOUBLE.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SexprIsInteger()

bool KI_TEST::SexprIsInteger ( const SEXPR::SEXPR aSexpr)
inline

Test predicate: is the s-expression an integer?

Definition at line 146 of file sexpr_test_utils.h.

147 {
149 }
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)

References IsSexprOfType(), and SEXPR::SEXPR_TYPE_ATOM_INTEGER.

◆ SexprIsIntegerWithValue()

bool KI_TEST::SexprIsIntegerWithValue ( const SEXPR::SEXPR aSexpr,
std::int64_t  aVal 
)
inline

Test predicate: is the s-expression an integer with the given value?

Definition at line 154 of file sexpr_test_utils.h.

155 {
157  && IsSexprValueEqual( aSexpr.GetLongInteger(), aVal );
158 }
int64_t GetLongInteger() const
Definition: sexpr.cpp:95
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)
bool IsSexprValueEqual(const VAL_T &aGot, const VAL_T &aExpected)
Predicate to check two s-expr values (of the same type) are equal.

References SEXPR::SEXPR::GetLongInteger(), IsSexprOfType(), IsSexprValueEqual(), and SEXPR::SEXPR_TYPE_ATOM_INTEGER.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SexprIsList()

bool KI_TEST::SexprIsList ( const SEXPR::SEXPR aSexpr)
inline

Test predicate: is the s-expression a double?

Definition at line 180 of file sexpr_test_utils.h.

181 {
183 }
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)

References IsSexprOfType(), and SEXPR::SEXPR_TYPE_LIST.

◆ SexprIsListOfLength()

bool KI_TEST::SexprIsListOfLength ( const SEXPR::SEXPR aSexpr,
size_t  aExpectedLength 
)
inline

Test predicate: is the s-expression a list with the given length?

Definition at line 188 of file sexpr_test_utils.h.

189 {
191  return false;
192 
193  if( aSexpr.GetNumberOfChildren() != aExpectedLength )
194  {
195  BOOST_TEST_MESSAGE( "List is wrong length: got " << aSexpr.GetNumberOfChildren()
196  << ", expected " << aExpectedLength );
197  return false;
198  }
199 
200  return true;
201 }
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)
size_t GetNumberOfChildren() const
Definition: sexpr.cpp:70

References SEXPR::SEXPR::GetNumberOfChildren(), IsSexprOfType(), and SEXPR::SEXPR_TYPE_LIST.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SexprIsString()

bool KI_TEST::SexprIsString ( const SEXPR::SEXPR aSexpr)
inline

Test predicate: is the s-expression a string?

Definition at line 129 of file sexpr_test_utils.h.

130 {
132 }
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)

References IsSexprOfType(), and SEXPR::SEXPR_TYPE_ATOM_STRING.

◆ SexprIsStringWithValue()

bool KI_TEST::SexprIsStringWithValue ( const SEXPR::SEXPR aSexpr,
const std::string &  aVal 
)
inline

Test predicate: is the s-expression a string with the given value?

Definition at line 137 of file sexpr_test_utils.h.

138 {
140  && IsSexprValueEqual( aSexpr.GetString(), aVal );
141 }
std::string const & GetString() const
Definition: sexpr.cpp:80
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)
bool IsSexprValueEqual(const VAL_T &aGot, const VAL_T &aExpected)
Predicate to check two s-expr values (of the same type) are equal.

References SEXPR::SEXPR::GetString(), IsSexprOfType(), IsSexprValueEqual(), and SEXPR::SEXPR_TYPE_ATOM_STRING.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SexprIsSymbol()

bool KI_TEST::SexprIsSymbol ( const SEXPR::SEXPR aSexpr)
inline

Test predicate: is the s-expression a symbol?

Definition at line 112 of file sexpr_test_utils.h.

113 {
115 }
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)

References IsSexprOfType(), and SEXPR::SEXPR_TYPE_ATOM_SYMBOL.

◆ SexprIsSymbolWithValue()

bool KI_TEST::SexprIsSymbolWithValue ( const SEXPR::SEXPR aSexpr,
const std::string &  aVal 
)
inline

Test predicate: is the s-expression a symbol with the given value?

Definition at line 120 of file sexpr_test_utils.h.

121 {
123  && IsSexprValueEqual( aSexpr.GetSymbol(), aVal );
124 }
std::string const & GetSymbol() const
Definition: sexpr.cpp:128
bool IsSexprOfType(const SEXPR::SEXPR &aSexpr, SEXPR::SEXPR_TYPE aType)
bool IsSexprValueEqual(const VAL_T &aGot, const VAL_T &aExpected)
Predicate to check two s-expr values (of the same type) are equal.

References SEXPR::SEXPR::GetSymbol(), IsSexprOfType(), IsSexprValueEqual(), and SEXPR::SEXPR_TYPE_ATOM_SYMBOL.

Referenced by BOOST_AUTO_TEST_CASE().