65 std::unique_ptr<SYMBOL_BUFFER>
makeBuffer(
const wxString& aName )
67 auto symbol = std::make_unique<LIB_SYMBOL>( aName );
68 auto screen = std::make_unique<SCH_SCREEN>();
70 return std::make_unique<SYMBOL_BUFFER>( std::move( symbol ), std::move( screen ) );
94 aRestorePending, aTreeShownNow );
106 std::unique_ptr<SYMBOL_BUFFER> buf = makeBuffer( wxS(
"R" ) );
115 BOOST_CHECK( ctx.
GetSymbol() != &buf->GetSymbol() );
116 BOOST_CHECK( ctx.
GetScreen() != buf->GetScreen() );
124 std::unique_ptr<SYMBOL_BUFFER> clean = makeBuffer( wxS(
"C" ) );
126 clean->GetScreen()->SetContentModified();
144 const wxString reference = wxS(
"R5" );
163 BOOST_CHECK( ctx.
GetTabKey().StartsWith( wxString( wxT(
"\x01" ) ) ) );
165 BOOST_CHECK( ctx.
GetSymbol() == symbol );
166 BOOST_CHECK( ctx.
GetScreen() == screen );
173 std::unique_ptr<SYMBOL_BUFFER> buf = makeBuffer( wxS(
"R" ) );
174 buf->GetScreen()->SetContentModified();
186 source.m_OpenTabs.push_back( { wxS(
"Device" ), wxS(
"R" ), 1, 1 } );
187 source.m_OpenTabs.push_back( { wxS(
"Connector" ), wxS(
"Conn_01x02" ), 2, 1 } );
188 source.m_ActiveTabKey = wxS(
"Connector:Conn_01x02" );
192 std::string serialized =
source.FormatAsString();
193 nlohmann::json reparsed = nlohmann::json::parse( serialized );
202 sink.
m_OpenTabs.push_back( { wxS(
"STALE" ), wxS(
"X" ), 1, 1 } );
205 static_cast<nlohmann::json&
>( reparsedInternals ) = reparsed;
209 BOOST_REQUIRE_EQUAL( sink.
m_OpenTabs.size(), 2u );
237 BOOST_REQUIRE_EQUAL(
undo.m_CommandsList.size(), 2u );
238 BOOST_REQUIRE_EQUAL(
redo.m_CommandsList.size(), 1u );
240 freeTransientUndoCommands(
undo,
nullptr );
241 freeTransientUndoCommands(
redo,
nullptr );
256 auto liveSymbol = std::make_unique<INSTRUMENTED_LIB_SYMBOL>( wxS(
"live" ), &dtorCount );
263 undo.PushCommand( liveCmd );
267 freeTransientUndoCommands(
undo, liveSymbol.get() );
282 std::unique_ptr<SYMBOL_BUFFER> buf = makeBuffer( wxS(
"LMR16006" ) );
297 BOOST_CHECK( !
model.Entries()[0].modified );
308 BOOST_CHECK( libTreeAutoHiddenForSchematicEdit(
false,
false,
true ) );
311 BOOST_CHECK( !libTreeAutoHiddenForSchematicEdit(
false,
false,
false ) );
315 BOOST_CHECK( libTreeAutoHiddenForSchematicEdit(
true,
true,
false ) );
319 BOOST_CHECK( !libTreeAutoHiddenForSchematicEdit(
true,
false,
false ) );
322 BOOST_CHECK( libTreeAutoHiddenForSchematicEdit(
true,
false,
true ) );
void SetContentModified(bool aModified=true)
void SetFlags(EDA_ITEM_FLAGS aMask)
GUI-free preview/dirty/close state machine.
Headless tests for the Symbol Editor tabbed-document plumbing.
INSTRUMENTED_LIB_SYMBOL(const wxString &aName, int *aDtorCounter)
~INSTRUMENTED_LIB_SYMBOL() override
void CloneFrom(const JSON_SETTINGS_INTERNALS &aOther)
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
JSON_SETTINGS_INTERNALS * Internals()
wxString AsString() const
Define a library symbol object.
wxString GetName() const override
LIB_SYMBOL(const wxString &aName, LIB_SYMBOL *aParent=nullptr, LEGACY_SYMBOL_LIB *aLibrary=nullptr)
A holder to handle information on schematic or board items.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
std::vector< OPEN_TAB > m_OpenTabs
One open symbol tab owning a working LIB_SYMBOL and screen lent to the frame while active.
LIB_SYMBOL * GetSymbol() const
Observe the working symbol/screen.
const wxString & GetReference() const
static wxString MakeTabKey(const wxString &aLib, const wxString &aName)
De-duplication key for a library:symbol pair.
static wxString MakeInstanceTabKey(const KIID &aSchematicSymbolUUID)
De-duplication key for a placed schematic instance, in a namespace disjoint from library keys.
SCH_SCREEN * GetScreen() const
wxString GetTabKey() const override
Stable identity for persistence and de-duplication.
wxString GetDisplayName(bool aShortForm=false) const override
Short label shown on the tab.
const KIID & GetSchematicSymbolUUID() const
void SetBodyStyle(int aBodyStyle)
bool IsModified() const override
True when the working screen carries unsaved edits.
bool IsFromSchematic() const
bool IsTransient() const
True for a tab that is session-only and not persisted.
static void freeTransientUndoCommands(UNDO_REDO_CONTAINER &aList, const LIB_SYMBOL *aLiveSymbol)
Free every command in the list and the UR_TRANSIENT-flagged copies it owns, which the shared deleters...
static void clearTabModifiedState(SYMBOL_EDITOR_TAB_CONTEXT &aContext, EDITOR_TABS_MODEL &aModel)
Clear a tab's dirty state on both the context (read on repaint) and the strip model (read on close),...
static bool libTreeAutoHiddenForSchematicEdit(bool aWasFromSchematic, bool aRestorePending, bool aTreeShownNow)
Resolve whether the library tree's auto-hide for a schematic edit still needs restoring on save.
A holder to handle a list of undo (or redo) commands.
void PushCommand(PICKED_ITEMS_LIST *aCommand)
#define UR_TRANSIENT
indicates the item is owned by the undo/redo stack
static bool libTreeAutoHiddenForSchematicEdit(bool aWasFromSchematic, bool aRestorePending, bool aTreeShownNow)
Expose the library-tree visibility guard under test.
SYMBOL_EDITOR_TABS_TEST_FIXTURE()
std::unique_ptr< SYMBOL_BUFFER > makeBuffer(const wxString &aName)
Build a buffer over a fresh symbol and screen for the given name.
void pushTransientCommand(UNDO_REDO_CONTAINER &aList, LIB_SYMBOL *aTransient)
Push a UR_TRANSIENT-flagged symbol copy as a single-item command.
static void freeTransientUndoCommands(UNDO_REDO_CONTAINER &aList, const LIB_SYMBOL *aLiveSymbol)
Expose the private static free helper under test.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SymbolTabContextOwnsWorkingCopy)
The context owns a working copy cloned from the buffer, seeds its dirty flag, and round-trips the per...
BOOST_CHECK_EQUAL(result, "25.4")