2 Use lldb Python API to verify that expression evaluation for property references uses the correct getters and setters
5 from __future__ import print_function
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.lldbtest import *
15 class ObjCPropertyTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
23 # Find the line number to break for main.c.
24 self.source_name = 'main.m'
27 @add_test_categories(['pyapi'])
28 def test_objc_properties(self):
29 """Test that expr uses the correct property getters and setters"""
30 if self.getArchitecture() == 'i386':
31 self.skipTest("requires modern objc runtime")
34 exe = os.path.join(os.getcwd(), "a.out")
36 # Create a target from the debugger.
38 target = self.dbg.CreateTarget (exe)
39 self.assertTrue(target, VALID_TARGET)
41 # Set up our breakpoints:
43 main_bkpt = target.BreakpointCreateBySourceRegex ("Set a breakpoint here.", lldb.SBFileSpec (self.source_name))
44 self.assertTrue(main_bkpt and
45 main_bkpt.GetNumLocations() == 1,
48 # Now launch the process, and do not stop at the entry point.
49 process = target.LaunchSimple (None, None, self.get_process_working_directory())
51 self.assertTrue(process.GetState() == lldb.eStateStopped,
54 threads = lldbutil.get_threads_stopped_at_breakpoint (process, main_bkpt)
55 self.assertTrue (len(threads) == 1)
57 frame = thread.GetFrameAtIndex(0)
59 mine = frame.FindVariable ("mine")
60 self.assertTrue (mine.IsValid())
61 access_count = mine.GetChildMemberWithName ("_access_count")
62 self.assertTrue (access_count.IsValid())
63 start_access_count = access_count.GetValueAsUnsigned (123456)
64 self.assertTrue (start_access_count != 123456)
67 # The first set of tests test calling the getter & setter of
68 # a property that actually only has a getter & setter and no
71 nonexistant_value = frame.EvaluateExpression("mine.nonexistantInt", False)
72 nonexistant_error = nonexistant_value.GetError()
73 self.assertTrue (nonexistant_error.Success())
74 nonexistant_int = nonexistant_value.GetValueAsUnsigned (123456)
75 self.assertTrue (nonexistant_int == 6)
77 # Calling the getter function would up the access count, so make sure that happened.
79 new_access_count = access_count.GetValueAsUnsigned (123456)
80 self.assertTrue (new_access_count - start_access_count == 1)
81 start_access_count = new_access_count
84 # Now call the setter, then make sure that
85 nonexistant_change = frame.EvaluateExpression("mine.nonexistantInt = 10", False)
86 nonexistant_error = nonexistant_change.GetError()
87 self.assertTrue (nonexistant_error.Success())
89 # Calling the setter function would up the access count, so make sure that happened.
91 new_access_count = access_count.GetValueAsUnsigned (123456)
92 self.assertTrue (new_access_count - start_access_count == 1)
93 start_access_count = new_access_count
96 # Now we call the getter of a property that is backed by an ivar,
97 # make sure it works and that we actually update the backing ivar.
100 backed_value = frame.EvaluateExpression("mine.backedInt", False)
101 backed_error = backed_value.GetError()
102 self.assertTrue (backed_error.Success())
103 backing_value = mine.GetChildMemberWithName ("_backedInt")
104 self.assertTrue (backing_value.IsValid())
105 self.assertTrue (backed_value.GetValueAsUnsigned (12345) == backing_value.GetValueAsUnsigned(23456))
107 unbacked_value = frame.EvaluateExpression("mine.unbackedInt", False)
108 unbacked_error = unbacked_value.GetError()
109 self.assertTrue (unbacked_error.Success())
111 idWithProtocol_value = frame.EvaluateExpression("mine.idWithProtocol", False)
112 idWithProtocol_error = idWithProtocol_value.GetError()
113 self.assertTrue (idWithProtocol_error.Success())
114 self.assertTrue (idWithProtocol_value.GetTypeName() == "id")