22#include <boost/test/data/test_case.hpp>
64 {
"10mm + 20 mm",
false,
VAL( 30e6 ) },
65 {
"3*(7+8)",
false,
VAL( 3 * ( 7 + 8 ) ) },
66 {
"3*7+8",
false,
VAL( 3 * 7 + 8 ) },
67 {
"(3*7)+8",
false,
VAL( 3 * 7 + 8 ) },
68 {
"10mm + 20)",
true,
VAL( 0 ) },
70 {
"1",
false,
VAL(1) },
71 {
"1.5",
false,
VAL(1.5) },
72 {
"1,5",
false,
VAL(1.5) },
73 {
"1mm",
false,
VAL(1e6) },
75 {
" 1 + 2 ",
false,
VAL(3) },
77 {
"1.5 + 0.2 + 0.1",
false,
VAL(1.8) },
79 {
"3 - 10",
false,
VAL(-7) },
81 {
"1 + 2 + 10 + 1000.05",
false,
VAL(1013.05) },
83 {
"1 + 2 - 4 * 20 / 2",
false,
VAL(-37) },
85 {
"(1)",
false,
VAL(1) },
87 {
"-(1 + (2 - 4)) * 20.8 / 2",
false,
VAL(10.4) },
89 {
"+2 - 1",
false,
VAL(1) },
92 {
"(2 || 0) == 1",
false,
VAL(1) },
93 {
"(7 || 0) + 5",
false,
VAL(6) }
98 {
"A.type == 'Pad' && B.type == 'Pad' && (A.existsOnLayer('F.Cu'))",
false,
VAL( 0.0 ) },
99 {
"A.Width > B.Width",
false,
VAL( 0.0 ) },
101 {
"A.Netclass",
false,
VAL(
"HV_LINE" ) },
102 {
"A.Net_Class == 'HV_LINE'",
false,
VAL( 1.0 ) },
103 {
"(A.Netclass == 'HV_LINE') && (B.netclass == 'otherClass') && (B.netclass != 'F.Cu')",
false,
VAL( 1.0 ) },
104 {
"A.Netclass + 1.0",
false,
VAL( 1.0 ) },
105 {
"A.hasNetclass('HV_LINE')",
false,
VAL( 1.0 ) },
106 {
"A.hasNetclass('HV_*')",
false,
VAL( 1.0 ) },
107 {
"A.existsOnLayer(B.Layer)",
false,
VAL( 1.0 ) },
108 {
"A.type == 'Track' && B.type == 'Track' && A.layer == 'F.Cu'",
false,
VAL( 1.0 ) },
109 {
"(A.type == 'Track') && (B.type == 'Track') && (A.layer == 'F.Cu')",
false,
VAL( 1.0 ) },
110 {
"A.type == 'Via' && A.isMicroVia()",
false,
VAL(0.0) }
128 bool error = !compiler.
Compile( expr, &ucode, &preflightContext );
132 if( error != expectError )
148 ok = (
result->EqualTo( &context, &expectedResult ) );
170 compiler.
Compile( aExpr, &ucode, &preflight );
172 BOOST_CHECK_MESSAGE( compiler.
IsErrorPending(),
"Expected a compile error for: " << aExpr.mb_str() );
182 compiler.
Compile( aExpr, &ucode, &preflight );
184 BOOST_CHECK_MESSAGE( !compiler.
IsErrorPending(),
"Expected expression to compile: " << aExpr.mb_str() );
190 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError );
203 std::shared_ptr<NETCLASS> netclass1(
new NETCLASS(
"HV_LINE" ) );
204 std::shared_ptr<NETCLASS> netclass2(
new NETCLASS(
"otherClass" ) );
215 trackA.
SetNet( net1info );
216 trackB.
SetNet( net2info );
225 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError, &trackA, &trackB );
244 testEvalExpr( wxT(
"A.Hatch_Orientation == 45deg" ),
VAL( 1.0 ),
false, &zone );
245 testEvalExpr( wxT(
"A.Minimum_Island_Area == 123456789" ),
VAL( 1.0 ),
false, &zone );
250 testEvalExpr( wxT(
"A.Ellipse_Rotation == 30deg" ),
VAL( 1.0 ),
false, &ellipse );
255 testEvalExpr( wxT(
"A.Solderpaste_Margin_Ratio_Override == 0.125" ),
VAL( 1.0 ),
false, &footprint );
259 testEvalExpr( wxT(
"A.Solderpaste_Margin_Ratio_Override == null" ),
VAL( 1.0 ),
false, &footprint );
279 testEvalExpr( wxT(
"A.Origin_X != A.End_X" ),
VAL( 1.0 ),
false, &track );
280 testEvalExpr( wxT(
"A.origin_y != A.End_Y" ),
VAL( 1.0 ),
false, &track );
296 [&](
const COLOR4D& aColor,
const wxString& aExpectedCss )
298 table.SetBorderColor( aColor );
301 wxString expression = wxT(
"A.Border_Color == '" ) + aExpectedCss + wxT(
"'" );
305 checkColor(
COLOR4D( 0.25, 0.5, 0.75, 0.5 ), wxT(
"rgba(64, 128, 191, 0.502)" ) );
307 checkColor(
COLOR4D( wxString( wxT(
"red" ) ) ), wxT(
"rgb(255, 0, 0)" ) );
317 std::set<std::pair<TYPE_ID, PROPERTY_BASE*>> seen;
318 std::map<wxString, std::set<LIBEVAL::VAR_TYPE_T>> fieldTypes;
327 if( !seen.emplace( cls.type, prop ).second )
333 "Unsupported expression property: class=" << cls.name.mb_str()
334 <<
", property=" << prop->
Name().mb_str()
335 <<
", type_hash=" << prop->
TypeHash() );
344 auto shapeTypes = fieldTypes.find( wxT(
"Shape" ) );
347 fieldTypes.erase( shapeTypes );
349 for(
const auto& [field, types] : fieldTypes )
351 BOOST_CHECK_MESSAGE( types.size() == 1,
"Incompatible expression types for property: " << field.mb_str() );
386 netSettings->SetNetChainClass( wxT(
"ChainHS" ), wxT(
"HighSpeed" ) );
392 netUnclassified->
SetNetChain( wxT(
"ChainOrphan" ) );
399 trackUnclassified.
SetNet( netUnclassified );
400 trackClassified.
SetNet( netClassified );
401 trackNoChain.
SetNet( netNoChain );
405 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 0.0 ),
false, &trackUnclassified, &trackUnclassified );
406 testEvalExpr( wxT(
"A.inNetChainClass('HighSpeed')" ),
VAL( 0.0 ),
false, &trackUnclassified, &trackUnclassified );
409 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 0.0 ),
false, &trackNoChain, &trackNoChain );
412 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 1.0 ),
false, &trackClassified, &trackClassified );
413 testEvalExpr( wxT(
"A.inNetChainClass('HighSpeed')" ),
VAL( 1.0 ),
false, &trackClassified, &trackClassified );
414 testEvalExpr( wxT(
"A.inNetChainClass('High*')" ),
VAL( 1.0 ),
false, &trackClassified, &trackClassified );
415 testEvalExpr( wxT(
"A.inNetChainClass('LowSpeed')" ),
VAL( 0.0 ),
false, &trackClassified, &trackClassified );
431 via->SetPosition( aPos );
432 via->SetLayerPair( aTop, aBottom );
457 testEvalExpr( wxT(
"A.isStackedVia()" ),
VAL( 1.0 ),
false, upperHop, upperHop );
458 testEvalExpr( wxT(
"A.isStackedVia()" ),
VAL( 1.0 ),
false, lowerHop, lowerHop );
461 testEvalExpr( wxT(
"A.isStackedVia()" ),
VAL( 0.0 ),
false, lone, lone );
464 testEvalExpr( wxT(
"A.isStackedVia()" ),
VAL( 0.0 ),
false, through, through );
467 testEvalExpr( wxT(
"A.isMicroVia() && !A.isStackedVia()" ),
VAL( 1.0 ),
false, lone, lone );
473 testEvalExpr( wxT(
"A.isStackedVia()" ),
VAL( 1.0 ),
false, lone, lone );
474 testEvalExpr( wxT(
"A.isStackedVia()" ),
VAL( 1.0 ),
false, landing, landing );
490 text->SetText( wxT(
"J1" ) );
542 compiler.
Compile( wxT(
"L.Layer == '*.Paste'" ), &ucode, &preflight );
550 paste.SetItems( &track, &track );
582 for(
const wxString& expression : {
583 wxString(
"A.intersectsFrontCourtyard(B.Parent)" ),
584 wxString(
"A.intersectsCourtyard(B.Parent.Reference)" ),
585 wxString(
"A.intersectsFrontCourtyard(B.Parent.getField('Reference'))" ) } )
598 context.
SetItems( &graphic, &targetChild );
601 context.
SetItems( &graphic, &otherChild );
604 context.
SetItems( &graphic, &targetChild );
618 expectCompileError( wxS(
"A.intersectsFrontCourtyard(B.Parent.unknownFunction())" ) );
626 for(
const wxString& constraint : {
627 wxString(
"assertion \"A.Type == 'Graphic'\"" ),
628 wxString(
"hole_size (min 0.2mm)" ), wxString(
"text_height (min 1mm)" ),
629 wxString(
"text_thickness (min 0.1mm)" ),
630 wxString(
"track_segment_length (min 1mm)" ), wxString(
"annular_width (min 0.1mm)" ),
631 wxString(
"solder_mask_expansion (opt 0mm)" ),
632 wxString(
"solder_paste_abs_margin (opt 0mm)" ),
633 wxString(
"solder_paste_rel_margin (opt 0mm)" ), wxString(
"disallow track" ),
634 wxString(
"via_diameter (min 0.5mm)" ), wxString(
"length (max 100mm)" ),
635 wxString(
"net_chain_length (max 100mm)" ), wxString(
"stub_length (max 1mm)" ),
636 wxString(
"return_path (layer 'B.Cu')" ), wxString(
"skew (max 1mm)" ),
637 wxString(
"via_count (max 2)" ),
638 wxString(
"via_dangling (max 0)" ), wxString(
"bridged_mask (min 0)" ),
639 wxString(
"microvia_stack_depth (max 2)" ), wxString(
"microvia_aspect_ratio (max 1)" ) } )
641 for(
bool conditionFirst : {
true,
false } )
645 wxString condition = wxS(
"(condition \"B.Type == 'Graphic'\")" );
646 wxString body = wxString::Format( wxS(
"(constraint %s)" ), constraint );
647 wxString source = wxS(
"(version 1)\n(rule test\n" )
648 + ( conditionFirst ? condition + wxS(
"\n" ) + body
649 : body + wxS(
"\n" ) + condition ) + wxS(
"\n)" );
650 std::vector<std::shared_ptr<DRC_RULE>> rules;
652 wxString controlSource = source;
653 controlSource.Replace( wxS(
"B.Type" ), wxS(
"A.Type" ) );
654 DRC_RULES_PARSER controlParser( controlSource, wxS(
"single item control" ) );
656 BOOST_REQUIRE_MESSAGE( !
reporter.GetMessages().Contains( wxS(
"ERROR:" ) ),
reporter.GetMessages() );
661 BOOST_CHECK_MESSAGE(
reporter.GetMessages().Contains( wxS(
"Item 'B'" ) ),
668 return error.What().Contains( wxS(
"Item 'B' is not available" ) )
669 && error.lineNumber == ( conditionFirst ? 3 : 4 );
681 for(
const wxString& body : {
682 wxString(
"(condition \"A.intersectsFrontCourtyard(B.Parent)\")"
683 "(constraint assertion \"A.Type == 'Graphic'\")" ),
684 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint hole_size (min 0.2mm))" ),
685 wxString(
"(constraint assertion \"B.Type == 'Graphic'\")" ),
686 wxString(
"(constraint assertion \"A.intersectsFrontCourtyard(B.Parent.getField('Reference'))\")" ),
687 wxString(
"(condition \"B.Type == 'Graphic'\")(constraint clearance (min 0.2mm))"
688 "(constraint hole_size (min 0.2mm))" ),
689 wxString(
"(condition \"AB.isCoupledDiffPair() && B.Type == 'Track'\")"
690 "(constraint length (max 100mm))" ) } )
694 std::vector<std::shared_ptr<DRC_RULE>> rules;
695 DRC_RULES_PARSER parser( wxS(
"(version 1)(rule test " ) + body + wxS(
")" ), wxS(
"preflight" ) );
699 return error.What().Contains( wxS(
"Item 'B' is not available" ) );
704 for(
const wxString& body : {
705 wxString(
"(condition \"A.Reference == 'B.Width'\")(constraint hole_size (min 0.2mm))" ),
706 wxString(
"(constraint assertion \"A.Type == 'Graphic'\")" ),
707 wxString(
"(condition \"A.intersectsFrontCourtyard(B.Parent)\")"
708 "(constraint physical_clearance (min 100mm))" ),
709 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint diff_pair_gap (min 0.2mm))" ),
710 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint track_width (min 0.2mm))" ),
711 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint diff_pair_uncoupled (max 1mm))" ),
712 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint length (max 100mm))" ),
713 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint net_chain_length (max 100mm))" ),
714 wxString(
"(condition \"AB.isCoupledDiffPair()\")(constraint skew (max 1mm))" ),
715 wxString(
"(condition \"B.Type == 'Track'\")(constraint track_width (min 0.2mm))" ),
716 wxString(
"(condition \"B.Type == 'Track'\")(constraint track_angle (min 45))" ),
717 wxString(
"(condition \"B.Type == 'Zone'\")(constraint thermal_relief_gap (min 0.2mm))" ) } )
721 std::vector<std::shared_ptr<DRC_RULE>> rules;
723 DRC_RULES_PARSER parser( wxS(
"(version 1)(rule test " ) + body + wxS(
")" ), wxS(
"preflight" ) );
725 BOOST_CHECK_MESSAGE( !
reporter.GetMessages().Contains( wxS(
"ERROR:" ) ),
reporter.GetMessages() );
733 auto requiresPairItems =
734 [](
const wxString& aExpr )
744 BOOST_CHECK( !requiresPairItems( wxT(
"A.Width == 1mm" ) ) );
745 BOOST_CHECK( requiresPairItems( wxT(
"B.Width == 1mm" ) ) );
746 BOOST_CHECK( requiresPairItems( wxT(
"AB.isCoupledDiffPair()" ) ) );
747 BOOST_CHECK( !requiresPairItems( wxT(
"A.Reference == 'B.Width'" ) ) );
constexpr EDA_IU_SCALE pcbIUScale
Construction utilities for PCB tests.
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
std::shared_ptr< NET_SETTINGS > m_NetSettings
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
const NETINFO_LIST & GetNetInfo() const
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT, bool aSkipConnectivity=false) override
Removes an item from the container.
void IncrementTimeStamp()
void SetCopperLayerCount(int aCount)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
void Parse(std::vector< std::shared_ptr< DRC_RULE > > &aRules, REPORTER *aReporter)
A color representation with 4 components: red, green, blue, alpha.
wxString ToCSSString() const
bool IsErrorPending() const
const ERROR_STATUS & GetError() const
bool Compile(const wxString &aString, UCODE *aCode, CONTEXT *aPreflightContext)
VALUE * Run(CONTEXT *ctx)
virtual const wxString & AsString() const
virtual double AsDouble() const
VAR_TYPE_T GetType() const
A collection of nets and the parameters used to route or test these nets.
Handle the data for a net.
void SetNetChain(const wxString &aNetChain)
void SetNetClass(const std::shared_ptr< NETCLASS > &aNetClass)
Container for NETINFO_ITEM elements, which are the nets.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
void SetItems(BOARD_ITEM *a, BOARD_ITEM *b=nullptr)
bool RequiresPairItems() const
static PCBEXPR_PROPERTY_KIND ClassifyProperty(const PROPERTY_BASE *aProperty)
static LIBEVAL::VAR_TYPE_T ExpressionType(PCBEXPR_PROPERTY_KIND aKind)
void SetWidth(int aWidth) override
void SetEnd(const VECTOR2I &aEnd) override
void SetEllipseRotation(const EDA_ANGLE &aA) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
void SetEnd(const VECTOR2I &aEnd)
void SetStart(const VECTOR2I &aStart)
virtual void SetWidth(int aWidth)
void SetDrill(int aDrill)
void SetPosition(const VECTOR2I &aPoint) override
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
For a via m_layer contains the top layer, the other layer is in m_bottomLayer/.
void SetViaType(VIATYPE aViaType)
void SetWidth(int aWidth) override
virtual size_t TypeHash() const =0
Return type-id of the property type.
const wxString & Name() const
Provide class metadata.Helper macro to map type hashes to names.
CLASSES_INFO GetAllClasses()
static PROPERTY_MANAGER & Instance()
void Rebuild()
Rebuild the list of all registered properties.
bool IsOfType(TYPE_ID aDerived, TYPE_ID aBase) const
Return true if aDerived is inherited from aBase.
A wrapper for reporting to a wxString object.
Handle a list of polygons defining a copper zone.
void SetHatchOrientation(const EDA_ANGLE &aStep)
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetIsRuleArea(bool aEnable)
void SetAssignedPriority(unsigned aPriority)
void SetMinIslandArea(long long int aArea)
PCB_LAYER_ID
A quick note on layer IDs:
void DrawRect(FOOTPRINT &aFootprint, const VECTOR2I &aPos, const VECTOR2I &aSize, int aRadius, int aWidth, PCB_LAYER_ID aLayer)
Draw a rectangle on a footprint.
friend std::ostream & operator<<(std::ostream &os, const EXPR_TO_TEST &expr)
LIBEVAL::VALUE expectedResult
A filename or source description, a problem input line, a line number, a byte offset,...
BOOST_DATA_TEST_CASE(ConvertToKicadUnit, boost::unit_test::data::make(altium_to_kicad_unit), input_value, expected_result)
Test conversation from Altium internal units into KiCad internal units.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
static void expectCompileError(const wxString &aExpr)
static void expectCompileSuccess(const wxString &aExpr)
static const std::vector< EXPR_TO_TEST > simpleExpressions
static bool testEvalExpr(const wxString &expr, const LIBEVAL::VALUE &expectedResult, bool expectError=false, BOARD_ITEM *itemA=nullptr, BOARD_ITEM *itemB=nullptr)
static const std::vector< EXPR_TO_TEST > introspectionExpressions
BOOST_AUTO_TEST_CASE(IntrospectedProperties)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I