Kaydet (Commit) cbd5b895 authored tarafından Jeremy Hylton's avatar Jeremy Hylton

Repair testNtoH for large long arguments.

If the long is large enough, the return value will be a negative int.
In this case, calling the function a second time won't return the
original value passed in.
üst cce7e34a
...@@ -248,15 +248,14 @@ class GeneralModuleTests(unittest.TestCase): ...@@ -248,15 +248,14 @@ class GeneralModuleTests(unittest.TestCase):
pass pass
def testNtoH(self): def testNtoH(self):
def twice(f): for func in socket.htonl, socket.ntohl:
def g(x): for i in (0, 1, 0xffff0000, 2L):
return f(f(x)) self.assertEqual(i, func(func(i)))
return g
for i in (0, 1, 0xffff0000, 2L, (2**32L) - 1): biglong = 2**32L - 1
self.assertEqual(i, twice(socket.htonl)(i)) swapped = func(biglong)
self.assertEqual(i, twice(socket.ntohl)(i)) self.assert_(swapped == biglong or swapped == -1)
self.assertRaises(OverflowError, socket.htonl, 2L**34) self.assertRaises(OverflowError, func, 2L**34)
self.assertRaises(OverflowError, socket.ntohl, 2L**34)
def testGetServByName(self): def testGetServByName(self):
"""Testing getservbyname().""" """Testing getservbyname()."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment