PageRenderTime 87ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/ttn-post-libtool-1-4-3-upgrade/SWIG/Examples/python/import_template/runme.py

#
Python | 111 lines | 102 code | 5 blank | 4 comment | 0 complexity | 80b54efbeebea95418413ab353359c55 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. # file: runme.py
  2. # Test various properties of classes defined in separate modules
  3. print "Testing the %import directive with templates"
  4. import base
  5. import foo
  6. import bar
  7. import spam
  8. # Create some objects
  9. print "Creating some objects"
  10. a = base.intBase()
  11. b = foo.intFoo()
  12. c = bar.intBar()
  13. d = spam.intSpam()
  14. # Try calling some methods
  15. print "Testing some methods"
  16. print "",
  17. print "Should see 'Base::A' ---> ",
  18. a.A()
  19. print "Should see 'Base::B' ---> ",
  20. a.B()
  21. print "Should see 'Foo::A' ---> ",
  22. b.A()
  23. print "Should see 'Foo::B' ---> ",
  24. b.B()
  25. print "Should see 'Bar::A' ---> ",
  26. c.A()
  27. print "Should see 'Bar::B' ---> ",
  28. c.B()
  29. print "Should see 'Spam::A' ---> ",
  30. d.A()
  31. print "Should see 'Spam::B' ---> ",
  32. d.B()
  33. # Try some casts
  34. print "\nTesting some casts\n"
  35. print "",
  36. x = a.toBase()
  37. print "Should see 'Base::A' ---> ",
  38. x.A()
  39. print "Should see 'Base::B' ---> ",
  40. x.B()
  41. x = b.toBase()
  42. print "Should see 'Foo::A' ---> ",
  43. x.A()
  44. print "Should see 'Base::B' ---> ",
  45. x.B()
  46. x = c.toBase()
  47. print "Should see 'Bar::A' ---> ",
  48. x.A()
  49. print "Should see 'Base::B' ---> ",
  50. x.B()
  51. x = d.toBase()
  52. print "Should see 'Spam::A' ---> ",
  53. x.A()
  54. print "Should see 'Base::B' ---> ",
  55. x.B()
  56. x = d.toBar()
  57. print "Should see 'Bar::B' ---> ",
  58. x.B()
  59. print "\nTesting some dynamic casts\n"
  60. x = d.toBase()
  61. print " Spam -> Base -> Foo : ",
  62. y = foo.intFoo_fromBase(x)
  63. if y:
  64. print "bad swig"
  65. else:
  66. print "good swig"
  67. print " Spam -> Base -> Bar : ",
  68. y = bar.intBar_fromBase(x)
  69. if y:
  70. print "good swig"
  71. else:
  72. print "bad swig"
  73. print " Spam -> Base -> Spam : ",
  74. y = spam.intSpam_fromBase(x)
  75. if y:
  76. print "good swig"
  77. else:
  78. print "bad swig"
  79. print " Foo -> Spam : ",
  80. y = spam.intSpam_fromBase(b)
  81. if y:
  82. print "bad swig"
  83. else:
  84. print "good swig"