Split wxPersistenceManager-related tests and actually build them
It seems better to organize the tests in different files and just provide a common fixture-like class to reuse functionality. Also use this as an opportunity to rewrite the tests to use Catch directly instead of using CppUnit-compatible macros. Finally, actually build these tests as part of the test suite.
This commit is contained in:
@@ -250,6 +250,8 @@ TEST_GUI_OBJECTS = \
|
||||
test_gui_safearrayconverttest.o \
|
||||
test_gui_settings.o \
|
||||
test_gui_socket.o \
|
||||
test_gui_tlw.o \
|
||||
test_gui_dataview.o \
|
||||
test_gui_boxsizer.o \
|
||||
test_gui_gridsizer.o \
|
||||
test_gui_wrapsizer.o \
|
||||
@@ -1015,6 +1017,12 @@ test_gui_settings.o: $(srcdir)/misc/settings.cpp $(TEST_GUI_ODEP)
|
||||
test_gui_socket.o: $(srcdir)/net/socket.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/net/socket.cpp
|
||||
|
||||
test_gui_tlw.o: $(srcdir)/persistence/tlw.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/persistence/tlw.cpp
|
||||
|
||||
test_gui_dataview.o: $(srcdir)/persistence/dataview.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/persistence/dataview.cpp
|
||||
|
||||
test_gui_boxsizer.o: $(srcdir)/sizers/boxsizer.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/sizers/boxsizer.cpp
|
||||
|
||||
|
@@ -236,6 +236,8 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_safearrayconverttest.obj \
|
||||
$(OBJS)\test_gui_settings.obj \
|
||||
$(OBJS)\test_gui_socket.obj \
|
||||
$(OBJS)\test_gui_tlw.obj \
|
||||
$(OBJS)\test_gui_dataview.obj \
|
||||
$(OBJS)\test_gui_boxsizer.obj \
|
||||
$(OBJS)\test_gui_gridsizer.obj \
|
||||
$(OBJS)\test_gui_wrapsizer.obj \
|
||||
@@ -1068,6 +1070,12 @@ $(OBJS)\test_gui_settings.obj: .\misc\settings.cpp
|
||||
$(OBJS)\test_gui_socket.obj: .\net\socket.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp
|
||||
|
||||
$(OBJS)\test_gui_tlw.obj: .\persistence\tlw.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\persistence\tlw.cpp
|
||||
|
||||
$(OBJS)\test_gui_dataview.obj: .\persistence\dataview.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\persistence\dataview.cpp
|
||||
|
||||
$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp
|
||||
|
||||
|
@@ -231,6 +231,8 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_safearrayconverttest.o \
|
||||
$(OBJS)\test_gui_settings.o \
|
||||
$(OBJS)\test_gui_socket.o \
|
||||
$(OBJS)\test_gui_tlw.o \
|
||||
$(OBJS)\test_gui_dataview.o \
|
||||
$(OBJS)\test_gui_boxsizer.o \
|
||||
$(OBJS)\test_gui_gridsizer.o \
|
||||
$(OBJS)\test_gui_wrapsizer.o \
|
||||
@@ -1045,6 +1047,12 @@ $(OBJS)\test_gui_settings.o: ./misc/settings.cpp
|
||||
$(OBJS)\test_gui_socket.o: ./net/socket.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_tlw.o: ./persistence/tlw.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_dataview.o: ./persistence/dataview.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_boxsizer.o: ./sizers/boxsizer.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@@ -242,6 +242,8 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_safearrayconverttest.obj \
|
||||
$(OBJS)\test_gui_settings.obj \
|
||||
$(OBJS)\test_gui_socket.obj \
|
||||
$(OBJS)\test_gui_tlw.obj \
|
||||
$(OBJS)\test_gui_dataview.obj \
|
||||
$(OBJS)\test_gui_boxsizer.obj \
|
||||
$(OBJS)\test_gui_gridsizer.obj \
|
||||
$(OBJS)\test_gui_wrapsizer.obj \
|
||||
@@ -1247,6 +1249,12 @@ $(OBJS)\test_gui_settings.obj: .\misc\settings.cpp
|
||||
$(OBJS)\test_gui_socket.obj: .\net\socket.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp
|
||||
|
||||
$(OBJS)\test_gui_tlw.obj: .\persistence\tlw.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\persistence\tlw.cpp
|
||||
|
||||
$(OBJS)\test_gui_dataview.obj: .\persistence\dataview.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\persistence\dataview.cpp
|
||||
|
||||
$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp
|
||||
|
||||
|
@@ -1,229 +0,0 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/persistence/persistence.cpp
|
||||
// Purpose: wxPersistentObjects unit test
|
||||
// Author: wxWidgets Team
|
||||
// Created: 2017-08-23
|
||||
// Copyright: (c) 2017 wxWidgets Team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Note: The wxDataViewCtrl test currently uses the derivative class
|
||||
// wxDataViewListCtrl for convenience.
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#include "wx/config.h"
|
||||
#include "wx/dataview.h"
|
||||
#include "wx/frame.h"
|
||||
#include "wx/persist/dataview.h"
|
||||
#include "wx/persist/toplevel.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define APP_NAME "cpptest"
|
||||
#define PO_PREFIX "/Persistent_Options"
|
||||
#define DVLC_PREFIX PO_PREFIX "/DataView/dvlc"
|
||||
#define DVLC_COL "Column #"
|
||||
#define DVLC_COL_PREFIX DVLC_PREFIX "/Columns/" DVLC_COL
|
||||
#define DVLC_SORT_PREFIX DVLC_PREFIX "/Sorting"
|
||||
#define DVLC_FRAME_PREFIX PO_PREFIX "/Window/frame"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// test class
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class PersistenceTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
PersistenceTestCase()
|
||||
{
|
||||
wxTheApp->SetAppName("PersistTest");
|
||||
wxConfig::Get()->DeleteGroup("/Persistent_Options");
|
||||
wxConfig::Get()->Flush();
|
||||
}
|
||||
|
||||
virtual void setUp();
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( PersistenceTestCase );
|
||||
CPPUNIT_TEST( FrameSaveTest );
|
||||
CPPUNIT_TEST( FrameRestoreTest );
|
||||
CPPUNIT_TEST( DVLCSaveTest );
|
||||
CPPUNIT_TEST( DVLCRestoreTest );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void FrameSaveTest();
|
||||
void FrameRestoreTest();
|
||||
void DVLCSaveTest();
|
||||
void DVLCRestoreTest();
|
||||
|
||||
wxDataViewListCtrl* m_list;
|
||||
wxFrame* m_frame;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(PersistenceTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( PersistenceTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PersistenceTestCase, "PersistenceTestCase" );
|
||||
|
||||
void PersistenceTestCase::setUp()
|
||||
{
|
||||
// Create the objects to persist.
|
||||
m_frame = new wxFrame(wxTheApp->GetTopWindow(), wxID_ANY,
|
||||
"Persistence Test",
|
||||
wxDefaultPosition, wxSize(400,400));
|
||||
|
||||
m_list = new wxDataViewListCtrl(m_frame, wxID_ANY,
|
||||
wxDefaultPosition,
|
||||
wxDLG_UNIT(m_frame, wxSize(-1,-1)),
|
||||
wxDV_ROW_LINES|wxDV_SINGLE);
|
||||
|
||||
// Define names so the objects can be found using wxConfig.
|
||||
m_frame->SetName("frame");
|
||||
m_list->SetName("dvlc");
|
||||
|
||||
// Add some columns to the DVLC.
|
||||
m_list->AppendTextColumn(DVLC_COL "1",
|
||||
wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
|
||||
wxDATAVIEW_COL_RESIZABLE |
|
||||
wxDATAVIEW_COL_REORDERABLE |
|
||||
wxDATAVIEW_COL_SORTABLE);
|
||||
m_list->AppendTextColumn(DVLC_COL "2",
|
||||
wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
|
||||
wxDATAVIEW_COL_RESIZABLE |
|
||||
wxDATAVIEW_COL_REORDERABLE |
|
||||
wxDATAVIEW_COL_SORTABLE);
|
||||
|
||||
// Populate with DVLC data.
|
||||
wxVector<wxVariant> data;
|
||||
|
||||
data.push_back("AAAA");
|
||||
data.push_back("BBBB");
|
||||
m_list->AppendItem(data);
|
||||
|
||||
data.clear();
|
||||
data.push_back("CCCC");
|
||||
data.push_back("DDDD");
|
||||
m_list->AppendItem(data);
|
||||
|
||||
data.clear();
|
||||
data.push_back("EEEE");
|
||||
data.push_back("FFFF");
|
||||
m_list->AppendItem(data);
|
||||
}
|
||||
|
||||
void PersistenceTestCase::FrameSaveTest()
|
||||
{
|
||||
// Adjust the initial settings.
|
||||
m_frame->SetPosition(wxPoint(100, 150));
|
||||
m_frame->SetSize(wxSize(450, 350));
|
||||
|
||||
// Get default managers.
|
||||
wxPersistenceManager& pm = wxPersistenceManager::Get();
|
||||
wxConfigBase* conf = wxConfig::Get();
|
||||
|
||||
pm.Register(m_frame);
|
||||
|
||||
// Destroy the frame immediately.
|
||||
m_frame->wxWindowBase::Destroy();
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val;
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_FRAME_PREFIX "/x", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(100, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_FRAME_PREFIX "/y", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(150, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_FRAME_PREFIX "/h", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(350, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_FRAME_PREFIX "/w", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(450, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_FRAME_PREFIX "/Iconized", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(0, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_FRAME_PREFIX "/Maximized", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(0, val);
|
||||
}
|
||||
|
||||
void PersistenceTestCase::FrameRestoreTest()
|
||||
{
|
||||
// Get default manager.
|
||||
wxPersistenceManager& pm = wxPersistenceManager::Get();
|
||||
|
||||
// Test that the objects are registered and can be restored.
|
||||
CPPUNIT_ASSERT(pm.RegisterAndRestore(m_frame));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(100, m_frame->GetPosition().x);
|
||||
CPPUNIT_ASSERT_EQUAL(150, m_frame->GetPosition().y);
|
||||
CPPUNIT_ASSERT_EQUAL(350, m_frame->GetSize().GetHeight());
|
||||
CPPUNIT_ASSERT_EQUAL(450, m_frame->GetSize().GetWidth());
|
||||
CPPUNIT_ASSERT(!m_frame->IsMaximized());
|
||||
CPPUNIT_ASSERT(!m_frame->IsIconized());
|
||||
}
|
||||
|
||||
void PersistenceTestCase::DVLCSaveTest()
|
||||
{
|
||||
// Adjust the initial settings.
|
||||
m_list->GetColumn(0)->SetWidth(150);
|
||||
m_list->GetColumn(1)->SetWidth(250);
|
||||
m_list->GetColumn(1)->SetSortOrder(false);
|
||||
|
||||
// Get default managers.
|
||||
wxPersistenceManager& pm = wxPersistenceManager::Get();
|
||||
wxConfigBase* conf = wxConfig::Get();
|
||||
|
||||
pm.Register(m_list);
|
||||
|
||||
// Destroy the frame containing the DVLC immediately.
|
||||
m_frame->wxWindowBase::Destroy();
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val;
|
||||
wxString text;
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_COL_PREFIX "1/Width", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(150, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_COL_PREFIX "2/Width", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(250, val);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_SORT_PREFIX "/Column", &text));
|
||||
CPPUNIT_ASSERT_EQUAL("Column #2", text);
|
||||
|
||||
CPPUNIT_ASSERT(conf->Read(DVLC_SORT_PREFIX "/Asc", &val));
|
||||
CPPUNIT_ASSERT_EQUAL(0, val);
|
||||
}
|
||||
|
||||
void PersistenceTestCase::DVLCRestoreTest()
|
||||
{
|
||||
// Get default manager.
|
||||
wxPersistenceManager& pm = wxPersistenceManager::Get();
|
||||
|
||||
// Test that the objects are registered and can be restored.
|
||||
CPPUNIT_ASSERT(pm.RegisterAndRestore(m_list));
|
||||
|
||||
// Test that the correct values were restored.
|
||||
CPPUNIT_ASSERT_EQUAL(150, m_list->GetColumn(0)->GetWidth());
|
||||
CPPUNIT_ASSERT_EQUAL(250, m_list->GetColumn(1)->GetWidth());
|
||||
CPPUNIT_ASSERT(m_list->GetColumn(1)->IsSortKey());
|
||||
CPPUNIT_ASSERT(!m_list->GetColumn(1)->IsSortOrderAscending());
|
||||
}
|
123
tests/persistence/dataview.cpp
Normal file
123
tests/persistence/dataview.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/persistence/dataview.cpp
|
||||
// Purpose: wxDataViewCtrl persistence support unit tests
|
||||
// Author: wxWidgets Team
|
||||
// Created: 2017-08-23
|
||||
// Copyright: (c) 2017 wxWidgets Team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "testpersistence.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dataview.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/persist/dataview.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define DVC_PREFIX PO_PREFIX "/DataView/dvc"
|
||||
#define DVC_COL "Column #"
|
||||
#define DVC_COL_PREFIX DVC_PREFIX "/Columns/" DVC_COL
|
||||
#define DVC_SORT_PREFIX DVC_PREFIX "/Sorting"
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// tests themselves
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Note: The wxDataViewCtrl test currently uses the derivative class
|
||||
// wxDataViewListCtrl for convenience.
|
||||
TEST_CASE_METHOD(PersistenceTests, "wxPersistDVC", "[persist][wxDataViewCtrl]")
|
||||
{
|
||||
// We can't just destroy the control itself directly, we need to destroy
|
||||
// its parent as only this will ensure that it gets wxWindowDestroyEvent
|
||||
// from which its state will be saved.
|
||||
wxWindow* const parent = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY);
|
||||
wxDataViewListCtrl* const list = new wxDataViewListCtrl(parent, wxID_ANY);
|
||||
list->SetName("dvc");
|
||||
|
||||
// Add some columns to the DVC.
|
||||
list->AppendTextColumn(DVC_COL "1",
|
||||
wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
|
||||
wxDATAVIEW_COL_RESIZABLE |
|
||||
wxDATAVIEW_COL_REORDERABLE |
|
||||
wxDATAVIEW_COL_SORTABLE);
|
||||
list->AppendTextColumn(DVC_COL "2",
|
||||
wxDATAVIEW_CELL_INERT, -1, wxALIGN_LEFT,
|
||||
wxDATAVIEW_COL_RESIZABLE |
|
||||
wxDATAVIEW_COL_REORDERABLE |
|
||||
wxDATAVIEW_COL_SORTABLE);
|
||||
|
||||
// Populate with DVC data.
|
||||
wxVector<wxVariant> data;
|
||||
|
||||
data.push_back("AAAA");
|
||||
data.push_back("BBBB");
|
||||
list->AppendItem(data);
|
||||
|
||||
data.clear();
|
||||
data.push_back("CCCC");
|
||||
data.push_back("DDDD");
|
||||
list->AppendItem(data);
|
||||
|
||||
data.clear();
|
||||
data.push_back("EEEE");
|
||||
data.push_back("FFFF");
|
||||
list->AppendItem(data);
|
||||
|
||||
SECTION("Save")
|
||||
{
|
||||
// Adjust the initial settings.
|
||||
list->GetColumn(0)->SetWidth(150);
|
||||
list->GetColumn(1)->SetWidth(250);
|
||||
list->GetColumn(1)->SetSortOrder(false);
|
||||
|
||||
wxPersistenceManager::Get().Register(list);
|
||||
|
||||
delete parent;
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val;
|
||||
wxString text;
|
||||
|
||||
const wxConfigBase* const conf = wxConfig::Get();
|
||||
|
||||
CHECK(conf->Read(DVC_COL_PREFIX "1/Width", &val));
|
||||
CHECK(150 == val);
|
||||
|
||||
CHECK(conf->Read(DVC_COL_PREFIX "2/Width", &val));
|
||||
CHECK(250 == val);
|
||||
|
||||
CHECK(conf->Read(DVC_SORT_PREFIX "/Column", &text));
|
||||
CHECK(text == "Column #2");
|
||||
|
||||
CHECK(conf->Read(DVC_SORT_PREFIX "/Asc", &val));
|
||||
CHECK(0 == val);
|
||||
}
|
||||
|
||||
SECTION("Restore")
|
||||
{
|
||||
EnableCleanup();
|
||||
|
||||
// Test that the object was registered and restored.
|
||||
CHECK(wxPersistenceManager::Get().RegisterAndRestore(list));
|
||||
|
||||
// Test that the correct values were restored.
|
||||
CHECK(150 == list->GetColumn(0)->GetWidth());
|
||||
CHECK(250 == list->GetColumn(1)->GetWidth());
|
||||
CHECK(list->GetColumn(1)->IsSortKey());
|
||||
CHECK(!list->GetColumn(1)->IsSortOrderAscending());
|
||||
}
|
||||
}
|
45
tests/persistence/testpersistence.h
Normal file
45
tests/persistence/testpersistence.h
Normal file
@@ -0,0 +1,45 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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"
|
||||
|
||||
#define PO_PREFIX "/Persistent_Options"
|
||||
|
||||
class PersistenceTests
|
||||
{
|
||||
public:
|
||||
PersistenceTests()
|
||||
: m_cleanup(false)
|
||||
{
|
||||
wxTheApp->SetAppName("wxPersistenceTests");
|
||||
}
|
||||
|
||||
// The tests using this fixture should call this method when they don't
|
||||
// need the values saved into wxConfig any more.
|
||||
void EnableCleanup()
|
||||
{
|
||||
m_cleanup = true;
|
||||
}
|
||||
|
||||
~PersistenceTests()
|
||||
{
|
||||
if ( m_cleanup )
|
||||
{
|
||||
wxConfig::Get()->DeleteGroup(PO_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_cleanup;
|
||||
};
|
||||
|
||||
#endif // WX_TESTS_PERSIST_TESTPERSISTENCE_H
|
95
tests/persistence/tlw.cpp
Normal file
95
tests/persistence/tlw.cpp
Normal file
@@ -0,0 +1,95 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/persistence/persistence.cpp
|
||||
// Purpose: wxTLW persistence support unit test
|
||||
// Author: wxWidgets Team
|
||||
// Created: 2017-08-23
|
||||
// Copyright: (c) 2017 wxWidgets Team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "testpersistence.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/frame.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/persist/toplevel.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define FRAME_OPTIONS_PREFIX PO_PREFIX "/Window/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")
|
||||
{
|
||||
// Set the geometry before saving.
|
||||
frame->SetPosition(pos);
|
||||
frame->SetSize(size);
|
||||
|
||||
wxPersistenceManager::Get().Register(frame);
|
||||
|
||||
// Destroy the frame immediately.
|
||||
delete frame;
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val;
|
||||
|
||||
const wxConfigBase* const conf = wxConfig::Get();
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/x", &val));
|
||||
CHECK(pos.x == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/y", &val));
|
||||
CHECK(pos.y == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/w", &val));
|
||||
CHECK(size.x == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/h", &val));
|
||||
CHECK(size.y == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/Iconized", &val));
|
||||
CHECK(0 == val);
|
||||
|
||||
CHECK(conf->Read(FRAME_OPTIONS_PREFIX "/Maximized", &val));
|
||||
CHECK(0 == val);
|
||||
}
|
||||
|
||||
SECTION("Restore")
|
||||
{
|
||||
EnableCleanup();
|
||||
|
||||
// Test that the object was registered and restored.
|
||||
CHECK(wxPersistenceManager::Get().RegisterAndRestore(frame));
|
||||
|
||||
CHECK(pos.x == frame->GetPosition().x);
|
||||
CHECK(pos.y == frame->GetPosition().y);
|
||||
CHECK(size.x == frame->GetSize().GetWidth());
|
||||
CHECK(size.y == frame->GetSize().GetHeight());
|
||||
CHECK(!frame->IsMaximized());
|
||||
CHECK(!frame->IsIconized());
|
||||
}
|
||||
}
|
@@ -261,6 +261,8 @@
|
||||
applications.
|
||||
-->
|
||||
net/socket.cpp
|
||||
persistence/tlw.cpp
|
||||
persistence/dataview.cpp
|
||||
sizers/boxsizer.cpp
|
||||
sizers/gridsizer.cpp
|
||||
sizers/wrapsizer.cpp
|
||||
|
@@ -545,6 +545,8 @@
|
||||
<ClCompile Include="misc\selstoretest.cpp" />
|
||||
<ClCompile Include="misc\settings.cpp" />
|
||||
<ClCompile Include="net\socket.cpp" />
|
||||
<ClCompile Include="persistence\tlw.cpp" />
|
||||
<ClCompile Include="persistence\dataview.cpp" />
|
||||
<ClCompile Include="sizers\boxsizer.cpp" />
|
||||
<ClCompile Include="sizers\gridsizer.cpp" />
|
||||
<ClCompile Include="sizers\wrapsizer.cpp" />
|
||||
|
@@ -227,6 +227,12 @@
|
||||
<ClCompile Include="net\socket.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="persistence\tlw.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="persistence\dataview.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="controls\spinctrldbltest.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
@@ -355,6 +355,9 @@
|
||||
<File
|
||||
RelativePath=".\config\config.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\persistence\dataview.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\dataviewctrltest.cpp">
|
||||
</File>
|
||||
@@ -559,6 +562,9 @@
|
||||
<File
|
||||
RelativePath=".\controls\textentrytest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\persistence\tlw.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\togglebuttontest.cpp">
|
||||
</File>
|
||||
|
@@ -910,6 +910,10 @@
|
||||
RelativePath=".\config\config.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\persistence\dataview.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\dataviewctrltest.cpp"
|
||||
>
|
||||
@@ -1214,6 +1218,10 @@
|
||||
RelativePath=".\controls\textentrytest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\persistence\tlw.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\togglebuttontest.cpp"
|
||||
>
|
||||
|
@@ -882,6 +882,10 @@
|
||||
RelativePath=".\config\config.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\persistence\dataview.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\dataviewctrltest.cpp"
|
||||
>
|
||||
@@ -1186,6 +1190,10 @@
|
||||
RelativePath=".\controls\textentrytest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\persistence\tlw.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\togglebuttontest.cpp"
|
||||
>
|
||||
|
Reference in New Issue
Block a user