@@ -18,11 +18,9 @@ def setUp(self):
18
18
# Find the line number to break inside main().
19
19
self .line = line_number ('main.c' , '// Set break point at this line.' )
20
20
21
- def test (self ):
22
- """Test 'image lookup -t days ' and check for correct display and enum value printing."""
21
+ def test_command_line (self ):
22
+ """Test 'image lookup -t enum_test_days ' and check for correct display and enum value printing."""
23
23
self .build ()
24
- exe = self .getBuildArtifact ("a.out" )
25
- self .runCmd ("file " + exe , CURRENT_EXECUTABLE_SET )
26
24
27
25
lldbutil .run_to_source_breakpoint (
28
26
self , '// Breakpoint for bitfield' , lldb .SBFileSpec ("main.c" ))
@@ -63,10 +61,10 @@ def test(self):
63
61
self .expect ("breakpoint list -f" , BREAKPOINT_HIT_ONCE ,
64
62
substrs = [' resolved, hit count = 1' ])
65
63
66
- # Look up information about the 'days ' enum type.
64
+ # Look up information about the 'enum_test_days ' enum type.
67
65
# Check for correct display.
68
- self .expect ("image lookup -t days " , DATA_TYPES_DISPLAYED_CORRECTLY ,
69
- substrs = ['enum days {' ,
66
+ self .expect ("image lookup -t enum_test_days " , DATA_TYPES_DISPLAYED_CORRECTLY ,
67
+ substrs = ['enum enum_test_days {' ,
70
68
'Monday' ,
71
69
'Tuesday' ,
72
70
'Wednesday' ,
@@ -124,3 +122,41 @@ def test(self):
124
122
'check for valid enumeration value' ,
125
123
substrs = [enum_value ])
126
124
lldbutil .continue_to_breakpoint (self .process (), bkpt )
125
+
126
+ def check_enum_members (self , members ):
127
+ name_matches = ["Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday" , "kNumDays" ]
128
+ value_matches = [- 3 , - 2 , - 1 , 0 , 1 , 2 , 3 , 4 ]
129
+
130
+ # First test that the list of members from the type works
131
+ num_matches = len (name_matches )
132
+ self .assertEqual (len (members ), num_matches , "enum_members returns the right number of elements" )
133
+ for idx in range (0 , num_matches ):
134
+ member = members [idx ]
135
+ self .assertTrue (member .IsValid (), "Got a valid member for idx: %d" % (idx ))
136
+ self .assertEqual (member .name , name_matches [idx ], "Name matches for %d" % (idx ))
137
+ self .assertEqual (member .signed , value_matches [idx ], "Value matches for %d" % (idx ))
138
+
139
+ def test_api (self ):
140
+ """Test the the SBTypeEnumMember API's work correctly for enum_test_days"""
141
+ self .build ()
142
+ target = lldbutil .run_to_breakpoint_make_target (self )
143
+
144
+ types = target .FindTypes ("enum_test_days" )
145
+ self .assertEqual (len (types ), 1 , "Found more than one enum_test_days type..." )
146
+ type = types .GetTypeAtIndex (0 )
147
+
148
+ # First check using the Python list returned by the type:
149
+ self .check_enum_members (type .enum_members )
150
+
151
+ # Now use the SBTypeEnumMemberList.
152
+ member_list = type .GetEnumMembers ()
153
+ self .check_enum_members (member_list )
154
+
155
+ # Now check that the by name accessor works:
156
+ for member in member_list :
157
+ name = member .name
158
+ check_member = member_list [name ]
159
+ self .assertTrue (check_member .IsValid (), "Got a valid member for %s." % (name ))
160
+ self .assertEqual (name , check_member .name , "Got back the right name" )
161
+ self .assertEqual (member .unsigned , check_member .unsigned )
162
+
0 commit comments