21#include <boost/test/data/test_case.hpp>
55 {
"10mm + 20 mm",
false,
VAL( 30e6 ) },
56 {
"3*(7+8)",
false,
VAL( 3 * ( 7 + 8 ) ) },
57 {
"3*7+8",
false,
VAL( 3 * 7 + 8 ) },
58 {
"(3*7)+8",
false,
VAL( 3 * 7 + 8 ) },
59 {
"10mm + 20)",
true,
VAL( 0 ) },
61 {
"1",
false,
VAL(1) },
62 {
"1.5",
false,
VAL(1.5) },
63 {
"1,5",
false,
VAL(1.5) },
64 {
"1mm",
false,
VAL(1e6) },
66 {
" 1 + 2 ",
false,
VAL(3) },
68 {
"1.5 + 0.2 + 0.1",
false,
VAL(1.8) },
70 {
"3 - 10",
false,
VAL(-7) },
72 {
"1 + 2 + 10 + 1000.05",
false,
VAL(1013.05) },
74 {
"1 + 2 - 4 * 20 / 2",
false,
VAL(-37) },
76 {
"(1)",
false,
VAL(1) },
78 {
"-(1 + (2 - 4)) * 20.8 / 2",
false,
VAL(10.4) },
80 {
"+2 - 1",
false,
VAL(1) },
83 {
"(2 || 0) == 1",
false,
VAL(1) },
84 {
"(7 || 0) + 5",
false,
VAL(6) }
89 {
"A.type == 'Pad' && B.type == 'Pad' && (A.existsOnLayer('F.Cu'))",
false,
VAL( 0.0 ) },
90 {
"A.Width > B.Width",
false,
VAL( 0.0 ) },
92 {
"A.Netclass",
false,
VAL(
"HV_LINE" ) },
93 {
"(A.Netclass == 'HV_LINE') && (B.netclass == 'otherClass') && (B.netclass != 'F.Cu')",
false,
95 {
"A.Netclass + 1.0",
false,
VAL( 1.0 ) },
96 {
"A.hasNetclass('HV_LINE')",
false,
VAL( 1.0 ) },
97 {
"A.hasNetclass('HV_*')",
false,
VAL( 1.0 ) },
98 {
"A.type == 'Track' && B.type == 'Track' && A.layer == 'F.Cu'",
false,
VAL( 1.0 ) },
99 {
"(A.type == 'Track') && (B.type == 'Track') && (A.layer == 'F.Cu')",
false,
VAL( 1.0 ) },
100 {
"A.type == 'Via' && A.isMicroVia()",
false,
VAL(0.0) }
105 bool expectError =
false,
BOARD_ITEM* itemA =
nullptr,
119 bool error = !compiler.
Compile( expr, &ucode, &preflightContext );
123 if( error != expectError )
139 ok = (
result->EqualTo( &context, &expectedResult ) );
157 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError );
170 std::shared_ptr<NETCLASS> netclass1(
new NETCLASS(
"HV_LINE" ) );
171 std::shared_ptr<NETCLASS> netclass2(
new NETCLASS(
"otherClass" ) );
176 net1info->SetNetClass( netclass1 );
177 net2info->SetNetClass( netclass2 );
182 trackA.
SetNet( net1info );
183 trackB.
SetNet( net2info );
192 testEvalExpr( expr.expression, expr.expectedResult, expr.expectError, &trackA, &trackB );
204 netSettings->SetNetChainClass( wxT(
"ChainHS" ), wxT(
"HighSpeed" ) );
206 auto netUnclassified =
new NETINFO_ITEM( &brd,
"netA", 1 );
207 auto netClassified =
new NETINFO_ITEM( &brd,
"netB", 2 );
210 netUnclassified->SetNetChain( wxT(
"ChainOrphan" ) );
211 netClassified->SetNetChain( wxT(
"ChainHS" ) );
217 trackUnclassified.
SetNet( netUnclassified );
218 trackClassified.
SetNet( netClassified );
219 trackNoChain.
SetNet( netNoChain );
223 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 0.0 ),
false, &trackUnclassified,
224 &trackUnclassified );
225 testEvalExpr( wxT(
"A.inNetChainClass('HighSpeed')" ),
VAL( 0.0 ),
false, &trackUnclassified,
226 &trackUnclassified );
229 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 0.0 ),
false, &trackNoChain,
233 testEvalExpr( wxT(
"A.inNetChainClass('*')" ),
VAL( 1.0 ),
false, &trackClassified,
235 testEvalExpr( wxT(
"A.inNetChainClass('HighSpeed')" ),
VAL( 1.0 ),
false, &trackClassified,
237 testEvalExpr( wxT(
"A.inNetChainClass('High*')" ),
VAL( 1.0 ),
false, &trackClassified,
239 testEvalExpr( wxT(
"A.inNetChainClass('LowSpeed')" ),
VAL( 0.0 ),
false, &trackClassified,
256 text->SetText( wxT(
"J1" ) );
281 auto expectCompileError =
282 [](
const wxString& aExpr )
288 compiler.
Compile( aExpr, &ucode, &preflight );
291 "Expected a compile error for: " << aExpr.mb_str() );
296 expectCompileError( wxT(
"A.Parent.bogusProperty" ) );
297 expectCompileError( wxT(
"A.bogus.Reference == 'J1'" ) );
298 expectCompileError( wxT(
"L.Parent.Type == 'Footprint'" ) );
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
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)
virtual void SetWidth(int aWidth)
Provide class metadata.Helper macro to map type hashes to names.
static PROPERTY_MANAGER & Instance()
void Rebuild()
Rebuild the list of all registered properties.
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_AUTO_TEST_SUITE_END()
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_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")