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
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
#include <
schematic_utils/schematic_file_util.h
>
22
23
#include <
connectivity/conn_pin_name.h
>
24
#include <
sch_pin.h
>
25
#include <
sch_screen.h
>
26
#include <
sch_sheet.h
>
27
#include <
sch_symbol.h
>
28
#include <
schematic.h
>
29
#include <
settings/settings_manager.h
>
30
31
using namespace
SCH_CONNECTIVITY
;
32
33
BOOST_AUTO_TEST_SUITE
( ConnectivityPinName )
34
35
BOOST_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
46
BOOST_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
58
BOOST_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
67
BOOST_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 ) );
73
BOOST_CHECK_EQUAL
(
RenderPinNetName
(
pin
, ref ),
expected
);
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
83
BOOST_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
112
BOOST_AUTO_TEST_SUITE_END
()
KIID
Definition
kiid.h:46
KIID::Hash
size_t Hash() const
Definition
kiid.cpp:231
SCH_ITEM
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition
sch_item.h:165
SCH_PIN
Definition
sch_pin.h:59
SCH_PIN::GetShownName
const wxString & GetShownName() const
Definition
sch_pin.cpp:680
SCH_PIN::GetDefaultNetName
wxString GetDefaultNetName(const SCH_SHEET_PATH &aPath, bool aForceNoConnect=false)
Definition
sch_pin.cpp:1666
SCH_SHEET_PATH
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Definition
sch_sheet_path.h:246
SCH_SYMBOL
Schematic symbol object.
Definition
sch_symbol.h:75
SETTINGS_MANAGER
Definition
settings_manager.h:48
conn_pin_name.h
KI_TEST::LoadSchematic
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
Definition
schematic_file_util.cpp:117
SCH_CONNECTIVITY
Definition
conn_navigation.cpp:28
SCH_CONNECTIVITY::RenderPinNetName
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.
Definition
conn_pin_name.cpp:27
sch_pin.h
sch_screen.h
sch_sheet.h
sch_symbol.h
schematic.h
schematic_file_util.h
settings_manager.h
SCH_CONNECTIVITY::PIN_NAME_FACT
Definition
conn_pin_name.h:27
SCH_CONNECTIVITY::PIN_NAME_REFERENCE
Definition
conn_pin_name.h:38
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:79
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(NamesUseUnitsButPadOnlyNamesDoNot)
Definition
test_connectivity_pin_name.cpp:35
BOOST_REQUIRE
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
path
std::string path
Definition
test_kibis.cpp:99
pin
KIBIS_PIN * pin
Definition
test_kibis.cpp:116
expected
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
SCH_SYMBOL_T
@ SCH_SYMBOL_T
Definition
typeinfo.h:168
unit_test_utils.h
src
qa
tests
eeschema
test_connectivity_pin_name.cpp
Generated on Thu Sep 17 2026 00:06:25 for KiCad PCB EDA Suite by
1.13.2