20#include <boost/test/unit_test.hpp>
27#include <wx/filename.h>
28#include <wx/stdpaths.h>
45 BOOST_CHECK( a == b );
49 BOOST_CHECK( a != b );
53 BOOST_CHECK( a == b );
67 BOOST_CHECK( a != b );
71 BOOST_CHECK( a == b );
75 BOOST_CHECK( a != b );
79 BOOST_CHECK( a == b );
93 BOOST_CHECK( a != b );
94 BOOST_CHECK( b != a );
101 const wxString& aExpected )
108 if( resolved->GetName() == aExpected )
111 for(
NETCLASS* constituent : resolved->GetConstituentNetclasses() )
113 if( constituent && constituent->GetName() == aExpected )
128 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
129 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
130 classes[wxS(
"HighSpeed" )] = highSpeed;
148 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
149 std::shared_ptr<NETCLASS> power = std::make_shared<NETCLASS>( wxS(
"Power" ),
false );
150 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
151 classes[wxS(
"HighSpeed" )] = highSpeed;
152 classes[wxS(
"Power" )] = power;
175 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
176 std::shared_ptr<NETCLASS> power = std::make_shared<NETCLASS>( wxS(
"Power" ),
false );
177 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
178 classes[wxS(
"HighSpeed" )] = highSpeed;
179 classes[wxS(
"Power" )] = power;
183 wxS(
"HighSpeed" ) );
229 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
230 std::shared_ptr<NETCLASS> power = std::make_shared<NETCLASS>( wxS(
"Power" ),
false );
231 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
232 classes[wxS(
"HighSpeed" )] = highSpeed;
233 classes[wxS(
"Power" )] = power;
238 BOOST_CHECK( a == b );
242 BOOST_CHECK( a == b );
247 BOOST_CHECK( a == b );
251 BOOST_CHECK( a == b );
264 source.SetNetChainClass( wxS(
"CHAIN_A" ), wxS(
"Default" ) );
265 source.SetNetChainClass( wxS(
"CHAIN_B" ), wxS(
"HighSpeed" ) );
266 source.SetNetChainClass( wxS(
"CHAIN_WITH_SPACES and: punctuation!" ), wxS(
"Power" ) );
267 source.SetNetChainClass( wxS(
"Unicode_éèê" ), wxS(
"RF_µwave" ) );
274 std::string serialized =
source.FormatAsString();
275 nlohmann::json reparsed = nlohmann::json::parse( serialized );
287 static_cast<nlohmann::json&
>( reparsedInternals ) = reparsed;
293 BOOST_CHECK( sink.
GetNetChainClass( wxS(
"CHAIN_A" ) ) == wxS(
"Default" ) );
294 BOOST_CHECK( sink.
GetNetChainClass( wxS(
"CHAIN_B" ) ) == wxS(
"HighSpeed" ) );
295 BOOST_CHECK( sink.
GetNetChainClass( wxS(
"CHAIN_WITH_SPACES and: punctuation!" ) )
297 BOOST_CHECK( sink.
GetNetChainClass( wxS(
"Unicode_éèê" ) ) == wxS(
"RF_µwave" ) );
299 BOOST_CHECK(
source == sink );
311 std::string serialized =
source.FormatAsString();
312 nlohmann::json reparsed = nlohmann::json::parse( serialized );
315 BOOST_CHECK( reparsed[
"net_chain_classes"].is_object() );
316 BOOST_CHECK( reparsed[
"net_chain_classes"].
empty() );
323 static_cast<nlohmann::json&
>( reparsedInternals ) = reparsed;
339 source.SetNetChainClass( wxS(
"KEEP" ), wxS(
"Default" ) );
343 nlohmann::json reparsed = nlohmann::json::parse(
source.FormatAsString() );
346 BOOST_REQUIRE_EQUAL( reparsed[
"net_chain_classes"].size(), 1u );
349 reparsed[
"net_chain_classes"][
"EMPTY"] =
"";
354 static_cast<nlohmann::json&
>( reparsedInternals ) = reparsed;
373 BOOST_CHECK( a != b );
377 BOOST_CHECK( a != b );
381 BOOST_CHECK( a == b );
385 BOOST_CHECK( a != b );
389 BOOST_CHECK( a == b );
400 source.SetNetChainNetClass( wxS(
"CHAIN_A" ), wxS(
"HighSpeed" ) );
401 source.SetNetChainNetClass( wxS(
"Unicode_éèê" ), wxS(
"RF_µwave" ) );
405 nlohmann::json reparsed = nlohmann::json::parse(
source.FormatAsString() );
407 BOOST_REQUIRE( reparsed.contains(
"net_chain_netclasses" ) );
408 BOOST_REQUIRE( reparsed[
"net_chain_netclasses"].is_object() );
412 reparsed[
"net_chain_netclasses"][
"EMPTY"] =
"";
420 static_cast<nlohmann::json&
>( reparsedInternals ) = reparsed;
429 BOOST_CHECK(
source == sink );
451 wxFileName tempDir( wxStandardPaths::Get().GetTempDir(), wxEmptyString );
452 wxString tempName = wxString::Format( wxT(
"kicad_qa_25065_%ld" ), wxGetProcessId() );
453 tempDir.AppendDir( tempName );
455 BOOST_REQUIRE( wxFileName::Mkdir( tempDir.GetPath(), wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
457 wxFileName tempFile( tempDir.GetPath(), wxT(
"project.json" ) );
499 std::ifstream in( tempFile.GetFullPath().fn_str(), std::ios::in | std::ios::binary );
500 std::string contents( ( std::istreambuf_iterator<char>( in ) ),
501 std::istreambuf_iterator<char>() );
503 nlohmann::json onDisk = nlohmann::json::parse( contents );
507 const nlohmann::json& netChainNetClasses = onDisk[
"net_settings"][
"net_chain_netclasses"];
508 const nlohmann::json& netChainClasses = onDisk[
"net_settings"][
"net_chain_classes"];
510 BOOST_CHECK( netChainNetClasses.contains(
"CHAIN_A" ) );
511 BOOST_CHECK( !netChainNetClasses.contains(
"CHAIN_B" ) );
512 BOOST_CHECK( netChainClasses.contains(
"CHAIN_A" ) );
513 BOOST_CHECK( !netChainClasses.contains(
"CHAIN_B" ) );
515 wxRemoveFile( tempFile.GetFullPath() );
516 wxFileName::Rmdir( tempDir.GetPath() );
529 BOOST_CHECK( a == b );
535 BOOST_CHECK( a != b );
539 BOOST_CHECK( a == b );
543 BOOST_CHECK( a != b );
554 std::shared_ptr<NETCLASS> replacement = std::make_shared<NETCLASS>(
NETCLASS::Default,
true );
555 replacement->SetTrackWidth( 300000 );
559 BOOST_CHECK( a != b );
571 std::shared_ptr<NETCLASS> highSpeedA = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
572 std::shared_ptr<NETCLASS> highSpeedB = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
577 BOOST_CHECK( a == b );
579 highSpeedA->SetClearance( 100000 );
581 BOOST_CHECK( a != b );
583 highSpeedB->SetClearance( 100000 );
585 BOOST_CHECK( a == b );
597 source.GetDefaultNetclass()->SetClearance( 250000 );
598 source.GetDefaultNetclass()->SetTrackWidth( 200000 );
599 source.GetDefaultNetclass()->SetDescription( wxS(
"Project default" ) );
601 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
602 highSpeed->SetClearance( 150000 );
603 highSpeed->SetTrackWidth( 127000 );
604 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
605 classes[wxS(
"HighSpeed" )] = highSpeed;
606 source.SetNetclasses( classes );
608 source.SetNetclassPatternAssignment( wxS(
"DDR_*" ), wxS(
"HighSpeed" ) );
609 source.SetNetclassLabelAssignment( wxS(
"EXACT_NET" ), { wxS(
"HighSpeed" ) } );
610 source.SetNetChainClass( wxS(
"DDR_BUS" ), wxS(
"HighSpeed" ) );
615 BOOST_CHECK(
source == sink );
619 source.GetDefaultNetclass()->SetClearance( 999999 );
621 BOOST_CHECK(
source != sink );
632 source.GetDefaultNetclass()->SetClearance( 100000 );
637 std::shared_ptr<NETCLASS> stale = std::make_shared<NETCLASS>( wxS(
"StaleClass" ),
false );
638 std::map<wxString, std::shared_ptr<NETCLASS>> staleClasses;
639 staleClasses[wxS(
"StaleClass" )] = stale;
647 BOOST_CHECK(
source == sink );
661 std::shared_ptr<NETCLASS> stalePower = std::make_shared<NETCLASS>( wxS(
"StalePower" ),
false );
662 std::map<wxString, std::shared_ptr<NETCLASS>> staleClasses;
663 staleClasses[wxS(
"StalePower" )] = stalePower;
687 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
688 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
689 classes[wxS(
"HighSpeed" )] = highSpeed;
721 std::shared_ptr<NETCLASS> highSpeed = std::make_shared<NETCLASS>( wxS(
"HighSpeed" ),
false );
722 std::map<wxString, std::shared_ptr<NETCLASS>> classes;
723 classes[wxS(
"HighSpeed" )] = highSpeed;
740 BOOST_CHECK(
resolvesToNetclass( settings, wxS(
"/Sheet2/CLK" ), wxS(
"HighSpeed" ) ) );
741 BOOST_CHECK(
resolvesToNetclass( settings, wxS(
"/Sheet2/DATA0" ), wxS(
"HighSpeed" ) ) );
742 BOOST_CHECK(
resolvesToNetclass( settings, wxS(
"/Sheet2/Sub/EN" ), wxS(
"HighSpeed" ) ) );
743 BOOST_CHECK( !
resolvesToNetclass( settings, wxS(
"/Sheet1/CLK" ), wxS(
"HighSpeed" ) ) );
746 BOOST_CHECK(
resolvesToNetclass( settings, wxS(
"/Other/RST" ), wxS(
"HighSpeed" ) ) );
747 BOOST_CHECK(
resolvesToNetclass( settings, wxS(
"/Sheet10/BUS" ), wxS(
"HighSpeed" ) ) );
750 BOOST_CHECK( colors.count( wxS(
"/Sheet2/CLK" ) ) == 1 );
751 BOOST_CHECK( colors.count( wxS(
"/Sheet1/CLK" ) ) == 0 );
768 const long last = std::numeric_limits<long>::max();
769 const wxString
text = wxString::Format(
"D[%ld..%ld]", last - 1, last );
770 std::vector<wxString> members;
772 BOOST_REQUIRE_EQUAL( members.size(), 2 );
779 std::vector<wxString> members;
781 BOOST_REQUIRE_EQUAL( members.size(), 3 );
789 size_t boundary = 99;
805 std::weak_ptr<NETCLASS> weakSignal;
808 std::shared_ptr<NETCLASS> signal = std::make_shared<NETCLASS>( wxS(
"Signal" ),
false );
817 BOOST_REQUIRE_EQUAL( composite->GetConstituentNetclasses().size(), 2u );
826 BOOST_CHECK( weakSignal.expired() );
void CloneFrom(const JSON_SETTINGS_INTERNALS &aOther)
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
void SetManager(SETTINGS_MANAGER *aManager)
JSON_SETTINGS_INTERNALS * Internals()
void ReleaseNestedSettings(NESTED_SETTINGS *aSettings)
Saves and frees a nested settings object, if it exists within this one.
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
A color representation with 4 components: red, green, blue, alpha.
bool LoadFromFile(const wxString &aDirectory="") override
Loads the JSON document from the parent and then calls Load()
A collection of nets and the parameters used to route or test these nets.
static const char Default[]
the name of the default NETCLASS
void SetClearance(int aClearance)
void SetTrackWidth(int aWidth)
NET_SETTINGS stores various net-related settings in a project context.
const std::map< wxString, wxString > & GetNetChainNetClasses() const
void SetNetChainClass(const wxString &aChain, const wxString &aClass)
Assign a net chain to a named class (used by inNetChainClass() DRC scope).
void SetNetChainNetClass(const wxString &aChain, const wxString &aNetclass)
Assign the netclass a net chain applies to all of its member nets.
std::shared_ptr< NETCLASS > GetEffectiveNetClass(const wxString &aNetName)
Fetches the effective (may be aggregate) netclass for the given net name.
wxString GetNetChainClass(const wxString &aChain) const
Look up the class assigned to a chain. Empty string means "no class".
bool HasEffectiveNetClass(const wxString &aNetName) const
Determines if an effective netclass for the given net name has been cached.
bool RenameNetPathPrefix(const wxString &aOldPrefix, const wxString &aNewPrefix)
Retarget netclass patterns and net colors after a path prefix changes (sheet rename).
void SetNetclasses(const std::map< wxString, std::shared_ptr< NETCLASS > > &netclasses)
Sets all netclass Calling this method will reset the effective netclass calculation caches.
void SetNetclassLabelAssignment(const wxString &netName, const std::set< wxString > &netclasses)
Sets a net name to netclasses assignment Calling user is responsible for resetting the effective netc...
void ClearNetclasses()
Clears all netclasses Calling this method will reset the effective netclass calculation caches.
wxString GetNetChainNetClass(const wxString &aChain) const
Look up the netclass a chain applies to its members. Empty string means "none".
void SetNetclassPatternAssignment(const wxString &pattern, const wxString &netclass)
Sets a netclass pattern assignment Calling this method will reset the effective netclass calculation ...
const std::map< wxString, std::shared_ptr< NETCLASS > > & GetNetclasses() const
Gets all netclasses.
static bool ParseBusGroup(const wxString &aGroup, wxString *name, std::vector< wxString > *aMemberList, size_t *aPrefixEnd=nullptr)
Parse a bus group label into the name and a list of components.
std::shared_ptr< NETCLASS > GetDefaultNetclass() const
Gets the default netclass for the project.
void SetChainPatternAssignment(NET_CHAIN_SOURCE aSource, const wxString &pattern, const wxString &netclass)
Sets a chain-derived netclass pattern assignment owned by aSource.
const std::map< wxString, wxString > & GetNetChainClasses() const
static bool ParseBusVector(const wxString &aBus, wxString *aName, std::vector< wxString > *aMemberList)
Parse a bus vector (e.g.
const std::map< wxString, KIGFX::COLOR4D > & GetNetColorAssignments() const
Gets all net name to color assignments.
void ClearChainPatternAssignments(NET_CHAIN_SOURCE aSource)
Clears the chain-derived pattern assignments owned by aSource, leaving the other source's entries in ...
void CopyFrom(NET_SETTINGS &aOther)
Deep-copy the persisted contents of aOther into this instance.
std::vector< std::pair< std::unique_ptr< EDA_COMBINED_MATCHER >, wxString > > & GetNetclassPatternAssignments()
Gets the netclass pattern assignments.
void ClearNetChainClasses()
Removes all chain-to-class assignments.
void ClearNetChainNetClasses()
Removes all chain-to-netclass assignments.
bool HasChainPatternAssignments(NET_CHAIN_SOURCE aSource) const
Returns true if aSource has contributed any chain-derived pattern assignment.
void SetNetclass(const wxString &netclassName, std::shared_ptr< NETCLASS > &netclass)
Sets the given netclass Calling user is responsible for resetting the effective netclass calculation ...
void SetDefaultNetclass(std::shared_ptr< NETCLASS > netclass)
Sets the default netclass for the project Calling user is responsible for resetting the effective net...
void SetNetColorAssignment(const wxString &netName, const KIGFX::COLOR4D &color)
Sets a net to color assignment Calling user is responsible for resetting the effective netclass calcu...
TEST_PROJECT_SETTINGS(const wxString &aFilename)
static bool empty(const wxTextEntryBase *aCtrl)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ChainClassAssignmentAffectsEquality)
static bool resolvesToNetclass(NET_SETTINGS &aSettings, const wxString &aNetName, const wxString &aExpected)
BOOST_CHECK_EQUAL(result, "25.4")