KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_project_file.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
32
33#include <filesystem>
34
35namespace fs = std::filesystem;
36
37
39{
40public:
42 {
43 m_tempDir = fs::temp_directory_path() / "kicad_project_file_test";
44 fs::remove_all( m_tempDir );
45 fs::create_directories( m_tempDir );
46 }
47
49 {
50 fs::remove_all( m_tempDir );
51 }
52
53 fs::path m_tempDir;
54};
55
56
57BOOST_FIXTURE_TEST_SUITE( ProjectFile, PROJECT_FILE_TEST_FIXTURE )
58
59
60
65BOOST_AUTO_TEST_CASE( SaveAsUpdatesTopLevelSheetNames )
66{
67 fs::path oldProjectDir = m_tempDir / "old_project";
68 fs::path newProjectDir = m_tempDir / "new_project";
69 fs::create_directories( oldProjectDir );
70 fs::create_directories( newProjectDir );
71
72 wxString oldProjectPath = wxString( oldProjectDir.string() ) + wxFileName::GetPathSeparator()
73 + wxS( "old_project." ) + FILEEXT::ProjectFileExtension;
74
75 PROJECT_FILE projectFile( oldProjectPath );
76
77 // Add a top-level sheet with name matching the project name
78 TOP_LEVEL_SHEET_INFO sheetInfo;
79 sheetInfo.uuid = KIID();
80 sheetInfo.name = wxS( "old_project" );
81 sheetInfo.filename = wxS( "old_project.kicad_sch" );
82
83 projectFile.GetTopLevelSheets().push_back( sheetInfo );
84
85 // Add another sheet with a custom name that should NOT be changed
86 TOP_LEVEL_SHEET_INFO customSheet;
87 customSheet.uuid = KIID();
88 customSheet.name = wxS( "CustomSheet" );
89 customSheet.filename = wxS( "custom_sheet.kicad_sch" );
90
91 projectFile.GetTopLevelSheets().push_back( customSheet );
92
93 // Perform SaveAs to new project
94 projectFile.SaveAs( wxString( newProjectDir.string() ), wxS( "new_project" ) );
95
96 // Verify the sheet name was updated
97 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.GetTopLevelSheets();
98
99 BOOST_REQUIRE_EQUAL( sheets.size(), 2 );
100
101 // First sheet's name should be updated to match the new project name
102 BOOST_CHECK_EQUAL( sheets[0].name, wxS( "new_project" ) );
103
104 // First sheet's filename should also be updated
105 BOOST_CHECK_EQUAL( sheets[0].filename, wxS( "new_project.kicad_sch" ) );
106
107 // Second sheet's custom name should remain unchanged
108 BOOST_CHECK_EQUAL( sheets[1].name, wxS( "CustomSheet" ) );
109
110 // Second sheet's filename should remain unchanged
111 BOOST_CHECK_EQUAL( sheets[1].filename, wxS( "custom_sheet.kicad_sch" ) );
112}
113
114
const char * name
Definition kiid.h:49
The backing store for a PROJECT, in JSON format.
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
std::vector< TOP_LEVEL_SHEET_INFO > & GetTopLevelSheets()
static const std::string ProjectFileExtension
Information about a top-level schematic sheet.
KIID uuid
Unique identifier for the sheet.
wxString name
Display name for the sheet.
wxString filename
Relative path to the sheet file.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")
Definition of file extensions used in Kicad.