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
m_schematic
->Reset();
63
64
m_sheet
=
m_schematic
->GetTopLevelSheet( 0 );
65
m_screen
=
m_sheet
->GetScreen();
66
67
m_parent_part
=
new
LIB_SYMBOL
(
"parent_part"
,
nullptr
);
68
69
m_lib_pin
=
new
SCH_PIN
(
m_parent_part
);
70
m_parent_part
->AddDrawItem(
m_lib_pin
);
71
72
// give the pin some kind of data we can use to test
73
m_lib_pin
->SetNumber(
"42"
);
74
m_lib_pin
->SetName(
"pinname"
);
75
m_lib_pin
->SetType(
ELECTRICAL_PINTYPE::PT_INPUT
);
76
m_lib_pin
->SetPosition(
VECTOR2I
( 1, 2 ) );
77
78
SCH_SHEET_PATH
path
;
79
m_parent_symbol
=
new
SCH_SYMBOL
( *
m_parent_part
,
m_parent_part
->GetLibId(), &
path
, 0, 0,
VECTOR2I
( 1, 2 ) );
80
m_parent_symbol
->SetRef( &
path
,
"U2"
);
81
m_parent_symbol
->UpdatePins();
82
83
m_sch_pin
=
m_parent_symbol
->GetPins( &
path
)[0];
84
85
m_screen
->Append(
m_parent_symbol
);
86
}
87
88
wxFileName
SchematicQAPath
(
const
wxString& aRelativePath )
override
89
{
90
wxFileName fn(
KI_TEST::GetEeschemaTestDataDir
() );
91
92
wxString
path
= fn.GetFullPath();
93
path
+= aRelativePath + wxT(
"."
) +
FILEEXT::KiCadSchematicFileExtension
;
94
95
return
wxFileName(
path
);
96
}
97
98
SCH_SCREEN
*
m_screen
;
99
100
SCH_SHEET
*
m_sheet
;
101
102
LIB_SYMBOL
*
m_parent_part
;
103
SCH_PIN
*
m_lib_pin
;
104
105
SCH_SYMBOL
*
m_parent_symbol
;
106
SCH_PIN
*
m_sch_pin
;
// owned by m_parent_symbol, not us
107
108
void
CreateGroup
()
109
{
110
SCH_GROUP
*
group
=
new
SCH_GROUP
(
m_screen
);
111
group
->AddItem(
m_parent_symbol
);
112
113
m_screen
->Append(
group
);
114
}
115
};
116
120
BOOST_FIXTURE_TEST_SUITE( SchGroup,
TEST_SCH_GROUP_FIXTURE
)
121
122
123
126
BOOST_AUTO_TEST_CASE
( Default )
127
{
128
CreateTestSchematic();
129
130
BOOST_CHECK_EQUAL
( m_sheet->IsTopLevelSheet(),
true
);
131
BOOST_CHECK_EQUAL
( m_sheet->GetPosition(),
VECTOR2I
( 0, 0 ) );
132
BOOST_CHECK_EQUAL
( m_sheet->CountSheets(), 1 );
133
BOOST_CHECK_EQUAL
( m_sheet->SymbolCount(), 1 );
134
135
BOOST_CHECK_EQUAL
( m_sheet->GetScreenCount(), 1 );
136
}
137
141
BOOST_AUTO_TEST_CASE
( CreateGroup )
142
{
143
CreateTestSchematic();
144
145
SCH_GROUP
*
group
=
new
SCH_GROUP
( m_screen );
146
group
->AddItem( m_parent_symbol );
147
148
m_screen->Append(
group
);
149
150
EE_RTREE::EE_TYPE
groups = m_screen->Items().OfType(
SCH_GROUP_T
);
151
BOOST_CHECK_EQUAL
( std::distance( groups.
begin
(), groups.
end
() ), 1 );
152
}
153
154
BOOST_AUTO_TEST_CASE
( LoadSchGroups )
155
{
156
LoadSchematic
( SchematicQAPath(
"groups_load_save"
) );
157
158
EE_RTREE::EE_TYPE
groups = m_schematic->RootScreen()->Items().OfType(
SCH_GROUP_T
);
159
160
BOOST_CHECK_EQUAL
( std::distance( groups.
begin
(), groups.
end
() ), 1 );
161
162
SCH_GROUP
*
group
=
static_cast<
SCH_GROUP
*
>
( *groups.
begin
() );
163
BOOST_CHECK_EQUAL
(
group
->GetName(),
"GroupName"
);
164
165
BOOST_CHECK_EQUAL
(
group
->GetItems().size(), 2 );
166
}
167
168
BOOST_AUTO_TEST_SUITE_END
()
BITMAPS::group
@ group
Definition
bitmaps_list.h:249
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:63
KI_TEST::SCHEMATIC_TEST_FIXTURE::m_schematic
std::unique_ptr< SCHEMATIC > m_schematic
Definition
eeschema_test_utils.h:61
LIB_SYMBOL
Define a library symbol object.
Definition
lib_symbol.h:83
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:100
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:228
SCH_SHEET
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition
sch_sheet.h:48
SCH_SYMBOL
Schematic symbol object.
Definition
sch_symbol.h:76
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:108
TEST_SCH_GROUP_FIXTURE::m_sch_pin
SCH_PIN * m_sch_pin
Definition
test_sch_group.cpp:106
TEST_SCH_GROUP_FIXTURE::m_lib_pin
SCH_PIN * m_lib_pin
Definition
test_sch_group.cpp:103
TEST_SCH_GROUP_FIXTURE::m_screen
SCH_SCREEN * m_screen
Definition
test_sch_group.cpp:98
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:100
TEST_SCH_GROUP_FIXTURE::m_parent_part
LIB_SYMBOL * m_parent_part
Definition
test_sch_group.cpp:102
TEST_SCH_GROUP_FIXTURE::SchematicQAPath
wxFileName SchematicQAPath(const wxString &aRelativePath) override
Definition
test_sch_group.cpp:88
TEST_SCH_GROUP_FIXTURE::m_parent_symbol
SCH_SYMBOL * m_parent_symbol
Definition
test_sch_group.cpp:105
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:132
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:509
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:136
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
path
std::string path
Definition
test_kibis.cpp:96
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Default)
Declare the test suite.
Definition
test_sch_group.cpp:126
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
SCH_GROUP_T
@ SCH_GROUP_T
Definition
typeinfo.h:177
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 Fri Jan 9 2026 00:06:50 for KiCad PCB EDA Suite by
1.13.2