def testDefaultValueWhenFuzzableBeforeMutation(self): fields = [String('a'), Container([Static('A'), String('B')])] default_container = Container(fields=fields, fuzzable=False) default_rendered = default_container.render() uut = self.get_uut(fields, fuzzable=True) uut_rendered = uut.render() self.assertEqual(default_rendered, uut_rendered)
def testContainsAllDefaultMutations(self): fields = [String('a'), Container([Static('A'), String('B')])] default_container = Container(fields=fields) default_mutations = self.get_all_mutations(default_container) uut = self.get_uut(fields) uut_mutations = self.get_all_mutations(uut) for mutation in default_mutations: self.assertIn(mutation, uut_mutations)
def testDefaultValueWhenFuzzableAfterReset(self): fields = [String('a'), Container([Static('A'), String('B')])] default_container = Container(fields=fields, fuzzable=False) default_rendered = default_container.render() uut = self.get_uut(fields, fuzzable=True) while uut.mutate(): pass uut.reset() uut_rendered = uut.render() self.assertEqual(default_rendered, uut_rendered)
def testCopy(self): fields = [ String('test_string', name='field1'), If(Equal('test_group_5', 'A'), String('if', name='if_field3'), name='if2'), IfNot(Equal('test_group_5', 'A'), String('ifnot', name='ifnot_field5'), name='ifnot4'), Group(name='test_group_5', values=['A', 'B', 'C']) ] uut = self.get_default_container(fields) uut_copy = uut.copy() uut_mutations = self.get_all_mutations(uut, reset=False) copy_mutations = self.get_all_mutations(uut_copy, reset=False) self.assertEqual(uut_mutations, copy_mutations)
def testGetRenderedFieldsCorrect(self): fields = [ String('test_string', name='field1'), If(Equal('test_group_5', 'A'), String('if', name='if_field3'), name='if2'), IfNot(Equal('test_group_5', 'A'), String('ifnot', name='ifnot_field5'), name='ifnot4'), Group(name='test_group_5', values=['A', 'B', 'C']) ] container = self.get_default_container(fields) if len(container.render()): self.assertEqual(len(container.get_rendered_fields()), 1) while container.mutate(): if len(container.render()): self.assertEqual(len(container.get_rendered_fields()), 1) else: self.assertEqual(len(container.get_rendered_fields()), 0)
def testRepeatSingleMaxTimes5(self): max_times = 5 fields = [ String('field1') ] repeater = Repeat(fields=fields, max_times=max_times) self._test_mutations(repeater, fields, max_times=max_times)
def get_default_container(self, fields=[], fuzzable=True, mutated_field=None): if mutated_field is None: mutated_field = String('static field') return OneOf(fields=fields, fuzzable=fuzzable, name=self.uut_name)
def testDelimiterExist(self): num_elems = 3 fields = [Static('A') for i in range(num_elems)] uut = self.get_uut(fields=fields, delim=String('/')) mutations = [m.tobytes().decode() for m in self.get_all_mutations(uut)] for m in mutations: if m != '': self.assertEqual(m.count('/'), (len(m) - 1) // 2)
def testlways(self): field = self.get_condition_field() condition = self.get_not_applies_always_condition() condition_container = self.cls(condition=condition, fields=[String(ConditionTest.inner_field_value)], fuzzable=True) # This is done to allow field name resolution enclosing = Container(fields=[field, condition_container]) rendered = condition_container.render() self.assertEqual(rendered, Bits()) while condition_container.mutate(): rendered = condition_container.render() self.assertEqual(rendered, Bits()) del enclosing
def testHashTheSameAfterReset(self): container = Pad(pad_length=10 * 8, fields=String('abc'), pad_data='\xff') hash_after_creation = container.hash() container.mutate() hash_after_mutate = container.hash() self.assertEqual(hash_after_creation, hash_after_mutate) container.reset() hash_after_reset = container.hash() self.assertEqual(hash_after_creation, hash_after_reset) while container.mutate(): hash_after_mutate_all = container.hash() self.assertEqual(hash_after_creation, hash_after_mutate_all) container.render() hash_after_render_all = container.hash() self.assertEqual(hash_after_creation, hash_after_render_all)