e3575d1f9c
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.
68 lines
1.6 KiB
C++
68 lines
1.6 KiB
C++
///////////////////////////////////////////////////////////////////////////////
|
|
// 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"
|
|
#include "wx/persist.h"
|
|
|
|
#define PO_PREFIX "/Persistent_Options"
|
|
|
|
class PersistenceTests
|
|
{
|
|
public:
|
|
PersistenceTests()
|
|
: m_managerOld(&wxPersistenceManager::Get())
|
|
{
|
|
// Install our custom manager, using custom config object, for the test
|
|
// duration.
|
|
wxPersistenceManager::Set(m_manager);
|
|
}
|
|
|
|
// Access the config object used for storing the settings.
|
|
const wxConfigBase& GetConfig() const
|
|
{
|
|
return *m_manager.GetConfig();
|
|
}
|
|
|
|
~PersistenceTests()
|
|
{
|
|
wxPersistenceManager::Set(*m_managerOld);
|
|
}
|
|
|
|
private:
|
|
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;
|
|
};
|
|
|
|
#endif // WX_TESTS_PERSIST_TESTPERSISTENCE_H
|