Coverage Report

Created: 2025-10-10 06:15

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
1.02k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
18
1.02k
  FuzzedDataProvider fdp(data, size);
19
1.02k
  const char *fuzz_enum_key1 = fdp.ConsumeRandomLengthString().c_str();
20
1.02k
  const char *fuzz_enum_key2 = fdp.ConsumeRandomLengthString().c_str();
21
1.02k
  const char *fuzz_enum_key3 = fdp.ConsumeRandomLengthString().c_str();
22
1.02k
  const char *fuzz_enum_key4 = fdp.ConsumeRandomLengthString().c_str();
23
1.02k
  const char *fuzz_enum_key5 = fdp.ConsumeRandomLengthString().c_str();
24
1.02k
  const char *fuzz_enum_key6 = fdp.ConsumeRandomLengthString().c_str();
25
1.02k
  const char *fuzz_enum_key7 = fdp.ConsumeRandomLengthString().c_str();
26
1.02k
  enum class FuzzEnum : int {
27
1.02k
    fuzz_enum_key1 = -5,
28
1.02k
    fuzz_enum_key2 = 0,
29
1.02k
    fuzz_enum_key3 = 10,
30
1.02k
    fuzz_enum_key4 = 11,
31
1.02k
    fuzz_enum_key5 = 12,
32
1.02k
    fuzz_enum_key6 = 13,
33
1.02k
    fuzz_enum_key7 = 14,
34
1.02k
  };
35
1.02k
  constexpr auto &s7 = magic_enum::enum_values<const FuzzEnum>();
36
37
1.02k
  auto c1 = magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeIntegral<int>());
38
1.02k
  auto c2 = magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeRandomLengthString());
39
1.02k
  auto c3 = magic_enum::enum_entries<FuzzEnum>();
40
1.02k
  auto c4 = magic_enum::enum_values<FuzzEnum>();
41
1.02k
  auto c5 = magic_enum::enum_contains<FuzzEnum>(fdp.ConsumeIntegral<int>());
42
1.02k
  auto c6 = magic_enum::enum_contains<FuzzEnum>(fdp.ConsumeIntegral<int>());
43
1.02k
  auto c7 = magic_enum::enum_names<FuzzEnum>();
44
1.02k
  auto c8 = magic_enum::is_unscoped_enum<FuzzEnum>::value;
45
1.02k
  auto c9 = magic_enum::is_scoped_enum<FuzzEnum>::value;
46
1.02k
  auto c10 =
47
1.02k
      magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeRandomLengthString().c_str());
48
1.02k
  auto c11 = magic_enum::enum_cast<FuzzEnum>(fdp.ConsumeRandomLengthString());
49
50
1.02k
  auto e_count = magic_enum::enum_count<FuzzEnum>();
51
52
1.02k
  magic_enum::containers::set e_set{FuzzEnum::fuzz_enum_key1, FuzzEnum::fuzz_enum_key2};
53
1.02k
  auto s1 = e_set.empty();
54
1.02k
  auto s2 = e_set.size();
55
1.02k
  e_set.insert(FuzzEnum::fuzz_enum_key3);
56
1.02k
  e_set.clear();
57
58
1.02k
  auto e_bitset = magic_enum::containers::bitset<FuzzEnum>();
59
1.02k
  e_bitset.set(FuzzEnum::fuzz_enum_key3);
60
1.02k
  auto b0 = e_bitset.size();
61
1.02k
  auto b1 = e_bitset.all();
62
1.02k
  auto b2 = e_bitset.any();
63
1.02k
  auto b3 = e_bitset.none();
64
1.02k
  auto b4 = e_bitset.count();
65
66
1.02k
  return 0;
67
1.02k
}