20#include <boost/test/unit_test.hpp>
27#include <wx/filename.h>
34wxString makeTempTargetPath(
const wxString& aTag )
36 wxString tempDir = wxFileName::GetTempDir();
37 wxString leaf = wxString::Format( wxT(
"kicad-lockfile-%s-%ld.kicad_pcb" ), aTag,
38 static_cast<long>( wxGetLocalTimeMillis().GetValue() ) );
39 return tempDir + wxFileName::GetPathSeparator() + leaf;
43wxString lockPathFor(
const wxString& aTargetPath )
45 wxFileName fn( aTargetPath );
48 return fn.GetFullPath();
52void writeRaw(
const wxString& aPath,
const std::string& aContent )
54 wxFFile fp( aPath, wxT(
"wb" ) );
57 if( !aContent.empty() )
58 BOOST_REQUIRE( fp.Write( aContent.data(), aContent.size() ) == aContent.size() );
71 wxString target = makeTempTargetPath( wxT(
"fresh" ) );
72 wxString lockPath = lockPathFor( target );
78 BOOST_CHECK( lock.
Valid() );
79 BOOST_CHECK( lock.
Locked() );
80 BOOST_CHECK( wxFileName::FileExists( lockPath ) );
83 BOOST_CHECK( !wxFileName::FileExists( lockPath ) );
89 wxString target = makeTempTargetPath( wxT(
"foreign" ) );
90 wxString lockPath = lockPathFor( target );
92 writeRaw( lockPath, R
"({"username":"someone-else","hostname":"another-host"})" );
96 BOOST_CHECK( !lock.Valid() );
102 wxRemoveFile( lockPath );
109 wxString target = makeTempTargetPath( wxT(
"empty" ) );
110 wxString lockPath = lockPathFor( target );
112 writeRaw( lockPath,
"" );
116 BOOST_CHECK( !lock.
Valid() );
119 BOOST_CHECK( lock.
Valid() );
122 BOOST_CHECK( !wxFileName::FileExists( lockPath ) );
129 wxString target = makeTempTargetPath( wxT(
"corrupt" ) );
130 wxString lockPath = lockPathFor( target );
132 writeRaw( lockPath, R
"({"username":"partia)" );
136 BOOST_CHECK( !lock.Valid() );
142 if( wxFileName::FileExists( lockPath ) )
143 wxRemoveFile( lockPath );
bool OverrideLock(bool aRemoveOnRelease=true)
Force the lock, overwriting the data that existed already.
static const std::string LockFileExtension
static const std::string LockFilePrefix
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(AcquireFreshLock)
BOOST_CHECK_EQUAL(result, "25.4")
Definition of file extensions used in Kicad.