20#include <boost/test/unit_test.hpp>
66 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
72 std::map<SCH_SYMBOL*, wxString> symbolNames;
78 auto* symbol =
static_cast<SCH_SYMBOL*
>( item );
79 symbolNames.emplace( symbol, symbol->GetNetChainName() );
83 BOOST_REQUIRE( std::any_of( symbolNames.begin(), symbolNames.end(),
84 [](
const auto& entry ) { return !entry.second.IsEmpty(); } ) );
86 bool hookFired =
false;
91 BOOST_CHECK_THROW( candidate.Rebuild( {} ), std::logic_error );
94 SCH_NETCHAIN* stray = candidate.CreateNetChainFromPotential(
95 candidate.GetPotentialNetChains().front().get(),
"ROLLBACK_PARTIAL" );
97 BOOST_REQUIRE_GT( candidate.GetCommittedNetChains().size(), 0u );
99 throw std::runtime_error(
"rollback test injected throw" );
102 BOOST_CHECK_THROW( graph->
Recalculate( sheets,
true ), std::runtime_error );
106 BOOST_CHECK( hookFired );
110 BOOST_CHECK( !m_schematic->NetChains().GetNetChainMemberNetOverrides().contains(
"ROLLBACK_PARTIAL" ) );
111 BOOST_CHECK( !m_schematic->NetChains().GetNetChainTerminalRefOverrides().contains(
"ROLLBACK_PARTIAL" ) );
113 for(
const auto& [symbol,
name] : symbolNames )
129 SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
134 bool hookFired =
false;
139 throw std::runtime_error(
"no-growth rollback test throw" );
142 BOOST_CHECK_THROW( graph->
Recalculate( sheets,
true ), std::runtime_error );
146 BOOST_CHECK( hookFired );
159 auto* graph = m_schematic->ConnectionGraph();
160 auto& chains = m_schematic->NetChains();
162 SCH_NETCHAIN* committed = chains.CreateNetChainFromPotential(
163 chains.GetPotentialNetChains().front().get(),
"ATOMIC_CHAIN" );
165 const auto originalNets = committed->
GetNets();
166 const auto originalMembers = chains.GetNetChainMemberNetOverrides();
174 auto* label =
static_cast<SCH_LABEL*
>( item );
177 if( connection && originalNets.contains( connection->Name() ) )
189 renamed->
SetText(
"ATOMIC_RENAMED" );
190 bool hookFired =
false;
195 throw std::runtime_error(
"existing chain refresh failure" );
198 BOOST_CHECK_THROW( graph->Recalculate( sheets,
true ), std::runtime_error );
201 BOOST_CHECK( hookFired );
202 BOOST_CHECK( chains.GetNetChainByName(
"ATOMIC_CHAIN" ) == committed );
203 BOOST_CHECK( committed->
GetNets() == originalNets );
205 BOOST_CHECK( committed->
GetSymbols().empty() );
206 BOOST_CHECK( chains.GetNetChainMemberNetOverrides() == originalMembers );
207 graph->Recalculate( sheets,
true );
208 BOOST_CHECK( committed->
GetNets().contains(
"/ATOMIC_RENAMED" ) );
209 BOOST_CHECK( chains.GetNetChainMemberNetOverrides().at(
"ATOMIC_CHAIN" ).contains(
"/ATOMIC_RENAMED" ) );
217 auto& chains = m_schematic->NetChains();
219 auto* original = chains.CreateNetChainFromPotential( chains.GetPotentialNetChains().front().get(),
225 BOOST_REQUIRE( candidate.CreateNetChainFromPotential( candidate.GetPotentialNetChains().front().get(),
228 m_schematic->ConnectionGraph()->Recalculate( m_schematic->Hierarchy(),
true );
230 BOOST_CHECK( chains.GetNetChainByName(
"ORIGINAL_CHAIN" ) == original );
231 BOOST_CHECK( chains.GetNetChainByName(
"ADDED_CHAIN" ) );
232 BOOST_CHECK( chains.NetChainsBuilt() );
Calculate the connectivity of a schematic and generate netlists.
SCH_NETCHAIN * GetNetChainByName(const wxString &aName)
static std::function< void(SCH_CONNECTIVITY::NETCHAIN_MANAGER &)> & RebuildNetChainsTestHook()
QA hook receives candidate state before publication and may throw to test rollback.
void Recalculate(const SCH_SHEET_LIST &aSheetList, bool aUnconditional=false, std::function< void(SCH_ITEM *)> *aChangedItemHandler=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Update the connection graph for the given list of sheets.
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetPotentialNetChains() const
Potential net chains are inferred groupings produced by RebuildNetChains() but not yet user-committed...
bool NetChainsBuilt() const
Returns true once RebuildNetChains() has completed at least once on this graph.
const std::vector< std::unique_ptr< SCH_NETCHAIN > > & GetCommittedNetChains() const
Return user-created (committed) net chains (legacy accessor retained under net-chain API).
virtual void SetText(const wxString &aText)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Persistent chain configuration and the derived chains for one schematic.
Base class for any item which can be embedded within the SCHEMATIC container class,...
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
A net chain is a collection of nets that are connected together through passive components.
const std::set< wxString > & GetNets() const
const std::set< class SCH_SYMBOL * > & GetSymbols() const
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
std::vector< FAB_LAYER_COLOR > dummy
NETCHAIN_ROLLBACK_FIXTURE()
std::unique_ptr< SCHEMATIC > m_schematic
~NETCHAIN_ROLLBACK_FIXTURE()
SETTINGS_MANAGER m_settingsManager
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_FIXTURE_TEST_CASE(NetChain_RebuildFailureDiscardsCandidate, NETCHAIN_ROLLBACK_FIXTURE)
BOOST_CHECK_EQUAL(result, "25.4")