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.MethodTypeInfo; 29 import com.sun.star.lib.uno.typeinfo.TypeInfo; 30 import com.sun.star.uno.UnoRuntime; 31 import com.sun.star.uno.XComponentContext; 32 import com.sun.star.uno.XInterface; 33 import complexlib.ComplexTestCase; 34 35 /** 36 * Test case for bug #107753#. 37 * 38 * <p>Bug #107753# "Java UNO: Proxies should implement intuitive semantics of 39 * equals and hashCode" requests that two proxies are equal iff they represent 40 * the same UNO object. This implies that if two proxies repsent the same UNO 41 * object, they must have the same hash code.</p> 42 */ 43 public final class Bug107753_Test extends ComplexTestCase { getTestObjectName()44 public String getTestObjectName() { 45 return getClass().getName(); 46 } 47 getTestMethodNames()48 public String[] getTestMethodNames() { 49 return new String[] { "test" }; 50 } 51 test()52 public void test() throws Exception { 53 TestBed t = new TestBed(); 54 assure("test", t.execute(new Provider(t), false, Client.class, 0)); 55 } 56 57 public static final class Client extends TestBed.Client { main(String[] args)58 public static void main(String[] args) { 59 new Client().execute(); 60 } 61 run(XComponentContext context)62 protected boolean run(XComponentContext context) throws Throwable { 63 boolean success = true; 64 XTransport transport = UnoRuntime.queryInterface( 65 XTransport.class, getBridge(context).getInstance("Transport")); 66 67 Object obj1a = new XType1() {}; 68 XType1 obj1b = UnoRuntime.queryInterface(XType1.class, obj1a); 69 success &= test("obj1a == obj1b", obj1a == obj1b); 70 71 Object obj2a = new XType2() {}; 72 XType2 obj2b = UnoRuntime.queryInterface(XType2.class, obj2a); 73 success &= test("obj2a == obj2b", obj2a == obj2b); 74 75 Object obj3a = transport.getType1(); 76 XType1 obj3b = UnoRuntime.queryInterface(XType1.class, obj3a); 77 success &= test( 78 "obj3a != obj3b; only meaningful as long as different proxy" 79 + " instances are used for different UNO interfaces of one UNO" 80 + " object", 81 obj3a != obj3b); 82 83 Object obj4a = transport.getType2(); 84 XType2 obj4b = UnoRuntime.queryInterface(XType2.class, obj4a); 85 success &= test( 86 "obj4a != obj4b; only meaningful as long as different proxy" 87 + " instances are used for different UNO interfaces of one UNO" 88 + " object", 89 obj4a != obj4b); 90 91 success &= test("UnoRuntime.areSame(null, null)", 92 UnoRuntime.areSame(null, null)); 93 success &= test("!UnoRuntime.areSame(null, obj1a)", 94 !UnoRuntime.areSame(null, obj1a)); 95 success &= test("!UnoRuntime.areSame(null, obj1b)", 96 !UnoRuntime.areSame(null, obj1b)); 97 success &= test("!UnoRuntime.areSame(null, obj2a)", 98 !UnoRuntime.areSame(null, obj2a)); 99 success &= test("!UnoRuntime.areSame(null, obj2b)", 100 !UnoRuntime.areSame(null, obj2b)); 101 success &= test("!UnoRuntime.areSame(null, obj3a)", 102 !UnoRuntime.areSame(null, obj3a)); 103 success &= test("!UnoRuntime.areSame(null, obj3b)", 104 !UnoRuntime.areSame(null, obj3b)); 105 success &= test("!UnoRuntime.areSame(null, obj4a)", 106 !UnoRuntime.areSame(null, obj4a)); 107 success &= test("!UnoRuntime.areSame(null, obj4b)", 108 !UnoRuntime.areSame(null, obj4b)); 109 110 success &= test("!obj1a.equals(null)", !obj1a.equals(null)); 111 success &= test("!UnoRuntime.areSame(obj1a, null)", 112 !UnoRuntime.areSame(obj1a, null)); 113 success &= test("obj1a.equals(obj1a)", obj1a.equals(obj1a)); 114 success &= test("UnoRuntime.areSame(obj1a, obj1a)", 115 UnoRuntime.areSame(obj1a, obj1a)); 116 success &= test("obj1a.equals(obj1b)", obj1a.equals(obj1b)); 117 success &= test("UnoRuntime.areSame(obj1a, obj1b)", 118 UnoRuntime.areSame(obj1a, obj1b)); 119 success &= test("!obj1a.equals(obj2a)", !obj1a.equals(obj2a)); 120 success &= test("!UnoRuntime.areSame(obj1a, obj2a)", 121 !UnoRuntime.areSame(obj1a, obj2a)); 122 success &= test("!obj1a.equals(obj2b)", !obj1a.equals(obj2b)); 123 success &= test("!UnoRuntime.areSame(obj1a, obj2b)", 124 !UnoRuntime.areSame(obj1a, obj2b)); 125 success &= test("!obj1a.equals(obj3a)", !obj1a.equals(obj3a)); 126 success &= test("!UnoRuntime.areSame(obj1a, obj3a)", 127 !UnoRuntime.areSame(obj1a, obj3a)); 128 success &= test("!obj1a.equals(obj3b)", !obj1a.equals(obj3b)); 129 success &= test("!UnoRuntime.areSame(obj1a, obj3b)", 130 !UnoRuntime.areSame(obj1a, obj3b)); 131 success &= test("!obj1a.equals(obj4a)", !obj1a.equals(obj4a)); 132 success &= test("!UnoRuntime.areSame(obj1a, obj4a)", 133 !UnoRuntime.areSame(obj1a, obj4a)); 134 success &= test("!obj1a.equals(obj4b)", !obj1a.equals(obj4b)); 135 success &= test("!UnoRuntime.areSame(obj1a, obj4b)", 136 !UnoRuntime.areSame(obj1a, obj4b)); 137 138 success &= test("!obj1b.equals(null)", !obj1b.equals(null)); 139 success &= test("!UnoRuntime.areSame(obj1b, null)", 140 !UnoRuntime.areSame(obj1b, null)); 141 success &= test("obj1b.equals(obj1a)", obj1b.equals(obj1a)); 142 success &= test("UnoRuntime.areSame(obj1b, obj1a)", 143 UnoRuntime.areSame(obj1b, obj1a)); 144 success &= test("obj1b.equals(obj1b)", obj1b.equals(obj1b)); 145 success &= test("UnoRuntime.areSame(obj1b, obj1b)", 146 UnoRuntime.areSame(obj1b, obj1b)); 147 success &= test("!obj1b.equals(obj2a)", !obj1b.equals(obj2a)); 148 success &= test("!UnoRuntime.areSame(obj1b, obj2a)", 149 !UnoRuntime.areSame(obj1b, obj2a)); 150 success &= test("!obj1b.equals(obj2b)", !obj1b.equals(obj2b)); 151 success &= test("!UnoRuntime.areSame(obj1b, obj2b)", 152 !UnoRuntime.areSame(obj1b, obj2b)); 153 success &= test("!obj1b.equals(obj3a)", !obj1b.equals(obj3a)); 154 success &= test("!UnoRuntime.areSame(obj1b, obj3a)", 155 !UnoRuntime.areSame(obj1b, obj3a)); 156 success &= test("!obj1b.equals(obj3b)", !obj1b.equals(obj3b)); 157 success &= test("!UnoRuntime.areSame(obj1b, obj3b)", 158 !UnoRuntime.areSame(obj1b, obj3b)); 159 success &= test("!obj1b.equals(obj4a)", !obj1b.equals(obj4a)); 160 success &= test("!UnoRuntime.areSame(obj1b, obj4a)", 161 !UnoRuntime.areSame(obj1b, obj4a)); 162 success &= test("!obj1b.equals(obj4b)", !obj1b.equals(obj4b)); 163 success &= test("!UnoRuntime.areSame(obj1b, obj4b)", 164 !UnoRuntime.areSame(obj1b, obj4b)); 165 166 success &= test("!obj2a.equals(null)", !obj2a.equals(null)); 167 success &= test("!UnoRuntime.areSame(obj2a, null)", 168 !UnoRuntime.areSame(obj2a, null)); 169 success &= test("!obj2a.equals(obj1a)", !obj2a.equals(obj1a)); 170 success &= test("!UnoRuntime.areSame(obj2a, obj1a)", 171 !UnoRuntime.areSame(obj2a, obj1a)); 172 success &= test("!obj2a.equals(obj1b)", !obj2a.equals(obj1b)); 173 success &= test("!UnoRuntime.areSame(obj2a, obj1b)", 174 !UnoRuntime.areSame(obj2a, obj1b)); 175 success &= test("obj2a.equals(obj2a)", obj2a.equals(obj2a)); 176 success &= test("UnoRuntime.areSame(obj2a, obj2a)", 177 UnoRuntime.areSame(obj2a, obj2a)); 178 success &= test("obj2a.equals(obj2b)", obj2a.equals(obj2b)); 179 success &= test("UnoRuntime.areSame(obj2a, obj2b)", 180 UnoRuntime.areSame(obj2a, obj2b)); 181 success &= test("!obj2a.equals(obj3a)", !obj2a.equals(obj3a)); 182 success &= test("!UnoRuntime.areSame(obj2a, obj3a)", 183 !UnoRuntime.areSame(obj2a, obj3a)); 184 success &= test("!obj2a.equals(obj3b)", !obj2a.equals(obj3b)); 185 success &= test("!UnoRuntime.areSame(obj2a, obj3b)", 186 !UnoRuntime.areSame(obj2a, obj3b)); 187 success &= test("!obj2a.equals(obj4a)", !obj2a.equals(obj4a)); 188 success &= test("!UnoRuntime.areSame(obj2a, obj4a)", 189 !UnoRuntime.areSame(obj2a, obj4a)); 190 success &= test("!obj2a.equals(obj4b)", !obj2a.equals(obj4b)); 191 success &= test("!UnoRuntime.areSame(obj2a, obj4b)", 192 !UnoRuntime.areSame(obj2a, obj4b)); 193 194 success &= test("!obj2b.equals(null)", !obj2b.equals(null)); 195 success &= test("!UnoRuntime.areSame(obj2b, null)", 196 !UnoRuntime.areSame(obj2b, null)); 197 success &= test("!obj2b.equals(obj1a)", !obj2b.equals(obj1a)); 198 success &= test("!UnoRuntime.areSame(obj2b, obj1a)", 199 !UnoRuntime.areSame(obj2b, obj1a)); 200 success &= test("!obj2b.equals(obj1b)", !obj2b.equals(obj1b)); 201 success &= test("!UnoRuntime.areSame(obj2b, obj1b)", 202 !UnoRuntime.areSame(obj2b, obj1b)); 203 success &= test("obj2b.equals(obj2a)", obj2b.equals(obj2a)); 204 success &= test("UnoRuntime.areSame(obj2b, obj2a)", 205 UnoRuntime.areSame(obj2b, obj2a)); 206 success &= test("obj2b.equals(obj2b)", obj2b.equals(obj2b)); 207 success &= test("UnoRuntime.areSame(obj2b, obj2b)", 208 UnoRuntime.areSame(obj2b, obj2b)); 209 success &= test("!obj2b.equals(obj3a)", !obj2b.equals(obj3a)); 210 success &= test("!UnoRuntime.areSame(obj2b, obj3a)", 211 !UnoRuntime.areSame(obj2b, obj3a)); 212 success &= test("!obj2b.equals(obj3b)", !obj2b.equals(obj3b)); 213 success &= test("!UnoRuntime.areSame(obj2b, obj3b)", 214 !UnoRuntime.areSame(obj2b, obj3b)); 215 success &= test("!obj2b.equals(obj4a)", !obj2b.equals(obj4a)); 216 success &= test("!UnoRuntime.areSame(obj2b, obj4a)", 217 !UnoRuntime.areSame(obj2b, obj4a)); 218 success &= test("!obj2b.equals(obj4b)", !obj2b.equals(obj4b)); 219 success &= test("!UnoRuntime.areSame(obj2b, obj4b)", 220 !UnoRuntime.areSame(obj2b, obj4b)); 221 222 success &= test("!obj3a.equals(null)", !obj3a.equals(null)); 223 success &= test("!UnoRuntime.areSame(obj3a, null)", 224 !UnoRuntime.areSame(obj3a, null)); 225 success &= test("!obj3a.equals(obj1a)", !obj3a.equals(obj1a)); 226 success &= test("!UnoRuntime.areSame(obj3a, obj1a)", 227 !UnoRuntime.areSame(obj3a, obj1a)); 228 success &= test("!obj3a.equals(obj1b)", !obj3a.equals(obj1b)); 229 success &= test("!UnoRuntime.areSame(obj3a, obj1b)", 230 !UnoRuntime.areSame(obj3a, obj1b)); 231 success &= test("!obj3a.equals(obj2a)", !obj3a.equals(obj2a)); 232 success &= test("!UnoRuntime.areSame(obj3a, obj2a)", 233 !UnoRuntime.areSame(obj3a, obj2a)); 234 success &= test("!obj3a.equals(obj2b)", !obj3a.equals(obj2b)); 235 success &= test("!UnoRuntime.areSame(obj3a, obj2b)", 236 !UnoRuntime.areSame(obj3a, obj2b)); 237 success &= test("obj3a.equals(obj3a)", obj3a.equals(obj3a)); 238 success &= test("UnoRuntime.areSame(obj3a, obj3a)", 239 UnoRuntime.areSame(obj3a, obj3a)); 240 success &= test("obj3a.equals(obj3b)", obj3a.equals(obj3b)); 241 success &= test("UnoRuntime.areSame(obj3a, obj3b)", 242 UnoRuntime.areSame(obj3a, obj3b)); 243 success &= test("!obj3a.equals(obj4a)", !obj3a.equals(obj4a)); 244 success &= test("!UnoRuntime.areSame(obj3a, obj4a)", 245 !UnoRuntime.areSame(obj3a, obj4a)); 246 success &= test("!obj3a.equals(obj4b)", !obj3a.equals(obj4b)); 247 success &= test("!UnoRuntime.areSame(obj3a, obj4b)", 248 !UnoRuntime.areSame(obj3a, obj4b)); 249 250 success &= test("!obj3b.equals(null)", !obj3b.equals(null)); 251 success &= test("!UnoRuntime.areSame(obj3b, null)", 252 !UnoRuntime.areSame(obj3b, null)); 253 success &= test("!obj3b.equals(obj1a)", !obj3b.equals(obj1a)); 254 success &= test("!UnoRuntime.areSame(obj3b, obj1a)", 255 !UnoRuntime.areSame(obj3b, obj1a)); 256 success &= test("!obj3b.equals(obj1b)", !obj3b.equals(obj1b)); 257 success &= test("!UnoRuntime.areSame(obj3b, obj1b)", 258 !UnoRuntime.areSame(obj3b, obj1b)); 259 success &= test("!obj3b.equals(obj2a)", !obj3b.equals(obj2a)); 260 success &= test("!UnoRuntime.areSame(obj3b, obj2a)", 261 !UnoRuntime.areSame(obj3b, obj2a)); 262 success &= test("!obj3b.equals(obj2b)", !obj3b.equals(obj2b)); 263 success &= test("!UnoRuntime.areSame(obj3b, obj2b)", 264 !UnoRuntime.areSame(obj3b, obj2b)); 265 success &= test("obj3b.equals(obj3a)", obj3b.equals(obj3a)); 266 success &= test("UnoRuntime.areSame(obj3b, obj3a)", 267 UnoRuntime.areSame(obj3b, obj3a)); 268 success &= test("obj3b.equals(obj3b)", obj3b.equals(obj3b)); 269 success &= test("UnoRuntime.areSame(obj3b, obj3b)", 270 UnoRuntime.areSame(obj3b, obj3b)); 271 success &= test("!obj3b.equals(obj4a)", !obj3b.equals(obj4a)); 272 success &= test("!UnoRuntime.areSame(obj3b, obj4a)", 273 !UnoRuntime.areSame(obj3b, obj4a)); 274 success &= test("!obj3b.equals(obj4b)", !obj3b.equals(obj4b)); 275 success &= test("!UnoRuntime.areSame(obj3b, obj4b)", 276 !UnoRuntime.areSame(obj3b, obj4b)); 277 278 success &= test("!obj4a.equals(null)", !obj4a.equals(null)); 279 success &= test("!UnoRuntime.areSame(obj4a, null)", 280 !UnoRuntime.areSame(obj4a, null)); 281 success &= test("!obj4a.equals(obj1a)", !obj4a.equals(obj1a)); 282 success &= test("!UnoRuntime.areSame(obj4a, obj1a)", 283 !UnoRuntime.areSame(obj4a, obj1a)); 284 success &= test("!obj4a.equals(obj1b)", !obj4a.equals(obj1b)); 285 success &= test("!UnoRuntime.areSame(obj4a, obj1b)", 286 !UnoRuntime.areSame(obj4a, obj1b)); 287 success &= test("!obj4a.equals(obj2a)", !obj4a.equals(obj2a)); 288 success &= test("!UnoRuntime.areSame(obj4a, obj2a)", 289 !UnoRuntime.areSame(obj4a, obj2a)); 290 success &= test("!obj4a.equals(obj2b)", !obj4a.equals(obj2b)); 291 success &= test("!UnoRuntime.areSame(obj4a, obj2b)", 292 !UnoRuntime.areSame(obj4a, obj2b)); 293 success &= test("!obj4a.equals(obj3a)", !obj4a.equals(obj3a)); 294 success &= test("!UnoRuntime.areSame(obj4a, obj3a)", 295 !UnoRuntime.areSame(obj4a, obj3a)); 296 success &= test("!obj4a.equals(obj3b)", !obj4a.equals(obj3b)); 297 success &= test("!UnoRuntime.areSame(obj4a, obj3b)", 298 !UnoRuntime.areSame(obj4a, obj3b)); 299 success &= test("obj4a.equals(obj4a)", obj4a.equals(obj4a)); 300 success &= test("UnoRuntime.areSame(obj4a, obj4a)", 301 UnoRuntime.areSame(obj4a, obj4a)); 302 success &= test("obj4a.equals(obj4b)", obj4a.equals(obj4b)); 303 success &= test("UnoRuntime.areSame(obj4a, obj4b)", 304 UnoRuntime.areSame(obj4a, obj4b)); 305 306 success &= test("!obj4b.equals(null)", !obj4b.equals(null)); 307 success &= test("!UnoRuntime.areSame(obj4b, null)", 308 !UnoRuntime.areSame(obj4b, null)); 309 success &= test("!obj4b.equals(obj1a)", !obj4b.equals(obj1a)); 310 success &= test("!UnoRuntime.areSame(obj4b, obj1a)", 311 !UnoRuntime.areSame(obj4b, obj1a)); 312 success &= test("!obj4b.equals(obj1b)", !obj4b.equals(obj1b)); 313 success &= test("!UnoRuntime.areSame(obj4b, obj1b)", 314 !UnoRuntime.areSame(obj4b, obj1b)); 315 success &= test("!obj4b.equals(obj2a)", !obj4b.equals(obj2a)); 316 success &= test("!UnoRuntime.areSame(obj4b, obj2a)", 317 !UnoRuntime.areSame(obj4b, obj2a)); 318 success &= test("!obj4b.equals(obj2b)", !obj4b.equals(obj2b)); 319 success &= test("!UnoRuntime.areSame(obj4b, obj2b)", 320 !UnoRuntime.areSame(obj4b, obj2b)); 321 success &= test("!obj4b.equals(obj3a)", !obj4b.equals(obj3a)); 322 success &= test("!UnoRuntime.areSame(obj4b, obj3a)", 323 !UnoRuntime.areSame(obj4b, obj3a)); 324 success &= test("!obj4b.equals(obj3b)", !obj4b.equals(obj3b)); 325 success &= test("!UnoRuntime.areSame(obj4b, obj3b)", 326 !UnoRuntime.areSame(obj4b, obj3b)); 327 success &= test("obj4b.equals(obj4a)", obj4b.equals(obj4a)); 328 success &= test("UnoRuntime.areSame(obj4b, obj4a)", 329 UnoRuntime.areSame(obj4b, obj4a)); 330 success &= test("obj4b.equals(obj4b)", obj4b.equals(obj4b)); 331 success &= test("UnoRuntime.areSame(obj4b, obj4b)", 332 UnoRuntime.areSame(obj4b, obj4b)); 333 334 success &= test("obj1a.hashCode() == obj1b.hashCode()", 335 obj1a.hashCode() == obj1b.hashCode()); 336 success &= test("obj2a.hashCode() == obj2b.hashCode()", 337 obj2a.hashCode() == obj2b.hashCode()); 338 success &= test("obj3a.hashCode() == obj3b.hashCode()", 339 obj3a.hashCode() == obj3b.hashCode()); 340 success &= test("obj4a.hashCode() == obj4b.hashCode()", 341 obj4a.hashCode() == obj4b.hashCode()); 342 343 return success; 344 } 345 test(String message, boolean condition)346 private static boolean test(String message, boolean condition) { 347 if (!condition) { 348 System.err.println("Failed: " + message); 349 } 350 return condition; 351 } 352 } 353 354 private static final class Provider implements XInstanceProvider { Provider(TestBed testBed)355 public Provider(TestBed testBed) { 356 this.testBed = testBed; 357 } 358 getInstance(String instanceName)359 public Object getInstance(String instanceName) { 360 return new XTransport() { 361 public Object getType1() { 362 return new XType1() {}; 363 } 364 365 public Object getType2() { 366 return new XType2() {}; 367 } 368 }; 369 } 370 371 private final TestBed testBed; 372 } 373 374 public interface XTransport extends XInterface { 375 Object getType1(); 376 377 Object getType2(); 378 379 TypeInfo[] UNOTYPEINFO = { new MethodTypeInfo("getType1", 0, 0), 380 new MethodTypeInfo("getType2", 1, 0) }; 381 } 382 383 public interface XType1 extends XInterface { 384 TypeInfo[] UNOTYPEINFO = null; 385 } 386 387 public interface XType2 extends XInterface { 388 TypeInfo[] UNOTYPEINFO = null; 389 } 390 } 391