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
|
// **********************************************************************
//
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <Ice/Ice.h>
#include <IceUtil/IceUtil.h>
#include <TestCommon.h>
#include <Test.h>
using namespace std;
using namespace Test;
class EmptyI : virtual public Empty
{
};
GPrx
allTests(const Ice::CommunicatorPtr& 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;
communicator->getProperties()->setProperty("FacetExceptionTestAdapter.Endpoints", "default");
Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("FacetExceptionTestAdapter");
Ice::ObjectPtr obj = new EmptyI;
adapter->add(obj, communicator->stringToIdentity("d"));
adapter->addFacet(obj, communicator->stringToIdentity("d"), "facetABCD");
try
{
#if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600)
IceUtil::DummyBCC dummy;
#endif
adapter->addFacet(obj, communicator->stringToIdentity("d"), "facetABCD");
test(false);
}
catch(Ice::AlreadyRegisteredException&)
{
}
adapter->removeFacet(communicator->stringToIdentity("d"), "facetABCD");
try
{
#if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600)
IceUtil::DummyBCC dummy;
#endif
adapter->removeFacet(communicator->stringToIdentity("d"), "facetABCD");
test(false);
}
catch(Ice::NotRegisteredException&)
{
}
cout << "ok" << endl;
cout << "testing removeAllFacets... " << flush;
Ice::ObjectPtr obj1 = new EmptyI;
Ice::ObjectPtr obj2 = new EmptyI;
adapter->addFacet(obj1, communicator->stringToIdentity("id1"), "f1");
adapter->addFacet(obj2, communicator->stringToIdentity("id1"), "f2");
Ice::ObjectPtr obj3 = new EmptyI;
adapter->addFacet(obj1, communicator->stringToIdentity("id2"), "f1");
adapter->addFacet(obj2, communicator->stringToIdentity("id2"), "f2");
adapter->addFacet(obj3, communicator->stringToIdentity("id2"), "");
Ice::FacetMap fm = adapter->removeAllFacets(communicator->stringToIdentity("id1"));
test(fm.size() == 2);
test(fm["f1"] == obj1);
test(fm["f2"] == obj2);
try
{
#if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600)
IceUtil::DummyBCC dummy;
#endif
adapter->removeAllFacets(communicator->stringToIdentity("id1"));
test(false);
}
catch(Ice::NotRegisteredException&)
{
}
fm = adapter->removeAllFacets(communicator->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:default -p 12010 -t 10000";
Ice::ObjectPrx db = communicator->stringToProxy(ref);
test(db);
cout << "ok" << endl;
cout << "testing unchecked cast... " << flush;
Ice::ObjectPrx prx = Ice::ObjectPrx::uncheckedCast(db);
test(prx->ice_getFacet().empty());
prx = Ice::ObjectPrx::uncheckedCast(db, "facetABCD");
test(prx->ice_getFacet() == "facetABCD");
Ice::ObjectPrx prx2 = Ice::ObjectPrx::uncheckedCast(prx);
test(prx2->ice_getFacet() == "facetABCD");
Ice::ObjectPrx prx3 = Ice::ObjectPrx::uncheckedCast(prx, "");
test(prx3->ice_getFacet().empty());
DPrx d = Test::DPrx::uncheckedCast(db);
test(d->ice_getFacet().empty());
DPrx df = Test::DPrx::uncheckedCast(db, "facetABCD");
test(df->ice_getFacet() == "facetABCD");
DPrx df2 = Test::DPrx::uncheckedCast(df);
test(df2->ice_getFacet() == "facetABCD");
DPrx df3 = Test::DPrx::uncheckedCast(df, "");
test(df3->ice_getFacet().empty());
cout << "ok" << endl;
cout << "testing checked cast... " << flush;
prx = Ice::ObjectPrx::checkedCast(db);
test(prx->ice_getFacet().empty());
prx = Ice::ObjectPrx::checkedCast(db, "facetABCD");
test(prx->ice_getFacet() == "facetABCD");
prx2 = Ice::ObjectPrx::checkedCast(prx);
test(prx2->ice_getFacet() == "facetABCD");
prx3 = Ice::ObjectPrx::checkedCast(prx, "");
test(prx3->ice_getFacet().empty());
d = Test::DPrx::checkedCast(db);
test(d->ice_getFacet().empty());
df = Test::DPrx::checkedCast(db, "facetABCD");
test(df->ice_getFacet() == "facetABCD");
df2 = Test::DPrx::checkedCast(df);
test(df2->ice_getFacet() == "facetABCD");
df3 = Test::DPrx::checkedCast(df, "");
test(df3->ice_getFacet().empty());
cout << "ok" << endl;
cout << "testing non-facets A, B, C, and D... " << flush;
d = DPrx::checkedCast(db);
test(d);
test(d == db);
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;
df = DPrx::checkedCast(d, "facetABCD");
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;
FPrx ff = FPrx::checkedCast(d, "facetEF");
test(ff);
test(ff->callE() == "E");
test(ff->callF() == "F");
cout << "ok" << endl;
cout << "testing facet G... " << flush;
GPrx gf = GPrx::checkedCast(ff, "facetGH");
test(gf);
test(gf->callG() == "G");
cout << "ok" << endl;
cout << "testing whether casting preserves the facet... " << flush;
HPrx hf = HPrx::checkedCast(gf);
test(hf);
test(hf->callG() == "G");
test(hf->callH() == "H");
cout << "ok" << endl;
return gf;
}
|