KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_empty_power_value.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 <lib_symbol.h>
25#include <sch_line.h>
26#include <sch_marker.h>
27#include <sch_pin.h>
28#include <sch_screen.h>
29#include <sch_sheet.h>
30#include <sch_symbol.h>
31#include <schematic.h>
33
34
35BOOST_AUTO_TEST_SUITE( ERCEmptyPowerValue )
36
37
39{
41 {
42 m_mgr.LoadProject( "" );
43 m_schematic = std::make_unique<SCHEMATIC>( &m_mgr.Prj() );
44 m_schematic->Reset();
45 SCH_SHEET* defaultSheet = m_schematic->GetTopLevelSheet( 0 );
46
47 m_screen = new SCH_SCREEN( m_schematic.get() );
48 m_sheet = new SCH_SHEET( m_schematic.get() );
49 m_sheet->SetScreen( m_screen );
50 m_schematic->AddTopLevelSheet( m_sheet );
51 m_schematic->RemoveTopLevelSheet( defaultSheet );
52 delete defaultSheet;
53 }
54
56 LIB_SYMBOL* MakePowerLibSymbol( const wxString& aName, bool aLocal )
57 {
58 LIB_SYMBOL* part = new LIB_SYMBOL( aName );
59
60 if( aLocal )
61 part->SetLocalPower();
62 else
63 part->SetGlobalPower();
64
65 SCH_PIN* pin = new SCH_PIN( part );
66 pin->SetNumber( wxT( "1" ) );
67 pin->SetName( aName );
69 pin->SetVisible( false );
70 part->AddDrawItem( pin );
71
72 part->GetValueField().SetText( aName );
73 m_libSymbols.emplace_back( part );
74
75 return part;
76 }
77
80 LIB_SYMBOL* MakeSymbolWithHiddenPowerPin( const wxString& aName, const wxString& aPinName )
81 {
82 LIB_SYMBOL* part = new LIB_SYMBOL( aName );
83
84 SCH_PIN* pin = new SCH_PIN( part );
85 pin->SetNumber( wxT( "1" ) );
86 pin->SetName( aPinName );
88 pin->SetVisible( false );
89 part->AddDrawItem( pin );
90
91 m_libSymbols.emplace_back( part );
92
93 return part;
94 }
95
96 SCH_SYMBOL* Place( LIB_SYMBOL* aPart, const VECTOR2I& aPos, const wxString& aValue )
97 {
98 SCH_SYMBOL* symbol = new SCH_SYMBOL( *aPart, aPart->GetLibId(), &m_schematic->CurrentSheet(), 1, 1, aPos );
99 symbol->GetField( FIELD_T::VALUE )->SetText( aValue );
100 m_screen->Append( symbol );
101
102 return symbol;
103 }
104
106 {
107 m_schematic->RebuildConnectivity();
108
109 ERC_TESTER tester( m_schematic.get() );
110 return tester.TestEmptyPowerValues();
111 }
112
114 {
115 int count = 0;
116
117 for( SCH_ITEM* item : m_screen->Items().OfType( SCH_MARKER_T ) )
118 {
119 SCH_MARKER* marker = static_cast<SCH_MARKER*>( item );
120
121 if( marker->GetRCItem()->GetErrorCode() == ERCE_EMPTY_POWER_VALUE )
122 count++;
123 }
124
125 return count;
126 }
127
129 std::unique_ptr<SCHEMATIC> m_schematic;
132 std::vector<std::unique_ptr<LIB_SYMBOL>> m_libSymbols;
133};
134
135
137{
138 LIB_SYMBOL* rail = MakePowerLibSymbol( wxT( "+3V3" ), false );
139
140 Place( rail, VECTOR2I( 1000000, 0 ), wxEmptyString );
141
142 BOOST_CHECK_EQUAL( RunCheck(), 1 );
143 BOOST_CHECK_EQUAL( CountMarkers(), 1 );
144}
145
146
148{
149 LIB_SYMBOL* rail = MakePowerLibSymbol( wxT( "+3V3" ), true );
150
151 Place( rail, VECTOR2I( 1000000, 0 ), wxEmptyString );
152
153 BOOST_CHECK_EQUAL( RunCheck(), 1 );
154 BOOST_CHECK_EQUAL( CountMarkers(), 1 );
155}
156
157
159{
160 LIB_SYMBOL* rail = MakePowerLibSymbol( wxT( "+3V3" ), false );
161
162 Place( rail, VECTOR2I( 1000000, 0 ), wxT( " " ) );
163
164 BOOST_CHECK_EQUAL( RunCheck(), 1 );
165 BOOST_CHECK_EQUAL( CountMarkers(), 1 );
166}
167
168
170{
171 LIB_SYMBOL* rail = MakePowerLibSymbol( wxT( "+3V3" ), false );
172 LIB_SYMBOL* ground = MakePowerLibSymbol( wxT( "GND" ), false );
173
174 Place( rail, VECTOR2I( 1000000, 0 ), wxT( "+3V3" ) );
175 Place( ground, VECTOR2I( 3000000, 0 ), wxT( "GND" ) );
176
177 BOOST_CHECK_EQUAL( RunCheck(), 0 );
178 BOOST_CHECK_EQUAL( CountMarkers(), 0 );
179}
180
181
182BOOST_FIXTURE_TEST_CASE( HiddenPowerPinOnOrdinarySymbolPasses, EMPTY_POWER_VALUE_ERC_FIXTURE )
183{
184 LIB_SYMBOL* part = MakeSymbolWithHiddenPowerPin( wxT( "74LS00" ), wxT( "VCC" ) );
185
186 Place( part, VECTOR2I( 1000000, 0 ), wxEmptyString );
187
188 BOOST_CHECK_EQUAL( RunCheck(), 0 );
189 BOOST_CHECK_EQUAL( CountMarkers(), 0 );
190}
191
192
Runs the electrical rules checks and adds a SCH_MARKER for each violation.
Definition erc.h:60
int TestEmptyPowerValues()
Check for power symbols whose value resolves to nothing, leaving their net unnamed.
Definition erc.cpp:762
Define a library symbol object.
Definition lib_symbol.h:114
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:190
void SetGlobalPower()
SCH_FIELD & GetValueField()
Definition lib_symbol.h:447
void SetLocalPower()
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
std::shared_ptr< RC_ITEM > GetRCItem() const
int GetErrorCode() const
Definition rc_item.h:213
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:170
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
Schematic symbol object.
Definition sch_symbol.h:75
SCH_FIELD * GetField(FIELD_T aFieldType)
Return a mandatory field in this symbol.
@ ERCE_EMPTY_POWER_VALUE
Power symbol has no value, so it names no net.
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
std::vector< std::unique_ptr< LIB_SYMBOL > > m_libSymbols
LIB_SYMBOL * MakeSymbolWithHiddenPowerPin(const wxString &aName, const wxString &aPinName)
An ordinary symbol carrying a hidden power input, the legacy shape that names its net from the pin an...
std::unique_ptr< SCHEMATIC > m_schematic
SCH_SYMBOL * Place(LIB_SYMBOL *aPart, const VECTOR2I &aPos, const wxString &aValue)
LIB_SYMBOL * MakePowerLibSymbol(const wxString &aName, bool aLocal)
Build a single pin power symbol, the shape every rail symbol in the stock library has.
@ VALUE
Field Value of part, i.e. "3.3K".
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_FIXTURE_TEST_CASE(EmptyGlobalPowerValueFlagged, EMPTY_POWER_VALUE_ERC_FIXTURE)
BOOST_AUTO_TEST_SUITE_END()
KIBIS_PIN * pin
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_MARKER_T
Definition typeinfo.h:154
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708