KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_hole_clearance_issue24355.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
63
66
67#include <board.h>
69#include <footprint.h>
70#include <pad.h>
71#include <drc/drc_item.h>
72#include <drc/drc_engine.h>
75
76
78{
80
82 {
83 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
84 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
85
86 if( m_board )
87 {
88 m_board->SetProject( nullptr );
89 m_board = nullptr;
90 }
91 }
92
94 std::unique_ptr<BOARD> m_board;
95};
96
97
99{
100 KI_TEST::LoadBoard( m_settingsManager, "issue24355/issue24355", m_board );
101
102 BOOST_REQUIRE_MESSAGE( m_board, "Failed to load board issue24355" );
103 BOOST_REQUIRE_EQUAL( m_board->Footprints().size(), 1 );
104
105 FOOTPRINT* fp = m_board->Footprints().front();
106 BOOST_REQUIRE_EQUAL( fp->Pads().size(), 2 );
107
108 // The bug is direction-sensitive; the fixture deliberately lists the
109 // NPTH pad first so the parser allocates it at the lower heap address.
110 // If a future allocator change flips this, the test may pass on buggy
111 // code by accident -- flag it so the failure mode is obvious.
112 PAD* first = fp->Pads()[0];
113 PAD* second = fp->Pads()[1];
114 BOOST_REQUIRE_MESSAGE( first->GetAttribute() == PAD_ATTRIB::NPTH,
115 "Fixture pad order changed: expected NPTH first." );
116 BOOST_REQUIRE_MESSAGE( second->GetAttribute() == PAD_ATTRIB::PTH,
117 "Fixture pad order changed: expected PTH second." );
118 BOOST_WARN_MESSAGE( static_cast<void*>( first ) < static_cast<void*>( second ),
119 "Heap put PTH below NPTH; the bug may not trigger in this run." );
120
121 int holeClearanceCount = 0;
122 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
123
124 BOOST_REQUIRE_MESSAGE( bds.m_DRCEngine, "DRC engine not initialized" );
125
126 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
128
130
132 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I& /*aPos*/, int /*aLayer*/,
133 const std::function<void( PCB_MARKER* )>& /*aPathGen*/ )
134 {
135 if( aItem->GetErrorCode() == DRCE_HOLE_CLEARANCE )
136 ++holeClearanceCount;
137 } );
138
139 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
140
142
143 BOOST_TEST_MESSAGE( wxString::Format( "Hole clearance violations: %d", holeClearanceCount ) );
144
145 // One violation per shared copper layer (F.Cu, B.Cu) for a 2-layer board.
146 BOOST_CHECK_EQUAL( holeClearanceCount, 2 );
147}
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
void RunTests(EDA_UNITS aUnits, bool aReportAllTrackErrors, bool aTestFootprints, BOARD_COMMIT *aCommit=nullptr)
Run the DRC tests.
void SetViolationHandler(DRC_VIOLATION_HANDLER aHandler)
Set an optional DRC violation handler (receives DRC_ITEMs and positions).
Definition drc_engine.h:168
void ClearViolationHandler()
Definition drc_engine.h:173
std::deque< PAD * > & Pads()
Definition footprint.h:377
Definition pad.h:65
PAD_ATTRIB GetAttribute() const
Definition pad.h:583
@ DRCE_HOLE_CLEARANCE
Definition drc_item.h:55
@ DRCE_FIRST
Definition drc_item.h:39
@ DRCE_LAST
Definition drc_item.h:124
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
DRC_HOLE_CLEARANCE_FIXTURE()=default
BOOST_FIXTURE_TEST_CASE(HoleClearanceIssue24355, DRC_HOLE_CLEARANCE_FIXTURE)
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:687