KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
 
class  DUMMY_TOOL
 
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.
 

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.
 
void DrawPolyline (FOOTPRINT &aFootprint, const std::vector< VECTOR2I > &aPts, int aWidth, PCB_LAYER_ID aLayer)
 Draw a polyline - a set of linked segments.
 
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.
 
void DrawRect (FOOTPRINT &aFootprint, const VECTOR2I &aPos, const VECTOR2I &aSize, int aRadius, int aWidth, PCB_LAYER_ID aLayer)
 Draw a rectangle on a footprint.
 
std::string GetPcbnewTestDataDir ()
 Utility which returns a path to the data directory where the test board files are stored.
 
void DumpBoardToFile (BOARD &aBoard, const std::string &aFilename)
 Utility function to simply write a Board out to a file.
 
std::unique_ptr< BOARD_ITEMReadBoardItemFromStream (std::istream &aStream)
 Utility function to read a BOARD_ITEM (probably a FOOTPRINT or a BOARD) from a file.
 
std::unique_ptr< BOARDReadBoardFromFileOrStream (const std::string &aFilename, std::istream &aFallback=std::cin)
 Read a board from a file, or another stream, as appropriate.
 
std::unique_ptr< FOOTPRINTReadFootprintFromFileOrStream (const std::string &aFilename, std::istream &aFallback)
 
void LoadBoard (SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
 
BOARD_ITEMRequireBoardItemWithTypeAndId (const BOARD &aBoard, KICAD_T aItemType, const KIID &aID)
 Get an item from the given board with a certain type and UUID.
 
void LoadAndTestBoardFile (const wxString aRelativePath, bool aRoundtrip, std::function< void(BOARD &)> aBoardTestFunction, std::optional< int > aExpectedBoardVersion=std::nullopt)
 Perform "some test" on a board file loaded from the path, then optionally save and reload and run the test again.
 
void FillZones (BOARD *m_board)
 
void CheckFootprint (const FOOTPRINT *expected, const FOOTPRINT *fp)
 Helper method to check if two footprints are semantically the same.
 
void CheckFpPad (const PAD *expected, const PAD *pad)
 
void CheckFpText (const PCB_TEXT *expected, const PCB_TEXT *text)
 
void CheckFpShape (const PCB_SHAPE *expected, const PCB_SHAPE *shape)
 
void CheckFpZone (const ZONE *expected, const ZONE *zone)
 
void CheckShapePolySet (const SHAPE_POLY_SET *expected, const SHAPE_POLY_SET *polyset)
 
template<typename ITEM >
std::unique_ptr< ITEMReadItemFromStream (std::istream &aStream)
 Read a specific kind of BOARD_ITEM from a stream.
 
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.
 
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.
 
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)
 
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.
 
SEG BuildHSeg (const VECTOR2I &aStart, int aLength)
 Build a horizontal segment from a point with a length.
 
SEG BuildVSeg (const VECTOR2I &aStart, int aLength)
 Build a vertical segment from a point with a length.
 
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.
 
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.
 
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.
 
template<typename T >
bool IsWithin (T aValue, T aNominal, T aError)
 Check if a value is within a tolerance of a nominal value.
 
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.
 
template<typename T >
bool IsWithinAndBelow (T aValue, T aNominal, T aErrorBelow)
 value is in range [aNominal - aErrorBelow, aNominal]
 
template<typename T >
bool IsWithinAndAbove (T aValue, T aNominal, T aErrorAbove)
 value is in range [aNominal, aNominal + aErrorAbove]
 
bool IsUUID (const std::string &aStr)
 Check if the string between the iterators looks like a UUID.
 
bool IsUUIDPathWithLevels (const std::string &aStr, unsigned aLevels)
 Predicate to check a string is a UUID path format.
 
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.
 
template<typename T >
bool CollectionHasNoDuplicates (const T &aCollection)
 Predicate to check a collection has no duplicate elements.
 
std::string GetEeschemaTestDataDir ()
 Get the configured location of Eeschema test data.
 
void wxAssertThrower (const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
 
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.
 
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.
 
bool IsImagePixelOfColor (const wxImage &aImage, int aX, int aY, const KIGFX::COLOR4D &aColor)
 Predicate to check an image pixel matches color and alpha.
 
bool FieldNameIdMatches (const SCH_FIELD &aField, const std::string &aExpectedName, int aExpectedId)
 Predicate to check a field name is as expected.
 
bool AreDefaultFieldsCorrect (const std::vector< SCH_FIELD > &aFields)
 Predicate to check that the mandatory fields look sensible.
 
SEXPR::SEXPR_TYPE getType (const SEXPR::SEXPR &aSexpr)
 Get the type of the s-expression.
 
std::string getDebugType (SEXPR::SEXPR_TYPE aType)
 Get a debug-friendly string for a given s-expr type.
 
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.
 
bool SexprIsSymbol (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a symbol?
 
bool SexprIsSymbolWithValue (const SEXPR::SEXPR &aSexpr, const std::string &aVal)
 Test predicate: is the s-expression a symbol with the given value?
 
bool SexprIsString (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a string?
 
bool SexprIsStringWithValue (const SEXPR::SEXPR &aSexpr, const std::string &aVal)
 Test predicate: is the s-expression a string with the given value?
 
bool SexprIsInteger (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression an integer?
 
bool SexprIsIntegerWithValue (const SEXPR::SEXPR &aSexpr, std::int64_t aVal)
 Test predicate: is the s-expression an integer with the given value?
 
bool SexprIsDouble (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a double?
 
bool SexprIsDoubleWithValue (const SEXPR::SEXPR &aSexpr, double aVal)
 Test predicate: is the s-expression a double with the given value?
 
bool SexprIsList (const SEXPR::SEXPR &aSexpr)
 Test predicate: is the s-expression a double?
 
bool SexprIsListOfLength (const SEXPR::SEXPR &aSexpr, size_t aExpectedLength)
 Test predicate: is the s-expression a list with the given length?
 
bool SexprConvertsToString (const SEXPR::SEXPR &aSexpr, const std::string &aExpStr)
 Predicate to check an SEXPR object converts to the expected string.
 
bool IsDrcMarkerOfType (const PCB_MARKER &aMarker, int aErrorCode)
 Predicate for testing the type of a DRC marker.
 

Typedef Documentation

◆ EXP_OBJ

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

Definition at line 149 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 150 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 169 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.

Function Documentation

◆ AreDefaultFieldsCorrect()

bool KI_TEST::AreDefaultFieldsCorrect ( const std::vector< SCH_FIELD > &  aFields)

Predicate to check that the mandatory fields look sensible.

Definition at line 86 of file lib_field_test_utils.h.

References FieldNameIdMatches().

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.

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

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

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

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

References SHAPE_POLY_SET::AddOutline().

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

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.

References BuildRectChain().

Referenced by TestSquareFillet().

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

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

◆ CheckFootprint()

◆ CheckFpPad()

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

Definition at line 329 of file board_test_utils.cpp.

References PADSTACK::ALL_LAYERS, CHECK_ENUM_CLASS_EQUAL, CheckFpShape(), expected, and pad.

Referenced by CheckFootprint().

◆ CheckFpShape()

◆ CheckFpText()

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

Definition at line 405 of file board_test_utils.cpp.

References CHECK_ENUM_CLASS_EQUAL, expected, and text.

Referenced by CheckFootprint().

◆ CheckFpZone()

◆ CheckShapePolySet()

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

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

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 62 of file board_construction_utils.cpp.

References FOOTPRINT::Add(), FOOTPRINT::GetOrientation(), and FOOTPRINT::GetPosition().

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 52 of file board_construction_utils.cpp.

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 81 of file board_construction_utils.cpp.

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.

References SEG::A, FOOTPRINT::Add(), SEG::B, FOOTPRINT::GetOrientation(), and FOOTPRINT::GetPosition().

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

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

References PCB_IO_KICAD_SEXPR::SaveBoard().

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

◆ DumpSchematicToFile()

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

Definition at line 40 of file schematic_file_util.cpp.

References SCH_IO_KICAD_SEXPR::SaveSchematicFile().

◆ FieldNameIdMatches()

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

Predicate to check a field name is as expected.

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

Definition at line 61 of file lib_field_test_utils.h.

References SCH_FIELD::GetCanonicalName(), and SCH_FIELD::GetId().

Referenced by AreDefaultFieldsCorrect(), and BOOST_AUTO_TEST_CASE().

◆ FillZones()

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

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 ( )

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 37 of file unit_test_utils.cpp.

References QA_EESCHEMA_DATA_LOCATION.

Referenced by BOOST_AUTO_TEST_CASE(), getCadstarTestFile(), getEagleTestSchematic(), TEST_SIM_LIBRARY_SPICE_FIXTURE::GetLibraryPath(), KI_TEST::SCHEMATIC_TEST_FIXTURE::GetSchematicPath(), TEST_NETLIST_EXPORTER_SPICE_FIXTURE::GetSchematicPath(), TEST_SIM_REGRESSIONS_FIXTURE::GetSchematicPath(), TEST_SCH_SHEET_LIST_FIXTURE::GetSchematicPath(), TEST_SCHEMATIC_FIXTURE::GetSchematicPath(), and LoadSchematic().

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

References QA_PCBNEW_DATA_LOCATION.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_DATA_TEST_CASE(), BOOST_FIXTURE_TEST_CASE(), createTestCases(), LoadAndTestBoardFile(), and LoadBoard().

◆ GetSexprDebugType()

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

Definition at line 76 of file sexpr_test_utils.h.

References getDebugType(), and getType().

Referenced by SEXPR::boost_test_print_type().

◆ getType()

◆ 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 61 of file geometry.h.

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

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

Referenced by BOOST_AUTO_TEST_CASE().

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

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.

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

References IsColorNearHex().

Referenced by BOOST_AUTO_TEST_CASE().

◆ IsSexprOfType()

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

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 30 of file uuid_test_utils.cpp.

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 39 of file uuid_test_utils.cpp.

References 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 51 of file geometry.h.

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

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.

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.

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.

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.

◆ LoadAndTestBoardFile()

void KI_TEST::LoadAndTestBoardFile ( const wxString  aRelativePath,
bool  aRoundtrip,
std::function< void(BOARD &)>  aBoardTestFunction,
std::optional< int >  aExpectedBoardVersion = std::nullopt 
)

Perform "some test" on a board file loaded from the path, then optionally save and reload and run the test again.

The roundtrip is useful to test stability of serialisation/reload.

Parameters
aRelativePathrelative path of file to load
aRoundtriptrue to save, reload and re-test
aBoardTestFunctionthe function that runs tests on the board
aExpectedBoardVersionthe expected board version, or nullopt to not check

Definition at line 130 of file board_test_utils.cpp.

References DumpBoardToFile(), GetPcbnewTestDataDir(), and ReadBoardFromFileOrStream().

Referenced by BOOST_FIXTURE_TEST_CASE().

◆ LoadBoard()

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

◆ LoadHierarchy()

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

◆ LoadHierarchyFromRoot()

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

Definition at line 104 of file schematic_file_util.cpp.

References LoadHierarchy(), and project.

Referenced by LoadSchematic().

◆ LoadSchematic()

◆ LoadSheetSchematicContents()

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

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

Referenced by BOOST_FIXTURE_TEST_CASE(), LoadAndTestBoardFile(), 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 73 of file board_file_utils.cpp.

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

Referenced by ReadItemFromStream().

◆ ReadFootprintFromFileOrStream()

std::unique_ptr< FOOTPRINT > KI_TEST::ReadFootprintFromFileOrStream ( const std::string &  aFilename,
std::istream &  aFallback 
)

Definition at line 122 of file board_file_utils.cpp.

◆ 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 78 of file board_file_utils.h.

References ITEM, and 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 
)

◆ RequireBoardItemWithTypeAndId()

BOARD_ITEM & KI_TEST::RequireBoardItemWithTypeAndId ( const BOARD aBoard,
KICAD_T  aItemType,
const KIID aID 
)

Get an item from the given board with a certain type and UUID.

If this doesn't exist, it's a BOOST_REQUIRE failure.

Parameters
aBoardthe board to look in
aItemTypethe required item type
aIDthe required
Returns
BOARD_ITEM& the required board item

Definition at line 119 of file board_test_utils.cpp.

References BOARD::GetItem(), and EDA_ITEM::Type().

Referenced by BOOST_FIXTURE_TEST_CASE().

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

References SEXPR::SEXPR::AsString().

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

Referenced by BOOST_AUTO_TEST_CASE().

◆ wxAssertThrower()

void KI_TEST::wxAssertThrower ( const wxString &  aFile,
int  aLine,
const wxString &  aFunc,
const wxString &  aCond,
const wxString &  aMsg 
)
inline

Definition at line 71 of file wx_assert.h.

Referenced by init_unit_test().