KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_rc_tree_model.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <boost/test/unit_test.hpp>
25
26#include <memory>
27
28#include <rc_item.h>
29
30
32{
33public:
35 RC_TREE_MODEL( nullptr, nullptr )
36 {
37 }
38
40 {
41 auto rcItem = std::make_shared<RC_ITEM>();
42 rcItem->SetItems( KIID(), niluuid, niluuid, niluuid );
43
44 auto marker = createNode( nullptr, rcItem, RC_TREE_NODE::MARKER );
45 auto child = createNode( marker, rcItem, RC_TREE_NODE::MAIN_ITEM );
46
47 marker->m_Children.push_back( child );
48 m_tree.push_back( marker );
49 return marker;
50 }
51
53 {
54 std::erase( m_tree, aNode );
55 retireNodeTree( aNode );
56 deleteNodeTree( aNode );
57 }
58};
59
60
61BOOST_AUTO_TEST_SUITE( RCTreeModel )
62
63
64BOOST_AUTO_TEST_CASE( DetachedHandlesBehaveAsInvalid )
65{
67 RC_TREE_NODE* marker = model.AddMarkerWithMainItem();
68 RC_TREE_NODE* child = marker->m_Children.front();
69
70 const wxDataViewItem staleMarker = RC_TREE_MODEL::ToItem( marker );
71 const wxDataViewItem staleChild = RC_TREE_MODEL::ToItem( child );
72
73 model.DetachTopLevel( marker );
74
75 wxDataViewItemArray children;
76
77 BOOST_CHECK( !model.IsContainer( staleMarker ) );
78 BOOST_CHECK( !model.GetParent( staleChild ).IsOk() );
79 BOOST_CHECK_EQUAL( model.GetChildren( staleMarker, children ), 0U );
80 BOOST_CHECK( children.empty() );
81 BOOST_CHECK( RC_TREE_MODEL::ToUUID( staleChild ) == niluuid );
82}
83
84
Definition kiid.h:48
std::vector< RC_TREE_NODE * > m_tree
Definition rc_item.h:354
void retireNodeTree(RC_TREE_NODE *aNode)
Definition rc_item.cpp:279
static wxDataViewItem ToItem(RC_TREE_NODE const *aNode)
Definition rc_item.h:254
RC_TREE_MODEL(EDA_DRAW_FRAME *aParentFrame, wxDataViewCtrl *aView)
Definition rc_item.cpp:256
void deleteNodeTree(RC_TREE_NODE *aNode)
Definition rc_item.cpp:292
RC_TREE_NODE * createNode(RC_TREE_NODE *aParent, const std::shared_ptr< RC_ITEM > &aRcItem, RC_TREE_NODE::NODE_TYPE aType)
Definition rc_item.cpp:265
static KIID ToUUID(wxDataViewItem aItem)
Definition rc_item.cpp:226
std::vector< RC_TREE_NODE * > m_Children
Definition rc_item.h:247
RC_TREE_NODE * AddMarkerWithMainItem()
void DetachTopLevel(RC_TREE_NODE *aNode)
KIID niluuid(0)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
KIBIS_MODEL * model
BOOST_CHECK_EQUAL(result, "25.4")