4ae4fd8680d811aab3dbc9eb12f774045b347894
[openbsd] /
1 """
2 Tests expression evaluation in context of an objc class.
3 """
4
5 import lldb
6 import lldbsuite.test.lldbutil as lldbutil
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9
10 class ContextObjectObjcTestCase(TestBase):
11
12     mydir = TestBase.compute_mydir(__file__)
13
14     @skipUnlessDarwin
15     def test_context_object_objc(self):
16         """Tests expression evaluation in context of an objc class."""
17         self.build()
18
19         (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec)
20         frame = thread.GetFrameAtIndex(0)
21
22         #
23         # Test objc class variable
24         #
25
26         obj_val = frame.FindVariable("objcClass")
27         self.assertTrue(obj_val.IsValid())
28         obj_val = obj_val.Dereference()
29         self.assertTrue(obj_val.IsValid())
30
31         # Test an empty expression evaluation
32         value = obj_val.EvaluateExpression("")
33         self.assertFalse(value.IsValid())
34         self.assertFalse(value.GetError().Success())
35
36         # Test retrieving of a field (not a local with the same name)
37         value = obj_val.EvaluateExpression("field")
38         self.assertTrue(value.IsValid())
39         self.assertTrue(value.GetError().Success())
40         self.assertEqual(value.GetValueAsSigned(), 1111)
41
42         # Test if the self pointer is properly evaluated
43
44         # Test retrieving of an objcClass's property through the self pointer
45         value = obj_val.EvaluateExpression("self.property")
46         self.assertTrue(value.IsValid())
47         self.assertTrue(value.GetError().Success())
48         self.assertEqual(value.GetValueAsSigned(), 2222)
49
50         # Test objcClass's methods evaluation through the self pointer
51         value = obj_val.EvaluateExpression("[self method]")
52         self.assertTrue(value.IsValid())
53         self.assertTrue(value.GetError().Success())
54         self.assertEqual(value.GetValueAsSigned(), 3333)
55
56         # Test if we can use a computation result reference object correctly
57
58         obj_val = frame.EvaluateExpression("[ObjcClass createNew]")
59         self.assertTrue(obj_val.IsValid())
60         obj_val = obj_val.Dereference()
61         self.assertTrue(obj_val.IsValid())
62
63         # Test an expression evaluation on it
64         value = obj_val.EvaluateExpression("1")
65         self.assertTrue(value.IsValid())
66         self.assertTrue(value.GetError().Success())
67
68         # Test retrieving of a field on it
69         value = obj_val.EvaluateExpression("field")
70         self.assertTrue(value.IsValid())
71         self.assertTrue(value.GetError().Success())
72         self.assertEqual(value.GetValueAsSigned(), 1111)
73
74     def setUp(self):
75         TestBase.setUp(self)
76
77         self.main_source = "main.m"
78         self.main_source_spec = lldb.SBFileSpec(self.main_source)