File: smart_pointer_const_overload_runme.py

package info (click to toggle)
swig 4.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 45,980 kB
  • sloc: cpp: 54,284; ansic: 29,022; java: 17,595; python: 12,734; cs: 10,421; ruby: 7,263; yacc: 6,501; makefile: 5,860; javascript: 5,538; sh: 5,422; perl: 4,246; php: 3,733; ml: 2,198; tcl: 2,015; lisp: 1,448; xml: 115
file content (124 lines) | stat: -rw-r--r-- 2,261 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from smart_pointer_const_overload import *

CONST_ACCESS = 1
MUTABLE_ACCESS = 2


def test(b, f):
    if f.x1 != 0:
        raise RuntimeError

    # Test member variable get
    if b.x1 != 0:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test member variable set
    b.x1 = 1

    if f.x1 != 1:
        raise RuntimeError

    if f.access1 != MUTABLE_ACCESS:
        raise RuntimeError

    # Test const method
    if b.getx1() != 1:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test mutable method
    b.setx1(2)

    if f.x1 != 2:
        raise RuntimeError

    if f.access1 != MUTABLE_ACCESS:
        raise RuntimeError

    # Test extended const method
    if b.getx2() != 2:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test extended mutable method
    b.setx2(3)

    if f.x1 != 3:
        raise RuntimeError

    if f.access1 != MUTABLE_ACCESS:
        raise RuntimeError

    # Test static method
    b.statMethod()

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test const member
    f.access1 = MUTABLE_ACCESS

    if b.y != 0:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test get through mutable pointer to const member
    f.access1 = MUTABLE_ACCESS

    if get_int(b.yp) != 0:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test get through const pointer to mutable member
    f.x1 = 4
    f.access1 = MUTABLE_ACCESS

    if get_int(b.xp) != 4:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test set through const pointer to mutable member
    f.access1 = MUTABLE_ACCESS
    set_int(b.xp, 5)

    if f.x1 != 5:
        raise RuntimeError

    if f.access1 != CONST_ACCESS:
        raise RuntimeError

    # Test set pointer to const member
    b.yp = new_int(6)

    if f.y != 0:
        raise RuntimeError

    if get_int(f.yp) != 6:
        raise RuntimeError

    if f.access1 != MUTABLE_ACCESS:
        raise RuntimeError

    delete_int(f.yp)

f = Foo()
b = Bar(f)

f2 = Foo()
b2 = Bar2(f2)

test(b, f)
test(b2, f2)