20#include <boost/test/unit_test.hpp>
21#include <boost/bimap.hpp>
22#include <magic_enum.hpp>
28#include <api/common/types/enums.pb.h>
29#include <api/board/board_types.pb.h>
49template<
typename KiCadEnum,
typename ProtoEnum>
52 boost::bimap<ProtoEnum, KiCadEnum> protoToKiCadSeen;
53 std::set<ProtoEnum> seenProtos;
55 for( ProtoEnum value : magic_enum::enum_values<ProtoEnum>() )
58 << magic_enum::enum_name( value ) )
60 std::string
name( magic_enum::enum_name( value ) );
61 auto splitPos =
name.find_first_of(
'_' );
64 BOOST_REQUIRE_MESSAGE( splitPos != std::string::npos,
65 "Proto enum name doesn't have a prefix" );
67 std::string suffix =
name.substr( splitPos );
70 if(
static_cast<int>( value ) == 0 )
72 BOOST_REQUIRE_MESSAGE( suffix.compare(
"_UNKNOWN" ) == 0,
73 "Proto enum with value 0 must be named <PREFIX>_UNKNOWN" );
79 BOOST_REQUIRE_NO_THROW( result = ( FromProtoEnum<KiCadEnum, ProtoEnum>( value ) ) );
82 BOOST_REQUIRE( !protoToKiCadSeen.left.count( value ) );
83 protoToKiCadSeen.left.insert( { value, result } );
87 for( KiCadEnum value : magic_enum::enum_values<KiCadEnum>() )
90 << magic_enum::enum_name( value ) )
94 if( aPartiallyMapped )
98 result = ToProtoEnum<KiCadEnum, ProtoEnum>( value );
103 BOOST_REQUIRE_MESSAGE( !protoToKiCadSeen.right.count( value ),
104 "Proto enum is mapped to this KiCad enum, but not vice versa" );
111 BOOST_REQUIRE_NO_THROW( result = ( ToProtoEnum<KiCadEnum, ProtoEnum>( value ) ) );
115 BOOST_REQUIRE( result !=
static_cast<ProtoEnum
>( 0 ) );
118 BOOST_REQUIRE( !seenProtos.count( result ) );
119 seenProtos.insert( result );
122 KiCadEnum roundTrip = FromProtoEnum<KiCadEnum, ProtoEnum>( result );
123 BOOST_REQUIRE( roundTrip == value );
130 testEnums<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>();
135 testEnums<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>();
140 testEnums<LINE_STYLE, types::StrokeLineStyle>();
145 testEnums<KICAD_T, types::KiCadObjectType>(
true );
150 testEnums<PCB_LAYER_ID, kiapi::board::types::BoardLayer>(
true );
155 testEnums<PAD_SHAPE, kiapi::board::types::PadStackShape>();
160 testEnums<ZONE_CONNECTION, kiapi::board::types::ZoneConnectionStyle>();
163BOOST_AUTO_TEST_SUITE_END()
An exception class to represent a WX assertion.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
void testEnums(bool aPartiallyMapped=false)
Checks if a KiCad enum has been properly mapped to a Protobuf enum.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
#define BOOST_TEST_CONTEXT(A)