File: ClientServer.py

package info (click to toggle)
python-orbit 0.3.1-12
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,492 kB
  • ctags: 801
  • sloc: sh: 9,444; ansic: 5,642; python: 1,141; makefile: 126
file content (246 lines) | stat: -rw-r--r-- 7,596 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env python
import CORBA,CompleteTest,CompleteTest__POA, Constants
import unittest,os,time

orb = CORBA.ORB_init([],CORBA.ORB_ID)
ior = open("ior").readline()
testharness = orb.string_to_object(ior)

class ObjectReferenceTest(unittest.TestCase):
    th = testharness

    def test_J0_narrow(self):
        d = self.th.get_reftest()
        import RefTestIDL
        n = d._narrow(RefTestIDL.Foo)
        n = d._narrow(RefTestIDL.Foo)
        self.th.cleanup_obj()

    def test_J1_narrow_validate(self):
        d = self.th.get_reftest2()
        #assert(d.__class__ == CORBA.Object)
        import RefTest2IDL
        n = d._narrow(RefTest2IDL.Foo)
        n = d._narrow(RefTest2IDL.Foo)
        n = d._narrow(RefTest2IDL.Foo)
        n = d._narrow(RefTest2IDL.Foo)
        #assert(n.__class__ ==  RefTest2IDL.Foo)
        assert(n.get_money() == "money")
        self.th.cleanup_obj()

    def test_J1_narrow_import(self):
        d = self.th.get_reftest()
        idl = __import__("RefTestIDL")
        n = d._narrow(idl.Foo)
        n = d._narrow(idl.Foo)
        self.th.cleanup_obj()

class ParameterReturnValueTest(unittest.TestCase):
    th = testharness
    
    def test_V0_foo(self):
        pass

class SendTest(unittest.TestCase):
    th = testharness

    def test_T0_send_string(self):
        assert(self.th.send_string(Constants.string) == 1)

    def test_T1_send_long(self):
        assert(self.th.send_long(Constants.long) == 1)

    def test_T2_send_float(self):
        assert(self.th.send_float(Constants.float) == 1)

    def test_T3_send_double(self):
        assert(self.th.send_double(Constants.double) == 1)

    def test_T3_send_octet_int(self):
        assert(self.th.send_octet_int(Constants.octet) == 1)

    def test_T4_send_octet_char(self):
        assert(self.th.send_octet_char(Constants.char) == 1)

    def test_T5_send_octet_string(self):
        self.assertRaises(CORBA.MARSHAL,self.th.send_octet_string,Constants.string)

    def test_T6_send_object(self):
        d = self.th.get_object()
        assert(d.get_string() == Constants.char)
        assert(self.th.send_object(d) == 1)
        self.th.cleanup_obj()

    def test_T7_send_noobject(self):
        assert(self.th.send_noobject(None) == 1)

    def test_T8_send_dummy(self):
        d = self.th.get_object()
        assert(d.get_string() == Constants.string)
        assert(self.th.send_object(d) == 1)
        self.th.cleanup_obj()

    def test_T9_send_string_seq(self):
        assert(self.th.send_string_seq(
            Constants.string_seq
            ) == 1)

    def test_T10_send_long_seq(self):
        assert(self.th.send_long_seq(
            Constants.long_seq
            ) == 1)

    def test_T11_send_float_seq(self):
        assert(self.th.send_float_seq(
            Constants.float_seq
            ) == 1)

    def test_T12_send_octet_int_seq(self):
        res = self.th.send_octet_int_seq ( Constants.octet_seq )
        assert ( res == 1 )

    def test_T13_send_octet_char_seq(self):
        assert(self.th.send_octet_char_seq(("a","c","b","e","d")) == 1)
    
    def test_T14_send_octet_string_seq(self):
	assert(self.th.send_octet_char_seq("acbed") == 1) 

    def test_T15_send_octet_mixed_seq(self):
        assert(self.th.send_octet_mixed_seq(
            ( "a",0x68,"b",0x78,"d" ) 
            ) == 1)

    def test_T16_send_object_seq(self):
        l = []
        for f in range(0,10):
            d = self.th.get_object()
            assert(d.get_string() == "dummy")
            l.append(d)
        assert(self.th.send_object_seq(l) == 1)
        self.th.cleanup_obj()

    def test_T17_send_noobject_seq(self):
        l = []
        for f in range(0,10):
            l.append(None)
        assert(self.th.send_noobject_seq(l) == 1)

    def test_T18_send_dummy_seq(self):
        l = []
        for f in range(0,10):
            d = self.th.get_dummy()
            assert(d.get_string() == "dummy")
            l.append(d)
        assert(self.th.send_dummy_seq(l) == 1)
        self.th.cleanup_obj()

class ReturnValueTest(unittest.TestCase):
    th = testharness

    def test_R1000_get_fake_string(self):
      self.assertRaises(CORBA.BAD_OPERATION,self.th.get_fake_string)

    def test_R1001_get_fake_object(self):
      self.assertRaises(CORBA.BAD_OPERATION,self.th.get_fake_string)

    def test_R0_string_return(self):
        assert(self.th.get_string() == "hello")

    def test_R1_long_return(self):
        assert(self.th.get_long() == 627)
    
    def test_R2_float_return(self):
        # this is crazy becaue of python's float handling?!
        # is there a way to fix this?
        assert(round(self.th.get_float(),2) == 627.23)
    
    def test_R3_null_return(self):
        assert(self.th.get_null() == None)
    
    def test_R4_dummy_return(self):
        d = self.th.get_dummy()
        assert(d.get_string() == "dummy")
        self.th.cleanup_obj()

    def test_R5_object_return(self):
        d = self.th.get_object()
        assert(d.get_string() == "dummy")
        self.th.cleanup_obj()
    
    def test_R6_noobject_return(self):
        d = self.th.get_noobject()
        assert(d == None)

    def test_R61_any_string_return(self):
        d = self.th.get_any()
        assert(type(d.tc) == type(CORBA.TypeCode("IDL:CORBA/String:1.0")))
        assert(d.value == "Test String")
        assert(type(d.tc) == type(CORBA.TypeCode("IDL:CORBA/String:1.0")))
        assert(d.value == "Test String")

    def test_R7_octet_int_return(self):
        d = self.th.get_octet_int()
        assert(d == 0x68)

    # This is not very correct - octets alone become integers
    # but the chr solves it for now.
    def test_R8_octet_char_return(self):
        d = self.th.get_octet_char()
        assert(chr(d) == "a")

    def test_R9_string_seq_return(self):
        # breaks if we return a tuple on servant
        assert(self.th.get_string_seq() == ("hello","goodbye","farewell"))

    def test_R10_long_seq_return(self):
        assert(self.th.get_long_seq() == (1,3,5,7))

    def test_R11_float_seq_return(self):
        # okay, will have to check the float issue here..
        assert(map(lambda x: round(x,2),self.th.get_float_seq()) \
            == 1.11,3.11,5.33,7.55,9.77)

    def test_R12_dummy_seq_return(self):
        ds = self.th.get_dummy_seq()
        for d in ds:
            assert(d.get_string() == "dummy")
        self.th.cleanup_obj()

    def test_R13_object_seq_return(self):
        ds = self.th.get_object_seq()
        for d in ds:
            assert(d.get_string() == "dummy")
        self.th.cleanup_obj()
    
    def test_R14_noobject_seq_return(self):
        ds = self.th.get_noobject_seq()
        # This call doesn't fail even when not defined in server - how
        # odd.
        for d in ds:
            assert(d == None)

    def test_R15_octet_string_return(self):
        d = self.th.get_octet_string_seq()
        assert(d == "abcdef" )

    def test_R16_octet_int_return(self):
        d = self.th.get_octet_int_seq()
        assert(d == "abcdef" )

    def test_R17_octet_char_return(self):
        d = self.th.get_octet_char_seq()
        assert(d == ( "abcdef" ) )

suite = unittest.TestSuite( ( 
    unittest.makeSuite( ParameterReturnValueTest ),
    unittest.makeSuite( SendTest ),
    unittest.makeSuite( ObjectReferenceTest ),
    unittest.makeSuite( ReturnValueTest )
) )

if __name__ == "__main__":
    os.spawnv(os.P_NOWAITO,"./servertest.py",['PYTHONPATH="../src"'])
    time.sleep(2)
    runner = unittest.TextTestRunner()
    runner.run(suite)
    th.shutdown_orb()