KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_empty_label.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 3
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
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
22
#include <
erc/erc.h
>
23
#include <
erc/erc_settings.h
>
24
#include <
sch_label.h
>
25
#include <
sch_line.h
>
26
#include <
sch_marker.h
>
27
#include <
sch_screen.h
>
28
#include <
sch_sheet.h
>
29
#include <
schematic.h
>
30
#include <
settings/settings_manager.h
>
31
32
33
BOOST_AUTO_TEST_SUITE
( ERCEmptyLabel )
34
35
36
struct
EMPTY_LABEL_ERC_FIXTURE
37
{
38
EMPTY_LABEL_ERC_FIXTURE
()
39
{
40
m_mgr
.LoadProject(
""
);
41
m_schematic
= std::make_unique<SCHEMATIC>( &
m_mgr
.Prj() );
42
m_schematic
->Reset();
43
SCH_SHEET
* defaultSheet =
m_schematic
->GetTopLevelSheet( 0 );
44
45
m_screen
=
new
SCH_SCREEN
(
m_schematic
.get() );
46
m_sheet
=
new
SCH_SHEET
(
m_schematic
.get() );
47
m_sheet
->SetScreen(
m_screen
);
48
m_schematic
->AddTopLevelSheet(
m_sheet
);
49
m_schematic
->RemoveTopLevelSheet( defaultSheet );
50
delete
defaultSheet;
51
}
52
53
void
AddWire
()
54
{
55
SCH_LINE
* wire =
new
SCH_LINE
(
VECTOR2I
( 0, 0 ),
LAYER_WIRE
);
56
wire->
SetEndPoint
(
VECTOR2I
( 5000000, 0 ) );
57
m_screen
->Append( wire );
58
}
59
60
int
RunCheck
()
61
{
62
ERC_TESTER
tester(
m_schematic
.get() );
63
return
tester.
TestEmptyLabelNames
();
64
}
65
66
int
CountMarkers
()
67
{
68
int
count = 0;
69
70
for
(
SCH_ITEM
* item :
m_screen
->Items().OfType(
SCH_MARKER_T
) )
71
{
72
SCH_MARKER
* marker =
static_cast<
SCH_MARKER
*
>
( item );
73
74
if
( marker->
GetRCItem
()->
GetErrorCode
() ==
ERCE_EMPTY_LABEL_NAME
)
75
count++;
76
}
77
78
return
count;
79
}
80
81
SETTINGS_MANAGER
m_mgr
;
82
std::unique_ptr<SCHEMATIC>
m_schematic
;
83
SCH_SCREEN
*
m_screen
;
84
SCH_SHEET
*
m_sheet
;
85
};
86
87
88
BOOST_FIXTURE_TEST_CASE
( EmptyLocalLabelFlagged,
EMPTY_LABEL_ERC_FIXTURE
)
89
{
90
AddWire();
91
92
// Named and empty label on the same wire, as in the issue repro
93
m_screen->Append(
new
SCH_LABEL
(
VECTOR2I
( 1000000, 0 ), wxT(
"PCIe_CLK_N"
) ) );
94
m_screen->Append(
new
SCH_LABEL
(
VECTOR2I
( 3000000, 0 ), wxEmptyString ) );
95
96
BOOST_CHECK_EQUAL
( RunCheck(), 1 );
97
BOOST_CHECK_EQUAL
( CountMarkers(), 1 );
98
}
99
100
101
BOOST_FIXTURE_TEST_CASE
( WhitespaceOnlyLabelsFlagged,
EMPTY_LABEL_ERC_FIXTURE
)
102
{
103
AddWire();
104
105
m_screen->Append(
new
SCH_LABEL
(
VECTOR2I
( 1000000, 0 ), wxT(
" "
) ) );
106
m_screen->Append(
new
SCH_GLOBALLABEL
(
VECTOR2I
( 3000000, 0 ), wxEmptyString ) );
107
m_screen->Append(
new
SCH_HIERLABEL
(
VECTOR2I
( 4000000, 0 ), wxEmptyString ) );
108
109
BOOST_CHECK_EQUAL
( RunCheck(), 3 );
110
BOOST_CHECK_EQUAL
( CountMarkers(), 3 );
111
}
112
113
114
BOOST_FIXTURE_TEST_CASE
( ValidAndDirectiveLabelsPass,
EMPTY_LABEL_ERC_FIXTURE
)
115
{
116
AddWire();
117
118
m_screen->Append(
new
SCH_LABEL
(
VECTOR2I
( 1000000, 0 ), wxT(
"PCIe_CLK_N"
) ) );
119
m_screen->Append(
new
SCH_GLOBALLABEL
(
VECTOR2I
( 3000000, 0 ), wxT(
"VBUS"
) ) );
120
121
m_screen->Append(
new
SCH_DIRECTIVE_LABEL
(
VECTOR2I
( 4000000, 0 ) ) );
122
123
BOOST_CHECK_EQUAL
( RunCheck(), 0 );
124
BOOST_CHECK_EQUAL
( CountMarkers(), 0 );
125
}
126
127
128
BOOST_AUTO_TEST_SUITE_END
()
ERC_TESTER
Definition
erc.h:48
ERC_TESTER::TestEmptyLabelNames
int TestEmptyLabelNames()
Check for labels with empty or whitespace-only names.
Definition
erc.cpp:672
MARKER_BASE::GetRCItem
std::shared_ptr< RC_ITEM > GetRCItem() const
Definition
marker_base.h:112
RC_ITEM::GetErrorCode
int GetErrorCode() const
Definition
rc_item.h:157
SCH_DIRECTIVE_LABEL
Definition
sch_label.h:445
SCH_GLOBALLABEL
Definition
sch_label.h:532
SCH_HIERLABEL
Definition
sch_label.h:607
SCH_ITEM
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition
sch_item.h:162
SCH_LABEL
Definition
sch_label.h:388
SCH_LINE
Segment description base class to describe items which have 2 end points (track, wire,...
Definition
sch_line.h:38
SCH_LINE::SetEndPoint
void SetEndPoint(const VECTOR2I &aPosition)
Definition
sch_line.h:145
SCH_MARKER
Definition
sch_marker.h:30
SCH_SCREEN
Definition
sch_screen.h:97
SCH_SHEET
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition
sch_sheet.h:44
SETTINGS_MANAGER
Definition
settings_manager.h:49
erc.h
erc_settings.h
ERCE_EMPTY_LABEL_NAME
@ ERCE_EMPTY_LABEL_NAME
Label has an empty or whitespace-only name.
Definition
erc_settings.h:100
LAYER_WIRE
@ LAYER_WIRE
Definition
layer_ids.h:458
sch_label.h
sch_line.h
sch_marker.h
sch_screen.h
sch_sheet.h
schematic.h
settings_manager.h
EMPTY_LABEL_ERC_FIXTURE
Definition
test_erc_empty_label.cpp:37
EMPTY_LABEL_ERC_FIXTURE::CountMarkers
int CountMarkers()
Definition
test_erc_empty_label.cpp:66
EMPTY_LABEL_ERC_FIXTURE::m_mgr
SETTINGS_MANAGER m_mgr
Definition
test_erc_empty_label.cpp:81
EMPTY_LABEL_ERC_FIXTURE::RunCheck
int RunCheck()
Definition
test_erc_empty_label.cpp:60
EMPTY_LABEL_ERC_FIXTURE::EMPTY_LABEL_ERC_FIXTURE
EMPTY_LABEL_ERC_FIXTURE()
Definition
test_erc_empty_label.cpp:38
EMPTY_LABEL_ERC_FIXTURE::AddWire
void AddWire()
Definition
test_erc_empty_label.cpp:53
EMPTY_LABEL_ERC_FIXTURE::m_screen
SCH_SCREEN * m_screen
Definition
test_erc_empty_label.cpp:83
EMPTY_LABEL_ERC_FIXTURE::m_schematic
std::unique_ptr< SCHEMATIC > m_schematic
Definition
test_erc_empty_label.cpp:82
EMPTY_LABEL_ERC_FIXTURE::m_sheet
SCH_SHEET * m_sheet
Definition
test_erc_empty_label.cpp:84
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_FIXTURE_TEST_CASE
BOOST_FIXTURE_TEST_CASE(EmptyLocalLabelFlagged, EMPTY_LABEL_ERC_FIXTURE)
Definition
test_erc_empty_label.cpp:88
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
SCH_MARKER_T
@ SCH_MARKER_T
Definition
typeinfo.h:155
unit_test_utils.h
VECTOR2I
VECTOR2< int32_t > VECTOR2I
Definition
vector2d.h:683
src
qa
tests
eeschema
erc
test_erc_empty_label.cpp
Generated on Sat Jul 25 2026 00:06:04 for KiCad PCB EDA Suite by
1.13.2