1 | # Copyright Bruno da Silva de Oliveira 2003. Use, modification and |
---|
2 | # distribution is subject to the Boost Software License, Version 1.0. |
---|
3 | # (See accompanying file LICENSE_1_0.txt or copy at |
---|
4 | # http:#www.boost.org/LICENSE_1_0.txt) |
---|
5 | import sys |
---|
6 | import unittest |
---|
7 | from Pyste.policies import * |
---|
8 | |
---|
9 | |
---|
10 | #================================================================================ |
---|
11 | # PolicicesTest |
---|
12 | #================================================================================ |
---|
13 | class PoliciesTest(unittest.TestCase): |
---|
14 | |
---|
15 | def testReturnInternal(self): |
---|
16 | 'tests the code from a simple internal_reference' |
---|
17 | |
---|
18 | x = return_internal_reference(1) |
---|
19 | self.assertEqual(x.Code(), 'return_internal_reference< 1 >') |
---|
20 | x = return_internal_reference(3) |
---|
21 | self.assertEqual(x.Code(), 'return_internal_reference< 3 >') |
---|
22 | |
---|
23 | |
---|
24 | def testCustodian(self): |
---|
25 | 'tests the code from a simple custodian_and_ward' |
---|
26 | |
---|
27 | x = with_custodian_and_ward(1,2) |
---|
28 | self.assertEqual(x.Code(), 'with_custodian_and_ward< 1, 2 >') |
---|
29 | x = with_custodian_and_ward(3,4) |
---|
30 | self.assertEqual(x.Code(), 'with_custodian_and_ward< 3, 4 >') |
---|
31 | |
---|
32 | |
---|
33 | def testReturnPolicies(self): |
---|
34 | 'tests all the return_value_policies' |
---|
35 | |
---|
36 | ret = 'return_value_policy< %s >' |
---|
37 | x = return_value_policy(reference_existing_object) |
---|
38 | self.assertEqual(x.Code(), ret % 'reference_existing_object') |
---|
39 | x = return_value_policy(copy_const_reference) |
---|
40 | self.assertEqual(x.Code(), ret % 'copy_const_reference') |
---|
41 | x = return_value_policy(copy_non_const_reference) |
---|
42 | self.assertEqual(x.Code(), ret % 'copy_non_const_reference') |
---|
43 | x = return_value_policy(manage_new_object) |
---|
44 | self.assertEqual(x.Code(), ret % 'manage_new_object') |
---|
45 | x = return_value_policy(return_opaque_pointer) |
---|
46 | self.assertEqual(x.Code(), ret % 'return_opaque_pointer') |
---|
47 | |
---|
48 | def testReturnWithCustodiam(self): |
---|
49 | 'test the mix of return_internal with custodian' |
---|
50 | |
---|
51 | x = return_internal_reference(1, with_custodian_and_ward(3,2)) |
---|
52 | self.assertEqual( |
---|
53 | x.Code(), |
---|
54 | 'return_internal_reference< 1, with_custodian_and_ward< 3, 2 > >') |
---|
55 | |
---|
56 | |
---|
57 | def testReturnPoliciesWithInternal(self): |
---|
58 | 'test the mix of return_internal with return_policy' |
---|
59 | |
---|
60 | x = return_internal_reference(1, return_value_policy(manage_new_object)) |
---|
61 | self.assertEqual( |
---|
62 | x.Code(), |
---|
63 | 'return_internal_reference< 1, return_value_policy< manage_new_object > >') |
---|
64 | |
---|
65 | |
---|
66 | if __name__ == '__main__': |
---|
67 | unittest.main() |
---|