File: li_std_vector_ptr_runme.py

package info (click to toggle)
swig 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 42,876 kB
  • sloc: cpp: 61,013; ansic: 27,612; java: 14,670; python: 10,632; cs: 8,103; makefile: 6,287; yacc: 6,197; sh: 5,247; ruby: 5,172; perl: 3,541; php: 2,069; ml: 2,066; lisp: 1,894; javascript: 1,300; tcl: 1,091; xml: 115
file content (64 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (3)
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
from li_std_vector_ptr import *

def check(val1, val2):
    if val1 != val2:
        raise RuntimeError("Values are not the same %s %s" % (val1, val2))
ip1 = makeIntPtr(11)
ip2 = makeIntPtr2(22)

vi = IntPtrVector((ip1, ip2))
check(getValueFromVector(vi, 0), 11)
check(getValueFromVector(vi, 1), 22)

check(getIntValue(vi[0]), 11)
check(getIntValue(vi[1]), 22)
check(getIntValue2(vi[0]), 11)
check(getIntValue2(vi[1]), 22)

ipp = makeIntPtrPtr(vi[0])
check(getIntValue3(ipp), 11) # Note: getIntValue3 takes int**

vA = APtrVector([makeA(33), makeA(34)])
check(getVectorValueA(vA, 0), 33)

vB = BPtrVector([makeB(133), makeB(134)])
check(getVectorValueB(vB, 0), 133)

vC = CPtrVector([makeC(1133), makeC(1134)])
check(getVectorValueC(vC, 0), 1133)


vA = [makeA(233), makeA(234)]
check(getVectorValueA(vA, 0), 233)

vB = [makeB(333), makeB(334)]
check(getVectorValueB(vB, 0), 333)

vC = [makeC(3333), makeC(3334)]
check(getVectorValueC(vC, 0), 3333)

# mixed A and B should not be accepted
vAB = [makeA(999), makeB(999)]
try:
  check(getVectorValueA(vAB, 0), 999)
  raise RuntimeError("missed exception")
except TypeError:
  pass

b111 = makeB(111)
bNones = BPtrVector([None, b111, None])

bCount = 0
noneCount = 0
for b in bNones:
  if b == None:
    noneCount = noneCount + 1
  else:
    if b.val != 111:
      raise RuntimeError("b.val is wrong")
    bCount = bCount + 1

if bCount != 1:
  raise RuntimeError("bCount wrong")
if noneCount != 2:
  raise RuntimeError("noneCount wrong")