96 CreateTemplateStructure(
98 {
"issue22289-dir",
"issue22289-backups",
"other-dir" },
99 {
"issue22289.kicad_pro",
"issue22289.kicad_sch",
"issue22289-dir/test.kicad_sym" } );
101 fs::path templatePath = m_tempDir /
"issue22289";
102 fs::path destPath = m_tempDir /
"myproject";
103 fs::create_directories( destPath );
108 wxFileName newProjectPath;
109 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
110 newProjectPath.SetName( wxS(
"myproject" ) );
111 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
113 std::vector<wxFileName> destFiles;
116 bool foundRenamedDir =
false;
117 bool foundRenamedFile =
false;
118 bool foundOtherDir =
false;
120 for(
const wxFileName& destFile : destFiles )
122 wxString fullPath = destFile.GetFullPath();
124 if( fullPath.Contains( wxS(
"myproject-dir" ) ) )
125 foundRenamedDir =
true;
127 if( fullPath.Contains( wxS(
"issue22289-dir" ) ) )
128 BOOST_FAIL(
"Directory should have been renamed from issue22289-dir to myproject-dir" );
130 if( fullPath.Contains( wxS(
"other-dir" ) ) )
131 foundOtherDir =
true;
133 if( destFile.GetName() == wxS(
"myproject" ) && destFile.GetExt() == wxS(
"kicad_pro" ) )
134 foundRenamedFile =
true;
137 BOOST_CHECK_MESSAGE( foundRenamedDir,
"Should find myproject-dir in destination files" );
138 BOOST_CHECK_MESSAGE( foundRenamedFile,
"Should find myproject.kicad_pro in destination files" );
139 BOOST_CHECK_MESSAGE( foundOtherDir,
"Should preserve other-dir (not matching template name)" );
145 CreateTemplateStructure(
147 {
"testtemplate-lib",
"testtemplate" },
148 {
"testtemplate.kicad_pro",
"testtemplate-lib/component.kicad_sym",
149 "testtemplate/nested.txt" } );
151 fs::path templatePath = m_tempDir /
"testtemplate";
152 fs::path destPath = m_tempDir /
"newproject";
153 fs::create_directories( destPath );
158 wxFileName newProjectPath;
159 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
160 newProjectPath.SetName( wxS(
"newproject" ) );
161 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
166 BOOST_CHECK_MESSAGE(
result,
"CreateProject should succeed: " + errorMsg.ToStdString() );
168 BOOST_CHECK( fs::exists( destPath /
"newproject.kicad_pro" ) );
169 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" ) );
170 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" /
"component.kicad_sym" ) );
172 BOOST_CHECK_MESSAGE( !fs::exists( destPath /
"testtemplate-lib" ),
173 "Old directory name should not exist" );
180 CreateTemplateStructure(
"mytemplate", {
"mytemplate" },
181 {
"mytemplate.kicad_pro",
"mytemplate/subfile.txt" } );
183 fs::path templatePath = m_tempDir /
"mytemplate";
184 fs::path destPath = m_tempDir /
"finalproject";
185 fs::create_directories( destPath );
190 wxFileName newProjectPath;
191 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
192 newProjectPath.SetName( wxS(
"finalproject" ) );
193 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
195 std::vector<wxFileName> destFiles;
198 bool foundExactRenamedDir =
false;
200 for(
const wxFileName& destFile : destFiles )
202 wxString fullPath = destFile.GetFullPath();
204 if( fullPath.Contains( wxS(
"/finalproject/finalproject/" ) )
205 || fullPath.Contains( wxS(
"\\finalproject\\finalproject\\" ) ) )
207 foundExactRenamedDir =
true;
210 if( fullPath.Contains( wxS(
"/finalproject/mytemplate/" ) )
211 || fullPath.Contains( wxS(
"\\finalproject\\mytemplate\\" ) ) )
213 BOOST_FAIL(
"Exact match directory should be renamed from mytemplate to finalproject" );
217 BOOST_CHECK_MESSAGE( foundExactRenamedDir,
"Should find renamed subdirectory finalproject" );
227 fs::path noMetaPath = m_tempDir /
"no_meta_template";
228 fs::create_directories( noMetaPath );
230 std::ofstream f( ( noMetaPath /
"no_meta_template.kicad_pro" ).
string() );
238 BOOST_CHECK_MESSAGE( !title->IsEmpty(),
"Template without meta dir should have an error title" );
243 BOOST_CHECK( *title == *title2 );
250 fs::path tmplPath = m_tempDir /
"meta_no_html";
251 fs::create_directories( tmplPath /
"meta" );
253 std::ofstream f( ( tmplPath /
"meta_no_html.kicad_pro" ).
string() );
261 BOOST_CHECK_MESSAGE( !title->IsEmpty(),
262 "Template with meta dir but no info.html should have an error title" );
271 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_seed" ).
string() );
274 BOOST_REQUIRE_MESSAGE( seeded.IsOk(),
"Seeding the default template should succeed" );
278 fs::path
expected = m_tempDir /
"default_seed" /
"default";
279 BOOST_CHECK( fs::exists(
expected ) );
280 BOOST_CHECK( fs::exists(
expected /
"meta" /
"info.html" ) );
281 BOOST_CHECK( fs::exists(
expected /
"default.kicad_pro" ) );
287 BOOST_CHECK_MESSAGE( tmpl.
GetError().IsEmpty(),
288 "Seeded default template should load without error: " + tmpl.
GetError() );
293 BOOST_CHECK( !title->IsEmpty() );
299 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_load" ).
string() );
304 fs::path destPath = m_tempDir /
"fromdefault";
305 fs::create_directories( destPath );
309 wxFileName newProjectPath;
310 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
311 newProjectPath.SetName( wxS(
"fromdefault" ) );
312 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
316 BOOST_REQUIRE_MESSAGE( tmpl.
CreateProject( newProjectPath, &errorMsg ),
317 "CreateProject should succeed: " + errorMsg.ToStdString() );
321 BOOST_CHECK_MESSAGE( mgr.
LoadProject( newProjectPath.GetFullPath() ),
322 "A project made from the default template must load" );
338 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_idempotent" ).
string() );
344 fs::path proFile = m_tempDir /
"default_idempotent" /
"default" /
"default.kicad_pro";
346 std::ofstream f( proFile.string() );
347 f <<
"{\"custom\":true}";
354 std::ifstream in( proFile.string() );
355 std::stringstream buffer;
356 buffer << in.rdbuf();
364 CreateTemplateStructure(
"rotemplate", {
"rotemplate-lib" },
365 {
"rotemplate.kicad_pro",
"rotemplate.kicad_sch",
"rotemplate-lib/component.kicad_sym" } );
367 fs::path templatePath = m_tempDir /
"rotemplate";
368 fs::path destPath = m_tempDir /
"rwproject";
369 fs::create_directories( destPath );
371 const std::vector<fs::path> templateFiles = { templatePath /
"rotemplate.kicad_pro",
372 templatePath /
"rotemplate.kicad_sch",
373 templatePath /
"rotemplate-lib" /
"component.kicad_sym" };
375 for(
const fs::path& file : templateFiles )
377 fs::permissions( file, fs::perms::owner_write | fs::perms::group_write | fs::perms::others_write,
378 fs::perm_options::remove );
383 wxFileName newProjectPath;
384 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
385 newProjectPath.SetName( wxS(
"rwproject" ) );
386 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
389 bool created = tmpl.
CreateProject( newProjectPath, &errorMsg );
393 for(
const fs::path& file : templateFiles )
394 fs::permissions( file, fs::perms::owner_write, fs::perm_options::add );
396 BOOST_REQUIRE_MESSAGE( created,
"CreateProject failed: " + errorMsg.ToStdString() );
398 const std::vector<fs::path> projectFiles = { destPath /
"rwproject.kicad_pro", destPath /
"rwproject.kicad_sch",
399 destPath /
"rwproject-lib" /
"component.kicad_sym" };
401 for(
const fs::path& file : projectFiles )
403 wxFileName fn( wxString::FromUTF8( file.string() ) );
405 BOOST_REQUIRE_MESSAGE( fn.FileExists(), file.string() +
" was not created" );
406 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")