KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_check.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
20#include "math/vector2d.h"
22#include <boost/test/data/test_case.hpp>
23
24#include <algorithm>
25#include <vector>
26
27#include <base_units.h>
28#include <board.h>
29#include <footprint.h>
30#include <pad.h>
31#include <pad_utils.h>
32#include <padstack.h>
33#include <units_provider.h>
34
35BOOST_AUTO_TEST_SUITE( PadCheck )
36
37namespace
38{
40
44struct PAD_CHECK_TEST_CASE : public KI_TEST::NAMED_CASE
45{
46 PAD_ATTRIB m_Attribute;
47 LSET m_Layers;
48 std::vector<PAD_CHECK_CODE> m_ExpectedCodes;
49};
50
51
52const std::vector<PAD_CHECK_TEST_CASE> padCheckCases = {
53 {
54 "inner-only SMD pad",
56 LSET( { In1_Cu, In2_Cu } ),
57 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
58 },
59 {
60 "inner-only CONN pad",
62 LSET( { In1_Cu } ),
63 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
64 },
65 // The current checker reports the missing outer copper, not the mask issue itself.
66 {
67 "inner-only SMD pad with front mask",
69 LSET( { In1_Cu, F_Mask } ),
70 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
71 },
72 // The current checker reports the missing outer copper, not the paste issue itself.
73 {
74 "inner-only SMD pad with back paste",
76 LSET( { In2_Cu, B_Paste } ),
77 { PAD_CHECK_CODE::PAD_NO_OUTER_COPPER },
78 },
79 {
80 "aperture pad with paste",
82 LSET( { F_Paste } ),
83 {}, // Not expected to trigger any pad check errors
84 },
85 {
86 "outer and inner SMD pad",
88 LSET( { F_Cu, In1_Cu, F_Mask, F_Paste } ),
89 {},
90 },
91 {
92 "both outer copper sides",
94 LSET( { F_Cu, B_Cu } ),
95 { PAD_CHECK_CODE::SMD_BOTH_OUTER_SIDES },
96 },
97 {
98 "wrong-side mask",
100 LSET( { B_Cu, F_Mask } ),
101 { PAD_CHECK_CODE::SMD_MASK_WRONG_SIDE },
102 },
103};
104
105
106void checkPadResults( const std::vector<PAD_UTILS::PAD_CHECK_RESULT>& aResults,
107 const std::vector<PAD_CHECK_CODE>& aExpectedCodes )
108{
109 std::vector<int> actualCodes;
110 actualCodes.reserve( aResults.size() );
111
112 for( const PAD_UTILS::PAD_CHECK_RESULT& message : aResults )
113 actualCodes.push_back( static_cast<int>( message.code ) );
114
115 std::vector<int> expectedCodes;
116 expectedCodes.reserve( aExpectedCodes.size() );
117
118 for( PAD_CHECK_CODE code : aExpectedCodes )
119 expectedCodes.push_back( static_cast<int>( code ) );
120
121 std::sort( actualCodes.begin(), actualCodes.end() );
122 std::sort( expectedCodes.begin(), expectedCodes.end() );
123
124 BOOST_CHECK_EQUAL_COLLECTIONS( actualCodes.begin(), actualCodes.end(), expectedCodes.begin(), expectedCodes.end() );
125}
126
127} // namespace
128
129
135{
139
143 {
144 m_Board.SetBoardUse( BOARD_USE::FPHOLDER );
145
146 m_Pad.SetAttribute( PAD_ATTRIB::SMD );
147 m_Pad.SetPadstackMode( PADSTACK::MODE::NORMAL );
149
150 const VECTOR2I padSize{ pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 1.0 ) };
151 m_Pad.SetSize( PADSTACK::ALL_LAYERS, padSize );
152 }
153
154 void setLayers( PAD_ATTRIB aAttrib, const LSET& aLayers )
155 {
156 m_Pad.SetAttribute( aAttrib );
157 m_Pad.SetLayerSet( aLayers );
158 }
159
165 std::vector<PAD_UTILS::PAD_CHECK_RESULT> runPadCheckOnPad()
166 {
168 std::vector<PAD_UTILS::PAD_CHECK_RESULT> messages;
169
170 const auto errorHandler =
171 [&]( const PAD_UTILS::PAD_CHECK_RESULT& aResult )
172 {
173 messages.push_back( aResult );
174 };
175
176 PAD_UTILS::CheckPad( m_Pad, units, false, errorHandler );
177
178 return messages;
179 }
180};
181
182
186BOOST_DATA_TEST_CASE_F( PAD_CHECK_FIXTURE, PadCheckCases, boost::unit_test::data::make( padCheckCases ), testCase )
187{
188 BOOST_TEST_CONTEXT( testCase.m_CaseName )
189 {
190 setLayers( testCase.m_Attribute, testCase.m_Layers );
191
192 const auto messages = runPadCheckOnPad();
193
194 checkPadResults( messages, testCase.m_ExpectedCodes );
195 }
196}
197
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
@ FPHOLDER
Definition board.h:403
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:170
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
Definition pad.h:61
std::string message
@ F_Paste
Definition layer_ids.h:100
@ B_Cu
Definition layer_ids.h:61
@ F_Mask
Definition layer_ids.h:93
@ B_Paste
Definition layer_ids.h:101
@ In2_Cu
Definition layer_ids.h:63
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
void CheckPad(const PAD &aPad, const UNITS_PROVIDER &aUnitsProvider, bool aForPadProperties, const PAD_CHECK_HANDLER &aErrorHandler)
Run non-board-specific checks on a pad.
PAD_CHECK_CODE
A specific pad check finding reason.
Definition pad_utils.h:70
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition padstack.h:96
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:98
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
Definition padstack.h:99
@ RECTANGLE
Definition padstack.h:53
A named data-driven test case.
Fixture for pad check tests: This sets up a board, footprint, and pad, and provides utility functions...
std::vector< PAD_UTILS::PAD_CHECK_RESULT > runPadCheckOnPad()
Runs the pad check on the current pad and returns the results.
void setLayers(PAD_ATTRIB aAttrib, const LSET &aLayers)
A single finding from CheckPad().
Definition pad_utils.h:107
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_DATA_TEST_CASE_F(CONNECTIVITY_DUMP_FIXTURE, LegacyAndEngineDumpsMatch, boost::unit_test::data::make(PARITY_FIXTURES), fixture)
BOOST_CHECK_EQUAL_COLLECTIONS(mixed.begin(), mixed.end(), expMixed.begin(), expMixed.end())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708