24#include <boost/test/unit_test.hpp>
29#include <nlohmann/json.hpp>
38ITEM_CHANGE makeAdded(
const KIID& aUuid,
const wxString& aType = wxS(
"PCB_TRACK" ) )
41 c.
id.push_back( aUuid );
48ITEM_CHANGE makeRemoved(
const KIID& aUuid,
const wxString& aType = wxS(
"PCB_TRACK" ) )
51 c.
id.push_back( aUuid );
58ITEM_CHANGE makeModifiedWidth(
const KIID& aUuid,
int aBefore,
int aAfter )
61 c.
id.push_back( aUuid );
66 d.
name = wxS(
"Width" );
78 c.
id.push_back( aUuid );
83 p1.
name = wxS(
"Position X" );
89 p2.
name = wxS(
"Reference" );
110 ours.
changes.push_back( makeAdded(
id ) );
115 BOOST_REQUIRE_EQUAL( plan.
actions.size(), 1u );
128 ours.
changes.push_back( makeAdded(
id ) );
129 theirs.
changes.push_back( makeAdded(
id ) );
134 BOOST_REQUIRE_EQUAL( plan.
actions.size(), 1u );
147 ours.
changes.push_back( makeRemoved(
id ) );
148 theirs.
changes.push_back( makeRemoved(
id ) );
153 BOOST_REQUIRE_EQUAL( plan.
actions.size(), 1u );
166 ours.
changes.push_back( makeRemoved(
id ) );
167 theirs.
changes.push_back( makeModifiedWidth(
id, 100, 200 ) );
172 BOOST_REQUIRE_EQUAL( plan.
actions.size(), 1u );
188 ourChange.
id.push_back(
id );
189 ourChange.
typeName = wxS(
"FOOTPRINT" );
192 p1.
name = wxS(
"Position X" );
196 ours.
changes.push_back( ourChange );
199 theirChange.
id.push_back(
id );
200 theirChange.
typeName = wxS(
"FOOTPRINT" );
203 p2.
name = wxS(
"Reference" );
207 theirs.
changes.push_back( theirChange );
212 BOOST_REQUIRE_EQUAL( plan.
actions.size(), 1u );
217 BOOST_REQUIRE_EQUAL( plan.
actions[0].props.size(), 2u );
219 bool foundOurs =
false, foundTheirs =
false;
230 BOOST_CHECK( foundOurs );
231 BOOST_CHECK( foundTheirs );
242 ours.
changes.push_back( makeModifiedWidth(
id, 100, 200 ) );
243 theirs.
changes.push_back( makeModifiedWidth(
id, 100, 300 ) );
248 BOOST_REQUIRE_EQUAL( plan.
actions.size(), 1u );
261 ours.
changes.push_back( makeModifiedWidth(
id, 100, 250 ) );
262 theirs.
changes.push_back( makeModifiedWidth(
id, 100, 250 ) );
280 z.
id.push_back(
id );
301 t.
id.push_back(
id );
322 dup.
id.push_back(
id );
341 ours.
changes.push_back( makeAdded(
id ) );
342 theirs.
changes.push_back( makeModifiedWidth(
id, 100, 200 ) );
347 nlohmann::json j = plan.
ToJson();
353 for( std::size_t i = 0; i < plan.
actions.size(); ++i )
360 for( std::size_t i = 0; i < plan.
unresolved.size(); ++i )
374 j[
"actions"] = nlohmann::json::array();
375 j[
"unresolved"] = nlohmann::json::array();
378 BOOST_CHECK( plan.
actions.empty() );
404 BOOST_CHECK( back == r );
423 pickOurs.
name = wxS(
"Width" );
425 r.
props.push_back( pickOurs );
428 custom.
name = wxS(
"Layer" );
431 r.
props.push_back( custom );
434 BOOST_CHECK( back == r );
435 BOOST_REQUIRE_EQUAL( back.
props.size(), 2u );
436 BOOST_CHECK( back.
props[0] == pickOurs );
437 BOOST_CHECK( back.
props[1] == custom );
458 const CASE kinds[] = {
465 for(
const CASE& c : kinds )
470 r.
name = wxS(
"Width" );
476 nlohmann::json j = r.
ToJson();
498 BOOST_CHECK( plan.
actions.empty() );
508 KIID parentId, childId;
517 ourParent.
id.push_back( parentId );
518 ourParent.
typeName = wxS(
"FOOTPRINT" );
522 ourChild.
id.push_back( parentId );
523 ourChild.
id.push_back( childId );
527 d1.
name = wxS(
"Number" );
531 ourParent.
children.push_back( ourChild );
533 ours.
changes.push_back( ourParent );
540 d2.
name = wxS(
"Number" );
544 theirParent.
children.push_back( theirChild );
546 theirs.
changes.push_back( theirParent );
554 bool foundChild =
false;
558 if( r.
id.size() == 2 && r.
id.back() == childId )
562 BOOST_CHECK( foundChild );
578 o.
id.push_back(
id );
582 d1.
name = wxS(
"Position X" );
589 t.
id.push_back(
id );
593 d2.
name = wxS(
"Reference" );
619 c1.
id.push_back(
id );
625 theirs.
changes.push_back( c2 );
641PROPERTY_DELTA MakeDelta(
const wxString& aName,
int aBefore,
int aAfter )
674 BOOST_CHECK( !outcome.isUnresolved );
683 BOOST_CHECK( !outcome.isUnresolved );
697#if wxDEBUG_LEVEL == 0
700 BOOST_CHECK( !outcome.isUnresolved );
714 BOOST_CHECK( !outcome.isUnresolved );
726 BOOST_CHECK( outcome.isUnresolved );
739 BOOST_CHECK( !outcome.isUnresolved );
750 BOOST_CHECK( !outcome.isUnresolved );
762 BOOST_CHECK( outcome.isUnresolved );
776 BOOST_CHECK( outcome.isUnresolved );
789 BOOST_CHECK( outcome.isUnresolved );
800 BOOST_CHECK( outcome.isUnresolved );
static DIFF_VALUE FromInt(int aValue)
static DIFF_VALUE FromString(const wxString &aValue)
Three-way merge plan generator.
MERGE_PLAN Plan(const DOCUMENT_DIFF &aAncestorOurs, const DOCUMENT_DIFF &aAncestorTheirs) const
Plan the merge given the canonical pair of diffs.
static void SeedGenerator(unsigned int aSeed)
Re-initialize the UUID generator with a given seed (for testing or QA purposes)
ITEM_RES
Resolution kind for a whole item.
PROPERTY_RESOLUTION_OUTCOME ResolvePropertyConflict(const PROPERTY_DELTA *aOurs, const PROPERTY_DELTA *aTheirs, const KICAD_MERGE_ENGINE::OPTIONS &aOptions)
Decide how to resolve a single property edit between two sides.
PROP_RES
Resolution kind for a single property of a single item.
The full set of changes between two parsed documents of one type.
std::vector< ITEM_CHANGE > changes
One change record on a single item.
std::vector< PROPERTY_DELTA > properties
std::vector< ITEM_CHANGE > children
std::vector< PROPERTY_RESOLUTION > props
static ITEM_RESOLUTION FromJson(const nlohmann::json &aJson)
nlohmann::json ToJson() const
bool preferAutoMerge
When true, property-orthogonal edits auto-merge silently.
bool autoResolveEqualValues
When true and a property edit conflicts but the side values are equal, the resolution is automaticall...
Result of planning a 3-way merge.
std::size_t ConflictCount() const
bool requiresConnectivityRebuild
std::vector< ITEM_RESOLUTION > actions
nlohmann::json ToJson() const
std::vector< KIID_PATH > unresolved
static MERGE_PLAN FromJson(const nlohmann::json &aJson)
Single (name, before, after) triple for one mutated property on an item.
static PROPERTY_RESOLUTION FromJson(const nlohmann::json &aJson)
nlohmann::json ToJson() const
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(OneSidedChangeAutoTakes)
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
#define CHECK_WX_ASSERT(STATEMENT)
A test macro to check a wxASSERT is thrown.