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 test_pointer_adoption_ext import * 6 7>>> num_a_instances() 80 9 10>>> a = create('dynamically allocated') 11>>> num_a_instances() 121 13 14>>> a.content() 15'dynamically allocated' 16 17>>> innards = a.get_inner() 18>>> innards.change('with an exposed reference') 19>>> a.content() 20'with an exposed reference' 21 22# The a instance should be kept alive... 23>>> a = None 24>>> num_a_instances() 251 26 27# ...until we're done with its innards 28>>> innards = None 29>>> num_a_instances() 300 31 32>>> b = B() 33>>> a = create('another') 34>>> b.a_content() 35'empty' 36>>> innards = b.adopt(a); 37>>> b.a_content() 38'another' 39>>> num_a_instances() 401 41>>> del a # innards and b are both holding a reference 42>>> num_a_instances() 431 44>>> innards.change('yet another') 45>>> b.a_content() 46'yet another' 47 48>>> del innards 49>>> num_a_instances() # b still owns a reference to a 501 51>>> del b 52>>> num_a_instances() 530 54 55Test call policies for constructors here 56 57>>> a = create('second a') 58>>> num_a_instances() 591 60>>> b = B(a) 61>>> num_a_instances() 621 63>>> a.content() 64'second a' 65 66>>> del a 67>>> num_a_instances() 681 69>>> b.a_content() 70'second a' 71 72>>> del b 73>>> num_a_instances() 740 75 76>>> assert as_A(create('dynalloc')) is not None 77>>> base = Base() 78>>> assert as_A(base) is None 79""" 80def run(args = None): 81 import sys 82 import doctest 83 84 if args is not None: 85 sys.argv = args 86 return doctest.testmod(sys.modules.get(__name__)) 87 88if __name__ == '__main__': 89 print("running...") 90 import sys 91 status = run()[0] 92 if (status == 0): print("Done.") 93 sys.exit(status) 94