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
25
#include <
qa_utils/wx_utils/unit_test_utils.h
>
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
36
#include <
qa_utils/uuid_test_utils.h
>
37
#include <
qa_utils/wx_utils/wx_assert.h
>
38
39
#include "
eeschema_test_utils.h
"
40
41
class
TEST_SCH_GROUP_FIXTURE
:
public
KI_TEST::SCHEMATIC_TEST_FIXTURE
42
{
43
public
:
44
TEST_SCH_GROUP_FIXTURE
()
45
{
46
//m_schematic = SCHEMATIC( nullptr );
47
//m_screen = SCH_SCREEN( &m_schematic );
48
}
49
50
~TEST_SCH_GROUP_FIXTURE
() {}
51
52
void
CreateTestSchematic
()
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
65
m_lib_pin
=
new
SCH_PIN
(
m_parent_part
);
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"
);
71
m_lib_pin
->SetType(
ELECTRICAL_PINTYPE::PT_INPUT
);
72
m_lib_pin
->SetPosition(
VECTOR2I
( 1, 2 ) );
73
74
SCH_SHEET_PATH
path
;
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
94
SCH_SCREEN
*
m_screen
;
95
96
SCH_SHEET
*
m_sheet
;
97
98
LIB_SYMBOL
*
m_parent_part
;
99
SCH_PIN
*
m_lib_pin
;
100
101
SCH_SYMBOL
*
m_parent_symbol
;
102
SCH_PIN
*
m_sch_pin
;
// owned by m_parent_symbol, not us
103
104
void
CreateGroup
()
105
{
106
SCH_GROUP
*
group
=
new
SCH_GROUP
(
m_screen
);
107
group
->AddItem(
m_parent_symbol
);
108
109
m_screen
->Append(
group
);
110
}
111
};
112
116
BOOST_FIXTURE_TEST_SUITE( SchGroup,
TEST_SCH_GROUP_FIXTURE
)
117
118
119
122
BOOST_AUTO_TEST_CASE
( Default )
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
137
BOOST_AUTO_TEST_CASE
( CreateGroup )
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
150
BOOST_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
164
BOOST_AUTO_TEST_SUITE_END
()
BITMAPS::group
@ group
Definition
bitmaps_list.h:246
KI_TEST::SCHEMATIC_TEST_FIXTURE
A generic fixture for loading schematics and associated settings for qa tests.
Definition
eeschema_test_utils.h:46
KI_TEST::SCHEMATIC_TEST_FIXTURE::m_manager
SETTINGS_MANAGER m_manager
Definition
eeschema_test_utils.h:59
KI_TEST::SCHEMATIC_TEST_FIXTURE::m_schematic
std::unique_ptr< SCHEMATIC > m_schematic
Definition
eeschema_test_utils.h:57
LIB_SYMBOL
Define a library symbol object.
Definition
lib_symbol.h:79
SCH_GROUP
A set of SCH_ITEMs (i.e., without duplicates).
Definition
sch_group.h:48
SCH_PIN
Definition
sch_pin.h:41
SCH_SCREEN
Definition
sch_screen.h:97
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:231
SCH_SHEET
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition
sch_sheet.h:44
SCH_SYMBOL
Schematic symbol object.
Definition
sch_symbol.h:69
TEST_SCH_GROUP_FIXTURE
Definition
test_sch_group.cpp:42
TEST_SCH_GROUP_FIXTURE::CreateTestSchematic
void CreateTestSchematic()
Definition
test_sch_group.cpp:52
TEST_SCH_GROUP_FIXTURE::CreateGroup
void CreateGroup()
Definition
test_sch_group.cpp:104
TEST_SCH_GROUP_FIXTURE::m_sch_pin
SCH_PIN * m_sch_pin
Definition
test_sch_group.cpp:102
TEST_SCH_GROUP_FIXTURE::m_lib_pin
SCH_PIN * m_lib_pin
Definition
test_sch_group.cpp:99
TEST_SCH_GROUP_FIXTURE::m_screen
SCH_SCREEN * m_screen
Definition
test_sch_group.cpp:94
TEST_SCH_GROUP_FIXTURE::~TEST_SCH_GROUP_FIXTURE
~TEST_SCH_GROUP_FIXTURE()
Definition
test_sch_group.cpp:50
TEST_SCH_GROUP_FIXTURE::m_sheet
SCH_SHEET * m_sheet
Definition
test_sch_group.cpp:96
TEST_SCH_GROUP_FIXTURE::m_parent_part
LIB_SYMBOL * m_parent_part
Definition
test_sch_group.cpp:98
TEST_SCH_GROUP_FIXTURE::SchematicQAPath
wxFileName SchematicQAPath(const wxString &aRelativePath) override
Definition
test_sch_group.cpp:84
TEST_SCH_GROUP_FIXTURE::m_parent_symbol
SCH_SYMBOL * m_parent_symbol
Definition
test_sch_group.cpp:101
TEST_SCH_GROUP_FIXTURE::TEST_SCH_GROUP_FIXTURE
TEST_SCH_GROUP_FIXTURE()
Definition
test_sch_group.cpp:44
eeschema_test_utils.h
FILEEXT::KiCadSchematicFileExtension
static const std::string KiCadSchematicFileExtension
Definition
wildcards_and_files_ext.h:128
lib_symbol.h
KI_TEST::GetEeschemaTestDataDir
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition
unit_test_utils.cpp:35
ELECTRICAL_PINTYPE::PT_INPUT
@ PT_INPUT
usual pin input: must be connected
Definition
pin_type.h:33
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:503
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:171
EE_RTREE::EE_TYPE::begin
SearchIter begin()
Definition
sch_rtree.h:210
EE_RTREE::EE_TYPE::end
SearchIter end()
Definition
sch_rtree.h:211
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
path
std::string path
Definition
test_kibis.cpp:100
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Default)
Declare the test suite.
Definition
test_sch_group.cpp:122
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
SCH_GROUP_T
@ SCH_GROUP_T
Definition
typeinfo.h:170
unit_test_utils.h
uuid_test_utils.h
Test utilities for timestamps.
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:683
wx_assert.h
src
qa
tests
eeschema
test_sch_group.cpp
Generated on Fri Jun 26 2026 00:05:44 for KiCad PCB EDA Suite by
1.13.2