21#include <boost/test/unit_test.hpp>
26#include <google/protobuf/any.pb.h>
28#include <api/board/board_types.pb.h>
41 m_settingsManager( true )
49template<
typename ProtoClass,
typename KiCadClass>
52 BOOST_TEST_CONTEXT( aInput->GetFriendlyName() <<
": " << aInput->m_Uuid.AsStdString() )
54 google::protobuf::Any any;
55 BOOST_REQUIRE_NO_THROW( aInput->Serialize( any ) );
57 BOOST_TEST_MESSAGE(
"Input: " << any.Utf8DebugString() );
60 BOOST_REQUIRE_MESSAGE( any.UnpackTo( &proto ),
61 "Any message did not unpack into the requested type" );
63 KiCadClass output( *
static_cast<KiCadClass*
>( aInput->Clone() ) );
65 bool deserializeResult =
false;
66 BOOST_REQUIRE_NO_THROW( deserializeResult = output.Deserialize( any ) );
67 BOOST_REQUIRE_MESSAGE( deserializeResult,
"Deserialize failed" );
70 google::protobuf::Any outputAny;
71 BOOST_REQUIRE_NO_THROW( output.Serialize( outputAny ) );
72 BOOST_TEST_MESSAGE(
"Output: " << outputAny.Utf8DebugString() );
74 if( !( outputAny.SerializeAsString() == any.SerializeAsString() ) )
76 BOOST_TEST_FAIL(
"Round-tripped protobuf does not match" );
80 if( !( output == *aInput ) )
82 BOOST_TEST_FAIL(
"Round-tripped object does not match" );
92 for(
PCB_TRACK* track : m_board->Tracks() )
94 switch( track->Type() )
97 testProtoFromKiCadObject<kiapi::board::types::Track>( track );
101 testProtoFromKiCadObject<kiapi::board::types::Arc>( track );
105 testProtoFromKiCadObject<kiapi::board::types::Via>( track );
113 for(
FOOTPRINT* footprint : m_board->Footprints() )
114 testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint );
126 for(
PCB_TRACK* track : m_board->Tracks() )
128 switch( track->Type() )
131 testProtoFromKiCadObject<kiapi::board::types::Via>(
static_cast<PCB_VIA*
>( track ) );
139 for(
FOOTPRINT* footprint : m_board->Footprints() )
140 testProtoFromKiCadObject<kiapi::board::types::FootprintInstance>( footprint );
void LoadBoard(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< BOARD > &aBoard)
std::unique_ptr< BOARD > m_board
SETTINGS_MANAGER m_settingsManager
BOOST_FIXTURE_TEST_CASE(BoardTypes, PROTO_TEST_FIXTURE)
void testProtoFromKiCadObject(KiCadClass *aInput)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)