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
28
29
#include <
qa_utils/wx_utils/unit_test_utils.h
>
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
40
#include <
qa_utils/uuid_test_utils.h
>
41
#include <
qa_utils/wx_utils/wx_assert.h
>
42
43
#include "
eeschema_test_utils.h
"
44
45
class
TEST_SCH_GROUP_FIXTURE
:
public
KI_TEST::SCHEMATIC_TEST_FIXTURE
46
{
47
public
:
48
TEST_SCH_GROUP_FIXTURE
()
49
{
50
//m_schematic = SCHEMATIC( nullptr );
51
//m_screen = SCH_SCREEN( &m_schematic );
52
}
53
54
~TEST_SCH_GROUP_FIXTURE
() {}
55
56
void
CreateTestSchematic
()
57
{
58
m_schematic
.reset();
59
60
m_manager
.LoadProject(
""
);
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() );
66
m_sheet
->SetScreen(
m_screen
);
67
68
m_schematic
->SetRoot(
m_sheet
);
69
70
m_parent_part
=
new
LIB_SYMBOL
(
"parent_part"
,
nullptr
);
71
72
m_lib_pin
=
new
SCH_PIN
(
m_parent_part
);
73
m_parent_part
->AddDrawItem(
m_lib_pin
);
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
81
SCH_SHEET_PATH
path
;
82
m_parent_symbol
=
new
SCH_SYMBOL
( *
m_parent_part
,
m_parent_part
->GetLibId(), &
path
, 0, 0,
VECTOR2I
( 1, 2 ) );
83
m_parent_symbol
->SetRef( &
path
,
"U2"
);
84
m_parent_symbol
->UpdatePins();
85
86
m_sch_pin
=
m_parent_symbol
->GetPins( &
path
)[0];
87
88
m_screen
->Append(
m_parent_symbol
);
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
101
SCH_SCREEN
*
m_screen
;
102
103
SCH_SHEET
*
m_sheet
;
104
105
LIB_SYMBOL
*
m_parent_part
;
106
SCH_PIN
*
m_lib_pin
;
107
108
SCH_SYMBOL
*
m_parent_symbol
;
109
SCH_PIN
*
m_sch_pin
;
// owned by m_parent_symbol, not us
110
111
void
CreateGroup
()
112
{
113
SCH_GROUP
*
group
=
new
SCH_GROUP
(
m_screen
);
114
group
->AddItem(
m_parent_symbol
);
115
116
m_screen
->Append(
group
);
117
}
118
};
119
123
BOOST_FIXTURE_TEST_SUITE( SchGroup,
TEST_SCH_GROUP_FIXTURE
)
124
125
126
129
BOOST_AUTO_TEST_CASE
( Default )
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
145
BOOST_AUTO_TEST_CASE
( CreateGroup )
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
158
BOOST_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
172
BOOST_AUTO_TEST_SUITE_END
()
BITMAPS::path
@ path
Definition
bitmaps_list.h:432
BITMAPS::group
@ group
Definition
bitmaps_list.h:248
KI_TEST::SCHEMATIC_TEST_FIXTURE
A generic fixture for loading schematics and associated settings for qa tests.
Definition
eeschema_test_utils.h:50
KI_TEST::SCHEMATIC_TEST_FIXTURE::m_manager
SETTINGS_MANAGER m_manager
Definition
eeschema_test_utils.h:62
KI_TEST::SCHEMATIC_TEST_FIXTURE::m_schematic
std::unique_ptr< SCHEMATIC > m_schematic
Definition
eeschema_test_utils.h:60
LIB_SYMBOL
Define a library symbol object.
Definition
lib_symbol.h:85
SCH_GROUP
A set of SCH_ITEMs (i.e., without duplicates).
Definition
sch_group.h:52
SCH_PIN
Definition
sch_pin.h:41
SCH_SCREEN
Definition
sch_screen.h:99
SCH_SHEET_PATH
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Definition
sch_sheet_path.h:133
SCH_SHEET
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition
sch_sheet.h:47
SCH_SYMBOL
Schematic symbol object.
Definition
sch_symbol.h:75
TEST_SCH_GROUP_FIXTURE
Definition
test_sch_group.cpp:46
TEST_SCH_GROUP_FIXTURE::CreateTestSchematic
void CreateTestSchematic()
Definition
test_sch_group.cpp:56
TEST_SCH_GROUP_FIXTURE::CreateGroup
void CreateGroup()
Definition
test_sch_group.cpp:111
TEST_SCH_GROUP_FIXTURE::m_sch_pin
SCH_PIN * m_sch_pin
Definition
test_sch_group.cpp:109
TEST_SCH_GROUP_FIXTURE::m_lib_pin
SCH_PIN * m_lib_pin
Definition
test_sch_group.cpp:106
TEST_SCH_GROUP_FIXTURE::m_screen
SCH_SCREEN * m_screen
Definition
test_sch_group.cpp:101
TEST_SCH_GROUP_FIXTURE::~TEST_SCH_GROUP_FIXTURE
~TEST_SCH_GROUP_FIXTURE()
Definition
test_sch_group.cpp:54
TEST_SCH_GROUP_FIXTURE::m_sheet
SCH_SHEET * m_sheet
Definition
test_sch_group.cpp:103
TEST_SCH_GROUP_FIXTURE::GetSchematicPath
wxFileName GetSchematicPath(const wxString &aRelativePath) override
Definition
test_sch_group.cpp:91
TEST_SCH_GROUP_FIXTURE::m_parent_part
LIB_SYMBOL * m_parent_part
Definition
test_sch_group.cpp:105
TEST_SCH_GROUP_FIXTURE::m_parent_symbol
SCH_SYMBOL * m_parent_symbol
Definition
test_sch_group.cpp:108
TEST_SCH_GROUP_FIXTURE::TEST_SCH_GROUP_FIXTURE
TEST_SCH_GROUP_FIXTURE()
Definition
test_sch_group.cpp:48
eeschema_test_utils.h
FILEEXT::KiCadSchematicFileExtension
static const std::string KiCadSchematicFileExtension
Definition
wildcards_and_files_ext.h:133
lib_symbol.h
KI_TEST::GetEeschemaTestDataDir
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition
unit_test_utils.cpp:34
ELECTRICAL_PINTYPE::PT_INPUT
@ PT_INPUT
usual pin input: must be connected
Definition
pin_type.h:37
sch_group.h
Class to handle a set of SCH_ITEMs.
LoadSchematic
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
Definition
sch_io_easyeda.cpp:508
sch_pin.h
sch_screen.h
sch_sheet.h
sch_symbol.h
schematic.h
EE_RTREE::EE_TYPE
The EE_TYPE struct provides a type-specific auto-range iterator to the RTree.
Definition
sch_rtree.h:195
EE_RTREE::EE_TYPE::begin
iterator begin()
Definition
sch_rtree.h:225
EE_RTREE::EE_TYPE::end
iterator end()
Definition
sch_rtree.h:230
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:134
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Default)
Declare the test suite.
Definition
test_sch_group.cpp:129
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
SCH_GROUP_T
@ SCH_GROUP_T
Definition
typeinfo.h:175
unit_test_utils.h
uuid_test_utils.h
Test utilities for timestamps.
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:695
wx_assert.h
src
qa
tests
eeschema
test_sch_group.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2