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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 */
20
21// Regression test for https://gitlab.com/kicad/code/kicad/-/issues/24217
22
24
25#include <connection_graph.h>
26#include <eeschema_helpers.h>
27#include <locale_io.h>
28#include <sch_reference_list.h>
29#include <sch_screen.h>
30#include <sch_sheet.h>
31#include <sch_sheet_path.h>
32#include <sch_symbol.h>
33#include <schematic.h>
34
36
37
38BOOST_AUTO_TEST_CASE( Issue24217_VariantSurvivesStaleInstancePath )
39{
41
42 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() ) +
43 wxS( "issue24217/issue24217.kicad_sch" );
44
45 // Load via the CLI helper so the regression covers `kicad-cli sch export bom`.
46 SCHEMATIC* sch = EESCHEMA_HELPERS::LoadSchematic( schPath, true, true );
47 BOOST_REQUIRE( sch != nullptr );
48
49 // The schematic's stored root UUID differs from the UUID in every (path ...) entry,
50 // simulating a v9 file re-rooted by v10 on save. Variant H0 marks R2/R3 DNP and
51 // overrides R1's value to "10k".
52 sch->SetCurrentVariant( wxS( "H0" ) );
53 BOOST_CHECK_EQUAL( sch->GetCurrentVariant(), wxS( "H0" ) );
54
56 sch->Hierarchy().GetSymbols( refs, SYMBOL_FILTER_NON_POWER, false );
57
58 BOOST_REQUIRE_EQUAL( refs.GetCount(), 3u );
59
60 auto findRef = [&]( const wxString& aRef ) -> SCH_REFERENCE*
61 {
62 for( size_t i = 0; i < refs.GetCount(); ++i )
63 {
64 if( refs[i].GetRef() == aRef )
65 return &refs[i];
66 }
67
68 return nullptr;
69 };
70
71 SCH_REFERENCE* r1 = findRef( wxS( "R1" ) );
72 SCH_REFERENCE* r2 = findRef( wxS( "R2" ) );
73 SCH_REFERENCE* r3 = findRef( wxS( "R3" ) );
74
75 BOOST_REQUIRE( r1 );
76 BOOST_REQUIRE( r2 );
77 BOOST_REQUIRE( r3 );
78
79 BOOST_CHECK_MESSAGE( r2->GetSymbol()->GetDNP( &r2->GetSheetPath(), wxS( "H0" ) ),
80 "R2 should be DNP in variant H0" );
81 BOOST_CHECK_MESSAGE( r3->GetSymbol()->GetDNP( &r3->GetSheetPath(), wxS( "H0" ) ),
82 "R3 should be DNP in variant H0" );
83 BOOST_CHECK_MESSAGE( !r1->GetSymbol()->GetDNP( &r1->GetSheetPath(), wxS( "H0" ) ),
84 "R1 should not be DNP in variant H0" );
85
86 SCH_FIELD* r1Value = r1->GetSymbol()->GetField( FIELD_T::VALUE );
87 BOOST_REQUIRE( r1Value );
88
89 wxString resolved = r1Value->GetShownText( &r1->GetSheetPath(), false, 0, wxS( "H0" ) );
90 BOOST_CHECK_EQUAL( resolved, wxS( "10k" ) );
91}
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:41
Holds all the data relating to one schematic.
Definition schematic.h:89
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")