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