2016-03-10 12:24:10 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function
|
|
|
|
import sys
|
|
|
|
sys.path.append('.')
|
|
|
|
|
2016-03-26 22:04:10 +00:00
|
|
|
from example.issues import print_cchar, print_char
|
2016-04-11 16:13:08 +00:00
|
|
|
from example.issues import DispatchIssue, dispatch_issue_go
|
2016-04-30 21:02:39 +00:00
|
|
|
from example.issues import Placeholder, return_vec_of_reference_wrapper
|
2016-04-27 12:33:52 +00:00
|
|
|
from example.issues import iterator_passthrough
|
2016-05-01 12:42:20 +00:00
|
|
|
from example.issues import ElementList, ElementA, print_element
|
2016-05-17 13:35:29 +00:00
|
|
|
from example.issues import expect_float, expect_int
|
2016-05-26 11:19:27 +00:00
|
|
|
from example.issues import A, call_f
|
2016-07-17 21:43:00 +00:00
|
|
|
from example.issues import StrIssue
|
2016-08-09 21:57:59 +00:00
|
|
|
from example.issues import NestA, NestB, NestC, print_NestA, print_NestB, print_NestC
|
2016-04-30 21:02:39 +00:00
|
|
|
import gc
|
2016-03-10 12:24:10 +00:00
|
|
|
|
|
|
|
print_cchar("const char *")
|
2016-03-26 22:04:10 +00:00
|
|
|
print_char('c')
|
2016-04-11 16:13:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class PyClass1(DispatchIssue):
|
|
|
|
def dispatch(self):
|
|
|
|
print("Yay..")
|
|
|
|
|
|
|
|
|
|
|
|
class PyClass2(DispatchIssue):
|
|
|
|
def dispatch(self):
|
|
|
|
try:
|
|
|
|
super(PyClass2, self).dispatch()
|
|
|
|
except Exception as e:
|
|
|
|
print("Failed as expected: " + str(e))
|
|
|
|
p = PyClass1()
|
|
|
|
dispatch_issue_go(p)
|
|
|
|
|
|
|
|
b = PyClass2()
|
|
|
|
dispatch_issue_go(b)
|
2016-04-20 15:00:57 +00:00
|
|
|
|
2016-04-21 10:21:14 +00:00
|
|
|
print(return_vec_of_reference_wrapper(Placeholder(4)))
|
2016-04-27 12:33:52 +00:00
|
|
|
|
|
|
|
print(list(iterator_passthrough(iter([3, 5, 7, 9, 11, 13, 15]))))
|
2016-04-30 21:02:39 +00:00
|
|
|
|
|
|
|
el = ElementList()
|
|
|
|
for i in range(10):
|
|
|
|
el.add(ElementA(i))
|
|
|
|
gc.collect()
|
|
|
|
for i, v in enumerate(el.get()):
|
|
|
|
print("%i==%i, " % (i, v.value()), end='')
|
|
|
|
print()
|
2016-05-01 12:42:20 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
print_element(None)
|
|
|
|
except Exception as e:
|
|
|
|
print("Failed as expected: " + str(e))
|
2016-05-17 13:35:29 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
print(expect_int(5.2))
|
|
|
|
except Exception as e:
|
|
|
|
print("Failed as expected: " + str(e))
|
|
|
|
|
|
|
|
print(expect_float(12))
|
2016-05-26 11:19:27 +00:00
|
|
|
|
|
|
|
class B(A):
|
|
|
|
def __init__(self):
|
|
|
|
super(B, self).__init__()
|
|
|
|
|
|
|
|
def f(self):
|
|
|
|
print("In python f()")
|
|
|
|
|
|
|
|
print("C++ version")
|
|
|
|
a = A()
|
|
|
|
call_f(a)
|
|
|
|
|
|
|
|
print("Python version")
|
|
|
|
b = B()
|
|
|
|
call_f(b)
|
|
|
|
|
2016-07-17 21:43:00 +00:00
|
|
|
print(StrIssue(3))
|
|
|
|
try:
|
|
|
|
print(StrIssue("no", "such", "constructor"))
|
|
|
|
except TypeError as e:
|
|
|
|
print("Failed as expected: " + str(e))
|
2016-08-09 21:57:59 +00:00
|
|
|
|
|
|
|
a = NestA()
|
|
|
|
b = NestB()
|
|
|
|
c = NestC()
|
|
|
|
a += 10
|
|
|
|
b.a += 100
|
|
|
|
c.b.a += 1000
|
|
|
|
b -= 1
|
|
|
|
c.b -= 3
|
|
|
|
c *= 7
|
|
|
|
print_NestA(a)
|
|
|
|
print_NestA(b.a)
|
|
|
|
print_NestA(c.b.a)
|
|
|
|
print_NestB(b)
|
|
|
|
print_NestB(c.b)
|
|
|
|
print_NestC(c)
|
2016-08-10 16:08:04 +00:00
|
|
|
abase = a.as_base()
|
|
|
|
print(abase.value)
|
|
|
|
a.as_base().value += 44
|
|
|
|
print(abase.value)
|
|
|
|
print(c.b.a.as_base().value)
|
|
|
|
c.b.a.as_base().value += 44
|
|
|
|
print(c.b.a.as_base().value)
|
|
|
|
del c
|
|
|
|
gc.collect()
|
|
|
|
del a # Should't delete while abase is still alive
|
|
|
|
gc.collect()
|
|
|
|
print(abase.value)
|
|
|
|
del abase
|
|
|
|
gc.collect()
|