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
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
class SelStoreTest
|
2008-03-31 11:22:10 -04:00
|
|
|
{
|
|
|
|
public:
|
2021-01-22 16:39:16 -05:00
|
|
|
SelStoreTest()
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(SelStoreTest);
|
2008-03-31 11:22:10 -04:00
|
|
|
};
|
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
const unsigned SelStoreTest::NUM_ITEMS = 10; // NB: must be even
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::SelectItem", "[selstore]")
|
2008-03-31 11:22:10 -04:00
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectItem(0);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == 1 );
|
|
|
|
CHECK( 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);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == 2 );
|
|
|
|
CHECK( 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);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == 1 );
|
|
|
|
CHECK( !m_store.IsSelected(0) );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::SelectRange", "[selstore]")
|
2008-03-31 11:22:10 -04:00
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectRange(0, NUM_ITEMS/2);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == NUM_ITEMS/2 + 1 );
|
|
|
|
CHECK( m_store.IsSelected(0) );
|
|
|
|
CHECK( !m_store.IsSelected(NUM_ITEMS - 1) );
|
2021-01-22 16:32:20 -05:00
|
|
|
|
|
|
|
m_store.SelectRange(NUM_ITEMS/2, NUM_ITEMS - 1);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == NUM_ITEMS );
|
|
|
|
CHECK( m_store.IsSelected(0) );
|
|
|
|
CHECK( m_store.IsSelected(NUM_ITEMS - 1) );
|
2021-01-22 16:32:20 -05:00
|
|
|
|
|
|
|
m_store.SelectRange(1, NUM_ITEMS - 2, false);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == 2 );
|
|
|
|
CHECK( m_store.IsSelected(0) );
|
|
|
|
CHECK( !m_store.IsSelected(NUM_ITEMS/2) );
|
|
|
|
CHECK( m_store.IsSelected(NUM_ITEMS - 1) );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::SetItemCount", "[selstore]")
|
2008-03-31 11:22:10 -04:00
|
|
|
{
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SelectRange(1, NUM_ITEMS - 2);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == NUM_ITEMS - 2 );
|
2008-03-31 11:22:10 -04:00
|
|
|
|
2021-01-22 16:32:20 -05:00
|
|
|
m_store.SetItemCount(NUM_ITEMS/2);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == NUM_ITEMS/2 - 1 );
|
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);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK( m_store.GetSelectedCount() == 1 );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::Clear", "[selstore]")
|
2008-03-31 11:22:10 -04:00
|
|
|
{
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(m_store.IsEmpty());
|
|
|
|
CHECK( m_store.GetSelectedCount() == 0 );
|
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:34:01 -05:00
|
|
|
CHECK(!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:34:01 -05:00
|
|
|
CHECK(m_store.IsEmpty());
|
|
|
|
CHECK( m_store.GetSelectedCount() == 0 );
|
2008-03-31 11:22:10 -04:00
|
|
|
}
|
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::Iterate", "[selstore]")
|
2014-09-27 16:46:15 -04:00
|
|
|
{
|
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:34:01 -05:00
|
|
|
CHECK(NUM_ITEMS/2 - 1 == m_store.GetFirstSelectedItem(cookie));
|
|
|
|
CHECK(NUM_ITEMS/2 == m_store.GetNextSelectedItem(cookie));
|
|
|
|
CHECK(NUM_ITEMS/2 + 1 == m_store.GetNextSelectedItem(cookie));
|
2014-09-27 16:46:15 -04:00
|
|
|
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(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);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(1 == m_store.GetFirstSelectedItem(cookie));
|
2014-09-27 16:46:15 -04:00
|
|
|
}
|
2014-09-27 16:46:21 -04:00
|
|
|
|
2021-01-22 16:39:16 -05:00
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::ItemsAddDelete", "[selstore]")
|
2014-09-27 16:46:21 -04:00
|
|
|
{
|
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);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(m_store.IsSelected(0));
|
|
|
|
CHECK(m_store.IsSelected(NUM_ITEMS/2));
|
|
|
|
CHECK(m_store.IsSelected(NUM_ITEMS));
|
|
|
|
CHECK(m_store.GetSelectedCount() == 3);
|
2021-01-22 16:32:20 -05:00
|
|
|
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(m_store.OnItemsDeleted(NUM_ITEMS/2 - 1, 2));
|
|
|
|
CHECK(m_store.IsSelected(0));
|
|
|
|
CHECK(m_store.IsSelected(NUM_ITEMS - 2));
|
|
|
|
CHECK(m_store.GetSelectedCount() == 2);
|
2021-01-22 16:32:20 -05:00
|
|
|
|
|
|
|
m_store.OnItemsInserted(0, 2);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(m_store.IsSelected(2));
|
|
|
|
CHECK(m_store.IsSelected(NUM_ITEMS));
|
|
|
|
CHECK(m_store.GetSelectedCount() == 2);
|
2021-01-22 16:32:20 -05:00
|
|
|
|
|
|
|
m_store.OnItemDelete(0);
|
|
|
|
|
|
|
|
m_store.SelectRange(0, NUM_ITEMS - 1);
|
2021-01-22 16:34:01 -05:00
|
|
|
CHECK(m_store.OnItemsDeleted(0, NUM_ITEMS/2));
|
|
|
|
CHECK(m_store.GetSelectedCount() == NUM_ITEMS/2);
|
|
|
|
CHECK(m_store.IsSelected(0));
|
|
|
|
CHECK(m_store.IsSelected(NUM_ITEMS/2));
|
2014-09-27 16:46:21 -04:00
|
|
|
}
|
2021-01-22 16:59:29 -05:00
|
|
|
|
|
|
|
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::InsertInSelected", "[selstore]")
|
|
|
|
{
|
|
|
|
m_store.SelectRange(0, NUM_ITEMS - 1);
|
|
|
|
CHECK( m_store.GetSelectedCount() == NUM_ITEMS );
|
|
|
|
|
|
|
|
// Newly inserted items shouldn't be selected, even if all the existing
|
|
|
|
// ones are.
|
|
|
|
m_store.OnItemsInserted(1, 3);
|
|
|
|
CHECK( !m_store.IsSelected(1) );
|
|
|
|
CHECK( !m_store.IsSelected(2) );
|
|
|
|
CHECK( !m_store.IsSelected(3) );
|
|
|
|
CHECK( m_store.GetSelectedCount() == NUM_ITEMS );
|
|
|
|
}
|