1# Copyright David Abrahams 2004. Distributed under the Boost
2# Software License, Version 1.0. (See accompanying
3# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4'''
5>>> from boost_shared_ptr_ext import *
6
7   Test that shared_ptr<Derived> can be converted to shared_ptr<Base>
8
9>>> Y.store(YYY(42))
10
11>>> x = X(17)
12>>> null_x = null(x)
13>>> null_x # should be None
14>>> identity(null_x) # should also be None
15
16>>> a = New(1)
17>>> A.call_f(a)
181
19>>> New(0)
20
21>>> type(factory(3))
22<class 'boost_shared_ptr_ext.Y'>
23>>> type(factory(42))
24<class 'boost_shared_ptr_ext.YY'>
25
26>>> class P(Z):
27...     def v(self):
28...         return -Z.v(self);
29...     def __del__(self):
30...         print('bye')
31...
32>>> p = P(12)
33>>> p.value()
3412
35>>> p.v()
36-12
37>>> look(p)
3812
39>>> try: modify(p)
40... except TypeError: pass
41... else: 'print(expected a TypeError)'
42>>> look(None)
43-1
44>>> store(p)
45>>> del p
46>>> Z.get().v()
47-12
48>>> Z.count()
491
50>>> Z.look_store()
5112
52>>> Z.release()
53bye
54>>> Z.count()
550
56
57>>> z = Z(13)
58>>> z.value()
5913
60>>> z.v()
6113
62>>> try: modify(z)
63... except TypeError: pass
64... else: 'print(expected a TypeError)'
65
66>>> Z.get() # should be None
67>>> store(z)
68>>> assert Z.get() is z  # show that deleter introspection works
69>>> del z
70>>> Z.get().value()
7113
72>>> Z.count()
731
74>>> Z.look_store()
7513
76>>> Z.release()
77>>> Z.count()
780
79
80>>> x = X(17)
81>>> x.value()
8217
83>>> look(x)
8417
85>>> try: modify(x)
86... except TypeError: pass
87... else: 'print(expected a TypeError)'
88>>> look(None)
89-1
90>>> store(x)
91>>> del x
92>>> X.count()
931
94>>> X.look_store()
9517
96>>> X.release()
97>>> X.count()
980
99
100
101>>> y = Y(19)
102>>> y.value()
10319
104>>> modify(y)
105>>> look(y)
106-1
107>>> store(Y(23))
108>>> Y.count()
1091
110>>> Y.look_store()
11123
112>>> Y.release()
113>>> Y.count()
1140
115'''
116
117def run(args = None):
118    import sys
119    import doctest
120
121    if args is not None:
122        sys.argv = args
123    return doctest.testmod(sys.modules.get(__name__))
124
125if __name__ == '__main__':
126    print("running...")
127    import sys
128    status = run()[0]
129    if (status == 0): print("Done.")
130    sys.exit(status)
131