KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_wx_dataviewctrl.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#define BOOST_TEST_NO_MAIN
21#include <boost/test/unit_test.hpp>
22
24
25
26BOOST_AUTO_TEST_SUITE( WxDataViewCtrl )
27
28
29namespace
30{
31// The canceller only exercises notification plumbing, so the accessors can be inert stubs.
32class EMPTY_MODEL : public wxDataViewModel
33{
34public:
35 void GetValue( wxVariant&, const wxDataViewItem&, unsigned int ) const override {}
36 bool SetValue( const wxVariant&, const wxDataViewItem&, unsigned int ) override { return false; }
37 wxDataViewItem GetParent( const wxDataViewItem& ) const override { return wxDataViewItem(); }
38 bool IsContainer( const wxDataViewItem& ) const override { return false; }
39 unsigned int GetChildren( const wxDataViewItem&, wxDataViewItemArray& ) const override
40 {
41 return 0;
42 }
43};
44} // namespace
45
46
47// Must fire on every item-removing notification (#24246 / #24805 crash) and stay silent on adds
48// and value changes, which leave the pending scroll valid.
49BOOST_AUTO_TEST_CASE( EnsureVisibleCancellerFiresOnItemRemoval )
50{
51 EMPTY_MODEL* model = new EMPTY_MODEL; // wxRefCounter starts owned at refcount 1
52 int cancels = 0;
53
54 model->AddNotifier( new WX_ENSURE_VISIBLE_CANCELLER( [&]() { cancels++; } ) );
55
56 const wxDataViewItem root;
57 const wxDataViewItem item( reinterpret_cast<void*>( 0x1 ) );
58
59 model->ItemAdded( root, item );
60 BOOST_CHECK_EQUAL( cancels, 0 );
61
62 model->ItemChanged( item );
63 BOOST_CHECK_EQUAL( cancels, 0 );
64
65 model->ItemDeleted( root, item );
66 BOOST_CHECK_EQUAL( cancels, 1 );
67
68 wxDataViewItemArray items;
69 items.Add( item );
70 model->ItemsDeleted( root, items );
71 BOOST_CHECK_EQUAL( cancels, 2 );
72
73 model->Cleared();
74 BOOST_CHECK_EQUAL( cancels, 3 );
75
76 // BeforeReset drops the scroll while items are live; AfterReset defaults to Cleared.
77 model->BeforeReset();
78 BOOST_CHECK_EQUAL( cancels, 4 );
79
80 model->AfterReset();
81 BOOST_CHECK_EQUAL( cancels, 5 );
82
83 model->DecRef(); // deletes the model, which deletes the notifier
84}
85
86
A wxDataViewModelNotifier that runs a callback whenever the model removes items or resets.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
KIBIS_MODEL * model
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(EnsureVisibleCancellerFiresOnItemRemoval)