KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_lib_id.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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 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
24
#include <
qa_utils/wx_utils/unit_test_utils.h
>
25
#include <boost/test/unit_test.hpp>
26
27
#include <
lib_id.h
>
28
29
30
BOOST_AUTO_TEST_SUITE
( LibId )
31
32
33
BOOST_AUTO_TEST_CASE
( ParseFullyQualified )
34
{
35
LIB_ID
id;
36
BOOST_CHECK(
id
.Parse(
"Package_SO:DGG56"
) == -1 );
37
BOOST_CHECK_EQUAL
(
id
.GetLibNickname(),
"Package_SO"
);
38
BOOST_CHECK_EQUAL
(
id
.GetLibItemName(),
"DGG56"
);
39
BOOST_CHECK(
id
.IsValid() );
40
BOOST_CHECK( !
id
.IsLegacy() );
41
BOOST_CHECK( !
id
.
empty
() );
42
}
43
44
45
BOOST_AUTO_TEST_CASE
( ParseLegacy )
46
{
47
LIB_ID
id;
48
BOOST_CHECK(
id
.Parse(
"DGG56"
) == -1 );
49
BOOST_CHECK(
id
.GetLibNickname().
empty
() );
50
BOOST_CHECK_EQUAL
(
id
.GetLibItemName(),
"DGG56"
);
51
BOOST_CHECK( !
id
.IsValid() );
52
BOOST_CHECK(
id
.IsLegacy() );
53
BOOST_CHECK( !
id
.
empty
() );
54
}
55
56
57
BOOST_AUTO_TEST_CASE
( EqualityFullyQualified )
58
{
59
LIB_ID
a( wxT(
"Package_SO"
), wxT(
"DGG56"
) );
60
LIB_ID
b( wxT(
"Package_SO"
), wxT(
"DGG56"
) );
61
LIB_ID
c( wxT(
"OtherLib"
), wxT(
"DGG56"
) );
62
63
BOOST_CHECK( a == b );
64
BOOST_CHECK( a != c );
65
}
66
67
68
BOOST_AUTO_TEST_CASE
( EqualityLegacyVsFullyQualified )
69
{
70
LIB_ID
legacy;
71
legacy.
Parse
(
"DGG56"
);
72
73
LIB_ID
qualified( wxT(
"Package_SO"
), wxT(
"DGG56"
) );
74
75
// Standard equality requires both library and item name to match
76
BOOST_CHECK( legacy != qualified );
77
78
// Legacy matching (item name only) should match when we explicitly compare just item names
79
BOOST_CHECK( legacy.
IsLegacy
() );
80
BOOST_CHECK_EQUAL
( legacy.
GetLibItemName
(), qualified.
GetLibItemName
() );
81
}
82
83
84
BOOST_AUTO_TEST_CASE
( FormatRoundTrip )
85
{
86
LIB_ID
qualified( wxT(
"Package_SO"
), wxT(
"DGG56"
) );
87
BOOST_CHECK_EQUAL
( qualified.
Format
().
wx_str
(), wxT(
"Package_SO:DGG56"
) );
88
89
LIB_ID
legacy;
90
legacy.
Parse
(
"DGG56"
);
91
BOOST_CHECK_EQUAL
( legacy.
Format
().
wx_str
(), wxT(
"DGG56"
) );
92
93
// Re-parse the formatted strings
94
LIB_ID
reparsed;
95
reparsed.
Parse
( qualified.
Format
() );
96
BOOST_CHECK( reparsed == qualified );
97
98
LIB_ID
reparsedLegacy;
99
reparsedLegacy.
Parse
( legacy.
Format
() );
100
BOOST_CHECK( reparsedLegacy.
IsLegacy
() );
101
BOOST_CHECK_EQUAL
( reparsedLegacy.
GetLibItemName
(), legacy.
GetLibItemName
() );
102
}
103
104
105
BOOST_AUTO_TEST_CASE
( EmptyId )
106
{
107
LIB_ID
empty
;
108
BOOST_CHECK(
empty
.empty() );
109
BOOST_CHECK( !
empty
.IsValid() );
110
BOOST_CHECK( !
empty
.IsLegacy() );
111
}
112
113
114
BOOST_AUTO_TEST_SUITE_END
()
LIB_ID
A logical library item identifier and consists of various portions much like a URI.
Definition
lib_id.h:49
LIB_ID::Parse
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition
lib_id.cpp:52
LIB_ID::Format
UTF8 Format() const
Definition
lib_id.cpp:119
LIB_ID::GetLibItemName
const UTF8 & GetLibItemName() const
Definition
lib_id.h:102
LIB_ID::IsLegacy
bool IsLegacy() const
Definition
lib_id.h:180
UTF8::wx_str
wxString wx_str() const
Definition
utf8.cpp:45
empty
static bool empty(const wxTextEntryBase *aCtrl)
Definition
dialog_sim_command.cpp:41
lib_id.h
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:136
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(ParseFullyQualified)
Definition
test_lib_id.cpp:33
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
common
test_lib_id.cpp
Generated on Sat Feb 21 2026 00:08:11 for KiCad PCB EDA Suite by
1.13.2