24#include <boost/test/unit_test.hpp>
28#include <nlohmann/json.hpp>
46 nlohmann::json j = aValue.ToJson();
49 "DIFF_VALUE round-trip mismatch for type "
50 <<
static_cast<int>( aValue.GetType() ) );
53 nlohmann::json j2 = out.
ToJson();
157 std::vector<VECTOR2I> outline = { { 0, 0 }, { 100, 0 }, { 100, 100 }, { 0, 100 } };
158 std::vector<VECTOR2I> hole = { { 25, 25 }, { 75, 25 }, { 75, 75 }, { 25, 75 } };
159 ps.push_back( { outline, hole } );
162 ps.push_back( { { { 200, 200 }, { 300, 200 }, { 250, 300 } } } );
181 d.
name = wxS(
"Position" );
185 nlohmann::json j = d.
ToJson();
187 BOOST_CHECK( out == d );
207 const CASE cases[] = {
209 {
"added", wxS(
"SolderMaskMargin" ),
DIFF_VALUE(),
222 for(
const CASE& c : cases )
232 BOOST_CHECK( out == d );
252 d.
name = wxS(
"Width" );
257 nlohmann::json j = c.
ToJson();
259 BOOST_CHECK( out == c );
266 d.
path = wxS(
"board.kicad_pcb" );
267 d.
docType = wxS(
"kicad_pcb" );
268 BOOST_CHECK( d.
Empty() );
277 BOOST_CHECK( !d.
Empty() );
280 nlohmann::json j = d.
ToJson();
294 BOOST_CHECK( p.
Empty() );
298 BOOST_CHECK( p.
Empty() );
303 p.
documents.front().changes.push_back( c );
304 BOOST_CHECK( !p.
Empty() );
317 KIID idA, idB, childKiid;
324 docA.
path = wxS(
"board.kicad_pcb" );
325 docA.
docType = wxS(
"kicad_pcb" );
336 docB.
path = wxS(
"sheet.kicad_sch" );
337 docB.
docType = wxS(
"kicad_sch" );
344 c2.
refdes = wxS(
"NET_A" );
347 d.
name = wxS(
"Width" );
354 childChange.
typeName = wxS(
"SCH_PIN" );
356 c2.
children.push_back( childChange );
363 BOOST_REQUIRE_EQUAL( out.
documents.size(), 2u );
375 BOOST_REQUIRE_EQUAL( out.
documents[0].changes.size(), 1u );
376 BOOST_REQUIRE_EQUAL( out.
documents[1].changes.size(), 1u );
377 BOOST_CHECK( out.
documents[0].changes[0] == c1 );
378 BOOST_CHECK( out.
documents[1].changes[0] == c2 );
409 nlohmann::json j = v.
ToJson();
414 BOOST_CHECK( back == v );
417 d.
name = wxString::FromUTF8(
"Réf" );
421 BOOST_CHECK( dback == d );
431 BOOST_REQUIRE_EQUAL( pipe( pipeFd ), 0 );
433 const int savedStdout = dup( STDOUT_FILENO );
436 BOOST_REQUIRE_EQUAL( dup2( pipeFd[1], STDOUT_FILENO ), STDOUT_FILENO );
439 const std::string content =
"diff A B\nhéllo\n";
443 BOOST_REQUIRE_EQUAL( dup2( savedStdout, STDOUT_FILENO ), STDOUT_FILENO );
444 close( savedStdout );
446 char buffer[256] = {};
447 ssize_t bytesRead = read( pipeFd[0], buffer,
sizeof( buffer ) - 1 );
451 BOOST_CHECK_EQUAL( std::string( buffer,
static_cast<std::size_t
>( bytesRead ) ), content );
511 BOOST_CHECK( a == b );
518 a.
name = wxS(
"Width" );
523 BOOST_CHECK( a == b );
525 b.
name = wxS(
"Layer" );
526 BOOST_CHECK( a != b );
530 BOOST_CHECK( a != b );
534 BOOST_CHECK( a != b );
548 KIID parent, padIdA, padIdB;
556 BOOST_CHECK( a == b );
563 BOOST_CHECK( a != b );
570 differentChild.
typeName = wxS(
"PAD" );
572 a.
children.push_back( differentChild );
573 BOOST_CHECK( a != b );
577 BOOST_CHECK( a == b );
A typed sum value used to carry the before/after of any single property.
static DIFF_VALUE FromLayer(PCB_LAYER_ID aLayer)
static DIFF_VALUE FromDouble(double aValue)
static DIFF_VALUE FromEnum(int aValue, const std::string &aLabel)
static DIFF_VALUE FromInt64(int64_t aValue)
static DIFF_VALUE FromInt(int aValue)
static DIFF_VALUE FromBox2I(const BOX2I &aValue)
const PolygonSet & AsPolygonSet() const
static DIFF_VALUE FromKiid(const KIID &aValue)
static DIFF_VALUE FromColor(const KIGFX::COLOR4D &aValue)
nlohmann::json ToJson() const
static DIFF_VALUE FromBool(bool aValue)
static DIFF_VALUE FromString(const wxString &aValue)
std::vector< std::vector< std::vector< VECTOR2I > > > PolygonSet
static DIFF_VALUE FromJson(const nlohmann::json &aJson)
static DIFF_VALUE FromPolygonSet(PolygonSet aValue)
static DIFF_VALUE FromVector2I(const VECTOR2I &aValue)
A color representation with 4 components: red, green, blue, alpha.
static void SeedGenerator(unsigned int aSeed)
Re-initialize the UUID generator with a given seed (for testing or QA purposes)
wxString AsString() const
CHANGE_KIND ChangeKindFromString(const std::string &aKind)
bool WriteDiffOutput(const std::string &aContent, const wxString &aOutputPath)
Write diff/merge text output to aOutputPath, or to stdout when the path is empty.
The full set of changes between two parsed documents of one type.
nlohmann::json ToJson() const
static DOCUMENT_DIFF FromJson(const nlohmann::json &aJson)
std::vector< ITEM_CHANGE > changes
One change record on a single item.
static ITEM_CHANGE FromJson(const nlohmann::json &aJson)
std::vector< PROPERTY_DELTA > properties
std::optional< wxString > refdes
std::vector< ITEM_CHANGE > children
nlohmann::json ToJson() const
Aggregated project-level diff covering many documents.
nlohmann::json ToJson() const
std::vector< DOCUMENT_DIFF > documents
static PROJECT_DIFF FromJson(const nlohmann::json &aJson)
Single (name, before, after) triple for one mutated property on an item.
static PROPERTY_DELTA FromJson(const nlohmann::json &aJson)
nlohmann::json ToJson() const
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(DiffValueNone)
static void roundTrip(const DIFF_VALUE &aValue)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_MESSAGE(totalMismatches==0, std::to_string(totalMismatches)+" board(s) with strategy disagreements")
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I