KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_applier_helpers.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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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
28
29#include <board.h>
30#include <board_item.h>
31#include <footprint.h>
32#include <pad.h>
34
35
36using namespace KICAD_DIFF;
37
38
40{
42 {
43 KI_TEST::LoadBoard( m_settings, "complex_hierarchy", m_board );
45 }
46
48 std::unique_ptr<BOARD> m_board;
49};
50
51
52BOOST_FIXTURE_TEST_SUITE( ApplierHelpers, APPLIER_HELPERS_FIXTURE )
53
54
55// Null board -> no inserts, no crash.
56BOOST_AUTO_TEST_CASE( CollectTopLevelIdsNullBoardIsNoop )
57{
58 std::set<KIID> out;
59 CollectTopLevelIds( nullptr, out );
60 BOOST_CHECK( out.empty() );
61}
62
63
64// Every top-level item's UUID must end up in the output set, while footprint
65// children (pads etc.) must NOT -- that "top-level only" boundary is the
66// helper's whole reason to exist. The const pointer also pins that the helper
67// is callable on a const BOARD without a const_cast in the caller.
68BOOST_AUTO_TEST_CASE( CollectTopLevelIdsIncludesItemsButNotChildren )
69{
70 const BOARD* constBoard = m_board.get();
71 std::set<KIID> out;
72 CollectTopLevelIds( constBoard, out );
73
74 BOOST_REQUIRE( !out.empty() );
75
76 for( const BOARD_ITEM* item : m_board->GetItemSet() )
77 {
78 if( item )
79 BOOST_CHECK( out.count( item->m_Uuid ) == 1 );
80 }
81
82 // A footprint's pads are children, not top-level items, so their UUIDs
83 // must be absent from the collected set.
84 bool checkedAChild = false;
85
86 for( const FOOTPRINT* fp : m_board->Footprints() )
87 {
88 for( const PAD* pad : fp->Pads() )
89 {
90 BOOST_CHECK( out.count( pad->m_Uuid ) == 0 );
91 checkedAChild = true;
92 }
93 }
94
95 BOOST_REQUIRE( checkedAChild ); // fixture must actually contain a footprint pad
96}
97
98
99// Output is additive: calling twice doesn't drop entries from the first call.
100BOOST_AUTO_TEST_CASE( CollectTopLevelIdsIsAdditive )
101{
102 std::set<KIID> out;
103 out.insert( KIID() );
104
105 const size_t initial = out.size();
106 CollectTopLevelIds( m_board.get(), out );
107
108 BOOST_CHECK_GT( out.size(), initial );
109}
110
111
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:80
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:320
Definition kiid.h:44
Definition pad.h:61
void CollectTopLevelIds(const BOARD *aBoard, std::set< KIID > &aOut)
Insert every top-level item UUID from aBoard into aOut.
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
std::unique_ptr< BOARD > m_board
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(CollectTopLevelIdsNullBoardIsNoop)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()