diff options
Diffstat (limited to 'cs/test')
-rw-r--r-- | cs/test/Ice/Makefile | 3 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/AllTests.cs | 187 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Client.cs | 33 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Collocated.cs | 41 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/CookieI.cs | 18 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/Makefile | 44 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/Makefile.mak | 39 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/ServantLocatorI.cs | 135 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Server.cs | 39 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/Test.ice | 40 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/TestAMD.ice | 40 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/TestAMDI.cs | 54 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/TestI.cs | 46 | ||||
-rw-r--r-- | cs/test/Ice/servantLocator/generated/.dummy | 0 | ||||
-rwxr-xr-x | cs/test/Ice/servantLocator/run.py | 32 |
15 files changed, 750 insertions, 1 deletions
diff --git a/cs/test/Ice/Makefile b/cs/test/Ice/Makefile index 1f16f817680..9c3a7db182d 100644 --- a/cs/test/Ice/Makefile +++ b/cs/test/Ice/Makefile @@ -26,7 +26,8 @@ SUBDIRS = application \ checksum \ stream \ retry \ - timeout + timeout \ + servantLocator $(EVERYTHING):: @for subdir in $(SUBDIRS); \ diff --git a/cs/test/Ice/servantLocator/AllTests.cs b/cs/test/Ice/servantLocator/AllTests.cs new file mode 100755 index 00000000000..66754cd5c8b --- /dev/null +++ b/cs/test/Ice/servantLocator/AllTests.cs @@ -0,0 +1,187 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using System; +using Test; +using Ice; + +public class AllTests +{ + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + public static void testExceptions(TestIntfPrx obj, bool collocated) + { + try + { + obj.requestFailedException(); + test(false); + } + catch(ObjectNotExistException ex) + { + if(!collocated) + { + test(ex.id.Equals(obj.ice_getIdentity())); + test(ex.facet.Equals(obj.ice_getFacet())); + test(ex.operation.Equals("requestFailedException")); + } + } + + try + { + obj.unknownUserException(); + test(false); + } + catch(UnknownUserException ex) + { + test(ex.unknown.Equals("reason")); + } + + try + { + obj.unknownLocalException(); + test(false); + } + catch(UnknownLocalException ex) + { + test(ex.unknown.Equals("reason")); + } + + try + { + obj.unknownException(); + test(false); + } + catch(UnknownException ex) + { + test(ex.unknown.Equals("reason")); + } + + try + { + obj.userException(); + test(false); + } + catch(UnknownUserException ex) + { + //Console.Error.WriteLine(ex.unknown); + test(!collocated); + test(ex.unknown.IndexOf("Test.TestIntfUserException") >= 0); + } + catch(TestIntfUserException) + { + test(collocated); + } + + try + { + obj.localException(); + test(false); + } + catch(UnknownLocalException ex) + { + //Console.Error.WriteLine(ex.unknown); + test(!collocated); + test(ex.unknown.IndexOf("Ice.SocketException") >= 0); + } + catch(SocketException) + { + test(collocated); + } + + try + { + obj.csException(); + test(false); + } + catch(UnknownException ex) + { + //Console.Error.WriteLine(ex.unknown); + test(!collocated); + test(ex.unknown.IndexOf("System.Exception: message") >= 0); + } + catch(System.Exception) + { + test(collocated); + } + } + + public static TestIntfPrx allTests(Ice.Communicator communicator, bool collocated) + { + Console.Out.Write("testing stringToProxy... "); + Console.Out.Flush(); + string @ref = "asm:default -p 12010 -t 2000"; + Ice.ObjectPrx @base = communicator.stringToProxy(@ref); + test(@base != null); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing checked cast... "); + Console.Out.Flush(); + TestIntfPrx obj = TestIntfPrxHelper.checkedCast(@base); + test(obj != null); + test(obj.Equals(@base)); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing servant locator..."); + Console.Out.Flush(); + @base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("category/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException) + { + } + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing default servant locator..."); + Console.Out.Flush(); + @base = communicator.stringToProxy("anothercat/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + @base = communicator.stringToProxy("locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("anothercat/unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException) + { + } + try + { + TestIntfPrxHelper.checkedCast(communicator.stringToProxy("unknown:default -p 12010 -t 10000")); + } + catch(ObjectNotExistException) + { + } + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing locate exceptions... "); + Console.Out.Flush(); + @base = communicator.stringToProxy("category/locate:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + testExceptions(obj, collocated); + Console.Out.WriteLine("ok"); + + Console.Out.Write("testing finished exceptions... "); + Console.Out.Flush(); + @base = communicator.stringToProxy("category/finished:default -p 12010 -t 10000"); + obj = TestIntfPrxHelper.checkedCast(@base); + testExceptions(obj, collocated); + Console.Out.WriteLine("ok"); + + return obj; + } +} diff --git a/cs/test/Ice/servantLocator/Client.cs b/cs/test/Ice/servantLocator/Client.cs new file mode 100755 index 00000000000..e926daaf993 --- /dev/null +++ b/cs/test/Ice/servantLocator/Client.cs @@ -0,0 +1,33 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using Test; + +public class Client +{ + internal class TestClient : Ice.Application + { + public override int run(string[] args) + { + TestIntfPrx obj = AllTests.allTests(communicator(), false); + obj.shutdown(); + return 0; + } + } + + public static void Main(string[] args) + { + TestClient app = new TestClient(); + int result = app.main(args); + if(result != 0) + { + System.Environment.Exit(result); + } + } +} diff --git a/cs/test/Ice/servantLocator/Collocated.cs b/cs/test/Ice/servantLocator/Collocated.cs new file mode 100755 index 00000000000..fcb518de41f --- /dev/null +++ b/cs/test/Ice/servantLocator/Collocated.cs @@ -0,0 +1,41 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using Test; + +public class Collocated +{ + internal class TestClient : Ice.Application + { + public override int run(string[] args) + { + communicator().getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 10000"); + communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0"); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI("category"), "category"); + adapter.addServantLocator(new ServantLocatorI(""), ""); + adapter.add(new TestI(), communicator().stringToIdentity("asm")); + + AllTests.allTests(communicator(), true); + + return 0; + } + } + + public static void Main(string[] args) + { + TestClient app = new TestClient(); + int result = app.main(args); + if(result != 0) + { + System.Environment.Exit(result); + } + } +} diff --git a/cs/test/Ice/servantLocator/CookieI.cs b/cs/test/Ice/servantLocator/CookieI.cs new file mode 100755 index 00000000000..f225eac92bb --- /dev/null +++ b/cs/test/Ice/servantLocator/CookieI.cs @@ -0,0 +1,18 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using Test; + +public sealed class CookieI : Cookie +{ + public override string message() + { + return "blahblah"; + } +} diff --git a/cs/test/Ice/servantLocator/Makefile b/cs/test/Ice/servantLocator/Makefile new file mode 100644 index 00000000000..522ef811e98 --- /dev/null +++ b/cs/test/Ice/servantLocator/Makefile @@ -0,0 +1,44 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ../../.. + +TARGETS = client.exe server.exe serveramd.exe collocated.exe + +C_SRCS = Client.cs AllTests.cs +S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs +COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs +SAMD_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestAMDI.cs + +SLICE_SRCS = $(SDIR)/Test.ice +SLICE_AMD_SRCS = $(SDIR)/TestAMD.ice + +SDIR = . + +GDIR = generated + +include $(top_srcdir)/config/Make.rules.cs + +MCSFLAGS := $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS := $(SLICE2CSFLAGS) -I. + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +server.exe: $(S_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +collocated.exe: $(COL_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +serveramd.exe: $(SAMD_SRCS) $(GEN_AMD_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ $(call ref,icecs) $(subst /,$(DSEP),$^) + +include .depend diff --git a/cs/test/Ice/servantLocator/Makefile.mak b/cs/test/Ice/servantLocator/Makefile.mak new file mode 100644 index 00000000000..2f95cdcc1d0 --- /dev/null +++ b/cs/test/Ice/servantLocator/Makefile.mak @@ -0,0 +1,39 @@ +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +top_srcdir = ..\..\.. + +TARGETS = client.exe server.exe collocated.exe + +C_SRCS = Client.cs AllTests.cs +S_SRCS = Server.cs CookieI.cs ServantLocatorI.cs TestI.cs +COL_SRCS = Collocated.cs AllTests.cs CookieI.cs ServantLocatorI.cs TestI.cs + +GEN_SRCS = $(GDIR)\Test.cs + +SDIR = . + +GDIR = generated + +!include $(top_srcdir)\config\Make.rules.mak + +MCSFLAGS = $(MCSFLAGS) -target:exe + +SLICE2CSFLAGS = $(SLICE2CSFLAGS) -I. + +client.exe: $(C_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(C_SRCS) $(GEN_SRCS) + +server.exe: $(S_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(S_SRCS) $(GEN_SRCS) + +collocated.exe: $(COL_SRCS) $(GEN_SRCS) + $(MCS) $(MCSFLAGS) -out:$@ -r:$(bindir)\icecs.dll $(COL_SRCS) $(GEN_SRCS) + +!include .depend diff --git a/cs/test/Ice/servantLocator/ServantLocatorI.cs b/cs/test/Ice/servantLocator/ServantLocatorI.cs new file mode 100755 index 00000000000..1ebb6ae20f6 --- /dev/null +++ b/cs/test/Ice/servantLocator/ServantLocatorI.cs @@ -0,0 +1,135 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using System; +using Test; +using Ice; + +public sealed class ServantLocatorI : Ice.LocalObjectImpl, Ice.ServantLocator +{ + public ServantLocatorI(String category) + { + _category = category; + _deactivated = false; + } + + ~ServantLocatorI() + { + lock(this) + { + test(_deactivated); + } + } + + private static void test(bool b) + { + if(!b) + { + throw new System.Exception(); + } + } + + public Ice.Object locate(Ice.Current current, out Ice.LocalObject cookie) + { + lock(this) + { + test(!_deactivated); + } + + test(current.id.category.Equals(_category) || _category.Length == 0); + + if(current.id.name.Equals("unknown")) + { + cookie = null; + return null; + } + + test(current.id.name.Equals("locate") || current.id.name.Equals("finished")); + if(current.id.name.Equals("locate")) + { + exception(current); + } + + cookie = new CookieI(); + + return new TestI(); + } + + public void finished(Ice.Current current, Ice.Object servant, Ice.LocalObject cookie) + { + lock(this) + { + test(!_deactivated); + } + + test(current.id.category.Equals(_category) || _category.Length == 0); + test(current.id.name.Equals("locate") || current.id.name.Equals("finished")); + + if(current.id.name.Equals("finished")) + { + exception(current); + } + + Cookie co = (Cookie) cookie; + test(co.message().Equals("blahblah")); + } + + public void deactivate(string category) + { + lock(this) + { + test(!_deactivated); + + _deactivated = true; + } + } + + private void exception(Ice.Current current) + { + if(current.operation.Equals("requestFailedException")) + { + throw new ObjectNotExistException(); + } + else if(current.operation.Equals("unknownUserException")) + { + UnknownUserException ex = new UnknownUserException(); + ex.unknown = "reason"; + throw ex; + } + else if(current.operation.Equals("unknownLocalException")) + { + UnknownLocalException ex = new UnknownLocalException(); + ex.unknown = "reason"; + throw ex; + } + else if(current.operation.Equals("unknownException")) + { + UnknownException ex = new UnknownException(); + ex.unknown = "reason"; + throw ex; + } + else if(current.operation.Equals("userException")) + { + throw new TestIntfUserException(); + } + else if(current.operation.Equals("localException")) + { + SocketException ex = new SocketException(); + ex.error = 0; + throw ex; + } + else if(current.operation.Equals("csException")) + { + throw new System.Exception("message"); + } + } + + private bool _deactivated; + private string _category; +} diff --git a/cs/test/Ice/servantLocator/Server.cs b/cs/test/Ice/servantLocator/Server.cs new file mode 100755 index 00000000000..6280e1373d4 --- /dev/null +++ b/cs/test/Ice/servantLocator/Server.cs @@ -0,0 +1,39 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +public class Server +{ + internal class TestServer : Ice.Application + { + public override int run(string[] args) + { + communicator().getProperties().setProperty("Ice.OA.TestAdapter.Endpoints", "default -p 12010 -t 2000"); + communicator().getProperties().setProperty("Ice.Warn.Dispatch", "0"); + + Ice.ObjectAdapter adapter = communicator().createObjectAdapter("TestAdapter"); + adapter.addServantLocator(new ServantLocatorI("category"), "category"); + adapter.addServantLocator(new ServantLocatorI(""), ""); + adapter.add(new TestI(), communicator().stringToIdentity("asm")); + + adapter.activate(); + adapter.waitForDeactivate(); + return 0; + } + } + + public static void Main(string[] args) + { + TestServer app = new TestServer(); + int result = app.main(args); + if(result != 0) + { + System.Environment.Exit(result); + } + } +} diff --git a/cs/test/Ice/servantLocator/Test.ice b/cs/test/Ice/servantLocator/Test.ice new file mode 100755 index 00000000000..82f3679d75f --- /dev/null +++ b/cs/test/Ice/servantLocator/Test.ice @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +exception TestIntfUserException +{ +}; + +interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + void userException(); + void csException(); + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +}; + +#endif diff --git a/cs/test/Ice/servantLocator/TestAMD.ice b/cs/test/Ice/servantLocator/TestAMD.ice new file mode 100644 index 00000000000..fdd81edd0db --- /dev/null +++ b/cs/test/Ice/servantLocator/TestAMD.ice @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2006 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. +// +// ********************************************************************** + +#ifndef TEST_ICE +#define TEST_ICE + +module Test +{ + +exception TestIntfUserException +{ +}; + +["amd"] interface TestIntf +{ + void requestFailedException(); + void unknownUserException(); + void unknownLocalException(); + void unknownException(); + void localException(); + void userException(); + void csException(); + + void shutdown(); +}; + +local class Cookie +{ + ["cpp:const"] string message(); +}; + +}; + +#endif diff --git a/cs/test/Ice/servantLocator/TestAMDI.cs b/cs/test/Ice/servantLocator/TestAMDI.cs new file mode 100644 index 00000000000..555c6ada355 --- /dev/null +++ b/cs/test/Ice/servantLocator/TestAMDI.cs @@ -0,0 +1,54 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using Test; + +public sealed class TestI : TestIntfDisp_ +{ + public override void requestFailedException_async(AMD_TestIntf_requestFailedException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void unknownUserException_async(AMD_TestIntf_unknownUserException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void unknownLocalException_async(AMD_TestIntf_unknownLocalException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void unknownException_async(AMD_TestIntf_unknownException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void localException_async(AMD_TestIntf_localException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void userException_async(AMD_TestIntf_userException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void csException_async(AMD_TestIntf_csException cb, Ice.Current current) + { + cb.ice_response(); + } + + public override void shutdown_async(AMD_TestIntf_shutdown cb, Ice.Current current) + { + current.adapter.deactivate(); + cb.ice_response(); + } +} diff --git a/cs/test/Ice/servantLocator/TestI.cs b/cs/test/Ice/servantLocator/TestI.cs new file mode 100755 index 00000000000..85f67a82bf7 --- /dev/null +++ b/cs/test/Ice/servantLocator/TestI.cs @@ -0,0 +1,46 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 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. +// +// ********************************************************************** + +using Test; + +public sealed class TestI : TestIntfDisp_ +{ + public override void requestFailedException(Ice.Current current) + { + } + + public override void unknownUserException(Ice.Current current) + { + } + + public override void unknownLocalException(Ice.Current current) + { + } + + public override void unknownException(Ice.Current current) + { + } + + public override void localException(Ice.Current current) + { + } + + public override void userException(Ice.Current current) + { + } + + public override void csException(Ice.Current current) + { + } + + public override void shutdown(Ice.Current current) + { + current.adapter.deactivate(); + } +} diff --git a/cs/test/Ice/servantLocator/generated/.dummy b/cs/test/Ice/servantLocator/generated/.dummy new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/cs/test/Ice/servantLocator/generated/.dummy diff --git a/cs/test/Ice/servantLocator/run.py b/cs/test/Ice/servantLocator/run.py new file mode 100755 index 00000000000..f5d55842c4b --- /dev/null +++ b/cs/test/Ice/servantLocator/run.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2007 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. +# +# ********************************************************************** + +import os, sys, getopt + +for toplevel in [".", "..", "../..", "../../..", "../../../.."]: + toplevel = os.path.normpath(toplevel) + if os.path.exists(os.path.join(toplevel, "config", "TestUtil.py")): + break +else: + raise "can't find toplevel directory!" + +sys.path.append(os.path.join(toplevel, "config")) +import TestUtil + +name = os.path.join("Ice", "servantLocator") + +print "tests with regular server." +TestUtil.clientServerTest(name) +print "tests with AMD server." +TestUtil.clientServerTestWithOptionsAndNames(name, "", "", "serveramd", "client") +print "tests with collocated server." +TestUtil.collocatedTest(name) + +sys.exit(0) |