Skip to content

Internal only change. #1649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion fuzztest/internal/type_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
#include "./fuzztest/internal/meta.h"
#include "./fuzztest/internal/printer.h"

namespace google::protobuf {
class EnumDescriptor;

template <typename E>
const EnumDescriptor* GetEnumDescriptor();
} // namespace google::protobuf

namespace fuzztest::internal {

// Return a best effort printer for type `T`.
Expand Down Expand Up @@ -575,7 +582,11 @@ struct UnknownPrinter {

template <typename T>
decltype(auto) AutodetectTypePrinter() {
if constexpr (std::numeric_limits<T>::is_integer || std::is_enum_v<T>) {
if constexpr (is_protocol_buffer_enum_v<T>) {
return ProtobufEnumPrinter<const google::protobuf::EnumDescriptor*>{
google::protobuf::GetEnumDescriptor<T>()};
} else if constexpr (std::numeric_limits<T>::is_integer ||
std::is_enum_v<T>) {
return IntegralPrinter{};
} else if constexpr (std::is_floating_point_v<T>) {
return FloatingPrinter{};
Expand Down
13 changes: 13 additions & 0 deletions fuzztest/internal/type_support_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ TEST(ProtobufEnumTest, Printer) {
EXPECT_THAT(TestPrintValue(internal::BareEnum::LABEL_OTHER, bare_domain),
ElementsAre("fuzztest::internal::BareEnum::LABEL_OTHER (10)",
"fuzztest::internal::BareEnum::LABEL_OTHER"));

auto element_domain = ElementOf(
{internal::TestProtobuf::Label3, internal::TestProtobuf::Label4});
using corpus_type = corpus_type_t<decltype(element_domain)>;
EXPECT_THAT(TestPrintValue(corpus_type(0), element_domain),
ElementsAre("fuzztest::internal::TestProtobuf::Label3 (2)",
"fuzztest::internal::TestProtobuf::Label3"));

auto bare_element_domain = ElementOf({internal::BareEnum::LABEL_OTHER});
using corpus_type = corpus_type_t<decltype(bare_element_domain)>;
EXPECT_THAT(TestPrintValue(corpus_type(0), bare_element_domain),
ElementsAre("fuzztest::internal::BareEnum::LABEL_OTHER (10)",
"fuzztest::internal::BareEnum::LABEL_OTHER"));
}

TEST(ContainerTest, Printer) {
Expand Down