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 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, 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
28
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#include <schematic.h>
41
42#include <sstream>
43
45{
46public:
48 {
49 for( unsigned i = 0; i < 4; ++i )
50 {
51 m_sheets.emplace_back( nullptr, VECTOR2I( i, i ) );
52
53 std::ostringstream ss;
54 ss << "Sheet" << i;
55 m_sheets[i].GetField( FIELD_T::SHEET_NAME )->SetText( ss.str() );
56 m_sheets[i].SetParent( &m_schematic );
57 }
58
59 // 0->1->2
60 m_linear.push_back( &m_sheets[0] );
61 m_linear.push_back( &m_sheets[1] );
62 m_linear.push_back( &m_sheets[2] );
63 }
64
67
73
75 std::vector<SCH_SHEET> m_sheets;
76};
77
78
82BOOST_FIXTURE_TEST_SUITE( SchSheetPath, TEST_SCH_SHEET_PATH_FIXTURE )
83
84
85
89{
90 BOOST_CHECK_EQUAL( m_empty_path.size(), 0 );
91
92 BOOST_CHECK_THROW( m_empty_path.at( 0 ), std::out_of_range );
93
94 // Sheet paths with no SCH_SCHEET object are illegal.
95 // CHECK_WX_ASSERT( m_empty_path.GetPageNumber() );
96
97 // These accessors return nullptr when empty (i.e. they don't crash)
98 BOOST_CHECK_EQUAL( m_empty_path.Last(), nullptr );
99 BOOST_CHECK_EQUAL( m_empty_path.LastScreen(), nullptr );
100
101 BOOST_CHECK_EQUAL( m_empty_path.PathAsString(), "/" );
102 BOOST_CHECK_EQUAL( m_empty_path.PathHumanReadable(), "/" );
103}
104
105
110{
111 BOOST_CHECK_EQUAL( m_linear.size(), 3 );
112
113 BOOST_CHECK_EQUAL( m_linear.at( 0 ), &m_sheets[0] );
114 BOOST_CHECK_EQUAL( m_linear.at( 1 ), &m_sheets[1] );
115 BOOST_CHECK_EQUAL( m_linear.at( 2 ), &m_sheets[2] );
116
117 BOOST_CHECK_EQUAL( m_linear.Last(), &m_sheets[2] );
118 BOOST_CHECK_EQUAL( m_linear.LastScreen(), nullptr );
119
120 // don't know what the uuids will be, but we know the format: /<8-4-4-4-12>/<8-4-4-4-12>/
122 KI_TEST::IsUUIDPathWithLevels, ( m_linear.PathAsString().ToStdString() )( 2 ) );
123
124 // Sheet0 is the root sheet and isn't in the path
125 BOOST_CHECK_EQUAL( m_linear.PathHumanReadable(), "/Sheet1/Sheet2/" );
126}
127
128
130{
131 SCH_SHEET_PATH otherEmpty;
132
133 BOOST_CHECK( m_empty_path == otherEmpty );
134
135 BOOST_CHECK( m_empty_path != m_linear );
136}
137
138
139BOOST_AUTO_TEST_CASE( SheetListGetOrdinalPath )
140{
141 // The "complex_hierarchy" test project has a root sheet with two sheets that reference the
142 // same file.
143 std::unique_ptr<SCHEMATIC> schematic;
144 wxFileName fn( wxString::Format( wxS( "%snetlists/complex_hierarchy" ),
146 wxS( "complex_hierarchy" ), FILEEXT::ProjectFileExtension );
147
148 schematic.reset( EESCHEMA_HELPERS::LoadSchematic( fn.GetFullPath(), false, false, nullptr ) );
149
150 SCH_SHEET_LIST hierarchy = schematic->Hierarchy();
151 BOOST_CHECK_EQUAL( hierarchy.size(), 3 );
152
153 // A null pointer should always result in an empty return value.
154 BOOST_CHECK( !hierarchy.GetOrdinalPath( nullptr ) );
155
156 // The root sheet is a single instance. It's always ordinal.
157 BOOST_CHECK( hierarchy.GetOrdinalPath( schematic->RootScreen() ).value() == hierarchy.at( 0 ) );
158
159 // The shared schematic with the lowest page number is the ordinal sheet path.
160 SCH_SHEET* sheet = hierarchy.at( 1 ).Last();
161 BOOST_CHECK( hierarchy.GetOrdinalPath( sheet->GetScreen() ).value() == hierarchy.at( 1 ) );
162
163 // The shared sheet with a higher page number is not the ordinal sheet path.
164 sheet = hierarchy.at( 2 ).Last();
165 BOOST_CHECK( hierarchy.GetOrdinalPath( sheet->GetScreen() ).value() == hierarchy.at( 1 ) );
166}
167
168
172BOOST_AUTO_TEST_CASE( SheetPathPageProperties )
173{
174 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), wxEmptyString );
175
176 // Add new instance to sheet object.
177 // BOOST_CHECK( m_linear.Last()->AddInstance( m_linear.Path() ) );
178 // m_linear.SetPageNumber( "1" );
179 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "1" );
180 // m_linear.SetPageNumber( "i" );
181 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "i" );
182}
183
184
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true)
Holds all the data relating to one schematic.
Definition schematic.h:88
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...
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:116
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.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(Empty)
Declare the test suite.
BOOST_CHECK_PREDICATE(ArePolylineEndPointsNearCircle,(chain)(c.m_geom.m_center_point)(radius)(accuracy+epsilon))
BOOST_CHECK_EQUAL(result, "25.4")
Test utilities for timestamps.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
Definition of file extensions used in Kicad.