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, see <https://www.gnu.org/licenses/>.
18 */
19
24
25#include <boost/test/unit_test.hpp>
26#include <eeschema_test_utils.h>
27
29#include <sch_screen.h>
30#include <sch_sheet.h>
31#include <sch_symbol.h>
32#include <schematic.h>
33#include <kiid.h>
34#include <sch_file_versions.h>
37
38#include <wx/filename.h>
39#include <wx/log.h>
40#include <wx/stdpaths.h>
41#include <sch_sheet_path.h>
42#include <trace_helpers.h>
43
44
45BOOST_AUTO_TEST_SUITE( LegacyLoad )
46
47
48BOOST_AUTO_TEST_CASE( TestLoadWithLogging )
49{
50 SETTINGS_MANAGER settingsManager;
51
52 // Create a temporary project
53 wxString tempDir = wxStandardPaths::Get().GetTempDir();
54 wxString projectPath = tempDir + wxFileName::GetPathSeparator() + wxT("test_legacy.kicad_pro");
55
56 settingsManager.LoadProject( projectPath.ToStdString() );
57 std::unique_ptr<SCHEMATIC> schematic = std::make_unique<SCHEMATIC>( nullptr );
58 PROJECT* project = &settingsManager.Prj();
59 schematic->SetProject( project );
60
61 // Load the legacy hierarchical schematic
62 wxFileName fn( KI_TEST::GetEeschemaTestDataDir() );
63 fn.AppendDir( "legacy_hierarchy" );
64 fn.SetName( "legacy_hierarchy" );
66 wxString mainFile = fn.GetFullPath();
67
68 BOOST_TEST_MESSAGE( "=== Loading schematic: " << mainFile.ToStdString() );
69 BOOST_REQUIRE( wxFileExists( mainFile ) );
70
72 SCH_SHEET* loadedSheet = nullptr;
73
74 BOOST_CHECK_NO_THROW( loadedSheet = io.LoadSchematicFile( mainFile, schematic.get() ) );
75 BOOST_REQUIRE( loadedSheet != nullptr );
76
77 BOOST_TEST_MESSAGE( "=== Setting root sheet" );
78 schematic->Reset();
79 SCH_SHEET* defaultSheet = schematic->GetTopLevelSheet( 0 );
80 schematic->AddTopLevelSheet( loadedSheet );
81 schematic->RemoveTopLevelSheet( defaultSheet );
82 delete defaultSheet;
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:531
EE_TYPE OfType(KICAD_T aType) const
Definition sch_rtree.h:221
wxString AsString() const
Definition kiid.cpp:393
wxString AsString() const
Definition kiid.cpp:242
Container for project specific data.
Definition project.h:62
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:162
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
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...
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
SCH_SCREEN * LastScreen()
wxString PathHumanReadable(bool aUseShortRootName=true, bool aStripTrailingSeparator=false, bool aEscapeSheetNames=false) const
Return the sheet path in a human readable form made from the sheet names.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
Schematic symbol object.
Definition sch_symbol.h:69
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("\n=== Real-World Polygon PIP Benchmark ===\n"<< formatTable(table))
wxLogTrace helper definitions.
@ SCH_SYMBOL_T
Definition typeinfo.h:169