95 CreateTemplateStructure(
97 {
"issue22289-dir",
"issue22289-backups",
"other-dir" },
98 {
"issue22289.kicad_pro",
"issue22289.kicad_sch",
"issue22289-dir/test.kicad_sym" } );
100 fs::path templatePath = m_tempDir /
"issue22289";
101 fs::path destPath = m_tempDir /
"myproject";
102 fs::create_directories( destPath );
107 wxFileName newProjectPath;
108 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
109 newProjectPath.SetName( wxS(
"myproject" ) );
110 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
112 std::vector<wxFileName> destFiles;
115 bool foundRenamedDir =
false;
116 bool foundRenamedFile =
false;
117 bool foundOtherDir =
false;
119 for(
const wxFileName& destFile : destFiles )
121 wxString fullPath = destFile.GetFullPath();
123 if( fullPath.Contains( wxS(
"myproject-dir" ) ) )
124 foundRenamedDir =
true;
126 if( fullPath.Contains( wxS(
"issue22289-dir" ) ) )
127 BOOST_FAIL(
"Directory should have been renamed from issue22289-dir to myproject-dir" );
129 if( fullPath.Contains( wxS(
"other-dir" ) ) )
130 foundOtherDir =
true;
132 if( destFile.GetName() == wxS(
"myproject" ) && destFile.GetExt() == wxS(
"kicad_pro" ) )
133 foundRenamedFile =
true;
136 BOOST_CHECK_MESSAGE( foundRenamedDir,
"Should find myproject-dir in destination files" );
137 BOOST_CHECK_MESSAGE( foundRenamedFile,
"Should find myproject.kicad_pro in destination files" );
138 BOOST_CHECK_MESSAGE( foundOtherDir,
"Should preserve other-dir (not matching template name)" );
144 CreateTemplateStructure(
146 {
"testtemplate-lib",
"testtemplate" },
147 {
"testtemplate.kicad_pro",
"testtemplate-lib/component.kicad_sym",
148 "testtemplate/nested.txt" } );
150 fs::path templatePath = m_tempDir /
"testtemplate";
151 fs::path destPath = m_tempDir /
"newproject";
152 fs::create_directories( destPath );
157 wxFileName newProjectPath;
158 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
159 newProjectPath.SetName( wxS(
"newproject" ) );
160 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
165 BOOST_CHECK_MESSAGE(
result,
"CreateProject should succeed: " + errorMsg.ToStdString() );
167 BOOST_CHECK( fs::exists( destPath /
"newproject.kicad_pro" ) );
168 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" ) );
169 BOOST_CHECK( fs::exists( destPath /
"newproject-lib" /
"component.kicad_sym" ) );
171 BOOST_CHECK_MESSAGE( !fs::exists( destPath /
"testtemplate-lib" ),
172 "Old directory name should not exist" );
179 CreateTemplateStructure(
"mytemplate", {
"mytemplate" },
180 {
"mytemplate.kicad_pro",
"mytemplate/subfile.txt" } );
182 fs::path templatePath = m_tempDir /
"mytemplate";
183 fs::path destPath = m_tempDir /
"finalproject";
184 fs::create_directories( destPath );
189 wxFileName newProjectPath;
190 newProjectPath.SetPath( wxString::FromUTF8( destPath.string() ) );
191 newProjectPath.SetName( wxS(
"finalproject" ) );
192 newProjectPath.SetExt( wxS(
"kicad_pro" ) );
194 std::vector<wxFileName> destFiles;
197 bool foundExactRenamedDir =
false;
199 for(
const wxFileName& destFile : destFiles )
201 wxString fullPath = destFile.GetFullPath();
203 if( fullPath.Contains( wxS(
"/finalproject/finalproject/" ) )
204 || fullPath.Contains( wxS(
"\\finalproject\\finalproject\\" ) ) )
206 foundExactRenamedDir =
true;
209 if( fullPath.Contains( wxS(
"/finalproject/mytemplate/" ) )
210 || fullPath.Contains( wxS(
"\\finalproject\\mytemplate\\" ) ) )
212 BOOST_FAIL(
"Exact match directory should be renamed from mytemplate to finalproject" );
216 BOOST_CHECK_MESSAGE( foundExactRenamedDir,
"Should find renamed subdirectory finalproject" );
wxString result
Test unit parsing edge cases and error handling.