47void testEnums(
bool aPartiallyMapped =
false, std::optional<KiCadEnum> aNullMapping = std::nullopt )
49 boost::bimap<ProtoEnum, KiCadEnum> protoToKiCadSeen;
50 std::set<ProtoEnum> seenProtos;
52 for( ProtoEnum value : magic_enum::enum_values<ProtoEnum>() )
54 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<ProtoEnum>() <<
"::" << magic_enum::enum_name( value ) )
56 std::string
name( magic_enum::enum_name( value ) );
57 auto splitPos =
name.find_first_of(
'_' );
60 BOOST_REQUIRE_MESSAGE( splitPos != std::string::npos,
"Proto enum name doesn't have a prefix" );
62 std::string suffix =
name.substr( splitPos );
65 if(
static_cast<int>( value ) == 0 )
67 BOOST_REQUIRE_MESSAGE( suffix.compare(
"_UNKNOWN" ) == 0,
68 "Proto enum with value 0 must be named <PREFIX>_UNKNOWN" );
78 protoToKiCadSeen.left.insert( { value,
result } );
82 for( KiCadEnum value : magic_enum::enum_values<KiCadEnum>() )
84 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<KiCadEnum>() <<
"::" << magic_enum::enum_name( value ) )
88 if( aPartiallyMapped )
97 BOOST_REQUIRE_MESSAGE( !protoToKiCadSeen.right.count( value ),
98 "Proto enum is mapped to this KiCad enum, but not vice versa" );
110 || ( aNullMapping && *aNullMapping == value ) );
114 seenProtos.insert(
result );
127 BOOST_TEST_CONTEXT( aInput->GetFriendlyName() <<
": " << aInput->m_Uuid.AsStdString() )
129 constexpr bool isGroup = std::is_base_of_v<EDA_GROUP, std::decay_t<KiCadClass>>;
131 std::unordered_set<EDA_ITEM*> cachedItems;
133 if constexpr( isGroup )
134 cachedItems = aInput->GetItems();
136 google::protobuf::Any
any;
137 BOOST_REQUIRE_NO_THROW( aInput->Serialize(
any ) );
140 BOOST_REQUIRE_MESSAGE(
any.UnpackTo( &proto ),
141 "Any message did not unpack into the requested type" );
143 std::unique_ptr<KiCadClass> output = aCreateOutput();
145 bool deserializeResult =
false;
146 BOOST_REQUIRE_NO_THROW( deserializeResult = output->Deserialize(
any ) );
147 BOOST_REQUIRE_MESSAGE( deserializeResult,
"Deserialize failed" );
149 google::protobuf::Any outputAny;
150 BOOST_REQUIRE_NO_THROW( output->Serialize( outputAny ) );
152 if( !( outputAny.SerializeAsString() ==
any.SerializeAsString() ) )
156 BOOST_TEST_FAIL(
"Round-tripped protobuf does not match" );
159 if constexpr( isGroup )
161 if( output->GetItems() != cachedItems )
162 BOOST_TEST_FAIL(
"Round-tripped group does not match" );
166 aInput->AddItem( item );
168 else if( !output->operator==( *aInput ) )
170 BOOST_TEST_FAIL(
"Round-tripped object does not match" );
void testEnums(bool aPartiallyMapped=false, std::optional< KiCadEnum > aNullMapping=std::nullopt)
Checks if a KiCad enum has been properly mapped to a Protobuf enum.
wxString result
Test unit parsing edge cases and error handling.