Skip to content

Commit

Permalink
Update checkedCast in Python (#2550)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jul 24, 2024
1 parent 3007323 commit fa4a4b4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
4 changes: 0 additions & 4 deletions python/modules/IcePy/Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1697,10 +1697,6 @@ checkedCastImpl(ProxyObject* p, const string& id, PyObject* facet, PyObject* ctx
AllowThreads allowThreads; // Release Python's global interpreter lock during remote invocations.
b = target->ice_isA(id, (ctx == 0 || ctx == Py_None) ? Ice::noExplicitContext : c);
}
catch (const Ice::FacetNotExistException&)
{
// Ignore.
}
catch (...)
{
setPythonException(current_exception());
Expand Down
60 changes: 44 additions & 16 deletions python/test/Ice/admin/AllTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,18 @@ def allTests(helper, communicator):
com = factory.createCommunicator(props)
obj = com.getAdmin()

proc = Ice.ProcessPrx.checkedCast(obj, "Process")
test(proc is None)
tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
test(tf is None)
try:
Ice.ProcessPrx.checkedCast(obj, "Process")
test(False)
except Ice.FacetNotExistException:
pass

try:
Test.TestFacetPrx.checkedCast(obj, "TestFacet")
test(False)
except Ice.FacetNotExistException:
pass

com.destroy()

#
Expand All @@ -279,10 +287,17 @@ def allTests(helper, communicator):
com = factory.createCommunicator(props)
obj = com.getAdmin()

pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
test(pa is None)
tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
test(tf is None)
try:
Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
test(False)
except Ice.FacetNotExistException:
pass

try:
Test.TestFacetPrx.checkedCast(obj, "TestFacet")
test(False)
except Ice.FacetNotExistException:
pass

com.destroy()

Expand All @@ -297,11 +312,17 @@ def allTests(helper, communicator):
com = factory.createCommunicator(props)
obj = com.getAdmin()

pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
test(pa is None)
try:
Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
test(False)
except Ice.FacetNotExistException:
pass

proc = Ice.ProcessPrx.checkedCast(obj, "Process")
test(proc is None)
try:
Ice.ProcessPrx.checkedCast(obj, "Process")
test(False)
except Ice.FacetNotExistException:
pass

com.destroy()

Expand All @@ -320,8 +341,12 @@ def allTests(helper, communicator):
tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
tf.op()

proc = Ice.ProcessPrx.checkedCast(obj, "Process")
test(proc is None)
try:
Ice.ProcessPrx.checkedCast(obj, "Process")
test(False)
except Ice.FacetNotExistException:
pass

com.destroy()

#
Expand All @@ -335,8 +360,11 @@ def allTests(helper, communicator):
com = factory.createCommunicator(props)
obj = com.getAdmin()

pa = Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
test(pa is None)
try:
Ice.PropertiesAdminPrx.checkedCast(obj, "Properties")
test(False)
except Ice.FacetNotExistException:
pass

tf = Test.TestFacetPrx.checkedCast(obj, "TestFacet")
tf.op()
Expand Down
6 changes: 5 additions & 1 deletion python/test/Ice/facets/AllTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ def allTests(helper, communicator):
test(df2.ice_getFacet() == "facetABCD")
df3 = Test.DPrx.checkedCast(df, "")
test(df3.ice_getFacet() == "")
test(Test.DPrx.checkedCast(df, "bogus") is None)
try:
Test.DPrx.checkedCast(df, "bogus")
test(False)
except Ice.FacetNotExistException:
pass
print("ok")

sys.stdout.write("testing non-facets A, B, C, and D... ")
Expand Down
7 changes: 6 additions & 1 deletion python/test/Ice/proxy/AllTests.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,12 @@ def allTests(helper, communicator, collocated):
test(cl == base)
test(derived == base)
test(cl == derived)
test(Test.MyDerivedClassPrx.checkedCast(cl, "facet") is None)

try:
Test.MyDerivedClassPrx.checkedCast(cl, "facet")
test(False)
except Ice.FacetNotExistException:
pass

loc = Ice.LocatorPrx.checkedCast(base)
test(loc is None)
Expand Down

0 comments on commit fa4a4b4

Please sign in to comment.