KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_update_pcb_legacy_fpid_dnp.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <boost/test/unit_test.hpp>
25#include <lib_id.h>
28
29
30BOOST_AUTO_TEST_SUITE( UpdatePcbLegacyFpidDnp )
31
32
33static LIB_ID makeFpid( const wxString& aLibrary, const wxString& aItem )
34{
35 LIB_ID id;
36 id.SetLibNickname( aLibrary );
37 id.SetLibItemName( aItem );
38 return id;
39}
40
41
42// Reproduces https://gitlab.com/kicad/code/kicad/-/issues/24586
43//
44// A symbol carrying a legacy (bare) footprint field such as "0603" is placed on a board whose
45// footprint is fully qualified as "my_footprints:0603". The variant handler in
46// BOARD_NETLIST_UPDATER decides whether a footprint is the component's base footprint via
47// fpidsEquivalent(). A strict equality test fails for legacy FPIDs (the board side always carries
48// a library nickname), so the matching board footprint is mistaken for a non-base variant and
49// gets a spurious "Do not place" attribute. The comparison must ignore the library nickname when
50// the schematic side is legacy.
51BOOST_AUTO_TEST_CASE( LegacySchematicFpidMatchesQualifiedBoardFpid )
52{
53 LIB_ID schematicFpid;
54 BOOST_REQUIRE_EQUAL( schematicFpid.Parse( wxS( "0603" ), true ), -1 );
55 BOOST_REQUIRE( schematicFpid.IsLegacy() );
56
57 LIB_ID boardFpid = makeFpid( wxS( "my_footprints" ), wxS( "0603" ) );
58
59 BOOST_CHECK( BOARD_NETLIST_UPDATER::fpidsEquivalent( boardFpid, schematicFpid ) );
60}
61
62
63// A legacy schematic FPID must not match a board footprint with a different item name, otherwise
64// genuine non-base variant footprints would no longer be flagged.
65BOOST_AUTO_TEST_CASE( LegacySchematicFpidDoesNotMatchDifferentItemName )
66{
67 LIB_ID schematicFpid;
68 BOOST_REQUIRE_EQUAL( schematicFpid.Parse( wxS( "0603" ), true ), -1 );
69
70 LIB_ID boardFpid = makeFpid( wxS( "my_footprints" ), wxS( "0805" ) );
71
72 BOOST_CHECK( !BOARD_NETLIST_UPDATER::fpidsEquivalent( boardFpid, schematicFpid ) );
73}
74
75
76// When the schematic side is fully qualified, the comparison must be exact so that a footprint
77// from a different library is correctly treated as a distinct (non-base) variant.
78BOOST_AUTO_TEST_CASE( QualifiedSchematicFpidComparesExactly )
79{
80 LIB_ID schematicFpid = makeFpid( wxS( "Connector_PinHeader_2.54mm" ),
81 wxS( "PinHeader_1x04_P2.54mm_Vertical" ) );
82
83 LIB_ID sameBoardFpid = makeFpid( wxS( "Connector_PinHeader_2.54mm" ),
84 wxS( "PinHeader_1x04_P2.54mm_Vertical" ) );
85 LIB_ID otherLibBoardFpid = makeFpid( wxS( "my_footprints" ),
86 wxS( "PinHeader_1x04_P2.54mm_Vertical" ) );
87
88 BOOST_CHECK( BOARD_NETLIST_UPDATER::fpidsEquivalent( sameBoardFpid, schematicFpid ) );
89 BOOST_CHECK( !BOARD_NETLIST_UPDATER::fpidsEquivalent( otherLibBoardFpid, schematicFpid ) );
90}
91
92
static bool fpidsEquivalent(const LIB_ID &aBoardFpid, const LIB_ID &aSchematicFpid)
Compare a board footprint ID against a schematic-derived footprint ID, ignoring the library nickname ...
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:48
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
Definition lib_id.cpp:96
bool IsLegacy() const
Definition lib_id.h:176
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(LegacySchematicFpidMatchesQualifiedBoardFpid)
static LIB_ID makeFpid(const wxString &aLibrary, const wxString &aItem)