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 247 248
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#include <Ice/Ice.h>
#include <IceUtil/IceUtil.h>
#include <TestHelper.h>
#include <Test.h>
using namespace std;
using namespace Test;
class EmptyI : public virtual Empty
{
};
GPrxPtr
allTests(Test::TestHelper* helper)
{
Ice::CommunicatorPtr communicator = helper->communicator();
cout << "testing Ice.Admin.Facets property... " << flush;
test(communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets").empty());
communicator->getProperties()->setProperty("Ice.Admin.Facets", "foobar");
Ice::StringSeq facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.size() == 1 && facetFilter[0] == "foobar");
communicator->getProperties()->setProperty("Ice.Admin.Facets", "foo\\'bar");
facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.size() == 1 && facetFilter[0] == "foo'bar");
communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar' toto 'titi'");
facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.size() == 3 && facetFilter[0] == "foo bar" && facetFilter[1] == "toto" &&
facetFilter[2] == "titi");
communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar\\' toto' 'titi'");
facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
test(facetFilter.size() == 2 && facetFilter[0] == "foo bar' toto" && facetFilter[1] == "titi");
// communicator->getProperties()->setProperty("Ice.Admin.Facets", "'foo bar' 'toto titi");
// facetFilter = communicator->getProperties()->getPropertyAsList("Ice.Admin.Facets");
// test(facetFilter.size() == 0);
communicator->getProperties()->setProperty("Ice.Admin.Facets", "");
cout << "ok" << endl;
cout << "testing facet registration exceptions... " << flush;
string localOAEndpoint;
{
ostringstream ostr;
if(communicator->getProperties()->getProperty("Ice.Default.Protocol") == "bt")
{
ostr << "default -a *";
}
else
{
ostr << "default -h *";
}
localOAEndpoint = ostr.str();
}
communicator->getProperties()->setProperty("FacetExceptionTestAdapter.Endpoints", localOAEndpoint);
if(communicator->getProperties()->getProperty("Ice.Default.Protocol") != "ssl" &&
communicator->getProperties()->getProperty("Ice.Default.Protocol") != "wss")
{
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("FacetExceptionTestAdapter");
Ice::ObjectPtr obj = ICE_MAKE_SHARED(EmptyI);
adapter->add(obj, Ice::stringToIdentity("d"));
adapter->addFacet(obj, Ice::stringToIdentity("d"), "facetABCD");
try
{
adapter->addFacet(obj, Ice::stringToIdentity("d"), "facetABCD");
test(false);
}
catch(const Ice::AlreadyRegisteredException&)
{
}
adapter->removeFacet(Ice::stringToIdentity("d"), "facetABCD");
try
{
adapter->removeFacet(Ice::stringToIdentity("d"), "facetABCD");
test(false);
}
catch(const Ice::NotRegisteredException&)
{
}
cout << "ok" << endl;
cout << "testing removeAllFacets... " << flush;
Ice::ObjectPtr obj1 = ICE_MAKE_SHARED(EmptyI);
Ice::ObjectPtr obj2 = ICE_MAKE_SHARED(EmptyI);
adapter->addFacet(obj1, Ice::stringToIdentity("id1"), "f1");
adapter->addFacet(obj2, Ice::stringToIdentity("id1"), "f2");
Ice::ObjectPtr obj3 = ICE_MAKE_SHARED(EmptyI);
adapter->addFacet(obj1, Ice::stringToIdentity("id2"), "f1");
adapter->addFacet(obj2, Ice::stringToIdentity("id2"), "f2");
adapter->addFacet(obj3, Ice::stringToIdentity("id2"), "");
Ice::FacetMap fm = adapter->removeAllFacets(Ice::stringToIdentity("id1"));
test(fm.size() == 2);
test(fm["f1"] == obj1);
test(fm["f2"] == obj2);
try
{
adapter->removeAllFacets(Ice::stringToIdentity("id1"));
test(false);
}
catch(const Ice::NotRegisteredException&)
{
}
fm = adapter->removeAllFacets(Ice::stringToIdentity("id2"));
test(fm.size() == 3);
test(fm["f1"] == obj1);
test(fm["f2"] == obj2);
test(fm[""] == obj3);
cout << "ok" << endl;
adapter->deactivate();
}
cout << "testing stringToProxy... " << flush;
string ref = "d:" + helper->getTestEndpoint();
Ice::ObjectPrxPtr db = communicator->stringToProxy(ref);
test(db);
cout << "ok" << endl;
cout << "testing unchecked cast... " << flush;
Ice::ObjectPrxPtr prx = ICE_UNCHECKED_CAST(Ice::ObjectPrx, db);
test(prx->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
prx = Ice::uncheckedCast<Ice::ObjectPrx>(db, "facetABCD");
#else
prx = Ice::ObjectPrx::uncheckedCast(db, "facetABCD");
#endif
test(prx->ice_getFacet() == "facetABCD");
Ice::ObjectPrxPtr prx2 = ICE_UNCHECKED_CAST(Ice::ObjectPrx, prx);
test(prx2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
shared_ptr<Ice::ObjectPrx> prx3 = Ice::uncheckedCast<Ice::ObjectPrx>(prx, "");
#else
Ice::ObjectPrx prx3 = Ice::ObjectPrx::uncheckedCast(prx, "");
#endif
test(prx3->ice_getFacet().empty());
DPrxPtr d = ICE_UNCHECKED_CAST(Test::DPrx, db);
test(d->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
shared_ptr<DPrx> df = Ice::uncheckedCast<Test::DPrx>(db, "facetABCD");
#else
DPrx df = Test::DPrx::uncheckedCast(db, "facetABCD");
#endif
test(df->ice_getFacet() == "facetABCD");
DPrxPtr df2 = ICE_UNCHECKED_CAST(Test::DPrx, df);
test(df2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
shared_ptr<DPrx> df3 = Ice::uncheckedCast<Test::DPrx>(df, "");
#else
DPrx df3 = Test::DPrx::uncheckedCast(df, "");
#endif
test(df3->ice_getFacet().empty());
cout << "ok" << endl;
cout << "testing checked cast... " << flush;
prx = ICE_CHECKED_CAST(Ice::ObjectPrx, db);
test(prx->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
prx = Ice::checkedCast<Ice::ObjectPrx>(db, "facetABCD");
#else
prx = Ice::ObjectPrx::checkedCast(db, "facetABCD");
#endif
test(prx->ice_getFacet() == "facetABCD");
prx2 = ICE_CHECKED_CAST(Ice::ObjectPrx, prx);
test(prx2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
prx3 = Ice::checkedCast<Ice::ObjectPrx>(prx, "");
#else
prx3 = Ice::ObjectPrx::checkedCast(prx, "");
#endif
test(prx3->ice_getFacet().empty());
d = ICE_CHECKED_CAST(Test::DPrx, db);
test(d->ice_getFacet().empty());
#ifdef ICE_CPP11_MAPPING
df = Ice::checkedCast<Test::DPrx>(db, "facetABCD");
#else
df = Test::DPrx::checkedCast(db, "facetABCD");
#endif
test(df->ice_getFacet() == "facetABCD");
df2 = ICE_CHECKED_CAST(Test::DPrx, df);
test(df2->ice_getFacet() == "facetABCD");
#ifdef ICE_CPP11_MAPPING
df3 = Ice::checkedCast<Test::DPrx>(df, "");
#else
df3 = Test::DPrx::checkedCast(df, "");
#endif
test(df3->ice_getFacet().empty());
cout << "ok" << endl;
cout << "testing non-facets A, B, C, and D... " << flush;
d = ICE_CHECKED_CAST(DPrx, db);
test(d);
#ifdef ICE_CPP11_MAPPING
test(Ice::targetEqualTo(d, db));
#else
test(d == db);
#endif
test(d->callA() == "A");
test(d->callB() == "B");
test(d->callC() == "C");
test(d->callD() == "D");
cout << "ok" << endl;
cout << "testing facets A, B, C, and D... " << flush;
#ifdef ICE_CPP11_MAPPING
df = Ice::checkedCast<DPrx>(d, "facetABCD");
#else
df = DPrx::checkedCast(d, "facetABCD");
#endif
test(df);
test(df->callA() == "A");
test(df->callB() == "B");
test(df->callC() == "C");
test(df->callD() == "D");
cout << "ok" << endl;
cout << "testing facets E and F... " << flush;
#ifdef ICE_CPP11_MAPPING
auto ff = Ice::checkedCast<FPrx>(d, "facetEF");
#else
FPrx ff = FPrx::checkedCast(d, "facetEF");
#endif
test(ff);
test(ff->callE() == "E");
test(ff->callF() == "F");
cout << "ok" << endl;
cout << "testing facet G... " << flush;
#ifdef ICE_CPP11_MAPPING
auto gf = Ice::checkedCast<GPrx>(ff, "facetGH");
#else
GPrx gf = GPrx::checkedCast(ff, "facetGH");
#endif
test(gf);
test(gf->callG() == "G");
cout << "ok" << endl;
cout << "testing whether casting preserves the facet... " << flush;
HPrxPtr hf = ICE_CHECKED_CAST(HPrx, gf);
test(hf);
test(hf->callG() == "G");
test(hf->callH() == "H");
cout << "ok" << endl;
return gf;
}
|