diff --git a/qa/tests/common/CMakeLists.txt b/qa/tests/common/CMakeLists.txt
index 76f858415c..db422161e7 100644
--- a/qa/tests/common/CMakeLists.txt
+++ b/qa/tests/common/CMakeLists.txt
@@ -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
diff --git a/qa/tests/common/test_commit.cpp b/qa/tests/common/test_commit.cpp
new file mode 100644
index 0000000000..6d06cbc881
--- /dev/null
+++ b/qa/tests/common/test_commit.cpp
@@ -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 .
+ */
+
+#include
+#include
+#include
+#include
+
+// 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( 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 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( 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()
+
diff --git a/qa/tests/eeschema/CMakeLists.txt b/qa/tests/eeschema/CMakeLists.txt
index 2f13f7fb82..04ddf71533 100644
--- a/qa/tests/eeschema/CMakeLists.txt
+++ b/qa/tests/eeschema/CMakeLists.txt
@@ -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
diff --git a/qa/tests/eeschema/test_sch_commit.cpp b/qa/tests/eeschema/test_sch_commit.cpp
new file mode 100644
index 0000000000..83e324e2f9
--- /dev/null
+++ b/qa/tests/eeschema/test_sch_commit.cpp
@@ -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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+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()
+
diff --git a/qa/tests/pcbnew/CMakeLists.txt b/qa/tests/pcbnew/CMakeLists.txt
index e725f79d4e..cdeb558c56 100644
--- a/qa/tests/pcbnew/CMakeLists.txt
+++ b/qa/tests/pcbnew/CMakeLists.txt
@@ -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
diff --git a/qa/tests/pcbnew/test_board_commit.cpp b/qa/tests/pcbnew/test_board_commit.cpp
new file mode 100644
index 0000000000..16707685b1
--- /dev/null
+++ b/qa/tests/pcbnew/test_board_commit.cpp
@@ -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 .
+ */
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+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()
+