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, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
27// Code under test
28#include <schematic.h>
29#include <sch_sheet.h>
30#include <sch_screen.h>
31#include <sch_group.h>
32#include <sch_symbol.h>
33#include <sch_pin.h>
34#include <lib_symbol.h>
35
38
39#include "eeschema_test_utils.h"
40
42{
43public:
45 {
46 //m_schematic = SCHEMATIC( nullptr );
47 //m_screen = SCH_SCREEN( &m_schematic );
48 }
49
51
53 {
54 m_schematic.reset();
55
56 m_manager.LoadProject( "" );
57 m_schematic = std::make_unique<SCHEMATIC>( &m_manager.Prj() );
58 m_schematic->Reset();
59
60 m_sheet = m_schematic->GetTopLevelSheet( 0 );
61 m_screen = m_sheet->GetScreen();
62
63 m_parent_part = new LIB_SYMBOL( "parent_part", nullptr );
64
66 m_parent_part->AddDrawItem( m_lib_pin );
67
68 // give the pin some kind of data we can use to test
69 m_lib_pin->SetNumber( "42" );
70 m_lib_pin->SetName( "pinname" );
72 m_lib_pin->SetPosition( VECTOR2I( 1, 2 ) );
73
75 m_parent_symbol = new SCH_SYMBOL( *m_parent_part, m_parent_part->GetLibId(), &path, 0, 0, VECTOR2I( 1, 2 ) );
76 m_parent_symbol->SetRef( &path, "U2" );
77 m_parent_symbol->UpdatePins();
78
79 m_sch_pin = m_parent_symbol->GetPins( &path )[0];
80
81 m_screen->Append( m_parent_symbol );
82 }
83
84 wxFileName SchematicQAPath( const wxString& aRelativePath ) override
85 {
86 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
87
88 wxString path = fn.GetFullPath();
89 path += aRelativePath + wxT( "." ) + FILEEXT::KiCadSchematicFileExtension;
90
91 return wxFileName( path );
92 }
93
95
97
100
102 SCH_PIN* m_sch_pin; // owned by m_parent_symbol, not us
103
105 {
107 group->AddItem( m_parent_symbol );
108
109 m_screen->Append( group );
110 }
111};
112
116BOOST_FIXTURE_TEST_SUITE( SchGroup, TEST_SCH_GROUP_FIXTURE )
117
118
119
123{
124 CreateTestSchematic();
125
126 BOOST_CHECK_EQUAL( m_sheet->IsTopLevelSheet(), true );
127 BOOST_CHECK_EQUAL( m_sheet->GetPosition(), VECTOR2I( 0, 0 ) );
128 BOOST_CHECK_EQUAL( m_sheet->CountSheets(), 1 );
129 BOOST_CHECK_EQUAL( m_sheet->SymbolCount(), 1 );
130
131 BOOST_CHECK_EQUAL( m_sheet->GetScreenCount(), 1 );
132}
133
138{
139 CreateTestSchematic();
140
141 SCH_GROUP* group = new SCH_GROUP( m_screen );
142 group->AddItem( m_parent_symbol );
143
144 m_screen->Append( group );
145
146 EE_RTREE::EE_TYPE groups = m_screen->Items().OfType( SCH_GROUP_T );
147 BOOST_CHECK_EQUAL( std::distance( groups.begin(), groups.end() ), 1 );
148}
149
150BOOST_AUTO_TEST_CASE( LoadSchGroups )
151{
152 LoadSchematic( SchematicQAPath( "groups_load_save" ) );
153
154 EE_RTREE::EE_TYPE groups = m_schematic->RootScreen()->Items().OfType( SCH_GROUP_T );
155
156 BOOST_CHECK_EQUAL( std::distance( groups.begin(), groups.end() ), 1 );
157
158 SCH_GROUP* group = static_cast<SCH_GROUP*>( *groups.begin() );
159 BOOST_CHECK_EQUAL( group->GetName(), "GroupName" );
160
161 BOOST_CHECK_EQUAL( group->GetItems().size(), 2 );
162}
163
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:79
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
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:44
Schematic symbol object.
Definition sch_symbol.h:69
wxFileName SchematicQAPath(const wxString &aRelativePath) override
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
@ PT_INPUT
usual pin input: must be connected
Definition pin_type.h:33
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:171
SearchIter begin()
Definition sch_rtree.h:210
SearchIter end()
Definition sch_rtree.h:211
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_AUTO_TEST_CASE(Default)
Declare the test suite.
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_GROUP_T
Definition typeinfo.h:170
Test utilities for timestamps.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683