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
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>
31
32
33BOOST_AUTO_TEST_SUITE( ERCEmptyLabel )
34
35
37{
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
61 {
62 ERC_TESTER tester( m_schematic.get() );
63 return tester.TestEmptyLabelNames();
64 }
65
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
82 std::unique_ptr<SCHEMATIC> m_schematic;
85};
86
87
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
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
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
int TestEmptyLabelNames()
Check for labels with empty or whitespace-only names.
Definition erc.cpp:672
std::shared_ptr< RC_ITEM > GetRCItem() const
int GetErrorCode() const
Definition rc_item.h:157
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:145
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
@ ERCE_EMPTY_LABEL_NAME
Label has an empty or whitespace-only name.
@ LAYER_WIRE
Definition layer_ids.h:458
std::unique_ptr< SCHEMATIC > m_schematic
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_FIXTURE_TEST_CASE(EmptyLocalLabelFlagged, EMPTY_LABEL_ERC_FIXTURE)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_MARKER_T
Definition typeinfo.h:155
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683