Coverage Report

Created: 2023-09-25 06:29

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