Use temporary wxConfig for persistence unit tests
This requires slightly more work, but ensures that we don't leave any traces of running the tests in the system registry or file system, as we can just call DeleteAll() on the config object after finishing with it.
This commit is contained in:
@@ -30,57 +30,66 @@
|
||||
|
||||
#define FRAME_OPTIONS_PREFIX PO_PREFIX "/Window/frame"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// local helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Create the frame used for testing.
|
||||
static wxFrame* CreatePersistenceTestFrame()
|
||||
{
|
||||
wxFrame* const frame = new wxFrame(wxTheApp->GetTopWindow(), wxID_ANY, "wxTest");
|
||||
frame->SetName("frame");
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// tests themselves
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]")
|
||||
{
|
||||
// Create the objects to persist or restore.
|
||||
wxFrame* const frame = new wxFrame(wxTheApp->GetTopWindow(), wxID_ANY, "wxTest");
|
||||
frame->SetName("frame");
|
||||
|
||||
const wxPoint pos(100, 150);
|
||||
const wxSize size(450, 350);
|
||||
|
||||
SECTION("Save")
|
||||
// Save the frame geometry.
|
||||
{
|
||||
wxFrame* const frame = CreatePersistenceTestFrame();
|
||||
|
||||
// Set the geometry before saving.
|
||||
frame->SetPosition(pos);
|
||||
frame->SetSize(size);
|
||||
|
||||
wxPersistenceManager::Get().Register(frame);
|
||||
CHECK(wxPersistenceManager::Get().Register(frame));
|
||||
|
||||
// Destroy the frame immediately.
|
||||
// Destroy the frame immediately, i.e. don't use Destroy() here.
|
||||
delete frame;
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val;
|
||||
int val = -1;
|
||||
|
||||
const wxConfigBase* const conf = wxConfig::Get();
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/x", &val));
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/x", &val));
|
||||
CHECK(pos.x == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/y", &val));
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/y", &val));
|
||||
CHECK(pos.y == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/w", &val));
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/w", &val));
|
||||
CHECK(size.x == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/h", &val));
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/h", &val));
|
||||
CHECK(size.y == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/Iconized", &val));
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/Iconized", &val));
|
||||
CHECK(0 == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/Maximized", &val));
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/Maximized", &val));
|
||||
CHECK(0 == val);
|
||||
}
|
||||
|
||||
SECTION("Restore")
|
||||
// Now try recreating the frame using the restored values.
|
||||
{
|
||||
EnableCleanup();
|
||||
wxFrame* const frame = CreatePersistenceTestFrame();
|
||||
|
||||
// Test that the object was registered and restored.
|
||||
CHECK(wxPersistenceManager::Get().RegisterAndRestore(frame));
|
||||
@@ -91,5 +100,7 @@ TEST_CASE_METHOD(PersistenceTests, "wxPersistTLW", "[persist][tlw]")
|
||||
CHECK(size.y == frame->GetSize().GetHeight());
|
||||
CHECK(!frame->IsMaximized());
|
||||
CHECK(!frame->IsIconized());
|
||||
|
||||
delete frame;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user