Skip to content

Commit 8d5cb72

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#246 from diffblue/owen/tests-for-lvsa
Add LVSA test for a field of a dynamic object
2 parents ffd011e + 1e5d5ed commit 8d5cb72

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed
493 Bytes
Binary file not shown.

regression/LVSA/TestBasic/Test.class

225 Bytes
Binary file not shown.

regression/LVSA/TestBasic/Test.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package LVSA.TestBasic;
22

33
public class Test {
4-
static Object output;
4+
static A output;
55

6-
public static void outputs_null() {
6+
public class A {
7+
public Object instanceObj;
8+
public boolean someBoolean;
9+
}
10+
11+
public void outputs_null() {
712
output = null;
813
}
914

10-
public static void outputs_dynamic_object() {
11-
output = new Object();
15+
public void outputs_dynamic_object() {
16+
output = new A();
17+
}
18+
19+
public void outputs_dynamic_object_with_allocated_field() {
20+
output = new A();
21+
output.instanceObj = new Object();
1222
}
1323
}

regression/LVSA/TestBasic/test_basic.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ def test_outputs_dynamic_object(tmpdir):
2222

2323
output_value_expectation.check_number_of_values(1)
2424
output_value_expectation.check_contains_dynamic_object()
25+
26+
27+
def test_outputs_dynamic_object_with_allocated_field(tmpdir):
28+
lvsa_driver = LvsaDriver(tmpdir, folder_name).with_test_function('outputs_dynamic_object_with_allocated_field')
29+
lvsa_expectation = lvsa_driver.run()
30+
31+
output_value_expectation = lvsa_expectation.check_output()
32+
33+
output_value_expectation.check_number_of_values(1)
34+
output_value_expectation.check_contains_dynamic_object()
35+
dynamic_object_id = output_value_expectation.get_dynamic_object_ids()[0]
36+
37+
output_value_expectation = lvsa_expectation.check_value_set(dynamic_object_id, '.instanceObj', most_recent=True)
38+
39+
output_value_expectation.check_number_of_values(1)
40+
output_value_expectation.check_contains_dynamic_object()

regression/LVSA/lvsa_driver.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def check_contains_external_value_set(self, expected_number=1, is_external_objec
7575
matches = [x for x in matches if x.has_been_read == has_been_read]
7676
assert expected_number == len(matches)
7777

78+
def get_dynamic_object_ids(self):
79+
return [dynamic_object.instance['id'] for dynamic_object in self.dynamic_objects]
80+
7881

7982
class LvsaExpectation:
8083
"""Encapsulate the output of LvsaDriver"""
@@ -136,6 +139,17 @@ def check_external_value_set(self, inner_class=None, suffix=None):
136139
assert len(matches) == 1
137140
return VariableExpectation(matches[0])
138141

142+
def check_value_set(self, dynamic_object_id, suffix, most_recent=None):
143+
target_id = 'value_set::dynamic_object' + dynamic_object_id
144+
if most_recent is True:
145+
target_id += 'most_recent_allocation'
146+
if most_recent is False:
147+
target_id += 'any_allocation'
148+
matches = [var_state for var_state in self.state if
149+
var_state['id'].startswith(target_id) and var_state['suffix'] == suffix]
150+
assert len(matches) == 1
151+
return VariableExpectation(matches[0])
152+
139153

140154
class LvsaDriver:
141155
"""Run LVSA"""

0 commit comments

Comments
 (0)