summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-08-29 02:28:42 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-08-29 02:28:42 (GMT)
commit8211237db89e1d77aff9d4da80059bae1cb3e881 (patch)
treed84233fb30e453664bee4bf16d7b71e14c49ec24 /Lib
parentda21ce3e3109c4a45f89386db42be4f0463aec11 (diff)
downloadcpython-8211237db89e1d77aff9d4da80059bae1cb3e881.zip
cpython-8211237db89e1d77aff9d4da80059bae1cb3e881.tar.gz
cpython-8211237db89e1d77aff9d4da80059bae1cb3e881.tar.bz2
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
ints, convert to PyLong (rather than throwing away the high-order 32 bits).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_marshal.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
new file mode 100644
index 0000000..38b3cd4
--- /dev/null
+++ b/Lib/test/test_marshal.py
@@ -0,0 +1,41 @@
+from test_support import TestFailed
+import marshal
+import sys
+
+# XXX Much more needed here.
+
+# Test the full range of Python ints.
+n = sys.maxint
+while n:
+ for expected in (-n, n):
+ s = marshal.dumps(expected)
+ got = marshal.loads(s)
+ if expected != got:
+ raise TestFailed("for int %d, marshal string is %r, loaded "
+ "back as %d" % (expected, s, got))
+ n = n >> 1
+
+# Simulate int marshaling on a 64-bit box. This is most interesting if
+# we're running the test on a 32-bit box, of course.
+
+def to_little_endian_string(value, nbytes):
+ bytes = []
+ for i in range(nbytes):
+ bytes.append(chr(value & 0xff))
+ value >>= 8
+ return ''.join(bytes)
+
+maxint64 = (1L << 63) - 1
+minint64 = -maxint64-1
+
+for base in maxint64, minint64, -maxint64, -(minint64 >> 1):
+ while base:
+ s = 'I' + to_little_endian_string(base, 8)
+ got = marshal.loads(s)
+ if base != got:
+ raise TestFailed("for int %d, simulated marshal string is %r, "
+ "loaded back as %d" % (base, s, got))
+ if base == -1: # a fixed-point for shifting right 1
+ base = 0
+ else:
+ base >>= 1