KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_drc_issue24525.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, see <https://www.gnu.org/licenses/>.
18 */
19
22#include <board.h>
24#include <board_item.h>
25#include <drc/drc_engine.h>
26#include <drc/drc_item.h>
27#include <pcb_marker.h>
30
31
32/*
33 * Regression test for https://gitlab.com/kicad/code/kicad/-/work_items/24525
34 *
35 * DRC reported "Text or graphic on Edge.Cuts layer" (DRCE_TEXT_ON_EDGECUTS) for text and
36 * dimensions on Edge.Cuts, but silently ignored tables and barcodes even though those also
37 * plot geometry onto the board outline. Reference images are deliberately exempt because
38 * they are never plotted to any output.
39 *
40 * The fixture places one text, one dimension, two tables (one rotated), one barcode and one
41 * reference image on Edge.Cuts. Expected result: 5 violations (text, dimension, 2 tables,
42 * barcode) and none from the reference image. On the unfixed code only 2 fire (text and
43 * dimension), so this test fails without the fix.
44 */
45
46
54
55
56BOOST_FIXTURE_TEST_CASE( DRCIssue24525_TableAndBarcodeOnEdgeCuts, DRC_ISSUE24525_FIXTURE )
57{
58 KI_TEST::LoadBoard( m_settingsManager, "issue24525/issue24525", m_board );
59
60 BOARD_DESIGN_SETTINGS& bds = m_board->GetDesignSettings();
61
62 // Make sure the rule under test is active regardless of what the fixture stored.
64
65 std::vector<DRC_ITEM> violations;
66
68 [&]( const std::shared_ptr<DRC_ITEM>& aItem, const VECTOR2I&, int,
69 const std::function<void( PCB_MARKER* )>& )
70 {
71 if( aItem->GetErrorCode() == DRCE_TEXT_ON_EDGECUTS )
72 violations.push_back( *aItem );
73 } );
74
75 bds.m_DRCEngine->RunTests( EDA_UNITS::MM, true, false );
76
77 std::map<KIID, EDA_ITEM*> itemMap;
78 m_board->FillItemMap( itemMap );
79
80 // Tally the violations by the type of the offending item so the test pins down exactly
81 // which item types are caught, not just the total.
82 std::map<KICAD_T, int> byType;
83
84 for( const DRC_ITEM& item : violations )
85 {
86 auto it = itemMap.find( item.GetMainItemID() );
87
88 BOOST_REQUIRE( it != itemMap.end() );
89
90 KICAD_T type = it->second->Type();
91
92 if( BaseType( type ) == PCB_DIMENSION_T )
93 type = PCB_DIMENSION_T;
94
95 byType[type]++;
96 }
97
98 BOOST_CHECK_EQUAL( byType[PCB_TEXT_T], 1 );
100 BOOST_CHECK_EQUAL( byType[PCB_TABLE_T], 2 );
101 BOOST_CHECK_EQUAL( byType[PCB_BARCODE_T], 1 );
102
103 // The reference image on Edge.Cuts must not be flagged. It is never plotted, so it
104 // cannot corrupt the outline.
106
107 BOOST_CHECK_EQUAL( violations.size(), 5 );
108}
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:164
@ DRCE_TEXT_ON_EDGECUTS
Definition drc_item.h:39
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
@ RPT_SEVERITY_ERROR
SETTINGS_MANAGER m_settingsManager
std::unique_ptr< BOARD > m_board
BOOST_FIXTURE_TEST_CASE(DRCIssue24525_TableAndBarcodeOnEdgeCuts, DRC_ISSUE24525_FIXTURE)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_CHECK_EQUAL(result, "25.4")
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition typeinfo.h:256
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:85
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:82
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:94
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:93
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:87
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683