44 boost::bimap<ProtoEnum, KiCadEnum> protoToKiCadSeen;
45 std::set<ProtoEnum> seenProtos;
47 for( ProtoEnum value : magic_enum::enum_values<ProtoEnum>() )
49 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<ProtoEnum>() <<
"::" << magic_enum::enum_name( value ) )
51 std::string
name( magic_enum::enum_name( value ) );
52 auto splitPos =
name.find_first_of(
'_' );
55 BOOST_REQUIRE_MESSAGE( splitPos != std::string::npos,
"Proto enum name doesn't have a prefix" );
57 std::string suffix =
name.substr( splitPos );
60 if(
static_cast<int>( value ) == 0 )
62 BOOST_REQUIRE_MESSAGE( suffix.compare(
"_UNKNOWN" ) == 0,
63 "Proto enum with value 0 must be named <PREFIX>_UNKNOWN" );
73 protoToKiCadSeen.left.insert( { value,
result } );
77 for( KiCadEnum value : magic_enum::enum_values<KiCadEnum>() )
79 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<KiCadEnum>() <<
"::" << magic_enum::enum_name( value ) )
83 if( aPartiallyMapped )
92 BOOST_REQUIRE_MESSAGE( !protoToKiCadSeen.right.count( value ),
93 "Proto enum is mapped to this KiCad enum, but not vice versa" );
108 seenProtos.insert(
result );
121 BOOST_TEST_CONTEXT( aInput->GetFriendlyName() <<
": " << aInput->m_Uuid.AsStdString() )
123 google::protobuf::Any
any;
124 BOOST_REQUIRE_NO_THROW( aInput->Serialize(
any ) );
127 BOOST_REQUIRE_MESSAGE(
any.UnpackTo( &proto ),
128 "Any message did not unpack into the requested type" );
130 std::unique_ptr<KiCadClass>
output = aCreateOutput();
132 bool deserializeResult =
false;
133 BOOST_REQUIRE_NO_THROW( deserializeResult =
output->Deserialize(
any ) );
134 BOOST_REQUIRE_MESSAGE( deserializeResult,
"Deserialize failed" );
136 google::protobuf::Any outputAny;
137 BOOST_REQUIRE_NO_THROW(
output->Serialize( outputAny ) );
139 if( !( outputAny.SerializeAsString() ==
any.SerializeAsString() ) )
143 BOOST_TEST_FAIL(
"Round-tripped protobuf does not match" );
146 if( !
output->operator==( *aInput ) )
147 BOOST_TEST_FAIL(
"Round-tripped object does not match" );
wxString result
Test unit parsing edge cases and error handling.