20#include <boost/test/unit_test.hpp>
28#include <wx/filename.h>
30#include <wx/wfstream.h>
31#include <wx/zipstrm.h>
49wxString makeProjectDir(
const wxString& aTag )
51 wxString dir = wxFileName::GetTempDir() + wxFileName::GetPathSeparator()
52 + wxString::Format( wxT(
"kicad-archiver-%s-%ld" ), aTag,
53 static_cast<long>( wxGetLocalTimeMillis().GetValue() ) );
55 BOOST_REQUIRE( wxFileName::Mkdir( dir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
60void writeFile(
const wxString& aPath,
const std::string& aContent )
62 wxFFile fp( aPath, wxT(
"wb" ) );
64 BOOST_REQUIRE( fp.Write( aContent.data(), aContent.size() ) == aContent.size() );
70bool makeUnreadable(
const wxString& aPath )
72 if( chmod( aPath.fn_str(), 0 ) != 0 )
76 wxFFile probe( aPath, wxT(
"rb" ) );
77 return !probe.IsOpened();
81std::set<wxString> zipEntryNames(
const wxString& aZipPath )
83 std::set<wxString> names;
84 wxFFileInputStream stream( aZipPath );
89 wxZipInputStream
zip( stream );
91 while( wxZipEntry* entry =
zip.GetNextEntry() )
93 names.insert( entry->GetName() );
101void removeProjectDir(
const wxString& aDir,
const wxString& aUnreadable )
103 chmod( aUnreadable.fn_str(), 0600 );
104 wxFileName::Rmdir( aDir, wxPATH_RMDIR_RECURSIVE );
112 wxString dir = makeProjectDir( wxT(
"nodialog" ) );
113 wxString board = dir + wxFileName::GetPathSeparator() + wxT(
"board.kicad_pcb" );
114 wxString sheet = dir + wxFileName::GetPathSeparator() + wxT(
"sheet.kicad_sch" );
115 wxString
zip = dir + wxT(
".zip" );
117 writeFile( board,
"(kicad_pcb)\n" );
118 writeFile( sheet,
"(kicad_sch)\n" );
120 if( !makeUnreadable( sheet ) )
123 removeProjectDir( dir, sheet );
132 BOOST_REQUIRE_EQUAL( logOverride.
GetCount(), 0u );
135 removeProjectDir( dir, sheet );
141 wxString dir = makeProjectDir( wxT(
"quietreport" ) );
142 wxString board = dir + wxFileName::GetPathSeparator() + wxT(
"board.kicad_pcb" );
143 wxString sheet = dir + wxFileName::GetPathSeparator() + wxT(
"sheet.kicad_sch" );
144 wxString
zip = dir + wxT(
".zip" );
146 writeFile( board,
"(kicad_pcb)\n" );
147 writeFile( sheet,
"(kicad_sch)\n" );
149 if( !makeUnreadable( sheet ) )
152 removeProjectDir( dir, sheet );
165 removeProjectDir( dir, sheet );
171 wxString dir = makeProjectDir( wxT(
"partial" ) );
172 wxString board = dir + wxFileName::GetPathSeparator() + wxT(
"board.kicad_pcb" );
173 wxString sheet = dir + wxFileName::GetPathSeparator() + wxT(
"sheet.kicad_sch" );
174 wxString
zip = dir + wxT(
".zip" );
176 writeFile( board,
"(kicad_pcb)\n" );
177 writeFile( sheet,
"(kicad_sch)\n" );
179 if( !makeUnreadable( sheet ) )
182 removeProjectDir( dir, sheet );
191 std::set<wxString> names = zipEntryNames(
zip );
192 BOOST_REQUIRE( names.count( wxT(
"board.kicad_pcb" ) ) == 1 );
193 BOOST_REQUIRE( names.count( wxT(
"sheet.kicad_sch" ) ) == 0 );
196 removeProjectDir( dir, sheet );
A scoped application of a wxLog target that counts error-level messages.
unsigned GetCount() const
static bool Archive(const wxString &aSrcDir, const wxString &aDestFile, REPORTER &aReporter, bool aVerbose=true, bool aIncludeExtraFiles=false)
Create an archive of the project.
A wrapper for reporting to a wxString object.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
IbisParser parser & reporter
BOOST_AUTO_TEST_CASE(Archive_UnreadableFileRaisesNoSystemError)
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")