Back to index

python3.2  3.2.2
Public Member Functions
test.test_xdrlib.XDRTest Class Reference

List of all members.

Public Member Functions

def test_xdr

Detailed Description

Definition at line 6 of file test_xdrlib.py.


Member Function Documentation

Definition at line 8 of file test_xdrlib.py.

00008 
00009     def test_xdr(self):
00010         p = xdrlib.Packer()
00011 
00012         s = b'hello world'
00013         a = [b'what', b'is', b'hapnin', b'doctor']
00014 
00015         p.pack_int(42)
00016         p.pack_int(-17)
00017         p.pack_uint(9)
00018         p.pack_bool(True)
00019         p.pack_bool(False)
00020         p.pack_uhyper(45)
00021         p.pack_float(1.9)
00022         p.pack_double(1.9)
00023         p.pack_string(s)
00024         p.pack_list(range(5), p.pack_uint)
00025         p.pack_array(a, p.pack_string)
00026 
00027         # now verify
00028         data = p.get_buffer()
00029         up = xdrlib.Unpacker(data)
00030 
00031         self.assertEqual(up.get_position(), 0)
00032 
00033         self.assertEqual(up.unpack_int(), 42)
00034         self.assertEqual(up.unpack_int(), -17)
00035         self.assertEqual(up.unpack_uint(), 9)
00036         self.assertTrue(up.unpack_bool() is True)
00037 
00038         # remember position
00039         pos = up.get_position()
00040         self.assertTrue(up.unpack_bool() is False)
00041 
00042         # rewind and unpack again
00043         up.set_position(pos)
00044         self.assertTrue(up.unpack_bool() is False)
00045 
00046         self.assertEqual(up.unpack_uhyper(), 45)
00047         self.assertAlmostEqual(up.unpack_float(), 1.9)
00048         self.assertAlmostEqual(up.unpack_double(), 1.9)
00049         self.assertEqual(up.unpack_string(), s)
00050         self.assertEqual(up.unpack_list(up.unpack_uint), list(range(5)))
00051         self.assertEqual(up.unpack_array(up.unpack_string), a)
00052         up.done()
00053         self.assertRaises(EOFError, up.unpack_uint)

Here is the call graph for this function:


The documentation for this class was generated from the following file: