2008-11-26 14:11:22 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/listctrltest.cpp
|
|
|
|
// Purpose: wxListCtrl unit test
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2008-11-26
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
2010-08-22 18:16:05 -04:00
|
|
|
// (c) 2010 Steven Lamerton
|
2008-11-26 14:11:22 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#if wxUSE_LISTCTRL
|
|
|
|
|
2008-11-26 14:11:22 -05:00
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2008-12-12 11:21:49 -05:00
|
|
|
#include "wx/listctrl.h"
|
2010-08-22 18:16:05 -04:00
|
|
|
#include "listbasetest.h"
|
|
|
|
#include "testableframe.h"
|
|
|
|
#include "wx/uiaction.h"
|
2008-12-12 11:21:49 -05:00
|
|
|
|
2008-11-26 14:11:22 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
class ListCtrlTestCase : public ListBaseTestCase, public CppUnit::TestCase
|
2008-11-26 14:11:22 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ListCtrlTestCase() { }
|
|
|
|
|
|
|
|
virtual void setUp();
|
|
|
|
virtual void tearDown();
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
virtual wxListCtrl *GetList() const { return m_list; }
|
|
|
|
|
2008-11-26 14:11:22 -05:00
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( ListCtrlTestCase );
|
2010-08-22 18:16:05 -04:00
|
|
|
wxLIST_BASE_TESTS();
|
2010-10-05 09:38:05 -04:00
|
|
|
CPPUNIT_TEST( EditLabel );
|
2010-08-22 18:16:05 -04:00
|
|
|
WXUISIM_TEST( ColumnClick );
|
|
|
|
WXUISIM_TEST( ColumnDrag );
|
2008-11-26 14:11:22 -05:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
2010-10-05 09:38:05 -04:00
|
|
|
void EditLabel();
|
2010-08-22 18:16:05 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
// Column events are only supported in wxListCtrl currently so we test them
|
|
|
|
// here rather than in ListBaseTest
|
|
|
|
void ColumnClick();
|
|
|
|
void ColumnDrag();
|
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
2008-11-26 14:11:22 -05:00
|
|
|
|
|
|
|
wxListCtrl *m_list;
|
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(ListCtrlTestCase)
|
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( ListCtrlTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2008-11-26 14:11:22 -05:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ListCtrlTestCase, "ListCtrlTestCase" );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test initialization
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void ListCtrlTestCase::setUp()
|
|
|
|
{
|
|
|
|
m_list = new wxListCtrl(wxTheApp->GetTopWindow());
|
2008-12-20 21:13:58 -05:00
|
|
|
m_list->SetWindowStyle(wxLC_REPORT);
|
2010-08-22 18:16:05 -04:00
|
|
|
m_list->SetSize(400, 200);
|
2008-11-26 14:11:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void ListCtrlTestCase::tearDown()
|
|
|
|
{
|
|
|
|
delete m_list;
|
|
|
|
m_list = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-05 09:38:05 -04:00
|
|
|
void ListCtrlTestCase::EditLabel()
|
|
|
|
{
|
|
|
|
m_list->InsertColumn(0, "Column 0");
|
|
|
|
m_list->InsertItem(0, "foo");
|
|
|
|
m_list->EditLabel(0);
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
void ListCtrlTestCase::ColumnDrag()
|
2008-11-26 14:11:22 -05:00
|
|
|
{
|
2010-08-22 18:16:05 -04:00
|
|
|
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
|
|
|
wxTestableFrame);
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_BEGIN_DRAG);
|
|
|
|
EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_DRAGGING);
|
|
|
|
EventCounter count2(m_list, wxEVT_COMMAND_LIST_COL_END_DRAG);
|
2009-03-23 08:18:51 -04:00
|
|
|
|
2008-11-26 14:11:22 -05:00
|
|
|
m_list->InsertColumn(0, "Column 0");
|
|
|
|
m_list->InsertColumn(1, "Column 1");
|
|
|
|
m_list->InsertColumn(2, "Column 2");
|
2010-08-22 18:16:05 -04:00
|
|
|
m_list->Update();
|
|
|
|
m_list->SetFocus();
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
wxUIActionSimulator sim;
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
wxPoint pt = m_list->ClientToScreen(wxPoint(m_list->GetColumnWidth(0), 5));
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
sim.MouseMove(pt);
|
|
|
|
wxYield();
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
sim.MouseDown();
|
|
|
|
wxYield();
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
sim.MouseMove(pt.x + 50, pt.y);
|
|
|
|
wxYield();
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
sim.MouseUp();
|
|
|
|
wxYield();
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_BEGIN_DRAG));
|
|
|
|
CPPUNIT_ASSERT(frame->GetEventCount(wxEVT_COMMAND_LIST_COL_DRAGGING) > 0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_END_DRAG));
|
2008-11-26 14:11:22 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
m_list->ClearAll();
|
2008-11-26 14:11:22 -05:00
|
|
|
}
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
void ListCtrlTestCase::ColumnClick()
|
2008-12-20 21:13:58 -05:00
|
|
|
{
|
2010-08-22 18:16:05 -04:00
|
|
|
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
|
|
|
wxTestableFrame);
|
2008-12-20 21:13:58 -05:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
EventCounter count(m_list, wxEVT_COMMAND_LIST_COL_CLICK);
|
|
|
|
EventCounter count1(m_list, wxEVT_COMMAND_LIST_COL_RIGHT_CLICK);
|
2008-12-20 21:13:58 -05:00
|
|
|
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
m_list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60);
|
2010-05-10 17:22:16 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
wxUIActionSimulator sim;
|
2010-05-10 17:22:16 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
sim.MouseMove(m_list->ClientToScreen(wxPoint(4, 4)));
|
|
|
|
wxYield();
|
2010-05-10 17:22:16 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
sim.MouseClick();
|
|
|
|
sim.MouseClick(wxMOUSE_BTN_RIGHT);
|
|
|
|
wxYield();
|
2009-04-21 13:19:08 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_CLICK));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, frame->GetEventCount(wxEVT_COMMAND_LIST_COL_RIGHT_CLICK));
|
2009-04-21 13:19:08 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
m_list->ClearAll();
|
2009-04-21 13:19:08 -04:00
|
|
|
}
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif // wxUSE_UIACTIONSIMULATOR
|
2009-04-21 13:19:08 -04:00
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif // wxUSE_LISTCTRL
|