| // WARNING: This file is machine generated by fidlgen. |
| |
| #pragma once |
| |
| #include <test/handlesintypes/cpp/fidl.h> |
| |
| #include "lib/fidl/cpp/fuzzing/traits.h" |
| #include "lib/fidl/cpp/internal/header.h" |
| // For ::std::max_element(). |
| #include <algorithm> |
| // For uint64_t. |
| #include <stdint.h> |
| |
| namespace fuzzing { |
| |
| using obj_type = ::test::handlesintypes::obj_type; |
| using UnionWithHandle = ::test::handlesintypes::UnionWithHandle; |
| using TableWithHandle = ::test::handlesintypes::TableWithHandle; |
| using HandlesInTypes = ::test::handlesintypes::HandlesInTypes; |
| |
| template <> |
| struct MinSize<obj_type> { |
| operator size_t() { return sizeof(uint64_t); } |
| }; |
| template <> |
| struct Allocate<obj_type> { |
| obj_type operator()(FuzzInput* src, size_t* size) { |
| obj_type out; |
| uint64_t selector; |
| ZX_ASSERT(*size >= sizeof(uint64_t)); |
| ZX_ASSERT(src->CopyObject(&selector)); |
| *size = sizeof(uint64_t); |
| |
| switch (selector % 2) { |
| case 0: |
| out = obj_type::NONE; |
| break; |
| case 1: |
| out = obj_type::VMO; |
| break; |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<UnionWithHandle> { |
| operator size_t() { |
| size_t sizes[] = {0, MinSize<::zx::vmo>()}; |
| return 1 + *std::max_element(sizes, sizes + 1 + 1); |
| } |
| }; |
| template <> |
| struct Allocate<UnionWithHandle> { |
| static_assert(1 > 0, "xunion must have at least one member"); |
| |
| UnionWithHandle operator()(FuzzInput* src, size_t* size) { |
| ZX_ASSERT(*size >= MinSize<UnionWithHandle>()); |
| |
| uint8_t selector; |
| ZX_ASSERT(src->CopyBytes(&selector, 1)); |
| (*size)++; |
| |
| UnionWithHandle out; |
| switch (selector % 1) { |
| case 0: { |
| out.set_h(Allocate<::zx::vmo>{}(src, size)); |
| break; |
| } |
| } |
| |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<TableWithHandle> { |
| operator size_t() { |
| return MinSize<::zx::vmo>(); |
| } |
| }; |
| template <> |
| struct Allocate<TableWithHandle> { |
| TableWithHandle operator()(FuzzInput* src, size_t* size) { |
| ZX_ASSERT(*size >= MinSize<TableWithHandle>()); |
| TableWithHandle out; |
| const size_t slack_per_member = (*size - MinSize<TableWithHandle>()) / 1; |
| size_t out_size; |
| out_size = MinSize<::zx::vmo>() + slack_per_member; |
| out.set_h(Allocate<::zx::vmo>{}(src, &out_size)); |
| return out; |
| } |
| }; |
| template <> |
| struct MinSize<HandlesInTypes> { |
| operator size_t() { |
| return MinSize<::zx::vmo>() + MinSize<::std::vector<::zx::vmo>>() + MinSize<::std::array<::zx::vmo, 5>>() + MinSize<::std::vector<::std::array<::zx::vmo, 5>>>() + MinSize<::test::handlesintypes::TableWithHandle>() + MinSize<::test::handlesintypes::UnionWithHandle>(); |
| } |
| }; |
| template <> |
| struct Allocate<HandlesInTypes> { |
| HandlesInTypes operator()(FuzzInput* src, size_t* size) { |
| ZX_ASSERT(*size >= MinSize<HandlesInTypes>()); |
| HandlesInTypes out; |
| const size_t slack_per_member = (*size - MinSize<HandlesInTypes>()) / 6; |
| size_t out_size; |
| out_size = MinSize<::zx::vmo>() + slack_per_member; |
| out.normal_handle = Allocate<::zx::vmo>{}(src, &out_size); |
| out_size = MinSize<::std::vector<::zx::vmo>>() + slack_per_member; |
| out.handle_in_vec = Allocate<::std::vector<::zx::vmo>>{}(src, &out_size); |
| out_size = MinSize<::std::array<::zx::vmo, 5>>() + slack_per_member; |
| out.handle_in_array = Allocate<::std::array<::zx::vmo, 5>>{}(src, &out_size); |
| out_size = MinSize<::std::vector<::std::array<::zx::vmo, 5>>>() + slack_per_member; |
| out.handle_in_mixed_vec_array = Allocate<::std::vector<::std::array<::zx::vmo, 5>>>{}(src, &out_size); |
| out_size = MinSize<::test::handlesintypes::TableWithHandle>() + slack_per_member; |
| out.table_with_handle = Allocate<::test::handlesintypes::TableWithHandle>{}(src, &out_size); |
| out_size = MinSize<::test::handlesintypes::UnionWithHandle>() + slack_per_member; |
| out.union_with_handle = Allocate<::test::handlesintypes::UnionWithHandle>{}(src, &out_size); |
| return out; |
| } |
| }; |
| |
| } // namespace fuzzing |