initial commit
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
165
libs/wxWidgets-3.3.1/tests/persistence/dataview.cpp
Normal file
165
libs/wxWidgets-3.3.1/tests/persistence/dataview.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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"
|
||||
|
||||
#if wxUSE_DATAVIEWCTRL
|
||||
|
||||
|
||||
#include "testpersistence.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dataview.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/persist/dataview.h"
|
||||
|
||||
#ifdef __WXGTK__
|
||||
#include "waitfor.h"
|
||||
#endif // __WXGTK__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// local helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Create the control used for testing.
|
||||
static wxDataViewCtrl* CreatePersistenceTestDVC()
|
||||
{
|
||||
// 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");
|
||||
|
||||
// Ensure the control is big enough to allow making its columns as wide as
|
||||
// we need them to be.
|
||||
parent->SetSize(parent->GetParent()->GetClientSize());
|
||||
list->SetSize(parent->GetClientSize());
|
||||
|
||||
// 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);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
void GTKWaitRealized(wxDataViewCtrl* list)
|
||||
{
|
||||
#ifdef __WXGTK__
|
||||
WaitFor("wxDataViewCtrl to be realized", [list]() {
|
||||
return list->GetColumn(0)->GetWidth() != 0;
|
||||
});
|
||||
#else // !__WXGTK__
|
||||
wxUnusedVar(list);
|
||||
#endif // __WXGTK__/!__WXGTK__
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// tests themselves
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// Note: The wxDataViewCtrl test currently uses the derivative class
|
||||
// wxDataViewListCtrl for convenience.
|
||||
TEST_CASE_METHOD(PersistenceTests, "wxPersistDVC", "[persist][wxDataViewCtrl]")
|
||||
{
|
||||
{
|
||||
wxDataViewCtrl* const list = CreatePersistenceTestDVC();
|
||||
|
||||
// Adjust the initial settings.
|
||||
list->GetColumn(0)->SetWidth(150);
|
||||
list->GetColumn(1)->SetWidth(250);
|
||||
list->GetColumn(1)->SetSortOrder(false);
|
||||
|
||||
CHECK(wxPersistenceManager::Get().Register(list));
|
||||
|
||||
// We need to wait until the window is fully realized and the column
|
||||
// widths are actually set.
|
||||
GTKWaitRealized(list);
|
||||
|
||||
// Deleting the control itself doesn't allow it to save its state as
|
||||
// the wxEVT_DESTROY handler is called too late, so delete its parent
|
||||
// (as would usually be the case) instead.
|
||||
delete list->GetParent();
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val = -1;
|
||||
wxString text;
|
||||
|
||||
CHECK(GetConfig().Read(DVC_COL_PREFIX "1/Width", &val));
|
||||
CHECK(150 == val);
|
||||
|
||||
CHECK(GetConfig().Read(DVC_COL_PREFIX "2/Width", &val));
|
||||
CHECK(250 == val);
|
||||
|
||||
CHECK(GetConfig().Read(DVC_SORT_PREFIX "/Column", &text));
|
||||
CHECK(text == "Column #2");
|
||||
|
||||
CHECK(GetConfig().Read(DVC_SORT_PREFIX "/Asc", &val));
|
||||
CHECK(0 == val);
|
||||
}
|
||||
|
||||
{
|
||||
wxDataViewCtrl* const list = CreatePersistenceTestDVC();
|
||||
|
||||
// Test that the object was registered and restored.
|
||||
CHECK(wxPersistenceManager::Get().RegisterAndRestore(list));
|
||||
|
||||
// Similar to above, we need to wait until it's realized after
|
||||
// restoring the widths.
|
||||
GTKWaitRealized(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());
|
||||
|
||||
delete list->GetParent();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
67
libs/wxWidgets-3.3.1/tests/persistence/testpersistence.h
Normal file
67
libs/wxWidgets-3.3.1/tests/persistence/testpersistence.h
Normal file
@@ -0,0 +1,67 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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() override
|
||||
{
|
||||
m_config.DeleteAll();
|
||||
}
|
||||
|
||||
wxConfigBase* GetConfig() const override
|
||||
{
|
||||
return const_cast<wxConfig*>(&m_config);
|
||||
}
|
||||
|
||||
private:
|
||||
wxConfig m_config;
|
||||
};
|
||||
|
||||
wxPersistenceManager *m_managerOld;
|
||||
TestPersistenceManager m_manager;
|
||||
};
|
||||
|
||||
#endif // WX_TESTS_PERSIST_TESTPERSISTENCE_H
|
||||
191
libs/wxWidgets-3.3.1/tests/persistence/tlw.cpp
Normal file
191
libs/wxWidgets-3.3.1/tests/persistence/tlw.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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"
|
||||
|
||||
|
||||
#include "testpersistence.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/frame.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/persist/toplevel.h"
|
||||
|
||||
#ifdef __WXGTK__
|
||||
#include "waitfor.h"
|
||||
#endif // __WXGTK__
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#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]")
|
||||
{
|
||||
const wxPoint pos(100, 150);
|
||||
const wxSize size(450, 350);
|
||||
|
||||
// Save the frame geometry.
|
||||
{
|
||||
wxFrame* const frame = CreatePersistenceTestFrame();
|
||||
|
||||
// Set the geometry before saving.
|
||||
frame->SetPosition(pos);
|
||||
frame->SetSize(size);
|
||||
|
||||
CHECK(wxPersistenceManager::Get().Register(frame));
|
||||
|
||||
// Destroy the frame immediately, i.e. don't use Destroy() here.
|
||||
delete frame;
|
||||
|
||||
// Test that the relevant keys have been stored correctly.
|
||||
int val = -1;
|
||||
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/x", &val));
|
||||
CHECK(pos.x == val);
|
||||
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/y", &val));
|
||||
CHECK(pos.y == val);
|
||||
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/w", &val));
|
||||
CHECK(size.x == val);
|
||||
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/h", &val));
|
||||
CHECK(size.y == val);
|
||||
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/Iconized", &val));
|
||||
CHECK(0 == val);
|
||||
|
||||
CHECK(GetConfig().Read(FRAME_OPTIONS_PREFIX "/Maximized", &val));
|
||||
CHECK(0 == val);
|
||||
}
|
||||
|
||||
// Now try recreating the frame using the restored values.
|
||||
bool checkIconized = true;
|
||||
{
|
||||
wxFrame* const frame = CreatePersistenceTestFrame();
|
||||
|
||||
// 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());
|
||||
|
||||
// Next try that restoring a minimized frame works correctly: for
|
||||
// Iconize() to have effect, we must show the frame first.
|
||||
frame->Iconize();
|
||||
frame->Show();
|
||||
|
||||
#ifdef __WXGTK__
|
||||
// When using Xvfb, the frame will never get iconized, presumably
|
||||
// because there is no WM, so don't even bother waiting or warning.
|
||||
if ( IsRunningUnderXVFB() )
|
||||
{
|
||||
checkIconized = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !WaitFor("frame to be iconized", [frame]() {
|
||||
return frame->IsIconized();
|
||||
}) )
|
||||
{
|
||||
checkIconized = false;
|
||||
}
|
||||
}
|
||||
#endif // __WXGTK__
|
||||
|
||||
delete frame;
|
||||
}
|
||||
|
||||
// Check geometry after restoring the minimized frame.
|
||||
{
|
||||
wxFrame* const frame = CreatePersistenceTestFrame();
|
||||
|
||||
CHECK(wxPersistenceManager::Get().RegisterAndRestore(frame));
|
||||
|
||||
// As above, we need to show the frame for it to be actually iconized.
|
||||
frame->Show();
|
||||
|
||||
CHECK(!frame->IsMaximized());
|
||||
if ( checkIconized )
|
||||
{
|
||||
#ifdef __WXGTK__
|
||||
WaitFor("frame to be iconized", [frame]() {
|
||||
return frame->IsIconized();
|
||||
});
|
||||
#endif // __WXGTK__
|
||||
|
||||
CHECK(frame->IsIconized());
|
||||
}
|
||||
|
||||
frame->Restore();
|
||||
|
||||
CHECK(pos.x == frame->GetPosition().x);
|
||||
CHECK(pos.y == frame->GetPosition().y);
|
||||
CHECK(size.x == frame->GetSize().GetWidth());
|
||||
CHECK(size.y == frame->GetSize().GetHeight());
|
||||
|
||||
// Next try that restoring a maximized frame works correctly: again,
|
||||
// for it to be really maximized, it must be shown.
|
||||
frame->Maximize();
|
||||
frame->Show();
|
||||
|
||||
delete frame;
|
||||
}
|
||||
|
||||
// Check geometry after restoring the maximized frame.
|
||||
//
|
||||
// This test currently fails under non-MSW platforms as they only save the
|
||||
// maximized frame size, and its normal size is lost and can't be restored.
|
||||
#ifdef __WXMSW__
|
||||
{
|
||||
wxFrame* const frame = CreatePersistenceTestFrame();
|
||||
|
||||
CHECK(wxPersistenceManager::Get().RegisterAndRestore(frame));
|
||||
|
||||
CHECK(frame->IsMaximized());
|
||||
CHECK(!frame->IsIconized());
|
||||
|
||||
frame->Restore();
|
||||
|
||||
CHECK(pos.x == frame->GetPosition().x);
|
||||
CHECK(pos.y == frame->GetPosition().y);
|
||||
CHECK(size.x == frame->GetSize().GetWidth());
|
||||
CHECK(size.y == frame->GetSize().GetHeight());
|
||||
|
||||
delete frame;
|
||||
}
|
||||
#endif // __WXMSW__
|
||||
}
|
||||
Reference in New Issue
Block a user