chromium/testing/libfuzzer/fuzzers/paint_vector_icon_fuzztest.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/command_line.h"
#include "skia/ext/switches.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/fuzztest/src/fuzztest/fuzztest.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/gfx/vector_icon_utils.h"

namespace {

Arbitrary;
Domain;
ElementOf;
Finite;
FlatMap;
InRange;
Just;
Map;
NonEmpty;
StructOf;
VariantOf;
VectorOf;

// Fuzztest does not yet support enums out of the box, but thankfully the
// `gfx::CommandType` enum is defined through a pair of macros that work very
// well for us. `DECLARE_VECTOR_COMMAND(x)` is supposed to be overridden like
// this before `DECLARE_VECTOR_COMMANDS` can be used. Dependency injection!
#define DECLARE_VECTOR_COMMAND(x)

// That allows us to define a domain that contains only valid vector commands.
auto AnyCommandType() {}

// Each command type has a specific number of args it expects, otherwise the
// command validation code CHECK-fails. We thus make sure to generate only
// valid sequences of `gfx::PathElement`s by packaging commands with the right
// number of arguments.
struct Command {};

// Returns the domain of all possible arguments for the given command.
//
// We need this to account for the fact that not all arguments are valid for
// all commands, and passing invalid arguments can trigger shallow CHECK
// failures that prevent deeper fuzzing.
Domain<std::vector<SkScalar>> AnyArgsForCommandType(gfx::CommandType type) {}

Domain<Command> AnyCommandWithType(gfx::CommandType type) {}

// Returns the domain of all possible commands.
auto AnyCommand() {}

// Flattens the given `commands` into a sequence of path elements that can be
// passed to `PaintVectorIcon()`.
std::vector<gfx::PathElement> ConvertCommands(
    const std::vector<Command>& commands) {}

class PaintVectorIconFuzzTest {};

FUZZ_TEST_F();

}  // namespace