KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24915_job_variant_fields.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
31
32#include <boost/test/unit_test.hpp>
33
35
36#include <eeschema_helpers.h>
38#include <locale_io.h>
39#include <sch_reference_list.h>
40#include <sch_sheet_path.h>
41#include <sch_symbol.h>
42#include <schematic.h>
43
44
45namespace
46{
47
48struct ISSUE24915_FIXTURE
49{
50 void LoadFixture()
51 {
52 wxString schPath =
53 wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() ) + wxS( "issue24217/issue24217.kicad_sch" );
54
55 m_schematic = EESCHEMA_HELPERS::LoadSchematic( schPath, true, true );
56 BOOST_REQUIRE( m_schematic != nullptr );
57
58 m_schematic->Hierarchy().GetSymbols( m_refs, SYMBOL_FILTER_NON_POWER, false );
59 BOOST_REQUIRE_EQUAL( m_refs.GetCount(), 3u );
60 }
61
62 const SCH_REFERENCE& FindRef( const wxString& aRef ) const
63 {
64 for( size_t i = 0; i < m_refs.GetCount(); ++i )
65 {
66 if( m_refs[i].GetRef() == aRef )
67 return m_refs[i];
68 }
69
70 BOOST_FAIL( "reference not found" );
71 return m_refs[0];
72 }
73
74 wxString ModelValue( SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL& aModel, const wxString& aRef,
75 const wxString& aField ) const
76 {
77 int col = aModel.GetFieldNameCol( aField );
78 BOOST_REQUIRE( col >= 0 );
79
80 SYMBOL_FIELDS_TABLE_DATA_MODEL_ROW row( FindRef( aRef ), ROW_STATE::NON_EXPANDABLE );
81 return aModel.GetGroupedValue( row, col );
82 }
83
84 // The export preview path, generated fields are re-resolved live instead of read
85 // from the data store.
86 wxString ExportValue( SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL& aModel, const wxString& aRef,
87 const wxString& aField ) const
88 {
89 int col = aModel.GetFieldNameCol( aField );
90 BOOST_REQUIRE( col >= 0 );
91
92 SYMBOL_FIELDS_TABLE_DATA_MODEL_ROW row( FindRef( aRef ), ROW_STATE::NON_EXPANDABLE );
93 return aModel.GetGroupedValue( row, col, wxS( ", " ), wxS( "-" ), true, false );
94 }
95
96 LOCALE_IO m_locale;
97 SCHEMATIC* m_schematic = nullptr;
98 SCH_REFERENCE_LIST m_refs;
99};
100
101} // namespace
102
103
104BOOST_FIXTURE_TEST_CASE( JobVariantDrivesFieldsDataStore, ISSUE24915_FIXTURE )
105{
106 LoadFixture();
107
108 // The failing scenario from the issue: the schematic sits on the default variant
109 // while the reopened job carries its own saved variant.
110 m_schematic->SetCurrentVariant( wxEmptyString );
111
112 SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL jobModel( m_refs );
113 jobModel.SetCurrentVariant( wxS( "H0" ) );
114 jobModel.AddColumn( wxS( "Value" ), wxS( "Value" ), false );
115 jobModel.AddColumn( wxS( "${DNP}" ), wxS( "DNP" ), false );
116
117 BOOST_CHECK_EQUAL( ModelValue( jobModel, wxS( "R1" ), wxS( "Value" ) ), wxS( "10k" ) );
118 BOOST_CHECK_EQUAL( ModelValue( jobModel, wxS( "R3" ), wxS( "Value" ) ), wxS( "2M" ) );
119 BOOST_CHECK_EQUAL( ModelValue( jobModel, wxS( "R2" ), wxS( "${DNP}" ) ), wxS( "1" ) );
120 BOOST_CHECK_EQUAL( ModelValue( jobModel, wxS( "R1" ), wxS( "${DNP}" ) ), wxS( "0" ) );
121
122 // The export path must follow the model's variant too, not the schematic's.
123 BOOST_CHECK_EQUAL( ExportValue( jobModel, wxS( "R2" ), wxS( "${DNP}" ) ), wxS( "DNP" ) );
124 BOOST_CHECK_EQUAL( ExportValue( jobModel, wxS( "R1" ), wxS( "${DNP}" ) ), wxEmptyString );
125 BOOST_CHECK_EQUAL( ExportValue( jobModel, wxS( "R1" ), wxS( "Value" ) ), wxS( "10k" ) );
126}
127
128
129BOOST_FIXTURE_TEST_CASE( SchematicVariantDoesNotLeakIntoDataStore, ISSUE24915_FIXTURE )
130{
131 LoadFixture();
132
133 // Control for the same contract from the other side: with H0 active on the
134 // schematic, a store populated for the default variant must show base values.
135 m_schematic->SetCurrentVariant( wxS( "H0" ) );
136
137 SYMBOL_FIELDS_EDITOR_GRID_DATA_MODEL baseModel( m_refs );
138 baseModel.AddColumn( wxS( "Value" ), wxS( "Value" ), false );
139 baseModel.AddColumn( wxS( "${DNP}" ), wxS( "DNP" ), false );
140
141 BOOST_CHECK_EQUAL( ModelValue( baseModel, wxS( "R1" ), wxS( "Value" ) ), wxS( "6k2" ) );
142 BOOST_CHECK_EQUAL( ModelValue( baseModel, wxS( "R3" ), wxS( "Value" ) ), wxS( "1M" ) );
143 BOOST_CHECK_EQUAL( ModelValue( baseModel, wxS( "R2" ), wxS( "${DNP}" ) ), wxS( "0" ) );
144
145 BOOST_CHECK_EQUAL( ExportValue( baseModel, wxS( "R2" ), wxS( "${DNP}" ) ), wxEmptyString );
146}
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true, REPORTER *aRootReporter=nullptr)
int GetFieldNameCol(const wxString &aFieldName) const
void SetCurrentVariant(const wxString &aVariantName)
Set the current variant name for highlighting purposes.
void AddColumn(const wxString &aFieldName, const wxString &aLabel, bool aAddedByUser) override
wxString GetGroupedValue(const DATA_MODEL_ROW< ITEM_TYPE > &aRow, int aCol, const wxString &refDelimiter=wxT(", "), const wxString &refRangeDelimiter=wxT("-"), bool resolveVars=false, bool listMixedValues=false)
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
DATA_MODEL_ROW< SCH_REFERENCE > SYMBOL_FIELDS_TABLE_DATA_MODEL_ROW
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(JobVariantDrivesFieldsDataStore, ISSUE24915_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")