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