KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_connectivity_pin_name.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 as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * 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 <https://www.gnu.org/licenses/>.
18 */
19
22
24#include <sch_pin.h>
25#include <sch_screen.h>
26#include <sch_sheet.h>
27#include <sch_symbol.h>
28#include <schematic.h>
30
31using namespace SCH_CONNECTIVITY;
32
33BOOST_AUTO_TEST_SUITE( ConnectivityPinName )
34
35BOOST_AUTO_TEST_CASE( NamesUseUnitsButPadOnlyNamesDoNot )
36{
37 PIN_NAME_FACT pin{ "IN", "3", "3", "3" };
38 PIN_NAME_REFERENCE ref{ "U2", "U2B", "symbol-id" };
39 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref ), "Net-(U2B-IN)" );
40 pin.name = "3";
41 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref ), "Net-(U2-Pad3)" );
42 pin.name.clear();
43 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref ), "Net-(U2-Pad3)" );
44}
45
46BOOST_AUTO_TEST_CASE( DuplicateNamesAndNoConnectUsePadSuffix )
47{
48 PIN_NAME_FACT pin{ "IN", "3", "3", "3" };
49 PIN_NAME_REFERENCE ref{ "U2", "U2B", "symbol-id" };
50 pin.hasDuplicateName = true;
51 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref ), "Net-(U2B-IN-Pad3)" );
52 pin.hasDuplicateName = false;
53 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref, true ), "unconnected-(U2B-IN-Pad3)" );
54 pin.noConnect = true;
55 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref ), "unconnected-(U2B-IN-Pad3)" );
56}
57
58BOOST_AUTO_TEST_CASE( EscapingAndStackedPadSelection )
59{
60 PIN_NAME_FACT pin{ "A/B\n", "[10,2]", "[10,2]", "2" };
61 PIN_NAME_REFERENCE ref{ "U2", "U2B", "symbol-id" };
62 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref, true ), "unconnected-(U2B-A{slash}B-Pad2)" );
63 pin.padNumber = "2/3";
64 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref, true ), "unconnected-(U2B-A{slash}B-Pad2{slash}3)" );
65}
66
67BOOST_AUTO_TEST_CASE( UnannotatedAndMissingReferencesUseUuid )
68{
69 PIN_NAME_FACT pin{ "IN", "[10,2]", "[10,2]", "2" };
70 PIN_NAME_REFERENCE ref{ "U?", "U?B", "00000000-0000-0000-0000-000000000001" };
71 const wxString expected = wxString::Format( "Net-(U?-%08x-Pad2)",
72 static_cast<unsigned>( KIID( ref.symbolUuid ).Hash() & 0xFFFFFFFF ) );
74 ref.symbolUuid = "symbol-id";
75 ref.reference.clear();
76 ref.referenceWithUnit.clear();
77 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref, true ), "unconnected-(symbol-id-Pad2)" );
78 pin.number = "3/4";
79 pin.padNumber = pin.shownNumber;
80 BOOST_CHECK_EQUAL( RenderPinNetName( pin, ref ), "Net-(symbol-id-Pad3/4)" );
81}
82
83BOOST_AUTO_TEST_CASE( OriginalAlternateFixtureUsesLibraryNumberAndReplacesCachedNcName )
84{
85 SETTINGS_MANAGER settings;
86 std::unique_ptr<SCHEMATIC> schematic;
87 KI_TEST::LoadSchematic( settings, "issue22286/bugtest", schematic );
88 const SCH_SHEET_PATH path = schematic->Hierarchy()[0];
89 SCH_PIN* target = nullptr;
90
91 for( SCH_ITEM* item : path.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
92 {
93 auto* symbol = static_cast<SCH_SYMBOL*>( item );
94
95 if( symbol->GetRef( &path ) != "J1" )
96 continue;
97
98 for( SCH_PIN* pin : symbol->GetPins( &path ) )
99 {
100 if( pin->GetNumber() == "8" )
101 target = pin;
102 }
103 }
104
105 BOOST_REQUIRE( target );
106 BOOST_CHECK_EQUAL( target->GetShownName(), "8.pow" );
107 BOOST_CHECK_EQUAL( target->GetDefaultNetName( path ), "Net-(J1-Pad8)" );
108 BOOST_CHECK_EQUAL( target->GetDefaultNetName( path, true ), "unconnected-(J1-Pad8)" );
109 BOOST_CHECK_EQUAL( target->GetDefaultNetName( path ), "Net-(J1-Pad8)" );
110}
111
Definition kiid.h:46
size_t Hash() const
Definition kiid.cpp:231
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
const wxString & GetShownName() const
Definition sch_pin.cpp:680
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition sch_pin.cpp:1666
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:75
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
wxString RenderPinNetName(const PIN_NAME_FACT &aPin, const PIN_NAME_REFERENCE &aReference, bool aForceNoConnect)
Render a non-power pin name from unescaped values; an absent reference uses the symbol UUID.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(NamesUseUnitsButPadOnlyNamesDoNot)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::string path
KIBIS_PIN * pin
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL(result, "25.4")
@ SCH_SYMBOL_T
Definition typeinfo.h:168