@@ -48,11 +48,10 @@ def structured_data_api_test(self):
48
48
s .Clear ()
49
49
error = example .GetDescription (s )
50
50
self .assertSuccess (error , "GetDescription works" )
51
- # Ensure str() doesn't raise an exception.
52
- self .assertTrue (str (example ))
53
51
if not "key_float" in s .GetData ():
54
52
self .fail ("FAILED: could not find key_float in description output" )
55
53
54
+ dict_struct = lldb .SBStructuredData ()
56
55
dict_struct = example .GetValueForKey ("key_dict" )
57
56
58
57
# Tests for dictionary data type
@@ -114,26 +113,21 @@ class MyRandomClass:
114
113
self .assertSuccess (example .SetFromJSON ("1" ))
115
114
self .assertEqual (example .GetType (), lldb .eStructuredDataTypeInteger )
116
115
self .assertEqual (example .GetIntegerValue (), 1 )
117
- self .assertEqual (int (example ), 1 )
118
116
119
117
self .assertSuccess (example .SetFromJSON ("4.19" ))
120
118
self .assertEqual (example .GetType (), lldb .eStructuredDataTypeFloat )
121
119
self .assertEqual (example .GetFloatValue (), 4.19 )
122
- self .assertEqual (float (example ), 4.19 )
123
120
124
121
self .assertSuccess (example .SetFromJSON ('"Bonjour, 123!"' ))
125
122
self .assertEqual (example .GetType (), lldb .eStructuredDataTypeString )
126
123
self .assertEqual (example .GetStringValue (42 ), "Bonjour, 123!" )
127
- self .assertEqual (str (example ), "Bonjour, 123!" )
128
124
129
125
self .assertSuccess (example .SetFromJSON ("true" ))
130
126
self .assertEqual (example .GetType (), lldb .eStructuredDataTypeBoolean )
131
127
self .assertTrue (example .GetBooleanValue ())
132
- self .assertTrue (example )
133
128
134
129
self .assertSuccess (example .SetFromJSON ("null" ))
135
130
self .assertEqual (example .GetType (), lldb .eStructuredDataTypeNull )
136
- self .assertFalse (example )
137
131
138
132
example = lldb .SBStructuredData ()
139
133
example .SetUnsignedIntegerValue (1 )
@@ -193,35 +187,38 @@ class MyRandomClass:
193
187
self .assertEqual (sb_data , example_arr )
194
188
195
189
def invalid_struct_test (self , example ):
190
+ invalid_struct = lldb .SBStructuredData ()
196
191
invalid_struct = example .GetValueForKey ("invalid_key" )
197
192
if invalid_struct .IsValid ():
198
193
self .fail ("An invalid object should have been returned" )
199
194
200
195
# Check Type API
201
- if invalid_struct .GetType () ! = lldb .eStructuredDataTypeInvalid :
196
+ if not invalid_struct .GetType () = = lldb .eStructuredDataTypeInvalid :
202
197
self .fail ("Wrong type returned: " + str (invalid_struct .GetType ()))
203
198
204
199
def dictionary_struct_test (self , example ):
205
200
# Check API returning a valid SBStructuredData of 'dictionary' type
201
+ dict_struct = lldb .SBStructuredData ()
206
202
dict_struct = example .GetValueForKey ("key_dict" )
207
203
if not dict_struct .IsValid ():
208
204
self .fail ("A valid object should have been returned" )
209
205
210
206
# Check Type API
211
- if dict_struct .GetType () ! = lldb .eStructuredDataTypeDictionary :
207
+ if not dict_struct .GetType () = = lldb .eStructuredDataTypeDictionary :
212
208
self .fail ("Wrong type returned: " + str (dict_struct .GetType ()))
213
209
214
210
# Check Size API for 'dictionary' type
215
- if dict_struct .GetSize () ! = 6 :
211
+ if not dict_struct .GetSize () = = 6 :
216
212
self .fail ("Wrong no of elements returned: " + str (dict_struct .GetSize ()))
217
213
218
214
def string_struct_test (self , dict_struct ):
215
+ string_struct = lldb .SBStructuredData ()
219
216
string_struct = dict_struct .GetValueForKey ("key_string" )
220
217
if not string_struct .IsValid ():
221
218
self .fail ("A valid object should have been returned" )
222
219
223
220
# Check Type API
224
- if string_struct .GetType () ! = lldb .eStructuredDataTypeString :
221
+ if not string_struct .GetType () = = lldb .eStructuredDataTypeString :
225
222
self .fail ("Wrong type returned: " + str (string_struct .GetType ()))
226
223
227
224
# Check API returning 'string' value
@@ -241,17 +238,18 @@ def uint_struct_test(self, dict_struct):
241
238
# Check a valid SBStructuredData containing an unsigned integer.
242
239
# We intentionally make this larger than what an int64_t can hold but
243
240
# still small enough to fit a uint64_t
241
+ uint_struct = lldb .SBStructuredData ()
244
242
uint_struct = dict_struct .GetValueForKey ("key_uint" )
245
243
if not uint_struct .IsValid ():
246
244
self .fail ("A valid object should have been returned" )
247
245
248
246
# Check Type API
249
- if uint_struct .GetType () ! = lldb .eStructuredDataTypeInteger :
247
+ if not uint_struct .GetType () = = lldb .eStructuredDataTypeInteger :
250
248
self .fail ("Wrong type returned: " + str (uint_struct .GetType ()))
251
249
252
250
# Check API returning unsigned integer value
253
251
output = uint_struct .GetUnsignedIntegerValue ()
254
- if output ! = 0xFFFFFFFF00000000 :
252
+ if not output = = 0xFFFFFFFF00000000 :
255
253
self .fail ("wrong output: " + str (output ))
256
254
257
255
# Calling wrong API on a SBStructuredData
@@ -264,17 +262,18 @@ def sint_struct_test(self, dict_struct):
264
262
# Check a valid SBStructuredData containing an signed integer.
265
263
# We intentionally make this smaller than what an uint64_t can hold but
266
264
# still small enough to fit a int64_t
265
+ sint_struct = lldb .SBStructuredData ()
267
266
sint_struct = dict_struct .GetValueForKey ("key_sint" )
268
267
if not sint_struct .IsValid ():
269
268
self .fail ("A valid object should have been returned" )
270
269
271
270
# Check Type API
272
- if sint_struct .GetType () ! = lldb .eStructuredDataTypeSignedInteger :
271
+ if not sint_struct .GetType () = = lldb .eStructuredDataTypeSignedInteger :
273
272
self .fail ("Wrong type returned: " + str (sint_struct .GetType ()))
274
273
275
274
# Check API returning signed integer value
276
275
output = sint_struct .GetSignedIntegerValue ()
277
- if output ! = - 42 :
276
+ if not output = = - 42 :
278
277
self .fail ("wrong output: " + str (output ))
279
278
280
279
# Calling wrong API on a SBStructuredData
@@ -284,26 +283,28 @@ def sint_struct_test(self, dict_struct):
284
283
self .fail ("Valid string " + output + " returned for an integer object" )
285
284
286
285
def double_struct_test (self , dict_struct ):
286
+ floating_point_struct = lldb .SBStructuredData ()
287
287
floating_point_struct = dict_struct .GetValueForKey ("key_float" )
288
288
if not floating_point_struct .IsValid ():
289
289
self .fail ("A valid object should have been returned" )
290
290
291
291
# Check Type API
292
- if floating_point_struct .GetType () ! = lldb .eStructuredDataTypeFloat :
292
+ if not floating_point_struct .GetType () = = lldb .eStructuredDataTypeFloat :
293
293
self .fail ("Wrong type returned: " + str (floating_point_struct .GetType ()))
294
294
295
295
# Check API returning 'double' value
296
296
output = floating_point_struct .GetFloatValue ()
297
- if output ! = 2.99 :
297
+ if not output = = 2.99 :
298
298
self .fail ("wrong output: " + str (output ))
299
299
300
300
def bool_struct_test (self , dict_struct ):
301
+ bool_struct = lldb .SBStructuredData ()
301
302
bool_struct = dict_struct .GetValueForKey ("key_bool" )
302
303
if not bool_struct .IsValid ():
303
304
self .fail ("A valid object should have been returned" )
304
305
305
306
# Check Type API
306
- if bool_struct .GetType () ! = lldb .eStructuredDataTypeBoolean :
307
+ if not bool_struct .GetType () = = lldb .eStructuredDataTypeBoolean :
307
308
self .fail ("Wrong type returned: " + str (bool_struct .GetType ()))
308
309
309
310
# Check API returning 'bool' value
@@ -313,108 +314,35 @@ def bool_struct_test(self, dict_struct):
313
314
314
315
def array_struct_test (self , dict_struct ):
315
316
# Check API returning a valid SBStructuredData of 'array' type
317
+ array_struct = lldb .SBStructuredData ()
316
318
array_struct = dict_struct .GetValueForKey ("key_array" )
317
319
if not array_struct .IsValid ():
318
320
self .fail ("A valid object should have been returned" )
319
321
320
322
# Check Type API
321
- if array_struct .GetType () ! = lldb .eStructuredDataTypeArray :
323
+ if not array_struct .GetType () = = lldb .eStructuredDataTypeArray :
322
324
self .fail ("Wrong type returned: " + str (array_struct .GetType ()))
323
325
324
326
# Check Size API for 'array' type
325
- if array_struct .GetSize () ! = 2 :
327
+ if not array_struct .GetSize () = = 2 :
326
328
self .fail ("Wrong no of elements returned: " + str (array_struct .GetSize ()))
327
329
328
330
# Check API returning a valid SBStructuredData for different 'array'
329
331
# indices
330
332
string_struct = array_struct .GetItemAtIndex (0 )
331
333
if not string_struct .IsValid ():
332
334
self .fail ("A valid object should have been returned" )
333
- if string_struct .GetType () ! = lldb .eStructuredDataTypeString :
335
+ if not string_struct .GetType () = = lldb .eStructuredDataTypeString :
334
336
self .fail ("Wrong type returned: " + str (string_struct .GetType ()))
335
337
output = string_struct .GetStringValue (5 )
336
- if output ! = "23" :
338
+ if not output = = "23" :
337
339
self .fail ("wrong output: " + str (output ))
338
340
339
341
string_struct = array_struct .GetItemAtIndex (1 )
340
342
if not string_struct .IsValid ():
341
343
self .fail ("A valid object should have been returned" )
342
- if string_struct .GetType () ! = lldb .eStructuredDataTypeString :
344
+ if not string_struct .GetType () = = lldb .eStructuredDataTypeString :
343
345
self .fail ("Wrong type returned: " + str (string_struct .GetType ()))
344
346
output = string_struct .GetStringValue (5 )
345
- if output ! = "arr" :
347
+ if not output = = "arr" :
346
348
self .fail ("wrong output: " + str (output ))
347
-
348
- def test_round_trip_scalars (self ):
349
- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 , True , False ):
350
- constructor = type (original )
351
- data = lldb .SBStructuredData ()
352
- data .SetFromJSON (json .dumps (original ))
353
- round_tripped = constructor (data )
354
- self .assertEqual (round_tripped , original )
355
-
356
- def test_dynamic (self ):
357
- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 , "" , "dirk" , True , False ):
358
- data = lldb .SBStructuredData ()
359
- data .SetFromJSON (json .dumps (original ))
360
- self .assertEqual (data .dynamic , original )
361
-
362
- def test_round_trip_int (self ):
363
- for original in (0 , 11 , - 1 ):
364
- data = lldb .SBStructuredData ()
365
- data .SetFromJSON (json .dumps (original ))
366
- self .assertEqual (int (data ), int (original ))
367
-
368
- def test_round_trip_float (self ):
369
- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 ):
370
- data = lldb .SBStructuredData ()
371
- data .SetFromJSON (json .dumps (original ))
372
- self .assertEqual (float (data ), float (original ))
373
-
374
- def test_round_trip_bool (self ):
375
- for original in (0 , 11 , - 1 , 0.0 , 4.5 , - 0.25 , "0.0" , "4.5" , "-0.25" ):
376
- data = lldb .SBStructuredData ()
377
- data .SetFromJSON (json .dumps (original ))
378
- self .assertEqual (bool (data ), bool (original ))
379
-
380
- for original in ([], {}, [1 ], {1 : 1 }):
381
- data = lldb .SBStructuredData ()
382
- data .SetFromJSON (json .dumps (original ))
383
- self .assertEqual (bool (data ), bool (original ))
384
-
385
- def test_assert_false (self ):
386
- self .assertFalse (lldb .SBStructuredData ())
387
- for original in ("0" , "0.0" , '""' , "[]" , "{}" ):
388
- data = lldb .SBStructuredData ()
389
- data .SetFromJSON (original )
390
- self .assertFalse (data )
391
-
392
- def test_iterate_array (self ):
393
- array = [0 , 1 , 2 ]
394
- data = lldb .SBStructuredData ()
395
- data .SetFromJSON (json .dumps (array ))
396
- for value in data :
397
- self .assertEqual (value , array .pop (0 ))
398
-
399
- def test_iterate_dictionary (self ):
400
- dictionary = {"0" : 0 , "1" : 1 , "2" : 2 }
401
- keys = set (dictionary .keys ())
402
- data = lldb .SBStructuredData ()
403
- data .SetFromJSON (json .dumps (dictionary ))
404
- for key in data :
405
- self .assertIn (key , keys )
406
- keys .remove (key )
407
-
408
- def test_getitem_array (self ):
409
- array = [1 , 2 , 3 ]
410
- data = lldb .SBStructuredData ()
411
- data .SetFromJSON (json .dumps (array ))
412
- for i in range (len (array )):
413
- self .assertEqual (data [i ], array [i ])
414
-
415
- def test_getitem_dictionary (self ):
416
- dictionary = {"one" : 1 , "two" : 2 , "three" : 3 }
417
- data = lldb .SBStructuredData ()
418
- data .SetFromJSON (json .dumps (dictionary ))
419
- for key in dictionary :
420
- self .assertEqual (data [key ], dictionary [key ])
0 commit comments