[ctypes-commit] ctypes/ctypes/test test_cast.py,1.3,1.4
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2006-06-09 07:02:17
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv6506 Modified Files: test_cast.py Log Message: Better test for the cast function. Index: test_cast.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/test_cast.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_cast.py 19 Apr 2006 16:42:28 -0000 1.3 --- test_cast.py 9 Jun 2006 07:02:10 -0000 1.4 *************** *** 31,45 **** self.failUnlessEqual([ptr[i] for i in range(3)], [42, 17, 2]) ! def test_ptr2array(self): ! array = (c_int * 3)(42, 17, 2) ! ! from sys import getrefcount - before = getrefcount(array) - ptr = cast(array, POINTER(c_int)) - self.failUnlessEqual(getrefcount(array), before + 1) - del ptr - self.failUnlessEqual(getrefcount(array), before) if __name__ == "__main__": --- 31,51 ---- self.failUnlessEqual([ptr[i] for i in range(3)], [42, 17, 2]) + def test_p2a_objects(self): + array = (c_char_p * 5)() + self.failUnlessEqual(array._objects, None) + array[0] = "foo bar" + self.failUnlessEqual(array._objects, {'0': "foo bar"}) ! p = cast(array, POINTER(c_char_p)) ! # array and p share a common _objects attribute ! self.failUnless(p._objects is array._objects) ! self.failUnlessEqual(array._objects, {'0': "foo bar"}) ! p[0] = "spam spam" ! self.failUnlessEqual(p._objects, {'0': "spam spam"}) ! self.failUnlessEqual(array._objects, {'0': "spam spam"}) ! p[1] = "foo bar" ! self.failUnlessEqual(p._objects, {'1': 'foo bar', '0': "spam spam"}) ! self.failUnlessEqual(array._objects, {'1': 'foo bar', '0': "spam spam"}) if __name__ == "__main__": |