KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_fab_pin.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 <boost/test/unit_test.hpp>
23#include <json_common.h>
24
25#include <array>
26#include <memory>
27#include <set>
28#include <string>
29
30#include <board.h>
31#include <footprint.h>
32#include <pad.h>
34
35
37{
38 const std::array<const char*, 3> boardNames = { "connect/connect.kicad_pcb",
39 "issue19325/issue19325.kicad_pcb",
40 "issue14130.kicad_pcb" };
41 size_t fiducials = 0;
42 size_t castellated = 0;
43 size_t tooling = 0;
44 size_t issue14130NpthTht = 0;
45 size_t issue14130NpthHole = 0;
46 size_t plated = 0;
47 size_t padCount = 0;
48 std::set<wxString> issue14130NpthNames;
49
50 for( const char* boardName : boardNames )
51 {
53 + boardName );
54 BOOST_REQUIRE_MESSAGE( board, boardName );
55
56 for( const FOOTPRINT* footprint : board->Footprints() )
57 {
58 for( size_t index = 0; index < footprint->Pads().size(); ++index )
59 {
60 const PAD* pad = footprint->Pads()[index];
61 FAB_PIN fabPin = MakeFabPin( *pad, index );
62 std::string location = std::string( boardName ) + "/" + footprint->GetReference().ToStdString() + "/"
63 + std::to_string( index );
64 ++padCount;
65
66 if( pad->GetProperty() == PAD_PROP::FIDUCIAL_GLBL )
67 {
68 ++fiducials;
70 }
71
72 if( pad->GetProperty() == PAD_PROP::CASTELLATED )
73 {
74 ++castellated;
75 BOOST_CHECK( GetFabPadRole( *pad ) == FAB_PAD_ROLE::CASTELLATED );
76 }
77
78 if( pad->GetAttribute() == PAD_ATTRIB::NPTH && pad->GetNumber().IsEmpty()
79 && pad->GetProperty() == PAD_PROP::NONE )
80 {
81 ++tooling;
82 BOOST_CHECK( GetFabPadRole( *pad ) == FAB_PAD_ROLE::TOOLING_HOLE );
83 BOOST_CHECK( pad->HasHole() );
84 BOOST_CHECK( fabPin.m_mount == FAB_MOUNT::THT || fabPin.m_mount == FAB_MOUNT::HOLE );
85 BOOST_CHECK( fabPin.m_electrical == FAB_ELECTRICAL::MECHANICAL );
86 }
87
88 if( std::string( boardName ) == "issue14130.kicad_pcb"
89 && footprint->GetReference() == wxS( "P2" ) && pad->GetAttribute() == PAD_ATTRIB::NPTH )
90 {
91 BOOST_CHECK_MESSAGE( issue14130NpthNames.insert( fabPin.m_name ).second,
92 location << " repeats an NPTH pin name" );
93
94 if( fabPin.m_mount == FAB_MOUNT::THT )
95 {
96 ++issue14130NpthTht;
97 }
98 else if( fabPin.m_mount == FAB_MOUNT::HOLE )
99 {
100 ++issue14130NpthHole;
101 }
102 }
103
104 if( std::string( boardName ) == "connect/connect.kicad_pcb"
105 && pad->GetAttribute() != PAD_ATTRIB::NPTH && !pad->GetNumber().IsEmpty()
106 && pad->IsOnCopperLayer() )
107 {
108 ++plated;
109 BOOST_CHECK( fabPin.m_electrical == FAB_ELECTRICAL::ELECTRICAL );
110 }
111 }
112 }
113 }
114
115 BOOST_CHECK_GT( fiducials, 0 );
116 BOOST_CHECK_GT( castellated, 0 );
117 BOOST_CHECK_GT( tooling, 0 );
118 BOOST_CHECK_GT( plated, 0 );
119 BOOST_CHECK_EQUAL( issue14130NpthNames.size(), 7 );
120 BOOST_CHECK_EQUAL( issue14130NpthTht, 1 );
121 BOOST_CHECK_EQUAL( issue14130NpthHole, 6 );
122 BOOST_CHECK_GT( padCount, 0 );
123}
int index
General utilities for PCB file IO for QA programs.
Definition pad.h:61
FAB_PAD_ROLE GetFabPadRole(const PAD &aPad)
Explicit fabrication properties take precedence over the unnumbered NPTH fallback.
Definition fab_pin.cpp:26
FAB_PIN MakeFabPin(const PAD &aPad, size_t aIndexInFootprint)
aIndexInFootprint is the pad's position in its footprint, used to name NPTH and unnumbered pads
Definition fab_pin.cpp:50
@ FIDUCIAL_GLOBAL
Definition fab_pin.h:31
std::string GetPcbnewTestDataDir()
Utility which returns a path to the data directory where the test board files are stored.
std::unique_ptr< BOARD > ReadBoardFromFileOrStream(const std::string &aFilename, std::istream &aFallback)
Read a board from a file, or another stream, as appropriate.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:102
@ FIDUCIAL_GLBL
a fiducial (usually a smd) for the full board
Definition padstack.h:116
@ NONE
no special fabrication property
Definition padstack.h:114
@ CASTELLATED
a pad with a castellated through hole
Definition padstack.h:120
wxString m_name
Definition fab_pin.h:58
FAB_ELECTRICAL m_electrical
Definition fab_pin.h:61
FAB_MOUNT m_mount
Definition fab_pin.h:60
BOOST_AUTO_TEST_CASE(FabPinRoles)
VECTOR2I location
BOOST_CHECK_EQUAL(result, "25.4")