1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package com.sun.star.lib.uno.bridges.javaremote; 25 26 import com.sun.star.bridge.XInstanceProvider; 27 import com.sun.star.lib.TestBed; 28 import com.sun.star.lib.uno.typeinfo.MemberTypeInfo; 29 import com.sun.star.lib.uno.typeinfo.MethodTypeInfo; 30 import com.sun.star.lib.uno.typeinfo.ParameterTypeInfo; 31 import com.sun.star.lib.uno.typeinfo.TypeInfo; 32 import com.sun.star.uno.Any; 33 import com.sun.star.uno.Type; 34 import com.sun.star.uno.TypeClass; 35 import com.sun.star.uno.UnoRuntime; 36 import com.sun.star.uno.XComponentContext; 37 import com.sun.star.uno.XInterface; 38 import complexlib.ComplexTestCase; 39 40 public final class PolyStructTest extends ComplexTestCase { getTestMethodNames()41 public String[] getTestMethodNames() { 42 return new String[] { "test" }; 43 } 44 test()45 public void test() throws Exception { 46 assure( 47 "test", 48 new TestBed().execute(new Provider(), false, Client.class, 0)); 49 } 50 51 public static final class Client extends TestBed.Client { main(String[] args)52 public static void main(String[] args) { 53 new Client().execute(); 54 } 55 run(XComponentContext context)56 protected boolean run(XComponentContext context) throws Throwable { 57 TestTransport t = UnoRuntime.queryInterface( 58 TestTransport.class, getBridge(context).getInstance("")); 59 60 assertEquals( 61 Boolean.FALSE, t.transportBoolean(new TestPolyStruct()).member); 62 assertEquals( 63 Boolean.FALSE, 64 t.transportBoolean(new TestPolyStruct(Boolean.FALSE)).member); 65 assertEquals( 66 Boolean.TRUE, 67 t.transportBoolean(new TestPolyStruct(Boolean.TRUE)).member); 68 69 assertEquals( 70 new Byte((byte) 0), 71 t.transportByte(new TestPolyStruct()).member); 72 assertEquals( 73 new Byte(Byte.MIN_VALUE), 74 t.transportByte( 75 new TestPolyStruct(new Byte(Byte.MIN_VALUE))).member); 76 assertEquals( 77 new Byte(Byte.MAX_VALUE), 78 t.transportByte( 79 new TestPolyStruct(new Byte(Byte.MAX_VALUE))).member); 80 81 assertEquals( 82 new Short((short) 0), 83 t.transportShort(new TestPolyStruct()).member); 84 assertEquals( 85 new Short(Short.MIN_VALUE), 86 t.transportShort( 87 new TestPolyStruct(new Short(Short.MIN_VALUE))).member); 88 assertEquals( 89 new Short(Short.MAX_VALUE), 90 t.transportShort( 91 new TestPolyStruct(new Short(Short.MAX_VALUE))).member); 92 93 assertEquals( 94 new Integer(0), t.transportLong(new TestPolyStruct()).member); 95 assertEquals( 96 new Integer(Integer.MIN_VALUE), 97 t.transportLong( 98 new TestPolyStruct(new Integer(Integer.MIN_VALUE))).member); 99 assertEquals( 100 new Integer(Integer.MAX_VALUE), 101 t.transportLong( 102 new TestPolyStruct(new Integer(Integer.MAX_VALUE))).member); 103 104 assertEquals( 105 new Long(0L), t.transportHyper(new TestPolyStruct()).member); 106 assertEquals( 107 new Long(Long.MIN_VALUE), 108 t.transportHyper( 109 new TestPolyStruct(new Long(Long.MIN_VALUE))).member); 110 assertEquals( 111 new Long(Long.MAX_VALUE), 112 t.transportHyper( 113 new TestPolyStruct(new Long(Long.MAX_VALUE))).member); 114 115 assertEquals( 116 new Float(0.0f), t.transportFloat(new TestPolyStruct()).member); 117 assertEquals( 118 new Float(Float.MIN_VALUE), 119 t.transportFloat( 120 new TestPolyStruct(new Float(Float.MIN_VALUE))).member); 121 assertEquals( 122 new Float(Float.MAX_VALUE), 123 t.transportFloat( 124 new TestPolyStruct(new Float(Float.MAX_VALUE))).member); 125 126 assertEquals( 127 new Double(0.0), 128 t.transportDouble(new TestPolyStruct()).member); 129 assertEquals( 130 new Double(Double.MIN_VALUE), 131 t.transportDouble( 132 new TestPolyStruct(new Double(Double.MIN_VALUE))).member); 133 assertEquals( 134 new Double(Double.MAX_VALUE), 135 t.transportDouble( 136 new TestPolyStruct(new Double(Double.MAX_VALUE))).member); 137 138 assertEquals( 139 new Character(Character.MIN_VALUE), 140 t.transportChar(new TestPolyStruct()).member); 141 assertEquals( 142 new Character(Character.MIN_VALUE), 143 t.transportChar( 144 new TestPolyStruct( 145 new Character(Character.MIN_VALUE))).member); 146 assertEquals( 147 new Character(Character.MAX_VALUE), 148 t.transportChar( 149 new TestPolyStruct( 150 new Character(Character.MAX_VALUE))).member); 151 152 assertEquals("", t.transportString(new TestPolyStruct()).member); 153 assertEquals( 154 "ABC", t.transportString(new TestPolyStruct("ABC")).member); 155 156 assertEquals( 157 Type.VOID, t.transportType(new TestPolyStruct()).member); 158 assertEquals( 159 new Type( 160 "[]com.sun.star.lib.uno.bridges.javaremote.TestPolyStruct" 161 + "<long>"), 162 t.transportType( 163 new TestPolyStruct( 164 new Type( 165 "[]com.sun.star.lib.uno.bridges.javaremote." 166 + "TestPolyStruct<long>"))).member); 167 168 assertEquals(null, t.transportAny(new TestPolyStruct()).member); 169 assertEquals( 170 Any.VOID, t.transportAny(new TestPolyStruct(Any.VOID)).member); 171 assertEquals(null, t.transportAny(new TestPolyStruct(null)).member); 172 assertEquals( 173 new Any(Type.UNSIGNED_LONG, new Integer(5)), 174 t.transportAny( 175 new TestPolyStruct( 176 new Any(Type.UNSIGNED_LONG, new Integer(5)))).member); 177 178 assertEquals( 179 TestEnum.VALUE1, t.transportEnum(new TestPolyStruct()).member); 180 assertEquals( 181 TestEnum.VALUE1, 182 t.transportEnum(new TestPolyStruct(TestEnum.VALUE1)).member); 183 assertEquals( 184 TestEnum.VALUE2, 185 t.transportEnum(new TestPolyStruct(TestEnum.VALUE2)).member); 186 187 return success; 188 } 189 assertEquals(Object expected, Object actual)190 private void assertEquals(Object expected, Object actual) { 191 if (!(expected == null ? actual == null : expected.equals(actual))) 192 { 193 new RuntimeException( 194 "failed; expected " + expected + ", got " + actual). 195 printStackTrace(); 196 success = false; 197 } 198 } 199 200 private boolean success = true; 201 } 202 203 private static final class Provider implements XInstanceProvider { getInstance(String instanceName)204 public Object getInstance(String instanceName) { 205 return new TestTransport() { 206 public TestPolyStruct transportBoolean(TestPolyStruct s) { 207 return s; 208 } 209 210 public TestPolyStruct transportByte(TestPolyStruct s) { 211 return s; 212 } 213 214 public TestPolyStruct transportShort(TestPolyStruct s) { 215 return s; 216 } 217 218 public TestPolyStruct transportLong(TestPolyStruct s) { 219 return s; 220 } 221 222 public TestPolyStruct transportHyper(TestPolyStruct s) { 223 return s; 224 } 225 226 public TestPolyStruct transportFloat(TestPolyStruct s) { 227 return s; 228 } 229 230 public TestPolyStruct transportDouble(TestPolyStruct s) { 231 return s; 232 } 233 234 public TestPolyStruct transportChar(TestPolyStruct s) { 235 return s; 236 } 237 238 public TestPolyStruct transportString(TestPolyStruct s) { 239 return s; 240 } 241 242 public TestPolyStruct transportType(TestPolyStruct s) { 243 return s; 244 } 245 246 public TestPolyStruct transportAny(TestPolyStruct s) { 247 return s; 248 } 249 250 public TestPolyStruct transportEnum(TestPolyStruct s) { 251 return s; 252 } 253 }; 254 } 255 } 256 } 257