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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 */
20
21// Regression tests for https://gitlab.com/kicad/code/kicad/-/issues/24360
22//
23// ${SHEETNAME} expanded to an empty string on the root sheet when the schematic
24// was loaded through the CLI/headless path (e.g. `kicad-cli sch export pdf`).
25// EESCHEMA_HELPERS::LoadSchematic now mirrors the interactive editor and names
26// the root sheet so the title-block text variable resolves correctly.
27
29
30#include <memory>
31
32#include <eeschema_helpers.h>
33#include <locale_io.h>
34#include <sch_sheet.h>
35#include <sch_sheet_path.h>
36#include <schematic.h>
37
38
39namespace
40{
41
42void checkRootSheetName( const wxString& aSchPath, bool aForceDefaultProject,
43 const wxString& aExpected )
44{
46
47 std::unique_ptr<SCHEMATIC> sch(
48 EESCHEMA_HELPERS::LoadSchematic( aSchPath, true, aForceDefaultProject ) );
49 BOOST_REQUIRE( sch != nullptr );
50
51 SCH_SHEET* root = sch->GetTopLevelSheet();
52 BOOST_REQUIRE( root != nullptr );
53 BOOST_CHECK_EQUAL( root->GetName(), aExpected );
54
55 SCH_SHEET_LIST hierarchy = sch->Hierarchy();
56 BOOST_REQUIRE_EQUAL( hierarchy.size(), 1u );
57
58 wxString token = wxS( "SHEETNAME" );
59 BOOST_REQUIRE( sch->ResolveTextVar( &hierarchy.at( 0 ), &token, 0 ) );
60 BOOST_CHECK_EQUAL( token, aExpected );
61}
62
63} // namespace
64
65
66// No .kicad_pro alongside the schematic -> headless loader falls back to the translated "Root".
67BOOST_AUTO_TEST_CASE( Issue24360_RootSheetNameFallback )
68{
69 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() )
70 + wxS( "issue24360/issue24360.kicad_sch" );
71
72 checkRootSheetName( schPath, /* aForceDefaultProject */ true, _( "Root" ) );
73}
74
75
76// .kicad_pro carries a schematic.top_level_sheets entry whose filename matches the loaded
77// schematic. The headless loader must honor that display name instead of overwriting with "Root".
78BOOST_AUTO_TEST_CASE( Issue24360_RootSheetNameFromProject )
79{
80 wxString schPath = wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() )
81 + wxS( "issue24360_project/issue24360_project.kicad_sch" );
82
83 checkRootSheetName( schPath, /* aForceDefaultProject */ false,
84 wxS( "Custom Display Name" ) );
85}
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:41
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:48
wxString GetName() const
Definition sch_sheet.h:140
#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")