From 5a72c02be9a7a5ac5671f079997ec58a71b661ba Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Mon, 11 Jan 2016 22:16:12 +0000 Subject: 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 --- .../Python/PythonDataObjectsTests.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 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 5c69251..605f023 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 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. -- cgit v1.1