Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_varsize_struct.VarSizeTest Class Reference

List of all members.

Public Member Functions

def test_resize
def test_array_invalid_length
def test_zerosized_array

Detailed Description

Definition at line 4 of file test_varsize_struct.py.


Member Function Documentation

Definition at line 34 of file test_varsize_struct.py.

00034 
00035     def test_array_invalid_length(self):
00036         # cannot create arrays with non-positive size
00037         self.assertRaises(ValueError, lambda: c_int * -1)
00038         self.assertRaises(ValueError, lambda: c_int * -3)

Here is the call graph for this function:

Definition at line 5 of file test_varsize_struct.py.

00005 
00006     def test_resize(self):
00007         class X(Structure):
00008             _fields_ = [("item", c_int),
00009                         ("array", c_int * 1)]
00010 
00011         self.assertEqual(sizeof(X), sizeof(c_int) * 2)
00012         x = X()
00013         x.item = 42
00014         x.array[0] = 100
00015         self.assertEqual(sizeof(x), sizeof(c_int) * 2)
00016 
00017         # make room for one additional item
00018         new_size = sizeof(X) + sizeof(c_int) * 1
00019         resize(x, new_size)
00020         self.assertEqual(sizeof(x), new_size)
00021         self.assertEqual((x.item, x.array[0]), (42, 100))
00022 
00023         # make room for 10 additional items
00024         new_size = sizeof(X) + sizeof(c_int) * 9
00025         resize(x, new_size)
00026         self.assertEqual(sizeof(x), new_size)
00027         self.assertEqual((x.item, x.array[0]), (42, 100))
00028 
00029         # make room for one additional item
00030         new_size = sizeof(X) + sizeof(c_int) * 1
00031         resize(x, new_size)
00032         self.assertEqual(sizeof(x), new_size)
00033         self.assertEqual((x.item, x.array[0]), (42, 100))

Here is the call graph for this function:

Definition at line 39 of file test_varsize_struct.py.

00039 
00040     def test_zerosized_array(self):
00041         array = (c_int * 0)()
00042         # accessing elements of zero-sized arrays raise IndexError
00043         self.assertRaises(IndexError, array.__setitem__, 0, None)
00044         self.assertRaises(IndexError, array.__getitem__, 0)
00045         self.assertRaises(IndexError, array.__setitem__, 1, None)
00046         self.assertRaises(IndexError, array.__getitem__, 1)
00047         self.assertRaises(IndexError, array.__setitem__, -1, None)
00048         self.assertRaises(IndexError, array.__getitem__, -1)

Here is the call graph for this function:


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