[Python-checkins] r79815 - in python/branches/py3k-jit: Modules/_testcapimodule.c Unittests/GetArgsTest.cc

collin.winter python-checkins at python.org
Tue Apr 6 02:32:05 CEST 2010


Author: collin.winter
Date: Tue Apr  6 02:32:05 2010
New Revision: 79815

Log:
Move a PyArg_ParseTuple test back to _testcapimodule.c until I can figure out why gtest doesn't like it. (Fails on 64-bit platforms.)

Modified:
   python/branches/py3k-jit/Modules/_testcapimodule.c
   python/branches/py3k-jit/Unittests/GetArgsTest.cc

Modified: python/branches/py3k-jit/Modules/_testcapimodule.c
==============================================================================
--- python/branches/py3k-jit/Modules/_testcapimodule.c	(original)
+++ python/branches/py3k-jit/Modules/_testcapimodule.c	Tue Apr  6 02:32:05 2010
@@ -807,6 +807,58 @@
 }
 #endif
 
+/* Test Z and Z# codes for PyArg_ParseTuple */
+static PyObject *
+test_Z_code(PyObject *self)
+{
+	PyObject *tuple, *obj;
+	Py_UNICODE *value1, *value2;
+	Py_ssize_t len1, len2;
+
+        tuple = PyTuple_New(2);
+        if (tuple == NULL)
+        	return NULL;
+
+	obj = PyUnicode_FromString("test");
+	PyTuple_SET_ITEM(tuple, 0, obj);
+	Py_INCREF(Py_None);
+	PyTuple_SET_ITEM(tuple, 1, Py_None);
+
+	/* swap values on purpose */
+        value1 = NULL;
+	value2 = PyUnicode_AS_UNICODE(obj);
+
+	/* Test Z for both values */
+        if (PyArg_ParseTuple(tuple, "ZZ:test_Z_code", &value1, &value2) < 0)
+		return NULL;
+        if (value1 != PyUnicode_AS_UNICODE(obj))
+        	return raiseTestError("test_Z_code",
+			"Z code returned wrong value for 'test'");
+        if (value2 != NULL)
+        	return raiseTestError("test_Z_code",
+			"Z code returned wrong value for None");
+
+        value1 = NULL;
+	value2 = PyUnicode_AS_UNICODE(obj);
+	len1 = -1;
+	len2 = -1;
+
+	/* Test Z# for both values */
+        if (PyArg_ParseTuple(tuple, "Z#Z#:test_Z_code", &value1, &len1, 
+			     &value2, &len2) < 0)
+        	return NULL;
+        if (value1 != PyUnicode_AS_UNICODE(obj) ||
+	    len1 != PyUnicode_GET_SIZE(obj))
+        	return raiseTestError("test_Z_code",
+			"Z# code returned wrong values for 'test'");
+        if (value2 != NULL ||
+	    len2 != 0)
+        	return raiseTestError("test_Z_code",
+			"Z# code returned wrong values for None'");
+
+	Py_DECREF(tuple);
+	Py_RETURN_NONE;
+}
 
 static PyObject *
 test_widechar(PyObject *self)
@@ -1583,6 +1635,7 @@
 	{"codec_incrementaldecoder",
 	 (PyCFunction)codec_incrementaldecoder,	 METH_VARARGS},
 #endif
+	{"test_Z_code",		(PyCFunction)test_Z_code,	 METH_NOARGS},
  	{"test_widechar",	(PyCFunction)test_widechar,	 METH_NOARGS},
 #ifdef WITH_THREAD
 	{"_test_thread_state",  test_thread_state, 		 METH_VARARGS},

Modified: python/branches/py3k-jit/Unittests/GetArgsTest.cc
==============================================================================
--- python/branches/py3k-jit/Unittests/GetArgsTest.cc	(original)
+++ python/branches/py3k-jit/Unittests/GetArgsTest.cc	Tue Apr  6 02:32:05 2010
@@ -183,42 +183,3 @@
 
     Py_DECREF(tuple);
 }
-
-
-// Test the Z and Z# codes for PyArg_ParseTuple.
-TEST_F(GetArgsTest, FormatCode_Z)
-{
-    PyObject *tuple = PyTuple_New(2);
-    ASSERT_TRUE(tuple != NULL);
-
-    PyObject *obj = PyUnicode_FromString("test");
-    PyTuple_SET_ITEM(tuple, 0, obj);
-    Py_INCREF(Py_None);
-    PyTuple_SET_ITEM(tuple, 1, Py_None);
-
-    // Swap values on purpose.
-    Py_UNICODE *value1 = NULL;
-    Py_UNICODE *value2 = PyUnicode_AS_UNICODE(obj);
-
-    /* Test Z for both values. */
-    EXPECT_GE(PyArg_ParseTuple(tuple, "ZZ:FormatCode_Z", &value1, &value2), 0);
-    EXPECT_EQ(value1, PyUnicode_AS_UNICODE(obj))
-            << "Z code returned wrong value for 'test'";
-    EXPECT_TRUE(value2 == NULL) << "Z code returned wrong value for None";
-
-    value1 = NULL;
-    value2 = PyUnicode_AS_UNICODE(obj);
-    Py_ssize_t len1 = -1;
-    Py_ssize_t len2 = -1;
-
-    // Test Z# for both values.
-    EXPECT_GE(PyArg_ParseTuple(tuple, "Z#Z#:FormatCode_Z", &value1, &len1,
-                               &value2, &len2), 0);
-    EXPECT_EQ(PyUnicode_AS_UNICODE(obj), value1);
-    EXPECT_EQ(PyUnicode_GET_SIZE(obj), len1);
-    EXPECT_TRUE(value2 == NULL);
-    EXPECT_EQ(0, len2);
-
-    Py_DECREF(tuple);
-
-}


More information about the Python-checkins mailing list