KiCad PCB EDA Suite
TEST_NETLISTS_FIXTURE Class Reference

Public Member Functions

 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.

Member Function Documentation

◆ cleanup()

void TEST_NETLISTS_FIXTURE::cleanup ( )

Definition at line 196 of file test_netlists.cpp.

197 {
198  wxRemoveFile( getNetlistFileName( true ) );
199 }
wxString getNetlistFileName(bool aTest=false)

References getNetlistFileName().

Referenced by doNetlistTest().

◆ compareNetlists()

void TEST_NETLISTS_FIXTURE::compareNetlists ( )

Definition at line 143 of file test_netlists.cpp.

144 {
145  NETLIST golden;
146  NETLIST test;
147 
148  {
149  std::unique_ptr<NETLIST_READER> netlistReader(
150  NETLIST_READER::GetNetlistReader( &golden, getNetlistFileName(), wxEmptyString ) );
151 
152  BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
153  }
154 
155  {
156  std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
157  &test, getNetlistFileName( true ), wxEmptyString ) );
158 
159  BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
160  }
161 
162  // Number of components should match
163  BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
164 
165  for( unsigned i = 0; i < golden.GetCount(); i++ )
166  {
167  COMPONENT* goldenComp = golden.GetComponent( i );
168  COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
169 
170  // Retrieval by reference
171  BOOST_REQUIRE_NE( refComp, nullptr );
172 
173  // Retrieval by KIID
174  COMPONENT* pathComp = test.GetComponentByPath( goldenComp->GetPath() );
175  BOOST_REQUIRE_NE( pathComp, nullptr );
176 
177  // We should have found the same component
178  BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
179 
180  // And that component should have the same number of attached nets
181  BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
182 
183  for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
184  {
185  const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
186  const COMPONENT_NET& testNet = refComp->GetNet( net );
187 
188  // The two nets at the same index should be identical
189  BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
190  BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
191  }
192  }
193 }
static NETLIST_READER * GetNetlistReader(NETLIST *aNetlist, const wxString &aNetlistFileName, const wxString &aCompFootprintFileName=wxEmptyString)
Function GetNetlistReader attempts to determine the net list file type of aNetlistFileName and return...
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:224
COMPONENT_NET is used to store the component pin name to net name (and pin function) associations sto...
Definition: pcb_netlist.h:44
wxString getNetlistFileName(bool aTest=false)
const wxString & GetNetName() const
Definition: pcb_netlist.h:60
NETLIST stores all of information read from a netlist along with the flags used to update the NETLIST...
Definition: pcb_netlist.h:194
unsigned GetNetCount() const
Definition: pcb_netlist.h:133
const wxString & GetReference() const
Definition: pcb_netlist.h:147
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:135
COMPONENT is used to store components and all of their related information found in a netlist.
Definition: pcb_netlist.h:80
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:233
const wxString & GetPinName() const
Definition: pcb_netlist.h:59
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:162

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

Referenced by doNetlistTest().

◆ doNetlistTest()

void TEST_NETLISTS_FIXTURE::doNetlistTest ( const wxString &  aBaseName)

Definition at line 202 of file test_netlists.cpp.

203 {
204  loadSchematic( aBaseName );
205  writeNetlist();
206  compareNetlists();
207  cleanup();
208 }
void loadSchematic(const wxString &aBaseName)

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

◆ getNetlistFileName()

wxString TEST_NETLISTS_FIXTURE::getNetlistFileName ( bool  aTest = false)

Definition at line 123 of file test_netlists.cpp.

124 {
125  wxFileName netFile = m_schematic.Prj().GetProjectFullName();
126 
127  if( aTest )
128  netFile.SetName( netFile.GetName() + "_test" );
129 
130  netFile.SetExt( NetlistFileExtension );
131 
132  return netFile.GetFullPath();
133 }
const std::string NetlistFileExtension
SCHEMATIC m_schematic
Schematic to load
VTBL_ENTRY const wxString GetProjectFullName() const
Function GetProjectFullName returns the full path and name of the project.
Definition: project.cpp:115
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:79

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 78 of file test_netlists.cpp.

79 {
80  wxString fn = getSchematicFile( aBaseName );
81 
82  BOOST_TEST_MESSAGE( fn );
83 
84  wxFileName pro( fn );
85  pro.SetExt( ProjectFileExtension );
86 
87  m_manager.LoadProject( pro.GetFullPath() );
88 
90 
94 
95  BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
96 
98 
99  SCH_SCREENS screens( m_schematic.Root() );
100 
101  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
102  screen->UpdateLocalLibSymbolLinks();
103 
105 
106  // Restore all of the loaded symbol instances from the root sheet screen.
108 
109  sheets.AnnotatePowerSymbols();
110 
111  // NOTE: This is required for multi-unit symbols to be correct
112  // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
113  for( SCH_SHEET_PATH& sheet : sheets )
114  sheet.UpdateAllScreenReferences();
115 
116  // NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
117  // SchematicCleanUp must be freed from its UI dependencies.
118 
119  m_schematic.ConnectionGraph()->Recalculate( sheets, true );
120 }
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void UpdateSymbolInstances(const std::vector< COMPONENT_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:91
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:131
const std::string ProjectFileExtension
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false)
Updates the connection graph for the given list of sheets.
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
virtual SCH_SHEET * Load(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:51
const std::vector< COMPONENT_INSTANCE_REFERENCE > & GetSymbolInstances() const
Definition: sch_screen.h:496
VTBL_ENTRY void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:257
void SetRoot(SCH_SHEET *aRootSheet)
Initializes the schematic with a new root sheet.
Definition: schematic.cpp:99
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:72
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
void Reset()
Initializes this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:49
SETTINGS_MANAGER m_manager
SCH_SHEET & Root() const
Definition: schematic.h:96
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 retreive the screen of the root sheet.
Definition: schematic.cpp:112
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:521
SCH_SHEET_PATH & CurrentSheet() const
Definition: schematic.h:121

References SCH_SHEET_LIST::AnnotatePowerSymbols(), SCHEMATIC::ConnectionGraph(), SCHEMATIC::CurrentSheet(), PROJECT::ELEM_SCH_PART_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 136 of file test_netlists.cpp.

137 {
138  auto exporter = std::make_unique<NETLIST_EXPORTER_KICAD>( &m_schematic );
139  BOOST_REQUIRE_EQUAL( exporter->WriteNetlist( getNetlistFileName( true ), 0 ), true );
140 }
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 62 of file test_netlists.cpp.

Referenced by loadSchematic().

◆ m_pi

SCH_PLUGIN* TEST_NETLISTS_FIXTURE::m_pi

Definition at line 60 of file test_netlists.cpp.

Referenced by loadSchematic(), and TEST_NETLISTS_FIXTURE().

◆ m_schematic

SCHEMATIC TEST_NETLISTS_FIXTURE::m_schematic

Schematic to load

Definition at line 58 of file test_netlists.cpp.

Referenced by getNetlistFileName(), loadSchematic(), and writeNetlist().


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