]> granicus.if.org Git - python/commitdiff
Add a test to make sure zlib.crc32 and binascii.crc32 return the same thing.
authorGregory P. Smith <greg@mad-scientist.com>
Tue, 18 Mar 2008 22:27:41 +0000 (22:27 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Tue, 18 Mar 2008 22:27:41 +0000 (22:27 +0000)
Fix a buglet in binascii.crc32, the second optional argument could previously
have a signedness mismatch with the C variable its going into.

Lib/test/test_zlib.py
Modules/binascii.c

index 7c7ef263b310601350718ecff68b5f43769256c7..9f0fe18c074b446a0a564e5d48e1662543f9be99 100644 (file)
@@ -1,6 +1,7 @@
 import unittest
 from test import test_support
 import zlib
+import binascii
 import random
 
 
@@ -47,6 +48,11 @@ class ChecksumTestCase(unittest.TestCase):
         self.assertEqual(zlib.adler32(foo+foo), -721416943)
         self.assertEqual(zlib.adler32('spam'), 72286642)
 
+    def test_same_as_binascii_crc32(self):
+        foo = 'abcdefghijklmnop'
+        self.assertEqual(binascii.crc32(foo), zlib.crc32(foo))
+        self.assertEqual(binascii.crc32('spam'), zlib.crc32('spam'))
+
 
 
 class ExceptionTestCase(unittest.TestCase):
index 00f950d19da426bc4d282004f3be270b0e1ee248..659e08ce5c6cbf48b52ef829102ae2f44e405901 100644 (file)
@@ -874,7 +874,7 @@ binascii_crc32(PyObject *self, PyObject *args)
        Py_ssize_t len;
        long result;
 
-       if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
+       if ( !PyArg_ParseTuple(args, "s#|k:crc32", &bin_data, &len, &crc) )
                return NULL;
 
        crc = ~ crc;