[Python-checkins] python/dist/src/Lib/test test_socket.py,1.44,1.45

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Thu, 25 Jul 2002 09:01:14 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv29556/Lib/test

Modified Files:
	test_socket.py 
Log Message:
Extended socket.htonl and ntohl to accept longs.

Fixes SF bug #568322.

The code should raise an OverflowError if the long is > 32 bits, even
on platforms where sizeof(long) > 4.





Index: test_socket.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_socket.py,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** test_socket.py	25 Jul 2002 15:37:23 -0000	1.44
--- test_socket.py	25 Jul 2002 16:01:11 -0000	1.45
***************
*** 248,251 ****
--- 248,262 ----
              pass
  
+     def testNtoH(self):
+         def twice(f):
+             def g(x):
+                 return f(f(x))
+             return g
+         for i in (0, 1, 0xffff0000, 2L, (2**32L) - 1):
+             self.assertEqual(i, twice(socket.htonl)(i))
+             self.assertEqual(i, twice(socket.ntohl)(i))
+         self.assertRaises(OverflowError, socket.htonl, 2L**34)
+         self.assertRaises(OverflowError, socket.ntohl, 2L**34)
+ 
      def testGetServByName(self):
          """Testing getservbyname()."""