KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_bus_alias_whitespace.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
* https://www.gnu.org/licenses/gpl-3.0.en.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
30
31
#include <
qa_utils/wx_utils/unit_test_utils.h
>
32
#include <
bus_alias.h
>
33
34
35
BOOST_AUTO_TEST_SUITE
( BusAliasWhitespace )
36
37
38
BOOST_AUTO_TEST_CASE
( SetNameTrimsWhitespace )
39
{
40
BUS_ALIAS
alias;
41
42
alias.
SetName
( wxS(
"DATA "
) );
43
BOOST_CHECK_EQUAL
( alias.
GetName
(), wxS(
"DATA"
) );
44
45
alias.
SetName
( wxS(
" DATA"
) );
46
BOOST_CHECK_EQUAL
( alias.
GetName
(), wxS(
"DATA"
) );
47
48
alias.
SetName
( wxS(
" DATA "
) );
49
BOOST_CHECK_EQUAL
( alias.
GetName
(), wxS(
"DATA"
) );
50
51
alias.
SetName
( wxS(
"DATA"
) );
52
BOOST_CHECK_EQUAL
( alias.
GetName
(), wxS(
"DATA"
) );
53
54
alias.
SetName
( wxS(
" "
) );
55
BOOST_CHECK_EQUAL
( alias.
GetName
(), wxS(
""
) );
56
}
57
58
59
BOOST_AUTO_TEST_CASE
( AddMemberTrimsWhitespace )
60
{
61
BUS_ALIAS
alias;
62
63
alias.
AddMember
( wxS(
"SDA "
) );
64
alias.
AddMember
( wxS(
" SCL"
) );
65
alias.
AddMember
( wxS(
" MOSI "
) );
66
alias.
AddMember
( wxS(
"MISO"
) );
67
68
BOOST_REQUIRE_EQUAL( alias.
Members
().size(), 4u );
69
BOOST_CHECK_EQUAL
( alias.
Members
()[0], wxS(
"SDA"
) );
70
BOOST_CHECK_EQUAL
( alias.
Members
()[1], wxS(
"SCL"
) );
71
BOOST_CHECK_EQUAL
( alias.
Members
()[2], wxS(
"MOSI"
) );
72
BOOST_CHECK_EQUAL
( alias.
Members
()[3], wxS(
"MISO"
) );
73
}
74
75
76
BOOST_AUTO_TEST_CASE
( AddMemberRejectsEmpty )
77
{
78
BUS_ALIAS
alias;
79
80
alias.
AddMember
( wxS(
""
) );
81
alias.
AddMember
( wxS(
" "
) );
82
alias.
AddMember
( wxS(
"SDA"
) );
83
84
BOOST_REQUIRE_EQUAL( alias.
Members
().size(), 1u );
85
BOOST_CHECK_EQUAL
( alias.
Members
()[0], wxS(
"SDA"
) );
86
}
87
88
89
BOOST_AUTO_TEST_CASE
( SetMembersTrimsWhitespace )
90
{
91
BUS_ALIAS
alias;
92
93
std::vector<wxString> members = { wxS(
" SDA "
), wxS(
"SCL "
), wxS(
" MOSI"
), wxS(
""
), wxS(
" "
) };
94
alias.
SetMembers
( members );
95
96
BOOST_REQUIRE_EQUAL( alias.
Members
().size(), 3u );
97
BOOST_CHECK_EQUAL
( alias.
Members
()[0], wxS(
"SDA"
) );
98
BOOST_CHECK_EQUAL
( alias.
Members
()[1], wxS(
"SCL"
) );
99
BOOST_CHECK_EQUAL
( alias.
Members
()[2], wxS(
"MOSI"
) );
100
}
101
102
103
BOOST_AUTO_TEST_CASE
( ClonePreservesTrimmedValues )
104
{
105
BUS_ALIAS
alias;
106
107
alias.
SetName
( wxS(
"DATA "
) );
108
alias.
AddMember
( wxS(
" SDA "
) );
109
alias.
AddMember
( wxS(
"SCL "
) );
110
111
std::shared_ptr<BUS_ALIAS> clone = alias.
Clone
();
112
113
BOOST_CHECK_EQUAL
( clone->GetName(), wxS(
"DATA"
) );
114
BOOST_REQUIRE_EQUAL( clone->Members().size(), 2u );
115
BOOST_CHECK_EQUAL
( clone->Members()[0], wxS(
"SDA"
) );
116
BOOST_CHECK_EQUAL
( clone->Members()[1], wxS(
"SCL"
) );
117
}
118
119
120
BOOST_AUTO_TEST_CASE
( ClearMembersWorks )
121
{
122
BUS_ALIAS
alias;
123
124
alias.
AddMember
( wxS(
"SDA"
) );
125
alias.
AddMember
( wxS(
"SCL"
) );
126
BOOST_CHECK_EQUAL
( alias.
Members
().size(), 2u );
127
128
alias.
ClearMembers
();
129
BOOST_CHECK_EQUAL
( alias.
Members
().size(), 0u );
130
}
131
132
133
BOOST_AUTO_TEST_SUITE_END
()
bus_alias.h
BUS_ALIAS
Definition
bus_alias.h:31
BUS_ALIAS::SetName
void SetName(const wxString &aName)
Definition
bus_alias.h:45
BUS_ALIAS::SetMembers
void SetMembers(const std::vector< wxString > &aMembers)
Definition
bus_alias.h:49
BUS_ALIAS::Clone
std::shared_ptr< BUS_ALIAS > Clone() const
Definition
bus_alias.h:38
BUS_ALIAS::ClearMembers
void ClearMembers()
Definition
bus_alias.h:70
BUS_ALIAS::GetName
wxString GetName() const
Definition
bus_alias.h:43
BUS_ALIAS::Members
const std::vector< wxString > & Members() const
Definition
bus_alias.h:47
BUS_ALIAS::AddMember
void AddMember(const wxString &aMember)
Definition
bus_alias.h:62
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:136
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(SetNameTrimsWhitespace)
Definition
test_bus_alias_whitespace.cpp:38
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
unit_test_utils.h
src
qa
tests
eeschema
test_bus_alias_whitespace.cpp
Generated on Sat Feb 21 2026 00:08:11 for KiCad PCB EDA Suite by
1.13.2