|
Last change
on this file since 45 was
29,
checked in by landauf, 17 years ago
|
|
updated boost from 1_33_1 to 1_34_1
|
|
File size:
2.0 KB
|
| Line | |
|---|
| 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 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) |
|---|
| 18 | 1 |
|---|
| 19 | >>> New(0) |
|---|
| 20 | |
|---|
| 21 | >>> type(factory(3)) |
|---|
| 22 | <class 'shared_ptr_ext.Y'> |
|---|
| 23 | >>> type(factory(42)) |
|---|
| 24 | <class '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() |
|---|
| 34 | 12 |
|---|
| 35 | >>> p.v() |
|---|
| 36 | -12 |
|---|
| 37 | >>> look(p) |
|---|
| 38 | 12 |
|---|
| 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() |
|---|
| 49 | 1 |
|---|
| 50 | >>> Z.look_store() |
|---|
| 51 | 12 |
|---|
| 52 | >>> Z.release() |
|---|
| 53 | bye |
|---|
| 54 | >>> Z.count() |
|---|
| 55 | 0 |
|---|
| 56 | |
|---|
| 57 | >>> z = Z(13) |
|---|
| 58 | >>> z.value() |
|---|
| 59 | 13 |
|---|
| 60 | >>> z.v() |
|---|
| 61 | 13 |
|---|
| 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() |
|---|
| 71 | 13 |
|---|
| 72 | >>> Z.count() |
|---|
| 73 | 1 |
|---|
| 74 | >>> Z.look_store() |
|---|
| 75 | 13 |
|---|
| 76 | >>> Z.release() |
|---|
| 77 | >>> Z.count() |
|---|
| 78 | 0 |
|---|
| 79 | |
|---|
| 80 | >>> x = X(17) |
|---|
| 81 | >>> x.value() |
|---|
| 82 | 17 |
|---|
| 83 | >>> look(x) |
|---|
| 84 | 17 |
|---|
| 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() |
|---|
| 93 | 1 |
|---|
| 94 | >>> X.look_store() |
|---|
| 95 | 17 |
|---|
| 96 | >>> X.release() |
|---|
| 97 | >>> X.count() |
|---|
| 98 | 0 |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | >>> y = Y(19) |
|---|
| 102 | >>> y.value() |
|---|
| 103 | 19 |
|---|
| 104 | >>> modify(y) |
|---|
| 105 | >>> look(y) |
|---|
| 106 | -1 |
|---|
| 107 | >>> store(Y(23)) |
|---|
| 108 | >>> Y.count() |
|---|
| 109 | 1 |
|---|
| 110 | >>> Y.look_store() |
|---|
| 111 | 23 |
|---|
| 112 | >>> Y.release() |
|---|
| 113 | >>> Y.count() |
|---|
| 114 | 0 |
|---|
| 115 | ''' |
|---|
| 116 | |
|---|
| 117 | def 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 | |
|---|
| 125 | if __name__ == '__main__': |
|---|
| 126 | print "running..." |
|---|
| 127 | import sys |
|---|
| 128 | status = run()[0] |
|---|
| 129 | if (status == 0): print "Done." |
|---|
| 130 | sys.exit(status) |
|---|
Note: See
TracBrowser
for help on using the repository browser.