KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_legacy_load.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
29#include <boost/test/unit_test.hpp>
30#include <eeschema_test_utils.h>
31
33#include <sch_screen.h>
34#include <sch_sheet.h>
35#include <sch_symbol.h>
36#include <schematic.h>
37#include <kiid.h>
38#include <sch_file_versions.h>
41
42#include <wx/filename.h>
43#include <wx/log.h>
44#include <wx/stdpaths.h>
45#include <sch_sheet_path.h>
46#include <trace_helpers.h>
47
48
49BOOST_AUTO_TEST_SUITE( LegacyLoad )
50
51
52BOOST_AUTO_TEST_CASE( TestLoadWithLogging )
53{
54 SETTINGS_MANAGER settingsManager;
55
56 // Create a temporary project
57 wxString tempDir = wxStandardPaths::Get().GetTempDir();
58 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxT("test_legacy.kicad_pro");
59
60 settingsManager.LoadProject( projectPath.ToStdString() );
61 std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr );
62 PROJECT* project = &settingsManager.Prj();
63 schematic->SetProject( project );
64
65 // Load the legacy hierarchical schematic
66 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
67 fn.AppendDir( "legacy_hierarchy" );
68 fn.SetName( "legacy_hierarchy" );
70 wxString mainFile = fn.GetFullPath();
71
72 BOOST_TEST_MESSAGE( "=== Loading schematic: " << mainFile.ToStdString() );
73 BOOST_REQUIRE( wxFileExists( mainFile ) );
74
76 SCH_SHEET* loadedSheet = nullptr;
77
78 BOOST_CHECK_NO_THROW( loadedSheet = io.LoadSchematicFile( mainFile, schematic.get() ) );
79 BOOST_REQUIRE( loadedSheet != nullptr );
80
81 BOOST_TEST_MESSAGE( "=== Setting root sheet" );
82 schematic->SetRoot( loadedSheet );
83
84 BOOST_TEST_MESSAGE( "=== Building hierarchy" );
85 schematic->RefreshHierarchy();
86 SCH_SHEET_LIST hierarchy = schematic->Hierarchy();
87
88 BOOST_TEST_MESSAGE( "=== Checking for missing symbol instances" );
89 hierarchy.CheckForMissingSymbolInstances( project->GetProjectName() );
90
91 BOOST_TEST_MESSAGE( "\n=== Testing symbol reference retrieval ===" );
92
93 // Test getting references for symbols on the first sub-sheet
94 if( hierarchy.size() >= 2 )
95 {
96 const SCH_SHEET_PATH& subSheetPath = hierarchy[1];
97 BOOST_TEST_MESSAGE( "Sheet path [1]: " << subSheetPath.PathHumanReadable( false ).ToStdString() );
98 BOOST_TEST_MESSAGE( "Sheet path KIID: " << subSheetPath.Path().AsString().ToStdString() );
99
100 if( subSheetPath.LastScreen() )
101 {
102 int count = 0;
103 for( SCH_ITEM* item : subSheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
104 {
105 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
106 wxString ref = symbol->GetRef( &subSheetPath, false );
107
108 BOOST_TEST_MESSAGE( " Symbol " << symbol->m_Uuid.AsString().ToStdString()
109 << " ref: " << ref.ToStdString() );
110
111 if( ++count >= 5 )
112 break; // Just test first 5 symbols
113 }
114 }
115 }
116
117 BOOST_TEST_MESSAGE( "=== Test completed ===" );
118}
119
120
const KIID m_Uuid
Definition eda_item.h:516
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:241
wxString AsString() const
Definition kiid.cpp:356
wxString AsString() const
Definition kiid.cpp:246
Container for project specific data.
Definition project.h:65
A SCH_IO derivation for loading schematic files using the new s-expression file format.
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:117
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
void CheckForMissingSymbolInstances(const wxString &aProjectName)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false) const
Return the sheet path in a human readable form made from the sheet names.
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
Schematic symbol object.
Definition sch_symbol.h:75
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
static const std::string KiCadSchematicFileExtension
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
wxLogTrace helper definitions.
@ SCH_SYMBOL_T
Definition typeinfo.h:176