48void testEnums(
bool aPartiallyMapped =
false, std::optional<KiCadEnum> aNullMapping = std::nullopt )
50 boost::bimap<ProtoEnum, KiCadEnum> protoToKiCadSeen;
51 std::set<ProtoEnum> seenProtos;
53 for( ProtoEnum value : magic_enum::enum_values<ProtoEnum>() )
55 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<ProtoEnum>() <<
"::" << magic_enum::enum_name( value ) )
57 std::string
name( magic_enum::enum_name( value ) );
58 auto splitPos =
name.find_first_of(
'_' );
61 BOOST_REQUIRE_MESSAGE( splitPos != std::string::npos,
"Proto enum name doesn't have a prefix" );
63 std::string suffix =
name.substr( splitPos );
66 if(
static_cast<int>( value ) == 0 )
68 BOOST_REQUIRE_MESSAGE( suffix.compare(
"_UNKNOWN" ) == 0,
69 "Proto enum with value 0 must be named <PREFIX>_UNKNOWN" );
79 protoToKiCadSeen.left.insert( { value,
result } );
83 for( KiCadEnum value : magic_enum::enum_values<KiCadEnum>() )
85 BOOST_TEST_CONTEXT( magic_enum::enum_type_name<KiCadEnum>() <<
"::" << magic_enum::enum_name( value ) )
89 if( aPartiallyMapped )
98 BOOST_REQUIRE_MESSAGE( !protoToKiCadSeen.right.count( value ),
99 "Proto enum is mapped to this KiCad enum, but not vice versa" );
111 || ( aNullMapping && *aNullMapping == value ) );
115 seenProtos.insert(
result );
128 BOOST_TEST_CONTEXT( aInput->GetFriendlyName() <<
": " << aInput->m_Uuid.AsStdString() )
130 constexpr bool isGroup = std::is_base_of_v<EDA_GROUP, std::decay_t<KiCadClass>>;
132 std::unordered_set<EDA_ITEM*> cachedItems;
134 if constexpr( isGroup )
135 cachedItems = aInput->GetItems();
137 google::protobuf::Any
any;
138 BOOST_REQUIRE_NO_THROW( aInput->Serialize(
any ) );
141 BOOST_REQUIRE_MESSAGE(
any.UnpackTo( &proto ),
142 "Any message did not unpack into the requested type" );
144 std::unique_ptr<KiCadClass> output = aCreateOutput();
146 bool deserializeResult =
false;
147 BOOST_REQUIRE_NO_THROW( deserializeResult = output->Deserialize(
any ) );
148 BOOST_REQUIRE_MESSAGE( deserializeResult,
"Deserialize failed" );
150 if constexpr( isGroup )
151 output->FinalizeGroupDeserialization();
153 google::protobuf::Any outputAny;
154 BOOST_REQUIRE_NO_THROW( output->Serialize( outputAny ) );
156 ProtoClass outputProto;
157 BOOST_REQUIRE_MESSAGE( outputAny.UnpackTo( &outputProto ),
158 "Round-tripped Any message did not unpack into the requested type" );
160 if( !google::protobuf::util::MessageDifferencer::Equals( proto, outputProto ) )
164 BOOST_TEST_FAIL(
"Round-tripped protobuf does not match" );
167 if constexpr( isGroup )
169 if( output->GetItems() != cachedItems )
170 BOOST_TEST_FAIL(
"Round-tripped group does not match" );
174 aInput->AddItem( item );
176 else if( !output->operator==( *aInput ) )
178 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.