KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_unique_group_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
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
25
26#include <boost/test/unit_test.hpp>
27
28#include <sch_screen.h>
29#include <sch_group.h>
31
32
33namespace
34{
35SCH_GROUP* addGroup( SCH_SCREEN& aScreen, const wxString& aName )
36{
37 SCH_GROUP* group = new SCH_GROUP( &aScreen );
38 group->SetName( aName );
39 aScreen.Append( group );
40 return group;
41}
42} // namespace
43
44
45BOOST_AUTO_TEST_SUITE( UniqueGroupNames )
46
47
48BOOST_AUTO_TEST_CASE( NullScreenReturnsBase )
49{
50 BOOST_CHECK_EQUAL( UniqueGroupName( nullptr, wxT( "Amp" ) ), wxString( wxT( "Amp" ) ) );
51}
52
53
54BOOST_AUTO_TEST_CASE( FreeNameIsKept )
55{
56 SCH_SCREEN screen;
57 addGroup( screen, wxT( "Other Group" ) );
58
59 BOOST_CHECK_EQUAL( UniqueGroupName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp" ) ) );
60}
61
62
63BOOST_AUTO_TEST_CASE( CollisionGetsSuffix )
64{
65 SCH_SCREEN screen;
66 addGroup( screen, wxT( "Amp" ) );
67
68 BOOST_CHECK_EQUAL( UniqueGroupName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp1" ) ) );
69}
70
71
72BOOST_AUTO_TEST_CASE( SuffixSkipsTakenNumbers )
73{
74 SCH_SCREEN screen;
75 addGroup( screen, wxT( "Amp" ) );
76 addGroup( screen, wxT( "Amp1" ) );
77
78 BOOST_CHECK_EQUAL( UniqueGroupName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp2" ) ) );
79}
80
81
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Class to handle a set of SCH_ITEMs.
wxString UniqueGroupName(SCH_SCREEN *aScreen, const wxString &aBaseName)
Return aBaseName, or aBaseName + smallest free integer if a group with that name already exists on aS...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(NullScreenReturnsBase)