Coverage Report

Created: 2025-12-03 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavif/build/_deps/fuzztest-src/fuzztest/domain.h
Line
Count
Source
1
// Copyright 2022 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// IWYU pragma: private, include "fuzztest/fuzztest.h"
16
// IWYU pragma: friend fuzztest/.*
17
18
#ifndef FUZZTEST_FUZZTEST_DOMAIN_H_
19
#define FUZZTEST_FUZZTEST_DOMAIN_H_
20
21
#include "./fuzztest/domain_core.h"  // IWYU pragma: export
22
#include "./fuzztest/internal/domains/in_regexp_impl.h"
23
#include "./fuzztest/internal/domains/protobuf_domain_impl.h"
24
25
namespace fuzztest {
26
27
// This namespace is here only as a way to disable ADL (argument-dependent
28
// lookup). Names should be used from the fuzztest:: namespace.
29
namespace internal_no_adl {
30
31
// InRegexp(regexp) represents strings that are sentences of a given regular
32
// expression `regexp`. The regular expression can use any syntax accepted by
33
// RE2 (https://github.com/google/re2/wiki/Syntax).
34
//
35
// Example usage:
36
//
37
//   InRegexp("[0-9]{4}-[0-9]{2}-[0-9]{2}")  // Date-like strings.
38
//
39
0
inline auto InRegexp(std::string_view regex) {
40
0
  return internal::InRegexpImpl(regex);
41
0
}
42
43
// ProtobufOf(std::function<const Message*()> get_prototype) creates a
44
// unique_ptr<Message> domain for the protobuf prototype (the default protobuf
45
// message) returned by `get_prototype()`.
46
//
47
// REQUIRES: `get_prototype` never returns nullptr.
48
//
49
// Example usage:
50
//
51
//   const Message* GetPrototypeMessage() {
52
//     const std::string name = GetPrototypeNameFromFlags();
53
//     const Descriptor* descriptor =
54
//         DescriptorPool::generated_pool()->FindMessageTypeByName(name);
55
//     return MessageFactory::generated_factory()->GetPrototype(descriptor);
56
//   }
57
//
58
//   ProtobufOf(GetPrototypeMessage)
59
template <typename PrototypeMessageProvider,
60
          typename T = std::remove_cv_t<std::remove_pointer_t<
61
              decltype(std::declval<PrototypeMessageProvider>()())>>>
62
auto ProtobufOf(PrototypeMessageProvider get_prototype) {
63
  constexpr bool kIsMessageClass = !std::is_copy_constructible_v<T>;
64
  if constexpr (kIsMessageClass) {
65
    return internal::ProtobufDomainUntypedImpl<T>(
66
        fuzztest::internal::PrototypePtr<T>(get_prototype),
67
        /*use_lazy_initialization=*/false);
68
  } else {  // T is derived class of Message
69
    using Message = typename T::Message;
70
    return internal::ProtobufDomainUntypedImpl<Message>(
71
        fuzztest::internal::PrototypePtr<Message>(get_prototype),
72
        /*use_lazy_initialization=*/false);
73
  }
74
}
75
76
}  // namespace internal_no_adl
77
78
// Inject the names from internal_no_adl into fuzztest, without allowing for
79
// ADL. Note that an `inline` namespace would not have this effect (ie it would
80
// still allow ADL to trigger).
81
using namespace internal_no_adl;  // NOLINT
82
83
}  // namespace fuzztest
84
85
#endif  // FUZZTEST_FUZZTEST_DOMAIN_H_