KiCad PCB EDA Suite
TEST_NETLIST_EXPORTER_KICAD_FIXTURE Class Reference
Inheritance diagram for TEST_NETLIST_EXPORTER_KICAD_FIXTURE:
TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD > KI_TEST::SCHEMATIC_TEST_FIXTURE

Public Member Functions

void CompareNetlists () override
 
void CompareNetlists () override
 
virtual wxString GetNetlistPath (bool aTest=false)
 
virtual unsigned GetNetlistOptions ()
 
void WriteNetlist ()
 
void Cleanup ()
 
void TestNetlist (const wxString &aBaseName)
 

Protected Member Functions

virtual void LoadSchematic (const wxString &aRelativePath)
 
virtual wxFileName GetSchematicPath (const wxString &aBaseName)
 

Protected Attributes

SCHEMATIC m_schematic
 

‍Schematic to load

More...
 
SCH_PLUGINm_pi
 
SETTINGS_MANAGER m_manager
 

Detailed Description

Definition at line 24 of file test_netlist_exporter_kicad.cpp.

Member Function Documentation

◆ Cleanup()

Definition at line 103 of file eeschema_test_utils.cpp.

153{
154 wxRemoveFile( GetNetlistPath( true ) );
156}
SCHEMATIC m_schematic
‍Schematic to load
void Reset()
Initialize this schematic to a blank one, unloading anything existing.
Definition: schematic.cpp:51

◆ CompareNetlists() [1/2]

void TEST_NETLIST_EXPORTER_KICAD_FIXTURE::CompareNetlists ( )
inlineoverridevirtual

Implements TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >.

Definition at line 27 of file test_netlist_exporter_kicad.cpp.

28 {
29 NETLIST golden;
31
32 {
33 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
34 &golden, GetNetlistPath(), wxEmptyString ) );
35
36 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
37 }
38
39 {
40 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
41 &test, GetNetlistPath( true ), wxEmptyString ) );
42
43 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
44 }
45
46 // Number of components should match
47 BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
48
49 for( unsigned i = 0; i < golden.GetCount(); i++ )
50 {
51 COMPONENT* goldenComp = golden.GetComponent( i );
52 COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
53
54 // Retrieval by reference
55 BOOST_REQUIRE_NE( refComp, nullptr );
56
57 // Retrieval by KIID
58 KIID_PATH path = goldenComp->GetPath();
59
60 BOOST_REQUIRE( !goldenComp->GetKIIDs().empty() );
61
62 path.push_back( goldenComp->GetKIIDs().front() );
63
64 COMPONENT* pathComp = test.GetComponentByPath( path );
65 BOOST_REQUIRE_NE( pathComp, nullptr );
66
67 // We should have found the same component
68 BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
69
70 // And that component should have the same number of attached nets
71 BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
72
73 for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
74 {
75 const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
76 const COMPONENT_NET& testNet = refComp->GetNet( net );
77
78 // The video test has a bunch of unconnected RESERVED pins which cause duplicate
79 // auto-generated netnames. The connectivity algo disambiguates these with "_n"
80 // suffixes, but since the algorithm is multi-threaded, which ones get which suffix
81 // is not deterministic. So skip these.
82 if( testNet.GetPinFunction().Contains( "RESERVED" ) )
83 continue;
84
85 // The two nets at the same index should be identical
86 BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
87 BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
88 }
89 }
90 }
Used to store the component pin name to net name (and pin function) associations stored in a netlist.
Definition: pcb_netlist.h:44
const wxString & GetNetName() const
Definition: pcb_netlist.h:58
const wxString & GetPinFunction() const
Definition: pcb_netlist.h:59
const wxString & GetPinName() const
Definition: pcb_netlist.h:57
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:85
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:111
const KIID_PATH & GetPath() const
Definition: pcb_netlist.h:143
const wxString & GetReference() const
Definition: pcb_netlist.h:126
const std::vector< KIID > & GetKIIDs() const
Definition: pcb_netlist.h:145
unsigned GetNetCount() const
Definition: pcb_netlist.h:109
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...
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:213
unsigned GetCount() const
Definition: pcb_netlist.h:234
COMPONENT * GetComponent(unsigned aIndex)
Return the COMPONENT at aIndex.
Definition: pcb_netlist.h:242

References NETLIST::GetComponent(), NETLIST::GetCount(), COMPONENT::GetKIIDs(), COMPONENT::GetNet(), COMPONENT::GetNetCount(), TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >::GetNetlistPath(), NETLIST_READER::GetNetlistReader(), COMPONENT_NET::GetNetName(), COMPONENT::GetPath(), COMPONENT_NET::GetPinFunction(), COMPONENT_NET::GetPinName(), COMPONENT::GetReference(), and path.

◆ CompareNetlists() [2/2]

void TEST_NETLIST_EXPORTER_KICAD_FIXTURE::CompareNetlists ( )
inlineoverridevirtual

Implements TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >.

Definition at line 27 of file test_netlists.cpp.

28 {
29 NETLIST golden;
31
32 {
33 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
34 &golden, getNetlistFileName(), wxEmptyString ) );
35
36 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
37 }
38
39 {
40 std::unique_ptr<NETLIST_READER> netlistReader( NETLIST_READER::GetNetlistReader(
41 &test, getNetlistFileName( true ), wxEmptyString ) );
42
43 BOOST_REQUIRE_NO_THROW( netlistReader->LoadNetlist() );
44 }
45
46 // Number of components should match
47 BOOST_REQUIRE_EQUAL( golden.GetCount(), test.GetCount() );
48
49 for( unsigned i = 0; i < golden.GetCount(); i++ )
50 {
51 COMPONENT* goldenComp = golden.GetComponent( i );
52 COMPONENT* refComp = test.GetComponentByReference( goldenComp->GetReference() );
53
54 // Retrieval by reference
55 BOOST_REQUIRE_NE( refComp, nullptr );
56
57 // Retrieval by KIID
58 KIID_PATH path = goldenComp->GetPath();
59
60 BOOST_REQUIRE( !goldenComp->GetKIIDs().empty() );
61
62 path.push_back( goldenComp->GetKIIDs().front() );
63
64 COMPONENT* pathComp = test.GetComponentByPath( path );
65 BOOST_REQUIRE_NE( pathComp, nullptr );
66
67 // We should have found the same component
68 BOOST_REQUIRE_EQUAL( refComp->GetReference(), pathComp->GetReference() );
69
70 // And that component should have the same number of attached nets
71 BOOST_REQUIRE_EQUAL( goldenComp->GetNetCount(), refComp->GetNetCount() );
72
73 for( unsigned net = 0; net < goldenComp->GetNetCount(); net++ )
74 {
75 const COMPONENT_NET& goldenNet = goldenComp->GetNet( net );
76 const COMPONENT_NET& testNet = refComp->GetNet( net );
77
78 // The video test has a bunch of unconnected RESERVED pins which cause duplicate
79 // auto-generated netnames. The connectivity algo disambiguates these with "_n"
80 // suffixes, but since the algorithm is multi-threaded, which ones get which suffix
81 // is not deterministic. So skip these.
82 if( testNet.GetPinFunction().Contains( "RESERVED" ) )
83 continue;
84
85 // The two nets at the same index should be identical
86 BOOST_REQUIRE_EQUAL( goldenNet.GetNetName(), testNet.GetNetName() );
87 BOOST_REQUIRE_EQUAL( goldenNet.GetPinName(), testNet.GetPinName() );
88 }
89 }
90 }

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

◆ GetNetlistOptions()

virtual unsigned TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >::GetNetlistOptions ( )
inlinevirtualinherited

Definition at line 97 of file eeschema_test_utils.h.

97{ return 0; }

◆ GetNetlistPath()

wxString TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >::GetNetlistPath ( bool  aTest = false)
virtualinherited

Definition at line 96 of file eeschema_test_utils.cpp.

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

◆ GetSchematicPath()

wxFileName KI_TEST::SCHEMATIC_TEST_FIXTURE::GetSchematicPath ( const wxString &  aBaseName)
protectedvirtualinherited

Reimplemented in TEST_SCH_SHEET_LIST_FIXTURE.

Definition at line 112 of file eeschema_test_utils.cpp.

113{
114 wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
115 fn.AppendDir( "netlists" );
116 fn.AppendDir( aBaseName );
117 fn.SetName( aBaseName );
118 fn.SetExt( KiCadSchematicFileExtension );
119
120 return fn;
121}
const std::string KiCadSchematicFileExtension
wxFileName GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.

References KI_TEST::GetEeschemaTestDataDir(), and KiCadSchematicFileExtension.

Referenced by KI_TEST::SCHEMATIC_TEST_FIXTURE::LoadSchematic().

◆ LoadSchematic()

void KI_TEST::SCHEMATIC_TEST_FIXTURE::LoadSchematic ( const wxString &  aRelativePath)
protectedvirtualinherited

Definition at line 65 of file eeschema_test_utils.cpp.

66{
67 wxFileName fn = GetSchematicPath( aBaseName );
68
69 BOOST_TEST_MESSAGE( fn.GetFullPath() );
70
71 wxFileName pro( fn );
72 pro.SetExt( ProjectFileExtension );
73
74 // Schematic must be reset before a project is reloaded
76 m_manager.LoadProject( pro.GetFullPath() );
77
79
81 m_schematic.SetRoot( m_pi->Load( fn.GetFullPath(), &m_schematic ) );
82
83 BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
84
86
87 SCH_SCREENS screens( m_schematic.Root() );
88
89 for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
90 screen->UpdateLocalLibSymbolLinks();
91
93
94 // Restore all of the loaded symbol instances from the root sheet screen.
97
98 sheets.AnnotatePowerSymbols();
99
100 // NOTE: This is required for multi-unit symbols to be correct
101 // Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
102 for( SCH_SHEET_PATH& sheet : sheets )
103 sheet.UpdateAllScreenReferences();
104
105 // NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
106 // SchematicCleanUp must be freed from its UI dependencies.
107
108 m_schematic.ConnectionGraph()->Recalculate( sheets, true );
109}
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 wxFileName GetSchematicPath(const wxString &aBaseName)
virtual void SetElem(ELEM_T aIndex, _ELEM *aElem)
Definition: project.cpp:293
@ ELEM_SCH_SYMBOL_LIBS
Definition: project.h:207
SCH_SHEET_PATH & CurrentSheet() const override
Definition: schematic.h:119
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:129
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:85
void SetRoot(SCH_SHEET *aRootSheet)
Initialize the schematic with a new root sheet.
Definition: schematic.cpp:104
void SetProject(PROJECT *aPrj)
Definition: schematic.cpp:76
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
SCH_SHEET & Root() const
Definition: schematic.h:90
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
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:177
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:613
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetSymbolInstances() const
Definition: sch_screen.h:488
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
Definition: sch_screen.h:493
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void UpdateSheetInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheetInstances)
Update all of the sheet instance information using aSheetInstances.
void UpdateSymbolInstances(const std::vector< SYMBOL_INSTANCE_REFERENCE > &aSymbolInstances)
Update all of the symbol instance information using aSymbolInstances.
void AnnotatePowerSymbols()
Silently annotate the not yet annotated power symbols of the entire hierarchy of the sheet path list.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
const std::string ProjectFileExtension

References SCHEMATIC::CurrentSheet(), PROJECT::ELEM_SCH_SYMBOL_LIBS, SCH_PLUGIN::GetError(), SCH_SCREENS::GetFirst(), SCH_SCREENS::GetNext(), KI_TEST::SCHEMATIC_TEST_FIXTURE::GetSchematicPath(), SCHEMATIC::GetSheets(), SCH_SCREEN::GetSymbolInstances(), SCH_PLUGIN::Load(), SETTINGS_MANAGER::LoadProject(), KI_TEST::SCHEMATIC_TEST_FIXTURE::m_manager, KI_TEST::SCHEMATIC_TEST_FIXTURE::m_pi, KI_TEST::SCHEMATIC_TEST_FIXTURE::m_schematic, SETTINGS_MANAGER::Prj(), ProjectFileExtension, SCH_SHEET_PATH::push_back(), SCHEMATIC::Reset(), SCHEMATIC::Root(), SCHEMATIC::RootScreen(), PROJECT::SetElem(), SCHEMATIC::SetProject(), SCHEMATIC::SetRoot(), and SCH_SHEET_LIST::UpdateSymbolInstances().

Referenced by TEST_SCH_REFERENCE_LIST_FIXTURE::loadTestCase().

◆ TestNetlist()

void TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >::TestNetlist ( const wxString &  aBaseName)
inherited

◆ WriteNetlist()

void TEST_NETLIST_EXPORTER_FIXTURE< NETLIST_EXPORTER_KICAD >::WriteNetlist
inherited

Definition at line 99 of file eeschema_test_utils.cpp.

140{
141 // In case of a crash the file may not have been deleted.
142 if( wxFileExists( GetNetlistPath( true ) ) )
143 wxRemoveFile( GetNetlistPath( true ) );
144
145 auto exporter = std::make_unique<Exporter>( &m_schematic );
146 BOOST_REQUIRE_EQUAL( exporter->WriteNetlist( GetNetlistPath( true ), GetNetlistOptions() ),
147 true );
148}

Member Data Documentation

◆ m_manager

SETTINGS_MANAGER KI_TEST::SCHEMATIC_TEST_FIXTURE::m_manager
protectedinherited

◆ m_pi

SCH_PLUGIN* KI_TEST::SCHEMATIC_TEST_FIXTURE::m_pi
protectedinherited

◆ m_schematic


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