Skip to content

Commit 0812f44

Browse files
authored
Add custom FuzzTest printers for types (AOMediaCodec#3039)
with C-style arrays. These printers are necessary to prevent compile-time errors in FuzzTest when it attempts to generate source code representations for structs containing C-style array fields. The `FuzzTestPrintSourceCode` functions are placed in the appropriate namespaces to enable Argument-Dependent Lookup (ADL), allowing FuzzTest to find and use them. For more information about custom value printers for FuzzTest, see https://github.com/google/fuzztest/blob/main/doc/domains-reference.md# customizing-value-printers-custom-value-printers
1 parent f0aac7d commit 0812f44

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/gtest/avif_fuzztest_helpers.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <cstdint>
88
#include <cstdlib>
99
#include <limits>
10+
#include <type_traits>
1011
#include <utility>
1112
#include <vector>
1213

@@ -17,6 +18,24 @@
1718
#include "gtest/gtest.h"
1819

1920
namespace avif {
21+
22+
//------------------------------------------------------------------------------
23+
// Custom FuzzTest printer for libavif types. Needed to avoid compile-time
24+
// errors due to structs with C-style array fields.
25+
//
26+
// These should reside in the same namespace as the types they print to enable
27+
// Argument-Dependent Lookup (ADL).
28+
// See https://github.com/google/fuzztest/blob/main/doc/domains-reference.md.
29+
template <typename Sink, typename Ptr,
30+
typename = std::enable_if_t<std::is_same_v<Ptr, ImagePtr> ||
31+
std::is_same_v<Ptr, EncoderPtr> ||
32+
std::is_same_v<Ptr, DecoderPtr>>>
33+
void FuzzTestPrintSourceCode(Sink& sink, const Ptr& ptr) {
34+
// Stub to avoid compile error for structs with C-style array fields.
35+
// Consider adding a useful source code representation here:
36+
// `absl::Format(&sink, ...);`
37+
}
38+
2039
namespace testutil {
2140

2241
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)