summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-01-11 22:16:12 +0000
committerZachary Turner <zturner@google.com>2016-01-11 22:16:12 +0000
commit5a72c02be9a7a5ac5671f079997ec58a71b661ba (patch)
tree76eb546c4d0511276ae20b5f73ba5dacda223524 /lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
parent472cc78ccb1c139b5eab4c91b25797e865f271ad (diff)
downloadbcm5719-llvm-5a72c02be9a7a5ac5671f079997ec58a71b661ba.tar.gz
bcm5719-llvm-5a72c02be9a7a5ac5671f079997ec58a71b661ba.zip
Introduce a PythonBytes class into PythonDataObjects.
This class behaves the same as PythonString on Python2, but differently on Python3. Unittests are added as well. llvm-svn: 257397
Diffstat (limited to 'lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp')
-rw-r--r--lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
index 5c6925179c6..605f0233e87 100644
--- a/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
+++ b/lldb/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
@@ -203,6 +203,27 @@ TEST_F(PythonDataObjectsTest, TestPythonInteger)
EXPECT_EQ(7, constructed_int.GetInteger());
}
+TEST_F(PythonDataObjectsTest, TestPythonBytes)
+{
+ static const char *test_bytes = "PythonDataObjectsTest::TestPythonBytes";
+ PyObject *py_bytes = PyBytes_FromString(test_bytes);
+ EXPECT_TRUE(PythonBytes::Check(py_bytes));
+ PythonBytes python_bytes(PyRefType::Owned, py_bytes);
+ EXPECT_EQ(PyObjectType::Bytes, python_bytes.GetObjectType());
+
+#if PY_MAJOR_VERSION < 3
+ EXPECT_TRUE(PythonString::Check(py_bytes));
+ EXPECT_EQ(PyObjectType::String, python_bytes.GetObjectType());
+#else
+ EXPECT_FALSE(PythonString::Check(py_bytes));
+ EXPECT_NE(PyObjectType::String, python_bytes.GetObjectType());
+#endif
+
+ llvm::ArrayRef<uint8_t> bytes = python_bytes.GetBytes();
+ EXPECT_EQ(bytes.size(), strlen(test_bytes));
+ EXPECT_EQ(0, ::memcmp(bytes.data(), test_bytes, bytes.size()));
+}
+
TEST_F(PythonDataObjectsTest, TestPythonString)
{
// Test that strings behave correctly when wrapped by a PythonString.
OpenPOWER on IntegriCloud