Coverage for /pythoncovmergedfiles/medio/medio/src/pyvex/fuzzing/enhanced_fdp.py: 75%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright 2021 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################################################################################
16"""
17Defines the EnhancedFuzzedDataProvider
18"""
20from atheris import FuzzedDataProvider
23class EnhancedFuzzedDataProvider(FuzzedDataProvider):
24 """
25 Extends the functionality of FuzzedDataProvider
26 """
28 def _consume_random_count(self) -> int:
29 """
30 :return: A count of bytes that is strictly in range 0<=n<=remaining_bytes
31 """
32 return self.ConsumeIntInRange(0, self.remaining_bytes())
34 def ConsumeRandomBytes(self) -> bytes:
35 """
36 Consume a 'random' count of the remaining bytes
37 :return: 0<=n<=remaining_bytes bytes
38 """
39 return self.ConsumeBytes(self._consume_random_count())
41 def ConsumeRemainingBytes(self) -> bytes:
42 """
43 :return: The remaining buffer
44 """
45 return self.ConsumeBytes(self.remaining_bytes())
47 def ConsumeRandomString(self) -> str:
48 """
49 Consume a 'random' length string, excluding surrogates
50 :return: The string
51 """
52 return self.ConsumeUnicodeNoSurrogates(self._consume_random_count())
54 def ConsumeRemainingString(self) -> str:
55 """
56 :return: The remaining buffer, as a string without surrogates
57 """
58 return self.ConsumeUnicodeNoSurrogates(self.remaining_bytes())
60 def PickValueInEnum(self, enum):
61 return self.PickValueInList([e.value for e in enum])