KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24217_cli_variant_export.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 2
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, see <https://www.gnu.org/licenses/>.
18 */
19
20// Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24217
21
23
24#include <connection_graph.h>
25#include <eeschema_helpers.h>
26#include <locale_io.h>
27#include <sch_reference_list.h>
28#include <sch_screen.h>
29#include <sch_sheet.h>
30#include <sch_sheet_path.h>
31#include <sch_symbol.h>
32#include <schematic.h>
33
35
36
37BOOST_AUTO_TEST_CASE( Issue24217_VariantSurvivesStaleInstancePath )
38{
40
41 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() ) +
42 wxS( "issue24217/issue24217.kicad_sch" );
43
44 // Load via the CLI helper so the regression covers `kicad-cli sch export bom`.
45 SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( schPath, true, true );
46 BOOST_REQUIRE( sch != nullptr );
47
48 // The schematic's stored root UUID differs from the UUID in every (path ...) entry,
49 // simulating a v9 file re-rooted by v10 on save. Variant H0 marks R2/R3 DNP and
50 // overrides R1's value to "10k".
51 sch->SetCurrentVariant( wxS( "H0" ) );
52 BOOST_CHECK_EQUAL( sch->GetCurrentVariant(), wxS( "H0" ) );
53
55 sch->Hierarchy().GetSymbols( refs, SYMBOL_FILTER_NON_POWER, false );
56
57 BOOST_REQUIRE_EQUAL( refs.GetCount(), 3u );
58
59 auto findRef = [&]( const wxString& aRef ) -> SCH_REFERENCE*
60 {
61 for( size_t i = 0; i < refs.GetCount(); ++i )
62 {
63 if( refs[i].GetRef() == aRef )
64 return &refs[i];
65 }
66
67 return nullptr;
68 };
69
70 SCH_REFERENCE* r1 = findRef( wxS( "R1" ) );
71 SCH_REFERENCE* r2 = findRef( wxS( "R2" ) );
72 SCH_REFERENCE* r3 = findRef( wxS( "R3" ) );
73
74 BOOST_REQUIRE( r1 );
75 BOOST_REQUIRE( r2 );
76 BOOST_REQUIRE( r3 );
77
78 BOOST_CHECK_MESSAGE( r2->GetSymbol()->GetDNP( &r2->GetSheetPath(), wxS( "H0" ) ),
79 "R2 should be DNP in variant H0" );
80 BOOST_CHECK_MESSAGE( r3->GetSymbol()->GetDNP( &r3->GetSheetPath(), wxS( "H0" ) ),
81 "R3 should be DNP in variant H0" );
82 BOOST_CHECK_MESSAGE( !r1->GetSymbol()->GetDNP( &r1->GetSheetPath(), wxS( "H0" ) ),
83 "R1 should not be DNP in variant H0" );
84
85 SCH_FIELD* r1Value = r1->GetSymbol()->GetField( FIELD_T::VALUE );
86 BOOST_REQUIRE( r1Value );
87
88 wxString resolved = r1Value->GetShownText( &r1->GetSheetPath(), false, 0, wxS( "H0" ) );
89 BOOST_CHECK_EQUAL( resolved, wxS( "10k" ) );
90}
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
Holds all the data relating to one schematic.
Definition schematic.h:90
void SetCurrentVariant(const wxString &aVariantName)
SCH_SHEET_LIST Hierarchy() const
Return the full schematic flattened hierarchical sheet list.
wxString GetCurrentVariant() const
Return the current variant being edited.
wxString GetShownText(const SCH_SHEET_PATH *aPath, bool aAllowExtraText, int aDepth=0, const wxString &aVariantName=wxEmptyString) const
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
A helper to define a symbol's reference designator in a schematic.
const SCH_SHEET_PATH & GetSheetPath() const
SCH_SYMBOL * GetSymbol() const
void GetSymbols(SCH_REFERENCE_LIST &aReferences, SYMBOL_FILTER aSymbolFilter, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
virtual bool GetDNP(const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) const override
Set or clear the 'Do Not Populate' flag.
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
@ SYMBOL_FILTER_NON_POWER
std::vector< FAB_LAYER_COLOR > dummy
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_CASE(Issue24217_VariantSurvivesStaleInstancePath)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_CHECK_EQUAL(result, "25.4")