KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_issue24360_root_sheetname.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
20// Regression tests for https://gitlab.com/kicad/code/kicad/-/issues/24360
21//
22// ${SHEETNAME} expanded to an empty string on the root sheet when the schematic
23// was loaded through the CLI/headless path (e.g. `kicad-cli sch export pdf`).
24// EESCHEMA_HELPERS::LoadSchematic now mirrors the interactive editor and names
25// the root sheet so the title-block text variable resolves correctly.
26
28
29#include <memory>
30
31#include <eeschema_helpers.h>
32#include <locale_io.h>
33#include <sch_sheet.h>
34#include <sch_sheet_path.h>
35#include <schematic.h>
36
37
38namespace
39{
40
41void checkRootSheetName( const wxString& aSchPath, bool aForceDefaultProject,
42 const wxString& aExpected )
43{
45
46 std::unique_ptr<SCHEMATIC> sch(
47 EESCHEMA_HELPERS::LoadSchematic( aSchPath, true, aForceDefaultProject ) );
48 BOOST_REQUIRE( sch != nullptr );
49
50 SCH_SHEET* root = sch->GetTopLevelSheet();
51 BOOST_REQUIRE( root != nullptr );
52 BOOST_CHECK_EQUAL( root->GetName(), aExpected );
53
54 SCH_SHEET_LIST hierarchy = sch->Hierarchy();
55 BOOST_REQUIRE_EQUAL( hierarchy.size(), 1u );
56
57 wxString token = wxS( "SHEETNAME" );
58 BOOST_REQUIRE( sch->ResolveTextVar( &hierarchy.at( 0 ), &token, 0 ) );
59 BOOST_CHECK_EQUAL( token, aExpected );
60}
61
62} // namespace
63
64
65// No .kicad_pro alongside the schematic -> headless loader falls back to the translated "Root".
66BOOST_AUTO_TEST_CASE( Issue24360_RootSheetNameFallback )
67{
68 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() )
69 + wxS( "issue24360/issue24360.kicad_sch" );
70
71 checkRootSheetName( schPath, /* aForceDefaultProject */ true, _( "Root" ) );
72}
73
74
75// .kicad_pro carries a schematic.top_level_sheets entry whose filename matches the loaded
76// schematic. The headless loader must honor that display name instead of overwriting with "Root".
77BOOST_AUTO_TEST_CASE( Issue24360_RootSheetNameFromProject )
78{
79 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() )
80 + wxS( "issue24360_project/issue24360_project.kicad_sch" );
81
82 checkRootSheetName( schPath, /* aForceDefaultProject */ false,
83 wxS( "Custom Display Name" ) );
84}
static SCHEMATIC * LoadSchematic(const wxString &aFileName, bool aSetActive, bool aForceDefaultProject, PROJECT *aProject=nullptr, bool aCalculateConnectivity=true)
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition locale_io.h:37
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
wxString GetName() const
Definition sch_sheet.h:136
#define _(s)
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
std::vector< FAB_LAYER_COLOR > dummy
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_CASE(Issue24360_RootSheetNameFallback)
BOOST_CHECK_EQUAL(result, "25.4")