mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Add QA for COMMMIT/SCH_COMMIT/BOARD_COMMIT
This commit is contained in:
parent
a9121d4cd1
commit
58c9893a3f
@ -35,6 +35,7 @@ set( QA_COMMON_SRCS
|
||||
test_bitmap_base.cpp
|
||||
test_collector.cpp
|
||||
test_color4d.cpp
|
||||
test_commit.cpp
|
||||
test_coroutine.cpp
|
||||
test_eda_shape.cpp
|
||||
test_eda_text.cpp
|
||||
|
116
qa/tests/common/test_commit.cpp
Normal file
116
qa/tests/common/test_commit.cpp
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <commit.h>
|
||||
#include <undo_redo_container.h>
|
||||
#include <eda_item.h>
|
||||
|
||||
// Minimal EDA_ITEM for testing
|
||||
class TEST_EDA_ITEM : public EDA_ITEM
|
||||
{
|
||||
public:
|
||||
TEST_EDA_ITEM( KICAD_T aType ) : EDA_ITEM( aType ) {}
|
||||
|
||||
wxString GetClass() const override { return wxT( "TEST_EDA_ITEM" ); }
|
||||
|
||||
EDA_ITEM* Clone() const override { return new TEST_EDA_ITEM( Type() ); }
|
||||
};
|
||||
|
||||
// Simple COMMIT implementation for testing
|
||||
class TEST_COMMIT : public COMMIT
|
||||
{
|
||||
public:
|
||||
void Push( const wxString&, int ) override {}
|
||||
void Revert() override {}
|
||||
|
||||
private:
|
||||
EDA_ITEM* parentObject( EDA_ITEM* aItem ) const override { return aItem; }
|
||||
EDA_ITEM* makeImage( EDA_ITEM* aItem ) const override { return aItem->Clone(); }
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( Commit )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( StageAndStatus )
|
||||
{
|
||||
TEST_COMMIT commit;
|
||||
TEST_EDA_ITEM itemAdd( PCB_T );
|
||||
TEST_EDA_ITEM itemRemove( PCB_T );
|
||||
TEST_EDA_ITEM itemModify( PCB_T );
|
||||
|
||||
commit.Add( &itemAdd );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &itemAdd ), CHT_ADD );
|
||||
|
||||
commit.Remove( &itemRemove );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &itemRemove ), CHT_REMOVE );
|
||||
|
||||
commit.Modify( &itemModify );
|
||||
TEST_EDA_ITEM* copy = static_cast<TEST_EDA_ITEM*>( itemModify.Clone() );
|
||||
commit.Modified( &itemModify, copy );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &itemModify ), CHT_MODIFY );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( StageContainers )
|
||||
{
|
||||
TEST_COMMIT commit;
|
||||
TEST_EDA_ITEM a( PCB_T );
|
||||
TEST_EDA_ITEM b( PCB_T );
|
||||
std::vector<EDA_ITEM*> items = { &a, &b };
|
||||
|
||||
commit.Stage( items, CHT_ADD );
|
||||
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &a ), CHT_ADD );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &b ), CHT_ADD );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( StagePickedItemsList )
|
||||
{
|
||||
TEST_COMMIT commit;
|
||||
TEST_EDA_ITEM newItem( PCB_T );
|
||||
TEST_EDA_ITEM modItem( PCB_T );
|
||||
TEST_EDA_ITEM* modCopy = static_cast<TEST_EDA_ITEM*>( modItem.Clone() );
|
||||
|
||||
PICKED_ITEMS_LIST list;
|
||||
ITEM_PICKER p1( nullptr, &newItem, UNDO_REDO::NEWITEM );
|
||||
list.PushItem( p1 );
|
||||
|
||||
ITEM_PICKER p2( nullptr, &modItem, UNDO_REDO::CHANGED );
|
||||
p2.SetLink( modCopy );
|
||||
list.PushItem( p2 );
|
||||
|
||||
commit.Stage( list );
|
||||
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &newItem ), CHT_ADD );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &modItem ), CHT_MODIFY );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( UnstageRemovesNewItem )
|
||||
{
|
||||
TEST_COMMIT commit;
|
||||
TEST_EDA_ITEM* item = new TEST_EDA_ITEM( PCB_T );
|
||||
item->SetFlags( IS_NEW );
|
||||
|
||||
commit.Add( item );
|
||||
commit.Unstage( item, nullptr );
|
||||
|
||||
BOOST_CHECK( commit.Empty() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -77,6 +77,7 @@ set( QA_EESCHEMA_SRCS
|
||||
test_ee_item.cpp
|
||||
test_incremental_netlister.cpp
|
||||
test_legacy_power_symbols.cpp
|
||||
test_sch_commit.cpp
|
||||
test_sch_group.cpp
|
||||
test_pin_numbers.cpp
|
||||
test_sch_netclass.cpp
|
||||
|
61
qa/tests/eeschema/test_sch_commit.cpp
Normal file
61
qa/tests/eeschema/test_sch_commit.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <sch_commit.h>
|
||||
#include <sch_group.h>
|
||||
#include <sch_text.h>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( SchCommit )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( RecursesThroughGroups )
|
||||
{
|
||||
TOOL_MANAGER mgr;
|
||||
SCH_COMMIT commit( &mgr );
|
||||
|
||||
SCH_TEXT t1;
|
||||
SCH_TEXT t2;
|
||||
SCH_GROUP group;
|
||||
group.AddItem( &t1 );
|
||||
group.AddItem( &t2 );
|
||||
|
||||
commit.Stage( &group, CHT_MODIFY, nullptr, RECURSE_MODE::RECURSE );
|
||||
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &t1 ), CHT_MODIFY );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &t2 ), CHT_MODIFY );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ClearsSelectedByDragFlag )
|
||||
{
|
||||
TOOL_MANAGER mgr;
|
||||
SCH_COMMIT commit( &mgr );
|
||||
|
||||
SCH_TEXT text;
|
||||
text.SetFlags( SELECTED_BY_DRAG );
|
||||
text.SetSelected();
|
||||
|
||||
commit.Stage( &text, CHT_MODIFY );
|
||||
|
||||
BOOST_CHECK( text.IsSelected() );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &text ), CHT_MODIFY );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -33,6 +33,7 @@ set( QA_PCBNEW_SRCS
|
||||
# test compilation units (start test_)
|
||||
test_array_pad_name_provider.cpp
|
||||
test_board_item.cpp
|
||||
test_board_commit.cpp
|
||||
test_component_classes.cpp
|
||||
test_generator_load_save.cpp
|
||||
test_graphics_load_save.cpp
|
||||
|
77
qa/tests/pcbnew/test_board_commit.cpp
Normal file
77
qa/tests/pcbnew/test_board_commit.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <pcbnew_utils/board_test_utils.h>
|
||||
#include <board.h>
|
||||
#include <board_commit.h>
|
||||
#include <pcb_shape.h>
|
||||
#include <pcb_group.h>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( BoardCommit )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( RecursesThroughGroups )
|
||||
{
|
||||
BOARD board;
|
||||
TOOL_MANAGER mgr;
|
||||
mgr.SetEnvironment( &board, nullptr, nullptr, nullptr, nullptr );
|
||||
KI_TEST::DUMMY_TOOL *dummyTool = new KI_TEST::DUMMY_TOOL();
|
||||
mgr.RegisterTool( dummyTool );
|
||||
BOARD_COMMIT commit( dummyTool );
|
||||
|
||||
PCB_SHAPE s1( nullptr, SHAPE_T::SEGMENT );
|
||||
PCB_SHAPE s2( nullptr, SHAPE_T::SEGMENT );
|
||||
PCB_GROUP group( nullptr );
|
||||
group.AddItem( &s1 );
|
||||
group.AddItem( &s2 );
|
||||
|
||||
commit.Stage( &group, CHT_MODIFY, nullptr, RECURSE_MODE::RECURSE );
|
||||
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &s1 ), CHT_MODIFY );
|
||||
BOOST_CHECK_EQUAL( commit.GetStatus( &s2 ), CHT_MODIFY );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( MakeImageCreatesTransientCopy )
|
||||
{
|
||||
PCB_SHAPE shape( nullptr, SHAPE_T::SEGMENT );
|
||||
EDA_ITEM* copy = BOARD_COMMIT::MakeImage( &shape );
|
||||
|
||||
BOOST_REQUIRE( copy );
|
||||
BOOST_CHECK( copy != &shape );
|
||||
BOOST_CHECK( copy->HasFlag( UR_TRANSIENT ) );
|
||||
|
||||
delete copy;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ReturnsBoardFromManager )
|
||||
{
|
||||
BOARD board;
|
||||
TOOL_MANAGER mgr;
|
||||
mgr.SetEnvironment( &board, nullptr, nullptr, nullptr, nullptr );
|
||||
KI_TEST::DUMMY_TOOL* dummyTool = new KI_TEST::DUMMY_TOOL();
|
||||
mgr.RegisterTool( dummyTool );
|
||||
|
||||
BOARD_COMMIT commit( dummyTool );
|
||||
|
||||
BOOST_CHECK_EQUAL( commit.GetBoard(), &board );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
x
Reference in New Issue
Block a user