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
32// Code under test
33#include <sch_sheet_path.h>
34
35#include <sch_sheet.h>
36
37#include <sstream>
38
40{
41public:
43 {
44 for( unsigned i = 0; i < 4; ++i )
45 {
46 m_sheets.emplace_back( nullptr, VECTOR2I( i, i ) );
47
48 std::ostringstream ss;
49 ss << "Sheet" << i;
50 m_sheets[i].GetFields()[SHEETNAME].SetText( ss.str() );
51 }
52
53 // 0->1->2
57 }
58
60
66
68 std::vector<SCH_SHEET> m_sheets;
69};
70
71
75BOOST_FIXTURE_TEST_SUITE( SchSheetPath, TEST_SCH_SHEET_PATH_FIXTURE )
76
77
78
82{
83 BOOST_CHECK_EQUAL( m_empty_path.size(), 0 );
84
85 BOOST_CHECK_THROW( m_empty_path.at( 0 ), std::out_of_range );
86
87 // Sheet paths with no SCH_SCHEET object are illegal.
88 // CHECK_WX_ASSERT( m_empty_path.GetPageNumber() );
89
90 // These accessors return nullptr when empty (i.e. they don't crash)
91 BOOST_CHECK_EQUAL( m_empty_path.Last(), nullptr );
92 BOOST_CHECK_EQUAL( m_empty_path.LastScreen(), nullptr );
93
94 BOOST_CHECK_EQUAL( m_empty_path.PathAsString(), "/" );
95 BOOST_CHECK_EQUAL( m_empty_path.PathHumanReadable(), "/" );
96}
97
98
103{
104 BOOST_CHECK_EQUAL( m_linear.size(), 3 );
105
106 BOOST_CHECK_EQUAL( m_linear.at( 0 ), &m_sheets[0] );
107 BOOST_CHECK_EQUAL( m_linear.at( 1 ), &m_sheets[1] );
108 BOOST_CHECK_EQUAL( m_linear.at( 2 ), &m_sheets[2] );
109
110 BOOST_CHECK_EQUAL( m_linear.Last(), &m_sheets[2] );
111 BOOST_CHECK_EQUAL( m_linear.LastScreen(), nullptr );
112
113 // don't know what the uuids will be, but we know the format: /<8-4-4-4-12>/<8-4-4-4-12>/
114 BOOST_CHECK_PREDICATE(
115 KI_TEST::IsUUIDPathWithLevels, ( m_linear.PathAsString().ToStdString() )( 2 ) );
116
117 // Sheet0 is the root sheet and isn't in the path
118 BOOST_CHECK_EQUAL( m_linear.PathHumanReadable(), "/Sheet1/Sheet2/" );
119}
120
121
123{
124 SCH_SHEET_PATH otherEmpty;
125
126 BOOST_CHECK( m_empty_path == otherEmpty );
127
128 BOOST_CHECK( m_empty_path != m_linear );
129}
130
131
135BOOST_AUTO_TEST_CASE( SheetPathPageProperties )
136{
137 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), wxEmptyString );
138
139 // Add new instance to sheet object.
140 // BOOST_CHECK( m_linear.Last()->AddInstance( m_linear.Path() ) );
141 // m_linear.SetPageNumber( "1" );
142 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "1" );
143 // m_linear.SetPageNumber( "i" );
144 // BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "i" );
145}
146
147
148BOOST_AUTO_TEST_SUITE_END()
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.
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.
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_CHECK(box.ClosestPointTo(VECTOR2D(0, 0))==VECTOR2D(1, 2))
Test suite for KiCad math code.
BOOST_AUTO_TEST_CASE(Empty)
Declare the test suite.
Test utilities for timestamps.
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588