92 CreateTemplateStructure(
94 {
"issue22289-dir",
"issue22289-backups",
"other-dir" },
95 {
"issue22289.kicad_pro",
"issue22289.kicad_sch",
"issue22289-dir/test.kicad_sym" } );
97 fs::path templatePath = m_tempDir /
"issue22289";
98 fs::path destPath = m_tempDir /
"myproject";
99 fs::create_directories( destPath );
104 wxFileName newProjectPath;
105 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
106 newProjectPath.SetName( wxS(
"myproject" ) );
107 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
109 std::vector<wxFileName> destFiles;
112 bool foundRenamedDir =
false;
113 bool foundRenamedFile =
false;
114 bool foundOtherDir =
false;
116 for(
const wxFileName& destFile : destFiles )
118 wxString fullPath = destFile.GetFullPath();
120 if( fullPath.Contains( wxS(
"myproject-dir" ) ) )
121 foundRenamedDir =
true;
123 if( fullPath.Contains( wxS(
"issue22289-dir" ) ) )
124 BOOST_FAIL(
"Directory should have been renamed from issue22289-dir to myproject-dir" );
126 if( fullPath.Contains( wxS(
"other-dir" ) ) )
127 foundOtherDir =
true;
129 if( destFile.GetName() == wxS(
"myproject" ) && destFile.GetExt() == wxS(
"kicad_pro" ) )
130 foundRenamedFile =
true;
133 BOOST_CHECK_MESSAGE( foundRenamedDir,
"Should find myproject-dir in destination files" );
134 BOOST_CHECK_MESSAGE( foundRenamedFile,
"Should find myproject.kicad_pro in destination files" );
135 BOOST_CHECK_MESSAGE( foundOtherDir,
"Should preserve other-dir (not matching template name)" );
141 CreateTemplateStructure(
143 {
"testtemplate-lib",
"testtemplate" },
144 {
"testtemplate.kicad_pro",
"testtemplate-lib/component.kicad_sym",
145 "testtemplate/nested.txt" } );
147 fs::path templatePath = m_tempDir /
"testtemplate";
148 fs::path destPath = m_tempDir /
"newproject";
149 fs::create_directories( destPath );
154 wxFileName newProjectPath;
155 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
156 newProjectPath.SetName( wxS(
"newproject" ) );
157 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
162 BOOST_CHECK_MESSAGE(
result,
"CreateProject should succeed: " + errorMsg.ToStdString() );
164 BOOST_CHECK( fs::exists( destPath /
"newproject.kicad_pro" ) );
165 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" ) );
166 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" /
"component.kicad_sym" ) );
168 BOOST_CHECK_MESSAGE( !fs::exists( destPath /
"testtemplate-lib" ),
169 "Old directory name should not exist" );
176 CreateTemplateStructure(
"mytemplate", {
"mytemplate" },
177 {
"mytemplate.kicad_pro",
"mytemplate/subfile.txt" } );
179 fs::path templatePath = m_tempDir /
"mytemplate";
180 fs::path destPath = m_tempDir /
"finalproject";
181 fs::create_directories( destPath );
186 wxFileName newProjectPath;
187 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
188 newProjectPath.SetName( wxS(
"finalproject" ) );
189 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
191 std::vector<wxFileName> destFiles;
194 bool foundExactRenamedDir =
false;
196 for(
const wxFileName& destFile : destFiles )
198 wxString fullPath = destFile.GetFullPath();
200 if( fullPath.Contains( wxS(
"/finalproject/finalproject/" ) )
201 || fullPath.Contains( wxS(
"\\finalproject\\finalproject\\" ) ) )
203 foundExactRenamedDir =
true;
206 if( fullPath.Contains( wxS(
"/finalproject/mytemplate/" ) )
207 || fullPath.Contains( wxS(
"\\finalproject\\mytemplate\\" ) ) )
209 BOOST_FAIL(
"Exact match directory should be renamed from mytemplate to finalproject" );
213 BOOST_CHECK_MESSAGE( foundExactRenamedDir,
"Should find renamed subdirectory finalproject" );
223 fs::path noMetaPath = m_tempDir /
"no_meta_template";
224 fs::create_directories( noMetaPath );
226 std::ofstream f( ( noMetaPath /
"no_meta_template.kicad_pro" ).
string() );
234 BOOST_CHECK_MESSAGE( !title->IsEmpty(),
"Template without meta dir should have an error title" );
239 BOOST_CHECK( *title == *title2 );
246 fs::path tmplPath = m_tempDir /
"meta_no_html";
247 fs::create_directories( tmplPath /
"meta" );
249 std::ofstream f( ( tmplPath /
"meta_no_html.kicad_pro" ).
string() );
257 BOOST_CHECK_MESSAGE( !title->IsEmpty(),
258 "Template with meta dir but no info.html should have an error title" );
267 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_seed" ).
string() );
270 BOOST_REQUIRE_MESSAGE( seeded.IsOk(),
"Seeding the default template should succeed" );
274 fs::path
expected = m_tempDir /
"default_seed" /
"default";
275 BOOST_CHECK( fs::exists(
expected ) );
276 BOOST_CHECK( fs::exists(
expected /
"meta" /
"info.html" ) );
277 BOOST_CHECK( fs::exists(
expected /
"default.kicad_pro" ) );
283 BOOST_CHECK_MESSAGE( tmpl.
GetError().IsEmpty(),
284 "Seeded default template should load without error: " + tmpl.
GetError() );
289 BOOST_CHECK( !title->IsEmpty() );
305 wxString baseDir = wxString::FromUTF8( ( m_tempDir /
"default_idempotent" ).
string() );
311 fs::path proFile = m_tempDir /
"default_idempotent" /
"default" /
"default.kicad_pro";
313 std::ofstream f( proFile.string() );
314 f <<
"{\"custom\":true}";
321 std::ifstream in( proFile.string() );
322 std::stringstream buffer;
323 buffer << in.rdbuf();
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")