93 CreateTemplateStructure(
95 {
"issue22289-dir",
"issue22289-backups",
"other-dir" },
96 {
"issue22289.kicad_pro",
"issue22289.kicad_sch",
"issue22289-dir/test.kicad_sym" } );
98 fs::path templatePath = m_tempDir /
"issue22289";
99 fs::path destPath = m_tempDir /
"myproject";
100 fs::create_directories( destPath );
105 wxFileName newProjectPath;
106 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
107 newProjectPath.SetName( wxS(
"myproject" ) );
108 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
110 std::vector<wxFileName> destFiles;
113 bool foundRenamedDir =
false;
114 bool foundRenamedFile =
false;
115 bool foundOtherDir =
false;
117 for(
const wxFileName& destFile : destFiles )
119 wxString fullPath = destFile.GetFullPath();
121 if( fullPath.Contains( wxS(
"myproject-dir" ) ) )
122 foundRenamedDir =
true;
124 if( fullPath.Contains( wxS(
"issue22289-dir" ) ) )
125 BOOST_FAIL(
"Directory should have been renamed from issue22289-dir to myproject-dir" );
127 if( fullPath.Contains( wxS(
"other-dir" ) ) )
128 foundOtherDir =
true;
130 if( destFile.GetName() == wxS(
"myproject" ) && destFile.GetExt() == wxS(
"kicad_pro" ) )
131 foundRenamedFile =
true;
134 BOOST_CHECK_MESSAGE( foundRenamedDir,
"Should find myproject-dir in destination files" );
135 BOOST_CHECK_MESSAGE( foundRenamedFile,
"Should find myproject.kicad_pro in destination files" );
136 BOOST_CHECK_MESSAGE( foundOtherDir,
"Should preserve other-dir (not matching template name)" );
142 CreateTemplateStructure(
144 {
"testtemplate-lib",
"testtemplate" },
145 {
"testtemplate.kicad_pro",
"testtemplate-lib/component.kicad_sym",
146 "testtemplate/nested.txt" } );
148 fs::path templatePath = m_tempDir /
"testtemplate";
149 fs::path destPath = m_tempDir /
"newproject";
150 fs::create_directories( destPath );
155 wxFileName newProjectPath;
156 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
157 newProjectPath.SetName( wxS(
"newproject" ) );
158 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
163 BOOST_CHECK_MESSAGE(
result,
"CreateProject should succeed: " + errorMsg.ToStdString() );
165 BOOST_CHECK( fs::exists( destPath /
"newproject.kicad_pro" ) );
166 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" ) );
167 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" /
"component.kicad_sym" ) );
169 BOOST_CHECK_MESSAGE( !fs::exists( destPath /
"testtemplate-lib" ),
170 "Old directory name should not exist" );
177 CreateTemplateStructure(
"mytemplate", {
"mytemplate" },
178 {
"mytemplate.kicad_pro",
"mytemplate/subfile.txt" } );
180 fs::path templatePath = m_tempDir /
"mytemplate";
181 fs::path destPath = m_tempDir /
"finalproject";
182 fs::create_directories( destPath );
187 wxFileName newProjectPath;
188 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
189 newProjectPath.SetName( wxS(
"finalproject" ) );
190 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
192 std::vector<wxFileName> destFiles;
195 bool foundExactRenamedDir =
false;
197 for(
const wxFileName& destFile : destFiles )
199 wxString fullPath = destFile.GetFullPath();
201 if( fullPath.Contains( wxS(
"/finalproject/finalproject/" ) )
202 || fullPath.Contains( wxS(
"\\finalproject\\finalproject\\" ) ) )
204 foundExactRenamedDir =
true;
207 if( fullPath.Contains( wxS(
"/finalproject/mytemplate/" ) )
208 || fullPath.Contains( wxS(
"\\finalproject\\mytemplate\\" ) ) )
210 BOOST_FAIL(
"Exact match directory should be renamed from mytemplate to finalproject" );
214 BOOST_CHECK_MESSAGE( foundExactRenamedDir,
"Should find renamed subdirectory finalproject" );
224 fs::path noMetaPath = m_tempDir /
"no_meta_template";
225 fs::create_directories( noMetaPath );
227 std::ofstream f( ( noMetaPath /
"no_meta_template.kicad_pro" ).
string() );
235 BOOST_CHECK_MESSAGE( !title->IsEmpty(),
"Template without meta dir should have an error title" );
240 BOOST_CHECK( *title == *title2 );
247 fs::path tmplPath = m_tempDir /
"meta_no_html";
248 fs::create_directories( tmplPath /
"meta" );
250 std::ofstream f( ( tmplPath /
"meta_no_html.kicad_pro" ).
string() );
258 BOOST_CHECK_MESSAGE( !title->IsEmpty(),
259 "Template with meta dir but no info.html should have an error title" );
268 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_seed" ).
string() );
271 BOOST_REQUIRE_MESSAGE( seeded.IsOk(),
"Seeding the default template should succeed" );
275 fs::path
expected = m_tempDir /
"default_seed" /
"default";
276 BOOST_CHECK( fs::exists(
expected ) );
277 BOOST_CHECK( fs::exists(
expected /
"meta" /
"info.html" ) );
278 BOOST_CHECK( fs::exists(
expected /
"default.kicad_pro" ) );
284 BOOST_CHECK_MESSAGE( tmpl.
GetError().IsEmpty(),
285 "Seeded default template should load without error: " + tmpl.
GetError() );
290 BOOST_CHECK( !title->IsEmpty() );
296 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_load" ).
string() );
301 fs::path destPath = m_tempDir /
"fromdefault";
302 fs::create_directories( destPath );
306 wxFileName newProjectPath;
307 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
308 newProjectPath.SetName( wxS(
"fromdefault" ) );
309 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
313 BOOST_REQUIRE_MESSAGE( tmpl.
CreateProject( newProjectPath, &errorMsg ),
314 "CreateProject should succeed: " + errorMsg.ToStdString() );
318 BOOST_CHECK_MESSAGE( mgr.
LoadProject( newProjectPath.GetFullPath() ),
319 "A project made from the default template must load" );
335 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_idempotent" ).
string() );
341 fs::path proFile = m_tempDir /
"default_idempotent" /
"default" /
"default.kicad_pro";
343 std::ofstream f( proFile.string() );
344 f <<
"{\"custom\":true}";
351 std::ifstream in( proFile.string() );
352 std::stringstream buffer;
353 buffer << in.rdbuf();
361 CreateTemplateStructure(
"rotemplate", {
"rotemplate-lib" },
362 {
"rotemplate.kicad_pro",
"rotemplate.kicad_sch",
"rotemplate-lib/component.kicad_sym" } );
364 fs::path templatePath = m_tempDir /
"rotemplate";
365 fs::path destPath = m_tempDir /
"rwproject";
366 fs::create_directories( destPath );
368 const std::vector<fs::path> templateFiles = { templatePath /
"rotemplate.kicad_pro",
369 templatePath /
"rotemplate.kicad_sch",
370 templatePath /
"rotemplate-lib" /
"component.kicad_sym" };
372 for(
const fs::path& file : templateFiles )
374 fs::permissions( file, fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write,
375 fs::perm_options::remove );
380 wxFileName newProjectPath;
381 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
382 newProjectPath.SetName( wxS(
"rwproject" ) );
383 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
386 bool created = tmpl.
CreateProject( newProjectPath, &errorMsg );
390 for(
const fs::path& file : templateFiles )
391 fs::permissions( file, fs::perms::owner_write, fs::perm_options::add );
393 BOOST_REQUIRE_MESSAGE( created,
"CreateProject failed: " + errorMsg.ToStdString() );
395 const std::vector<fs::path> projectFiles = { destPath /
"rwproject.kicad_pro", destPath /
"rwproject.kicad_sch",
396 destPath /
"rwproject-lib" /
"component.kicad_sym" };
398 for(
const fs::path& file : projectFiles )
400 wxFileName fn( wxString::FromUTF8( file.string() ) );
402 BOOST_REQUIRE_MESSAGE( fn.FileExists(), file.string() +
" was not created" );
403 BOOST_CHECK_MESSAGE( fn.IsFileWritable(), file.string() +
" is read only" );
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")