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>
52template<
typename KiCadEnum,
typename ProtoEnum>
55 boost::bimap<ProtoEnum, KiCadEnum> protoToKiCadSeen;
56 std::set<ProtoEnum> seenProtos;
58 for( ProtoEnum value : magic_enum::enum_values<ProtoEnum>() )
60 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<ProtoEnum>() <<
"::"
61 << magic_enum::enum_name( value ) )
63 std::string
name( magic_enum::enum_name( value ) );
64 auto splitPos =
name.find_first_of(
'_' );
67 BOOST_REQUIRE_MESSAGE( splitPos != std::string::npos,
68 "Proto enum name doesn't have a prefix" );
70 std::string suffix =
name.substr( splitPos );
73 if(
static_cast<int>( value ) == 0 )
75 BOOST_REQUIRE_MESSAGE( suffix.compare(
"_UNKNOWN" ) == 0,
76 "Proto enum with value 0 must be named <PREFIX>_UNKNOWN" );
82 BOOST_REQUIRE_NO_THROW( result = ( FromProtoEnum<KiCadEnum, ProtoEnum>( value ) ) );
85 BOOST_REQUIRE( !protoToKiCadSeen.left.count( value ) );
86 protoToKiCadSeen.left.insert( { value, result } );
90 for( KiCadEnum value : magic_enum::enum_values<KiCadEnum>() )
92 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<KiCadEnum>() <<
"::"
93 << magic_enum::enum_name( value ) )
97 if( aPartiallyMapped )
101 result = ToProtoEnum<KiCadEnum, ProtoEnum>( value );
106 BOOST_REQUIRE_MESSAGE( !protoToKiCadSeen.right.count( value ),
107 "Proto enum is mapped to this KiCad enum, but not vice versa" );
114 BOOST_REQUIRE_NO_THROW( result = ( ToProtoEnum<KiCadEnum, ProtoEnum>( value ) ) );
118 BOOST_REQUIRE( result !=
static_cast<ProtoEnum
>( 0 ) );
121 BOOST_REQUIRE( !seenProtos.count( result ) );
122 seenProtos.insert( result );
125 KiCadEnum roundTrip = FromProtoEnum<KiCadEnum, ProtoEnum>( result );
126 BOOST_REQUIRE( roundTrip == value );
133 testEnums<GR_TEXT_H_ALIGN_T, types::HorizontalAlignment>();
138 testEnums<GR_TEXT_V_ALIGN_T, types::VerticalAlignment>();
143 testEnums<LINE_STYLE, types::StrokeLineStyle>();
148 testEnums<KICAD_T, types::KiCadObjectType>(
true );
153 testEnums<PCB_LAYER_ID, kiapi::board::types::BoardLayer>(
true );
158 testEnums<PAD_SHAPE, kiapi::board::types::PadStackShape>();
163 testEnums<ZONE_CONNECTION, kiapi::board::types::ZoneConnectionStyle>();
168 testEnums<PAD_ATTRIB, kiapi::board::types::PadType>();
173 testEnums<PADSTACK::MODE, kiapi::board::types::PadStackType>();
178 testEnums<PAD_DRILL_SHAPE, kiapi::board::types::DrillShape>();
183 testEnums<PADSTACK::UNCONNECTED_LAYER_MODE, kiapi::board::types::UnconnectedLayerRemoval>();
189 testEnums<VIATYPE, kiapi::board::types::ViaType>(
true );
194 testEnums<ISLAND_REMOVAL_MODE, kiapi::board::types::IslandRemovalMode>();
199 testEnums<ZONE_FILL_MODE, kiapi::board::types::ZoneFillMode>();
204 testEnums<ZONE_BORDER_DISPLAY_STYLE, kiapi::board::types::ZoneBorderStyle>();
209 testEnums<RULE_AREA_PLACEMENT_SOURCE_TYPE, kiapi::board::types::PlacementRuleSourceType>();
214 testEnums<TEARDROP_TYPE, kiapi::board::types::TeardropType>();
219 testEnums<DIM_TEXT_BORDER, kiapi::board::types::DimensionTextBorderStyle>();
224 testEnums<DIM_UNITS_FORMAT, kiapi::board::types::DimensionUnitFormat>();
229 testEnums<DIM_ARROW_DIRECTION, kiapi::board::types::DimensionArrowDirection>();
234 testEnums<DIM_PRECISION, kiapi::board::types::DimensionPrecision>();
239 testEnums<DIM_TEXT_POSITION, kiapi::board::types::DimensionTextPosition>();
244 testEnums<DIM_UNITS_MODE, kiapi::board::types::DimensionUnit>();
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)
BOOST_AUTO_TEST_SUITE_END()
Class ZONE_SETTINGS used to handle zones parameters in dialogs.