From f9d6d204e8af0d9ac4ae020e65491b7d398930bd Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 25 Jan 2016 23:21:09 +0000 Subject: 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 --- .../ScriptInterpreter/Python/PythonDataObjectsTests.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp') 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 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. -- cgit v1.2.3