1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
///////////////////////////////////////////////////////////////////////////////
// Name: tests/controls/virtlistctrltest.cpp
// Purpose: wxListCtrl unit tests for virtual mode
// Author: Vadim Zeitlin
// Created: 2010-11-13
// Copyright: (c) 2010 Vadim Zeitlin <vadim@wxwidgets.org>
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#if wxUSE_LISTCTRL
#ifndef WX_PRECOMP
#include "wx/app.h"
#endif // WX_PRECOMP
#include "wx/listctrl.h"
#include "testableframe.h"
#include "wx/uiaction.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class VirtListCtrlTestCase : public CppUnit::TestCase
{
public:
VirtListCtrlTestCase() { }
virtual void setUp() wxOVERRIDE;
virtual void tearDown() wxOVERRIDE;
private:
CPPUNIT_TEST_SUITE( VirtListCtrlTestCase );
CPPUNIT_TEST( UpdateSelection );
WXUISIM_TEST( DeselectedEvent );
CPPUNIT_TEST_SUITE_END();
void UpdateSelection();
void DeselectedEvent();
wxListCtrl *m_list;
wxDECLARE_NO_COPY_CLASS(VirtListCtrlTestCase);
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( VirtListCtrlTestCase );
// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VirtListCtrlTestCase, "VirtListCtrlTestCase" );
// ----------------------------------------------------------------------------
// test initialization
// ----------------------------------------------------------------------------
void VirtListCtrlTestCase::setUp()
{
// Define a class overriding OnGetItemText() which must be overridden for
// any virtual list control.
class VirtListCtrl : public wxListCtrl
{
public:
VirtListCtrl()
: wxListCtrl(wxTheApp->GetTopWindow(), wxID_ANY,
wxPoint(0, 0), wxSize(400, 200),
wxLC_REPORT | wxLC_VIRTUAL)
{
}
protected:
virtual wxString OnGetItemText(long item, long column) const wxOVERRIDE
{
return wxString::Format("Row %ld, col %ld", item, column);
}
};
m_list = new VirtListCtrl;
}
void VirtListCtrlTestCase::tearDown()
{
delete m_list;
m_list = NULL;
}
void VirtListCtrlTestCase::UpdateSelection()
{
m_list->SetItemCount(10);
CPPUNIT_ASSERT_EQUAL( 0, m_list->GetSelectedItemCount() );
m_list->SetItemState(7, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
m_list->SetItemState(0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
CPPUNIT_ASSERT_EQUAL( 2, m_list->GetSelectedItemCount() );
// The item 7 is now invalid and so shouldn't be counted as selected any
// more.
m_list->SetItemCount(5);
CPPUNIT_ASSERT_EQUAL( 1, m_list->GetSelectedItemCount() );
}
void VirtListCtrlTestCase::DeselectedEvent()
{
#if wxUSE_UIACTIONSIMULATOR
m_list->AppendColumn("Col0");
m_list->SetItemCount(1);
wxListCtrl* const list = m_list;
EventCounter selected(list, wxEVT_LIST_ITEM_SELECTED);
EventCounter deselected(list, wxEVT_LIST_ITEM_DESELECTED);
wxUIActionSimulator sim;
wxRect pos;
list->GetItemRect(0, pos);
//We move in slightly so we are not on the edge
wxPoint point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 10);
sim.MouseMove(point);
wxYield();
sim.MouseClick();
wxYield();
// We want a point within the listctrl but below any items
point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 50);
sim.MouseMove(point);
wxYield();
sim.MouseClick();
wxYield();
CPPUNIT_ASSERT_EQUAL(1, selected.GetCount());
CPPUNIT_ASSERT_EQUAL(1, deselected.GetCount());
#endif
}
#endif // wxUSE_LISTCTRL
|