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