#include "lldb/Core/Scalar.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Endian.h"
#include "lldb/Utility/Status.h"
error.SetErrorString("Invalid c-string value string.");
return error;
}
- bool success = false;
switch (encoding) {
case eEncodingInvalid:
error.SetErrorString("Invalid encoding.");
break;
case eEncodingUint:
- if (byte_size <= sizeof(unsigned long long)) {
- uint64_t uval64 =
- StringConvert::ToUInt64(value_str, UINT64_MAX, 0, &success);
- if (!success)
+ if (byte_size <= sizeof(uint64_t)) {
+ uint64_t uval64;
+ if (!llvm::to_integer(value_str, uval64))
error.SetErrorStringWithFormat(
"'%s' is not a valid unsigned integer string value", value_str);
else if (!UIntValueIsValidForSize(uval64, byte_size))
break;
case eEncodingSint:
- if (byte_size <= sizeof(long long)) {
- uint64_t sval64 =
- StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
- if (!success)
+ if (byte_size <= sizeof(int64_t)) {
+ int64_t sval64;
+ if (!llvm::to_integer(value_str, sval64))
error.SetErrorStringWithFormat(
"'%s' is not a valid signed integer string value", value_str);
else if (!SIntValueIsValidForSize(sval64, byte_size))
#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;
}
}
}
+
+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());
+}