2010-08-22 18:16:05 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/gridtest.cpp
|
|
|
|
// Purpose: wxGrid unit test
|
|
|
|
// Author: Steven Lamerton
|
|
|
|
// Created: 2010-06-25
|
|
|
|
// Copyright: (c) 2010 Steven Lamerton
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#if wxUSE_GRID
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/grid.h"
|
|
|
|
#include "testableframe.h"
|
|
|
|
#include "asserthelper.h"
|
|
|
|
#include "wx/uiaction.h"
|
|
|
|
|
2012-06-01 12:21:08 -04:00
|
|
|
// FIXME: A lot of mouse-related tests sporadically fail in wxGTK. This happens
|
|
|
|
// almost all the time but sometimes the tests do pass and the failure
|
|
|
|
// doesn't happen when debugging so this looks like some kind of event
|
|
|
|
// dispatching/simulating problem rather than a real problem in wxGrid.
|
|
|
|
//
|
|
|
|
// Just disable these tests for now but it would be really great to
|
|
|
|
// really fix the problem.
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
#define NONGTK_TEST(test)
|
|
|
|
#else
|
|
|
|
#define NONGTK_TEST(test) WXUISIM_TEST(test)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
class GridTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GridTestCase() { }
|
|
|
|
|
|
|
|
virtual void setUp();
|
|
|
|
virtual void tearDown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( GridTestCase );
|
|
|
|
WXUISIM_TEST( CellEdit );
|
2012-06-01 12:21:08 -04:00
|
|
|
NONGTK_TEST( CellClick );
|
|
|
|
NONGTK_TEST( CellSelect );
|
|
|
|
NONGTK_TEST( LabelClick );
|
|
|
|
NONGTK_TEST( SortClick );
|
2010-08-22 18:16:05 -04:00
|
|
|
WXUISIM_TEST( Size );
|
2012-06-01 12:21:08 -04:00
|
|
|
NONGTK_TEST( RangeSelect );
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST( Cursor );
|
|
|
|
CPPUNIT_TEST( Selection );
|
|
|
|
CPPUNIT_TEST( AddRowCol );
|
|
|
|
CPPUNIT_TEST( ColumnOrder );
|
2013-04-24 05:01:57 -04:00
|
|
|
CPPUNIT_TEST( ColumnVisibility );
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST( LineFormatting );
|
|
|
|
CPPUNIT_TEST( SortSupport );
|
|
|
|
CPPUNIT_TEST( Labels );
|
|
|
|
CPPUNIT_TEST( SelectionMode );
|
|
|
|
CPPUNIT_TEST( CellFormatting );
|
|
|
|
WXUISIM_TEST( Editable );
|
|
|
|
WXUISIM_TEST( ReadOnly );
|
|
|
|
CPPUNIT_TEST( PseudoTest_NativeHeader );
|
2012-06-01 12:21:08 -04:00
|
|
|
NONGTK_TEST( LabelClick );
|
|
|
|
NONGTK_TEST( SortClick );
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST( ColumnOrder );
|
|
|
|
CPPUNIT_TEST( PseudoTest_NativeLabels );
|
2012-06-01 12:21:08 -04:00
|
|
|
NONGTK_TEST( LabelClick );
|
|
|
|
NONGTK_TEST( SortClick );
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST( ColumnOrder );
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void CellEdit();
|
|
|
|
void CellClick();
|
|
|
|
void CellSelect();
|
|
|
|
void LabelClick();
|
|
|
|
void SortClick();
|
|
|
|
void Size();
|
|
|
|
void RangeSelect();
|
|
|
|
void Cursor();
|
|
|
|
void Selection();
|
|
|
|
void AddRowCol();
|
|
|
|
void ColumnOrder();
|
2013-04-24 05:01:57 -04:00
|
|
|
void ColumnVisibility();
|
2010-08-22 18:16:05 -04:00
|
|
|
void LineFormatting();
|
|
|
|
void SortSupport();
|
|
|
|
void Labels();
|
|
|
|
void SelectionMode();
|
|
|
|
void CellFormatting();
|
|
|
|
void Editable();
|
|
|
|
void ReadOnly();
|
|
|
|
void PseudoTest_NativeHeader() { ms_nativeheader = true; }
|
|
|
|
void PseudoTest_NativeLabels() { ms_nativeheader = false;
|
|
|
|
ms_nativelabels = true; }
|
|
|
|
|
|
|
|
static bool ms_nativeheader;
|
|
|
|
static bool ms_nativelabels;
|
|
|
|
|
|
|
|
wxGrid *m_grid;
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(GridTestCase);
|
2010-08-22 18:16:05 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( GridTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GridTestCase, "GridTestCase" );
|
|
|
|
|
|
|
|
//initialise the static variable
|
|
|
|
bool GridTestCase::ms_nativeheader = false;
|
|
|
|
bool GridTestCase::ms_nativelabels = false;
|
|
|
|
|
|
|
|
void GridTestCase::setUp()
|
|
|
|
{
|
|
|
|
m_grid = new wxGrid(wxTheApp->GetTopWindow(), wxID_ANY);
|
|
|
|
m_grid->CreateGrid(10, 2);
|
|
|
|
m_grid->SetSize(400, 200);
|
|
|
|
|
|
|
|
if( ms_nativeheader )
|
|
|
|
m_grid->UseNativeColHeader();
|
|
|
|
|
|
|
|
if( ms_nativelabels )
|
|
|
|
m_grid->SetUseNativeColLabels();
|
|
|
|
|
|
|
|
m_grid->Refresh();
|
|
|
|
m_grid->Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::tearDown()
|
|
|
|
{
|
2012-04-29 19:22:10 -04:00
|
|
|
// This is just a hack to continue the rest of the tests to run: if we
|
|
|
|
// destroy the header control while it has capture, this results in an
|
|
|
|
// assert failure and while handling an exception from it more bad things
|
|
|
|
// happen (as it's thrown from a dtor), resulting in simply aborting
|
|
|
|
// everything. So ensure that it doesn't have capture in any case.
|
|
|
|
//
|
|
|
|
// Of course, the right thing to do would be to understand why does it
|
|
|
|
// still have capture when the grid is destroyed sometimes.
|
|
|
|
wxWindow* const win = wxWindow::GetCapture();
|
|
|
|
if ( win )
|
|
|
|
win->ReleaseMouse();
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
wxDELETE(m_grid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::CellEdit()
|
|
|
|
{
|
2013-06-12 20:08:27 -04:00
|
|
|
// TODO on OSX when running the grid test suite solo this works
|
|
|
|
// but not when running it together with other tests
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXOSX__)
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter changing(m_grid, wxEVT_GRID_CELL_CHANGING);
|
|
|
|
EventCounter changed(m_grid, wxEVT_GRID_CELL_CHANGED);
|
|
|
|
EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
m_grid->SetFocus();
|
|
|
|
m_grid->SetGridCursor(1, 1);
|
|
|
|
m_grid->ShowCellEditControl();
|
|
|
|
|
|
|
|
sim.Text("abab");
|
|
|
|
sim.Char(WXK_RETURN);
|
|
|
|
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, created.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, changing.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, changed.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::CellClick()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter lclick(m_grid, wxEVT_GRID_CELL_LEFT_CLICK);
|
|
|
|
EventCounter ldclick(m_grid, wxEVT_GRID_CELL_LEFT_DCLICK);
|
|
|
|
EventCounter rclick(m_grid, wxEVT_GRID_CELL_RIGHT_CLICK);
|
|
|
|
EventCounter rdclick(m_grid, wxEVT_GRID_CELL_RIGHT_DCLICK);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
wxRect rect = m_grid->CellToRect(0, 0);
|
|
|
|
wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
|
2012-03-11 10:32:24 -04:00
|
|
|
point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
|
|
|
|
m_grid->GetColLabelSize())
|
|
|
|
+ wxPoint(2, 2));
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseMove(point);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
|
|
|
|
lclick.Clear();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseDblClick();
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
//A double click event sends a single click event first
|
|
|
|
//test to ensure this still happens in the future
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseClick(wxMOUSE_BTN_RIGHT);
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
|
|
|
|
rclick.Clear();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::CellSelect()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter cell(m_grid, wxEVT_GRID_SELECT_CELL);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
wxRect rect = m_grid->CellToRect(0, 0);
|
|
|
|
wxPoint point = m_grid->CalcScrolledPosition(rect.GetPosition());
|
2012-03-11 10:32:24 -04:00
|
|
|
point = m_grid->ClientToScreen(point + wxPoint(m_grid->GetRowLabelSize(),
|
|
|
|
m_grid->GetColLabelSize())
|
|
|
|
+ wxPoint(4, 4));
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseMove(point);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, cell.GetCount());
|
|
|
|
|
|
|
|
cell.Clear();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
m_grid->SetGridCursor(1, 1);
|
|
|
|
m_grid->GoToCell(1, 0);
|
|
|
|
|
|
|
|
sim.MouseMove(point);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseDblClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(3, cell.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::LabelClick()
|
|
|
|
{
|
2010-09-23 13:02:08 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter lclick(m_grid, wxEVT_GRID_LABEL_LEFT_CLICK);
|
|
|
|
EventCounter ldclick(m_grid, wxEVT_GRID_LABEL_LEFT_DCLICK);
|
|
|
|
EventCounter rclick(m_grid, wxEVT_GRID_LABEL_RIGHT_CLICK);
|
|
|
|
EventCounter rdclick(m_grid, wxEVT_GRID_LABEL_RIGHT_DCLICK);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
wxPoint pos(m_grid->GetRowLabelSize() + 2, 2);
|
|
|
|
pos = m_grid->ClientToScreen(pos);
|
|
|
|
|
|
|
|
sim.MouseMove(pos);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, lclick.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseDblClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, ldclick.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseClick(wxMOUSE_BTN_RIGHT);
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
|
|
|
|
rclick.Clear();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
sim.MouseDblClick(wxMOUSE_BTN_RIGHT);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
if( ms_nativeheader )
|
|
|
|
{
|
|
|
|
//Right double click not supported with native headers so we get two
|
|
|
|
//right click events
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(2, rclick.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rdclick.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::SortClick()
|
|
|
|
{
|
2010-09-23 13:02:08 -04:00
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2010-08-22 18:16:05 -04:00
|
|
|
m_grid->SetSortingColumn(0);
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter sort(m_grid, wxEVT_GRID_COL_SORT);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
wxPoint pos(m_grid->GetRowLabelSize() + 4, 4);
|
|
|
|
pos = m_grid->ClientToScreen(pos);
|
|
|
|
|
|
|
|
sim.MouseMove(pos);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseClick();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, sort.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::Size()
|
|
|
|
{
|
2013-06-12 20:08:27 -04:00
|
|
|
// TODO on OSX resizing interactively works, but not automated
|
2014-09-23 13:42:36 -04:00
|
|
|
// Grid could not pass the test under GTK, OSX, and Universal.
|
|
|
|
// So there may has bug in Grid implementation
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR && !defined(__WXGTK__) && !defined(__WXOSX__) \
|
|
|
|
&& !defined(__WXUNIVERSAL__)
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter colsize(m_grid, wxEVT_GRID_COL_SIZE);
|
|
|
|
EventCounter rowsize(m_grid, wxEVT_GRID_ROW_SIZE);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() +
|
|
|
|
m_grid->GetColSize(0), 5));
|
|
|
|
|
|
|
|
sim.MouseMove(pt);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseDown();
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseMove(pt.x + 50, pt.y);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseUp();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, colsize.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
pt = m_grid->ClientToScreen(wxPoint(5, m_grid->GetColLabelSize() +
|
|
|
|
m_grid->GetRowSize(0)));
|
|
|
|
|
|
|
|
sim.MouseDragDrop(pt.x, pt.y, pt.x, pt.y + 50);
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, rowsize.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::RangeSelect()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter select(m_grid, wxEVT_GRID_RANGE_SELECT);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
//We add the extra 10 to ensure that we are inside the cell
|
|
|
|
wxPoint pt = m_grid->ClientToScreen(wxPoint(m_grid->GetRowLabelSize() + 10,
|
|
|
|
m_grid->GetColLabelSize() + 10)
|
|
|
|
);
|
|
|
|
|
|
|
|
sim.MouseMove(pt);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseDown();
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseMove(pt.x + 50, pt.y + 50);
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.MouseUp();
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1, select.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::Cursor()
|
|
|
|
{
|
|
|
|
m_grid->SetGridCursor(1, 1);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorRow());
|
|
|
|
|
|
|
|
m_grid->MoveCursorDown(false);
|
|
|
|
m_grid->MoveCursorLeft(false);
|
|
|
|
m_grid->MoveCursorUp(false);
|
|
|
|
m_grid->MoveCursorUp(false);
|
|
|
|
m_grid->MoveCursorRight(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
|
|
|
|
|
|
|
|
m_grid->SetCellValue(0, 0, "some text");
|
|
|
|
m_grid->SetCellValue(3, 0, "other text");
|
|
|
|
m_grid->SetCellValue(0, 1, "more text");
|
|
|
|
m_grid->SetCellValue(3, 1, "extra text");
|
|
|
|
|
|
|
|
m_grid->Update();
|
|
|
|
m_grid->Refresh();
|
|
|
|
|
|
|
|
m_grid->MoveCursorLeftBlock(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
|
|
|
|
|
|
|
|
m_grid->MoveCursorDownBlock(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow());
|
|
|
|
|
|
|
|
m_grid->MoveCursorRightBlock(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetGridCursorRow());
|
|
|
|
|
|
|
|
m_grid->MoveCursorUpBlock(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetGridCursorCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetGridCursorRow());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::Selection()
|
|
|
|
{
|
|
|
|
m_grid->SelectAll();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsSelection());
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsInSelection(0, 0));
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1));
|
|
|
|
|
|
|
|
m_grid->SelectBlock(1, 0, 3, 1);
|
|
|
|
|
|
|
|
wxGridCellCoordsArray topleft = m_grid->GetSelectionBlockTopLeft();
|
|
|
|
wxGridCellCoordsArray bottomright = m_grid->GetSelectionBlockBottomRight();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, topleft.Count());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, bottomright.Count());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, topleft.Item(0).GetCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, topleft.Item(0).GetRow());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, bottomright.Item(0).GetCol());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, bottomright.Item(0).GetRow());
|
|
|
|
|
|
|
|
m_grid->SelectCol(1);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsInSelection(0, 1));
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsInSelection(9, 1));
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0));
|
|
|
|
|
|
|
|
m_grid->SelectRow(4);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsInSelection(4, 0));
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsInSelection(4, 1));
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsInSelection(3, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::AddRowCol()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(10, m_grid->GetNumberRows());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_grid->GetNumberCols());
|
|
|
|
|
|
|
|
m_grid->AppendCols();
|
|
|
|
m_grid->AppendRows();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(11, m_grid->GetNumberRows());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetNumberCols());
|
|
|
|
|
|
|
|
m_grid->AppendCols(2);
|
|
|
|
m_grid->AppendRows(2);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(13, m_grid->GetNumberRows());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(5, m_grid->GetNumberCols());
|
|
|
|
|
|
|
|
m_grid->InsertCols(1, 2);
|
|
|
|
m_grid->InsertRows(2, 3);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(16, m_grid->GetNumberRows());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(7, m_grid->GetNumberCols());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::ColumnOrder()
|
|
|
|
{
|
|
|
|
m_grid->AppendCols(2);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(4, m_grid->GetNumberCols());
|
|
|
|
|
|
|
|
wxArrayInt neworder;
|
|
|
|
neworder.push_back(1);
|
|
|
|
neworder.push_back(3);
|
|
|
|
neworder.push_back(2);
|
|
|
|
neworder.push_back(0);
|
|
|
|
|
|
|
|
m_grid->SetColumnsOrder(neworder);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(3));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(0));
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColAt(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColAt(1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColAt(2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColAt(3));
|
|
|
|
|
|
|
|
m_grid->ResetColPos();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(0, m_grid->GetColPos(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_grid->GetColPos(1));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_grid->GetColPos(2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_grid->GetColPos(3));
|
|
|
|
}
|
|
|
|
|
2013-04-24 05:01:57 -04:00
|
|
|
void GridTestCase::ColumnVisibility()
|
|
|
|
{
|
|
|
|
m_grid->AppendCols(3);
|
|
|
|
CPPUNIT_ASSERT( m_grid->IsColShown(1) );
|
|
|
|
|
|
|
|
m_grid->HideCol(1);
|
|
|
|
CPPUNIT_ASSERT( !m_grid->IsColShown(1) );
|
|
|
|
CPPUNIT_ASSERT( m_grid->IsColShown(2) );
|
|
|
|
|
|
|
|
m_grid->ShowCol(1);
|
|
|
|
CPPUNIT_ASSERT( m_grid->IsColShown(1) );
|
|
|
|
}
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
void GridTestCase::LineFormatting()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT(m_grid->GridLinesEnabled());
|
|
|
|
|
|
|
|
m_grid->EnableGridLines(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_grid->GridLinesEnabled());
|
|
|
|
|
|
|
|
m_grid->EnableGridLines();
|
|
|
|
|
|
|
|
m_grid->SetGridLineColour(*wxRED);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(m_grid->GetGridLineColour(), *wxRED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::SortSupport()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_grid->GetSortingColumn());
|
|
|
|
|
|
|
|
m_grid->SetSortingColumn(1);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsSortingBy(0));
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsSortingBy(1));
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsSortOrderAscending());
|
|
|
|
|
|
|
|
m_grid->SetSortingColumn(0, false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsSortingBy(0));
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsSortingBy(1));
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsSortOrderAscending());
|
|
|
|
|
|
|
|
m_grid->UnsetSortingColumn();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsSortingBy(0));
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsSortingBy(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::Labels()
|
|
|
|
{
|
|
|
|
CPPUNIT_ASSERT_EQUAL("A", m_grid->GetColLabelValue(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("1", m_grid->GetRowLabelValue(0));
|
|
|
|
|
|
|
|
m_grid->SetColLabelValue(0, "Column 1");
|
|
|
|
m_grid->SetRowLabelValue(0, "Row 1");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Column 1", m_grid->GetColLabelValue(0));
|
|
|
|
CPPUNIT_ASSERT_EQUAL("Row 1", m_grid->GetRowLabelValue(0));
|
|
|
|
|
|
|
|
m_grid->SetLabelTextColour(*wxGREEN);
|
|
|
|
m_grid->SetLabelBackgroundColour(*wxRED);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetLabelTextColour());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetLabelBackgroundColour());
|
|
|
|
|
|
|
|
m_grid->SetColLabelTextOrientation(wxVERTICAL);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxVERTICAL),
|
|
|
|
static_cast<int>(m_grid->GetColLabelTextOrientation()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::SelectionMode()
|
|
|
|
{
|
|
|
|
//We already test this mode in Select
|
|
|
|
CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectCells,
|
|
|
|
m_grid->GetSelectionMode());
|
|
|
|
|
|
|
|
//Test row selection be selecting a single cell and checking the whole
|
|
|
|
//row is selected
|
|
|
|
m_grid->SetSelectionMode(wxGrid::wxGridSelectRows);
|
|
|
|
m_grid->SelectBlock(3, 1, 3, 1);
|
|
|
|
|
2011-12-29 18:39:27 -05:00
|
|
|
wxArrayInt selectedRows = m_grid->GetSelectedRows();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, selectedRows.Count());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, selectedRows[0]);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectRows,
|
|
|
|
m_grid->GetSelectionMode());
|
|
|
|
|
|
|
|
|
|
|
|
//Test column selection be selecting a single cell and checking the whole
|
|
|
|
//column is selected
|
|
|
|
m_grid->SetSelectionMode(wxGrid::wxGridSelectColumns);
|
|
|
|
m_grid->SelectBlock(3, 1, 3, 1);
|
|
|
|
|
2011-12-29 18:39:27 -05:00
|
|
|
wxArrayInt selectedCols = m_grid->GetSelectedCols();
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, selectedCols.Count());
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, selectedCols[0]);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(wxGrid::wxGridSelectColumns,
|
|
|
|
m_grid->GetSelectionMode());
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::CellFormatting()
|
|
|
|
{
|
|
|
|
//Check that initial alignment is default
|
|
|
|
int horiz, cellhoriz, vert, cellvert;
|
|
|
|
|
|
|
|
m_grid->GetDefaultCellAlignment(&horiz, &vert);
|
|
|
|
m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(cellhoriz, horiz);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(cellvert, vert);
|
|
|
|
|
|
|
|
//Check initial text colour and background colour are default
|
|
|
|
wxColour text, back;
|
|
|
|
|
|
|
|
back = m_grid->GetDefaultCellBackgroundColour();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellBackgroundColour(0, 0));
|
|
|
|
|
|
|
|
back = m_grid->GetDefaultCellTextColour();
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(back, m_grid->GetCellTextColour(0, 0));
|
|
|
|
|
2011-12-24 13:30:52 -05:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
m_grid->SetCellAlignment(wxALIGN_CENTRE, 0, 0);
|
2010-08-22 18:16:05 -04:00
|
|
|
m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellhoriz);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_CENTRE), cellvert);
|
2011-12-24 13:30:52 -05:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
m_grid->SetCellAlignment(0, 0, wxALIGN_LEFT, wxALIGN_BOTTOM);
|
|
|
|
m_grid->GetCellAlignment(0, 0, &cellhoriz, &cellvert);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_LEFT), cellhoriz);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(static_cast<int>(wxALIGN_BOTTOM), cellvert);
|
|
|
|
|
2011-12-24 13:30:52 -05:00
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
|
|
|
m_grid->SetCellTextColour(*wxRED, 0, 0);
|
2010-08-22 18:16:05 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(*wxRED, m_grid->GetCellTextColour(0, 0));
|
2011-12-24 13:30:52 -05:00
|
|
|
#endif // WXWIN_COMPATIBILITY_2_8
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
m_grid->SetCellTextColour(0, 0, *wxGREEN);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(*wxGREEN, m_grid->GetCellTextColour(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::Editable()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
//As the grid is not editable we shouldn't create an editor
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsEditable());
|
|
|
|
|
|
|
|
m_grid->EnableEditing(false);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsEditable());
|
|
|
|
|
|
|
|
m_grid->SetFocus();
|
|
|
|
m_grid->SetGridCursor(1, 1);
|
|
|
|
m_grid->ShowCellEditControl();
|
|
|
|
|
|
|
|
sim.Text("abab");
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.Char(WXK_RETURN);
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void GridTestCase::ReadOnly()
|
|
|
|
{
|
|
|
|
#if wxUSE_UIACTIONSIMULATOR
|
|
|
|
//As the cell is readonly we shouldn't create an editor
|
2012-03-11 10:32:24 -04:00
|
|
|
EventCounter created(m_grid, wxEVT_GRID_EDITOR_CREATED);
|
2010-08-22 18:16:05 -04:00
|
|
|
|
|
|
|
wxUIActionSimulator sim;
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(!m_grid->IsReadOnly(1, 1));
|
|
|
|
|
|
|
|
m_grid->SetReadOnly(1, 1);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsReadOnly(1, 1));
|
|
|
|
|
|
|
|
m_grid->SetFocus();
|
|
|
|
m_grid->SetGridCursor(1, 1);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_grid->IsCurrentCellReadOnly());
|
|
|
|
|
|
|
|
m_grid->ShowCellEditControl();
|
|
|
|
|
|
|
|
sim.Text("abab");
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
sim.Char(WXK_RETURN);
|
|
|
|
wxYield();
|
|
|
|
|
2012-03-11 10:32:24 -04:00
|
|
|
CPPUNIT_ASSERT_EQUAL(0, created.GetCount());
|
2010-08-22 18:16:05 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //wxUSE_GRID
|