PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/python/import/runme.py

#
Python | 111 lines | 102 code | 5 blank | 4 comment | 0 complexity | e05725a257bfe6aab6406ae8e77f6fa4 MD5 | raw file
  1# file: runme.py
  2# Test various properties of classes defined in separate modules
  3
  4print "Testing the %import directive"
  5import base
  6import foo
  7import bar
  8import spam
  9
 10# Create some objects
 11
 12print "Creating some objects"
 13
 14a = base.Base()
 15b = foo.Foo()
 16c = bar.Bar()
 17d = spam.Spam()
 18
 19# Try calling some methods
 20print "Testing some methods"
 21print "",
 22print "Should see 'Base::A' ---> ",
 23a.A()
 24print "Should see 'Base::B' ---> ",
 25a.B()
 26
 27print "Should see 'Foo::A' ---> ",
 28b.A()
 29print "Should see 'Foo::B' ---> ",
 30b.B()
 31
 32print "Should see 'Bar::A' ---> ",
 33c.A()
 34print "Should see 'Bar::B' ---> ",
 35c.B()
 36
 37print "Should see 'Spam::A' ---> ",
 38d.A()
 39print "Should see 'Spam::B' ---> ",
 40d.B()
 41
 42# Try some casts
 43
 44print "\nTesting some casts\n"
 45print "",
 46
 47x = a.toBase()
 48print "Should see 'Base::A' ---> ",
 49x.A()
 50print "Should see 'Base::B' ---> ",
 51x.B()
 52
 53x = b.toBase()
 54print "Should see 'Foo::A' ---> ",
 55x.A()
 56
 57print "Should see 'Base::B' ---> ",
 58x.B()
 59
 60x = c.toBase()
 61print "Should see 'Bar::A' ---> ",
 62x.A()
 63
 64print "Should see 'Base::B' ---> ",
 65x.B()
 66
 67x = d.toBase()
 68print "Should see 'Spam::A' ---> ",
 69x.A()
 70
 71print "Should see 'Base::B' ---> ",
 72x.B()
 73
 74x = d.toBar()
 75print "Should see 'Bar::B' ---> ",
 76x.B()
 77
 78print "\nTesting some dynamic casts\n"
 79x = d.toBase()
 80
 81print " Spam -> Base -> Foo : ",
 82y = foo.Foo_fromBase(x)
 83if y:
 84      print "bad swig"
 85else:
 86      print "good swig"
 87
 88print " Spam -> Base -> Bar : ",
 89y = bar.Bar_fromBase(x)
 90if y:
 91      print "good swig"
 92else:
 93      print "bad swig"
 94      
 95print " Spam -> Base -> Spam : ",
 96y = spam.Spam_fromBase(x)
 97if y:
 98      print "good swig"
 99else:
100      print "bad swig"
101
102print " Foo -> Spam : ",
103y = spam.Spam_fromBase(b)
104if y:
105      print "bad swig"
106else:
107      print "good swig"
108
109
110
111