Coverage Report

Created: 2026-09-01 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/magic_enum_fuzzer.cc
Line
Count
Source
1
/* Copyright 2023 Google LLC
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
      http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
*/
12
#include <fuzzer/FuzzedDataProvider.h>
13
#include <iostream>
14
#include <magic_enum.hpp>
15
#include <magic_enum_containers.hpp>
16
17
969
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
18
969
  FuzzedDataProvider fdp(data, size);
19
969
  const char *fuzz_enum_key1 = fdp.ConsumeRandomLengthString().c_str();
20
969
  const char *fuzz_enum_key2 = fdp.ConsumeRandomLengthString().c_str();
21
969
  const char *fuzz_enum_key3 = fdp.ConsumeRandomLengthString().c_str();
22
969
  const char *fuzz_enum_key4 = fdp.ConsumeRandomLengthString().c_str();
23
969
  const char *fuzz_enum_key5 = fdp.ConsumeRandomLengthString().c_str();
24
969
  const char *fuzz_enum_key6 = fdp.ConsumeRandomLengthString().c_str();
25
969
  const char *fuzz_enum_key7 = fdp.ConsumeRandomLengthString().c_str();
26
969
  enum class FuzzEnum : int {
27
969
    fuzz_enum_key1 = -5,
28
969
    fuzz_enum_key2 = 0,
29
969
    fuzz_enum_key3 = 10,
30
969
    fuzz_enum_key4 = 11,
31
969
    fuzz_enum_key5 = 12,
32
969
    fuzz_enum_key6 = 13,
33
969
    fuzz_enum_key7 = 14,
34
969
  };
35
969
  constexpr auto &s7 = magic_enum::enum_values<const FuzzEnum>();
36
37
969
  auto c1 = magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeIntegral<int>());
38
969
  auto c2 = magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeRandomLengthString());
39
969
  auto c3 = magic_enum::enum_entries<FuzzEnum>();
40
969
  auto c4 = magic_enum::enum_values<FuzzEnum>();
41
969
  auto c5 = magic_enum::enum_contains<FuzzEnum>(fdp.ConsumeIntegral<int>());
42
969
  auto c6 = magic_enum::enum_contains<FuzzEnum>(fdp.ConsumeIntegral<int>());
43
969
  auto c7 = magic_enum::enum_names<FuzzEnum>();
44
969
  auto c8 = magic_enum::is_unscoped_enum<FuzzEnum>::value;
45
969
  auto c9 = magic_enum::is_scoped_enum<FuzzEnum>::value;
46
969
  auto c10 =
47
969
      magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeRandomLengthString().c_str());
48
969
  auto c11 = magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeRandomLengthString());
49
50
969
  auto e_count = magic_enum::enum_count<FuzzEnum>();
51
52
969
  magic_enum::containers::set e_set{FuzzEnum::fuzz_enum_key1, FuzzEnum::fuzz_enum_key2};
53
969
  auto s1 = e_set.empty();
54
969
  auto s2 = e_set.size();
55
969
  e_set.insert(FuzzEnum::fuzz_enum_key3);
56
969
  e_set.clear();
57
58
969
  auto e_bitset = magic_enum::containers::bitset<FuzzEnum>();
59
969
  e_bitset.set(FuzzEnum::fuzz_enum_key3);
60
969
  auto b0 = e_bitset.size();
61
969
  auto b1 = e_bitset.all();
62
969
  auto b2 = e_bitset.any();
63
969
  auto b3 = e_bitset.none();
64
969
  auto b4 = e_bitset.count();
65
66
969
  return 0;
67
969
}