39#include <wx/filename.h>
44#include <system_error>
46namespace fs = std::filesystem;
68 m_tempDir( fs::temp_directory_path() /
"kicad_settings_manager_test" )
83 wxString
Path(
const std::string& aName )
const
85 return wxString( (
m_tempDir / aName ).
string() );
159 fs::path themePath = m_tempDir /
"theme.json";
161 auto readFile = [](
const fs::path& aPath )
163 std::ifstream in( aPath );
164 std::stringstream buffer;
165 buffer << in.rdbuf();
172 nlohmann::json js = nlohmann::json::parse(
readFile( themePath ) );
174 js.erase(
"gerbview" );
176 std::ofstream out( themePath );
177 out << std::setw( 2 ) << js << std::endl;
181 std::string before =
readFile( themePath );
186 BOOST_CHECK( !cfg.
SaveToFile( wxEmptyString ) );
194 wxString projectPath = Path(
"spelling.kicad_pro" );
197 std::ofstream out( projectPath.ToStdString() );
198 out << R
"({"meta": {"filename": "spelling.kicad_pro", "version": 3}})";
214 const nlohmann::json& aOwner )
216 fs::path pro = aDir / ( aName +
".kicad_pro" );
219 std::ofstream out( pro.string() );
220 out << R
"({"meta": {"filename": ")" << aName << R"(.kicad_pro", "version": 3}})";
224 lck << aOwner.dump();
226 return wxString( pro.string() );
232 nlohmann::json owner;
233 owner[
"username"] = std::string( wxGetUserId().mb_str() );
234 owner[
"hostname"] = std::string( wxGetHostName().mb_str() );
235 owner[
"token"] =
"0123456789abcdef0123456789abcdef";
252 BOOST_CHECK( !
project->IsReadOnly() );
253 BOOST_CHECK(
project->GetProjectLock() !=
nullptr );
261 nlohmann::json owner;
262 owner[
"username"] =
"someone-else";
263 owner[
"hostname"] =
"another-host";
274 BOOST_CHECK(
project->IsReadOnly() );
290 bool created =
false;
301 BOOST_CHECK(
project->IsReadOnly() );
307 std::string(
"0123456789abcdef0123456789abcdef" ) );
338 fs::path pro = m_tempDir /
"unversioned.kicad_pro";
341 std::ofstream out( pro.string() );
345 wxString projectPath = wxString( pro.string() );
357 BOOST_CHECK_MESSAGE( kiway.
LockHeldWhenNotified(),
"The project must own its lock before the change is announced" );
359 BOOST_CHECK(
project->GetProjectLock() !=
nullptr );
Color settings are a bit different than most of the settings objects in that there can be more than o...
FLUSH_TEST_SETTINGS(const wxString &aFullPath)
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
std::vector< PARAM_BASE * > m_params
The list of parameters (owned by this object)
JSON_SETTINGS(const wxString &aFilename, SETTINGS_LOC aLocation, int aSchemaVersion)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
KIWAY(int aCtlBits, wxFrame *aTop=nullptr)
Advisory lock over a file, taken by writing a sibling lock file and holding an exclusive lock on it f...
static wxString LockPathFor(const wxString &aFilename)
Container for project specific data.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
COMMON_SETTINGS * GetCommonSettings() const
Retrieve the common settings shared by all applications.
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
void SetKiway(KIWAY *aKiway)
Associate this setting manager with the given Kiway.
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
void FlushAndRelease(JSON_SETTINGS *aSettings, bool aSave=true)
If the given settings object is registered, save it to disk and unregister it.
bool m_lockHeldWhenNotified
void ProjectChanged() override
Calls ProjectChanged() on all KIWAY_PLAYERs.
bool LockHeldWhenNotified() const
SETTINGS_MANAGER & m_manager
TEST_KIWAY(SETTINGS_MANAGER &aManager)
static std::string ToStdString(const wxString &aStr)
#define KFCTL_STANDALONE
Running as a standalone Top.
static bool readFile(const wxString &aFileName, wxString &aOut, size_t aLimit=0)
Read a file into aOut.
wxString Path(const std::string &aName) const
~SETTINGS_MANAGER_FIXTURE()
SETTINGS_MANAGER_FIXTURE()
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(LoadFlushesDirtySettings)
static wxString seedLockedProject(const fs::path &aDir, const std::string &aName, const nlohmann::json &aOwner)
static nlohmann::json selfOwnerRecord()
BOOST_CHECK_EQUAL(result, "25.4")