1 //
2 // Copyright (c) ZeroC, Inc. All rights reserved.
3 //
4
5 #include <Ice/Ice.h>
6 #include <TestHelper.h>
7 #include <TestI.h>
8
9 using namespace std;
10 using namespace Test;
11
12 void
allTests(Test::TestHelper * helper)13 allTests(Test::TestHelper* helper)
14 {
15 Ice::CommunicatorPtr communicator = helper->communicator();
16 Ice::ObjectAdapterPtr oa = communicator->createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost");
17 oa->activate();
18
19 Ice::ObjectPtr servant = ICE_MAKE_SHARED(MyObjectI);
20
21 //
22 // Register default servant with category "foo"
23 //
24 oa->addDefaultServant(servant, "foo");
25
26 //
27 // Start test
28 //
29 cout << "testing single category... " << flush;
30
31 Ice::ObjectPtr r = oa->findDefaultServant("foo");
32 test(r == servant);
33
34 r = oa->findDefaultServant("bar");
35 test(r == 0);
36
37 Ice::Identity identity;
38 identity.category = "foo";
39
40 string names[] = { "foo", "bar", "x", "y", "abcdefg" };
41
42 int idx;
43
44 for(idx = 0; idx < 5; ++idx)
45 {
46 identity.name = names[idx];
47 MyObjectPrxPtr prx = ICE_UNCHECKED_CAST(MyObjectPrx, oa->createProxy(identity));
48 prx->ice_ping();
49 test(prx->getName() == names[idx]);
50 }
51
52 identity.name = "ObjectNotExist";
53 MyObjectPrxPtr prx = ICE_UNCHECKED_CAST(MyObjectPrx, oa->createProxy(identity));
54 try
55 {
56 prx->ice_ping();
57 test(false);
58 }
59 catch(const Ice::ObjectNotExistException&)
60 {
61 // Expected
62 }
63
64 try
65 {
66 prx->getName();
67 test(false);
68 }
69 catch(const Ice::ObjectNotExistException&)
70 {
71 // Expected
72 }
73
74 identity.name = "FacetNotExist";
75 prx = ICE_UNCHECKED_CAST(MyObjectPrx, oa->createProxy(identity));
76 try
77 {
78 prx->ice_ping();
79 test(false);
80 }
81 catch(const Ice::FacetNotExistException&)
82 {
83 // Expected
84 }
85
86 try
87 {
88 prx->getName();
89 test(false);
90 }
91 catch(const Ice::FacetNotExistException&)
92 {
93 // Expected
94 }
95
96 identity.category = "bar";
97 for(idx = 0; idx < 5; idx++)
98 {
99 identity.name = names[idx];
100 prx = ICE_UNCHECKED_CAST(MyObjectPrx, oa->createProxy(identity));
101
102 try
103 {
104 prx->ice_ping();
105 test(false);
106 }
107 catch(const Ice::ObjectNotExistException&)
108 {
109 // Expected
110 }
111
112 try
113 {
114 prx->getName();
115 test(false);
116 }
117 catch(const Ice::ObjectNotExistException&)
118 {
119 // Expected
120 }
121 }
122
123 oa->removeDefaultServant("foo");
124 identity.category = "foo";
125 prx = ICE_UNCHECKED_CAST(MyObjectPrx, oa->createProxy(identity));
126 try
127 {
128 prx->ice_ping();
129 }
130 catch(const Ice::ObjectNotExistException&)
131 {
132 // Expected
133 }
134
135 cout << "ok" << endl;
136
137 cout << "testing default category... " << flush;
138
139 oa->addDefaultServant(servant, "");
140
141 r = oa->findDefaultServant("bar");
142 test(r == 0);
143
144 r = oa->findDefaultServant("");
145 test(r == servant);
146
147 for(idx = 0; idx < 5; ++idx)
148 {
149 identity.name = names[idx];
150 prx = ICE_UNCHECKED_CAST(MyObjectPrx, oa->createProxy(identity));
151 prx->ice_ping();
152 test(prx->getName() == names[idx]);
153 }
154
155 cout << "ok" << endl;
156 }
157