diff options
author | Pavel Labath <labath@google.com> | 2018-06-19 17:24:03 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-06-19 17:24:03 +0000 |
commit | 61547259de2cb70c0343e5cf30596b9fecfa4c7a (patch) | |
tree | 267ff6e26f4922913ea72a6819aacc7f1853791f /lldb/unittests/Core/ScalarTest.cpp | |
parent | bcd6416123e016dab7b681d21e4f66c9b6c20279 (diff) | |
download | bcm5719-llvm-61547259de2cb70c0343e5cf30596b9fecfa4c7a.tar.gz bcm5719-llvm-61547259de2cb70c0343e5cf30596b9fecfa4c7a.zip |
Scalar: Use llvm integer conversion functions
StringConvert was the only non-Utility dependency of this class. Getting
rid of it means it will be easy to move this class to a lower layer.
While I was in there, I also added a couple of unit tests for the Scalar
string conversion function.
llvm-svn: 335060
Diffstat (limited to 'lldb/unittests/Core/ScalarTest.cpp')
-rw-r--r-- | lldb/unittests/Core/ScalarTest.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lldb/unittests/Core/ScalarTest.cpp b/lldb/unittests/Core/ScalarTest.cpp index 5fad1691fdd..9c241c26e66 100644 --- a/lldb/unittests/Core/ScalarTest.cpp +++ b/lldb/unittests/Core/ScalarTest.cpp @@ -14,8 +14,10 @@ #include "lldb/Utility/Endian.h" #include "lldb/Utility/Status.h" #include "lldb/Utility/StreamString.h" +#include "llvm/Testing/Support/Error.h" using namespace lldb_private; +using namespace llvm; TEST(ScalarTest, RightShiftOperator) { int a = 0x00001000; @@ -185,3 +187,34 @@ TEST(ScalarTest, Promotion) { } } } + +TEST(ScalarTest, SetValueFromCString) { + Scalar a; + + EXPECT_THAT_ERROR( + a.SetValueFromCString("1234567890123", lldb::eEncodingUint, 8).ToError(), + Succeeded()); + EXPECT_EQ(1234567890123ull, a); + + EXPECT_THAT_ERROR( + a.SetValueFromCString("-1234567890123", lldb::eEncodingSint, 8).ToError(), + Succeeded()); + EXPECT_EQ(-1234567890123ll, a); + + EXPECT_THAT_ERROR( + a.SetValueFromCString("asdf", lldb::eEncodingSint, 8).ToError(), + Failed()); + EXPECT_THAT_ERROR( + a.SetValueFromCString("asdf", lldb::eEncodingUint, 8).ToError(), + Failed()); + EXPECT_THAT_ERROR( + a.SetValueFromCString("1234567890123", lldb::eEncodingUint, 4).ToError(), + Failed()); + EXPECT_THAT_ERROR(a.SetValueFromCString("123456789012345678901234567890", + lldb::eEncodingUint, 8) + .ToError(), + Failed()); + EXPECT_THAT_ERROR( + a.SetValueFromCString("-123", lldb::eEncodingUint, 8).ToError(), + Failed()); +} |