2019-04-23 08:18:15 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-12-06 12:47:18 +00:00
|
|
|
* Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.TXT for contributors.
|
2019-04-23 08:18:15 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2020-10-18 20:30:37 +00:00
|
|
|
* Test suite for #SCH_SHEET_PATH and #SCH_SHEET_LIST
|
2019-04-23 08:18:15 +00:00
|
|
|
*/
|
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// Code under test
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
|
2020-02-28 21:55:51 +00:00
|
|
|
#include "uuid_test_utils.h"
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
#include <sch_sheet.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
class TEST_SCH_SHEET_PATH_FIXTURE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_SCH_SHEET_PATH_FIXTURE()
|
|
|
|
{
|
|
|
|
for( unsigned i = 0; i < 4; ++i )
|
|
|
|
{
|
2020-05-13 02:00:37 +00:00
|
|
|
m_sheets.emplace_back( nullptr, wxPoint( i, i ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
std::ostringstream ss;
|
|
|
|
ss << "Sheet" << i;
|
2020-03-13 09:53:44 +00:00
|
|
|
m_sheets[i].GetFields()[SHEETNAME].SetText( ss.str() );
|
2019-04-23 08:18:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 0->1->2
|
|
|
|
m_linear.push_back( &m_sheets[0] );
|
|
|
|
m_linear.push_back( &m_sheets[1] );
|
|
|
|
m_linear.push_back( &m_sheets[2] );
|
|
|
|
}
|
|
|
|
|
|
|
|
SCH_SHEET_PATH m_empty_path;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We look at sheet 2 in the hierarchy:
|
|
|
|
* Sheets: 0 -> 1 -> 2
|
|
|
|
*/
|
|
|
|
SCH_SHEET_PATH m_linear;
|
|
|
|
|
|
|
|
/// handy store of SCH_SHEET objects
|
|
|
|
std::vector<SCH_SHEET> m_sheets;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare the test suite
|
|
|
|
*/
|
|
|
|
BOOST_FIXTURE_TEST_SUITE( SchSheetPath, TEST_SCH_SHEET_PATH_FIXTURE )
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check properties of an empty SCH_SHEET_PATH
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Empty )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL( m_empty_path.size(), 0 );
|
|
|
|
|
|
|
|
BOOST_CHECK_THROW( m_empty_path.at( 0 ), std::out_of_range );
|
|
|
|
|
2021-12-06 12:47:18 +00:00
|
|
|
// Sheet paths with no SCH_SCHEET object are illegal.
|
2021-12-08 18:36:23 +00:00
|
|
|
// CHECK_WX_ASSERT( m_empty_path.GetPageNumber() );
|
2021-12-06 12:47:18 +00:00
|
|
|
|
2019-04-23 08:18:15 +00:00
|
|
|
// These accessors return nullptr when empty (i.e. they don't crash)
|
|
|
|
BOOST_CHECK_EQUAL( m_empty_path.Last(), nullptr );
|
|
|
|
BOOST_CHECK_EQUAL( m_empty_path.LastScreen(), nullptr );
|
|
|
|
|
2020-02-22 21:39:59 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_empty_path.PathAsString(), "/" );
|
2019-04-23 08:18:15 +00:00
|
|
|
BOOST_CHECK_EQUAL( m_empty_path.PathHumanReadable(), "/" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check properties of a non-empty SCH_SHEET_PATH
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( NonEmpty )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.size(), 3 );
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.at( 0 ), &m_sheets[0] );
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.at( 1 ), &m_sheets[1] );
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.at( 2 ), &m_sheets[2] );
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.Last(), &m_sheets[2] );
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.LastScreen(), nullptr );
|
|
|
|
|
2020-02-22 21:47:44 +00:00
|
|
|
// don't know what the uuids will be, but we know the format: /<8-4-4-4-12>/<8-4-4-4-12>/
|
2019-04-23 08:18:15 +00:00
|
|
|
BOOST_CHECK_PREDICATE(
|
2020-02-22 21:47:44 +00:00
|
|
|
KI_TEST::IsUUIDPathWithLevels, ( m_linear.PathAsString().ToStdString() )( 2 ) );
|
2019-04-23 08:18:15 +00:00
|
|
|
|
|
|
|
// Sheet0 is the root sheet and isn't in the path
|
|
|
|
BOOST_CHECK_EQUAL( m_linear.PathHumanReadable(), "/Sheet1/Sheet2/" );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( Compare )
|
|
|
|
{
|
|
|
|
SCH_SHEET_PATH otherEmpty;
|
|
|
|
|
|
|
|
BOOST_CHECK( m_empty_path == otherEmpty );
|
|
|
|
|
|
|
|
BOOST_CHECK( m_empty_path != m_linear );
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test sheet path page number properties.
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( SheetPathPageProperties )
|
|
|
|
{
|
2021-12-08 18:36:23 +00:00
|
|
|
// BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), wxEmptyString );
|
2021-12-06 12:47:18 +00:00
|
|
|
|
|
|
|
// Add new instance to sheet object.
|
2021-12-08 18:36:23 +00:00
|
|
|
// BOOST_CHECK( m_linear.Last()->AddInstance( m_linear.Path() ) );
|
|
|
|
// m_linear.SetPageNumber( "1" );
|
|
|
|
// BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "1" );
|
|
|
|
// m_linear.SetPageNumber( "i" );
|
|
|
|
// BOOST_CHECK_EQUAL( m_linear.GetPageNumber(), "i" );
|
2020-10-18 20:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|