KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_unique_sheet_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_sheet.h>
31
32
33namespace
34{
35SCH_SHEET* addSheet( SCH_SCREEN& aScreen, const wxString& aName )
36{
37 SCH_SHEET* sheet = new SCH_SHEET();
38 sheet->SetName( aName );
39 aScreen.Append( sheet );
40 return sheet;
41}
42} // namespace
43
44
45BOOST_AUTO_TEST_SUITE( UniqueSheetNames )
46
47
48BOOST_AUTO_TEST_CASE( NullScreenReturnsBase )
49{
50 BOOST_CHECK_EQUAL( UniqueSheetName( nullptr, wxT( "Amp" ) ), wxString( wxT( "Amp" ) ) );
51}
52
53
54BOOST_AUTO_TEST_CASE( FreeNameIsKept )
55{
56 SCH_SCREEN screen;
57 addSheet( screen, wxT( "Other Sheet" ) );
58
59 BOOST_CHECK_EQUAL( UniqueSheetName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp" ) ) );
60}
61
62
63BOOST_AUTO_TEST_CASE( CollisionGetsSuffix )
64{
65 SCH_SCREEN screen;
66 addSheet( screen, wxT( "Amp" ) );
67
68 BOOST_CHECK_EQUAL( UniqueSheetName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp1" ) ) );
69}
70
71
72BOOST_AUTO_TEST_CASE( SuffixSkipsTakenNumbers )
73{
74 SCH_SCREEN screen;
75 addSheet( screen, wxT( "Amp" ) );
76 addSheet( screen, wxT( "Amp1" ) );
77 addSheet( screen, wxT( "Amp2" ) );
78
79 BOOST_CHECK_EQUAL( UniqueSheetName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp3" ) ) );
80}
81
82
83BOOST_AUTO_TEST_CASE( ComparisonIsCaseInsensitive )
84{
85 SCH_SCREEN screen;
86 addSheet( screen, wxT( "AMP" ) );
87 addSheet( screen, wxT( "amp1" ) );
88
89 BOOST_CHECK_EQUAL( UniqueSheetName( &screen, wxT( "Amp" ) ), wxString( wxT( "Amp2" ) ) );
90}
91
92
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
void SetName(const wxString &aName)
Definition sch_sheet.h:137
wxString UniqueSheetName(SCH_SCREEN *aScreen, const wxString &aBaseName)
Return aBaseName, or aBaseName + smallest free integer if a sheet 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)