37namespace fs = std::filesystem;
45 m_tempDir = fs::temp_directory_path() /
"kicad_project_file_test";
69 fs::path oldProjectDir = m_tempDir /
"old_project";
70 fs::path newProjectDir = m_tempDir /
"new_project";
71 fs::create_directories( oldProjectDir );
72 fs::create_directories( newProjectDir );
74 wxString oldProjectPath = wxString( oldProjectDir.string() ) + wxFileName::GetPathSeparator()
82 sheetInfo.
name = wxS(
"old_project" );
83 sheetInfo.
filename = wxS(
"old_project.kicad_sch" );
90 customSheet.
name = wxS(
"CustomSheet" );
91 customSheet.
filename = wxS(
"custom_sheet.kicad_sch" );
96 projectFile.
SaveAs( wxString( newProjectDir.string() ), wxS(
"new_project" ) );
99 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
101 BOOST_REQUIRE_EQUAL( sheets.size(), 2 );
128 fs::path projectDir = m_tempDir /
"my_project";
129 fs::create_directories( projectDir );
132 std::string proContent = R
"({
134 "filename": "my_project.kicad_pro",
138 "top_level_sheets": [
140 "uuid": "00000000-0000-0000-0000-000000000000",
142 "filename": "default.kicad_sch"
148 fs::path proPath = projectDir / "my_project.kicad_pro";
149 std::ofstream proFile( proPath );
150 proFile << proContent;
154 fs::path schPath = projectDir /
"my_project.kicad_sch";
155 std::ofstream schFile( schPath );
156 schFile <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
157 schFile <<
" (uuid \"12345678-1234-1234-1234-123456789abc\")";
158 schFile <<
" (paper \"A4\"))";
163 settingsManager.
LoadProject( wxString( proPath.string() ) );
168 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
170 BOOST_REQUIRE_EQUAL( sheets.size(), 1 );
185 fs::path projectDir = m_tempDir /
"valid_project";
186 fs::create_directories( projectDir );
189 std::string proContent = R
"({
191 "filename": "valid_project.kicad_pro",
195 "top_level_sheets": [
197 "uuid": "00000000-0000-0000-0000-000000000000",
198 "name": "valid_project",
199 "filename": "valid_project.kicad_sch"
205 fs::path proPath = projectDir / "valid_project.kicad_pro";
206 std::ofstream proFile( proPath );
207 proFile << proContent;
211 fs::path schPath = projectDir /
"valid_project.kicad_sch";
212 std::ofstream schFile( schPath );
213 schFile <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
214 schFile <<
" (uuid \"12345678-1234-1234-1234-123456789abc\")";
215 schFile <<
" (paper \"A4\"))";
219 settingsManager.
LoadProject( wxString( proPath.string() ) );
224 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
226 BOOST_REQUIRE_EQUAL( sheets.size(), 1 );
~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.
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 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_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.