summaryrefslogtreecommitdiff
path: root/Examples/test-suite/python/li_std_vector_ptr_runme.py
blob: 875d1c9c96b17ad1a338924d515c81c0e8ab1a5f (plain)
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")