ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / test / Ice / facets / AllTests.cpp
blob8af13cd7007ece6e4ac37d8da0511011d7988e78
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 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 // **********************************************************************
10 #include <Ice/Ice.h>
11 #include <IceUtil/IceUtil.h>
12 #include <TestCommon.h>
13 #include <Test.h>
15 using namespace std;
16 using namespace Test;
18 class EmptyI : virtual public Empty
22 GPrx
23 allTests(const Ice::CommunicatorPtr& communicator)
25 cout << "testing Ice.Admin.Facets property... " << flush;
26 test(communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets").empty());
27 communicator->getProperties()->setProperty("Ice.Admin.Facets", "foobar");
28 Ice::StringSeq facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
29 test(facetFilter.size() == 1 && facetFilter[0] == "foobar");
30 communicator->getProperties()->setProperty("Ice.Admin.Facets", "foo\\'bar");
31 facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
32 test(facetFilter.size() == 1 && facetFilter[0] == "foo'bar");
33 communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
34 facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
35 test(facetFilter.size() == 3 && facetFilter[0] == "foo bar" && facetFilter[1] == "toto" &&
36 facetFilter[2] == "titi");
37 communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
38 facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
39 test(facetFilter.size() == 2 && facetFilter[0] == "foo bar' toto" && facetFilter[1] == "titi");
40 // communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
41 // facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
42 // test(facetFilter.size() == 0);
43 communicator->getProperties()->setProperty("Ice.Admin.Facets", "");
44 cout << "ok" << endl;
46 cout << "testing facet registration exceptions... " << flush;
47 communicator->getProperties()->setProperty("FacetExceptionTestAdapter.Endpoints", "default");
48 Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("FacetExceptionTestAdapter");
49 Ice::ObjectPtr obj = new EmptyI;
50 adapter->add(obj, communicator->stringToIdentity("d"));
51 adapter->addFacet(obj, communicator->stringToIdentity("d"), "facetABCD");
52 try
54 adapter->addFacet(obj, communicator->stringToIdentity("d"), "facetABCD");
55 test(false);
57 catch(Ice::AlreadyRegisteredException&)
60 adapter->removeFacet(communicator->stringToIdentity("d"), "facetABCD");
61 try
63 adapter->removeFacet(communicator->stringToIdentity("d"), "facetABCD");
64 test(false);
66 catch(Ice::NotRegisteredException&)
69 cout << "ok" << endl;
71 cout << "testing removeAllFacets... " << flush;
72 Ice::ObjectPtr obj1 = new EmptyI;
73 Ice::ObjectPtr obj2 = new EmptyI;
74 adapter->addFacet(obj1, communicator->stringToIdentity("id1"), "f1");
75 adapter->addFacet(obj2, communicator->stringToIdentity("id1"), "f2");
76 Ice::ObjectPtr obj3 = new EmptyI;
77 adapter->addFacet(obj1, communicator->stringToIdentity("id2"), "f1");
78 adapter->addFacet(obj2, communicator->stringToIdentity("id2"), "f2");
79 adapter->addFacet(obj3, communicator->stringToIdentity("id2"), "");
80 Ice::FacetMap fm = adapter->removeAllFacets(communicator->stringToIdentity("id1"));
81 test(fm.size() == 2);
82 test(fm["f1"] == obj1);
83 test(fm["f2"] == obj2);
84 try
86 adapter->removeAllFacets(communicator->stringToIdentity("id1"));
87 test(false);
89 catch(Ice::NotRegisteredException&)
92 fm = adapter->removeAllFacets(communicator->stringToIdentity("id2"));
93 test(fm.size() == 3);
94 test(fm["f1"] == obj1);
95 test(fm["f2"] == obj2);
96 test(fm[""] == obj3);
97 cout << "ok" << endl;
99 adapter->deactivate();
101 cout << "testing stringToProxy... " << flush;
102 string ref = "d:default -p 12010";
103 Ice::ObjectPrx db = communicator->stringToProxy(ref);
104 test(db);
105 cout << "ok" << endl;
107 cout << "testing unchecked cast... " << flush;
108 Ice::ObjectPrx prx = Ice::ObjectPrx::uncheckedCast(db);
109 test(prx->ice_getFacet().empty());
110 prx = Ice::ObjectPrx::uncheckedCast(db, "facetABCD");
111 test(prx->ice_getFacet() == "facetABCD");
112 Ice::ObjectPrx prx2 = Ice::ObjectPrx::uncheckedCast(prx);
113 test(prx2->ice_getFacet() == "facetABCD");
114 Ice::ObjectPrx prx3 = Ice::ObjectPrx::uncheckedCast(prx, "");
115 test(prx3->ice_getFacet().empty());
116 DPrx d = Test::DPrx::uncheckedCast(db);
117 test(d->ice_getFacet().empty());
118 DPrx df = Test::DPrx::uncheckedCast(db, "facetABCD");
119 test(df->ice_getFacet() == "facetABCD");
120 DPrx df2 = Test::DPrx::uncheckedCast(df);
121 test(df2->ice_getFacet() == "facetABCD");
122 DPrx df3 = Test::DPrx::uncheckedCast(df, "");
123 test(df3->ice_getFacet().empty());
124 cout << "ok" << endl;
126 cout << "testing checked cast... " << flush;
127 prx = Ice::ObjectPrx::checkedCast(db);
128 test(prx->ice_getFacet().empty());
129 prx = Ice::ObjectPrx::checkedCast(db, "facetABCD");
130 test(prx->ice_getFacet() == "facetABCD");
131 prx2 = Ice::ObjectPrx::checkedCast(prx);
132 test(prx2->ice_getFacet() == "facetABCD");
133 prx3 = Ice::ObjectPrx::checkedCast(prx, "");
134 test(prx3->ice_getFacet().empty());
135 d = Test::DPrx::checkedCast(db);
136 test(d->ice_getFacet().empty());
137 df = Test::DPrx::checkedCast(db, "facetABCD");
138 test(df->ice_getFacet() == "facetABCD");
139 df2 = Test::DPrx::checkedCast(df);
140 test(df2->ice_getFacet() == "facetABCD");
141 df3 = Test::DPrx::checkedCast(df, "");
142 test(df3->ice_getFacet().empty());
143 cout << "ok" << endl;
145 cout << "testing non-facets A, B, C, and D... " << flush;
146 d = DPrx::checkedCast(db);
147 test(d);
148 test(d == db);
149 test(d->callA() == "A");
150 test(d->callB() == "B");
151 test(d->callC() == "C");
152 test(d->callD() == "D");
153 cout << "ok" << endl;
155 cout << "testing facets A, B, C, and D... " << flush;
156 df = DPrx::checkedCast(d, "facetABCD");
157 test(df);
158 test(df->callA() == "A");
159 test(df->callB() == "B");
160 test(df->callC() == "C");
161 test(df->callD() == "D");
162 cout << "ok" << endl;
164 cout << "testing facets E and F... " << flush;
165 FPrx ff = FPrx::checkedCast(d, "facetEF");
166 test(ff);
167 test(ff->callE() == "E");
168 test(ff->callF() == "F");
169 cout << "ok" << endl;
171 cout << "testing facet G... " << flush;
172 GPrx gf = GPrx::checkedCast(ff, "facetGH");
173 test(gf);
174 test(gf->callG() == "G");
175 cout << "ok" << endl;
177 cout << "testing whether casting preserves the facet... " << flush;
178 HPrx hf = HPrx::checkedCast(gf);
179 test(hf);
180 test(hf->callG() == "G");
181 test(hf->callH() == "H");
182 cout << "ok" << endl;
184 return gf;