summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-01-25 23:21:09 +0000
committerZachary Turner <zturner@google.com>2016-01-25 23:21:09 +0000
commitf9d6d204e8af0d9ac4ae020e65491b7d398930bd (patch)
treebb42c70af5549b337af9d04530b8d32f9daa7b18 /lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
parent10a50b188ebdd8a1c3a6c9f7646cabf3f059584a (diff)
downloadbcm5719-llvm-f9d6d204e8af0d9ac4ae020e65491b7d398930bd.tar.gz
bcm5719-llvm-f9d6d204e8af0d9ac4ae020e65491b7d398930bd.zip
Fix swig typemap for SBEvent.
This needs to be able to handle bytes, strings, and bytearray objects. In Python 2 this was easy because bytes and strings are the same thing, but in Python 3 the 2 cases need to be handled separately. So as not to mix raw Python C API code with PythonDataObjects code, I've also introduced a PythonByteArray class to PythonDataObjects to make the paradigm used here consistent. llvm-svn: 258741
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp')
-rw-r--r--lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
index 605f0233e87..e2b40d5f602 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
@@ -224,6 +224,20 @@ TEST_F(PythonDataObjectsTest, TestPythonBytes)
EXPECT_EQ(0, ::memcmp(bytes.data(), test_bytes, bytes.size()));
}
+TEST_F(PythonDataObjectsTest, TestPythonByteArray)
+{
+ static const char *test_bytes = "PythonDataObjectsTest::TestPythonByteArray";
+ llvm::StringRef orig_bytes(test_bytes);
+ PyObject *py_bytes = PyByteArray_FromStringAndSize(test_bytes, orig_bytes.size());
+ EXPECT_TRUE(PythonByteArray::Check(py_bytes));
+ PythonByteArray python_bytes(PyRefType::Owned, py_bytes);
+ EXPECT_EQ(PyObjectType::ByteArray, python_bytes.GetObjectType());
+
+ llvm::ArrayRef<uint8_t> after_bytes = python_bytes.GetBytes();
+ EXPECT_EQ(after_bytes.size(), orig_bytes.size());
+ EXPECT_EQ(0, ::memcmp(orig_bytes.data(), test_bytes, orig_bytes.size()));
+}
+
TEST_F(PythonDataObjectsTest, TestPythonString)
{
// Test that strings behave correctly when wrapped by a PythonString.
OpenPOWER on IntegriCloud