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, see <https://www.gnu.org/licenses/>.
18 */
19
21#include <boost/test/unit_test.hpp>
22
23#include <lib_id.h>
24
25
27
28
29BOOST_AUTO_TEST_CASE( ParseFullyQualified )
30{
31 LIB_ID id;
32 BOOST_CHECK( id.Parse( "Package_SO:DGG56" ) == -1 );
33 BOOST_CHECK_EQUAL( id.GetLibNickname(), "Package_SO" );
34 BOOST_CHECK_EQUAL( id.GetLibItemName(), "DGG56" );
35 BOOST_CHECK( id.IsValid() );
36 BOOST_CHECK( !id.IsLegacy() );
37 BOOST_CHECK( !id.empty() );
38}
39
40
42{
43 LIB_ID id;
44 BOOST_CHECK( id.Parse( "DGG56" ) == -1 );
45 BOOST_CHECK( id.GetLibNickname().empty() );
46 BOOST_CHECK_EQUAL( id.GetLibItemName(), "DGG56" );
47 BOOST_CHECK( !id.IsValid() );
48 BOOST_CHECK( id.IsLegacy() );
49 BOOST_CHECK( !id.empty() );
50}
51
52
53BOOST_AUTO_TEST_CASE( EqualityFullyQualified )
54{
55 LIB_ID a( wxT( "Package_SO" ), wxT( "DGG56" ) );
56 LIB_ID b( wxT( "Package_SO" ), wxT( "DGG56" ) );
57 LIB_ID c( wxT( "OtherLib" ), wxT( "DGG56" ) );
58
59 BOOST_CHECK( a == b );
60 BOOST_CHECK( a != c );
61}
62
63
64BOOST_AUTO_TEST_CASE( EqualityLegacyVsFullyQualified )
65{
66 LIB_ID legacy;
67 legacy.Parse( "DGG56" );
68
69 LIB_ID qualified( wxT( "Package_SO" ), wxT( "DGG56" ) );
70
71 // Standard equality requires both library and item name to match
72 BOOST_CHECK( legacy != qualified );
73
74 // Legacy matching (item name only) should match when we explicitly compare just item names
75 BOOST_CHECK( legacy.IsLegacy() );
76 BOOST_CHECK_EQUAL( legacy.GetLibItemName(), qualified.GetLibItemName() );
77}
78
79
80BOOST_AUTO_TEST_CASE( FormatRoundTrip )
81{
82 LIB_ID qualified( wxT( "Package_SO" ), wxT( "DGG56" ) );
83 BOOST_CHECK_EQUAL( qualified.Format().wx_str(), wxT( "Package_SO:DGG56" ) );
84
85 LIB_ID legacy;
86 legacy.Parse( "DGG56" );
87 BOOST_CHECK_EQUAL( legacy.Format().wx_str(), wxT( "DGG56" ) );
88
89 // Re-parse the formatted strings
90 LIB_ID reparsed;
91 reparsed.Parse( qualified.Format() );
92 BOOST_CHECK( reparsed == qualified );
93
94 LIB_ID reparsedLegacy;
95 reparsedLegacy.Parse( legacy.Format() );
96 BOOST_CHECK( reparsedLegacy.IsLegacy() );
97 BOOST_CHECK_EQUAL( reparsedLegacy.GetLibItemName(), legacy.GetLibItemName() );
98}
99
100
102{
104 BOOST_CHECK( empty.empty() );
105 BOOST_CHECK( !empty.IsValid() );
106 BOOST_CHECK( !empty.IsLegacy() );
107}
108
109
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
Definition lib_id.cpp:48
UTF8 Format() const
Definition lib_id.cpp:115
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
bool IsLegacy() const
Definition lib_id.h:176
wxString wx_str() const
Definition utf8.cpp:41
static bool empty(const wxTextEntryBase *aCtrl)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(ParseFullyQualified)
BOOST_CHECK_EQUAL(result, "25.4")