2 Tests expression evaluation in context of an objc class.
6 import lldbsuite.test.lldbutil as lldbutil
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
10 class ContextObjectObjcTestCase(TestBase):
12 mydir = TestBase.compute_mydir(__file__)
15 def test_context_object_objc(self):
16 """Tests expression evaluation in context of an objc class."""
19 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec)
20 frame = thread.GetFrameAtIndex(0)
23 # Test objc class variable
26 obj_val = frame.FindVariable("objcClass")
27 self.assertTrue(obj_val.IsValid())
28 obj_val = obj_val.Dereference()
29 self.assertTrue(obj_val.IsValid())
31 # Test an empty expression evaluation
32 value = obj_val.EvaluateExpression("")
33 self.assertFalse(value.IsValid())
34 self.assertFalse(value.GetError().Success())
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)
42 # Test if the self pointer is properly evaluated
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)
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)
56 # Test if we can use a computation result reference object correctly
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())
63 # Test an expression evaluation on it
64 value = obj_val.EvaluateExpression("1")
65 self.assertTrue(value.IsValid())
66 self.assertTrue(value.GetError().Success())
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)
77 self.main_source = "main.m"
78 self.main_source_spec = lldb.SBFileSpec(self.main_source)