Exemple #1
0
    def test_set_sets_can_associate_data_to_UNDEFINED(self):
        environment = Environment(environment={})

        data = DataSet({'value'}, 6)
        environment.set(UNDEFINED, data)

        # Testing internal attribute which is not ideal, but I am trying to not rely on any other behavior
        # (e.g. without using `get`).
        self.assertDictEqual(environment._environment, {UNDEFINED: data})
Exemple #2
0
    def test_get_returns_a_dataset_with_UNDEFINED_when_the_environment_variable_is_not_set(
            self):
        environment = Environment(environment={})

        name = 'variable_name'
        variable_names = {name}

        result_values, _ = environment.get(variable_names)
        self.assertEqual(result_values, {UNDEFINED})
Exemple #3
0
    def test_get_returns_a_dataset_with_UNDEFINED_when_the_environment_variable_is_not_set(
            self):
        environment = Environment(environment={})

        name = 'variable_name'
        variable_names = DataSet({name}, len(name))

        result_values, _ = environment.get(variable_names)
        self.assertEqual(result_values, DataSet({UNDEFINED}, UNKNOWN_SIZE))
Exemple #4
0
    def test_set_sets_associates_data_to_a_given_variable_name(self):
        environment = Environment(environment={})

        data = DataSet({'value'}, 6)
        environment.set('variable_name', data)

        # Testing internal attribute which is not ideal, but I am trying to not rely on any other behavior
        # (e.g. without using `get`).
        self.assertDictEqual(environment._environment, {'variable_name': data})
Exemple #5
0
    def test_get_returns_the_pointer_associated_with_an_existing_environment_variable(
            self):
        name = 'variable_name'
        data = DataSet({self.pointer}, self.pointer_length)
        environment = Environment(environment={name: data})

        variable_names = DataSet({name}, len(name))

        result_values, _ = environment.get(variable_names)
        self.assertEqual(result_values, data)
Exemple #6
0
    def test_get_returns_the_pointer_associated_with_an_existing_environment_variable(
            self):
        name = 'variable_name'
        data = {claripy.BVV(self.pointer, self.pointer_length)}
        environment = Environment(environment={name: data})

        variable_names = {name}

        result_values, _ = environment.get(variable_names)
        self.assertEqual(result_values, data)
Exemple #7
0
    def test_get_result_tells_if_environment_does_not_know_about_one_of_the_variable(
            self):
        name = 'variable_name'
        data = {claripy.BVV(b'value\x00', 6 * 8)}
        environment = Environment(environment={name: data})

        name = 'variable_name'
        variable_names = {name, 'unknown_name'}

        _, has_unknown = environment.get(variable_names)
        self.assertTrue(has_unknown)
Exemple #8
0
    def test_get_result_tells_if_environment_knows_about_all_the_variables(
            self):
        name = 'variable_name'
        data = {claripy.BVV(self.pointer, self.pointer_length)}
        environment = Environment(environment={name: data})

        name = 'variable_name'
        variable_names = {name}

        _, has_unknown = environment.get(variable_names)
        self.assertFalse(has_unknown)
Exemple #9
0
    def test_get_result_tells_if_environment_knows_about_all_the_variables(
            self):
        name = 'variable_name'
        data = DataSet({self.pointer}, self.pointer_length)
        environment = Environment(environment={name: data})

        name = 'variable_name'
        variable_names = DataSet({name}, UNKNOWN_SIZE)

        _, has_unknown = environment.get(variable_names)
        self.assertFalse(has_unknown)
Exemple #10
0
    def test_get_result_tells_if_environment_does_not_know_about_one_of_the_variable(
            self):
        name = 'variable_name'
        data = DataSet({'value'}, 6)
        environment = Environment(environment={name: data})

        name = 'variable_name'
        variable_names = DataSet({name, 'unknown_name'}, UNKNOWN_SIZE)

        _, has_unknown = environment.get(variable_names)
        self.assertTrue(has_unknown)
Exemple #11
0
    def test_get_returns_values_associated_with_all_possible_given_names(self):
        environment_data = {
            'variable_name': DataSet({self.pointer}, self.pointer_length),
            UNDEFINED: DataSet({UNDEFINED}, UNKNOWN_SIZE)
        }
        environment = Environment(environment=environment_data)

        variable_names = DataSet({'variable_name', UNDEFINED}, UNKNOWN_SIZE)
        expected_result = DataSet({self.pointer, UNDEFINED}, UNKNOWN_SIZE)

        result_values, _ = environment.get(variable_names)
        self.assertEqual(result_values, expected_result)
Exemple #12
0
    def test_get_returns_values_associated_with_all_possible_given_names(self):
        environment_data = {
            'variable_name': {claripy.BVV(self.pointer, self.pointer_length)},
            UNDEFINED: {UNDEFINED},
        }
        environment = Environment(environment=environment_data)

        variable_names = {'variable_name', UNDEFINED}
        expected_result = {
            claripy.BVV(self.pointer, self.pointer_length), UNDEFINED
        }

        result_values, _ = environment.get(variable_names)
        self.assertEqual(result_values, expected_result)
Exemple #13
0
    def test_merge_two_environments_merge_data_associated_with_each_variable(
            self):
        first = 'variable_name'
        second = 'other_variable_name'
        environment = Environment(environment={first: DataSet({'value1'}, 7)})
        other_environment = Environment(
            environment={
                first: DataSet({'value2'}, 7),
                second: DataSet({UNDEFINED}, UNKNOWN_SIZE)
            })

        expected_environment = Environment(
            environment={
                first: DataSet({'value1', 'value2'}, 7),
                second: DataSet({UNDEFINED}, UNKNOWN_SIZE)
            })

        self.assertEqual(environment.merge(other_environment),
                         expected_environment)
Exemple #14
0
    def test_merge_two_environments_merge_data_associated_with_each_variable(
            self):
        first = 'variable_name'
        second = 'other_variable_name'
        environment = Environment(
            environment={first: {claripy.BVV(b'value1\x00', 7 * 8)}})
        other_environment = Environment(environment={
            first: {claripy.BVV(b'value2\x00', 7 * 8)},
            second: {UNDEFINED}
        })

        expected_environment = Environment(
            environment={
                first: {
                    claripy.BVV(b'value1\x00', 7 * 8),
                    claripy.BVV(b'value2\x00', 7 * 8)
                },
                second: {UNDEFINED}
            })

        self.assertEqual(environment.merge(other_environment),
                         expected_environment)
Exemple #15
0
    def test_merge_fails_when_merging_with_a_non_Environment_instance(self):
        environment = Environment(
            environment={'variable_name': DataSet({'value1'}, 7)})
        other_environment = 0x42

        self.assertRaises(TypeError, environment.merge, other_environment)
Exemple #16
0
    def test_get_fails_when_called_with_wrong_type_of_name(self):
        environment = Environment(environment={})
        variable_names = DataSet({0x42}, 8)

        self.assertRaises(TypeError, environment.get, variable_names)
Exemple #17
0
    def test_get_fails_when_called_with_wrong_type_of_name(self):
        environment = Environment(environment={})
        variable_names = {claripy.BVV(0x42, 8 * 8)}

        self.assertRaises(TypeError, environment.get, variable_names)
Exemple #18
0
    def test_merge_fails_when_merging_with_a_non_Environment_instance(self):
        environment = Environment(
            environment={'variable_name': {claripy.BVV(b'value1\x00', 7 * 8)}})
        other_environment = 0x42

        self.assertRaises(TypeError, environment.merge, other_environment)
Exemple #19
0
    def test_set_fails_when_wvariable_name_is_of_wrong_type(self):
        environment = Environment(environment={})

        data = DataSet({'value'}, 6)

        self.assertRaises(TypeError, environment.set, 0x42, data)
Exemple #20
0
    def test_set_fails_when_wvariable_name_is_of_wrong_type(self):
        environment = Environment(environment={})

        data = {claripy.BVV(b'value\x00', 6 * 8)}

        self.assertRaises(TypeError, environment.set, 0x42, data)