KiCad PCB EDA Suite
TEST_NETLISTS_FIXTURE Class Reference

Public Member Functions

 TEST_NETLISTS_FIXTURE ()
 
virtual ~TEST_NETLISTS_FIXTURE ()
 
void loadSchematic (const wxString &aBaseName)
 
wxString getNetlistFileName (bool aTest=false)
 
void writeNetlist ()
 
void compareNetlists ()
 
void cleanup ()
 
void doNetlistTest (const wxString &aBaseName)
 

Public Attributes

SCHEMATIC m_schematic
 

Schematic to load

More...
 
SCH_PLUGINm_pi
 
SETTINGS_MANAGER m_manager
 

Detailed Description

Definition at line 35 of file test_netlists.cpp.

Constructor & Destructor Documentation

◆ TEST_NETLISTS_FIXTURE()

TEST_NETLISTS_FIXTURE::TEST_NETLISTS_FIXTURE ( )
inline

Definition at line 38 of file test_netlists.cpp.

38  :
39  m_schematic( nullptr ),
40  m_manager( true )
41  {
42  m_pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
43  }
SCHEMATIC m_schematic
Schematic to load
SETTINGS_MANAGER m_manager

References m_pi.

◆ ~TEST_NETLISTS_FIXTURE()

virtual TEST_NETLISTS_FIXTURE::~TEST_NETLISTS_FIXTURE ( )
inlinevirtual

Definition at line 45 of file test_netlists.cpp.

46  {
49  }
SCHEMATIC m_schematic
Schematic to load
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51
static void ReleasePlugin(SCH_PLUGIN *aPlugin)
Release a SCH_PLUGIN back to the system, and may cause it to be unloaded from memory.
Definition: sch_io_mgr.cpp:69

References m_pi, m_schematic, SCH_IO_MGR::ReleasePlugin(), and SCHEMATIC::Reset().

Member Function Documentation

◆ cleanup()

void TEST_NETLISTS_FIXTURE::cleanup ( )

Definition at line 208 of file test_netlists.cpp.

209 {
210  wxRemoveFile( getNetlistFileName( true ) );
211  m_schematic.Reset();
212 }
wxString getNetlistFileName(bool aTest=false)
SCHEMATIC m_schematic
Schematic to load
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51

References getNetlistFileName(), m_schematic, and SCHEMATIC::Reset().

Referenced by doNetlistTest().

◆ compareNetlists()

void TEST_NETLISTS_FIXTURE::compareNetlists ( )

Definition at line 149 of file test_netlists.cpp.

150 {
151  NETLIST golden;
152  NETLIST test;
153 
154  {
155  std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
156  &golden, getNetlistFileName(), wxEmptyString ) );
157 
158  BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
159  }
160 
161  {
162  std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
163  &test, getNetlistFileName( true ), wxEmptyString ) );
164 
165  BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
166  }
167 
168  // Number of components should match
169  BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
170 
171  for( unsigned i = 0; i < golden.GetCount(); i++ )
172  {
173  COMPONENT* goldenComp = golden.GetComponent( i );
174  COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
175 
176  // Retrieval by reference
177  BOOST_REQUIRE_NE( refComp, nullptr );
178 
179  // Retrieval by KIID
180  KIID_PATH path = goldenComp->GetPath();
181 
182  BOOST_REQUIRE( !goldenComp->GetKIIDs().empty() );
183 
184  path.push_back( goldenComp->GetKIIDs().front() );
185 
186  COMPONENT* pathComp = test.GetComponentByPath( path );
187  BOOST_REQUIRE_NE( pathComp, nullptr );
188 
189  // We should have found the same component
190  BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
191 
192  // And that component should have the same number of attached nets
193  BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
194 
195  for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
196  {
197  const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
198  const COMPONENT_NET& testNet = refComp->GetNet( net );
199 
200  // The two nets at the same index should be identical
201  BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
202  BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
203  }
204  }
205 }
static NETLIST_READER * GetNetlistReader(NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
Attempt to determine the net list file type of aNetlistFileName and return the appropriate NETLIST_RE...
unsigned GetCount() const
Definition: pcb_netlist.h:228
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:43
wxString getNetlistFileName(bool aTest=false)
const wxString & GetNetName() const
Definition: pcb_netlist.h:58
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:206
unsigned GetNetCount() const
Definition: pcb_netlist.h:109
const wxString & GetReference() const
Definition: pcb_netlist.h:123
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:111
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:84
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:236
const wxString & GetPinName() const
Definition: pcb_netlist.h:57
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:138
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:140

References NETLIST::GetComponent(), NETLIST::GetCount(), COMPONENT::GetKIIDs(), COMPONENT::GetNet(), COMPONENT::GetNetCount(), getNetlistFileName(), NETLIST_READER::GetNetlistReader(), COMPONENT_NET::GetNetName(), COMPONENT::GetPath(), COMPONENT_NET::GetPinName(), COMPONENT::GetReference(), and path.

Referenced by doNetlistTest().

◆ doNetlistTest()

void TEST_NETLISTS_FIXTURE::doNetlistTest ( const wxString &  aBaseName)

Definition at line 215 of file test_netlists.cpp.

216 {
217  loadSchematic( aBaseName );
218  writeNetlist();
219  compareNetlists();
220  cleanup();
221 }
void loadSchematic(const wxString &aBaseName)

References cleanup(), compareNetlists(), loadSchematic(), and writeNetlist().

◆ getNetlistFileName()

wxString TEST_NETLISTS_FIXTURE::getNetlistFileName ( bool  aTest = false)

Definition at line 129 of file test_netlists.cpp.

130 {
131  wxFileName netFile = m_schematic.Prj().GetProjectFullName();
132 
133  if( aTest )
134  netFile.SetName( netFile.GetName() + "_test" );
135 
136  netFile.SetExt( NetlistFileExtension );
137 
138  return netFile.GetFullPath();
139 }
const std::string NetlistFileExtension
SCHEMATIC m_schematic
Schematic to load
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:116
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75

References PROJECT::GetProjectFullName(), m_schematic, NetlistFileExtension, and SCHEMATIC::Prj().

Referenced by cleanup(), compareNetlists(), and writeNetlist().

◆ loadSchematic()

void TEST_NETLISTS_FIXTURE::loadSchematic ( const wxString &  aBaseName)

Definition at line 84 of file test_netlists.cpp.

85 {
86  wxString fn = getSchematicFile( aBaseName );
87 
88  BOOST_TEST_MESSAGE( fn );
89 
90  wxFileName pro( fn );
91  pro.SetExt( ProjectFileExtension );
92 
93  m_manager.LoadProject( pro.GetFullPath() );
94 
96 
100 
101  BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
102 
104 
105  SCH_SCREENS screens( m_schematic.Root() );
106 
107  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
108  screen->UpdateLocalLibSymbolLinks();
109 
111 
112  // Restore all of the loaded symbol instances from the root sheet screen.
114 
115  sheets.AnnotatePowerSymbols();
116 
117  // NOTE: This is required for multi-unit symbols to be correct
118  // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
119  for( SCH_SHEET_PATH& sheet : sheets )
120  sheet.UpdateAllScreenReferences();
121 
122  // NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
123  // SchematicCleanUp must be freed from its UI dependencies.
124 
125  m_schematic.ConnectionGraph()->Recalculate( sheets, true );
126 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:131
const std::string ProjectFileExtension
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const PROPERTIES *aProperties=nullptr)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:51
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetSymbolInstances() const
Definition: sch_screen.h:486
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr)
Updates the connection graph for the given list of sheets.
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:258
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:104
SCHEMATIC m_schematic
Schematic to load
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:76
void UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
SETTINGS_MANAGER m_manager
SCH_SHEET & Root() const
Definition: schematic.h:92
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:177
static wxString getSchematicFile(const wxString &aBaseName)
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:121
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:593

References SCH_SHEET_LIST::AnnotatePowerSymbols(), SCHEMATIC::ConnectionGraph(), SCHEMATIC::CurrentSheet(), PROJECT::ELEM_SCH_SYMBOL_LIBS, SCH_PLUGIN::GetError(), getSchematicFile(), SCHEMATIC::GetSheets(), SCH_SCREEN::GetSymbolInstances(), SCH_PLUGIN::Load(), SETTINGS_MANAGER::LoadProject(), m_manager, m_pi, m_schematic, SETTINGS_MANAGER::Prj(), ProjectFileExtension, SCH_SHEET_PATH::push_back(), CONNECTION_GRAPH::Recalculate(), SCHEMATIC::Reset(), SCHEMATIC::Root(), SCHEMATIC::RootScreen(), PROJECT::SetElem(), SCHEMATIC::SetProject(), SCHEMATIC::SetRoot(), and SCH_SHEET_LIST::UpdateSymbolInstances().

Referenced by doNetlistTest().

◆ writeNetlist()

void TEST_NETLISTS_FIXTURE::writeNetlist ( )

Definition at line 142 of file test_netlists.cpp.

143 {
144  auto exporter = std::make_unique<NETLIST_EXPORTER_KICAD>( &m_schematic );
145  BOOST_REQUIRE_EQUAL( exporter->WriteNetlist( getNetlistFileName( true ), 0 ), true );
146 }
wxString getNetlistFileName(bool aTest=false)
SCHEMATIC m_schematic
Schematic to load

References getNetlistFileName(), and m_schematic.

Referenced by doNetlistTest().

Member Data Documentation

◆ m_manager

SETTINGS_MANAGER TEST_NETLISTS_FIXTURE::m_manager

Definition at line 68 of file test_netlists.cpp.

Referenced by loadSchematic().

◆ m_pi

SCH_PLUGIN* TEST_NETLISTS_FIXTURE::m_pi

Definition at line 66 of file test_netlists.cpp.

Referenced by loadSchematic(), TEST_NETLISTS_FIXTURE(), and ~TEST_NETLISTS_FIXTURE().

◆ m_schematic

SCHEMATIC TEST_NETLISTS_FIXTURE::m_schematic

Schematic to load

Definition at line 64 of file test_netlists.cpp.

Referenced by cleanup(), getNetlistFileName(), loadSchematic(), writeNetlist(), and ~TEST_NETLISTS_FIXTURE().


The documentation for this class was generated from the following file: