Files
kicad-source-mirror/qa/tests/common/test_lib_id.cpp
T
Seth Hillbrand c28dd5d4a9 Fix perpetual footprint change notifications for legacy FPIDs
When schematic symbols have footprint fields without library name prefixes
(e.g., "DGG56" instead of "Package_SO:DGG56"), the netlist updater's FPID
comparison always fails against the board's fully qualified FPIDs, causing
"Update PCB from Schematic" to perpetually report footprint changes that
can never be resolved.

Match by item name only when the schematic-side FPID has no library
nickname (legacy format), and warn the user to add the library prefix.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/22958
2026-02-13 11:20:10 -08:00

115 lines
3.4 KiB
C++

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <boost/test/unit_test.hpp>
#include <lib_id.h>
BOOST_AUTO_TEST_SUITE( LibId )
BOOST_AUTO_TEST_CASE( ParseFullyQualified )
{
LIB_ID id;
BOOST_CHECK( id.Parse( "Package_SO:DGG56" ) == -1 );
BOOST_CHECK_EQUAL( id.GetLibNickname(), "Package_SO" );
BOOST_CHECK_EQUAL( id.GetLibItemName(), "DGG56" );
BOOST_CHECK( id.IsValid() );
BOOST_CHECK( !id.IsLegacy() );
BOOST_CHECK( !id.empty() );
}
BOOST_AUTO_TEST_CASE( ParseLegacy )
{
LIB_ID id;
BOOST_CHECK( id.Parse( "DGG56" ) == -1 );
BOOST_CHECK( id.GetLibNickname().empty() );
BOOST_CHECK_EQUAL( id.GetLibItemName(), "DGG56" );
BOOST_CHECK( !id.IsValid() );
BOOST_CHECK( id.IsLegacy() );
BOOST_CHECK( !id.empty() );
}
BOOST_AUTO_TEST_CASE( EqualityFullyQualified )
{
LIB_ID a( wxT( "Package_SO" ), wxT( "DGG56" ) );
LIB_ID b( wxT( "Package_SO" ), wxT( "DGG56" ) );
LIB_ID c( wxT( "OtherLib" ), wxT( "DGG56" ) );
BOOST_CHECK( a == b );
BOOST_CHECK( a != c );
}
BOOST_AUTO_TEST_CASE( EqualityLegacyVsFullyQualified )
{
LIB_ID legacy;
legacy.Parse( "DGG56" );
LIB_ID qualified( wxT( "Package_SO" ), wxT( "DGG56" ) );
// Standard equality requires both library and item name to match
BOOST_CHECK( legacy != qualified );
// Legacy matching (item name only) should match when we explicitly compare just item names
BOOST_CHECK( legacy.IsLegacy() );
BOOST_CHECK_EQUAL( legacy.GetLibItemName(), qualified.GetLibItemName() );
}
BOOST_AUTO_TEST_CASE( FormatRoundTrip )
{
LIB_ID qualified( wxT( "Package_SO" ), wxT( "DGG56" ) );
BOOST_CHECK_EQUAL( qualified.Format().wx_str(), wxT( "Package_SO:DGG56" ) );
LIB_ID legacy;
legacy.Parse( "DGG56" );
BOOST_CHECK_EQUAL( legacy.Format().wx_str(), wxT( "DGG56" ) );
// Re-parse the formatted strings
LIB_ID reparsed;
reparsed.Parse( qualified.Format() );
BOOST_CHECK( reparsed == qualified );
LIB_ID reparsedLegacy;
reparsedLegacy.Parse( legacy.Format() );
BOOST_CHECK( reparsedLegacy.IsLegacy() );
BOOST_CHECK_EQUAL( reparsedLegacy.GetLibItemName(), legacy.GetLibItemName() );
}
BOOST_AUTO_TEST_CASE( EmptyId )
{
LIB_ID empty;
BOOST_CHECK( empty.empty() );
BOOST_CHECK( !empty.IsValid() );
BOOST_CHECK( !empty.IsLegacy() );
}
BOOST_AUTO_TEST_SUITE_END()