You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

  1. from __future__ import print_function
  2. import sys
  3. sys.path.append('.')
  4. from example import StringList, print_opaque_list
  5. from example import ClassWithSTLVecProperty
  6. from example import return_void_ptr, print_void_ptr
  7. from example import return_null_str, print_null_str
  8. from example import return_unique_ptr
  9. from example import Example1
  10. #####
  11. l = StringList()
  12. l.push_back("Element 1")
  13. l.push_back("Element 2")
  14. print_opaque_list(l)
  15. print("Back element is %s" % l.back())
  16. for i, k in enumerate(l):
  17. print("%i/%i : %s" % (i + 1, len(l), k))
  18. l.pop_back()
  19. print_opaque_list(l)
  20. #####
  21. cvp = ClassWithSTLVecProperty()
  22. print_opaque_list(cvp.stringList)
  23. cvp.stringList = l
  24. cvp.stringList.push_back("Element 3")
  25. print_opaque_list(cvp.stringList)
  26. #####
  27. print_void_ptr(return_void_ptr())
  28. print_void_ptr(Example1()) # Should also work for other C++ types
  29. try:
  30. print_void_ptr([1, 2, 3]) # This should not work
  31. except Exception as e:
  32. print("Caught expected exception: " + str(e))
  33. print(return_null_str())
  34. print_null_str(return_null_str())
  35. #####
  36. ptr = return_unique_ptr()
  37. print(ptr)
  38. print_opaque_list(ptr)