KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_schematic.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
25#include "eeschema_test_utils.h"
26
27#include <lib_symbol.h>
28#include <sch_screen.h>
29#include <sch_symbol.h>
30#include <schematic.h>
31#include <bus_alias.h>
32#include <project.h>
35
36
38{
39protected:
40 wxFileName SchematicQAPath( const wxString& aRelativePath ) override;
41};
42
43
44wxFileName TEST_SCHEMATIC_FIXTURE::SchematicQAPath( const wxString& aRelativePath )
45{
46 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
47
48 wxString path = fn.GetFullPath();
49 path += aRelativePath + wxT( "." ) + FILEEXT::KiCadSchematicFileExtension;
50
51 return wxFileName( path );
52}
53
54
55BOOST_FIXTURE_TEST_SUITE( Schematic, TEST_SCHEMATIC_FIXTURE )
56
57
58BOOST_AUTO_TEST_CASE( TestSchematicSharedByMultipleProjects )
59{
60 LoadSchematic( SchematicQAPath( "schematic_object_tests/not_shared_by_multiple_projects/"
61 "not_shared_by_multiple_projects" ) );
62
63 std::set<const SCH_SCREEN*> sharedScreens = m_schematic->GetSchematicsSharedByMultipleProjects();
64
65 BOOST_CHECK( sharedScreens.empty() );
66
67 LoadSchematic( SchematicQAPath( "schematic_object_tests/shared_by_multiple_projects/"
68 "project_a/project_a" ) );
69
70 sharedScreens = m_schematic->GetSchematicsSharedByMultipleProjects();
71
72 BOOST_CHECK( !sharedScreens.empty() );
73}
74
75
76BOOST_AUTO_TEST_CASE( TestSchematicIsComplexHierarchy )
77{
78 LoadSchematic( SchematicQAPath( "netlists/group_bus_matching/group_bus_matching" ) );
79
80 BOOST_CHECK( !m_schematic->IsComplexHierarchy() );
81
82 LoadSchematic( SchematicQAPath( "netlists/complex_hierarchy/complex_hierarchy" ) );
83
84 BOOST_CHECK( m_schematic->IsComplexHierarchy() );
85}
86
87
88BOOST_AUTO_TEST_CASE( BusAliasesKeepLastDefinitionAcrossReset )
89{
90 LoadSchematic( SchematicQAPath( "netlists/hierarchy_aliases/hierarchy_aliases" ) );
91 auto original = m_schematic->GetBusAlias( wxS( "ALIAS1" ) );
92 BOOST_REQUIRE( original );
93 auto changed = original->Clone();
94 changed->SetMembers( { wxS( "CHANGED" ) } );
95
96 m_schematic->AddBusAlias( changed );
97 BOOST_REQUIRE( m_schematic->GetBusAlias( original->GetName() ) );
98 BOOST_CHECK( m_schematic->GetBusAlias( original->GetName() )->Members() == changed->Members() );
99 BOOST_CHECK( m_schematic->Project().GetProjectFile().m_BusAliases.at( original->GetName() )
100 == changed->Members() );
101 changed->SetMembers( original->Members() );
102 BOOST_CHECK( m_schematic->GetBusAlias( original->GetName() )->Members() != changed->Members() );
103 changed->SetMembers( { wxS( "CHANGED" ) } );
104
105 m_schematic->AddBusAlias( original );
106 BOOST_CHECK( m_schematic->GetAllBusAliases().back()->Members() == original->Members() );
107 m_schematic->SetBusAliases( { original, changed, original } );
108 BOOST_CHECK( m_schematic->GetAllBusAliases().back()->Members() == original->Members() );
109 m_schematic->SetBusAliases( m_schematic->GetAllBusAliases() );
110 BOOST_REQUIRE( m_schematic->GetBusAlias( original->GetName() ) );
111
112 m_schematic->Reset();
113 BOOST_REQUIRE( m_schematic->GetBusAlias( original->GetName() ) );
114 BOOST_CHECK( m_schematic->GetBusAlias( original->GetName() )->Members() == original->Members() );
115 m_schematic->SetBusAliases( {} );
116 m_schematic->Reset();
117 BOOST_CHECK( m_schematic->GetAllBusAliases().empty() );
118 BOOST_CHECK( m_schematic->Project().GetProjectFile().m_BusAliases.empty() );
119}
120
121
122BOOST_AUTO_TEST_CASE( DestructionReleasesSharedHierarchySymbols )
123{
124 LoadSchematic( SchematicQAPath( "issue23840/BusAndVectors" ) );
125 const SCH_SHEET_LIST sheets = m_schematic->BuildSheetListSortedByPageNumbers();
126 BOOST_REQUIRE_EQUAL( sheets.size(), 3 );
127 std::set<SCH_SCREEN*> screens;
128
129 for( const SCH_SHEET_PATH& path : sheets )
130 screens.insert( path.LastScreen() );
131
132 BOOST_REQUIRE_EQUAL( screens.size(), 2 );
133 std::vector<std::weak_ptr<LIB_SYMBOL>> symbols;
134
135 for( SCH_SCREEN* screen : screens )
136 {
137 BOOST_REQUIRE( !screen->GetLibSymbols().empty() );
138 symbols.emplace_back( screen->GetLibSymbols().begin()->second->SharedPtr() );
139 auto items = screen->Items().OfType( SCH_SYMBOL_T );
140 BOOST_REQUIRE( items.begin() != items.end() );
141 const auto* symbol = static_cast<const SCH_SYMBOL*>( *items.begin() );
142 BOOST_REQUIRE( symbol->GetLibSymbolRef() );
143 symbols.emplace_back( symbol->GetLibSymbolRef()->SharedPtr() );
144 }
145
146 for( const std::weak_ptr<LIB_SYMBOL>& symbol : symbols )
147 BOOST_REQUIRE( !symbol.expired() );
148
149 m_schematic.reset();
150
151 for( const std::weak_ptr<LIB_SYMBOL>& symbol : symbols )
152 BOOST_CHECK( symbol.expired() );
153}
154
155
A generic fixture for loading schematics and associated settings for qa tests.
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...
Schematic symbol object.
Definition sch_symbol.h:75
wxFileName SchematicQAPath(const wxString &aRelativePath) override
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_AUTO_TEST_CASE(TestSchematicSharedByMultipleProjects)
@ SCH_SYMBOL_T
Definition typeinfo.h:168
Definition of file extensions used in Kicad.