21#include <boost/test/data/test_case.hpp>
60 {
"10mm + 20 mm",
false,
VAL( 30e6 ) },
61 {
"3*(7+8)",
false,
VAL( 3 * ( 7 + 8 ) ) },
62 {
"3*7+8",
false,
VAL( 3 * 7 + 8 ) },
63 {
"(3*7)+8",
false,
VAL( 3 * 7 + 8 ) },
64 {
"10mm + 20)",
true,
VAL( 0 ) },
66 {
"1",
false,
VAL(1) },
67 {
"1.5",
false,
VAL(1.5) },
68 {
"1,5",
false,
VAL(1.5) },
69 {
"1mm",
false,
VAL(1e6) },
71 {
" 1 + 2 ",
false,
VAL(3) },
73 {
"1.5 + 0.2 + 0.1",
false,
VAL(1.8) },
75 {
"3 - 10",
false,
VAL(-7) },
77 {
"1 + 2 + 10 + 1000.05",
false,
VAL(1013.05) },
79 {
"1 + 2 - 4 * 20 / 2",
false,
VAL(-37) },
81 {
"(1)",
false,
VAL(1) },
83 {
"-(1 + (2 - 4)) * 20.8 / 2",
false,
VAL(10.4) },
85 {
"+2 - 1",
false,
VAL(1) },
88 {
"(2 || 0) == 1",
false,
VAL(1) },
89 {
"(7 || 0) + 5",
false,
VAL(6) }
94 {
"A.type == 'Pad' && B.type == 'Pad' && (A.existsOnLayer('F.Cu'))",
false,
VAL( 0.0 ) },
95 {
"A.Width > B.Width",
false,
VAL( 0.0 ) },
97 {
"A.Netclass",
false,
VAL(
"HV_LINE" ) },
98 {
"A.Net_Class == 'HV_LINE'",
false,
VAL( 1.0 ) },
99 {
"(A.Netclass == 'HV_LINE') && (B.netclass == 'otherClass') && (B.netclass != 'F.Cu')",
false,
VAL( 1.0 ) },
100 {
"A.Netclass + 1.0",
false,
VAL( 1.0 ) },
101 {
"A.hasNetclass('HV_LINE')",
false,
VAL( 1.0 ) },
102 {
"A.hasNetclass('HV_*')",
false,
VAL( 1.0 ) },
103 {
"A.type == 'Track' && B.type == 'Track' && A.layer == 'F.Cu'",
false,
VAL( 1.0 ) },
104 {
"(A.type == 'Track') && (B.type == 'Track') && (A.layer == 'F.Cu')",
false,
VAL( 1.0 ) },
105 {
"A.type == 'Via' && A.isMicroVia()",
false,
VAL(0.0) }
110 bool expectError =
false,
BOARD_ITEM* itemA =
nullptr,
124 bool error = !compiler.
Compile( expr, &ucode, &preflightContext );
128 if( error != expectError )
144 ok = (
result->EqualTo( &context, &expectedResult ) );
166 compiler.
Compile( aExpr, &ucode, &preflight );
168 BOOST_CHECK_MESSAGE( compiler.
IsErrorPending(),
"Expected a compile error for: " << aExpr.mb_str() );
178 compiler.
Compile( aExpr, &ucode, &preflight );
180 BOOST_CHECK_MESSAGE( !compiler.
IsErrorPending(),
"Expected expression to compile: " << aExpr.mb_str() );
186 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError );
199 std::shared_ptr<NETCLASS> netclass1(
new NETCLASS(
"HV_LINE" ) );
200 std::shared_ptr<NETCLASS> netclass2(
new NETCLASS(
"otherClass" ) );
205 net1info->SetNetClass( netclass1 );
206 net2info->SetNetClass( netclass2 );
211 trackA.
SetNet( net1info );
212 trackB.
SetNet( net2info );
221 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError, &trackA, &trackB );
239 testEvalExpr( wxT(
"A.Hatch_Orientation == 45deg" ),
VAL( 1.0 ),
false, &zone );
240 testEvalExpr( wxT(
"A.Minimum_Island_Area == 123456789" ),
VAL( 1.0 ),
false, &zone );
245 testEvalExpr( wxT(
"A.Ellipse_Rotation == 30deg" ),
VAL( 1.0 ),
false, &ellipse );
250 testEvalExpr( wxT(
"A.Solderpaste_Margin_Ratio_Override == 0.125" ),
VAL( 1.0 ),
false,
255 testEvalExpr( wxT(
"A.Solderpaste_Margin_Ratio_Override == null" ),
VAL( 1.0 ),
false,
267 const auto checkColor = [&](
const COLOR4D& aColor,
const wxString& aExpectedCss )
269 table.SetBorderColor( aColor );
272 wxString expression = wxT(
"A.Border_Color == '" ) + aExpectedCss + wxT(
"'" );
276 checkColor(
COLOR4D( 0.25, 0.5, 0.75, 0.5 ), wxT(
"rgba(64, 128, 191, 0.502)" ) );
277 checkColor(
COLOR4D( wxString( wxT(
"red" ) ) ), wxT(
"rgb(255, 0, 0)" ) );
285 std::set<std::pair<TYPE_ID, PROPERTY_BASE*>> seen;
286 std::map<wxString, std::set<LIBEVAL::VAR_TYPE_T>> fieldTypes;
295 if( !seen.emplace( cls.type, prop ).second )
301 "Unsupported expression property: class=" << cls.name.mb_str()
302 <<
", property=" << prop->
Name().mb_str()
303 <<
", type_hash=" << prop->
TypeHash() );
312 auto shapeTypes = fieldTypes.find( wxT(
"Shape" ) );
315 fieldTypes.erase( shapeTypes );
317 for(
const auto& [field, types] : fieldTypes )
319 BOOST_CHECK_MESSAGE( types.size() == 1,
320 "Incompatible expression types for property: " << field.mb_str() );
353 netSettings->SetNetChainClass( wxT(
"ChainHS" ), wxT(
"HighSpeed" ) );
355 auto netUnclassified =
new NETINFO_ITEM( &brd,
"netA", 1 );
356 auto netClassified =
new NETINFO_ITEM( &brd,
"netB", 2 );
359 netUnclassified->SetNetChain( wxT(
"ChainOrphan" ) );
360 netClassified->SetNetChain( wxT(
"ChainHS" ) );
366 trackUnclassified.
SetNet( netUnclassified );
367 trackClassified.
SetNet( netClassified );
368 trackNoChain.
SetNet( netNoChain );
372 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 0.0 ),
false, &trackUnclassified,
373 &trackUnclassified );
374 testEvalExpr( wxT(
"A.inNetChainClass('HighSpeed')" ),
VAL( 0.0 ),
false, &trackUnclassified,
375 &trackUnclassified );
378 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 0.0 ),
false, &trackNoChain,
382 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 1.0 ),
false, &trackClassified,
384 testEvalExpr( wxT(
"A.inNetChainClass('HighSpeed')" ),
VAL( 1.0 ),
false, &trackClassified,
386 testEvalExpr( wxT(
"A.inNetChainClass('High*')" ),
VAL( 1.0 ),
false, &trackClassified,
388 testEvalExpr( wxT(
"A.inNetChainClass('LowSpeed')" ),
VAL( 0.0 ),
false, &trackClassified,
405 text->SetText( wxT(
"J1" ) );
453 auto requiresPairItems =
454 [](
const wxString& aExpr )
464 BOOST_CHECK( !requiresPairItems( wxT(
"A.Width == 1mm" ) ) );
465 BOOST_CHECK( requiresPairItems( wxT(
"B.Width == 1mm" ) ) );
466 BOOST_CHECK( requiresPairItems( wxT(
"AB.isCoupledDiffPair()" ) ) );
467 BOOST_CHECK( !requiresPairItems( wxT(
"A.Reference == 'B.Width'" ) ) );
constexpr EDA_IU_SCALE pcbIUScale
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
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
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.
Container for NETINFO_ITEM elements, which are the nets.
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 SetEllipseRotation(const EDA_ANGLE &aA) override
virtual void SetWidth(int aWidth)
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.
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)
friend std::ostream & operator<<(std::ostream &os, const EXPR_TO_TEST &expr)
LIBEVAL::VALUE expectedResult
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()
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_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")