gt:             p.begin_op(ctx, new Callback_TestIntf_op()
context: // **********************************************************************
  //
  // Copyright (c) 2003-2011 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.
  //
  // **********************************************************************
  
  package test.Ice.ami;
  
  import java.io.PrintWriter;
  
  import test.Ice.ami.Test.TestIntfPrx;
  import test.Ice.ami.Test.TestIntfPrxHelper;
  import test.Ice.ami.Test.TestIntfControllerPrx;
  import test.Ice.ami.Test.TestIntfControllerPrxHelper;
  import test.Ice.ami.Test.TestIntfException;
  import test.Ice.ami.Test.Callback_TestIntf_op;
  import test.Ice.ami.Test.Callback_TestIntf_opWithResult;
  import test.Ice.ami.Test.Callback_TestIntf_opWithUE;
  import test.Ice.ami.Test.Callback_TestIntf_opWithPayload;
  import test.Util.Application;
  
  public class AllTests
  {
      private static void
      test(boolean b)
      {
          if(!b)
          {
              throw new RuntimeException();
          }
      }
  
      private static class CallbackBase
      {
          CallbackBase()
          {
              _called = false;
          }
  
          public synchronized void check()
          {
              while(!_called)
              {
                  try
                  {
                      wait();
                  }
                  catch(InterruptedException ex)
                  {
                  }
              }
  
              _called = false;
          }
  
          public synchronized void called()
          {
              assert(!_called);
              _called = true;
              notify();
          }
  
          private boolean _called;
      }
  
      static class AsyncCallback extends CallbackBase
      {
          public AsyncCallback()
          {
          }
  
          public void
          isA(Ice.AsyncResult result)
          {
              test(result.getProxy().end_ice_isA(result));
              called();
          }
  
          public void
          ping(Ice.AsyncResult result)
          {
              result.getProxy().end_ice_ping(result);
              called();
          }
  
          public void
          id(Ice.AsyncResult result)
          {
              test(result.getProxy().end_ice_id(result).equals("::Test::TestIntf"));
              called();
          }
  
          public void
          ids(Ice.AsyncResult result)
          {
              test(result.getProxy().end_ice_ids(result).length == 2);
              called();
          }
  
          public void
          op(Ice.AsyncResult result)
          {
              TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result);
              called();
          }
  
          public void
          opWithResult(Ice.AsyncResult result)
          {
              test(TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithResult(result) == 15);
              called();
          }
  
          public void
          opWithUE(Ice.AsyncResult result)
          {
              try
              {
                  TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_opWithUE(result);
                  test(false);
              }
              catch(TestIntfException ex)
              {
                  called();
              }
              catch(Ice.LocalException ex)
              {
                  test(false);
              }
          }
  
          public void
          isAEx(Ice.AsyncResult result)
          {
              try
              {
                  result.getProxy().end_ice_isA(result);
                  test(false);
              }
              catch(Ice.NoEndpointException ex)
              {
                  called();
              }
              catch(Ice.LocalException ex)
              {
                  test(false);
              }
          }
  
          public void
          pingEx(Ice.AsyncResult result)
          {
              try
              {
                  result.getProxy().end_ice_ping(result);
                  test(false);
              }
              catch(Ice.NoEndpointException ex)
              {
                  called();
              }
              catch(Ice.LocalException ex)
              {
                  test(false);
              }
          }
  
          public void
          idEx(Ice.AsyncResult result)
          {
              try
              {
                  result.getProxy().end_ice_id(result);
                  test(false);
              }
              catch(Ice.NoEndpointException ex)
              {
                  called();
              }
              catch(Ice.LocalException ex)
              {
                  test(false);
              }
          }
  
          public void
          idsEx(Ice.AsyncResult result)
          {
              try
              {
                  result.getProxy().end_ice_ids(result);
                  test(false);
              }
              catch(Ice.NoEndpointException ex)
              {
                  called();
              }
              catch(Ice.LocalException ex)
              {
                  test(false);
              }
          }
  
          public void
          opEx(Ice.AsyncResult result)
          {
              try
              {
                  TestIntfPrxHelper.uncheckedCast(result.getProxy()).end_op(result);
                  test(false);
              }
              catch(Ice.NoEndpointException ex)
              {
                  called();
              }
              catch(Ice.LocalException ex)
              {
                  test(false);
              }
          }
      }
  
      static class ResponseCallback extends CallbackBase
      {
          ResponseCallback()
          {
          }
  
          public void
          isA(boolean r)
          {
              test(r);
              called();
          }
  
          public void
          ping()
          {
              called();
          }
  
          public void
          id(String id)
          {
              test(id.equals("::Test::TestIntf"));
              called();
          }
  
          public void
          ids(String[] ids)
          {
              test(ids.length == 2);
              called();
          }
  
          public void
          op()
          {
              called();
          }
  
          public void
          opWithResult(int r)
          {
              test(r == 15);
              called();
          }
  
          public void
          opWithUE(Ice.UserException e)
          {
              try
              {
                  throw e;
              }
              catch(TestIntfException ex)
              {
                  called();
              }
              catch(Ice.UserException ex)
              {
                  test(false);
              }
          }
      }
  
      static class ExceptionCallback extends CallbackBase
      {
          public ExceptionCallback()
          {
          }
  
          public void
          isA(boolean r)
          {
              test(false);
          }
  
          public void
          ping()
          {
              test(false);
          }
  
          public void
          id(String id)
          {
              test(false);
          }
  
          public void
          ids(String[] ids)
          {
              test(false);
          }
  
          public void
          op()
          {
              test(false);
          }
  
          public void
          ex(Ice.LocalException ex)
          {
              test(ex instanceof Ice.NoEndpointException);
              called();
          }
  
          public void
          noEx(Ice.LocalException ex)
          {
              test(false);
          }
      }
  
      static class SentCallback extends CallbackBase
      {
          SentCallback()
          {
              _thread = Thread.currentThread().getId();
          }
  
          public void
          isA(boolean r)
          {
          }
  
          public void
          ping()
          {
          }
  
          public void
          id(String s)
          {
          }
  
          public void
          ids(String[] s)
          {
          }
  
          public void
          opAsync(Ice.AsyncResult r)
          {
          }
  
          public void
          op()
          {
          }
  
          public void
          ex(Ice.LocalException ex)
          {
          }
  
          public void
          sent(Ice.AsyncResult r)
          {
              test(r.sentSynchronously() && _thread == Thread.currentThread().getId() ||
                   !r.sentSynchronously() && _thread != Thread.currentThread().getId());
              called();
          }
  
          public void
          sent(boolean ss)
          {
              test(ss && _thread == Thread.currentThread().getId() ||
                   !ss && _thread != Thread.currentThread().getId());
              called();
          }
  
          long _thread;
      }
  
      static class FlushCallback extends CallbackBase
      {
          FlushCallback()
          {
              _thread = Thread.currentThread().getId();
          }
  
          public void
          completedAsync(Ice.AsyncResult r)
          {
              test(false);
          }
  
          public void
          exception(Ice.LocalException ex)
          {
              test(false);
          }
  
          public void
          sentAsync(Ice.AsyncResult r)
          {
              test((r.sentSynchronously() && _thread == Thread.currentThread().getId()) ||
                   (!r.sentSynchronously() && _thread != Thread.currentThread().getId()));
              called();
          }
  
          public void
          sent(boolean sentSynchronously)
          {
              test((sentSynchronously && _thread == Thread.currentThread().getId()) ||
                   (!sentSynchronously && _thread != Thread.currentThread().getId()));
              called();
          }
  
          long _thread;
      }
  
      static class FlushExCallback extends CallbackBase
      {
          FlushExCallback()
          {
          }
  
          public void
          completedAsync(Ice.AsyncResult r)
          {
              try
              {
                  if(r.getConnection() != null)
                  {
                      r.getConnection().end_flushBatchRequests(r);
                  }
                  else
                  {
                      r.getProxy().end_ice_flushBatchRequests(r);
                  }
                  test(false);
              }
              catch(Ice.LocalException ex)
              {
                  called();
              }
          }
  
          public void
          exception(Ice.LocalException ex)
          {
              called();
          }
  
          public void
          sentAsync(Ice.AsyncResult r)
          {
              test(false);
          }
  
          public void
          sent(boolean sentSynchronously)
          {
              test(false);
          }
      }
  
      enum ThrowType { LocalException, OtherException };
  
      static class Thrower extends CallbackBase
      {
          public Thrower(ThrowType t)
          {
              _t = t;
          }
  
          public void
          opAsync(Ice.AsyncResult r)
          {
              called();
              throwEx();
          }
  
          public void
          op()
          {
              called();
              throwEx();
          }
  
          public void
          noOp()
          {
          }
  
          public void
          ex(Ice.LocalException ex)
          {
              called();
              throwEx();
          }
  
          public void
          sent(boolean ss)
          {
              called();
              throwEx();
          }
  
          private void
          throwEx()
          {
              switch(_t)
              {
              case LocalException:
              {
                  throw new Ice.ObjectNotExistException();
              }
              case OtherException:
              {
                  throw new RuntimeException();
              }
              default:
              {
                  assert(false);
                  break;
              }
              }
          }
  
          ThrowType _t;
      }
  
      public static void
      allTests(Application app)
      {
          Ice.Communicator communicator = app.communicator();
          PrintWriter out = app.getWriter();
  
          String sref = "test:default -p 12010";
          Ice.ObjectPrx obj = communicator.stringToProxy(sref);
          test(obj != null);
  
          TestIntfPrx p = TestIntfPrxHelper.uncheckedCast(obj);
  
          sref = "testController:tcp -p 12011";
          obj = communicator.stringToProxy(sref);
          test(obj != null);
  
          TestIntfControllerPrx testController = TestIntfControllerPrxHelper.uncheckedCast(obj);
  
          out.print("testing begin/end invocation... ");
          out.flush();
          {
              Ice.AsyncResult result;
              java.util.Map<String, String> ctx = new java.util.HashMap<String, String>();
  
              result = p.begin_ice_isA("::Test::TestIntf");
              test(p.end_ice_isA(result));
              result = p.begin_ice_isA("::Test::TestIntf", ctx);
              test(p.end_ice_isA(result));
  
              result = p.begin_ice_ping();
              p.end_ice_ping(result);
              result = p.begin_ice_ping(ctx);
              p.end_ice_ping(result);
  
              result = p.begin_ice_id();
              test(p.end_ice_id(result).equals("::Test::TestIntf"));
              result = p.begin_ice_id(ctx);
              test(p.end_ice_id(result).equals("::Test::TestIntf"));
  
              result = p.begin_ice_ids();
              test(p.end_ice_ids(result).length == 2);
              result = p.begin_ice_ids(ctx);
              test(p.end_ice_ids(result).length == 2);
  
              result = p.begin_op();
              p.end_op(result);
              result = p.begin_op(ctx);
              p.end_op(result);
  
              result = p.begin_opWithResult();
              test(p.end_opWithResult(result) == 15);
              result = p.begin_opWithResult(ctx);
              test(p.end_opWithResult(result) == 15);
  
              result = p.begin_opWithUE();
              try
              {
                  p.end_opWithUE(result);
                  test(false);
              }
              catch(TestIntfException ex)
              {
              }
              result = p.begin_opWithUE(ctx);
              try
              {
                  p.end_opWithUE(result);
                  test(false);
              }
              catch(TestIntfException ex)
              {
              }
          }
          out.println("ok");
  
          out.print("testing async callback... ");
          out.flush();
          {
              final AsyncCallback cb = new AsyncCallback();
              java.util.Map<String, String> ctx = new java.util.HashMap<String, String>();
  
              p.begin_ice_isA("::Test::TestIntf", new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.isA(r);
                      }
                  });
              cb.check();
  
              p.begin_ice_isA("::Test::TestIntf", ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.isA(r);
                      }
                  });
              cb.check();
  
              p.begin_ice_ping(new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.ping(r);
                      }
                  });
              cb.check();
              p.begin_ice_ping(ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.ping(r);
                      }
                  });
              cb.check();
  
              p.begin_ice_id(new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.id(r);
                      }
                  });
              cb.check();
              p.begin_ice_id(ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.id(r);
                      }
                  });
              cb.check();
  
              p.begin_ice_ids(new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.ids(r);
                      }
                  });
              cb.check();
              p.begin_ice_ids(ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.ids(r);
                      }
                  });
              cb.check();
  
              p.begin_op(new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.op(r);
                      }
                  });
              cb.check();
              p.begin_op(ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.op(r);
                      }
                  });
              cb.check();
  
              p.begin_opWithResult(new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.opWithResult(r);
                      }
                  });
              cb.check();
              p.begin_opWithResult(ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.opWithResult(r);
                      }
                  });
              cb.check();
  
              p.begin_opWithUE(new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.opWithUE(r);
                      }
                  });
              cb.check();
              p.begin_opWithUE(ctx, new Ice.Callback()
                  {
                      public void
                      completed(Ice.AsyncResult r)
                      {
                          cb.opWithUE(r);
                      }
                  });
              cb.check();
          }
          out.println("ok");
  
          out.print("testing response callback... ");
          out.flush();
          {
              final ResponseCallback cb = new ResponseCallback();
              java.util.Map<String, String> ctx = new java.util.HashMap<String, String>();
  
              p.begin_ice_isA("::Test::TestIntf", new Ice.Callback_Object_ice_isA()
                  {
                      public void
                      response(boolean r)
                      {
                          cb.isA(r);
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
              p.begin_ice_isA("::Test::TestIntf", ctx, new Ice.Callback_Object_ice_isA()
                  {
                      public void
                      response(boolean r)
                      {
                          cb.isA(r);
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
  
              p.begin_ice_ping(new Ice.Callback_Object_ice_ping()
                  {
                      public void
                      response()
                      {
                          cb.ping();
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
              p.begin_ice_ping(ctx, new Ice.Callback_Object_ice_ping()
                  {
                      public void
                      response()
                      {
                          cb.ping();
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
  
              p.begin_ice_id(new Ice.Callback_Object_ice_id()
                  {
                      public void
                      response(String id)
                      {
                          cb.id(id);
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
              p.begin_ice_id(ctx, new Ice.Callback_Object_ice_id()
                  {
                      public void
                      response(String id)
                      {
                          cb.id(id);
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
  
              p.begin_ice_ids(new Ice.Callback_Object_ice_ids()
                  {
                      public void
                      response(String[] ids)
                      {
                          cb.ids(ids);
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
              p.begin_ice_ids(ctx, new Ice.Callback_Object_ice_ids()
                  {
                      public void
                      response(String[] ids)
                      {
                          cb.ids(ids);
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
  
              p.begin_op(new Callback_TestIntf_op()
                  {
                      public void
                      response()
                      {
                          cb.op();
                      }
  
                      public void
                      exception(Ice.LocalException ex)
                      {
                          test(false);
                      }
                  });
              cb.check();
  