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
|
// **********************************************************************
//
// 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.
//
// **********************************************************************
import Test.*;
import java.io.*;
public class AllTests
{
private static void
test(boolean b)
{
if(!b)
{
throw new RuntimeException();
}
}
public static InitialPrx
allTests(Ice.Communicator communicator, boolean collocated)
{
String ref = "initial:default -p 12010 -t 10000";
Ice.ObjectPrx base = communicator.stringToProxy(ref);
InitialPrx initial = InitialPrxHelper.checkedCast(base);
System.out.print("testing serialization... ");
System.out.flush();
//
// Call getStruct1 and force an error.
//
try
{
//
// We expect this test to raise an exception: we are attempting to deserialize
// an instance of Struct1 using java.io.ObjectInputStream. However, we must
// use Ice.ObjectInputStream instead because Struct1 contains a proxy.
//
byte[] bytes = initial.getStruct1();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
ois.readObject();
test(false);
}
catch(IOException ex)
{
// Expected.
}
catch(Throwable ex)
{
test(false);
}
//
// Call getStruct1.
//
try
{
byte[] bytes = initial.getStruct1();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Ice.ObjectInputStream ois = new Ice.ObjectInputStream(communicator, bais);
Struct1 s = (Struct1)ois.readObject();
checkStruct1(s);
}
catch(Throwable ex)
{
test(false);
}
//
// Call getBase.
//
try
{
byte[] bytes = initial.getBase();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Ice.ObjectInputStream ois = new Ice.ObjectInputStream(communicator, bais);
Base b = (Base)ois.readObject();
checkBase(b);
}
catch(Throwable ex)
{
test(false);
}
//
// Call getEx.
//
try
{
byte[] bytes = initial.getEx();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
Ice.ObjectInputStream ois = new Ice.ObjectInputStream(communicator, bais);
Ex ex = (Ex)ois.readObject();
checkStruct1(ex.s);
checkBase(ex.b);
}
catch(Throwable ex)
{
test(false);
}
System.out.println("ok");
return initial;
}
private static void
checkStruct1(Struct1 s)
{
test(s.bo);
test(s.by == (byte)1);
test(s.sh == (short)2);
test(s.i == 3);
test(s.l == 4);
test(s.f == (float)5.0);
test(s.d == 6.0);
test(s.str.equals("7"));
test(s.e == MyEnum.enum2);
test(s.p != null);
s.p.ice_ping(); // Make sure the deserialized proxy is usable.
}
private static void
checkBase(Base b)
{
test(b.b == b);
test(b.o == b);
checkStruct1(b.s);
test(java.util.Arrays.equals(b.seq1, new byte[] { 0, 1, 2, 3, 4 }));
test(java.util.Arrays.equals(b.seq2, new int[] { 5, 6, 7, 8, 9 }));
test(java.util.Arrays.equals(b.seq3, new MyEnum[] { MyEnum.enum3, MyEnum.enum2, MyEnum.enum1 }));
test(java.util.Arrays.equals(b.seq4, new Base[] { b }));
test(b.d1.get(new Byte((byte)1)).equals(Boolean.TRUE));
test(b.d2.get(new Short((short)2)).equals(new Integer(3)));
test(b.d3.get("enum3") == MyEnum.enum3);
test(b.d4.get("b") == b);
test(b instanceof Derived);
Derived d = (Derived)b;
test(d.p != null);
d.p.ice_ping();
}
}
|