2009-01-17 08:16:25 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/controls/treectrltest.cpp
|
|
|
|
// Purpose: wxTreeCtrl unit test
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2008-11-26
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/treectrl.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TreeCtrlTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TreeCtrlTestCase() { }
|
|
|
|
|
|
|
|
virtual void setUp();
|
|
|
|
virtual void tearDown();
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( TreeCtrlTestCase );
|
|
|
|
CPPUNIT_TEST( HasChildren );
|
2009-06-06 10:15:06 -04:00
|
|
|
CPPUNIT_TEST( SelectItemSingle );
|
|
|
|
CPPUNIT_TEST( PseudoTest_MultiSelect );
|
|
|
|
CPPUNIT_TEST( SelectItemMulti );
|
2009-01-17 08:16:25 -05:00
|
|
|
CPPUNIT_TEST( PseudoTest_SetHiddenRoot );
|
|
|
|
CPPUNIT_TEST( HasChildren );
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void HasChildren();
|
2009-06-06 10:15:06 -04:00
|
|
|
void SelectItemSingle();
|
|
|
|
void SelectItemMulti();
|
|
|
|
void PseudoTest_MultiSelect() { ms_multiSelect = true; }
|
2009-01-17 08:16:25 -05:00
|
|
|
void PseudoTest_SetHiddenRoot() { ms_hiddenRoot = true; }
|
|
|
|
|
2009-06-06 10:15:06 -04:00
|
|
|
static bool ms_multiSelect;
|
2009-01-17 08:16:25 -05:00
|
|
|
static bool ms_hiddenRoot;
|
|
|
|
|
2009-06-06 10:15:06 -04:00
|
|
|
// the tree control itself
|
2009-01-17 08:16:25 -05:00
|
|
|
wxTreeCtrl *m_tree;
|
|
|
|
|
2009-06-06 10:15:06 -04:00
|
|
|
// and some of its items
|
|
|
|
wxTreeItemId m_root,
|
|
|
|
m_child1,
|
|
|
|
m_child2,
|
|
|
|
m_grandchild;
|
|
|
|
|
2009-01-17 08:16:25 -05:00
|
|
|
DECLARE_NO_COPY_CLASS(TreeCtrlTestCase)
|
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( TreeCtrlTestCase );
|
|
|
|
|
|
|
|
// also include in it's own registry so that these tests can be run alone
|
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TreeCtrlTestCase, "TreeCtrlTestCase" );
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test initialization
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-06-06 10:15:06 -04:00
|
|
|
bool TreeCtrlTestCase::ms_multiSelect = false;
|
2009-01-17 08:16:25 -05:00
|
|
|
bool TreeCtrlTestCase::ms_hiddenRoot = false;
|
|
|
|
|
|
|
|
void TreeCtrlTestCase::setUp()
|
|
|
|
{
|
|
|
|
m_tree = new wxTreeCtrl(wxTheApp->GetTopWindow());
|
2009-06-06 10:15:06 -04:00
|
|
|
|
|
|
|
if ( ms_multiSelect )
|
|
|
|
m_tree->ToggleWindowStyle(wxTR_MULTIPLE);
|
|
|
|
|
2009-01-17 08:16:25 -05:00
|
|
|
if ( ms_hiddenRoot )
|
|
|
|
m_tree->ToggleWindowStyle(wxTR_HIDE_ROOT); // actually set it
|
2009-06-06 10:15:06 -04:00
|
|
|
|
|
|
|
m_root = m_tree->AddRoot("root");
|
|
|
|
m_child1 = m_tree->AppendItem(m_root, "child1");
|
|
|
|
m_child2 = m_tree->AppendItem(m_root, "child2");
|
|
|
|
m_grandchild = m_tree->AppendItem(m_child1, "grandchild");
|
2009-01-17 08:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TreeCtrlTestCase::tearDown()
|
|
|
|
{
|
|
|
|
delete m_tree;
|
|
|
|
m_tree = NULL;
|
2009-06-06 10:15:06 -04:00
|
|
|
|
|
|
|
m_root =
|
|
|
|
m_child1 =
|
|
|
|
m_child2 =
|
|
|
|
m_grandchild = wxTreeItemId();
|
2009-01-17 08:16:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the tests themselves
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void TreeCtrlTestCase::HasChildren()
|
|
|
|
{
|
2009-06-06 10:15:06 -04:00
|
|
|
CPPUNIT_ASSERT( m_tree->HasChildren(m_root) );
|
|
|
|
CPPUNIT_ASSERT( m_tree->HasChildren(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( !m_tree->HasChildren(m_child2) );
|
|
|
|
CPPUNIT_ASSERT( !m_tree->HasChildren(m_grandchild) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void TreeCtrlTestCase::SelectItemSingle()
|
|
|
|
{
|
|
|
|
// this test should be only ran in single-selection control
|
|
|
|
CPPUNIT_ASSERT( !m_tree->HasFlag(wxTR_MULTIPLE) );
|
|
|
|
|
|
|
|
// initially nothing is selected
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
|
|
|
|
|
|
|
|
// selecting an item should make it selected
|
|
|
|
m_tree->SelectItem(m_child1);
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child1) );
|
|
|
|
|
|
|
|
// selecting it again shouldn't change anything
|
|
|
|
m_tree->SelectItem(m_child1);
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child1) );
|
|
|
|
|
|
|
|
// selecting another item should switch the selection to it
|
|
|
|
m_tree->SelectItem(m_child2);
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) );
|
|
|
|
|
|
|
|
// selecting it again still shouldn't change anything
|
|
|
|
m_tree->SelectItem(m_child2);
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) );
|
|
|
|
|
|
|
|
// deselecting an item should remove the selection entirely
|
|
|
|
m_tree->UnselectItem(m_child2);
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child2) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void TreeCtrlTestCase::SelectItemMulti()
|
|
|
|
{
|
|
|
|
// this test should be only ran in multi-selection control
|
|
|
|
CPPUNIT_ASSERT( m_tree->HasFlag(wxTR_MULTIPLE) );
|
|
|
|
|
|
|
|
// initially nothing is selected
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
|
|
|
|
|
|
|
|
// selecting an item should make it selected
|
|
|
|
m_tree->SelectItem(m_child1);
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child1) );
|
|
|
|
|
|
|
|
// selecting it again shouldn't change anything
|
|
|
|
m_tree->SelectItem(m_child1);
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child1) );
|
|
|
|
|
|
|
|
// selecting another item shouldn't deselect the previously selected one
|
|
|
|
m_tree->SelectItem(m_child2);
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) );
|
|
|
|
|
|
|
|
// selecting it again still shouldn't change anything
|
|
|
|
m_tree->SelectItem(m_child2);
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) );
|
|
|
|
|
|
|
|
// deselecting one of the items should leave the others selected
|
|
|
|
m_tree->UnselectItem(m_child1);
|
|
|
|
CPPUNIT_ASSERT( !m_tree->IsSelected(m_child1) );
|
|
|
|
CPPUNIT_ASSERT( m_tree->IsSelected(m_child2) );
|
2009-01-17 08:16:25 -05:00
|
|
|
}
|
|
|
|
|