Coverage for /pythoncovmergedfiles/medio/medio/src/pyvex/fuzzing/enhanced_fdp.py: 80%
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"""
19from atheris import FuzzedDataProvider
22class EnhancedFuzzedDataProvider(FuzzedDataProvider):
23 """
24 Extends the functionality of FuzzedDataProvider
25 """
27 def _consume_random_count(self) -> int:
28 """
29 :return: A count of bytes that is strictly in range 0<=n<=remaining_bytes
30 """
31 return self.ConsumeIntInRange(0, self.remaining_bytes())
33 def ConsumeRandomBytes(self) -> bytes:
34 """
35 Consume a 'random' count of the remaining bytes
36 :return: 0<=n<=remaining_bytes bytes
37 """
38 return self.ConsumeBytes(self._consume_random_count())
40 def ConsumeRemainingBytes(self) -> bytes:
41 """
42 :return: The remaining buffer
43 """
44 return self.ConsumeBytes(self.remaining_bytes())
46 def ConsumeRandomString(self) -> str:
47 """
48 Consume a 'random' length string, excluding surrogates
49 :return: The string
50 """
51 return self.ConsumeUnicodeNoSurrogates(self._consume_random_count())
53 def ConsumeRemainingString(self) -> str:
54 """
55 :return: The remaining buffer, as a string without surrogates
56 """
57 return self.ConsumeUnicodeNoSurrogates(self.remaining_bytes())
59 def PickValueInEnum(self, enum):
60 return self.PickValueInList([e.value for e in enum])