29#include <wx/filename.h>
35namespace fs = std::filesystem;
43 m_tempDir = fs::temp_directory_path() /
"kicad_project_file_test";
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 );
72 wxString oldProjectPath = wxString( oldProjectDir.string() ) + wxFileName::GetPathSeparator()
80 sheetInfo.
name = wxS(
"old_project" );
81 sheetInfo.
filename = wxS(
"old_project.kicad_sch" );
88 customSheet.
name = wxS(
"CustomSheet" );
89 customSheet.
filename = wxS(
"custom_sheet.kicad_sch" );
94 projectFile.
SaveAs( wxString( newProjectDir.string() ), wxS(
"new_project" ) );
97 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
99 BOOST_REQUIRE_EQUAL( sheets.size(), 2 );
126 fs::path projectDir = m_tempDir /
"my_project";
127 fs::create_directories( projectDir );
130 std::string proContent = R
"({
132 "filename": "my_project.kicad_pro",
136 "top_level_sheets": [
138 "uuid": "00000000-0000-0000-0000-000000000000",
140 "filename": "default.kicad_sch"
146 fs::path proPath = projectDir / "my_project.kicad_pro";
147 std::ofstream proFile( proPath );
148 proFile << proContent;
152 fs::path schPath = projectDir /
"my_project.kicad_sch";
153 std::ofstream schFile( schPath );
154 schFile <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
155 schFile <<
" (uuid \"12345678-1234-1234-1234-123456789abc\")";
156 schFile <<
" (paper \"A4\"))";
161 settingsManager.
LoadProject( wxString( proPath.string() ) );
166 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
168 BOOST_REQUIRE_EQUAL( sheets.size(), 1 );
183 fs::path projectDir = m_tempDir /
"valid_project";
184 fs::create_directories( projectDir );
187 std::string proContent = R
"({
189 "filename": "valid_project.kicad_pro",
193 "top_level_sheets": [
195 "uuid": "00000000-0000-0000-0000-000000000000",
196 "name": "valid_project",
197 "filename": "valid_project.kicad_sch"
203 fs::path proPath = projectDir / "valid_project.kicad_pro";
204 std::ofstream proFile( proPath );
205 proFile << proContent;
209 fs::path schPath = projectDir /
"valid_project.kicad_sch";
210 std::ofstream schFile( schPath );
211 schFile <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
212 schFile <<
" (uuid \"12345678-1234-1234-1234-123456789abc\")";
213 schFile <<
" (paper \"A4\"))";
217 settingsManager.
LoadProject( wxString( proPath.string() ) );
222 const std::vector<TOP_LEVEL_SHEET_INFO>& sheets = projectFile.
GetTopLevelSheets();
224 BOOST_REQUIRE_EQUAL( sheets.size(), 1 );
247 fs::path projectDir = m_tempDir /
"jobset_project";
248 fs::create_directories( projectDir );
250 std::string proContent = R
"({
252 "filename": "jobset_project.kicad_pro",
257 fs::path proPath = projectDir / "jobset_project.kicad_pro";
258 std::ofstream proFile( proPath );
259 proFile << proContent;
262 wxFileName absFn( wxString( proPath.string() ) );
263 absFn.MakeAbsolute();
264 wxString absPath = absFn.GetFullPath();
279 BOOST_CHECK( afterReload == heldProject );
297 fs::path projADir = m_tempDir /
"proj_a";
298 fs::path projBDir = m_tempDir /
"proj_b";
299 fs::create_directories( projADir );
300 fs::create_directories( projBDir );
305 const std::string projectName =
"shared_name";
307 auto writeProject = [&](
const fs::path& aDir )
309 std::string content =
"{\n"
311 " \"filename\": \"" + projectName +
".kicad_pro\",\n"
314 " \"schematic\": {\n"
315 " \"top_level_sheets\": [\n"
317 " \"uuid\": \"00000000-0000-0000-0000-000000000000\",\n"
318 " \"name\": \"" + projectName +
"\",\n"
319 " \"filename\": \"" + projectName +
".kicad_sch\"\n"
324 std::ofstream out( aDir / ( projectName +
".kicad_pro" ) );
328 std::ofstream sch( aDir / ( projectName +
".kicad_sch" ) );
329 sch <<
"(kicad_sch (version 20231120) (generator \"eeschema\") (generator_version \"9.99\")";
330 sch <<
" (uuid \"12345678-1234-1234-1234-123456789abc\") (paper \"A4\"))";
334 fs::path proAPath = projADir / ( projectName +
".kicad_pro" );
335 fs::path proBPath = projBDir / ( projectName +
".kicad_pro" );
336 writeProject( projADir );
337 writeProject( projBDir );
356 auto readFile = [](
const fs::path& aPath )
358 std::ifstream in( aPath );
359 std::stringstream buffer;
360 buffer << in.rdbuf();
365 std::string savedB =
readFile( proBPath );
367 "unloaded project must be saved to its own directory" );
370 std::string savedA =
readFile( proAPath );
372 "active project's file must not receive the unloaded project's data" );
~PROJECT_FILE_TEST_FIXTURE()
PROJECT_FILE_TEST_FIXTURE()
The backing store for a PROJECT, in JSON format.
std::map< wxString, wxString > m_TextVars
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.
virtual PROJECT_FILE & GetProjectFile() const
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.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
static const std::string ProjectFileExtension
static bool readFile(const wxString &aFileName, wxString &aOut, size_t aLimit=0)
Read a file into aOut.
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_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
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.