KiCad PCB EDA Suite
test_sch_sheet_list.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 (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21#include "eeschema_test_utils.h"
22
23#include <sch_sheet_path.h>
25
27{
28protected:
29 wxFileName GetSchematicPath( const wxString& aRelativePath ) override;
30};
31
32
33wxFileName TEST_SCH_SHEET_LIST_FIXTURE::GetSchematicPath( const wxString& aRelativePath )
34{
35 wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
36 fn.AppendDir( "netlists" );
37
38 wxString path = fn.GetFullPath();
39 path += aRelativePath + wxT( "." ) + KiCadSchematicFileExtension;
40
41 return wxFileName( path );
42}
43
44
45BOOST_FIXTURE_TEST_SUITE( SchSheetList, TEST_SCH_SHEET_LIST_FIXTURE )
46
47
48BOOST_AUTO_TEST_CASE( TestSheetListPageProperties )
49{
50 LoadSchematic( "complex_hierarchy/complex_hierarchy" );
51
52 SCH_SHEET_LIST sheets = m_schematic.GetSheets();
53
55
56 sheets.SetInitialPageNumbers();
57
58 // The root sheet should now be page 1.
59 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
60 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
61 BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
62}
63
64
65BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign )
66{
67 BOOST_TEST_CONTEXT( "Read Sub-Sheet, prior to modification" )
68 {
69 // Check the Sub Sheet has the expected page numbers
70 LoadSchematic( "complex_hierarchy_shared/ampli_ht/ampli_ht" );
71
72 SCH_SHEET_LIST sheets = m_schematic.GetSheets();
73
74 BOOST_CHECK_EQUAL( sheets.size(), 2 );
75 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" );
76 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" );
77 }
78
79 BOOST_TEST_CONTEXT( "Read Root Sheet, prior to modification" )
80 {
81 // Check the parent sheet has the expected page numbers
82 LoadSchematic( "complex_hierarchy_shared/complex_hierarchy" );
83
84 SCH_SHEET_LIST sheets = m_schematic.GetSheets();
85
86 BOOST_CHECK_EQUAL( sheets.size(), 5 );
87 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
88 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
89 BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
90 BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "4" );
91 BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "5" );
92 }
93
94 BOOST_TEST_CONTEXT( "Modify page numbers in root sheet" )
95 {
96 SCH_SHEET_LIST sheets = m_schematic.GetSheets();
97
98 // Amend Page numbers
99 sheets.at( 0 ).SetPageNumber( "A" );
100 sheets.at( 1 ).SetPageNumber( "B" );
101 sheets.at( 2 ).SetPageNumber( "C" );
102 sheets.at( 3 ).SetPageNumber( "D" );
103 sheets.at( 4 ).SetPageNumber( "E" );
104
105 // Save and reload
106 wxFileName rootFn = GetSchematicPath( "complex_hierarchy_shared/complex_hierarchy" );
107 wxFileName prjFn = rootFn;
108
109 prjFn.SetExt( ProjectFileExtension );
110
111 rootFn.AppendDir( "temp" );
112 BOOST_CHECK( rootFn.Mkdir() );
113
114 wxFileName newPrjFn = rootFn;
115 newPrjFn.SetExt( ProjectFileExtension );
116 BOOST_CHECK( wxCopyFile( prjFn.GetFullPath(), newPrjFn.GetFullPath() ) );
117
118 m_pi->Save( rootFn.GetFullPath(), &m_schematic.Root(), &m_schematic );
119
120 wxFileName subSheetFn = rootFn;
121 BOOST_CHECK( subSheetFn.AppendDir( "ampli_ht" ) );
122 BOOST_CHECK( subSheetFn.Mkdir() );
123
124 subSheetFn.SetName( "ampli_ht" );
125 m_pi->Save( subSheetFn.GetFullPath(), sheets.at( 1 ).Last(), &m_schematic );
126
127 subSheetFn.SetName( "filter" );
128 m_pi->Save( subSheetFn.GetFullPath(), sheets.at( 2 ).Last(), &m_schematic );
129
130 LoadSchematic( "complex_hierarchy_shared/temp/complex_hierarchy" );
131
132 sheets = m_schematic.GetSheets();
133
134 BOOST_CHECK_EQUAL( sheets.size(), 5 );
135 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "A" );
136 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "B" );
137 BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "C" );
138 BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "D" );
139 BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "E" );
140
141 // Cleanup
142 BOOST_CHECK( wxRemoveFile( subSheetFn.GetFullPath() ) );
143 subSheetFn.SetName( "ampli_ht" );
144 BOOST_CHECK( wxRemoveFile( subSheetFn.GetFullPath() ) );
145 BOOST_CHECK( subSheetFn.Rmdir() );
146 BOOST_CHECK( wxRemoveFile( newPrjFn.GetFullPath() ) );
147 BOOST_CHECK( wxRemoveFile( rootFn.GetFullPath() ) );
148 BOOST_CHECK( rootFn.Rmdir() );
149 }
150
151 BOOST_TEST_CONTEXT( "Read Sub-Sheet, after modification" )
152 {
153 // Check the Sub Sheet has the expected page numbers
154 // (This should not have been modified after editing the root sheet)
155 LoadSchematic( "complex_hierarchy_shared/ampli_ht/ampli_ht" );
156
157 SCH_SHEET_LIST sheets = m_schematic.GetSheets();
158
159 BOOST_CHECK_EQUAL( sheets.size(), 2 );
160 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" );
161 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" );
162 }
163}
164
165BOOST_AUTO_TEST_SUITE_END()
A generic fixture for loading schematics and associated settings for qa tests.
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void SetInitialPageNumbers()
Set initial sheet page numbers.
bool AllSheetPageNumbersEmpty() const
Check all of the sheet instance for empty page numbers.
wxFileName GetSchematicPath(const wxString &aRelativePath) override
const std::string ProjectFileExtension
const std::string KiCadSchematicFileExtension
wxFileName GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
BOOST_AUTO_TEST_CASE(TestSheetListPageProperties)
#define BOOST_TEST_CONTEXT(A)
Definition of file extensions used in Kicad.