KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_dialog_kicad_merge_3way.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
26
27
28namespace
29{
30class TEST_MERGE_DIALOG : public DIALOG_KICAD_MERGE_3WAY
31{
32public:
33 TEST_MERGE_DIALOG( const KICAD_DIFF::MERGE_PLAN& aPlan ) :
34 DIALOG_KICAD_MERGE_3WAY( nullptr, aPlan )
35 {
36 }
37
43
44 void SelectConflict( int aIndex )
45 {
46 m_listConflicts->SetSelection( aIndex );
47 wxCommandEvent event;
48 OnConflictSelected( event );
49 }
50
51 void Choose( wxRadioButton* aChoice )
52 {
53 aChoice->SetValue( true );
54 wxCommandEvent event;
55 OnResolutionChanged( event );
56 }
57};
58
59
60struct MERGE_DIALOG_FIXTURE
61{
62 KI_TEST::SCOPED_PROCESS_ENV_VAR autoResolution{ wxS( "KICAD_MERGETOOL_AUTO" ), std::nullopt };
63 TEST_MERGE_DIALOG* dialog = nullptr;
64
65 ~MERGE_DIALOG_FIXTURE()
66 {
67 if( dialog )
68 dialog->Destroy();
69 }
70
71 bool CreateDialog()
72 {
74 {
75 BOOST_TEST_MESSAGE( "Skipping test - no display available" );
76 return false;
77 }
78
80
81 for( int i = 0; i < 3; ++i )
82 {
84 action.id.push_back( KIID() );
85 plan.unresolved.push_back( action.id );
86 plan.actions.push_back( action );
87 }
88
89 dialog = new TEST_MERGE_DIALOG( plan );
90 return true;
91 }
92};
93} // namespace
94
95
96BOOST_FIXTURE_TEST_SUITE( MergeDialog, MERGE_DIALOG_FIXTURE )
97
98
99BOOST_AUTO_TEST_CASE( ConflictsStartUnresolved )
100{
101 if( !CreateDialog() )
102 return;
103
104 BOOST_CHECK_EQUAL( dialog->m_listConflicts->GetSelection(), 0 );
105 BOOST_CHECK( dialog->m_radioUnresolved->GetValue() );
106 BOOST_CHECK( !dialog->m_radioOurs->GetValue() );
107 BOOST_CHECK( !dialog->m_radioTheirs->GetValue() );
108 BOOST_CHECK( !dialog->m_radioAncestor->GetValue() );
109 BOOST_CHECK( !dialog->m_sdbSizerApply->IsEnabled() );
110
111 for( const KICAD_DIFF::ITEM_RESOLUTION& action : dialog->GetResolvedPlan().actions )
112 BOOST_CHECK( action.kind == KICAD_DIFF::ITEM_RES::KEEP );
113}
114
115
116BOOST_AUTO_TEST_CASE( SelectingAnotherConflictDoesNotChooseOurs )
117{
118 if( !CreateDialog() )
119 return;
120
121 dialog->Choose( dialog->m_radioOurs );
122 BOOST_CHECK( dialog->GetResolvedPlan().actions[0].kind == KICAD_DIFF::ITEM_RES::TAKE_OURS );
123
124 dialog->SelectConflict( 1 );
125 BOOST_CHECK( dialog->m_radioUnresolved->GetValue() );
126 BOOST_CHECK( !dialog->m_radioOurs->GetValue() );
127 BOOST_CHECK( !dialog->m_radioTheirs->GetValue() );
128 BOOST_CHECK( !dialog->m_radioAncestor->GetValue() );
129 BOOST_CHECK( dialog->GetResolvedPlan().actions[1].kind == KICAD_DIFF::ITEM_RES::KEEP );
130 BOOST_CHECK( !dialog->m_sdbSizerApply->IsEnabled() );
131
132 dialog->SelectConflict( 0 );
133 BOOST_CHECK( dialog->m_radioOurs->GetValue() );
134 BOOST_CHECK( !dialog->m_radioUnresolved->GetValue() );
135 BOOST_CHECK( dialog->GetResolvedPlan().actions[0].kind == KICAD_DIFF::ITEM_RES::TAKE_OURS );
136}
137
138
139BOOST_AUTO_TEST_CASE( ApplyRequiresAChoiceForEveryConflict )
140{
141 if( !CreateDialog() )
142 return;
143
144 dialog->Choose( dialog->m_radioOurs );
145 BOOST_CHECK( !dialog->m_sdbSizerApply->IsEnabled() );
146
147 dialog->SelectConflict( 1 );
148 dialog->Choose( dialog->m_radioTheirs );
149 BOOST_CHECK( dialog->GetResolvedPlan().actions[1].kind == KICAD_DIFF::ITEM_RES::TAKE_THEIRS );
150 BOOST_CHECK( !dialog->m_sdbSizerApply->IsEnabled() );
151
152 dialog->SelectConflict( 2 );
153 dialog->Choose( dialog->m_radioAncestor );
154 BOOST_CHECK( dialog->GetResolvedPlan().actions[2].kind == KICAD_DIFF::ITEM_RES::TAKE_ANCESTOR );
155 BOOST_CHECK( dialog->m_sdbSizerApply->IsEnabled() );
156
157 dialog->SelectConflict( 0 );
158 dialog->Choose( dialog->m_radioUnresolved );
159 BOOST_CHECK( dialog->GetResolvedPlan().actions[0].kind == KICAD_DIFF::ITEM_RES::KEEP );
160 BOOST_CHECK( !dialog->m_sdbSizerApply->IsEnabled() );
161
162 dialog->Choose( dialog->m_radioOurs );
163 BOOST_CHECK( dialog->m_sdbSizerApply->IsEnabled() );
164}
165
166
Resolve a three-way merge by choosing a version for each conflicting item.
Definition kiid.h:46
RAII helper that sets a process-level environment variable for the lifetime of the object.
static std::vector< PENDING_PROPERTY > plan(const EDA_ITEM &aSource, const EDA_ITEM &aTarget, const std::set< wxString > &aEnabledKeys)
Target properties to write, paired with values read off the source.
bool CanDoDisplayTests()
Some tests on some platforms require a display connection to run.
Result of planning a 3-way merge.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_CASE(ConflictsStartUnresolved)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_MESSAGE("Polyline has "<< chain.PointCount()<< " points")
BOOST_CHECK_EQUAL(result, "25.4")