35#include <nlohmann/json.hpp>
64 std::unique_ptr<SYMBOL_BUFFER>
makeBuffer(
const wxString& aName )
66 auto symbol = std::make_unique<LIB_SYMBOL>( aName );
67 auto screen = std::make_unique<SCH_SCREEN>();
69 return std::make_unique<SYMBOL_BUFFER>( std::move( symbol ), std::move( screen ) );
97 std::unique_ptr<SYMBOL_BUFFER> buf = makeBuffer( wxS(
"R" ) );
106 BOOST_CHECK( ctx.
GetSymbol() != &buf->GetSymbol() );
107 BOOST_CHECK( ctx.
GetScreen() != buf->GetScreen() );
115 std::unique_ptr<SYMBOL_BUFFER> clean = makeBuffer( wxS(
"C" ) );
117 clean->GetScreen()->SetContentModified();
135 const wxString reference = wxS(
"R5" );
154 BOOST_CHECK( ctx.
GetTabKey().StartsWith( wxString( wxT(
"\x01" ) ) ) );
156 BOOST_CHECK( ctx.
GetSymbol() == symbol );
157 BOOST_CHECK( ctx.
GetScreen() == screen );
164 std::unique_ptr<SYMBOL_BUFFER> buf = makeBuffer( wxS(
"R" ) );
165 buf->GetScreen()->SetContentModified();
177 source.
m_OpenTabs.push_back( { wxS(
"Device" ), wxS(
"R" ), 1, 1 } );
178 source.
m_OpenTabs.push_back( { wxS(
"Connector" ), wxS(
"Conn_01x02" ), 2, 1 } );
184 nlohmann::json reparsed = nlohmann::json::parse( serialized );
193 sink.
m_OpenTabs.push_back( { wxS(
"STALE" ), wxS(
"X" ), 1, 1 } );
196 static_cast<nlohmann::json&
>( reparsedInternals ) = reparsed;
200 BOOST_REQUIRE_EQUAL( sink.
m_OpenTabs.size(), 2u );
228 BOOST_REQUIRE_EQUAL(
undo.m_CommandsList.size(), 2u );
229 BOOST_REQUIRE_EQUAL(
redo.m_CommandsList.size(), 1u );
231 freeTransientUndoCommands(
undo,
nullptr );
232 freeTransientUndoCommands(
redo,
nullptr );
247 auto liveSymbol = std::make_unique<INSTRUMENTED_LIB_SYMBOL>( wxS(
"live" ), &dtorCount );
254 undo.PushCommand( liveCmd );
258 freeTransientUndoCommands(
undo, liveSymbol.get() );
void SetContentModified(bool aModified=true)
void SetFlags(EDA_ITEM_FLAGS aMask)
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.
const std::string FormatAsString()
JSON_SETTINGS_INTERNALS * Internals()
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
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.
wxString GetDisplayName() const override
Short label shown on the tab.
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.
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 an instance (schematic) tab, which is session-only and never 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...
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
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")