KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_lib_merge_applier.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 3
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/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 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
27
28#include <map>
29#include <memory>
30#include <utility>
31#include <vector>
32
33#include <wx/string.h>
34
35
36using namespace KICAD_DIFF;
37
38
39namespace
40{
41
42// Minimal copy-constructible stand-in. The applier only does
43// std::make_unique<ITEM>(*src) on the chosen side, so anything
44// copyable works — we just stamp a side tag so the test can verify
45// which side flowed through.
46struct TestItem
47{
48 wxString name;
49 wxString side; // "anc" / "ours" / "theirs" — set by the fixture, never copied from
50};
51
52
53using ItemStore = std::vector<TestItem>;
54using ItemMap = std::map<wxString, const TestItem*>;
55
56
57ItemMap MakeMap( ItemStore& aStore )
58{
59 ItemMap m;
60
61 for( const TestItem& it : aStore )
62 m[it.name] = &it;
63
64 return m;
65}
66
67
68ITEM_RESOLUTION Action( const wxString& aName, ITEM_RES aKind )
69{
71 r.id = LibraryItemKiidPath( aName );
72 r.kind = aKind;
73 return r;
74}
75
76
77const TestItem* Find( const std::vector<std::unique_ptr<TestItem>>& aOut, const wxString& aName )
78{
79 for( const auto& up : aOut )
80 {
81 if( up && up->name == aName )
82 return up.get();
83 }
84
85 return nullptr;
86}
87
88} // namespace
89
90
91BOOST_AUTO_TEST_SUITE( LibMergeApplier )
92
93
94BOOST_AUTO_TEST_CASE( TakeOurs_PicksOursSide )
95{
96 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
97 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
98 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
99
101 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::TAKE_OURS ) );
102
103 ItemMap ancMap = MakeMap( anc );
104
105 ItemMap oursMap = MakeMap( ours );
106
107 ItemMap theirsMap = MakeMap( theirs );
108
109 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
110 auto out = applier.Apply();
111
112 BOOST_REQUIRE_EQUAL( out.size(), 1 );
113 BOOST_CHECK( out[0]->name == wxS( "R" ) );
114 BOOST_CHECK( out[0]->side == wxS( "ours" ) );
116}
117
118
119BOOST_AUTO_TEST_CASE( TakeTheirs_PicksTheirsSide )
120{
121 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
122 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
123 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
124
126 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::TAKE_THEIRS ) );
127
128 ItemMap ancMap = MakeMap( anc );
129
130 ItemMap oursMap = MakeMap( ours );
131
132 ItemMap theirsMap = MakeMap( theirs );
133
134 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
135 auto out = applier.Apply();
136
137 BOOST_REQUIRE_EQUAL( out.size(), 1 );
138 BOOST_CHECK( out[0]->side == wxS( "theirs" ) );
140}
141
142
143BOOST_AUTO_TEST_CASE( TakeAncestor_PicksAncestorSide )
144{
145 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
146 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
147 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
148
150 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::TAKE_ANCESTOR ) );
151
152 ItemMap ancMap = MakeMap( anc );
153
154 ItemMap oursMap = MakeMap( ours );
155
156 ItemMap theirsMap = MakeMap( theirs );
157
158 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
159 auto out = applier.Apply();
160
161 BOOST_REQUIRE_EQUAL( out.size(), 1 );
162 BOOST_CHECK( out[0]->side == wxS( "anc" ) );
164}
165
166
167BOOST_AUTO_TEST_CASE( TakeOurs_MissingInOurs_ErasesFromOutput )
168{
169 // TAKE_OURS where ours doesn't have the item — applier must erase
170 // the live entry rather than leaving the ancestor copy.
171 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
172 ItemStore ours; // empty
173 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
174
176 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::TAKE_OURS ) );
177
178 ItemMap ancMap = MakeMap( anc );
179
180 ItemMap oursMap = MakeMap( ours );
181
182 ItemMap theirsMap = MakeMap( theirs );
183
184 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
185 auto out = applier.Apply();
186
187 BOOST_CHECK( out.empty() );
189}
190
191
192BOOST_AUTO_TEST_CASE( Delete_RemovesItem )
193{
194 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
195 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
196 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
197
199 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::DELETE_ITEM ) );
200
201 ItemMap ancMap = MakeMap( anc );
202
203 ItemMap oursMap = MakeMap( ours );
204
205 ItemMap theirsMap = MakeMap( theirs );
206
207 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
208 auto out = applier.Apply();
209
210 BOOST_CHECK( out.empty() );
212}
213
214
215BOOST_AUTO_TEST_CASE( Keep_PrefersAncestor )
216{
217 // KEEP with ancestor present should pick ancestor.
218 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
219 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
220 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
221
223 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::KEEP ) );
224
225 ItemMap ancMap = MakeMap( anc );
226
227 ItemMap oursMap = MakeMap( ours );
228
229 ItemMap theirsMap = MakeMap( theirs );
230
231 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
232 auto out = applier.Apply();
233
234 BOOST_REQUIRE_EQUAL( out.size(), 1 );
235 BOOST_CHECK( out[0]->side == wxS( "anc" ) );
236 BOOST_CHECK_EQUAL( applier.GetReport().itemsKept, 1 );
237}
238
239
240BOOST_AUTO_TEST_CASE( Keep_FallsBackToOurs_WhenAncestorMissing )
241{
242 // The both-added case: no ancestor, item exists on both sides.
243 // KEEP walks anc -> ours -> theirs so ours wins.
244 ItemStore anc;
245 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
246 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
247
249 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::KEEP ) );
250
251 ItemMap ancMap = MakeMap( anc );
252
253 ItemMap oursMap = MakeMap( ours );
254
255 ItemMap theirsMap = MakeMap( theirs );
256
257 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
258 auto out = applier.Apply();
259
260 BOOST_REQUIRE_EQUAL( out.size(), 1 );
261 BOOST_CHECK( out[0]->side == wxS( "ours" ) );
262 BOOST_CHECK_EQUAL( applier.GetReport().itemsKept, 1 );
263}
264
265
266BOOST_AUTO_TEST_CASE( Keep_FallsBackToTheirs_WhenAncestorAndOursMissing )
267{
268 // Only theirs has the item. KEEP should still produce it (otherwise an
269 // independent same-name add on theirs vanishes — exactly the documented
270 // bug the fallback walk guards against).
271 ItemStore anc;
272 ItemStore ours;
273 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
274
276 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::KEEP ) );
277
278 ItemMap ancMap = MakeMap( anc );
279
280 ItemMap oursMap = MakeMap( ours );
281
282 ItemMap theirsMap = MakeMap( theirs );
283
284 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
285 auto out = applier.Apply();
286
287 BOOST_REQUIRE_EQUAL( out.size(), 1 );
288 BOOST_CHECK( out[0]->side == wxS( "theirs" ) );
289 BOOST_CHECK_EQUAL( applier.GetReport().itemsKept, 1 );
290}
291
292
293BOOST_AUTO_TEST_CASE( Keep_AllSidesMissing_ProducesNothing )
294{
295 // Defensive: a KEEP resolution for an item that's in none of the maps.
296 // Should not crash; should produce no output and still bump itemsKept.
297 ItemStore anc, ours, theirs;
298
300 plan.actions.push_back( Action( wxS( "Ghost" ), ITEM_RES::KEEP ) );
301
302 ItemMap ancMap = MakeMap( anc );
303
304 ItemMap oursMap = MakeMap( ours );
305
306 ItemMap theirsMap = MakeMap( theirs );
307
308 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
309 auto out = applier.Apply();
310
311 BOOST_CHECK( out.empty() );
312 // The action is keyed by KIID_PATH; with no item present in any map,
313 // the action is unreachable (allNames is empty). itemsKept stays 0.
314 BOOST_CHECK_EQUAL( applier.GetReport().itemsKept, 0 );
315}
316
317
318BOOST_AUTO_TEST_CASE( MergeProps_FallsBackToOurs_AndTracksId )
319{
320 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
321 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
322 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
323
325 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::MERGE_PROPS ) );
326
327 ItemMap ancMap = MakeMap( anc );
328
329 ItemMap oursMap = MakeMap( ours );
330
331 ItemMap theirsMap = MakeMap( theirs );
332
333 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
334 auto out = applier.Apply();
335
336 BOOST_REQUIRE_EQUAL( out.size(), 1 );
337 BOOST_CHECK( out[0]->side == wxS( "ours" ) );
341 == LibraryItemKiidPath( wxS( "R" ) ) );
342}
343
344
345BOOST_AUTO_TEST_CASE( MergeProps_TakesTheCombinedItem )
346{
347 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
348 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
349 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
350
352 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::MERGE_PROPS ) );
353
354 ItemMap ancMap = MakeMap( anc );
355 ItemMap oursMap = MakeMap( ours );
356 ItemMap theirsMap = MakeMap( theirs );
357
358 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ),
359 []( const KIID_PATH& )
360 {
361 return std::make_unique<TestItem>( TestItem{ wxS( "R" ),
362 wxS( "both" ) } );
363 } );
364 auto out = applier.Apply();
365
366 BOOST_REQUIRE_EQUAL( out.size(), 1 );
367 BOOST_CHECK( out[0]->side == wxS( "both" ) );
368 BOOST_CHECK_EQUAL( applier.GetReport().mergePropsFallback, 0 );
369}
370
371
372BOOST_AUTO_TEST_CASE( NoActionForItem_PassesAncestorThrough )
373{
374 // An item present in ancestor but with no plan action stays in `live`
375 // because the applier seeds `live = m_ancestor` and only mutates entries
376 // that have a matching action.
377 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
378 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) } };
379 ItemStore theirs;
380
381 MERGE_PLAN plan; // empty — no actions
382
383 ItemMap ancMap = MakeMap( anc );
384
385 ItemMap oursMap = MakeMap( ours );
386
387 ItemMap theirsMap = MakeMap( theirs );
388
389 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
390 auto out = applier.Apply();
391
392 BOOST_REQUIRE_EQUAL( out.size(), 1 );
393 BOOST_CHECK( out[0]->side == wxS( "anc" ) );
394}
395
396
397BOOST_AUTO_TEST_CASE( ActionForUnknownName_IsHarmless )
398{
399 // A plan action whose id doesn't match any item in any map should be
400 // silently ignored (allNames doesn't contain it, so the inner loop
401 // never visits that action).
402 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
403 ItemStore ours, theirs;
404
406 plan.actions.push_back( Action( wxS( "Phantom" ), ITEM_RES::DELETE_ITEM ) );
407
408 ItemMap ancMap = MakeMap( anc );
409
410 ItemMap oursMap = MakeMap( ours );
411
412 ItemMap theirsMap = MakeMap( theirs );
413
414 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
415 auto out = applier.Apply();
416
417 BOOST_REQUIRE_EQUAL( out.size(), 1 ); // R passed through
418 BOOST_CHECK( out[0]->name == wxS( "R" ) );
420}
421
422
423BOOST_AUTO_TEST_CASE( OutputSortedByName )
424{
425 // live is std::map<wxString, ...>, so output should be in name order.
426 ItemStore anc{ { wxS( "C" ), wxS( "anc" ) }, { wxS( "A" ), wxS( "anc" ) },
427 { wxS( "B" ), wxS( "anc" ) } };
428 ItemStore ours, theirs;
429
430 MERGE_PLAN plan; // no actions — pure pass-through
431
432 ItemMap ancMap = MakeMap( anc );
433
434 ItemMap oursMap = MakeMap( ours );
435
436 ItemMap theirsMap = MakeMap( theirs );
437
438 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
439 auto out = applier.Apply();
440
441 BOOST_REQUIRE_EQUAL( out.size(), 3 );
442 BOOST_CHECK( out[0]->name == wxS( "A" ) );
443 BOOST_CHECK( out[1]->name == wxS( "B" ) );
444 BOOST_CHECK( out[2]->name == wxS( "C" ) );
445}
446
447
448BOOST_AUTO_TEST_CASE( OutputIsFreshCopy_NotPointerAlias )
449{
450 // Applier returns owned unique_ptrs via std::make_unique<ITEM>(*src).
451 // Mutating the source map's item after Apply() must not affect output.
452 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
453 ItemStore ours, theirs;
454
455 MERGE_PLAN plan; // no actions
456
457 ItemMap ancMap = MakeMap( anc );
458
459 ItemMap oursMap = MakeMap( ours );
460
461 ItemMap theirsMap = MakeMap( theirs );
462
463 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
464 auto out = applier.Apply();
465
466 BOOST_REQUIRE_EQUAL( out.size(), 1 );
467 anc[0].side = wxS( "MUTATED" );
468 BOOST_CHECK( out[0]->side == wxS( "anc" ) );
469}
470
471
472BOOST_AUTO_TEST_CASE( MixedActions_AllCountersAdvance )
473{
474 // One action of each kind in a single plan. Verifies counters increment
475 // independently and the same applier instance can handle a mixed plan.
476 ItemStore anc{
477 { wxS( "Keep" ), wxS( "anc" ) },
478 { wxS( "DelMe" ), wxS( "anc" ) },
479 { wxS( "Anc" ), wxS( "anc" ) },
480 { wxS( "MergeProps" ), wxS( "anc" ) },
481 };
482 ItemStore ours{
483 { wxS( "Keep" ), wxS( "ours" ) },
484 { wxS( "DelMe" ), wxS( "ours" ) },
485 { wxS( "Anc" ), wxS( "ours" ) },
486 { wxS( "OursOnly" ), wxS( "ours" ) },
487 { wxS( "MergeProps" ), wxS( "ours" ) },
488 };
489 ItemStore theirs{
490 { wxS( "Keep" ), wxS( "theirs" ) },
491 { wxS( "TheirsOnly" ), wxS( "theirs" ) },
492 { wxS( "MergeProps" ), wxS( "theirs" ) },
493 };
494
496 plan.actions.push_back( Action( wxS( "Keep" ), ITEM_RES::KEEP ) );
497 plan.actions.push_back( Action( wxS( "DelMe" ), ITEM_RES::DELETE_ITEM ) );
498 plan.actions.push_back( Action( wxS( "Anc" ), ITEM_RES::TAKE_ANCESTOR ) );
499 plan.actions.push_back( Action( wxS( "OursOnly" ), ITEM_RES::TAKE_OURS ) );
500 plan.actions.push_back( Action( wxS( "TheirsOnly" ), ITEM_RES::TAKE_THEIRS ) );
501 plan.actions.push_back( Action( wxS( "MergeProps" ), ITEM_RES::MERGE_PROPS ) );
502
503 ItemMap ancMap = MakeMap( anc );
504
505 ItemMap oursMap = MakeMap( ours );
506
507 ItemMap theirsMap = MakeMap( theirs );
508
509 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
510 auto out = applier.Apply();
511
512 const auto& r = applier.GetReport();
513 BOOST_CHECK_EQUAL( r.itemsKept, 1 );
514 BOOST_CHECK_EQUAL( r.itemsDeleted, 1 );
515 BOOST_CHECK_EQUAL( r.itemsTakenAncestor, 1 );
516 BOOST_CHECK_EQUAL( r.itemsTakenOurs, 1 );
517 BOOST_CHECK_EQUAL( r.itemsTakenTheirs, 1 );
518 BOOST_CHECK_EQUAL( r.mergePropsFallback, 1 );
519
520 // Five live items: Keep, Anc, OursOnly, TheirsOnly, MergeProps; DelMe was
521 // deleted. Pinning the exact size catches accidental over-emission.
522 BOOST_REQUIRE_EQUAL( out.size(), 5 );
523
524 const TestItem* keep = Find( out, wxS( "Keep" ) );
525 const TestItem* anc_pick = Find( out, wxS( "Anc" ) );
526 const TestItem* ours_only = Find( out, wxS( "OursOnly" ) );
527 const TestItem* theirs_one = Find( out, wxS( "TheirsOnly" ) );
528 const TestItem* merge = Find( out, wxS( "MergeProps" ) );
529
530 BOOST_REQUIRE( keep );
531 BOOST_REQUIRE( anc_pick );
532 BOOST_REQUIRE( ours_only );
533 BOOST_REQUIRE( theirs_one );
534 BOOST_REQUIRE( merge );
535 BOOST_CHECK( keep->side == wxS( "anc" ) );
536 BOOST_CHECK( anc_pick->side == wxS( "anc" ) );
537 BOOST_CHECK( ours_only->side == wxS( "ours" ) );
538 BOOST_CHECK( theirs_one->side == wxS( "theirs" ) );
539 BOOST_CHECK( merge->side == wxS( "ours" ) );
540 BOOST_CHECK( Find( out, wxS( "DelMe" ) ) == nullptr );
541}
542
543
544BOOST_AUTO_TEST_CASE( MergeProps_OursMissing_StillTracksIdAndErasesLive )
545{
546 // MERGE_PROPS where ours doesn't have the item: take(m_ours, ...) must
547 // erase the live entry (because pick(m_ours) returns null), and the
548 // mergePropsFallbackIds vector must still record the ID so the job
549 // handler can surface the unresolved conflict to the user.
550 ItemStore anc{ { wxS( "R" ), wxS( "anc" ) } };
551 ItemStore ours;
552 ItemStore theirs{ { wxS( "R" ), wxS( "theirs" ) } };
553
555 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::MERGE_PROPS ) );
556
557 ItemMap ancMap = MakeMap( anc );
558 ItemMap oursMap = MakeMap( ours );
559 ItemMap theirsMap = MakeMap( theirs );
560 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
561 auto out = applier.Apply();
562
563 BOOST_CHECK( out.empty() );
567 == LibraryItemKiidPath( wxS( "R" ) ) );
568}
569
570
571BOOST_AUTO_TEST_CASE( NonMergeProps_DoesNotPopulateFallbackIds )
572{
573 // Pin that fallbackIds is only touched by the MERGE_PROPS branch. A plan
574 // of pure non-MERGE_PROPS actions must leave the vector empty.
575 ItemStore anc{ { wxS( "A" ), wxS( "anc" ) }, { wxS( "B" ), wxS( "anc" ) },
576 { wxS( "C" ), wxS( "anc" ) } };
577 ItemStore ours{ { wxS( "A" ), wxS( "ours" ) } };
578 ItemStore theirs{ { wxS( "B" ), wxS( "theirs" ) } };
579
581 plan.actions.push_back( Action( wxS( "A" ), ITEM_RES::TAKE_OURS ) );
582 plan.actions.push_back( Action( wxS( "B" ), ITEM_RES::TAKE_THEIRS ) );
583 plan.actions.push_back( Action( wxS( "C" ), ITEM_RES::DELETE_ITEM ) );
584
585 ItemMap ancMap = MakeMap( anc );
586 ItemMap oursMap = MakeMap( ours );
587 ItemMap theirsMap = MakeMap( theirs );
588 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
589 applier.Apply();
590
592 BOOST_CHECK( applier.GetReport().mergePropsFallbackIds.empty() );
593}
594
595
596BOOST_AUTO_TEST_CASE( ReportResetOnReapply )
597{
598 // GetReport() must reset on every Apply() — otherwise counters would
599 // double when callers re-run the applier (e.g., regression-test loops).
600 // Include a MERGE_PROPS action so the vector field (mergePropsFallbackIds)
601 // is also exercised: a non-trivial reset path must clear the vector too.
602 ItemStore anc{ { wxS( "M" ), wxS( "anc" ) } };
603 ItemStore ours{ { wxS( "R" ), wxS( "ours" ) }, { wxS( "M" ), wxS( "ours" ) } };
604 ItemStore theirs{ { wxS( "M" ), wxS( "theirs" ) } };
605
607 plan.actions.push_back( Action( wxS( "R" ), ITEM_RES::TAKE_OURS ) );
608 plan.actions.push_back( Action( wxS( "M" ), ITEM_RES::MERGE_PROPS ) );
609
610 ItemMap ancMap = MakeMap( anc );
611 ItemMap oursMap = MakeMap( ours );
612 ItemMap theirsMap = MakeMap( theirs );
613 LIB_MERGE_APPLIER<TestItem> applier( ancMap, oursMap, theirsMap, std::move( plan ) );
614 applier.Apply();
615 applier.Apply();
616
619 BOOST_CHECK_EQUAL( applier.GetReport().mergePropsFallbackIds.size(), 1u );
620}
621
622
const char * name
Materialize a MERGE_PLAN into a merged name-keyed library.
const REPORT & GetReport() const
std::vector< std::unique_ptr< ITEM > > Apply()
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.
ITEM_RES
Resolution kind for a whole item.
KIID_PATH LibraryItemKiidPath(const wxString &aName)
Build a deterministic synthetic KIID_PATH from a library item name (symbol name or footprint name).
std::vector< KIID_PATH > mergePropsFallbackIds
Item IDs (KIID_PATH from LibraryItemKiidPath) for resolutions that the applier silently downgraded (c...
Result of planning a 3-way merge.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK(res.column_datatype(0)==SQL_NUMERIC||res.column_datatype(0)==SQL_DECIMAL)
BOOST_REQUIRE_EQUAL(rows.size(), 1)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_REQUIRE(res.columns()==1)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(TakeOurs_PicksOursSide)