Merge in from trunk r64802 - r68625
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68626 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
140
tests/controls/dataviewctrltest.cpp
Normal file
140
tests/controls/dataviewctrltest.cpp
Normal file
@@ -0,0 +1,140 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/controls/treectrltest.cpp
|
||||
// Purpose: wxDataViewCtrl unit test
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2011-08-08
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2011 Vaclav Slavik <vslavik@gmail.com>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#if wxUSE_DATAVIEWCTRL
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "wx/app.h"
|
||||
#include "wx/dataview.h"
|
||||
|
||||
#include "testableframe.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class DataViewCtrlTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
DataViewCtrlTestCase() { }
|
||||
|
||||
virtual void setUp();
|
||||
virtual void tearDown();
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( DataViewCtrlTestCase );
|
||||
CPPUNIT_TEST( DeleteSelected );
|
||||
CPPUNIT_TEST( DeleteNotSelected );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void DeleteSelected();
|
||||
void DeleteNotSelected();
|
||||
|
||||
// the dataview control itself
|
||||
wxDataViewTreeCtrl *m_dvc;
|
||||
|
||||
// and some of its items
|
||||
wxDataViewItem m_root,
|
||||
m_child1,
|
||||
m_child2,
|
||||
m_grandchild;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(DataViewCtrlTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( DataViewCtrlTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DataViewCtrlTestCase, "DataViewCtrlTestCase" );
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test initialization
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DataViewCtrlTestCase::setUp()
|
||||
{
|
||||
m_dvc = new wxDataViewTreeCtrl(wxTheApp->GetTopWindow(),
|
||||
wxID_ANY,
|
||||
wxDefaultPosition,
|
||||
wxSize(400, 200),
|
||||
wxDV_MULTIPLE);
|
||||
|
||||
m_root = m_dvc->AppendContainer(wxDataViewItem(), "The root");
|
||||
m_child1 = m_dvc->AppendContainer(m_root, "child1");
|
||||
m_grandchild = m_dvc->AppendItem(m_child1, "grandchild");
|
||||
m_child2 = m_dvc->AppendItem(m_root, "child2");
|
||||
|
||||
m_dvc->SetSize(400, 200);
|
||||
m_dvc->ExpandAncestors(m_root);
|
||||
m_dvc->Refresh();
|
||||
m_dvc->Update();
|
||||
}
|
||||
|
||||
void DataViewCtrlTestCase::tearDown()
|
||||
{
|
||||
delete m_dvc;
|
||||
m_dvc = NULL;
|
||||
|
||||
m_root =
|
||||
m_child1 =
|
||||
m_child2 =
|
||||
m_grandchild = wxDataViewItem();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// the tests themselves
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void DataViewCtrlTestCase::DeleteSelected()
|
||||
{
|
||||
wxDataViewItemArray sel;
|
||||
sel.push_back(m_child1);
|
||||
sel.push_back(m_grandchild);
|
||||
sel.push_back(m_child2);
|
||||
m_dvc->SetSelections(sel);
|
||||
|
||||
// delete a selected item
|
||||
m_dvc->DeleteItem(m_child1);
|
||||
|
||||
m_dvc->GetSelections(sel);
|
||||
|
||||
// m_child1 and its children should be removed from the selection now
|
||||
CPPUNIT_ASSERT( sel.size() == 1 );
|
||||
CPPUNIT_ASSERT( sel[0] == m_child2 );
|
||||
}
|
||||
|
||||
void DataViewCtrlTestCase::DeleteNotSelected()
|
||||
{
|
||||
wxDataViewItemArray sel;
|
||||
sel.push_back(m_child1);
|
||||
sel.push_back(m_grandchild);
|
||||
m_dvc->SetSelections(sel);
|
||||
|
||||
// delete unselected item
|
||||
m_dvc->DeleteItem(m_child2);
|
||||
|
||||
m_dvc->GetSelections(sel);
|
||||
|
||||
// m_child1 and its children should be removed from the selection now
|
||||
CPPUNIT_ASSERT( sel.size() == 2 );
|
||||
CPPUNIT_ASSERT( sel[0] == m_child1 );
|
||||
CPPUNIT_ASSERT( sel[1] == m_grandchild );
|
||||
}
|
||||
|
||||
#endif //wxUSE_TREECTRL
|
@@ -59,6 +59,9 @@ private:
|
||||
CPPUNIT_TEST( Style );
|
||||
CPPUNIT_TEST( Lines );
|
||||
CPPUNIT_TEST( LogTextCtrl );
|
||||
CPPUNIT_TEST( PositionToCoords );
|
||||
CPPUNIT_TEST( PositionToCoordsRich );
|
||||
CPPUNIT_TEST( PositionToCoordsRich2 );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void MultiLineReplace();
|
||||
@@ -71,6 +74,11 @@ private:
|
||||
void Style();
|
||||
void Lines();
|
||||
void LogTextCtrl();
|
||||
void PositionToCoords();
|
||||
void PositionToCoordsRich();
|
||||
void PositionToCoordsRich2();
|
||||
|
||||
void DoPositionToCoordsTestWithStyle(long style);
|
||||
|
||||
wxTextCtrl *m_text;
|
||||
|
||||
@@ -380,7 +388,6 @@ void TextCtrlTestCase::Style()
|
||||
|
||||
void TextCtrlTestCase::Lines()
|
||||
{
|
||||
#ifndef __WXOSX__
|
||||
delete m_text;
|
||||
m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
|
||||
wxDefaultPosition, wxSize(400, 200), wxTE_MULTILINE | wxTE_DONTWRAP);
|
||||
@@ -399,6 +406,17 @@ void TextCtrlTestCase::Lines()
|
||||
CPPUNIT_ASSERT_EQUAL(5, m_text->GetNumberOfLines());
|
||||
CPPUNIT_ASSERT_EQUAL(0, m_text->GetLineLength(3));
|
||||
CPPUNIT_ASSERT_EQUAL("", m_text->GetLineText(3));
|
||||
|
||||
// Verify that wrapped lines count as 2 lines.
|
||||
//
|
||||
// This currently doesn't work neither in wxGTK nor wxOSX/Cocoa, see
|
||||
// #12366, where GetNumberOfLines() always returns the number of logical,
|
||||
// not physical, lines.
|
||||
m_text->AppendText("\n" + wxString(50, '1') + ' ' + wxString(50, '2'));
|
||||
#if defined(__WXGTK__) || defined(__WXOSX_COCOA__)
|
||||
CPPUNIT_ASSERT_EQUAL(6, m_text->GetNumberOfLines());
|
||||
#else
|
||||
CPPUNIT_ASSERT_EQUAL(7, m_text->GetNumberOfLines());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -422,4 +440,98 @@ void TextCtrlTestCase::LogTextCtrl()
|
||||
CPPUNIT_ASSERT(!m_text->IsEmpty());
|
||||
}
|
||||
|
||||
void TextCtrlTestCase::PositionToCoords()
|
||||
{
|
||||
DoPositionToCoordsTestWithStyle(0);
|
||||
}
|
||||
|
||||
void TextCtrlTestCase::PositionToCoordsRich()
|
||||
{
|
||||
DoPositionToCoordsTestWithStyle(wxTE_RICH);
|
||||
}
|
||||
|
||||
void TextCtrlTestCase::PositionToCoordsRich2()
|
||||
{
|
||||
DoPositionToCoordsTestWithStyle(wxTE_RICH2);
|
||||
}
|
||||
|
||||
void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style)
|
||||
{
|
||||
static const int TEXT_HEIGHT = 200;
|
||||
|
||||
delete m_text;
|
||||
m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
|
||||
wxDefaultPosition, wxSize(400, TEXT_HEIGHT),
|
||||
wxTE_MULTILINE | style);
|
||||
|
||||
// Asking for invalid index should fail.
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(1) );
|
||||
|
||||
// Getting position shouldn't return wxDefaultPosition except if the method
|
||||
// is not implemented at all in the current port.
|
||||
const wxPoint pos0 = m_text->PositionToCoords(0);
|
||||
if ( pos0 == wxDefaultPosition )
|
||||
{
|
||||
#if defined(__WXMSW__) || defined(__WXGTK20__)
|
||||
CPPUNIT_FAIL( "PositionToCoords() unexpectedly failed." );
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
CPPUNIT_ASSERT(pos0.x >= 0);
|
||||
CPPUNIT_ASSERT(pos0.y >= 0);
|
||||
|
||||
|
||||
m_text->SetValue("Hello");
|
||||
wxYield(); // Let GTK layout the control correctly.
|
||||
|
||||
// Position of non-first character should be positive.
|
||||
const long posHello4 = m_text->PositionToCoords(4).x;
|
||||
CPPUNIT_ASSERT( posHello4 > 0 );
|
||||
|
||||
// Asking for position beyond the last character should succeed and return
|
||||
// reasonable result.
|
||||
CPPUNIT_ASSERT( m_text->PositionToCoords(5).x > posHello4 );
|
||||
|
||||
// But asking for the next position should fail.
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( m_text->PositionToCoords(6) );
|
||||
|
||||
// Test getting the coordinates of the last character when it is in the
|
||||
// beginning of a new line to exercise MSW code which has specific logic
|
||||
// for it.
|
||||
m_text->AppendText("\n");
|
||||
const wxPoint posLast = m_text->PositionToCoords(m_text->GetLastPosition());
|
||||
CPPUNIT_ASSERT_EQUAL( pos0.x, posLast.x );
|
||||
CPPUNIT_ASSERT( posLast.y > 0 );
|
||||
|
||||
|
||||
// Add enough contents to the control to make sure it has a scrollbar.
|
||||
m_text->SetValue("First line" + wxString(50, '\n') + "Last line");
|
||||
m_text->SetInsertionPoint(0);
|
||||
wxYield(); // Let GTK layout the control correctly.
|
||||
|
||||
// This shouldn't change anything for the first position coordinates.
|
||||
CPPUNIT_ASSERT_EQUAL( pos0, m_text->PositionToCoords(0) );
|
||||
|
||||
// And the last one must be beyond the window boundary and so not be
|
||||
// visible -- but getting its coordinate should still work.
|
||||
CPPUNIT_ASSERT
|
||||
(
|
||||
m_text->PositionToCoords(m_text->GetLastPosition()).y > TEXT_HEIGHT
|
||||
);
|
||||
|
||||
|
||||
// Now make it scroll to the end and check that the first position now has
|
||||
// negative offset as its above the visible part of the window while the
|
||||
// last position is in its bounds.
|
||||
m_text->SetInsertionPointEnd();
|
||||
|
||||
CPPUNIT_ASSERT( m_text->PositionToCoords(0).y < 0 );
|
||||
CPPUNIT_ASSERT
|
||||
(
|
||||
m_text->PositionToCoords(m_text->GetInsertionPoint()).y <= TEXT_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#endif //wxUSE_TEXTCTRL
|
||||
|
Reference in New Issue
Block a user