KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pad_roundtrip.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 modify it
7 * under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * 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 <http://www.gnu.org/licenses/>.
18 */
19
20#include <filesystem>
21#include <qa_utils/file_utils.h>
23#include <boost/test/unit_test.hpp>
24
25#include <memory>
26
27#include <base_units.h>
28#include <footprint.h>
29#include <pad.h>
31
32
37{
39 m_Footprint( nullptr ),
40 m_Pad( new PAD( &m_Footprint ) )
41 {
42 m_Footprint.SetReference( "U1" );
43
44 // Set some default pad properties.
45 // Override them if necessary for specific test cases.
46 m_Pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
47 m_Pad->SetNumber( "1" );
48 m_Pad->SetAttribute( PAD_ATTRIB::SMD );
49 m_Pad->SetLayerSet( LSET( { F_Cu } ) );
51
52 const VECTOR2I padSize( pcbIUScale.mmToIU( 1.0 ), pcbIUScale.mmToIU( 2.0 ) );
53 m_Pad->SetSize( PADSTACK::ALL_LAYERS, padSize );
54
55 m_Footprint.Add( m_Pad );
56 }
57
63 std::unique_ptr<FOOTPRINT> RoundTrip() const
64 {
65 KI_TEST::SCOPED_TEMP_DIR tempDir( "kicad_qa_pad_roundtrip" );
66 std::filesystem::path savePath = tempDir.CreateChildDir( "pad.pretty" ) / "pad.kicad_mod";
67
69
70 return KI_TEST::ReadFootprintFromFile( savePath, savePath.stem().string() );
71 }
72
75};
76
77
78BOOST_AUTO_TEST_SUITE( PadRoundTrip )
79
80
81
85{
86 m_Pad->SetAttribute( PAD_ATTRIB::NON_COMPONENT );
87 m_Pad->SetLayerSet( LSET( { In1_Cu } ) );
88
89 // Inner-layer pads need a custom stackup to be properly represented.
90 m_Footprint.SetStackupMode( FOOTPRINT_STACKUP::CUSTOM_LAYERS );
91 m_Footprint.SetStackupLayers( LSET::AllCuMask( 4 ) );
92
93 std::unique_ptr<FOOTPRINT> loaded = RoundTrip();
94
95 BOOST_REQUIRE( loaded );
96 BOOST_REQUIRE_EQUAL( loaded->Pads().size(), 1 );
97
98 const PAD* loadedPad = loaded->Pads().front();
99
101 BOOST_CHECK( loadedPad->GetLayerSet() == LSET( { In1_Cu } ) );
102 BOOST_CHECK_EQUAL( loadedPad->GetDrillSize().x, 0 );
103 BOOST_CHECK_EQUAL( loadedPad->GetDrillSize().y, 0 );
104}
105
106
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
General utilities for PCB file IO for QA programs.
std::filesystem::path CreateChildDir(const wxString &aName) const
Create and return the path to a direct child directory.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
Definition pad.h:61
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:579
PAD_ATTRIB GetAttribute() const
Definition pad.h:582
VECTOR2I GetDrillSize() const
Definition pad.h:320
@ CUSTOM_LAYERS
Stackup handling where the footprint can have any number of copper layers, and objects on those layer...
Definition footprint.h:116
@ In1_Cu
Definition layer_ids.h:62
@ F_Cu
Definition layer_ids.h:60
void DumpFootprintToFile(const FOOTPRINT &aFootprint, const std::filesystem::path &aLibraryPath)
Same as DumpBoardToFile, but for footprints.
std::unique_ptr< FOOTPRINT > ReadFootprintFromFile(const std::filesystem::path &aFilename, const wxString &aFootprintName)
Read a footprint object aFootprintName from aFileName.
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
Definition padstack.h:106
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ RECTANGLE
Definition padstack.h:55
Sets up a footprint and a single pad, and provides a save/reload round trip.
std::unique_ptr< FOOTPRINT > RoundTrip() const
Save the fixture footprint to a temporary library and load it back.
BOOST_FIXTURE_TEST_CASE(ServerStartsAndResponds, API_SERVER_E2E_FIXTURE)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708