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...
 
class  CONSOLE_LOG
 
class  CONSOLE_MSG_REPORTER
 
struct  kitest_cmp_drawings
 
class  SCHEMATIC_TEST_FIXTURE
 A generic fixture for loading schematics and associated settings for qa 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

void DrawSegment (FOOTPRINT &aFootprint, const SEG &aSeg, int aWidth, PCB_LAYER_ID aLayer)
 Draw a segment in the given footprint. More...
 
void DrawPolyline (FOOTPRINT &aFootprint, const std::vector< VECTOR2I > &aPts, int aWidth, PCB_LAYER_ID aLayer)
 Draw a polyline - a set of linked segments. More...
 
void DrawArc (FOOTPRINT &aFootprint, const VECTOR2I &aCentre, const VECTOR2I &aStart, const EDA_ANGLE &aAngle, int aWidth, PCB_LAYER_ID aLayer)
 Draw an arc on a footprint. More...
 
void DrawRect (FOOTPRINT &aFootprint, const VECTOR2I &aPos, const VECTOR2I &aSize, int aRadius, int aWidth, PCB_LAYER_ID aLayer)
 Draw a rectangle on a footprint. More...
 
std::string GetPcbnewTestDataDir ()
 Utility which returns a path to the data directory where the test board files are stored. 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_ITEMReadBoardItemFromStream (std::istream &aStream)
 Utility function to read a BOARD_ITEM (probably a FOOTPRINT 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...
 
void LoadBoard (SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
 
void FillZones (BOARD *m_board)
 
void CheckFootprint (const FOOTPRINT *expected, const FOOTPRINT *fp)
 Helper method to check if two footprints are semantically the same. More...
 
void CheckFpPad (const PAD *expected, const PAD *pad)
 
void CheckFpText (const FP_TEXT *expected, const FP_TEXT *text)
 
void CheckFpShape (const FP_SHAPE *expected, const FP_SHAPE *shape)
 
void CheckFpZone (const FP_ZONE *expected, const FP_ZONE *zone)
 
void CheckShapePolySet (const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
 
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...
 
std::string getEeschemaTestDataDir ()
 
void DumpSchematicToFile (SCHEMATIC &aSchematic, SCH_SHEET &aSheet, const std::string &aFilename)
 
void LoadSheetSchematicContents (const std::string &fileName, SCH_SHEET *sheet)
 
void LoadHierarchy (SCHEMATIC *schematic, SCH_SHEET *sheet, const std::string &sheetFilename, std::unordered_map< std::string, SCH_SCREEN * > &parsedScreens)
 
std::unique_ptr< SCHEMATICLoadHierarchyFromRoot (const std::string &rootFilename, PROJECT *project)
 
void LoadSchematic (SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
 
std::unique_ptr< SCHEMATICReadSchematicFromStream (std::istream &aStream, PROJECT *aProject)
 
std::unique_ptr< SCHEMATICReadSchematicFromFile (const std::string &aFilename, PROJECT *aProject)
 
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 std::vector< LIB_FIELD > &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 PCB_MARKER &aMarker, int aErrorCode)
 Predicate for testing the type of a DRC marker. More...
 

Typedef Documentation

◆ EXP_OBJ

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

Definition at line 178 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 179 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 FOOTPRINT'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 198 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};
@ OK
Tool exited OK.
@ UNKNOWN_TOOL
The tool asked for was not found.
@ TOOL_SPECIFIC
Tools can define their own statuses from here onwards.
@ BAD_CMDLINE
The command line was not correct for the tool.

Function Documentation

◆ AreDefaultFieldsCorrect()

bool KI_TEST::AreDefaultFieldsCorrect ( const std::vector< LIB_FIELD > &  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 98 of file lib_field_test_utils.h.

99{
100 const unsigned expectedCount = MANDATORY_FIELD_T::MANDATORY_FIELDS;
101 if( aFields.size() < expectedCount )
102 {
104 "Expected at least " << expectedCount << " fields, got " << aFields.size() );
105 return false;
106 }
107
108 bool ok = true;
109
110 ok &= FieldNameIdMatches( aFields[0], "Reference", MANDATORY_FIELD_T::REFERENCE_FIELD );
111 ok &= FieldNameIdMatches( aFields[1], "Value", MANDATORY_FIELD_T::VALUE_FIELD );
112 ok &= FieldNameIdMatches( aFields[2], "Footprint", MANDATORY_FIELD_T::FOOTPRINT_FIELD );
113 ok &= FieldNameIdMatches( aFields[3], "Datasheet", MANDATORY_FIELD_T::DATASHEET_FIELD );
114
115 return ok;
116}
bool FieldNameIdMatches(const LIB_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
Predicate to check a field name is as expected.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
#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_FIELD, FieldNameIdMatches(), FOOTPRINT_FIELD, MANDATORY_FIELDS, REFERENCE_FIELD, and VALUE_FIELD.

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}
Represent a set of closed polygons.
int AddOutline(const SHAPE_LINE_CHAIN &aOutline)
Adds a new hole to the given outline (default: last) and returns its index.
int AddHole(const SHAPE_LINE_CHAIN &aHole, int aOutline=-1)
Return the area of this poly set.
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 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:42

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}

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}
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...

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}

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}

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

◆ CheckFootprint()

void KI_TEST::CheckFootprint ( const FOOTPRINT expected,
const FOOTPRINT fp 
)

Helper method to check if two footprints are semantically the same.

Definition at line 167 of file board_test_utils.cpp.

168{
169 CHECK_ENUM_CLASS_EQUAL( expected->Type(), fp->Type() );
170
171 // TODO: validate those informations match the importer
172 BOOST_CHECK_EQUAL( expected->GetPosition(), fp->GetPosition() );
173 BOOST_CHECK_EQUAL( expected->GetOrientation(), fp->GetOrientation() );
174
175 BOOST_CHECK_EQUAL( expected->GetReference(), fp->GetReference() );
176 BOOST_CHECK_EQUAL( expected->GetValue(), fp->GetValue() );
177 BOOST_CHECK_EQUAL( expected->GetDescription(), fp->GetDescription() );
178 BOOST_CHECK_EQUAL( expected->GetKeywords(), fp->GetKeywords() );
179 BOOST_CHECK_EQUAL( expected->GetAttributes(), fp->GetAttributes() );
180 BOOST_CHECK_EQUAL( expected->GetFlag(), fp->GetFlag() );
181 //BOOST_CHECK_EQUAL( expected->GetProperties(), fp->GetProperties() );
182 BOOST_CHECK_EQUAL( expected->GetTypeName(), fp->GetTypeName() );
183
184 // simple test if count matches
185 BOOST_CHECK_EQUAL( expected->Pads().size(), fp->Pads().size() );
186 BOOST_CHECK_EQUAL( expected->GraphicalItems().size(), fp->GraphicalItems().size() );
187 BOOST_CHECK_EQUAL( expected->Zones().size(), fp->Zones().size() );
188 BOOST_CHECK_EQUAL( expected->Groups().size(), fp->Groups().size() );
189 BOOST_CHECK_EQUAL( expected->Models().size(), fp->Models().size() );
190
191 std::set<PAD*, FOOTPRINT::cmp_pads> expectedPads( expected->Pads().begin(),
192 expected->Pads().end() );
193 std::set<PAD*, FOOTPRINT::cmp_pads> fpPads( fp->Pads().begin(), fp->Pads().end() );
194 for( auto itExpected = expectedPads.begin(), itFp = fpPads.begin();
195 itExpected != expectedPads.end() && itFp != fpPads.end(); itExpected++, itFp++ )
196 {
197 CheckFpPad( *itExpected, *itFp );
198 }
199
200 std::set<BOARD_ITEM*, kitest_cmp_drawings> expectedGraphicalItems(
201 expected->GraphicalItems().begin(), expected->GraphicalItems().end() );
202 std::set<BOARD_ITEM*, kitest_cmp_drawings> fpGraphicalItems( fp->GraphicalItems().begin(),
203 fp->GraphicalItems().end() );
204 for( auto itExpected = expectedGraphicalItems.begin(), itFp = fpGraphicalItems.begin();
205 itExpected != expectedGraphicalItems.end() && itFp != fpGraphicalItems.end();
206 itExpected++, itFp++ )
207 {
208 BOOST_CHECK_EQUAL( ( *itExpected )->Type(), ( *itFp )->Type() );
209 switch( ( *itExpected )->Type() )
210 {
211 case PCB_FP_TEXT_T:
212 {
213 const FP_TEXT* expectedText = static_cast<const FP_TEXT*>( *itExpected );
214 const FP_TEXT* text = static_cast<const FP_TEXT*>( *itFp );
215
216 CheckFpText( expectedText, text );
217 }
218 break;
219 case PCB_FP_SHAPE_T:
220 {
221 const FP_SHAPE* expectedShape = static_cast<const FP_SHAPE*>( *itExpected );
222 const FP_SHAPE* shape = static_cast<const FP_SHAPE*>( *itFp );
223
224 CheckFpShape( expectedShape, shape );
225 }
226 break;
227 /*case PCB_FP_DIM_ALIGNED_T: break;
228 case PCB_FP_DIM_LEADER_T: break;
229 case PCB_FP_DIM_CENTER_T: break;
230 case PCB_FP_DIM_RADIAL_T: break;
231 case PCB_FP_DIM_ORTHOGONAL_T: break;*/
232 default: BOOST_ERROR( "KICAD_T not known" ); break;
233 }
234 }
235
236 std::set<FP_ZONE*, FOOTPRINT::cmp_zones> expectedZones( expected->Zones().begin(),
237 expected->Zones().end() );
238 std::set<FP_ZONE*, FOOTPRINT::cmp_zones> fpZones( fp->Zones().begin(), fp->Zones().end() );
239 for( auto itExpected = expectedZones.begin(), itFp = fpZones.begin();
240 itExpected != expectedZones.end() && itFp != fpZones.end(); itExpected++, itFp++ )
241 {
242 CheckFpZone( *itExpected, *itFp );
243 }
244
245 // TODO: Groups
246}
#define CHECK_ENUM_CLASS_EQUAL(L, R)
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
EDA_ANGLE GetOrientation() const
Definition: footprint.h:191
wxString GetDescription() const
Definition: footprint.h:218
FP_GROUPS & Groups()
Definition: footprint.h:179
int GetAttributes() const
Definition: footprint.h:250
PADS & Pads()
Definition: footprint.h:170
wxString GetTypeName() const
Get the type of footprint.
Definition: footprint.cpp:769
std::vector< FP_3DMODEL > & Models()
Definition: footprint.h:184
const wxString & GetValue() const
Definition: footprint.h:547
const wxString & GetReference() const
Definition: footprint.h:519
int GetFlag() const
Definition: footprint.h:255
FP_ZONES & Zones()
Definition: footprint.h:176
wxString GetKeywords() const
Definition: footprint.h:221
VECTOR2I GetPosition() const override
Definition: footprint.h:188
DRAWINGS & GraphicalItems()
Definition: footprint.h:173
void CheckFpZone(const FP_ZONE *expected, const FP_ZONE *zone)
void CheckFpPad(const PAD *expected, const PAD *pad)
void CheckFpShape(const FP_SHAPE *expected, const FP_SHAPE *shape)
void CheckFpText(const FP_TEXT *expected, const FP_TEXT *text)
VECTOR3I expected(15, 30, 45)
@ PCB_FP_SHAPE_T
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
@ PCB_FP_TEXT_T
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92

References CHECK_ENUM_CLASS_EQUAL, CheckFpPad(), CheckFpShape(), CheckFpText(), CheckFpZone(), expected, FOOTPRINT::GetAttributes(), FOOTPRINT::GetDescription(), FOOTPRINT::GetFlag(), FOOTPRINT::GetKeywords(), FOOTPRINT::GetOrientation(), FOOTPRINT::GetPosition(), FOOTPRINT::GetReference(), FOOTPRINT::GetTypeName(), FOOTPRINT::GetValue(), FOOTPRINT::GraphicalItems(), FOOTPRINT::Groups(), FOOTPRINT::Models(), FOOTPRINT::Pads(), PCB_FP_SHAPE_T, PCB_FP_TEXT_T, text, EDA_ITEM::Type(), and FOOTPRINT::Zones().

Referenced by BOOST_AUTO_TEST_CASE().

◆ CheckFpPad()

void KI_TEST::CheckFpPad ( const PAD expected,
const PAD pad 
)

Definition at line 249 of file board_test_utils.cpp.

250{
251 BOOST_TEST_CONTEXT( "Assert PAD with KIID=" << expected->m_Uuid.AsString() )
252 {
253 CHECK_ENUM_CLASS_EQUAL( expected->Type(), pad->Type() );
254
255 BOOST_CHECK_EQUAL( expected->GetNumber(), pad->GetNumber() );
256 CHECK_ENUM_CLASS_EQUAL( expected->GetAttribute(), pad->GetAttribute() );
257 CHECK_ENUM_CLASS_EQUAL( expected->GetProperty(), pad->GetProperty() );
258 CHECK_ENUM_CLASS_EQUAL( expected->GetShape(), pad->GetShape() );
259
260 BOOST_CHECK_EQUAL( expected->IsLocked(), pad->IsLocked() );
261
262 BOOST_CHECK_EQUAL( expected->GetPosition(), pad->GetPosition() );
263 BOOST_CHECK_EQUAL( expected->GetSize(), pad->GetSize() );
264 BOOST_CHECK_EQUAL( expected->GetOrientation(), pad->GetOrientation() );
265 BOOST_CHECK_EQUAL( expected->GetDelta(), pad->GetDelta() );
266 BOOST_CHECK_EQUAL( expected->GetOffset(), pad->GetOffset() );
267 BOOST_CHECK_EQUAL( expected->GetDrillSize(), pad->GetDrillSize() );
268 CHECK_ENUM_CLASS_EQUAL( expected->GetDrillShape(), pad->GetDrillShape() );
269
270 BOOST_CHECK_EQUAL( expected->GetLayerSet(), pad->GetLayerSet() );
271
272 BOOST_CHECK_EQUAL( expected->GetNetCode(), pad->GetNetCode() );
273 BOOST_CHECK_EQUAL( expected->GetPinFunction(), pad->GetPinFunction() );
274 BOOST_CHECK_EQUAL( expected->GetPinType(), pad->GetPinType() );
275 BOOST_CHECK_EQUAL( expected->GetPadToDieLength(), pad->GetPadToDieLength() );
276 BOOST_CHECK_EQUAL( expected->GetLocalSolderMaskMargin(), pad->GetLocalSolderMaskMargin() );
277 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMargin(),
278 pad->GetLocalSolderPasteMargin() );
279 BOOST_CHECK_EQUAL( expected->GetLocalSolderPasteMarginRatio(),
280 pad->GetLocalSolderPasteMarginRatio() );
281 BOOST_CHECK_EQUAL( expected->GetLocalClearance(), pad->GetLocalClearance() );
282 CHECK_ENUM_CLASS_EQUAL( expected->GetZoneConnection(), pad->GetZoneConnection() );
283 BOOST_CHECK_EQUAL( expected->GetThermalSpokeWidth(), pad->GetThermalSpokeWidth() );
284 BOOST_CHECK_EQUAL( expected->GetThermalSpokeAngle(), pad->GetThermalSpokeAngle() );
285 BOOST_CHECK_EQUAL( expected->GetThermalGap(), pad->GetThermalGap() );
286 BOOST_CHECK_EQUAL( expected->GetRoundRectRadiusRatio(), pad->GetRoundRectRadiusRatio() );
287 BOOST_CHECK_EQUAL( expected->GetChamferRectRatio(), pad->GetChamferRectRatio() );
288 BOOST_CHECK_EQUAL( expected->GetChamferPositions(), pad->GetChamferPositions() );
289 BOOST_CHECK_EQUAL( expected->GetRemoveUnconnected(), pad->GetRemoveUnconnected() );
290 BOOST_CHECK_EQUAL( expected->GetKeepTopBottom(), pad->GetKeepTopBottom() );
291
292 // TODO: check complex pad shapes
293 CHECK_ENUM_CLASS_EQUAL( expected->GetAnchorPadShape(), pad->GetAnchorPadShape() );
294 CHECK_ENUM_CLASS_EQUAL( expected->GetCustomShapeInZoneOpt(),
295 pad->GetCustomShapeInZoneOpt() );
296 }
297}
#define BOOST_TEST_CONTEXT(A)

References BOOST_TEST_CONTEXT, CHECK_ENUM_CLASS_EQUAL, expected, and pad.

Referenced by CheckFootprint().

◆ CheckFpShape()

void KI_TEST::CheckFpShape ( const FP_SHAPE expected,
const FP_SHAPE shape 
)

Definition at line 334 of file board_test_utils.cpp.

335{
336 BOOST_TEST_CONTEXT( "Assert FP_SHAPE with KIID=" << expected->m_Uuid.AsString() )
337 {
338 CHECK_ENUM_CLASS_EQUAL( expected->Type(), shape->Type() );
339
340 CHECK_ENUM_CLASS_EQUAL( expected->GetShape(), shape->GetShape() );
341
342 BOOST_CHECK_EQUAL( expected->IsLocked(), shape->IsLocked() );
343
344 BOOST_CHECK_EQUAL( expected->GetStart(), shape->GetStart() );
345 BOOST_CHECK_EQUAL( expected->GetEnd(), shape->GetEnd() );
346 if( expected->GetShape() == SHAPE_T::ARC )
347 {
348 // center and position might differ as they are calculated from start/mid/end -> compare mid instead
349 BOOST_CHECK_EQUAL( expected->GetArcMid(), shape->GetArcMid() );
350 }
351 else
352 {
353 BOOST_CHECK_EQUAL( expected->GetCenter(), shape->GetCenter() );
354 BOOST_CHECK_EQUAL( expected->GetPosition(), shape->GetPosition() );
355 }
356 BOOST_CHECK_EQUAL( expected->GetBezierC1(), shape->GetBezierC1() );
357 BOOST_CHECK_EQUAL( expected->GetBezierC2(), shape->GetBezierC2() );
358
359 CheckShapePolySet( &expected->GetPolyShape(), &shape->GetPolyShape() );
360
361 BOOST_CHECK_EQUAL( expected->GetLayerSet(), shape->GetLayerSet() );
362
363 BOOST_CHECK_EQUAL( expected->GetStroke().GetWidth(), shape->GetStroke().GetWidth() );
364 CHECK_ENUM_CLASS_EQUAL( expected->GetStroke().GetPlotStyle(),
365 shape->GetStroke().GetPlotStyle() );
366 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), shape->GetFillMode() );
367 }
368}
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:185
virtual bool IsLocked() const
Definition: board_item.cpp:71
const VECTOR2I & GetBezierC2() const
Definition: eda_shape.h:179
FILL_T GetFillMode() const
Definition: eda_shape.h:101
SHAPE_POLY_SET & GetPolyShape()
Definition: eda_shape.h:247
SHAPE_T GetShape() const
Definition: eda_shape.h:113
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition: eda_shape.h:145
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition: eda_shape.h:120
const VECTOR2I & GetBezierC1() const
Definition: eda_shape.h:176
VECTOR2I GetArcMid() const
Definition: eda_shape.cpp:488
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_shape.h:67
STROKE_PARAMS GetStroke() const override
Definition: pcb_shape.h:71
VECTOR2I GetPosition() const override
Definition: pcb_shape.h:65
int GetWidth() const
Definition: stroke_params.h:98
PLOT_DASH_TYPE GetPlotStyle() const
void CheckShapePolySet(const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)

References ARC, BOOST_TEST_CONTEXT, CHECK_ENUM_CLASS_EQUAL, CheckShapePolySet(), expected, EDA_SHAPE::GetArcMid(), EDA_SHAPE::GetBezierC1(), EDA_SHAPE::GetBezierC2(), PCB_SHAPE::GetCenter(), EDA_SHAPE::GetEnd(), EDA_SHAPE::GetFillMode(), BOARD_ITEM::GetLayerSet(), STROKE_PARAMS::GetPlotStyle(), EDA_SHAPE::GetPolyShape(), PCB_SHAPE::GetPosition(), EDA_SHAPE::GetShape(), EDA_SHAPE::GetStart(), PCB_SHAPE::GetStroke(), STROKE_PARAMS::GetWidth(), BOARD_ITEM::IsLocked(), and EDA_ITEM::Type().

Referenced by CheckFootprint().

◆ CheckFpText()

void KI_TEST::CheckFpText ( const FP_TEXT expected,
const FP_TEXT text 
)

Definition at line 300 of file board_test_utils.cpp.

301{
302 BOOST_TEST_CONTEXT( "Assert FP_TEXT with KIID=" << expected->m_Uuid.AsString() )
303 {
304 CHECK_ENUM_CLASS_EQUAL( expected->Type(), text->Type() );
305
306 CHECK_ENUM_CLASS_EQUAL( expected->GetType(), text->GetType() );
307
308 BOOST_CHECK_EQUAL( expected->IsLocked(), text->IsLocked() );
309
310 BOOST_CHECK_EQUAL( expected->GetText(), text->GetText() );
311 BOOST_CHECK_EQUAL( expected->GetPosition(), text->GetPosition() );
312 BOOST_CHECK_EQUAL( expected->GetTextAngle(), text->GetTextAngle() );
313 BOOST_CHECK_EQUAL( expected->IsKeepUpright(), text->IsKeepUpright() );
314
315 BOOST_CHECK_EQUAL( expected->GetLayerSet(), text->GetLayerSet() );
316 BOOST_CHECK_EQUAL( expected->IsVisible(), text->IsVisible() );
317
318 BOOST_CHECK_EQUAL( expected->GetTextSize(), text->GetTextSize() );
319 BOOST_CHECK_EQUAL( expected->GetLineSpacing(), text->GetLineSpacing() );
320 BOOST_CHECK_EQUAL( expected->GetTextThickness(), text->GetTextThickness() );
321 BOOST_CHECK_EQUAL( expected->IsBold(), text->IsBold() );
322 BOOST_CHECK_EQUAL( expected->IsItalic(), text->IsItalic() );
323 BOOST_CHECK_EQUAL( expected->GetHorizJustify(), text->GetHorizJustify() );
324 BOOST_CHECK_EQUAL( expected->GetVertJustify(), text->GetVertJustify() );
325 BOOST_CHECK_EQUAL( expected->IsMirrored(), text->IsMirrored() );
326 BOOST_CHECK_EQUAL( expected->GetFontName(),
327 text->GetFontName() ); // TODO: bold/italic setting?
328
329 // TODO: render cache?
330 }
331}

References BOOST_TEST_CONTEXT, CHECK_ENUM_CLASS_EQUAL, expected, and text.

Referenced by CheckFootprint().

◆ CheckFpZone()

void KI_TEST::CheckFpZone ( const FP_ZONE expected,
const FP_ZONE zone 
)

Definition at line 371 of file board_test_utils.cpp.

372{
373 BOOST_TEST_CONTEXT( "Assert FP_ZONE with KIID=" << expected->m_Uuid.AsString() )
374 {
375 CHECK_ENUM_CLASS_EQUAL( expected->Type(), zone->Type() );
376
377 BOOST_CHECK_EQUAL( expected->IsLocked(), zone->IsLocked() );
378
379 BOOST_CHECK_EQUAL( expected->GetNetCode(), zone->GetNetCode() );
380 BOOST_CHECK_EQUAL( expected->GetAssignedPriority(), zone->GetAssignedPriority() );
381 CHECK_ENUM_CLASS_EQUAL( expected->GetPadConnection(), zone->GetPadConnection() );
382 BOOST_CHECK_EQUAL( expected->GetLocalClearance(), zone->GetLocalClearance() );
383 BOOST_CHECK_EQUAL( expected->GetMinThickness(), zone->GetMinThickness() );
384
385 BOOST_CHECK_EQUAL( expected->GetLayerSet(), zone->GetLayerSet() );
386
387 BOOST_CHECK_EQUAL( expected->IsFilled(), zone->IsFilled() );
388 CHECK_ENUM_CLASS_EQUAL( expected->GetFillMode(), zone->GetFillMode() );
389 BOOST_CHECK_EQUAL( expected->GetHatchThickness(), zone->GetHatchThickness() );
390 BOOST_CHECK_EQUAL( expected->GetHatchGap(), zone->GetHatchGap() );
391 BOOST_CHECK_EQUAL( expected->GetHatchOrientation(), zone->GetHatchOrientation() );
392 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingLevel(), zone->GetHatchSmoothingLevel() );
393 BOOST_CHECK_EQUAL( expected->GetHatchSmoothingValue(), zone->GetHatchSmoothingValue() );
394 BOOST_CHECK_EQUAL( expected->GetHatchBorderAlgorithm(), zone->GetHatchBorderAlgorithm() );
395 BOOST_CHECK_EQUAL( expected->GetHatchHoleMinArea(), zone->GetHatchHoleMinArea() );
396 BOOST_CHECK_EQUAL( expected->GetThermalReliefGap(), zone->GetThermalReliefGap() );
397 BOOST_CHECK_EQUAL( expected->GetThermalReliefSpokeWidth(),
399 BOOST_CHECK_EQUAL( expected->GetCornerSmoothingType(), zone->GetCornerSmoothingType() );
400 BOOST_CHECK_EQUAL( expected->GetCornerRadius(), zone->GetCornerRadius() );
401 CHECK_ENUM_CLASS_EQUAL( expected->GetIslandRemovalMode(), zone->GetIslandRemovalMode() );
402 BOOST_CHECK_EQUAL( expected->GetMinIslandArea(), zone->GetMinIslandArea() );
403
404 BOOST_CHECK_EQUAL( expected->GetIsRuleArea(), zone->GetIsRuleArea() );
405 BOOST_CHECK_EQUAL( expected->GetDoNotAllowCopperPour(), zone->GetDoNotAllowCopperPour() );
406 BOOST_CHECK_EQUAL( expected->GetDoNotAllowVias(), zone->GetDoNotAllowVias() );
407 BOOST_CHECK_EQUAL( expected->GetDoNotAllowTracks(), zone->GetDoNotAllowTracks() );
408 BOOST_CHECK_EQUAL( expected->GetDoNotAllowPads(), zone->GetDoNotAllowPads() );
409 BOOST_CHECK_EQUAL( expected->GetDoNotAllowFootprints(), zone->GetDoNotAllowFootprints() );
410
411 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
412 CHECK_ENUM_CLASS_EQUAL( expected->GetTeardropAreaType(), zone->GetTeardropAreaType() );
413 BOOST_CHECK_EQUAL( expected->GetZoneName(), zone->GetZoneName() );
414
415 CheckShapePolySet( expected->Outline(), zone->Outline() );
416 // TODO: filled zones
417 }
418}
int GetHatchBorderAlgorithm() const
Definition: zone.h:278
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:697
bool GetDoNotAllowVias() const
Definition: zone.h:699
const ISLAND_REMOVAL_MODE GetIslandRemovalMode() const
Definition: zone.h:711
bool GetDoNotAllowPads() const
Definition: zone.h:701
bool GetDoNotAllowTracks() const
Definition: zone.h:700
bool IsFilled() const
Definition: zone.h:242
SHAPE_POLY_SET * Outline()
Definition: zone.h:312
long long int GetMinIslandArea() const
Definition: zone.h:714
wxString GetZoneName() const
Definition: zone.h:124
int GetLocalClearance(wxString *aSource) const override
Return any local clearances set in the "classic" (ie: pre-rule) system.
Definition: zone.cpp:470
int GetMinThickness() const
Definition: zone.h:251
ZONE_CONNECTION GetPadConnection() const
Definition: zone.h:248
int GetHatchThickness() const
Definition: zone.h:260
double GetHatchHoleMinArea() const
Definition: zone.h:275
int GetThermalReliefSpokeWidth() const
Definition: zone.h:195
EDA_ANGLE GetHatchOrientation() const
Definition: zone.h:266
bool GetDoNotAllowFootprints() const
Definition: zone.h:702
ZONE_FILL_MODE GetFillMode() const
Definition: zone.h:174
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: zone.h:122
bool GetDoNotAllowCopperPour() const
Definition: zone.h:698
int GetHatchGap() const
Definition: zone.h:263
TEARDROP_TYPE GetTeardropAreaType() const
Definition: zone.h:692
double GetHatchSmoothingValue() const
Definition: zone.h:272
int GetHatchSmoothingLevel() const
Definition: zone.h:269
unsigned int GetCornerRadius() const
Definition: zone.h:652
int GetCornerSmoothingType() const
Definition: zone.h:648
int GetThermalReliefGap() const
Definition: zone.h:184
unsigned GetAssignedPriority() const
Definition: zone.h:112

References BOOST_TEST_CONTEXT, CHECK_ENUM_CLASS_EQUAL, CheckShapePolySet(), expected, ZONE::GetAssignedPriority(), ZONE::GetCornerRadius(), ZONE::GetCornerSmoothingType(), ZONE::GetDoNotAllowCopperPour(), ZONE::GetDoNotAllowFootprints(), ZONE::GetDoNotAllowPads(), ZONE::GetDoNotAllowTracks(), ZONE::GetDoNotAllowVias(), ZONE::GetFillMode(), ZONE::GetHatchBorderAlgorithm(), ZONE::GetHatchGap(), ZONE::GetHatchHoleMinArea(), ZONE::GetHatchOrientation(), ZONE::GetHatchSmoothingLevel(), ZONE::GetHatchSmoothingValue(), ZONE::GetHatchThickness(), ZONE::GetIslandRemovalMode(), ZONE::GetIsRuleArea(), ZONE::GetLayerSet(), ZONE::GetLocalClearance(), ZONE::GetMinIslandArea(), ZONE::GetMinThickness(), BOARD_CONNECTED_ITEM::GetNetCode(), ZONE::GetPadConnection(), ZONE::GetTeardropAreaType(), ZONE::GetThermalReliefGap(), ZONE::GetThermalReliefSpokeWidth(), ZONE::GetZoneName(), ZONE::IsFilled(), BOARD_ITEM::IsLocked(), ZONE::Outline(), and EDA_ITEM::Type().

Referenced by CheckFootprint().

◆ CheckShapePolySet()

void KI_TEST::CheckShapePolySet ( const SHAPE_POLY_SET expected,
const SHAPE_POLY_SET polyset 
)

Definition at line 421 of file board_test_utils.cpp.

422{
423 BOOST_TEST_CONTEXT( "Assert SHAPE_POLY_SET" )
424 {
425 BOOST_CHECK_EQUAL( expected->OutlineCount(), polyset->OutlineCount() );
426 BOOST_CHECK_EQUAL( expected->TotalVertices(), polyset->TotalVertices() );
427
428 // TODO: check all outlines and holes
429 }
430}
int TotalVertices() const
Delete aIdx-th polygon from the set.
int OutlineCount() const
Return the number of vertices in a given outline/hole.

References BOOST_TEST_CONTEXT, expected, SHAPE_POLY_SET::OutlineCount(), and SHAPE_POLY_SET::TotalVertices().

Referenced by CheckFpShape(), and CheckFpZone().

◆ 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 235 of file unit_test_utils.h.

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

References expected.

Referenced by BOOST_AUTO_TEST_CASE(), 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 281 of file unit_test_utils.h.

282{
283 T sorted = aCollection;
284 std::sort( sorted.begin(), sorted.end() );
285
286 return std::adjacent_find( sorted.begin(), sorted.end() ) == sorted.end();
287}

Referenced by BOOST_AUTO_TEST_CASE().

◆ DrawArc()

void KI_TEST::DrawArc ( FOOTPRINT aFootprint,
const VECTOR2I aCentre,
const VECTOR2I aStart,
const EDA_ANGLE aAngle,
int  aWidth,
PCB_LAYER_ID  aLayer 
)

Draw an arc on a footprint.

Parameters
aModThe footprint to add the segment to
aCentreThe arc centre
aStartThe arc start point
aAngleThe arc angle
aWidthThe width of the arc segment
aLayerThe layer to draw on

Definition at line 59 of file board_construction_utils.cpp.

61{
62 std::unique_ptr<FP_SHAPE> arc = std::make_unique<FP_SHAPE>( &aFootprint, SHAPE_T::ARC );
63
64 arc->SetCenter0( aCentre );
65 arc->SetStart0( aStart );
66 arc->SetArcAngleAndEnd0( aAngle );
67
68 arc->SetStroke( STROKE_PARAMS( aWidth, PLOT_DASH_TYPE::SOLID ) );
69 arc->SetLayer( aLayer );
70
71 aFootprint.Add( arc.release() );
72}
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
Definition: footprint.cpp:567
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88

References FOOTPRINT::Add(), ARC, and SOLID.

Referenced by DrawRect().

◆ DrawPolyline()

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

Draw a polyline - a set of linked segments.

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

Definition at line 49 of file board_construction_utils.cpp.

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

References DrawSegment().

◆ DrawRect()

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

Draw a rectangle on a footprint.

Parameters
aModThe footprint 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 75 of file board_construction_utils.cpp.

77{
78 const auto x_r = aPos.x + aSize.x / 2;
79 const auto x_l = aPos.x - aSize.x / 2;
80 const auto y_t = aPos.y + aSize.y / 2;
81 const auto y_b = aPos.y - aSize.y / 2;
82
83 const auto xin_r = x_r - aRadius;
84 const auto xin_l = x_l + aRadius;
85 const auto yin_t = y_t - aRadius;
86 const auto yin_b = y_b + aRadius;
87
88 // If non-zero (could be zero if it's a stadium shape)
89 if( xin_l != xin_r )
90 {
91 DrawSegment( aFootprint, { { xin_l, y_t }, { xin_r, y_t } }, aWidth, aLayer );
92 DrawSegment( aFootprint, { { xin_l, y_b }, { xin_r, y_b } }, aWidth, aLayer );
93 }
94
95 if( yin_b != yin_t )
96 {
97 DrawSegment( aFootprint, { { x_l, yin_b }, { x_l, yin_t } }, aWidth, aLayer );
98 DrawSegment( aFootprint, { { x_r, yin_b }, { x_r, yin_t } }, aWidth, aLayer );
99 }
100
101 if( aRadius > 0 )
102 {
103 DrawArc( aFootprint, { xin_r, yin_t }, { x_r, yin_t }, ANGLE_90, aWidth, aLayer );
104 DrawArc( aFootprint, { xin_l, yin_t }, { xin_l, y_t }, ANGLE_90, aWidth, aLayer );
105 DrawArc( aFootprint, { xin_l, yin_b }, { x_l, yin_b }, ANGLE_90, aWidth, aLayer );
106 DrawArc( aFootprint, { xin_r, yin_b }, { xin_r, y_b }, ANGLE_90, aWidth, aLayer );
107 }
108}
static constexpr EDA_ANGLE & ANGLE_90
Definition: eda_angle.h:425
void DrawArc(FOOTPRINT &aFootprint, const VECTOR2I &aCentre, const VECTOR2I &aStart, const EDA_ANGLE &aAngle, int aWidth, PCB_LAYER_ID aLayer)
Draw an arc on a footprint.

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

Referenced by AddRectCourtyard().

◆ DrawSegment()

void KI_TEST::DrawSegment ( FOOTPRINT aFootprint,
const SEG aSeg,
int  aWidth,
PCB_LAYER_ID  aLayer 
)

Draw a segment in the given footprint.

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

Definition at line 35 of file board_construction_utils.cpp.

36{
37 std::unique_ptr<FP_SHAPE> seg = std::make_unique<FP_SHAPE>( &aFootprint, SHAPE_T::SEGMENT );
38
39 seg->SetStart0( aSeg.A );
40 seg->SetEnd0( aSeg.B );
41
42 seg->SetStroke( STROKE_PARAMS( aWidth, PLOT_DASH_TYPE::SOLID ) );
43 seg->SetLayer( aLayer );
44
45 aFootprint.Add( seg.release() );
46}
VECTOR2I A
Definition: seg.h:49
VECTOR2I B
Definition: seg.h:50

References SEG::A, FOOTPRINT::Add(), SEG::B, SEGMENT, and SOLID.

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

◆ 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_PLUGIN API.

Note: The aBoard param is non-const because PCB_PLUGIN::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 65 of file board_file_utils.cpp.

66{
67 PCB_PLUGIN io;
68 io.Save( aFilename, &board );
69}
A PLUGIN derivation for saving and loading Pcbnew s-expression formatted files.
Definition: pcb_plugin.h:261
void Save(const wxString &aFileName, BOARD *aBoard, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aBoard to a storage file in a format that this PLUGIN implementation knows about or it can be u...
Definition: pcb_plugin.cpp:271

References PCB_PLUGIN::Save().

Referenced by BOOST_FIXTURE_TEST_CASE(), KI_TEST::BOARD_DUMPER::DumpBoardToFile(), and testSaveLoad().

◆ DumpSchematicToFile()

void KI_TEST::DumpSchematicToFile ( SCHEMATIC aSchematic,
SCH_SHEET aSheet,
const std::string &  aFilename 
)

Definition at line 67 of file schematic_file_util.cpp.

68{
70 io.Save( aFilename, &aSheet, &aSchematic );
71}
A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.
void Save(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...

References SCH_SEXPR_PLUGIN::Save().

◆ 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 70 of file lib_field_test_utils.h.

72{
73 bool ok = true;
74 const auto gotName = aField.GetCanonicalName();
75
76 if( gotName != aExpectedName )
77 {
78 BOOST_TEST_INFO( "Field name: got '" << gotName << "', expected '" << aExpectedName );
79 ok = false;
80 }
81
82 const int gotId = aField.GetId();
83
84 if( gotId != aExpectedId )
85 {
86 BOOST_TEST_INFO( "Field ID: got '" << gotId << "', expected '" << aExpectedId );
87 ok = false;
88 }
89
90 return ok;
91}
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:479
int GetId() const
Definition: lib_field.h:114

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

Referenced by AreDefaultFieldsCorrect(), and BOOST_AUTO_TEST_CASE().

◆ FillZones()

void KI_TEST::FillZones ( BOARD m_board)

Definition at line 108 of file board_test_utils.cpp.

109{
110 TOOL_MANAGER toolMgr;
111 toolMgr.SetEnvironment( m_board, nullptr, nullptr, nullptr, nullptr );
112
113 BOARD_COMMIT commit( &toolMgr );
114 ZONE_FILLER filler( m_board, &commit );
115 std::vector<ZONE*> toFill;
116
117 for( ZONE* zone : m_board->Zones() )
118 toFill.push_back( zone );
119
120 if( filler.Fill( toFill, false, nullptr ) )
121 commit.Push( _( "Fill Zone(s)" ), SKIP_UNDO | SKIP_SET_DIRTY | ZONE_FILL_OP | SKIP_CONNECTIVITY );
122
123 m_board->BuildConnectivity();
124}
#define SKIP_CONNECTIVITY
Definition: board_commit.h:42
#define SKIP_SET_DIRTY
Definition: board_commit.h:41
#define SKIP_UNDO
Definition: board_commit.h:39
#define ZONE_FILL_OP
Definition: board_commit.h:43
ZONES & Zones()
Definition: board.h:313
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:162
Master controller class:
Definition: tool_manager.h:55
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
#define _(s)

References _, BOARD::BuildConnectivity(), ZONE_FILLER::Fill(), BOARD_COMMIT::Push(), TOOL_MANAGER::SetEnvironment(), SKIP_CONNECTIVITY, SKIP_SET_DIRTY, SKIP_UNDO, ZONE_FILL_OP, and BOARD::Zones().

Referenced by BOOST_FIXTURE_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()

std::string KI_TEST::getEeschemaTestDataDir ( )

Definition at line 44 of file schematic_file_util.cpp.

45{
46 const char* env = std::getenv( "KICAD_TEST_EESCHEMA_DATA_DIR" );
47 std::string fn;
48
49 if( !env )
50 {
51 // Use the compiled-in location of the data dir (i.e. where the files were at build time)
53 }
54 else
55 {
56 // Use whatever was given in the env var
57 fn = env;
58 }
59
60 // Ensure the string ends in / to force a directory interpretation
61 fn += "/";
62
63 return fn;
64}
#define QA_EESCHEMA_DATA_LOCATION

References QA_EESCHEMA_DATA_LOCATION.

Referenced by LoadSchematic().

◆ 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 overridden by the KICAD_TEST_EESCHEMA_DATA_DIR environment variable.

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

Definition at line 41 of file eeschema_test_utils.cpp.

42{
43 const char* env = std::getenv( "KICAD_TEST_EESCHEMA_DATA_DIR" );
44 wxString fn;
45
46 if( !env )
47 {
48 // Use the compiled-in location of the data dir
49 // (i.e. where the files were at build time)
51 }
52 else
53 {
54 // Use whatever was given in the env var
55 fn << env;
56 }
57
58 // Ensure the string ends in / to force a directory interpretation
59 fn << "/";
60
61 return wxFileName{ fn };
62}
#define QA_EESCHEMA_DATA_LOCATION

References QA_EESCHEMA_DATA_LOCATION.

Referenced by getEagleTestSchematic(), TEST_SIM_LIBRARY_SPICE_FIXTURE::GetLibraryPath(), KI_TEST::SCHEMATIC_TEST_FIXTURE::GetSchematicPath(), and TEST_SCH_SHEET_LIST_FIXTURE::GetSchematicPath().

◆ GetPcbnewTestDataDir()

std::string KI_TEST::GetPcbnewTestDataDir ( )

Utility which returns a path to the data directory where the test board files are stored.

Definition at line 42 of file board_file_utils.cpp.

43{
44 const char* env = std::getenv( "KICAD_TEST_PCBNEW_DATA_DIR" );
45 std::string fn;
46
47 if( !env )
48 {
49 // Use the compiled-in location of the data dir (i.e. where the files were at build time)
51 }
52 else
53 {
54 // Use whatever was given in the env var
55 fn = env;
56 }
57
58 // Ensure the string ends in / to force a directory interpretation
59 fn += "/";
60
61 return fn;
62}
#define QA_PCBNEW_DATA_LOCATION

References QA_PCBNEW_DATA_LOCATION.

Referenced by BOOST_AUTO_TEST_CASE(), createTestCases(), and LoadBoard().

◆ 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

Get the type of the s-expression.

Definition at line 38 of file sexpr_test_utils.h.

39{
40 if( aSexpr.IsList() )
42 else if( aSexpr.IsSymbol() )
44 else if( aSexpr.IsString() )
46 else if( aSexpr.IsDouble() )
48 else if( aSexpr.IsInteger() )
50
51 throw( std::invalid_argument( "<Unknown S-Expression Type!>" ) );
52}
bool IsInteger() const
Definition: sexpr.h:53
bool IsString() const
Definition: sexpr.h:51
bool IsList() const
Definition: sexpr.h:49
bool IsDouble() const
Definition: sexpr.h:52
bool IsSymbol() const
Definition: sexpr.h:50

References SEXPR::SEXPR::IsDouble(), SEXPR::SEXPR::IsInteger(), SEXPR::SEXPR::IsList(), SEXPR::SEXPR::IsString(), SEXPR::SEXPR::IsSymbol(), 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().

◆ 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}
Define a general 2D-vector/point.
Definition: vector2d.h:74

◆ 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 r
Red component.
Definition: color4d.h:390
double g
Green component.
Definition: color4d.h:391
double a
Alpha component.
Definition: color4d.h:393
double b
Blue component.
Definition: color4d.h:392

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}

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 PCB_MARKER 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}
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition: marker_base.h:105

References 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.

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}

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 formatted 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.

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}

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}

◆ LoadBoard()

void KI_TEST::LoadBoard ( SETTINGS_MANAGER aSettingsManager,
const wxString &  aRelPath,
std::unique_ptr< BOARD > &  aBoard 
)

Definition at line 70 of file board_test_utils.cpp.

72{
73 if( aBoard )
74 {
75 aBoard->SetProject( nullptr );
76 aBoard = nullptr;
77 }
78
79 std::string absPath = GetPcbnewTestDataDir() + aRelPath.ToStdString();
80 wxFileName projectFile( absPath + ".kicad_pro" );
81 wxFileName legacyProject( absPath + ".pro" );
82 std::string boardPath = absPath + ".kicad_pcb";
83 wxFileName rulesFile( absPath + ".kicad_dru" );
84
85 if( projectFile.Exists() )
86 aSettingsManager.LoadProject( projectFile.GetFullPath() );
87 else if( legacyProject.Exists() )
88 aSettingsManager.LoadProject( legacyProject.GetFullPath() );
89
90 aBoard = ReadBoardFromFileOrStream( boardPath );
91
92 if( projectFile.Exists() || legacyProject.Exists() )
93 aBoard->SetProject( &aSettingsManager.Prj() );
94
95 auto m_DRCEngine = std::make_shared<DRC_ENGINE>( aBoard.get(), &aBoard->GetDesignSettings() );
96
97 if( rulesFile.Exists() )
98 m_DRCEngine->InitEngine( rulesFile );
99 else
100 m_DRCEngine->InitEngine( wxFileName() );
101
102 aBoard->GetDesignSettings().m_DRCEngine = m_DRCEngine;
103 aBoard->BuildListOfNets();
104 aBoard->BuildConnectivity();
105}
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.

References GetPcbnewTestDataDir(), SETTINGS_MANAGER::LoadProject(), SETTINGS_MANAGER::Prj(), and ReadBoardFromFileOrStream().

Referenced by BOOST_FIXTURE_TEST_CASE().

◆ LoadHierarchy()

void KI_TEST::LoadHierarchy ( SCHEMATIC schematic,
SCH_SHEET sheet,
const std::string &  sheetFilename,
std::unordered_map< std::string, SCH_SCREEN * > &  parsedScreens 
)

Definition at line 84 of file schematic_file_util.cpp.

86{
87 SCH_SCREEN* screen = nullptr;
88
89 if( !sheet->GetScreen() )
90 {
91 // Construct paths
92 const wxFileName fileName( sheetFilename );
93 const std::string filePath( fileName.GetPath( wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR ) );
94 const std::string fileBareName( fileName.GetFullName() );
95
96 // Check for existing screen
97 auto screenFound = parsedScreens.find( fileBareName );
98 if( screenFound != parsedScreens.end() )
99 screen = screenFound->second;
100
101 // Configure sheet with existing screen, or load screen
102 if( screen )
103 {
104 // Screen already loaded - assign to sheet
105 sheet->SetScreen( screen );
106 sheet->GetScreen()->SetParent( schematic );
107 }
108 else
109 {
110 // Load screen and assign to sheet
111 screen = new SCH_SCREEN( schematic );
112 parsedScreens.insert( { fileBareName, screen } );
113 sheet->SetScreen( screen );
114 sheet->GetScreen()->SetFileName( sheetFilename );
115 LoadSheetSchematicContents( sheetFilename, sheet );
116 }
117
118 // Recurse through child sheets
119 for( SCH_ITEM* item : sheet->GetScreen()->Items().OfType( SCH_SHEET_T ) )
120 {
121 SCH_SHEET* childSheet = static_cast<SCH_SHEET*>( item );
122 wxFileName childSheetFilename = childSheet->GetFileName();
123 if( !childSheetFilename.IsAbsolute() )
124 childSheetFilename.MakeAbsolute( filePath );
125 std::string childSheetFullFilename( childSheetFilename.GetFullPath() );
126 LoadHierarchy( schematic, childSheet, childSheetFullFilename, parsedScreens );
127 }
128 }
129}
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:238
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:109
void SetFileName(const wxString &aFileName)
Set the file name for this screen to aFileName.
Definition: sch_screen.cpp:110
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:302
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:106
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:162
void LoadSheetSchematicContents(const std::string &fileName, SCH_SHEET *sheet)
void LoadHierarchy(SCHEMATIC *schematic, SCH_SHEET *sheet, const std::string &sheetFilename, std::unordered_map< std::string, SCH_SCREEN * > &parsedScreens)
@ SCH_SHEET_T
Definition: typeinfo.h:158

References SCH_SHEET::GetFileName(), SCH_SHEET::GetScreen(), SCH_SCREEN::Items(), LoadHierarchy(), LoadSheetSchematicContents(), EE_RTREE::OfType(), SCH_SHEET_T, SCH_SCREEN::SetFileName(), EDA_ITEM::SetParent(), and SCH_SHEET::SetScreen().

Referenced by LoadHierarchy(), and LoadHierarchyFromRoot().

◆ LoadHierarchyFromRoot()

std::unique_ptr< SCHEMATIC > KI_TEST::LoadHierarchyFromRoot ( const std::string &  rootFilename,
PROJECT project 
)

Definition at line 131 of file schematic_file_util.cpp.

133{
134 std::unique_ptr<SCHEMATIC> schematic( new SCHEMATIC( nullptr ) );
135 std::unordered_map<std::string, SCH_SCREEN*> parsedScreens;
136
137 schematic->SetProject( project );
138 SCH_SHEET* rootSheet = new SCH_SHEET( schematic.get() );
139 schematic->SetRoot( rootSheet );
140 LoadHierarchy( schematic.get(), rootSheet, rootFilename, parsedScreens );
141
142 return schematic;
143}
Holds all the data relating to one schematic.
Definition: schematic.h:61

References LoadHierarchy(), and project.

Referenced by LoadSchematic().

◆ LoadSchematic()

void KI_TEST::LoadSchematic ( SETTINGS_MANAGER aSettingsManager,
const wxString &  aRelPath,
std::unique_ptr< SCHEMATIC > &  aSchematic 
)

Definition at line 146 of file schematic_file_util.cpp.

148{
149 if( aSchematic )
150 {
151 PROJECT* prj = &aSchematic->Prj();
152
153 aSchematic->SetProject( nullptr );
154 aSettingsManager.UnloadProject( prj, false );
155 aSchematic->Reset();
156 }
157
158 std::string absPath = getEeschemaTestDataDir() + aRelPath.ToStdString();
159 wxFileName projectFile( absPath + ".kicad_pro" );
160 wxFileName legacyProject( absPath + ".pro" );
161 std::string schematicPath = absPath + ".kicad_sch";
162
163 if( projectFile.Exists() )
164 aSettingsManager.LoadProject( projectFile.GetFullPath() );
165 else if( legacyProject.Exists() )
166 aSettingsManager.LoadProject( legacyProject.GetFullPath() );
167 else
168 aSettingsManager.LoadProject( "" );
169
170 aSettingsManager.Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
171
172 aSchematic = LoadHierarchyFromRoot( schematicPath, &aSettingsManager.Prj() );
173
174 aSchematic->CurrentSheet().push_back( &aSchematic->Root() );
175
176 SCH_SCREENS screens( aSchematic->Root() );
177
178 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
179 screen->UpdateLocalLibSymbolLinks();
180
181 SCH_SHEET_LIST sheets = aSchematic->GetSheets();
182
183 // Restore all of the loaded symbol instances from the root sheet screen.
184 sheets.UpdateSymbolInstanceData( aSchematic->RootScreen()->GetSymbolInstances() );
185 sheets.UpdateSheetInstanceData( aSchematic->RootScreen()->GetSheetInstances() );
186
187 if( aSchematic->RootScreen()->GetFileFormatVersionAtLoad() < 20221206 )
188 {
189 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
190 screen->MigrateSimModels();
191 }
192
193 sheets.AnnotatePowerSymbols();
194
195 // NOTE: This is required for multi-unit symbols to be correct
196 // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
197 for( SCH_SHEET_PATH& sheet : sheets )
198 sheet.UpdateAllScreenReferences();
199
200 // NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
201 // SchematicCleanUp must be freed from its UI dependencies.
202
203 aSchematic->ConnectionGraph()->Recalculate( sheets, true );
204}
Container for project specific data.
Definition: project.h:64
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:294
@ ELEM_SCH_SYMBOL_LIBS
Definition: project.h:208
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:638
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void UpdateSheetInstanceData(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
void UpdateSymbolInstanceData(const std::vector< SCH_SYMBOL_INSTANCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
std::unique_ptr< SCHEMATIC > LoadHierarchyFromRoot(const std::string &rootFilename, PROJECT *project)
std::string getEeschemaTestDataDir()

References SCH_SHEET_LIST::AnnotatePowerSymbols(), PROJECT::ELEM_SCH_SYMBOL_LIBS, getEeschemaTestDataDir(), SCH_SCREENS::GetFirst(), SCH_SCREENS::GetNext(), LoadHierarchyFromRoot(), SETTINGS_MANAGER::LoadProject(), SETTINGS_MANAGER::Prj(), PROJECT::SetElem(), SETTINGS_MANAGER::UnloadProject(), SCH_SHEET_LIST::UpdateSheetInstanceData(), and SCH_SHEET_LIST::UpdateSymbolInstanceData().

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), and TEST_NETLIST_EXPORTER_FIXTURE< Exporter >::TestNetlist().

◆ LoadSheetSchematicContents()

void KI_TEST::LoadSheetSchematicContents ( const std::string &  fileName,
SCH_SHEET sheet 
)

Definition at line 73 of file schematic_file_util.cpp.

74{
75 std::ifstream fileStream;
76 fileStream.open( fileName );
77 wxASSERT( fileStream.is_open() );
79 reader.SetStream( fileStream );
80 SCH_SEXPR_PARSER parser( &reader );
81 parser.ParseSchematic( sheet );
82}
Object to parser s-expression symbol library and schematic file formats.
LINE_READER that wraps a given std::istream instance.
void SetStream(std::istream &aStream)
Set the stream for this line reader.

References SCH_SEXPR_PARSER::ParseSchematic(), and STDISTREAM_LINE_READER::SetStream().

Referenced by LoadHierarchy().

◆ 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 93 of file board_file_utils.cpp.

95{
96 std::istream* in_stream = nullptr;
97 std::ifstream file_stream;
98
99 if( aFilename.empty() )
100 {
101 // no file, read stdin
102 in_stream = &aFallback;
103 }
104 else
105 {
106 file_stream.open( aFilename );
107 in_stream = &file_stream;
108 }
109
110 return ReadItemFromStream<BOARD>( *in_stream );
111}

Referenced by BOOST_FIXTURE_TEST_CASE(), LoadBoard(), loadKicadProject(), polygon_gererator_main(), polygon_triangulation_main(), and testSaveLoad().

◆ ReadBoardItemFromStream()

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

Utility function to read a BOARD_ITEM (probably a FOOTPRINT 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 72 of file board_file_utils.cpp.

73{
74 // Take input from stdin
76 reader.SetStream( aStream );
77
78 PCB_PARSER parser( &reader, nullptr, nullptr );
79 std::unique_ptr<BOARD_ITEM> board;
80
81 try
82 {
83 board.reset( parser.Parse() );
84 }
85 catch( const IO_ERROR& )
86 {
87 }
88
89 return board;
90}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
Read a Pcbnew s-expression formatted LINE_READER object and returns the appropriate BOARD_ITEM object...
Definition: pcb_parser.h:74

References PCB_PARSER::Parse(), and STDISTREAM_LINE_READER::SetStream().

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 FOOTPRINT or BOARD)
Parameters
aStreamthe stream to read from.

Definition at line 77 of file board_file_utils.h.

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

References ReadBoardItemFromStream().

◆ ReadSchematicFromFile()

std::unique_ptr< SCHEMATIC > KI_TEST::ReadSchematicFromFile ( const std::string &  aFilename,
PROJECT aProject 
)

◆ ReadSchematicFromStream()

std::unique_ptr< SCHEMATIC > KI_TEST::ReadSchematicFromStream ( std::istream &  aStream,
PROJECT aProject 
)

◆ 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

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 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.

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

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}

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}
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}

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

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}

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

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

Referenced by BOOST_AUTO_TEST_CASE().