KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_group.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
30
31// Code under test
32#include <schematic.h>
33#include <sch_sheet.h>
34#include <sch_screen.h>
35#include <sch_group.h>
36#include <sch_symbol.h>
37#include <sch_pin.h>
38#include <lib_symbol.h>
39
42
43#include "eeschema_test_utils.h"
44
46{
47public:
49 {
50 //m_schematic = SCHEMATIC( nullptr );
51 //m_screen = SCH_SCREEN( &m_schematic );
52 }
53
55
57 {
58 m_schematic.release();
59
61 m_schematic = std::make_unique<SCHEMATIC>( &m_manager.Prj() );
62
63 m_screen = new SCH_SCREEN( m_schematic.get() );
64
65 m_sheet = new SCH_SHEET( m_schematic.get() );
67
68 m_schematic->SetRoot( m_sheet );
69
70 m_parent_part = new LIB_SYMBOL( "parent_part", nullptr );
71
74
75 // give the pin some kind of data we can use to test
76 m_lib_pin->SetNumber( "42" );
77 m_lib_pin->SetName( "pinname" );
78 m_lib_pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT );
79 m_lib_pin->SetPosition( VECTOR2I( 1, 2 ) );
80
83 m_parent_symbol->SetRef( &path, "U2" );
85
87
89 }
90
91 wxFileName GetSchematicPath( const wxString& aRelativePath ) override
92 {
93 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
94
95 wxString path = fn.GetFullPath();
96 path += aRelativePath + wxT( "." ) + FILEEXT::KiCadSchematicFileExtension;
97
98 return wxFileName( path );
99 }
100
102
104
107
109 SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
110
112 {
114 group->AddItem( m_parent_symbol );
115
117 }
118};
119
123BOOST_FIXTURE_TEST_SUITE( SchGroup, TEST_SCH_GROUP_FIXTURE )
124
125
126
130{
131 CreateTestSchematic();
132
133 //BOOST_CHECK_NOT_EQUAL( m_sheet.GetParent(), nullptr );
134 BOOST_CHECK_EQUAL( m_sheet->IsRootSheet(), true );
135 BOOST_CHECK_EQUAL( m_sheet->GetPosition(), VECTOR2I( 0, 0 ) );
136 BOOST_CHECK_EQUAL( m_sheet->CountSheets(), 1 );
137 BOOST_CHECK_EQUAL( m_sheet->SymbolCount(), 1 );
138
139 BOOST_CHECK_EQUAL( m_sheet->GetScreenCount(), 1 );
140}
141
146{
147 CreateTestSchematic();
148
149 SCH_GROUP* group = new SCH_GROUP( m_screen );
150 group->AddItem( m_parent_symbol );
151
152 m_screen->Append( group );
153
154 EE_RTREE::EE_TYPE groups = m_screen->Items().OfType( SCH_GROUP_T );
155 BOOST_CHECK_EQUAL( std::distance( groups.begin(), groups.end() ), 1 );
156}
157
158BOOST_AUTO_TEST_CASE( LoadSchGroups )
159{
160 LoadSchematic( "groups_load_save" );
161
162 EE_RTREE::EE_TYPE groups = m_schematic->RootScreen()->Items().OfType( SCH_GROUP_T );
163
164 BOOST_CHECK_EQUAL( std::distance( groups.begin(), groups.end() ), 1 );
165
166 SCH_GROUP* group = static_cast<SCH_GROUP*>( *groups.begin() );
167 BOOST_CHECK_EQUAL( group->GetName(), "GroupName" );
168
169 BOOST_CHECK_EQUAL( group->GetItems().size(), 2 );
170}
171
A generic fixture for loading schematics and associated settings for qa tests.
std::unique_ptr< SCHEMATIC > m_schematic
Define a library symbol object.
Definition: lib_symbol.h:85
const LIB_ID & GetLibId() const override
Definition: lib_symbol.h:155
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:786
A set of SCH_ITEMs (i.e., without duplicates).
Definition: sch_group.h:52
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:554
void SetName(const wxString &aName)
Definition: sch_pin.cpp:405
void SetPosition(const VECTOR2I &aPos) override
Definition: sch_pin.h:224
void SetType(ELECTRICAL_PINTYPE aType)
Definition: sch_pin.cpp:315
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Definition: sch_screen.cpp:158
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:47
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:137
Schematic symbol object.
Definition: sch_symbol.h:75
void UpdatePins()
Updates the cache of SCH_PIN objects for each pin.
Definition: sch_symbol.cpp:288
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:592
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
wxFileName GetSchematicPath(const wxString &aRelativePath) override
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Class to handle a set of SCH_ITEMs.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
The EE_TYPE struct provides a type-specific auto-range iterator to the RTree.
Definition: sch_rtree.h:195
iterator begin()
Definition: sch_rtree.h:225
iterator end()
Definition: sch_rtree.h:230
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Default)
Declare the test suite.
@ SCH_GROUP_T
Definition: typeinfo.h:173
Test utilities for timestamps.
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695