33#include <wx/filename.h>
38namespace fs = std::filesystem;
46 m_tempDir = fs::temp_directory_path() /
"kicad_project_file_test";
70 fs::path oldProjectDir = m_tempDir /
"old_project";
71 fs::path newProjectDir = m_tempDir /
"new_project";
72 fs::create_directories( oldProjectDir );
73 fs::create_directories( newProjectDir );
75 wxString oldProjectPath = wxString( oldProjectDir.string() ) + wxFileName::GetPathSeparator()
83 sheetInfo.
name = wxS(
"old_project" );
84 sheetInfo.
filename = wxS(
"old_project.kicad_sch" );
91 customSheet.
name = wxS(
"CustomSheet" );
92 customSheet.
filename = wxS(
"custom_sheet.kicad_sch" );
97 projectFile.
SaveAs( wxString( newProjectDir.string() ), wxS(
"new_project" ) );
100 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
102 BOOST_REQUIRE_EQUAL( sheets.size(), 2 );
129 fs::path projectDir = m_tempDir /
"my_project";
130 fs::create_directories( projectDir );
133 std::string proContent = R
"({
135 "filename": "my_project.kicad_pro",
139 "top_level_sheets": [
141 "uuid": "00000000-0000-0000-0000-000000000000",
143 "filename": "default.kicad_sch"
149 fs::path proPath = projectDir / "my_project.kicad_pro";
150 std::ofstream proFile( proPath );
151 proFile << proContent;
155 fs::path schPath = projectDir /
"my_project.kicad_sch";
156 std::ofstream schFile( schPath );
157 schFile <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
158 schFile <<
" (uuid \"12345678-1234-1234-1234-123456789abc\")";
159 schFile <<
" (paper \"A4\"))";
164 settingsManager.
LoadProject( wxString( proPath.string() ) );
169 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
171 BOOST_REQUIRE_EQUAL( sheets.size(), 1 );
186 fs::path projectDir = m_tempDir /
"valid_project";
187 fs::create_directories( projectDir );
190 std::string proContent = R
"({
192 "filename": "valid_project.kicad_pro",
196 "top_level_sheets": [
198 "uuid": "00000000-0000-0000-0000-000000000000",
199 "name": "valid_project",
200 "filename": "valid_project.kicad_sch"
206 fs::path proPath = projectDir / "valid_project.kicad_pro";
207 std::ofstream proFile( proPath );
208 proFile << proContent;
212 fs::path schPath = projectDir /
"valid_project.kicad_sch";
213 std::ofstream schFile( schPath );
214 schFile <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
215 schFile <<
" (uuid \"12345678-1234-1234-1234-123456789abc\")";
216 schFile <<
" (paper \"A4\"))";
220 settingsManager.
LoadProject( wxString( proPath.string() ) );
225 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
227 BOOST_REQUIRE_EQUAL( sheets.size(), 1 );
250 fs::path projectDir = m_tempDir /
"jobset_project";
251 fs::create_directories( projectDir );
253 std::string proContent = R
"({
255 "filename": "jobset_project.kicad_pro",
260 fs::path proPath = projectDir / "jobset_project.kicad_pro";
261 std::ofstream proFile( proPath );
262 proFile << proContent;
265 wxFileName absFn( wxString( proPath.string() ) );
266 absFn.MakeAbsolute();
267 wxString absPath = absFn.GetFullPath();
282 BOOST_CHECK( afterReload == heldProject );
~PROJECT_FILE_TEST_FIXTURE()
PROJECT_FILE_TEST_FIXTURE()
The backing store for a PROJECT, in JSON format.
bool SaveAs(const wxString &aDirectory, const wxString &aFile)
std::vector< TOP_LEVEL_SHEET_INFO > & GetTopLevelSheets()
Container for project specific data.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
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_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(SaveAsUpdatesTopLevelSheetNames)
Test that SaveAs updates top-level sheet names when they match the old project name.
BOOST_CHECK_EQUAL(result, "25.4")
Definition of file extensions used in Kicad.