2017-12-14 18:43:24 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/persistence/testpersistence.h
|
|
|
|
// Purpose: Fixture for wxPersistentObject unit tests
|
|
|
|
// Author: wxWidgets Team
|
|
|
|
// Created: 2017-08-23
|
|
|
|
// Copyright: (c) 2017 wxWidgets Team
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef WX_TESTS_PERSIST_TESTPERSISTENCE_H
|
|
|
|
#define WX_TESTS_PERSIST_TESTPERSISTENCE_H
|
|
|
|
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/config.h"
|
2017-12-15 08:43:43 -05:00
|
|
|
#include "wx/persist.h"
|
2017-12-14 18:43:24 -05:00
|
|
|
|
|
|
|
#define PO_PREFIX "/Persistent_Options"
|
|
|
|
|
|
|
|
class PersistenceTests
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PersistenceTests()
|
2017-12-15 08:43:43 -05:00
|
|
|
: m_managerOld(&wxPersistenceManager::Get())
|
2017-12-14 18:43:24 -05:00
|
|
|
{
|
2017-12-15 08:43:43 -05:00
|
|
|
// Install our custom manager, using custom config object, for the test
|
|
|
|
// duration.
|
|
|
|
wxPersistenceManager::Set(m_manager);
|
2017-12-14 18:43:24 -05:00
|
|
|
}
|
|
|
|
|
2017-12-15 08:43:43 -05:00
|
|
|
// Access the config object used for storing the settings.
|
|
|
|
const wxConfigBase& GetConfig() const
|
2017-12-14 18:43:24 -05:00
|
|
|
{
|
2017-12-15 08:43:43 -05:00
|
|
|
return *m_manager.GetConfig();
|
2017-12-14 18:43:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
~PersistenceTests()
|
|
|
|
{
|
2017-12-15 08:43:43 -05:00
|
|
|
wxPersistenceManager::Set(*m_managerOld);
|
2017-12-14 18:43:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2017-12-15 08:43:43 -05:00
|
|
|
class TestPersistenceManager : public wxPersistenceManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestPersistenceManager()
|
|
|
|
: m_config("PersistenceTests", "wxWidgets")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~TestPersistenceManager() wxOVERRIDE
|
|
|
|
{
|
|
|
|
m_config.DeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxConfigBase* GetConfig() const wxOVERRIDE
|
|
|
|
{
|
|
|
|
return const_cast<wxConfig*>(&m_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxConfig m_config;
|
|
|
|
};
|
|
|
|
|
|
|
|
wxPersistenceManager *m_managerOld;
|
|
|
|
TestPersistenceManager m_manager;
|
2017-12-14 18:43:24 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // WX_TESTS_PERSIST_TESTPERSISTENCE_H
|