~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to cpp/test/Ice/operations/TwowaysNewAMI.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// **********************************************************************
 
2
//
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
 
4
//
 
5
// This copy of Ice is licensed to you under the terms described in the
 
6
// ICE_LICENSE file included in this distribution.
 
7
//
 
8
// **********************************************************************
 
9
 
 
10
#include <Ice/Ice.h>
 
11
#include <TestCommon.h>
 
12
#include <Test.h>
 
13
 
 
14
using namespace std;
 
15
 
 
16
namespace
 
17
{
 
18
 
 
19
class CallbackBase : public Ice::LocalObject
 
20
{
 
21
public:
 
22
 
 
23
    CallbackBase() :
 
24
        _called(false)
 
25
    {
 
26
    }
 
27
 
 
28
    virtual ~CallbackBase()
 
29
    {
 
30
    }
 
31
 
 
32
    void check()
 
33
    {
 
34
        IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_m);
 
35
        while(!_called)
 
36
        {
 
37
            _m.wait();
 
38
        }
 
39
        _called = false;
 
40
    }
 
41
    
 
42
protected:
 
43
 
 
44
    void called()
 
45
    {
 
46
        IceUtil::Monitor<IceUtil::Mutex>::Lock sync(_m);
 
47
        assert(!_called);
 
48
        _called = true;
 
49
        _m.notify();
 
50
    }
 
51
 
 
52
private:
 
53
 
 
54
    IceUtil::Monitor<IceUtil::Mutex> _m;
 
55
    bool _called;
 
56
};
 
57
 
 
58
typedef IceUtil::Handle<CallbackBase> CallbackBasePtr;
 
59
 
 
60
class Callback : public CallbackBase
 
61
{
 
62
public:
 
63
 
 
64
    Callback()
 
65
    {
 
66
    }
 
67
 
 
68
    Callback(const Ice::CommunicatorPtr& communicator)
 
69
        : _communicator(communicator)
 
70
    {
 
71
    }
 
72
 
 
73
    void ping()
 
74
    {
 
75
        called();
 
76
    }
 
77
 
 
78
    void isA(bool result)
 
79
    {
 
80
        test(result);
 
81
        called();
 
82
    }
 
83
 
 
84
    void id(const string& id)
 
85
    {
 
86
        test(id == Test::MyDerivedClass::ice_staticId());
 
87
        called();
 
88
    }
 
89
 
 
90
    void ids(const Ice::StringSeq& ids)
 
91
    {
 
92
        test(ids.size() == 3);
 
93
        test(ids[0] == "::Ice::Object");
 
94
        test(ids[1] == "::Test::MyClass");
 
95
        test(ids[2] == "::Test::MyDerivedClass");
 
96
        called();
 
97
    }
 
98
    
 
99
    void opVoid()
 
100
    {
 
101
        called();
 
102
    }
 
103
 
 
104
    void opContext(const Ice::Context&)
 
105
    {
 
106
        called();
 
107
    }
 
108
 
 
109
    void opByte(Ice::Byte r, Ice::Byte b)
 
110
    {
 
111
        test(b == Ice::Byte(0xf0));
 
112
        test(r == Ice::Byte(0xff));
 
113
        called();
 
114
    }
 
115
 
 
116
    void opBool(bool r, bool b)
 
117
    {
 
118
        test(b);
 
119
        test(!r);
 
120
        called();
 
121
    }
 
122
 
 
123
    void opShortIntLong(Ice::Long r, Ice::Short s, Ice::Int i, Ice::Long l)
 
124
    {
 
125
        test(s == 10);
 
126
        test(i == 11);
 
127
        test(l == 12);
 
128
        test(r == 12);
 
129
        called();
 
130
    }
 
131
 
 
132
    void opFloatDouble(Ice::Double r, Ice::Float f, Ice::Double d)
 
133
    {
 
134
        test(f == Ice::Float(3.14));
 
135
        test(d == Ice::Double(1.1E10));
 
136
        test(r == Ice::Double(1.1E10));
 
137
        called();
 
138
    }
 
139
 
 
140
    void opString(const ::std::string& r, const ::std::string& s)
 
141
    {
 
142
        test(s == "world hello");
 
143
        test(r == "hello world");
 
144
        called();
 
145
    }
 
146
 
 
147
    void opMyEnum(Test::MyEnum r, Test::MyEnum e)
 
148
    {
 
149
        test(e == Test::enum2);
 
150
        test(r == Test::enum3);
 
151
        called();
 
152
    }
 
153
 
 
154
    void opMyClass(const Test::MyClassPrx& r, const Test::MyClassPrx& c1, const Test::MyClassPrx& c2)
 
155
    {
 
156
        test(c1->ice_getIdentity() == _communicator->stringToIdentity("test"));
 
157
        test(c2->ice_getIdentity() == _communicator->stringToIdentity("noSuchIdentity"));
 
158
        test(r->ice_getIdentity() == _communicator->stringToIdentity("test"));
 
159
 
 
160
        //
 
161
        // We can't do the callbacks below in connection serialization mode.
 
162
        //
 
163
        if(_communicator->getProperties()->getPropertyAsInt("Ice.ThreadPool.Client.Serialize"))
 
164
        {
 
165
            r->opVoid();
 
166
            c1->opVoid();
 
167
            try
 
168
            {
 
169
                c2->opVoid();
 
170
                test(false);
 
171
            }
 
172
            catch(const Ice::ObjectNotExistException&)
 
173
            {
 
174
            }
 
175
        }
 
176
        called();
 
177
    }
 
178
 
 
179
    void opStruct(const Test::Structure& rso, const Test::Structure& so)
 
180
    {
 
181
        test(rso.p == 0);
 
182
        test(rso.e == Test::enum2);
 
183
        test(rso.s.s == "def");
 
184
        test(so.e == Test::enum3);
 
185
        test(so.s.s == "a new string");
 
186
 
 
187
        //
 
188
        // We can't do the callbacks below in connection serialization mode.
 
189
        //
 
190
        if(_communicator->getProperties()->getPropertyAsInt("Ice.ThreadPool.Client.Serialize"))
 
191
        {
 
192
            so.p->opVoid();
 
193
        }
 
194
        called();
 
195
    }
 
196
 
 
197
    void opByteS(const Test::ByteS& rso, const Test::ByteS& bso)
 
198
    {
 
199
        test(bso.size() == 4);
 
200
        test(bso[0] == Ice::Byte(0x22));
 
201
        test(bso[1] == Ice::Byte(0x12));
 
202
        test(bso[2] == Ice::Byte(0x11));
 
203
        test(bso[3] == Ice::Byte(0x01));
 
204
        test(rso.size() == 8);
 
205
        test(rso[0] == Ice::Byte(0x01));
 
206
        test(rso[1] == Ice::Byte(0x11));
 
207
        test(rso[2] == Ice::Byte(0x12));
 
208
        test(rso[3] == Ice::Byte(0x22));
 
209
        test(rso[4] == Ice::Byte(0xf1));
 
210
        test(rso[5] == Ice::Byte(0xf2));
 
211
        test(rso[6] == Ice::Byte(0xf3));
 
212
        test(rso[7] == Ice::Byte(0xf4));
 
213
        called();
 
214
    }
 
215
 
 
216
    void opBoolS(const Test::BoolS& rso, const Test::BoolS& bso)
 
217
    {
 
218
        test(bso.size() == 4);
 
219
        test(bso[0]);
 
220
        test(bso[1]);
 
221
        test(!bso[2]);
 
222
        test(!bso[3]);
 
223
        test(rso.size() == 3);
 
224
        test(!rso[0]);
 
225
        test(rso[1]);
 
226
        test(rso[2]);
 
227
        called();
 
228
    }
 
229
 
 
230
    void opShortIntLongS(const Test::LongS& rso, const Test::ShortS& sso, const Test::IntS& iso, const Test::LongS& lso)
 
231
    {
 
232
        test(sso.size() == 3);
 
233
        test(sso[0] == 1);
 
234
        test(sso[1] == 2);
 
235
        test(sso[2] == 3);
 
236
        test(iso.size() == 4);
 
237
        test(iso[0] == 8);
 
238
        test(iso[1] == 7);
 
239
        test(iso[2] == 6);
 
240
        test(iso[3] == 5);
 
241
        test(lso.size() == 6);
 
242
        test(lso[0] == 10);
 
243
        test(lso[1] == 30);
 
244
        test(lso[2] == 20);
 
245
        test(lso[3] == 10);
 
246
        test(lso[4] == 30);
 
247
        test(lso[5] == 20);
 
248
        test(rso.size() == 3);
 
249
        test(rso[0] == 10);
 
250
        test(rso[1] == 30);
 
251
        test(rso[2] == 20);
 
252
        called();
 
253
    }
 
254
 
 
255
    void opFloatDoubleS(const Test::DoubleS& rso, const Test::FloatS& fso, const Test::DoubleS& dso)
 
256
    {
 
257
        test(fso.size() == 2);
 
258
        test(fso[0] == ::Ice::Float(3.14));
 
259
        test(fso[1] == ::Ice::Float(1.11));
 
260
        test(dso.size() == 3);
 
261
        test(dso[0] == ::Ice::Double(1.3E10));
 
262
        test(dso[1] == ::Ice::Double(1.2E10));
 
263
        test(dso[2] == ::Ice::Double(1.1E10));
 
264
        test(rso.size() == 5);
 
265
        test(rso[0] == ::Ice::Double(1.1E10));
 
266
        test(rso[1] == ::Ice::Double(1.2E10));
 
267
        test(rso[2] == ::Ice::Double(1.3E10));
 
268
        test(::Ice::Float(rso[3]) == ::Ice::Float(3.14));
 
269
        test(::Ice::Float(rso[4]) == ::Ice::Float(1.11));
 
270
        called();
 
271
    }
 
272
 
 
273
    void opStringS(const Test::StringS& rso, const Test::StringS& sso)
 
274
    {
 
275
        test(sso.size() == 4);
 
276
        test(sso[0] == "abc");
 
277
        test(sso[1] == "de");
 
278
        test(sso[2] == "fghi");
 
279
        test(sso[3] == "xyz");
 
280
        test(rso.size() == 3);
 
281
        test(rso[0] == "fghi");
 
282
        test(rso[1] == "de");
 
283
        test(rso[2] == "abc");
 
284
        called();
 
285
    }
 
286
 
 
287
    void opByteSS(const Test::ByteSS& rso, const Test::ByteSS& bso)
 
288
    {
 
289
        test(bso.size() == 2);
 
290
        test(bso[0].size() == 1);
 
291
        test(bso[0][0] == Ice::Byte(0xff));
 
292
        test(bso[1].size() == 3);
 
293
        test(bso[1][0] == Ice::Byte(0x01));
 
294
        test(bso[1][1] == Ice::Byte(0x11));
 
295
        test(bso[1][2] == Ice::Byte(0x12));
 
296
        test(rso.size() == 4);
 
297
        test(rso[0].size() == 3);
 
298
        test(rso[0][0] == Ice::Byte(0x01));
 
299
        test(rso[0][1] == Ice::Byte(0x11));
 
300
        test(rso[0][2] == Ice::Byte(0x12));
 
301
        test(rso[1].size() == 1);
 
302
        test(rso[1][0] == Ice::Byte(0xff));
 
303
        test(rso[2].size() == 1);
 
304
        test(rso[2][0] == Ice::Byte(0x0e));
 
305
        test(rso[3].size() == 2);
 
306
        test(rso[3][0] == Ice::Byte(0xf2));
 
307
        test(rso[3][1] == Ice::Byte(0xf1));
 
308
        called();
 
309
    }
 
310
 
 
311
    void opFloatDoubleSS(const Test::DoubleSS& rso, const Test::FloatSS& fso, const Test::DoubleSS& dso)
 
312
    {
 
313
        test(fso.size() == 3);
 
314
        test(fso[0].size() == 1);
 
315
        test(fso[0][0] == ::Ice::Float(3.14));
 
316
        test(fso[1].size() == 1);
 
317
        test(fso[1][0] == ::Ice::Float(1.11));
 
318
        test(fso[2].size() == 0);
 
319
        test(dso.size() == 1);
 
320
        test(dso[0].size() == 3);
 
321
        test(dso[0][0] == ::Ice::Double(1.1E10));
 
322
        test(dso[0][1] == ::Ice::Double(1.2E10));
 
323
        test(dso[0][2] == ::Ice::Double(1.3E10));
 
324
        test(rso.size() == 2);
 
325
        test(rso[0].size() == 3);
 
326
        test(rso[0][0] == ::Ice::Double(1.1E10));
 
327
        test(rso[0][1] == ::Ice::Double(1.2E10));
 
328
        test(rso[0][2] == ::Ice::Double(1.3E10));
 
329
        test(rso[1].size() == 3);
 
330
        test(rso[1][0] == ::Ice::Double(1.1E10));
 
331
        test(rso[1][1] == ::Ice::Double(1.2E10));
 
332
        test(rso[1][2] == ::Ice::Double(1.3E10));
 
333
        called();
 
334
    }
 
335
 
 
336
    void opStringSS(const Test::StringSS& rso, const Test::StringSS& sso)
 
337
    {
 
338
        test(sso.size() == 5);
 
339
        test(sso[0].size() == 1);
 
340
        test(sso[0][0] == "abc");
 
341
        test(sso[1].size() == 2);
 
342
        test(sso[1][0] == "de");
 
343
        test(sso[1][1] == "fghi");
 
344
        test(sso[2].size() == 0);
 
345
        test(sso[3].size() == 0);
 
346
        test(sso[4].size() == 1);
 
347
        test(sso[4][0] == "xyz");
 
348
        test(rso.size() == 3);
 
349
        test(rso[0].size() == 1);
 
350
        test(rso[0][0] == "xyz");
 
351
        test(rso[1].size() == 0);
 
352
        test(rso[2].size() == 0);
 
353
        called();
 
354
    }
 
355
 
 
356
    void opByteBoolD(const Test::ByteBoolD& ro, const Test::ByteBoolD& _do)
 
357
    {
 
358
        Test::ByteBoolD di1;
 
359
        di1[10] = true;
 
360
        di1[100] = false;
 
361
        test(_do == di1);
 
362
        test(ro.size() == 4);
 
363
        test(ro.find(10) != ro.end());
 
364
        test(ro.find(10)->second == true);
 
365
        test(ro.find(11) != ro.end());
 
366
        test(ro.find(11)->second == false);
 
367
        test(ro.find(100) != ro.end());
 
368
        test(ro.find(100)->second == false);
 
369
        test(ro.find(101) != ro.end());
 
370
        test(ro.find(101)->second == true);
 
371
        called();
 
372
    }
 
373
 
 
374
    void opShortIntD(const Test::ShortIntD& ro, const Test::ShortIntD& _do)
 
375
    {
 
376
        Test::ShortIntD di1;
 
377
        di1[110] = -1;
 
378
        di1[1100] = 123123;
 
379
        test(_do == di1);
 
380
        test(ro.size() == 4);
 
381
        test(ro.find(110) != ro.end());
 
382
        test(ro.find(110)->second == -1);
 
383
        test(ro.find(111) != ro.end());
 
384
        test(ro.find(111)->second == -100);
 
385
        test(ro.find(1100) != ro.end());
 
386
        test(ro.find(1100)->second == 123123);
 
387
        test(ro.find(1101) != ro.end());
 
388
        test(ro.find(1101)->second == 0);
 
389
        called();
 
390
    }
 
391
 
 
392
    void opLongFloatD(const Test::LongFloatD& ro, const Test::LongFloatD& _do)
 
393
    {
 
394
        Test::LongFloatD di1;
 
395
        di1[999999110] = Ice::Float(-1.1);
 
396
        di1[999999111] = Ice::Float(123123.2);
 
397
        test(_do == di1);
 
398
        test(ro.size() == 4);
 
399
        test(ro.find(999999110) != ro.end());
 
400
        test(ro.find(999999110)->second == Ice::Float(-1.1));
 
401
        test(ro.find(999999120) != ro.end());
 
402
        test(ro.find(999999120)->second == Ice::Float(-100.4));
 
403
        test(ro.find(999999111) != ro.end());
 
404
        test(ro.find(999999111)->second == Ice::Float(123123.2));
 
405
        test(ro.find(999999130) != ro.end());
 
406
        test(ro.find(999999130)->second == Ice::Float(0.5));
 
407
        called();
 
408
    }
 
409
 
 
410
    void opStringStringD(const Test::StringStringD& ro, const Test::StringStringD& _do)
 
411
    {
 
412
        Test::StringStringD di1;
 
413
        di1["foo"] = "abc -1.1";
 
414
        di1["bar"] = "abc 123123.2";
 
415
        test(_do == di1);
 
416
        test(ro.size() == 4);
 
417
        test(ro.find("foo") != ro.end());
 
418
        test(ro.find("foo")->second == "abc -1.1");
 
419
        test(ro.find("FOO") != ro.end());
 
420
        test(ro.find("FOO")->second == "abc -100.4");
 
421
        test(ro.find("bar") != ro.end());
 
422
        test(ro.find("bar")->second == "abc 123123.2");
 
423
        test(ro.find("BAR") != ro.end());
 
424
        test(ro.find("BAR")->second == "abc 0.5");
 
425
        called();
 
426
    }
 
427
 
 
428
    void opStringMyEnumD(const Test::StringMyEnumD& ro, const Test::StringMyEnumD& _do)
 
429
    {
 
430
        Test::StringMyEnumD di1;
 
431
        di1["abc"] = Test::enum1;
 
432
        di1[""] = Test::enum2;
 
433
        test(_do == di1);
 
434
        test(ro.size() == 4);
 
435
        test(ro.find("abc") != ro.end());
 
436
        test(ro.find("abc")->second == Test::enum1);
 
437
        test(ro.find("qwerty") != ro.end());
 
438
        test(ro.find("qwerty")->second == Test::enum3);
 
439
        test(ro.find("") != ro.end());
 
440
        test(ro.find("")->second == Test::enum2);
 
441
        test(ro.find("Hello!!") != ro.end());
 
442
        test(ro.find("Hello!!")->second == Test::enum2);
 
443
        called();
 
444
    }
 
445
 
 
446
    void opMyStructMyEnumD(const Test::MyStructMyEnumD& ro, const Test::MyStructMyEnumD& _do)
 
447
    {
 
448
        Test::MyStruct s11 = { 1, 1 };
 
449
        Test::MyStruct s12 = { 1, 2 };
 
450
        Test::MyStructMyEnumD di1;
 
451
        di1[s11] = Test::enum1;
 
452
        di1[s12] = Test::enum2;
 
453
        test(_do == di1);
 
454
        Test::MyStruct s22 = { 2, 2 };
 
455
        Test::MyStruct s23 = { 2, 3 };
 
456
        test(ro.size() == 4);
 
457
        test(ro.find(s11) != ro.end());
 
458
        test(ro.find(s11)->second == Test::enum1);
 
459
        test(ro.find(s12) != ro.end());
 
460
        test(ro.find(s12)->second == Test::enum2);
 
461
        test(ro.find(s22) != ro.end());
 
462
        test(ro.find(s22)->second == Test::enum3);
 
463
        test(ro.find(s23) != ro.end());
 
464
        test(ro.find(s23)->second == Test::enum2);
 
465
        called();
 
466
    }
 
467
 
 
468
    void opIntS(const Test::IntS& r)
 
469
    {
 
470
        for(int j = 0; j < static_cast<int>(r.size()); ++j)
 
471
        {
 
472
            test(r[j] == -j);
 
473
        }
 
474
        called();
 
475
    }
 
476
 
 
477
    void opDoubleMarshaling()
 
478
    {
 
479
        called();
 
480
    }
 
481
 
 
482
    void opDerived()
 
483
    {
 
484
        called();
 
485
    }
 
486
 
 
487
    void exCB(const Ice::Exception& ex)
 
488
    {
 
489
        test(false);
 
490
    }
 
491
 
 
492
private:
 
493
 
 
494
    Ice::CommunicatorPtr _communicator;
 
495
};
 
496
typedef IceUtil::Handle<Callback> CallbackPtr;
 
497
 
 
498
}
 
499
 
 
500
void
 
501
twowaysNewAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p)
 
502
{
 
503
    {
 
504
        CallbackPtr cb = new Callback;
 
505
        Ice::Callback_Object_ice_pingPtr callback = Ice::newCallback_Object_ice_ping(cb,
 
506
                                                                                     &Callback::ping,
 
507
                                                                                     &Callback::exCB);
 
508
        p->begin_ice_ping(callback);
 
509
        cb->check();
 
510
    }
 
511
 
 
512
    {
 
513
        CallbackPtr cb = new Callback;
 
514
        Ice::Callback_Object_ice_isAPtr callback = Ice::newCallback_Object_ice_isA(cb,
 
515
                                                                                   &Callback::isA,
 
516
                                                                                   &Callback::exCB);
 
517
        p->begin_ice_isA(Test::MyClass::ice_staticId(), callback);
 
518
        cb->check();
 
519
    }
 
520
    
 
521
    {
 
522
        CallbackPtr cb = new Callback;
 
523
        Ice::Callback_Object_ice_idPtr callback = Ice::newCallback_Object_ice_id(cb,
 
524
                                                                                 &Callback::id,
 
525
                                                                                 &Callback::exCB);
 
526
        p->begin_ice_id(callback);
 
527
        cb->check();
 
528
    }
 
529
    
 
530
    {
 
531
        CallbackPtr cb = new Callback;
 
532
        Ice::Callback_Object_ice_idsPtr callback = Ice::newCallback_Object_ice_ids(cb,
 
533
                                                                                   &Callback::ids,
 
534
                                                                                   &Callback::exCB);
 
535
        p->begin_ice_ids(callback);
 
536
        cb->check();
 
537
    }
 
538
 
 
539
    {
 
540
        CallbackPtr cb = new Callback;
 
541
        Test::Callback_MyClass_opVoidPtr callback = Test::newCallback_MyClass_opVoid(cb,
 
542
                                                                                     &Callback::opVoid,
 
543
                                                                                     &Callback::exCB);
 
544
        p->begin_opVoid(callback);
 
545
        cb->check();
 
546
    }
 
547
    
 
548
    {
 
549
        Ice::Double d = 1278312346.0 / 13.0;
 
550
        Test::DoubleS ds(5, d);
 
551
        CallbackPtr cb = new Callback;
 
552
        Test::Callback_MyClass_opBytePtr callback = Test::newCallback_MyClass_opByte(cb,
 
553
                                                                                     &Callback::opByte,
 
554
                                                                                     &Callback::exCB);
 
555
        p->begin_opByte(Ice::Byte(0xff), Ice::Byte(0x0f), callback);
 
556
        cb->check();
 
557
    }
 
558
    
 
559
 
 
560
    {
 
561
        CallbackPtr cb = new Callback;
 
562
        Test::Callback_MyClass_opVoidPtr callback = Test::newCallback_MyClass_opVoid(cb,
 
563
                                                                                     &Callback::opVoid,
 
564
                                                                                     &Callback::exCB);
 
565
        p->begin_opVoid(callback);
 
566
        cb->check();
 
567
    }
 
568
 
 
569
    {
 
570
        CallbackPtr cb = new Callback;
 
571
        Test::Callback_MyClass_opBoolPtr callback = Test::newCallback_MyClass_opBool(cb,
 
572
                                                                                     &Callback::opBool,
 
573
                                                                                     &Callback::exCB);
 
574
        p->begin_opBool(true, false, callback);
 
575
        cb->check();
 
576
    }
 
577
 
 
578
    {
 
579
        CallbackPtr cb = new Callback;
 
580
        Test::Callback_MyClass_opShortIntLongPtr callback = 
 
581
            Test::newCallback_MyClass_opShortIntLong(cb, &Callback::opShortIntLong, &Callback::exCB);
 
582
        p->begin_opShortIntLong(10, 11, 12, callback);
 
583
        cb->check();
 
584
    }
 
585
 
 
586
    {
 
587
        CallbackPtr cb = new Callback;
 
588
        Test::Callback_MyClass_opFloatDoublePtr callback = 
 
589
            Test::newCallback_MyClass_opFloatDouble(cb, &Callback::opFloatDouble, &Callback::exCB);
 
590
        p->begin_opFloatDouble(Ice::Float(3.14), Ice::Double(1.1E10), callback);
 
591
        cb->check();
 
592
    }
 
593
 
 
594
    {
 
595
        CallbackPtr cb = new Callback;
 
596
        Test::Callback_MyClass_opStringPtr callback = Test::newCallback_MyClass_opString(cb,
 
597
                                                                                         &Callback::opString,
 
598
                                                                                         &Callback::exCB);
 
599
        p->begin_opString("hello", "world", callback);
 
600
        cb->check();
 
601
    }
 
602
 
 
603
    {
 
604
        CallbackPtr cb = new Callback;
 
605
        Test::Callback_MyClass_opMyEnumPtr callback = Test::newCallback_MyClass_opMyEnum(cb,
 
606
                                                                                         &Callback::opMyEnum,
 
607
                                                                                         &Callback::exCB);
 
608
        p->begin_opMyEnum(Test::enum2, callback);
 
609
        cb->check();
 
610
    }
 
611
 
 
612
    {
 
613
        CallbackPtr cb = new Callback(communicator);
 
614
        Test::Callback_MyClass_opMyClassPtr callback = Test::newCallback_MyClass_opMyClass(cb,
 
615
                                                                                           &Callback::opMyClass,
 
616
                                                                                           &Callback::exCB);
 
617
        p->begin_opMyClass(p, callback);
 
618
        cb->check();
 
619
    }
 
620
 
 
621
    {
 
622
        Test::Structure si1;
 
623
        si1.p = p;
 
624
        si1.e = Test::enum3;
 
625
        si1.s.s = "abc";
 
626
        Test::Structure si2;
 
627
        si2.p = 0;
 
628
        si2.e = Test::enum2;
 
629
        si2.s.s = "def";
 
630
        
 
631
        CallbackPtr cb = new Callback(communicator);
 
632
        Test::Callback_MyClass_opStructPtr callback = Test::newCallback_MyClass_opStruct(cb,
 
633
                                                                                         &Callback::opStruct,
 
634
                                                                                         &Callback::exCB);
 
635
        p->begin_opStruct(si1, si2, callback);
 
636
        cb->check();
 
637
    }
 
638
 
 
639
    {
 
640
        Test::ByteS bsi1;
 
641
        Test::ByteS bsi2;
 
642
 
 
643
        bsi1.push_back(Ice::Byte(0x01));
 
644
        bsi1.push_back(Ice::Byte(0x11));
 
645
        bsi1.push_back(Ice::Byte(0x12));
 
646
        bsi1.push_back(Ice::Byte(0x22));
 
647
 
 
648
        bsi2.push_back(Ice::Byte(0xf1));
 
649
        bsi2.push_back(Ice::Byte(0xf2));
 
650
        bsi2.push_back(Ice::Byte(0xf3));
 
651
        bsi2.push_back(Ice::Byte(0xf4));
 
652
 
 
653
        CallbackPtr cb = new Callback;
 
654
        Test::Callback_MyClass_opByteSPtr callback = Test::newCallback_MyClass_opByteS(cb,
 
655
                                                                                       &Callback::opByteS,
 
656
                                                                                       &Callback::exCB);
 
657
        p->begin_opByteS(bsi1, bsi2, callback);
 
658
        cb->check();
 
659
    }
 
660
 
 
661
    {
 
662
        Test::BoolS bsi1;
 
663
        Test::BoolS bsi2;
 
664
 
 
665
        bsi1.push_back(true);
 
666
        bsi1.push_back(true);
 
667
        bsi1.push_back(false);
 
668
 
 
669
        bsi2.push_back(false);
 
670
 
 
671
        CallbackPtr cb = new Callback;
 
672
        Test::Callback_MyClass_opBoolSPtr callback = Test::newCallback_MyClass_opBoolS(cb,
 
673
                                                                                       &Callback::opBoolS,
 
674
                                                                                       &Callback::exCB);
 
675
        p->begin_opBoolS(bsi1, bsi2, callback);
 
676
        cb->check();
 
677
    }
 
678
 
 
679
    {
 
680
        Test::ShortS ssi;
 
681
        Test::IntS isi;
 
682
        Test::LongS lsi;
 
683
 
 
684
        ssi.push_back(1);
 
685
        ssi.push_back(2);
 
686
        ssi.push_back(3);
 
687
 
 
688
        isi.push_back(5);
 
689
        isi.push_back(6);
 
690
        isi.push_back(7);
 
691
        isi.push_back(8);
 
692
 
 
693
        lsi.push_back(10);
 
694
        lsi.push_back(30);
 
695
        lsi.push_back(20);
 
696
 
 
697
        CallbackPtr cb = new Callback;
 
698
        Test::Callback_MyClass_opShortIntLongSPtr callback = 
 
699
            Test::newCallback_MyClass_opShortIntLongS(cb, &Callback::opShortIntLongS, &Callback::exCB);
 
700
        p->begin_opShortIntLongS(ssi, isi, lsi, callback);
 
701
        cb->check();
 
702
    }
 
703
 
 
704
    {
 
705
        Test::FloatS fsi;
 
706
        Test::DoubleS dsi;
 
707
 
 
708
        fsi.push_back(Ice::Float(3.14));
 
709
        fsi.push_back(Ice::Float(1.11));
 
710
 
 
711
        dsi.push_back(Ice::Double(1.1E10));
 
712
        dsi.push_back(Ice::Double(1.2E10));
 
713
        dsi.push_back(Ice::Double(1.3E10));
 
714
 
 
715
        CallbackPtr cb = new Callback;
 
716
        Test::Callback_MyClass_opFloatDoubleSPtr callback = 
 
717
            Test::newCallback_MyClass_opFloatDoubleS(cb, &Callback::opFloatDoubleS, &Callback::exCB);
 
718
        p->begin_opFloatDoubleS(fsi, dsi, callback);
 
719
        cb->check();
 
720
    }
 
721
 
 
722
    {
 
723
        Test::StringS ssi1;
 
724
        Test::StringS ssi2;
 
725
 
 
726
        ssi1.push_back("abc");
 
727
        ssi1.push_back("de");
 
728
        ssi1.push_back("fghi");
 
729
 
 
730
        ssi2.push_back("xyz");
 
731
 
 
732
        CallbackPtr cb = new Callback;
 
733
        Test::Callback_MyClass_opStringSPtr callback = Test::newCallback_MyClass_opStringS(cb,
 
734
                                                                                           &Callback::opStringS,
 
735
                                                                                           &Callback::exCB);
 
736
        p->begin_opStringS(ssi1, ssi2, callback);
 
737
        cb->check();
 
738
    }
 
739
 
 
740
    {
 
741
        Test::ByteSS bsi1;
 
742
        bsi1.resize(2);
 
743
        Test::ByteSS bsi2;
 
744
        bsi2.resize(2);
 
745
 
 
746
        bsi1[0].push_back(Ice::Byte(0x01));
 
747
        bsi1[0].push_back(Ice::Byte(0x11));
 
748
        bsi1[0].push_back(Ice::Byte(0x12));
 
749
        bsi1[1].push_back(Ice::Byte(0xff));
 
750
 
 
751
        bsi2[0].push_back(Ice::Byte(0x0e));
 
752
        bsi2[1].push_back(Ice::Byte(0xf2));
 
753
        bsi2[1].push_back(Ice::Byte(0xf1));
 
754
 
 
755
        CallbackPtr cb = new Callback;
 
756
        Test::Callback_MyClass_opByteSSPtr callback = Test::newCallback_MyClass_opByteSS(cb,
 
757
                                                                                         &Callback::opByteSS,
 
758
                                                                                         &Callback::exCB);
 
759
        p->begin_opByteSS(bsi1, bsi2, callback);
 
760
        cb->check();
 
761
    }
 
762
 
 
763
    {
 
764
        Test::FloatSS fsi;
 
765
        fsi.resize(3);
 
766
        Test::DoubleSS dsi;
 
767
        dsi.resize(1);
 
768
 
 
769
        fsi[0].push_back(Ice::Float(3.14));
 
770
        fsi[1].push_back(Ice::Float(1.11));
 
771
 
 
772
        dsi[0].push_back(Ice::Double(1.1E10));
 
773
        dsi[0].push_back(Ice::Double(1.2E10));
 
774
        dsi[0].push_back(Ice::Double(1.3E10));
 
775
 
 
776
        CallbackPtr cb = new Callback;
 
777
        Test::Callback_MyClass_opFloatDoubleSSPtr callback = 
 
778
            Test::newCallback_MyClass_opFloatDoubleSS(cb, &Callback::opFloatDoubleSS, &Callback::exCB);
 
779
        p->begin_opFloatDoubleSS(fsi, dsi, callback);
 
780
        cb->check();
 
781
    }
 
782
 
 
783
    {
 
784
        Test::StringSS ssi1;
 
785
        ssi1.resize(2);
 
786
        Test::StringSS ssi2;
 
787
        ssi2.resize(3);
 
788
 
 
789
        ssi1[0].push_back("abc");
 
790
        ssi1[1].push_back("de");
 
791
        ssi1[1].push_back("fghi");
 
792
 
 
793
        ssi2[2].push_back("xyz");
 
794
 
 
795
        CallbackPtr cb = new Callback;
 
796
        Test::Callback_MyClass_opStringSSPtr callback = 
 
797
            Test::newCallback_MyClass_opStringSS(cb, &Callback::opStringSS, &Callback::exCB);
 
798
        p->begin_opStringSS(ssi1, ssi2, callback);
 
799
        cb->check();
 
800
    }
 
801
 
 
802
    {
 
803
        Test::ByteBoolD di1;
 
804
        di1[10] = true;
 
805
        di1[100] = false;
 
806
        Test::ByteBoolD di2;
 
807
        di2[10] = true;
 
808
        di2[11] = false;
 
809
        di2[101] = true;
 
810
 
 
811
        CallbackPtr cb = new Callback;
 
812
        Test::Callback_MyClass_opByteBoolDPtr callback = 
 
813
            Test::newCallback_MyClass_opByteBoolD(cb, &Callback::opByteBoolD, &Callback::exCB);
 
814
        p->begin_opByteBoolD(di1, di2, callback);
 
815
        cb->check();
 
816
    }
 
817
 
 
818
    {
 
819
        Test::ShortIntD di1;
 
820
        di1[110] = -1;
 
821
        di1[1100] = 123123;
 
822
        Test::ShortIntD di2;
 
823
        di2[110] = -1;
 
824
        di2[111] = -100;
 
825
        di2[1101] = 0;
 
826
 
 
827
        CallbackPtr cb = new Callback;
 
828
        Test::Callback_MyClass_opShortIntDPtr callback = 
 
829
            Test::newCallback_MyClass_opShortIntD(cb, &Callback::opShortIntD, &Callback::exCB);
 
830
        p->begin_opShortIntD(di1, di2, callback);
 
831
        cb->check();
 
832
    }
 
833
 
 
834
    {
 
835
        Test::LongFloatD di1;
 
836
        di1[999999110] = Ice::Float(-1.1);
 
837
        di1[999999111] = Ice::Float(123123.2);
 
838
        Test::LongFloatD di2;
 
839
        di2[999999110] = Ice::Float(-1.1);
 
840
        di2[999999120] = Ice::Float(-100.4);
 
841
        di2[999999130] = Ice::Float(0.5);
 
842
 
 
843
        CallbackPtr cb = new Callback;
 
844
        Test::Callback_MyClass_opLongFloatDPtr callback = 
 
845
            Test::newCallback_MyClass_opLongFloatD(cb, &Callback::opLongFloatD, &Callback::exCB);
 
846
        p->begin_opLongFloatD(di1, di2, callback);
 
847
        cb->check();
 
848
    }
 
849
 
 
850
    {
 
851
        Test::StringStringD di1;
 
852
        di1["foo"] = "abc -1.1";
 
853
        di1["bar"] = "abc 123123.2";
 
854
        Test::StringStringD di2;
 
855
        di2["foo"] = "abc -1.1";
 
856
        di2["FOO"] = "abc -100.4";
 
857
        di2["BAR"] = "abc 0.5";
 
858
 
 
859
        CallbackPtr cb = new Callback;
 
860
        Test::Callback_MyClass_opStringStringDPtr callback = 
 
861
            Test::newCallback_MyClass_opStringStringD(cb, &Callback::opStringStringD, &Callback::exCB);
 
862
        p->begin_opStringStringD(di1, di2, callback);
 
863
        cb->check();
 
864
    }
 
865
 
 
866
    {
 
867
        Test::StringMyEnumD di1;
 
868
        di1["abc"] = Test::enum1;
 
869
        di1[""] = Test::enum2;
 
870
        Test::StringMyEnumD di2;
 
871
        di2["abc"] = Test::enum1;
 
872
        di2["qwerty"] = Test::enum3;
 
873
        di2["Hello!!"] = Test::enum2;
 
874
 
 
875
        CallbackPtr cb = new Callback;
 
876
        Test::Callback_MyClass_opStringMyEnumDPtr callback = 
 
877
            Test::newCallback_MyClass_opStringMyEnumD(cb, &Callback::opStringMyEnumD, &Callback::exCB);
 
878
        p->begin_opStringMyEnumD(di1, di2, callback);
 
879
        cb->check();
 
880
    }
 
881
 
 
882
    {
 
883
        Test::MyStruct s11 = { 1, 1 };
 
884
        Test::MyStruct s12 = { 1, 2 };
 
885
        Test::MyStructMyEnumD di1;
 
886
        di1[s11] = Test::enum1;
 
887
        di1[s12] = Test::enum2;
 
888
 
 
889
        Test::MyStruct s22 = { 2, 2 };
 
890
        Test::MyStruct s23 = { 2, 3 };
 
891
        Test::MyStructMyEnumD di2;
 
892
        di2[s11] = Test::enum1;
 
893
        di2[s22] = Test::enum3;
 
894
        di2[s23] = Test::enum2;
 
895
 
 
896
        CallbackPtr cb = new Callback;
 
897
        Test::Callback_MyClass_opMyStructMyEnumDPtr callback = 
 
898
            Test::newCallback_MyClass_opMyStructMyEnumD(cb, &Callback::opMyStructMyEnumD, &Callback::exCB);
 
899
        p->begin_opMyStructMyEnumD(di1, di2, callback);
 
900
        cb->check();
 
901
    }
 
902
 
 
903
    {
 
904
        const int lengths[] = { 0, 1, 2, 126, 127, 128, 129, 253, 254, 255, 256, 257, 1000 };
 
905
 
 
906
        for(unsigned int l = 0; l != sizeof(lengths) / sizeof(*lengths); ++l)
 
907
        {
 
908
            Test::IntS s;
 
909
            for(int i = 0; i < lengths[l]; ++i)
 
910
            {
 
911
                s.push_back(i);
 
912
            }
 
913
            CallbackPtr cb = new Callback;
 
914
            Test::Callback_MyClass_opIntSPtr callback = 
 
915
                Test::newCallback_MyClass_opIntS(cb, &Callback::opIntS, &Callback::exCB);
 
916
            p->begin_opIntS(s, callback);
 
917
            cb->check();
 
918
        }
 
919
    }
 
920
 
 
921
    {
 
922
        Test::StringStringD ctx;
 
923
        ctx["one"] = "ONE";
 
924
        ctx["two"] = "TWO";
 
925
        ctx["three"] = "THREE";
 
926
        {
 
927
            test(p->ice_getContext().empty());
 
928
            Ice::AsyncResultPtr r = p->begin_opContext();
 
929
            Ice::Context c = p->end_opContext(r);
 
930
            test(c != ctx);
 
931
        }
 
932
        {
 
933
            test(p->ice_getContext().empty());
 
934
            Ice::AsyncResultPtr r = p->begin_opContext(ctx);
 
935
            Ice::Context c = p->end_opContext(r);
 
936
            test(c == ctx);
 
937
        }
 
938
        Test::MyClassPrx p2 = Test::MyClassPrx::checkedCast(p->ice_context(ctx));
 
939
        test(p2->ice_getContext() == ctx);
 
940
        {
 
941
            Ice::AsyncResultPtr r = p2->begin_opContext();
 
942
            Ice::Context c = p2->end_opContext(r);
 
943
            test(c == ctx);
 
944
        }
 
945
        {
 
946
            Test::MyClassPrx p2 = Test::MyClassPrx::checkedCast(p->ice_context(ctx));
 
947
            Ice::AsyncResultPtr r = p2->begin_opContext(ctx);
 
948
            Ice::Context c = p2->end_opContext(r);
 
949
            test(c == ctx);
 
950
        }
 
951
 
 
952
        {
 
953
            //
 
954
            // Test implicit context propagation
 
955
            //
 
956
            
 
957
            string impls[] = {"Shared", "PerThread"};
 
958
            for(int i = 0; i < 2; i++)
 
959
            {
 
960
                Ice::InitializationData initData;
 
961
                initData.properties = communicator->getProperties()->clone();
 
962
                initData.properties->setProperty("Ice.ImplicitContext", impls[i]);
 
963
                
 
964
                Ice::CommunicatorPtr ic = Ice::initialize(initData);
 
965
 
 
966
                Ice::Context ctx;
 
967
                ctx["one"] = "ONE";
 
968
                ctx["two"] = "TWO";
 
969
                ctx["three"] = "THREE";
 
970
 
 
971
 
 
972
                Test::MyClassPrx p = Test::MyClassPrx::uncheckedCast(
 
973
                    ic->stringToProxy("test:default -p 12010"));
 
974
                
 
975
                
 
976
                ic->getImplicitContext()->setContext(ctx);
 
977
                test(ic->getImplicitContext()->getContext() == ctx);
 
978
                {
 
979
                    Ice::AsyncResultPtr r = p->begin_opContext();
 
980
                    Ice::Context c = p->end_opContext(r);
 
981
                    test(c == ctx);
 
982
                }
 
983
 
 
984
                ic->getImplicitContext()->put("zero", "ZERO");
 
985
          
 
986
                ctx = ic->getImplicitContext()->getContext();
 
987
                {
 
988
                    Ice::AsyncResultPtr r = p->begin_opContext();
 
989
                    Ice::Context c = p->end_opContext(r);
 
990
                    test(c == ctx);
 
991
                }
 
992
                
 
993
                Ice::Context prxContext;
 
994
                prxContext["one"] = "UN";
 
995
                prxContext["four"] = "QUATRE";
 
996
                
 
997
                Ice::Context combined = prxContext;
 
998
                combined.insert(ctx.begin(), ctx.end());
 
999
                test(combined["one"] == "UN");
 
1000
                
 
1001
                p = Test::MyClassPrx::uncheckedCast(p->ice_context(prxContext));
 
1002
                
 
1003
                ic->getImplicitContext()->setContext(Ice::Context());
 
1004
                {
 
1005
                    Ice::AsyncResultPtr r = p->begin_opContext();
 
1006
                    Ice::Context c = p->end_opContext(r);
 
1007
                    test(c == prxContext);
 
1008
                }
 
1009
 
 
1010
                ic->getImplicitContext()->setContext(ctx);
 
1011
                {
 
1012
                    Ice::AsyncResultPtr r = p->begin_opContext();
 
1013
                    Ice::Context c = p->end_opContext(r);
 
1014
                    test(c == combined);
 
1015
                }
 
1016
 
 
1017
                ic->getImplicitContext()->setContext(Ice::Context());
 
1018
                ic->destroy();
 
1019
            }
 
1020
        }
 
1021
    }
 
1022
 
 
1023
    {
 
1024
        Ice::Double d = 1278312346.0 / 13.0;
 
1025
        Test::DoubleS ds(5, d);
 
1026
        CallbackPtr cb = new Callback;
 
1027
        Test::Callback_MyClass_opDoubleMarshalingPtr callback = 
 
1028
            Test::newCallback_MyClass_opDoubleMarshaling(cb, &Callback::opDoubleMarshaling, &Callback::exCB);
 
1029
        p->begin_opDoubleMarshaling(d, ds, callback);
 
1030
        cb->check();
 
1031
    }
 
1032
 
 
1033
    {
 
1034
        Test::MyDerivedClassPrx derived = Test::MyDerivedClassPrx::checkedCast(p);
 
1035
        test(derived);
 
1036
        CallbackPtr cb = new Callback;
 
1037
        Test::Callback_MyDerivedClass_opDerivedPtr callback = 
 
1038
            Test::newCallback_MyDerivedClass_opDerived(cb, &Callback::opDerived, &Callback::exCB);
 
1039
        derived->begin_opDerived(callback);
 
1040
        cb->check();
 
1041
    }
 
1042
}