]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/objc/objc-property/TestObjCProperty.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / objc / objc-property / TestObjCProperty.py
1 """
2 Use lldb Python API to verify that expression evaluation for property references uses the correct getters and setters
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import re
11 import lldb
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.lldbtest import *
14
15 class ObjCPropertyTestCase(TestBase):
16
17     mydir = TestBase.compute_mydir(__file__)
18
19     def setUp(self):
20         # Call super's setUp().                                                                                                           
21         TestBase.setUp(self)
22
23         # Find the line number to break for main.c.                                                                                       
24         self.source_name = 'main.m'
25
26     @skipUnlessDarwin
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")
32
33         self.build()
34         exe = os.path.join(os.getcwd(), "a.out")
35
36         # Create a target from the debugger.
37
38         target = self.dbg.CreateTarget (exe)
39         self.assertTrue(target, VALID_TARGET)
40
41         # Set up our breakpoints:
42         
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,
46                         VALID_BREAKPOINT)
47
48         # Now launch the process, and do not stop at the entry point.
49         process = target.LaunchSimple (None, None, self.get_process_working_directory())
50
51         self.assertTrue(process.GetState() == lldb.eStateStopped,
52                         PROCESS_STOPPED)
53
54         threads = lldbutil.get_threads_stopped_at_breakpoint (process, main_bkpt)
55         self.assertTrue (len(threads) == 1)
56         thread = threads[0]
57         frame = thread.GetFrameAtIndex(0)
58
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)
65
66         #
67         # The first set of tests test calling the getter & setter of
68         # a property that actually only has a getter & setter and no
69         # @property.
70         #
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)
76         
77         # Calling the getter function would up the access count, so make sure that happened.
78         
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
82
83         #
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())
88
89         # Calling the setter function would up the access count, so make sure that happened.
90         
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
94
95         #
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.
98         #
99
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))
106
107         unbacked_value = frame.EvaluateExpression("mine.unbackedInt", False)
108         unbacked_error = unbacked_value.GetError()
109         self.assertTrue (unbacked_error.Success())
110
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")