KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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_io/sch_io.h>
24#include <sch_sheet_path.h>
26
28{
29protected:
30 wxFileName GetSchematicPath( const wxString& aRelativePath ) override;
31};
32
33
34wxFileName TEST_SCH_SHEET_LIST_FIXTURE::GetSchematicPath( const wxString& aRelativePath )
35{
36 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
37 fn.AppendDir( "netlists" );
38
39 wxString path = fn.GetFullPath();
40 path += aRelativePath + wxT( "." ) + FILEEXT::KiCadSchematicFileExtension;
41
42 return wxFileName( path );
43}
44
45
46BOOST_FIXTURE_TEST_SUITE( SchSheetList, TEST_SCH_SHEET_LIST_FIXTURE )
47
48
49BOOST_AUTO_TEST_CASE( TestSheetListPageProperties )
50{
51 LoadSchematic( "complex_hierarchy/complex_hierarchy" );
52
53 SCH_SHEET_LIST sheets = m_schematic.BuildSheetListSortedByPageNumbers();
54
55 BOOST_CHECK( sheets.AllSheetPageNumbersEmpty() );
56
57 sheets.SetInitialPageNumbers();
58
59 // The root sheet should now be page 1.
60 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
61 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
62 BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
63}
64
65
66BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign )
67{
68 BOOST_TEST_CONTEXT( "Read Sub-Sheet, prior to modification" )
69 {
70 // Check the Sub Sheet has the expected page numbers
71 LoadSchematic( "complex_hierarchy_shared/ampli_ht/ampli_ht" );
72
73 SCH_SHEET_LIST sheets = m_schematic.BuildSheetListSortedByPageNumbers();
74
75 BOOST_CHECK_EQUAL( sheets.size(), 2 );
76 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" );
77 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" );
78 }
79
80 BOOST_TEST_CONTEXT( "Read Root Sheet, prior to modification" )
81 {
82 // Check the parent sheet has the expected page numbers
83 LoadSchematic( "complex_hierarchy_shared/complex_hierarchy" );
84
85 SCH_SHEET_LIST sheets = m_schematic.BuildSheetListSortedByPageNumbers();
86
87 BOOST_CHECK_EQUAL( sheets.size(), 5 );
88 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
89 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
90 BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
91 BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "4" );
92 BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "5" );
93 }
94
95 BOOST_TEST_CONTEXT( "Modify page numbers in root sheet" )
96 {
97 SCH_SHEET_LIST sheets = m_schematic.BuildSheetListSortedByPageNumbers();
98
99 // Amend Page numbers
100 sheets.at( 0 ).SetPageNumber( "A" );
101 sheets.at( 1 ).SetPageNumber( "B" );
102 sheets.at( 2 ).SetPageNumber( "C" );
103 sheets.at( 3 ).SetPageNumber( "D" );
104 sheets.at( 4 ).SetPageNumber( "E" );
105
106 // Save and reload
107 wxFileName rootFn = GetSchematicPath( "complex_hierarchy_shared/complex_hierarchy" );
108 wxFileName prjFn = rootFn;
109
110 prjFn.SetExt( FILEEXT::ProjectFileExtension );
111
112 rootFn.AppendDir( "temp" );
113 BOOST_CHECK( rootFn.Mkdir() );
114
115 wxFileName newPrjFn = rootFn;
116 newPrjFn.SetExt( FILEEXT::ProjectFileExtension );
117 BOOST_CHECK( wxCopyFile( prjFn.GetFullPath(), newPrjFn.GetFullPath() ) );
118
119 m_pi->SaveSchematicFile( rootFn.GetFullPath(), &m_schematic.Root(), &m_schematic );
120
121 wxFileName subSheetFn = rootFn;
122 BOOST_CHECK( subSheetFn.AppendDir( "ampli_ht" ) );
123 BOOST_CHECK( subSheetFn.Mkdir() );
124
125 subSheetFn.SetName( "ampli_ht" );
126 m_pi->SaveSchematicFile( subSheetFn.GetFullPath(), sheets.at( 1 ).Last(), &m_schematic );
127
128 subSheetFn.SetName( "filter" );
129 m_pi->SaveSchematicFile( subSheetFn.GetFullPath(), sheets.at( 2 ).Last(), &m_schematic );
130
131 LoadSchematic( "complex_hierarchy_shared/temp/complex_hierarchy" );
132
133 sheets = m_schematic.BuildSheetListSortedByPageNumbers();
134
135 BOOST_CHECK_EQUAL( sheets.size(), 5 );
136 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "A" );
137 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "B" );
138 BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "C" );
139 BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "D" );
140 BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "E" );
141
142 // Cleanup
143 BOOST_CHECK( wxRemoveFile( subSheetFn.GetFullPath() ) );
144 subSheetFn.SetName( "ampli_ht" );
145 BOOST_CHECK( wxRemoveFile( subSheetFn.GetFullPath() ) );
146 BOOST_CHECK( subSheetFn.Rmdir() );
147 BOOST_CHECK( wxRemoveFile( newPrjFn.GetFullPath() ) );
148 BOOST_CHECK( wxRemoveFile( rootFn.GetFullPath() ) );
149 BOOST_CHECK( rootFn.Rmdir() );
150 }
151
152 BOOST_TEST_CONTEXT( "Read Sub-Sheet, after modification" )
153 {
154 // Check the Sub Sheet has the expected page numbers
155 // (This should not have been modified after editing the root sheet)
156 LoadSchematic( "complex_hierarchy_shared/ampli_ht/ampli_ht" );
157
158 SCH_SHEET_LIST sheets = m_schematic.BuildSheetListSortedByPageNumbers();
159
160 BOOST_CHECK_EQUAL( sheets.size(), 2 );
161 BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" );
162 BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" );
163 }
164}
165
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
static const std::string ProjectFileExtension
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
static void LoadSchematic(SCHEMATIC *aSchematic, SCH_SHEET *aRootSheet, const wxString &aFileName)
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(TestSheetListPageProperties)
Definition of file extensions used in Kicad.