/src/libavif/build/_deps/fuzztest-src/common/defs.h
Line | Count | Source |
1 | | // Copyright 2022 The Centipede Authors. |
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 | | // https://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 | | #ifndef FUZZTEST_COMMON_DEFS_H_ |
16 | | #define FUZZTEST_COMMON_DEFS_H_ |
17 | | |
18 | | // Only simple definitions here. No code, no dependencies. |
19 | | // span.h is an exception as it's header-only and very simple. |
20 | | |
21 | | #include <cstdint> |
22 | | #include <random> |
23 | | #include <string> |
24 | | #include <string_view> |
25 | | #include <vector> |
26 | | |
27 | | #include "absl/types/span.h" |
28 | | |
29 | | namespace centipede { |
30 | | |
31 | | // Just a good random number generator. |
32 | | using Rng = std::mt19937_64; |
33 | | |
34 | | using ByteArray = std::vector<uint8_t>; |
35 | | using ByteSpan = absl::Span<const uint8_t>; |
36 | | |
37 | | // Wraps a container's data into a `ByteSpan`. The lifetime of `blob` should be |
38 | | // >= that of the returned object. |
39 | | template <typename Container> |
40 | 0 | ByteSpan AsByteSpan(const Container &blob) { |
41 | 0 | return ByteSpan(reinterpret_cast<const uint8_t *>(blob.data()), |
42 | 0 | blob.size() * sizeof(typename Container::value_type)); |
43 | 0 | } |
44 | | |
45 | | // Reinterprets a `ByteSpan` as a string_view pointing at the same data. The |
46 | | // lifetime of `str` should be >= that of the returned object. |
47 | 0 | inline std::string_view AsStringView(ByteSpan str) { |
48 | 0 | return std::string_view(reinterpret_cast<const char *>(str.data()), |
49 | 0 | str.size()); |
50 | 0 | } |
51 | | |
52 | 0 | inline std::string AsString(ByteSpan str) { |
53 | 0 | return std::string(AsStringView(str)); |
54 | 0 | } |
55 | | |
56 | | // Macro used to allow tests to access protected or private members of a class. |
57 | | #define FRIEND_TEST(test_case_name, test_name) \ |
58 | | friend class test_case_name##_##test_name##_Test |
59 | | |
60 | | } // namespace centipede |
61 | | |
62 | | #endif // FUZZTEST_COMMON_DEFS_H_ |