2008-03-31 11:22:10 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/misc/selstoretest.cpp
|
|
|
|
// Purpose: wxSelectionStore unit test
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Created: 2008-03-31
|
|
|
|
// Copyright: (c) 2008 Vadim Zeitlin
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "wx/selstore.h"
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SelStoreTestCase : public CppUnit::TestCase
|
|
|
|
{
|
|
|
|
public:
|
2021-01-22 16:32:20 -05:00
|
|
|
SelStoreTestCase() { }
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2018-07-29 05:09:17 -04:00
|
|
|
virtual void setUp() wxOVERRIDE
|
2008-03-31 11:22:10 -04:00
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SetItemCount(NUM_ITEMS);
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CPPUNIT_TEST_SUITE( SelStoreTestCase );
|
|
|
|
CPPUNIT_TEST( SelectItem );
|
|
|
|
CPPUNIT_TEST( SelectRange );
|
|
|
|
CPPUNIT_TEST( SetItemCount );
|
|
|
|
CPPUNIT_TEST( Clear );
|
2014-09-27 16:46:15 -04:00
|
|
|
CPPUNIT_TEST( Iterate );
|
2014-09-27 16:46:21 -04:00
|
|
|
CPPUNIT_TEST( ItemsAddDelete );
|
2008-03-31 11:22:10 -04:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
void SelectItem();
|
|
|
|
void SelectRange();
|
|
|
|
void SetItemCount();
|
|
|
|
void Clear();
|
2014-09-27 16:46:15 -04:00
|
|
|
void Iterate();
|
2014-09-27 16:46:21 -04:00
|
|
|
void ItemsAddDelete();
|
2008-03-31 11:22:10 -04:00
|
|
|
|
|
|
|
// NB: must be even
|
|
|
|
static const unsigned NUM_ITEMS;
|
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
wxSelectionStore m_store;
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_NO_COPY_CLASS(SelStoreTestCase);
|
2008-03-31 11:22:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( SelStoreTestCase );
|
|
|
|
|
2011-04-30 06:57:04 -04:00
|
|
|
// also include in its own registry so that these tests can be run alone
|
2008-03-31 11:22:10 -04:00
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SelStoreTestCase, "SelStoreTestCase" );
|
|
|
|
|
|
|
|
const unsigned SelStoreTestCase::NUM_ITEMS = 10; // NB: must be even
|
|
|
|
|
|
|
|
void SelStoreTestCase::SelectItem()
|
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(0);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u, m_store.GetSelectedCount() );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(0) );
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(NUM_ITEMS - 1);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u, m_store.GetSelectedCount() );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(NUM_ITEMS - 1) );
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(0, false);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u, m_store.GetSelectedCount() );
|
|
|
|
CPPUNIT_ASSERT( !m_store.IsSelected(0) );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelStoreTestCase::SelectRange()
|
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectRange(0, NUM_ITEMS/2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( NUM_ITEMS/2 + 1, m_store.GetSelectedCount() );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(0) );
|
|
|
|
CPPUNIT_ASSERT( !m_store.IsSelected(NUM_ITEMS - 1) );
|
|
|
|
|
|
|
|
m_store.SelectRange(NUM_ITEMS/2, NUM_ITEMS - 1);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( NUM_ITEMS, m_store.GetSelectedCount() );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(0) );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(NUM_ITEMS - 1) );
|
|
|
|
|
|
|
|
m_store.SelectRange(1, NUM_ITEMS - 2, false);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 2u, m_store.GetSelectedCount() );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(0) );
|
|
|
|
CPPUNIT_ASSERT( !m_store.IsSelected(NUM_ITEMS/2) );
|
|
|
|
CPPUNIT_ASSERT( m_store.IsSelected(NUM_ITEMS - 1) );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelStoreTestCase::SetItemCount()
|
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectRange(1, NUM_ITEMS - 2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( NUM_ITEMS - 2, m_store.GetSelectedCount() );
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SetItemCount(NUM_ITEMS/2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( NUM_ITEMS/2 - 1, m_store.GetSelectedCount() );
|
2008-03-31 11:22:10 -04:00
|
|
|
|
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.Clear();
|
|
|
|
m_store.SetItemCount(NUM_ITEMS);
|
2008-03-31 11:22:10 -04:00
|
|
|
|
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(NUM_ITEMS/2 - 1);
|
|
|
|
m_store.SelectItem(NUM_ITEMS/2 + 1);
|
|
|
|
m_store.SetItemCount(NUM_ITEMS/2);
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 1u, m_store.GetSelectedCount() );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SelStoreTestCase::Clear()
|
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
CPPUNIT_ASSERT(m_store.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u, m_store.GetSelectedCount() );
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(0);
|
2014-09-27 16:46:18 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
CPPUNIT_ASSERT(!m_store.IsEmpty());
|
2014-09-27 16:46:18 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.Clear();
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
CPPUNIT_ASSERT(m_store.IsEmpty());
|
|
|
|
CPPUNIT_ASSERT_EQUAL( 0u, m_store.GetSelectedCount() );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
2014-09-27 16:46:15 -04:00
|
|
|
void SelStoreTestCase::Iterate()
|
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectRange(NUM_ITEMS/2 - 1, NUM_ITEMS/2 + 1);
|
2014-09-27 16:46:15 -04:00
|
|
|
|
|
|
|
wxSelectionStore::IterationState cookie;
|
2021-01-22 16:32:20 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(NUM_ITEMS/2 - 1, m_store.GetFirstSelectedItem(cookie));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(NUM_ITEMS/2, m_store.GetNextSelectedItem(cookie));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(NUM_ITEMS/2 + 1, m_store.GetNextSelectedItem(cookie));
|
2014-09-27 16:46:15 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
CPPUNIT_ASSERT_EQUAL(wxSelectionStore::NO_SELECTION, m_store.GetNextSelectedItem(cookie));
|
2014-09-27 16:46:15 -04:00
|
|
|
|
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectRange(0, NUM_ITEMS - 1);
|
|
|
|
m_store.SelectItem(0, false);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(1, m_store.GetFirstSelectedItem(cookie));
|
2014-09-27 16:46:15 -04:00
|
|
|
}
|
2014-09-27 16:46:21 -04:00
|
|
|
|
|
|
|
void SelStoreTestCase::ItemsAddDelete()
|
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(0);
|
|
|
|
m_store.SelectItem(NUM_ITEMS/2);
|
|
|
|
m_store.SelectItem(NUM_ITEMS - 1);
|
|
|
|
|
|
|
|
m_store.OnItemsInserted(NUM_ITEMS/2 + 1, 1);
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(0));
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(NUM_ITEMS/2));
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(NUM_ITEMS));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(3, m_store.GetSelectedCount());
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(m_store.OnItemsDeleted(NUM_ITEMS/2 - 1, 2));
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(0));
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(NUM_ITEMS - 2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_store.GetSelectedCount());
|
|
|
|
|
|
|
|
m_store.OnItemsInserted(0, 2);
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(2));
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(NUM_ITEMS));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2, m_store.GetSelectedCount());
|
|
|
|
|
|
|
|
m_store.OnItemDelete(0);
|
|
|
|
|
|
|
|
m_store.SelectRange(0, NUM_ITEMS - 1);
|
|
|
|
CPPUNIT_ASSERT(m_store.OnItemsDeleted(0, NUM_ITEMS/2));
|
|
|
|
CPPUNIT_ASSERT_EQUAL(NUM_ITEMS/2, m_store.GetSelectedCount());
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(0));
|
|
|
|
CPPUNIT_ASSERT(m_store.IsSelected(NUM_ITEMS/2));
|
2014-09-27 16:46:21 -04:00
|
|
|
}
|