2020-10-18 20:30:37 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-11-23 13:05:28 +00:00
|
|
|
* Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2020-10-18 20:30:37 +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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2020-10-18 20:30:37 +00:00
|
|
|
#include "eeschema_test_utils.h"
|
|
|
|
|
|
|
|
#include <sch_sheet_path.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
|
2022-04-11 20:49:26 +00:00
|
|
|
class TEST_SCH_SHEET_LIST_FIXTURE : public KI_TEST::SCHEMATIC_TEST_FIXTURE
|
2020-10-18 20:30:37 +00:00
|
|
|
{
|
2022-04-11 20:49:26 +00:00
|
|
|
protected:
|
2022-06-12 03:39:13 +00:00
|
|
|
wxFileName GetSchematicPath( const wxString& aRelativePath ) override;
|
2020-10-18 20:30:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
wxFileName TEST_SCH_SHEET_LIST_FIXTURE::GetSchematicPath( const wxString& aRelativePath )
|
2021-05-01 22:24:09 +00:00
|
|
|
{
|
|
|
|
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
|
|
|
|
fn.AppendDir( "netlists" );
|
|
|
|
|
|
|
|
wxString path = fn.GetFullPath();
|
|
|
|
path += aRelativePath + wxT( "." ) + KiCadSchematicFileExtension;
|
|
|
|
|
|
|
|
return wxFileName( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
BOOST_FIXTURE_TEST_SUITE( SchSheetList, TEST_SCH_SHEET_LIST_FIXTURE )
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( TestSheetListPageProperties )
|
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
LoadSchematic( "complex_hierarchy/complex_hierarchy" );
|
2020-10-18 20:30:37 +00:00
|
|
|
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
|
|
|
|
|
|
|
|
BOOST_CHECK( sheets.AllSheetPageNumbersEmpty() );
|
|
|
|
|
|
|
|
sheets.SetInitialPageNumbers();
|
|
|
|
|
|
|
|
// The root sheet should now be page 1.
|
2021-12-06 12:47:18 +00:00
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
|
2020-10-18 20:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-01 22:24:09 +00:00
|
|
|
BOOST_AUTO_TEST_CASE( TestEditPageNumbersInSharedDesign )
|
|
|
|
{
|
|
|
|
BOOST_TEST_CONTEXT( "Read Sub-Sheet, prior to modification" )
|
|
|
|
{
|
|
|
|
// Check the Sub Sheet has the expected page numbers
|
2022-06-12 03:39:13 +00:00
|
|
|
LoadSchematic( "complex_hierarchy_shared/ampli_ht/ampli_ht" );
|
2021-05-01 22:24:09 +00:00
|
|
|
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( sheets.size(), 2 );
|
2021-12-06 12:47:18 +00:00
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" );
|
2021-05-01 22:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_TEST_CONTEXT( "Read Root Sheet, prior to modification" )
|
|
|
|
{
|
|
|
|
// Check the parent sheet has the expected page numbers
|
2022-06-12 03:39:13 +00:00
|
|
|
LoadSchematic( "complex_hierarchy_shared/complex_hierarchy" );
|
2021-05-01 22:24:09 +00:00
|
|
|
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( sheets.size(), 5 );
|
2021-12-06 12:47:18 +00:00
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "1" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "2" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "3" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "4" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "5" );
|
2021-05-01 22:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_TEST_CONTEXT( "Modify page numbers in root sheet" )
|
|
|
|
{
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
|
|
|
|
|
2021-06-09 19:32:58 +00:00
|
|
|
// Amend Page numbers
|
2021-12-06 12:47:18 +00:00
|
|
|
sheets.at( 0 ).SetPageNumber( "A" );
|
|
|
|
sheets.at( 1 ).SetPageNumber( "B" );
|
|
|
|
sheets.at( 2 ).SetPageNumber( "C" );
|
|
|
|
sheets.at( 3 ).SetPageNumber( "D" );
|
|
|
|
sheets.at( 4 ).SetPageNumber( "E" );
|
2021-05-01 22:24:09 +00:00
|
|
|
|
|
|
|
// Save and reload
|
2022-11-23 13:05:28 +00:00
|
|
|
wxFileName rootFn = GetSchematicPath( "complex_hierarchy_shared/complex_hierarchy" );
|
|
|
|
wxFileName prjFn = rootFn;
|
2021-05-01 22:24:09 +00:00
|
|
|
|
2022-11-23 13:05:28 +00:00
|
|
|
prjFn.SetExt( ProjectFileExtension );
|
2022-11-23 00:08:08 +00:00
|
|
|
|
2022-11-23 13:05:28 +00:00
|
|
|
rootFn.AppendDir( "temp" );
|
|
|
|
BOOST_CHECK( rootFn.Mkdir() );
|
|
|
|
|
|
|
|
wxFileName newPrjFn = rootFn;
|
|
|
|
newPrjFn.SetExt( ProjectFileExtension );
|
|
|
|
BOOST_CHECK( wxCopyFile( prjFn.GetFullPath(), newPrjFn.GetFullPath() ) );
|
|
|
|
|
|
|
|
m_pi->Save( rootFn.GetFullPath(), &m_schematic.Root(), &m_schematic );
|
|
|
|
|
|
|
|
wxFileName subSheetFn = rootFn;
|
|
|
|
BOOST_CHECK( subSheetFn.AppendDir( "ampli_ht" ) );
|
|
|
|
BOOST_CHECK( subSheetFn.Mkdir() );
|
|
|
|
|
|
|
|
subSheetFn.SetName( "ampli_ht" );
|
|
|
|
m_pi->Save( subSheetFn.GetFullPath(), sheets.at( 1 ).Last(), &m_schematic );
|
|
|
|
|
|
|
|
subSheetFn.SetName( "filter" );
|
|
|
|
m_pi->Save( subSheetFn.GetFullPath(), sheets.at( 2 ).Last(), &m_schematic );
|
|
|
|
|
|
|
|
LoadSchematic( "complex_hierarchy_shared/temp/complex_hierarchy" );
|
|
|
|
|
|
|
|
sheets = m_schematic.GetSheets();
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( sheets.size(), 5 );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "A" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "B" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 2 ).GetPageNumber(), "C" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 3 ).GetPageNumber(), "D" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 4 ).GetPageNumber(), "E" );
|
2021-05-01 22:24:09 +00:00
|
|
|
|
|
|
|
// Cleanup
|
2022-11-23 13:05:28 +00:00
|
|
|
BOOST_CHECK( wxRemoveFile( subSheetFn.GetFullPath() ) );
|
|
|
|
subSheetFn.SetName( "ampli_ht" );
|
|
|
|
BOOST_CHECK( wxRemoveFile( subSheetFn.GetFullPath() ) );
|
|
|
|
BOOST_CHECK( subSheetFn.Rmdir() );
|
|
|
|
BOOST_CHECK( wxRemoveFile( newPrjFn.GetFullPath() ) );
|
|
|
|
BOOST_CHECK( wxRemoveFile( rootFn.GetFullPath() ) );
|
|
|
|
BOOST_CHECK( rootFn.Rmdir() );
|
2021-05-01 22:24:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_TEST_CONTEXT( "Read Sub-Sheet, after modification" )
|
|
|
|
{
|
|
|
|
// Check the Sub Sheet has the expected page numbers
|
|
|
|
// (This should not have been modified after editing the root sheet)
|
2022-06-12 03:39:13 +00:00
|
|
|
LoadSchematic( "complex_hierarchy_shared/ampli_ht/ampli_ht" );
|
2021-05-01 22:24:09 +00:00
|
|
|
|
|
|
|
SCH_SHEET_LIST sheets = m_schematic.GetSheets();
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( sheets.size(), 2 );
|
2021-12-06 12:47:18 +00:00
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 0 ).GetPageNumber(), "i" );
|
|
|
|
BOOST_CHECK_EQUAL( sheets.at( 1 ).GetPageNumber(), "ii" );
|
2021-05-01 22:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 20:30:37 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|