diff options
| author | Med Ismail Bennani <ismail@bennani.ma> | 2023-05-22 13:52:09 -0700 |
|---|---|---|
| committer | Med Ismail Bennani <ismail@bennani.ma> | 2023-05-22 16:14:00 -0700 |
| commit | 1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68 (patch) | |
| tree | a281d98fa2d451a04b2b657c02ee19a98c674e3c /lldb/test/API/python_api | |
| parent | 01c5ec3d6209875de05de94cd7923c4e462c3317 (diff) | |
| download | llvm-1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68.zip llvm-1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68.tar.gz llvm-1370a1cb5b97ecfc4fd2cb550159db9c9ebd3a68.tar.bz2 | |
[lldb] Add support for negative integer to {SB,}StructuredData
This patch refactors the `StructuredData::Integer` class to make it
templated, makes it private and adds 2 public specialization for both
`int64_t` & `uint64_t` with a public type aliases, respectively
`SignedInteger` & `UnsignedInteger`.
It adds new getter for signed and unsigned interger values to the
`StructuredData::Object` base class and changes the implementation of
`StructuredData::Array::GetItemAtIndexAsInteger` and
`StructuredData::Dictionary::GetValueForKeyAsInteger` to support signed
and unsigned integers.
This patch also adds 2 new `Get{Signed,Unsigned}IntegerValue` to the
`SBStructuredData` class and marks `GetIntegerValue` as deprecated.
Finally, this patch audits all the caller of `StructuredData::Integer`
or `StructuredData::GetIntegerValue` to use the proper type as well the
various tests that uses `SBStructuredData.GetIntegerValue`.
rdar://105575764
Differential Revision: https://reviews.llvm.org/D150485
Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
Diffstat (limited to 'lldb/test/API/python_api')
| -rw-r--r-- | lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py index 0ab14c0..938cccc 100644 --- a/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py +++ b/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py @@ -22,12 +22,17 @@ class TestStructuredDataAPI(TestBase): s = lldb.SBStream() dict_str = json.dumps( - {"key_dict": - {"key_string":"STRING", - "key_uint":0xffffffff00000000, - "key_float":2.99, - "key_bool":True, - "key_array":["23","arr"]}}) + { + "key_dict": { + "key_string": "STRING", + "key_uint": 0xFFFFFFFF00000000, + "key_sint": -42, + "key_float": 2.99, + "key_bool": True, + "key_array": ["23", "arr"], + } + } + ) s.Print(dict_str) example = lldb.SBStructuredData() @@ -46,7 +51,7 @@ class TestStructuredDataAPI(TestBase): self.assertSuccess(error, "GetDescription works") if not "key_float" in s.GetData(): self.fail("FAILED: could not find key_float in description output") - + dict_struct = lldb.SBStructuredData() dict_struct = example.GetValueForKey("key_dict") @@ -59,6 +64,9 @@ class TestStructuredDataAPI(TestBase): # Tests for integer data type self.uint_struct_test(dict_struct) + # Tests for integer data type + self.sint_struct_test(dict_struct) + # Tests for floating point data type self.double_struct_test(dict_struct) @@ -90,7 +98,7 @@ class TestStructuredDataAPI(TestBase): self.fail("Wrong type returned: " + str(dict_struct.GetType())) # Check Size API for 'dictionary' type - if not dict_struct.GetSize() == 5: + if not dict_struct.GetSize() == 6: self.fail("Wrong no of elements returned: " + str(dict_struct.GetSize())) @@ -131,8 +139,8 @@ class TestStructuredDataAPI(TestBase): if not uint_struct.GetType() == lldb.eStructuredDataTypeInteger: self.fail("Wrong type returned: " + str(uint_struct.GetType())) - # Check API returning 'integer' value - output = uint_struct.GetIntegerValue() + # Check API returning unsigned integer value + output = uint_struct.GetUnsignedIntegerValue() if not output == 0xffffffff00000000: self.fail("wrong output: " + str(output)) @@ -140,6 +148,30 @@ class TestStructuredDataAPI(TestBase): # (e.g. getting a string value from an integer type structure) output = uint_struct.GetStringValue(25) if output: + self.fail("Valid string " + output + " returned for an integer object") + + def sint_struct_test(self, dict_struct): + # Check a valid SBStructuredData containing an signed integer. + # We intentionally make this smaller than what an uint64_t can hold but + # still small enough to fit a int64_t + sint_struct = lldb.SBStructuredData() + sint_struct = dict_struct.GetValueForKey("key_sint") + if not sint_struct.IsValid(): + self.fail("A valid object should have been returned") + + # Check Type API + if not sint_struct.GetType() == lldb.eStructuredDataTypeSignedInteger: + self.fail("Wrong type returned: " + str(sint_struct.GetType())) + + # Check API returning signed integer value + output = sint_struct.GetSignedIntegerValue() + if not output == -42: + self.fail("wrong output: " + str(output)) + + # Calling wrong API on a SBStructuredData + # (e.g. getting a string value from an integer type structure) + output = sint_struct.GetStringValue(69) + if output: self.fail( "Valid string " + output + |
