diff options
Diffstat (limited to 'java/test')
-rw-r--r-- | java/test/Ice/enums/AllTests.java | 273 | ||||
-rw-r--r-- | java/test/Ice/enums/Client.java | 40 | ||||
-rw-r--r-- | java/test/Ice/enums/Server.java | 43 | ||||
-rw-r--r-- | java/test/Ice/enums/Test.ice | 89 | ||||
-rw-r--r-- | java/test/Ice/enums/TestIntfI.java | 49 | ||||
-rwxr-xr-x | java/test/Ice/enums/run.py | 26 |
6 files changed, 520 insertions, 0 deletions
diff --git a/java/test/Ice/enums/AllTests.java b/java/test/Ice/enums/AllTests.java new file mode 100644 index 00000000000..b86c3191aa2 --- /dev/null +++ b/java/test/Ice/enums/AllTests.java @@ -0,0 +1,273 @@ +// ********************************************************************** +// +// 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.enums; + +import test.Ice.enums.Test.*; +import java.io.PrintWriter; + +public class AllTests +{ + private static void + test(boolean b) + { + if(!b) + { + throw new RuntimeException(); + } + } + + public static TestIntfPrx + allTests(Ice.Communicator communicator, PrintWriter out) + { + String ref = "test:default -p 12010"; + Ice.ObjectPrx obj = communicator.stringToProxy(ref); + test(obj != null); + TestIntfPrx proxy = TestIntfPrxHelper.checkedCast(obj); + test(proxy != null); + + out.print("testing enum values... "); + out.flush(); + + test(ByteEnum.benum1.value() == 0); + test(ByteEnum.benum2.value() == 1); + test(ByteEnum.benum3.value() == ByteConst1.value); + test(ByteEnum.benum4.value() == ByteConst1.value + 1); + test(ByteEnum.benum5.value() == ShortConst1.value); + test(ByteEnum.benum6.value() == ShortConst1.value + 1); + test(ByteEnum.benum7.value() == IntConst1.value); + test(ByteEnum.benum8.value() == IntConst1.value + 1); + test(ByteEnum.benum9.value() == LongConst1.value); + test(ByteEnum.benum10.value() == LongConst1.value + 1); + test(ByteEnum.benum11.value() == ByteConst2.value); + + test(ByteEnum.valueOf(0) == ByteEnum.benum1); + test(ByteEnum.valueOf(1) == ByteEnum.benum2); + test(ByteEnum.valueOf(ByteConst1.value) == ByteEnum.benum3); + test(ByteEnum.valueOf(ByteConst1.value + 1) == ByteEnum.benum4); + test(ByteEnum.valueOf(ShortConst1.value) == ByteEnum.benum5); + test(ByteEnum.valueOf(ShortConst1.value + 1) == ByteEnum.benum6); + test(ByteEnum.valueOf(IntConst1.value) == ByteEnum.benum7); + test(ByteEnum.valueOf(IntConst1.value + 1) == ByteEnum.benum8); + test(ByteEnum.valueOf((int)LongConst1.value) == ByteEnum.benum9); + test(ByteEnum.valueOf((int)LongConst1.value + 1) == ByteEnum.benum10); + test(ByteEnum.valueOf(ByteConst2.value) == ByteEnum.benum11); + + test(ShortEnum.senum1.value() == 3); + test(ShortEnum.senum2.value() == 4); + test(ShortEnum.senum3.value() == ByteConst1.value); + test(ShortEnum.senum4.value() == ByteConst1.value + 1); + test(ShortEnum.senum5.value() == ShortConst1.value); + test(ShortEnum.senum6.value() == ShortConst1.value + 1); + test(ShortEnum.senum7.value() == IntConst1.value); + test(ShortEnum.senum8.value() == IntConst1.value + 1); + test(ShortEnum.senum9.value() == LongConst1.value); + test(ShortEnum.senum10.value() == LongConst1.value + 1); + test(ShortEnum.senum11.value() == ShortConst2.value); + + test(ShortEnum.valueOf(3) == ShortEnum.senum1); + test(ShortEnum.valueOf(4) == ShortEnum.senum2); + test(ShortEnum.valueOf(ByteConst1.value) == ShortEnum.senum3); + test(ShortEnum.valueOf(ByteConst1.value + 1) == ShortEnum.senum4); + test(ShortEnum.valueOf(ShortConst1.value) == ShortEnum.senum5); + test(ShortEnum.valueOf(ShortConst1.value + 1) == ShortEnum.senum6); + test(ShortEnum.valueOf(IntConst1.value) == ShortEnum.senum7); + test(ShortEnum.valueOf(IntConst1.value + 1) == ShortEnum.senum8); + test(ShortEnum.valueOf((int)LongConst1.value) == ShortEnum.senum9); + test(ShortEnum.valueOf((int)LongConst1.value + 1) == ShortEnum.senum10); + test(ShortEnum.valueOf(ShortConst2.value) == ShortEnum.senum11); + + test(IntEnum.ienum1.value() == 0); + test(IntEnum.ienum2.value() == 1); + test(IntEnum.ienum3.value() == ByteConst1.value); + test(IntEnum.ienum4.value() == ByteConst1.value + 1); + test(IntEnum.ienum5.value() == ShortConst1.value); + test(IntEnum.ienum6.value() == ShortConst1.value + 1); + test(IntEnum.ienum7.value() == IntConst1.value); + test(IntEnum.ienum8.value() == IntConst1.value + 1); + test(IntEnum.ienum9.value() == LongConst1.value); + test(IntEnum.ienum10.value() == LongConst1.value + 1); + test(IntEnum.ienum11.value() == IntConst2.value); + test(IntEnum.ienum12.value() == LongConst2.value); + + test(IntEnum.valueOf(0) == IntEnum.ienum1); + test(IntEnum.valueOf(1) == IntEnum.ienum2); + test(IntEnum.valueOf(ByteConst1.value) == IntEnum.ienum3); + test(IntEnum.valueOf(ByteConst1.value + 1) == IntEnum.ienum4); + test(IntEnum.valueOf(ShortConst1.value) == IntEnum.ienum5); + test(IntEnum.valueOf(ShortConst1.value + 1) == IntEnum.ienum6); + test(IntEnum.valueOf(IntConst1.value) == IntEnum.ienum7); + test(IntEnum.valueOf(IntConst1.value + 1) == IntEnum.ienum8); + test(IntEnum.valueOf((int)LongConst1.value) == IntEnum.ienum9); + test(IntEnum.valueOf((int)LongConst1.value + 1) == IntEnum.ienum10); + test(IntEnum.valueOf(IntConst2.value) == IntEnum.ienum11); + test(IntEnum.valueOf((int)LongConst2.value) == IntEnum.ienum12); + + test(SimpleEnum.red.value() == 0); + test(SimpleEnum.green.value() == 1); + test(SimpleEnum.blue.value() == 2); + + test(SimpleEnum.valueOf(0) == SimpleEnum.red); + test(SimpleEnum.valueOf(1) == SimpleEnum.green); + test(SimpleEnum.valueOf(2) == SimpleEnum.blue); + + out.println("ok"); + + out.print("testing enum streaming... "); + out.flush(); + + Ice.OutputStream os; + byte[] bytes; + + final boolean encoding_1_0 = + communicator.getProperties().getProperty("Ice.Default.EncodingVersion").equals("1.0"); + + os = Ice.Util.createOutputStream(communicator); + ByteEnum.benum11.ice_write(os); + bytes = os.finished(); + test(bytes.length == 1); // ByteEnum should require one byte + + os = Ice.Util.createOutputStream(communicator); + ShortEnum.senum11.ice_write(os); + bytes = os.finished(); + test(bytes.length == (encoding_1_0 ? 2 : 5)); + + os = Ice.Util.createOutputStream(communicator); + IntEnum.ienum11.ice_write(os); + bytes = os.finished(); + test(bytes.length == (encoding_1_0 ? 4 : 5)); + + os = Ice.Util.createOutputStream(communicator); + SimpleEnum.blue.ice_write(os); + bytes = os.finished(); + test(bytes.length == 1); // SimpleEnum should require one byte + + out.println("ok"); + + out.print("testing enum operations... "); + out.flush(); + + ByteEnumHolder byteEnum = new ByteEnumHolder(); + test(proxy.opByte(ByteEnum.benum1, byteEnum) == ByteEnum.benum1); + test(byteEnum.value == ByteEnum.benum1); + test(proxy.opByte(ByteEnum.benum11, byteEnum) == ByteEnum.benum11); + test(byteEnum.value == ByteEnum.benum11); + + ShortEnumHolder shortEnum = new ShortEnumHolder(); + test(proxy.opShort(ShortEnum.senum1, shortEnum) == ShortEnum.senum1); + test(shortEnum.value == ShortEnum.senum1); + test(proxy.opShort(ShortEnum.senum11, shortEnum) == ShortEnum.senum11); + test(shortEnum.value == ShortEnum.senum11); + + IntEnumHolder intEnum = new IntEnumHolder(); + test(proxy.opInt(IntEnum.ienum1, intEnum) == IntEnum.ienum1); + test(intEnum.value == IntEnum.ienum1); + test(proxy.opInt(IntEnum.ienum11, intEnum) == IntEnum.ienum11); + test(intEnum.value == IntEnum.ienum11); + test(proxy.opInt(IntEnum.ienum12, intEnum) == IntEnum.ienum12); + test(intEnum.value == IntEnum.ienum12); + + SimpleEnumHolder s = new SimpleEnumHolder(); + test(proxy.opSimple(SimpleEnum.green, s) == SimpleEnum.green); + test(s.value == SimpleEnum.green); + + out.println("ok"); + + out.print("testing enum exceptions... "); + out.flush(); + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeByte((byte)2); // Invalid enumerator + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + ByteEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeByte((byte)128); // Invalid enumerator + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + ByteEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeShort((short)-1); // Negative enumerators are not supported + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + ShortEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeShort((short)0); // Invalid enumerator + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + ShortEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeShort((short)32767); // Invalid enumerator + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + ShortEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeInt(-1); // Negative enumerators are not supported + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + IntEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + try + { + os = Ice.Util.createOutputStream(communicator); + os.writeInt(2); // Invalid enumerator + Ice.InputStream in = Ice.Util.createInputStream(communicator, os.finished()); + IntEnum.ice_read(in); + test(false); + } + catch(Ice.MarshalException ex) + { + } + + out.println("ok"); + + return proxy; + } +} diff --git a/java/test/Ice/enums/Client.java b/java/test/Ice/enums/Client.java new file mode 100644 index 00000000000..52585870fd9 --- /dev/null +++ b/java/test/Ice/enums/Client.java @@ -0,0 +1,40 @@ +// ********************************************************************** +// +// 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.enums; + +import test.Ice.enums.Test.TestIntfPrx; + +public class Client extends test.Util.Application +{ + public int run(String[] args) + { + Ice.Communicator communicator = communicator(); + TestIntfPrx test = AllTests.allTests(communicator, getWriter()); + test.shutdown(); + return 0; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.enums"); + return initData; + } + + public static void main(String[] args) + { + Client c = new Client(); + int status = c.main("Client", args); + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/enums/Server.java b/java/test/Ice/enums/Server.java new file mode 100644 index 00000000000..dc1e98554f9 --- /dev/null +++ b/java/test/Ice/enums/Server.java @@ -0,0 +1,43 @@ +// ********************************************************************** +// +// 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.enums; + +public class Server extends test.Util.Application +{ + public int run(String[] args) + { + Ice.Communicator communicator = communicator(); + Ice.ObjectAdapter adapter = communicator.createObjectAdapter("TestAdapter"); + Ice.Object test = new TestIntfI(); + adapter.add(test, communicator.stringToIdentity("test")); + + adapter.activate(); + + return WAIT; + } + + protected Ice.InitializationData getInitData(Ice.StringSeqHolder argsH) + { + Ice.InitializationData initData = new Ice.InitializationData(); + initData.properties = Ice.Util.createProperties(argsH); + initData.properties.setProperty("Ice.Package.Test", "test.Ice.enums"); + initData.properties.setProperty("TestAdapter.Endpoints", "default -p 12010"); + return initData; + } + + public static void main(String[] args) + { + Server c = new Server(); + int status = c.main("Server", args); + + System.gc(); + System.exit(status); + } +} diff --git a/java/test/Ice/enums/Test.ice b/java/test/Ice/enums/Test.ice new file mode 100644 index 00000000000..f843258fcbc --- /dev/null +++ b/java/test/Ice/enums/Test.ice @@ -0,0 +1,89 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2012 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. +// +// ********************************************************************** + +#pragma once + +[["java:package:test.Ice.enums"]] +module Test +{ + +const byte ByteConst1 = 10; +const short ShortConst1 = 20; +const int IntConst1 = 30; +const long LongConst1 = 40; + +const byte ByteConst2 = 126; +const short ShortConst2 = 32766; +const int IntConst2 = 2147483647; +const long LongConst2 = 2147483646; + +enum ByteEnum +{ + benum1, + benum2, + benum3 = ByteConst1, + benum4, + benum5 = ShortConst1, + benum6, + benum7 = IntConst1, + benum8, + benum9 = LongConst1, + benum10, + benum11 = ByteConst2 +}; + +enum ShortEnum +{ + senum1 = 3, + senum2, + senum3 = ByteConst1, + senum4, + senum5 = ShortConst1, + senum6, + senum7 = IntConst1, + senum8, + senum9 = LongConst1, + senum10, + senum11 = ShortConst2 +}; + +enum IntEnum +{ + ienum1, + ienum2, + ienum3 = ByteConst1, + ienum4, + ienum5 = ShortConst1, + ienum6, + ienum7 = IntConst1, + ienum8, + ienum9 = LongConst1, + ienum10, + ienum11 = IntConst2, + ienum12 = LongConst2 +}; + +enum SimpleEnum +{ + red, + green, + blue +}; + +interface TestIntf +{ + ByteEnum opByte(ByteEnum b1, out ByteEnum b2); + ShortEnum opShort(ShortEnum s1, out ShortEnum s2); + IntEnum opInt(IntEnum i1, out IntEnum i2); + SimpleEnum opSimple(SimpleEnum s1, out SimpleEnum s2); + + void shutdown(); +}; + +}; diff --git a/java/test/Ice/enums/TestIntfI.java b/java/test/Ice/enums/TestIntfI.java new file mode 100644 index 00000000000..92fdf0a7a24 --- /dev/null +++ b/java/test/Ice/enums/TestIntfI.java @@ -0,0 +1,49 @@ +// ********************************************************************** +// +// 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.enums; + +import test.Ice.enums.Test.*; + +public final class TestIntfI extends _TestIntfDisp +{ + public ByteEnum + opByte(ByteEnum b1, ByteEnumHolder b2, Ice.Current current) + { + b2.value = b1; + return b1; + } + + public ShortEnum + opShort(ShortEnum s1, ShortEnumHolder s2, Ice.Current current) + { + s2.value = s1; + return s1; + } + + public IntEnum + opInt(IntEnum i1, IntEnumHolder i2, Ice.Current current) + { + i2.value = i1; + return i1; + } + + public SimpleEnum + opSimple(SimpleEnum s1, SimpleEnumHolder s2, Ice.Current current) + { + s2.value = s1; + return s1; + } + + public void + shutdown(Ice.Current current) + { + current.adapter.getCommunicator().shutdown(); + } +} diff --git a/java/test/Ice/enums/run.py b/java/test/Ice/enums/run.py new file mode 100755 index 00000000000..690e20e4973 --- /dev/null +++ b/java/test/Ice/enums/run.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# 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. +# +# ********************************************************************** + +import os, sys + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +print("Running test with 1.0 encoding.") +TestUtil.clientServerTest(additionalClientOptions="--Ice.Default.EncodingVersion=1.0", additionalServerOptions="--Ice.Default.EncodingVersion=1.0") +print("Running test with 1.1 encoding.") +TestUtil.clientServerTest() |