Tests for Connection.pending
diff --git a/OpenSSL/ssl/connection.c b/OpenSSL/ssl/connection.c
index 6ee484d..5a4fab0 100755
--- a/OpenSSL/ssl/connection.c
+++ b/OpenSSL/ssl/connection.c
@@ -253,10 +253,10 @@
@return: A Context object\n\
";
static PyObject *
-ssl_Connection_get_context(ssl_ConnectionObj *self, PyObject *args)
-{
- if (!PyArg_ParseTuple(args, ":get_context"))
+ssl_Connection_get_context(ssl_ConnectionObj *self, PyObject *args) {
+ if (!PyArg_ParseTuple(args, ":get_context")) {
return NULL;
+ }
Py_INCREF(self->context);
return (PyObject *)self->context;
@@ -268,17 +268,17 @@
@return: The number of bytes available in the receive buffer.\n\
";
static PyObject *
-ssl_Connection_pending(ssl_ConnectionObj *self, PyObject *args)
-{
+ssl_Connection_pending(ssl_ConnectionObj *self, PyObject *args) {
int ret;
- if (!PyArg_ParseTuple(args, ":pending"))
+ if (!PyArg_ParseTuple(args, ":pending")) {
return NULL;
+ }
ret = SSL_pending(self->ssl);
return PyInt_FromLong((long)ret);
}
-
+
static char ssl_Connection_bio_write_doc[] = "\n\
When using non-socket connections this function sends\n\
\"dirty\" data that would have traveled in on the network.\n\
diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py
index c1f3fbd..6cec75e 100644
--- a/OpenSSL/test/test_ssl.py
+++ b/OpenSSL/test/test_ssl.py
@@ -11,7 +11,7 @@
from unittest import main
from OpenSSL.crypto import TYPE_RSA, FILETYPE_PEM, PKey, dump_privatekey, load_certificate, load_privatekey
-from OpenSSL.SSL import SysCallError, WantReadError, Context, ContextType, Connection, ConnectionType, Error
+from OpenSSL.SSL import SysCallError, WantReadError, WantWriteError, Context, ContextType, Connection, ConnectionType, Error
from OpenSSL.SSL import SSLv2_METHOD, SSLv3_METHOD, SSLv23_METHOD, TLSv1_METHOD
from OpenSSL.SSL import OP_NO_SSLv2, OP_NO_SSLv3, OP_SINGLE_DH_USE
from OpenSSL.SSL import VERIFY_PEER, VERIFY_FAIL_IF_NO_PEER_CERT, VERIFY_CLIENT_ONCE
@@ -336,6 +336,16 @@
self.assertRaises(TypeError, connection.get_context, None)
+ def test_pending(self):
+ connection = Connection(Context(TLSv1_METHOD), None)
+ self.assertEquals(connection.pending(), 0)
+
+
+ def test_pending_wrong_args(self):
+ connection = Connection(Context(TLSv1_METHOD), None)
+ self.assertRaises(TypeError, connection.pending, None)
+
+
class ConnectionGetCipherListTests(TestCase):
def test_wrongargs(self):
@@ -424,6 +434,7 @@
self.assertRaises(SysCallError, server.sendall, "hello, world")
+
class ErrorTests(TestCase):
"""
Unit tests for L{OpenSSL.SSL.Error}.