KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_creepage_engine_parity.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
30
33
34#include <board.h>
36#include <advanced_config.h>
37#include <drc/drc_item.h>
38#include <drc/drc_engine.h>
41
42#include <set>
43
44
46{
48
50 {
51 if( m_board && m_board->GetDesignSettings().m_DRCEngine )
52 m_board->GetDesignSettings().m_DRCEngine->ClearViolationHandler();
53
54 if( m_board )
55 {
56 m_board->SetProject( nullptr );
57 m_board = nullptr;
58 }
59 }
60
64 std::multiset<wxString> runCreepage()
65 {
66 std::multiset<wxString> result;
67 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
68
69 for( int ii = DRCE_FIRST; ii <= DRCE_LAST; ++ii )
71
73
75 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
76 const std::function<void( PCB_MARKER* )>& )
77 {
78 if( bds.GetSeverity( aItem->GetErrorCode() ) == SEVERITY::RPT_SEVERITY_ERROR )
79 result.emplace( aItem->GetErrorMessage( false ) );
80 } );
81
82 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
84
85 return result;
86 }
87
89 std::unique_ptr<BOARD> m_board;
90};
91
92
94{
95 explicit ADVANCED_CFG_FLAG_GUARD( bool aValue )
96 {
97 bool& flag = const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_RealtimeCreepage;
98 m_saved = flag;
99 flag = aValue;
100 }
101
103 {
104 const_cast<ADVANCED_CFG&>( ADVANCED_CFG::GetCfg() ).m_RealtimeCreepage = m_saved;
105 }
106
108};
109
110
111static void checkParity( CREEPAGE_PARITY_FIXTURE& aFixture, const std::string& aBoard )
112{
113 KI_TEST::LoadBoard( aFixture.m_settingsManager, aBoard, aFixture.m_board );
114 BOOST_REQUIRE_MESSAGE( aFixture.m_board, "Failed to load board " << aBoard );
115 BOOST_REQUIRE_MESSAGE( aFixture.m_board->GetDesignSettings().m_DRCEngine,
116 "DRC engine not initialized" );
117
118 std::multiset<wxString> v1;
119 std::multiset<wxString> v2;
120
121 {
122 ADVANCED_CFG_FLAG_GUARD guard( false );
123 v1 = aFixture.runCreepage();
124 }
125
126 {
127 ADVANCED_CFG_FLAG_GUARD guard( true );
128 v2 = aFixture.runCreepage();
129 }
130
131 BOOST_TEST_MESSAGE( wxString::Format( "%s: V1=%d V2=%d violations", aBoard.c_str(),
132 (int) v1.size(), (int) v2.size() ) );
133
134 BOOST_CHECK_EQUAL( v1.size(), v2.size() );
135 BOOST_CHECK_MESSAGE( v1 == v2, "V2 engine violation set differs from V1 for " << aBoard );
136}
137
138
139BOOST_FIXTURE_TEST_SUITE( CreepageEngineParity, CREEPAGE_PARITY_FIXTURE )
140
141
142BOOST_AUTO_TEST_CASE( CreepageBoard )
143{
144 checkParity( *this, "creepage/creepage" );
145}
146
147
148BOOST_AUTO_TEST_CASE( CreepageMalformedEdge )
149{
150 checkParity( *this, "creepage/creepage_malformed_edge" );
151}
152
153
154BOOST_AUTO_TEST_CASE( CreepageSlots )
155{
156 checkParity( *this, "creepage_slots/creepage_slots" );
157}
158
159
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
Container for design settings for a BOARD object.
std::map< int, SEVERITY > m_DRCSeverities
std::shared_ptr< DRC_ENGINE > m_DRCEngine
SEVERITY GetSeverity(int aDRCErrorCode)
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1149
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:164
void ClearViolationHandler()
Definition drc_engine.h:169
@ DRCE_CREEPAGE
Definition drc_item.h:41
@ DRCE_FIRST
Definition drc_item.h:35
@ DRCE_LAST
Definition drc_item.h:121
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_IGNORE
CREEPAGE_PARITY_FIXTURE()=default
std::multiset< wxString > runCreepage()
Run the creepage DRC and return the multiset of violation messages.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(CreepageBoard)
static void checkParity(CREEPAGE_PARITY_FIXTURE &aFixture, const std::string &aBoard)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I v1(5, 5, 5)
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_MESSAGE("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2I v2(1, 0)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683