qa_eeschema refactor: Create generic SCHEMATIC_TEST_FIXTURE

This commit is contained in:
Roberto Fernandez Bautista 2022-04-11 21:49:26 +01:00
parent 0e2429b5cc
commit 1db8229068
4 changed files with 82 additions and 169 deletions

View File

@ -30,6 +30,8 @@
#include <eeschema/sch_screen.h>
#include <eeschema/schematic.h>
#include <eeschema/connection_graph.h>
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <wildcards_and_files_ext.h>
#ifndef QA_EESCHEMA_DATA_LOCATION
@ -60,24 +62,39 @@ wxFileName KI_TEST::GetEeschemaTestDataDir()
}
std::unique_ptr<SCHEMATIC> ReadSchematicFromFile( const std::string& aFilename )
void KI_TEST::SCHEMATIC_TEST_FIXTURE::loadSchematic( const wxString& aRelativePath )
{
auto pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr );
wxFileName fn = getSchematicFile( aRelativePath );
schematic->Reset();
schematic->SetRoot( pi->Load( aFilename, schematic.get() ) );
schematic->CurrentSheet().push_back( &schematic->Root() );
BOOST_TEST_MESSAGE( fn.GetFullPath() );
SCH_SCREENS screens( schematic->Root() );
wxFileName pro( fn );
pro.SetExt( ProjectFileExtension );
m_schematic.Reset();
m_schematic.CurrentSheet().clear();
m_manager.LoadProject( pro.GetFullPath() );
m_manager.Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
m_schematic.SetProject( &m_manager.Prj() );
m_schematic.SetRoot( m_pi->Load( fn.GetFullPath(), &m_schematic ) );
BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
m_schematic.CurrentSheet().push_back( &m_schematic.Root() );
SCH_SCREENS screens( m_schematic.Root() );
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
screen->UpdateLocalLibSymbolLinks();
SCH_SHEET_LIST sheets = schematic->GetSheets();
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
// Restore all of the loaded symbol instances from the root sheet screen.
sheets.UpdateSymbolInstances( schematic->RootScreen()->GetSymbolInstances() );
sheets.UpdateSymbolInstances( m_schematic.RootScreen()->GetSymbolInstances() );
sheets.UpdateSheetInstances( m_schematic.RootScreen()->GetSheetInstances() );
sheets.AnnotatePowerSymbols();
@ -89,7 +106,18 @@ std::unique_ptr<SCHEMATIC> ReadSchematicFromFile( const std::string& aFilename )
// NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
// SchematicCleanUp must be freed from its UI dependencies.
schematic->ConnectionGraph()->Recalculate( sheets, true );
return schematic;
m_schematic.ConnectionGraph()->Recalculate( sheets, true );
}
wxFileName KI_TEST::SCHEMATIC_TEST_FIXTURE::getSchematicFile( const wxString& aBaseName )
{
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
fn.AppendDir( "netlists" );
fn.AppendDir( aBaseName );
fn.SetName( aBaseName );
fn.SetExt( KiCadSchematicFileExtension );
return fn;
}

View File

@ -24,11 +24,14 @@
#ifndef QA_EESCHEMA_EESCHEMA_TEST_UTILS__H
#define QA_EESCHEMA_EESCHEMA_TEST_UTILS__H
#include <schematic.h>
#include <settings/settings_manager.h>
#include <sch_io_mgr.h>
#include <wx/filename.h>
namespace KI_TEST
{
/**
* Get the configured location of Eeschema test data.
*
@ -39,6 +42,37 @@ namespace KI_TEST
*/
wxFileName GetEeschemaTestDataDir();
/**
* A generic fixture for loading schematics and associated settings for qa tests
*/
class SCHEMATIC_TEST_FIXTURE
{
public:
SCHEMATIC_TEST_FIXTURE() : m_schematic( nullptr ), m_manager( true )
{
m_pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
}
virtual ~SCHEMATIC_TEST_FIXTURE()
{
m_schematic.Reset();
delete m_pi;
}
protected:
void loadSchematic( const wxString& aRelativePath );
virtual wxFileName getSchematicFile( const wxString& aBaseName );
///> Schematic to load
SCHEMATIC m_schematic;
SCH_PLUGIN* m_pi;
SETTINGS_MANAGER m_manager;
};
} // namespace KI_TEST
#endif // QA_EESCHEMA_EESCHEMA_TEST_UTILS__H

View File

@ -32,24 +32,9 @@
#include <wildcards_and_files_ext.h>
class TEST_NETLISTS_FIXTURE
class TEST_NETLISTS_FIXTURE : public KI_TEST::SCHEMATIC_TEST_FIXTURE
{
public:
TEST_NETLISTS_FIXTURE() :
m_schematic( nullptr ),
m_manager( true )
{
m_pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
}
virtual ~TEST_NETLISTS_FIXTURE()
{
m_schematic.Reset();
SCH_IO_MGR::ReleasePlugin( m_pi );
}
void loadSchematic( const wxString& aBaseName );
protected:
wxString getNetlistFileName( bool aTest = false );
void writeNetlist();
@ -59,73 +44,9 @@ public:
void cleanup();
void doNetlistTest( const wxString& aBaseName );
///> Schematic to load
SCHEMATIC m_schematic;
SCH_PLUGIN* m_pi;
SETTINGS_MANAGER m_manager;
};
static wxString getSchematicFile( const wxString& aBaseName )
{
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
fn.AppendDir( "netlists" );
fn.AppendDir( aBaseName );
fn.SetName( aBaseName );
fn.SetExt( KiCadSchematicFileExtension );
return fn.GetFullPath();
}
void TEST_NETLISTS_FIXTURE::loadSchematic( const wxString& aBaseName )
{
wxString fn = getSchematicFile( aBaseName );
BOOST_TEST_MESSAGE( fn );
wxFileName pro( fn );
pro.SetExt( ProjectFileExtension );
m_manager.LoadProject( pro.GetFullPath() );
m_manager.Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
m_schematic.Reset();
m_schematic.SetProject( &m_manager.Prj() );
m_schematic.SetRoot( m_pi->Load( fn, &m_schematic ) );
BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
m_schematic.CurrentSheet().push_back( &m_schematic.Root() );
SCH_SCREENS screens( m_schematic.Root() );
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
screen->UpdateLocalLibSymbolLinks();
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
// Restore all of the loaded symbol instances from the root sheet screen.
sheets.UpdateSymbolInstances( m_schematic.RootScreen()->GetSymbolInstances() );
sheets.AnnotatePowerSymbols();
// NOTE: This is required for multi-unit symbols to be correct
// Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
for( SCH_SHEET_PATH& sheet : sheets )
sheet.UpdateAllScreenReferences();
// NOTE: SchematicCleanUp is not called; QA schematics must already be clean or else
// SchematicCleanUp must be freed from its UI dependencies.
m_schematic.ConnectionGraph()->Recalculate( sheets, true );
}
wxString TEST_NETLISTS_FIXTURE::getNetlistFileName( bool aTest )
{
wxFileName netFile = m_schematic.Prj().GetProjectFullName();

View File

@ -20,87 +20,17 @@
#include <qa_utils/wx_utils/unit_test_utils.h>
#include "eeschema_test_utils.h"
#include <sch_io_mgr.h>
#include <sch_screen.h>
#include <sch_sheet_path.h>
#include <schematic.h>
#include <settings/settings_manager.h>
#include <wildcards_and_files_ext.h>
class TEST_SCH_SHEET_LIST_FIXTURE
class TEST_SCH_SHEET_LIST_FIXTURE : public KI_TEST::SCHEMATIC_TEST_FIXTURE
{
public:
TEST_SCH_SHEET_LIST_FIXTURE() :
m_schematic( nullptr ),
m_manager( true )
{
m_pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_KICAD );
}
virtual ~TEST_SCH_SHEET_LIST_FIXTURE()
{
m_schematic.Reset();
delete m_pi;
}
void loadSchematic( const wxString& aRelativePath );
wxFileName buildFullPath( const wxString& aRelativePath );
///> Schematic to load
SCHEMATIC m_schematic;
SCH_PLUGIN* m_pi;
SETTINGS_MANAGER m_manager;
protected:
wxFileName getSchematicFile( const wxString& aRelativePath ) override;
};
void TEST_SCH_SHEET_LIST_FIXTURE::loadSchematic( const wxString& aRelativePath )
{
wxFileName fn = buildFullPath( aRelativePath );
BOOST_TEST_MESSAGE( fn.GetFullPath() );
wxFileName pro( fn );
pro.SetExt( ProjectFileExtension );
m_schematic.Reset();
m_schematic.CurrentSheet().clear();
m_manager.LoadProject( pro.GetFullPath() );
m_manager.Prj().SetElem( PROJECT::ELEM_SCH_SYMBOL_LIBS, nullptr );
m_schematic.SetProject( &m_manager.Prj() );
m_schematic.SetRoot( m_pi->Load( fn.GetFullPath(), &m_schematic ) );
BOOST_REQUIRE_EQUAL( m_pi->GetError().IsEmpty(), true );
m_schematic.CurrentSheet().push_back( &m_schematic.Root() );
SCH_SCREENS screens( m_schematic.Root() );
for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
screen->UpdateLocalLibSymbolLinks();
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
// Restore all of the loaded symbol instances from the root sheet screen.
sheets.UpdateSymbolInstances( m_schematic.RootScreen()->GetSymbolInstances() );
sheets.UpdateSheetInstances( m_schematic.RootScreen()->GetSheetInstances() );
sheets.AnnotatePowerSymbols();
// NOTE: This is required for multi-unit symbols to be correct
// Normally called from SCH_EDIT_FRAME::FixupJunctions() but could be refactored
for( SCH_SHEET_PATH& sheet : sheets )
sheet.UpdateAllScreenReferences();
}
wxFileName TEST_SCH_SHEET_LIST_FIXTURE::buildFullPath( const wxString& aRelativePath )
wxFileName TEST_SCH_SHEET_LIST_FIXTURE::getSchematicFile( const wxString& aRelativePath )
{
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
fn.AppendDir( "netlists" );
@ -174,7 +104,7 @@ BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign )
// Save and reload
wxString tempName = "complex_hierarchy_shared/complex_hierarchy_modified";
wxFileName tempFn = buildFullPath( tempName );
wxFileName tempFn = getSchematicFile( tempName );
m_pi->Save( tempFn.GetFullPath(), &m_schematic.Root(), &m_schematic );
loadSchematic( tempName );