KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_sch_sheet_path.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) 2019-2020 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 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
31#include "eeschema_test_utils.h"
32
33// Code under test
34#include <sch_sheet_path.h>
35
37#include <eeschema_helpers.h>
38#include <sch_screen.h>
39#include <sch_sheet.h>
40
41#include <sstream>
42
44{
45public:
47 {
48 for( unsigned i = 0; i < 4; ++i )
49 {
50 m_sheets.emplace_back( nullptr, VECTOR2I( i, i ) );
51
52 std::ostringstream ss;
53 ss << "Sheet" << i;
54 m_sheets[i].GetFields()[SHEETNAME].SetText( ss.str() );
55 }
56
57 // 0->1->2
61 }
62
64
70
72 std::vector<SCH_SHEET> m_sheets;
73};
74
75
79BOOST_FIXTURE_TEST_SUITE( SchSheetPath, TEST_SCH_SHEET_PATH_FIXTURE )
80
81
82
86{
87 BOOST_CHECK_EQUAL( m_empty_path.size(), 0 );
88
89 BOOST_CHECK_THROW( m_empty_path.at( 0 ), std::out_of_range );
90
91 // Sheet paths with no SCH_SCHEET object are illegal.
92 // CHECK_WX_ASSERT( m_empty_path.GetPageNumber() );
93
94 // These accessors return nullptr when empty (i.e. they don't crash)
95 BOOST_CHECK_EQUAL( m_empty_path.Last(), nullptr );
96 BOOST_CHECK_EQUAL( m_empty_path.LastScreen(), nullptr );
97
98 BOOST_CHECK_EQUAL( m_empty_path.PathAsString(), "/" );
99 BOOST_CHECK_EQUAL( m_empty_path.PathHumanReadable(), "/" );
100}
101
102
107{
108 BOOST_CHECK_EQUAL( m_linear.size(), 3 );
109
110 BOOST_CHECK_EQUAL( m_linear.at( 0 ), &m_sheets[0] );
111 BOOST_CHECK_EQUAL( m_linear.at( 1 ), &m_sheets[1] );
112 BOOST_CHECK_EQUAL( m_linear.at( 2 ), &m_sheets[2] );
113
114 BOOST_CHECK_EQUAL( m_linear.Last(), &m_sheets[2] );
115 BOOST_CHECK_EQUAL( m_linear.LastScreen(), nullptr );
116
117 // don't know what the uuids will be, but we know the format: /<8-4-4-4-12>/<8-4-4-4-12>/
118 BOOST_CHECK_PREDICATE(
119 KI_TEST::IsUUIDPathWithLevels, ( m_linear.PathAsString().ToStdString() )( 2 ) );
120
121 // Sheet0 is the root sheet and isn't in the path
122 BOOST_CHECK_EQUAL( m_linear.PathHumanReadable(), "/Sheet1/Sheet2/" );
123}
124
125
127{
128 SCH_SHEET_PATH otherEmpty;
129
130 BOOST_CHECK( m_empty_path == otherEmpty );
131
132 BOOST_CHECK( m_empty_path != m_linear );
133}
134
135
136BOOST_AUTO_TEST_CASE( SheetListGetOrdinalPath )
137{
138 // The "complex_hierarchy" test project has a root sheet with two sheets that reference the
139 // same file.
140 std::unique_ptr<SCHEMATIC> schematic;
141 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() + wxS( "netlists/complex_hierarchy" ),
142 wxS( "complex_hierarchy" ), FILEEXT::ProjectFileExtension );
143
144 schematic.reset( EESCHEMA_HELPERS::LoadSchematic( fn.GetFullPath(), false, false, nullptr ) );
145
146 SCH_SHEET_LIST hierarchy = schematic->Hierarchy();
147 BOOST_CHECK_EQUAL( hierarchy.size(), 3 );
148
149 // A null pointer should always result in an empty return value.
150 BOOST_CHECK( !hierarchy.GetOrdinalPath( nullptr ) );
151
152 // The root sheet is a single instance. It's always ordinal.
153 BOOST_CHECK( hierarchy.GetOrdinalPath( schematic->RootScreen() ).value() == hierarchy.at( 0 ) );
154
155 // The shared schematic with the lowest page number is the ordinal sheet path.
156 SCH_SHEET* sheet = hierarchy.at( 1 ).Last();
157 BOOST_CHECK( hierarchy.GetOrdinalPath( sheet->GetScreen() ).value() == hierarchy.at( 1 ) );
158
159 // The shared sheet with a higher page number is not the ordinal sheet path.
160 sheet = hierarchy.at( 2 ).Last();
161 BOOST_CHECK( hierarchy.GetOrdinalPath( sheet->GetScreen() ).value() == hierarchy.at( 1 ) );
162}
163
164
168BOOST_AUTO_TEST_CASE( SheetPathPageProperties )
169{
170 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), wxEmptyString );
171
172 // Add new instance to sheet object.
173 // BOOST_CHECK( m_linear.Last()->AddInstance( m_linear.Path() ) );
174 // m_linear.SetPageNumber( "1" );
175 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "1" );
176 // m_linear.SetPageNumber( "i" );
177 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "i" );
178}
179
180
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
std::optional< SCH_SHEET_PATH > GetOrdinalPath(const SCH_SCREEN *aScreen) const
Return the ordinal sheet path of aScreen.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:110
std::vector< SCH_SHEET > m_sheets
handy store of SCH_SHEET objects
SCH_SHEET_PATH m_linear
We look at sheet 2 in the hierarchy: Sheets: 0 -> 1 -> 2.
static const std::string ProjectFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
bool IsUUIDPathWithLevels(const std::string &aStr, unsigned aLevels)
Predicate to check a string is a UUID path format.
@ SHEETNAME
Definition: sch_sheet.h:45
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Empty)
Declare the test suite.
Test utilities for timestamps.
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:691
Definition of file extensions used in Kicad.