2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package test
.java_remote
;
21 import com
.sun
.star
.bridge
.XInstanceProvider
;
22 import com
.sun
.star
.lib
.uno
.typeinfo
.MethodTypeInfo
;
23 import com
.sun
.star
.lib
.uno
.typeinfo
.TypeInfo
;
24 import com
.sun
.star
.uno
.UnoRuntime
;
25 import com
.sun
.star
.uno
.XComponentContext
;
26 import com
.sun
.star
.uno
.XInterface
;
27 import complexlib
.ComplexTestCase
;
28 import test
.lib
.TestBed
;
31 * Test case for bug #107753#.
33 * <p>Bug #107753# "Java UNO: Proxies should implement intuitive semantics of
34 * equals and hashCode" requests that two proxies are equal iff they represent
35 * the same UNO object. This implies that if two proxies repsent the same UNO
36 * object, they must have the same hash code.</p>
38 public final class Bug107753_Test
extends ComplexTestCase
{
39 public String
getTestObjectName() {
40 return getClass().getName();
43 public String
[] getTestMethodNames() {
44 return new String
[] { "test" };
47 public void test() throws Exception
{
48 TestBed t
= new TestBed();
49 assure("test", t
.execute(new Provider(t
), false, Client
.class, 0));
52 public static final class Client
extends TestBed
.Client
{
53 public static void main(String
[] args
) {
54 new Client().execute();
57 protected boolean run(XComponentContext context
) throws Throwable
{
58 boolean success
= true;
59 XTransport transport
= UnoRuntime
.queryInterface(
60 XTransport
.class, getBridge(context
).getInstance("Transport"));
62 Object obj1a
= new XType1() {};
63 XType1 obj1b
= UnoRuntime
.queryInterface(XType1
.class, obj1a
);
64 success
&= test("obj1a == obj1b", obj1a
== obj1b
);
66 Object obj2a
= new XType2() {};
67 XType2 obj2b
= UnoRuntime
.queryInterface(XType2
.class, obj2a
);
68 success
&= test("obj2a == obj2b", obj2a
== obj2b
);
70 Object obj3a
= transport
.getType1();
71 XType1 obj3b
= UnoRuntime
.queryInterface(XType1
.class, obj3a
);
73 "obj3a != obj3b; only meaningful as long as different proxy"
74 + " instances are used for different UNO interfaces of one UNO"
78 Object obj4a
= transport
.getType2();
79 XType2 obj4b
= UnoRuntime
.queryInterface(XType2
.class, obj4a
);
81 "obj4a != obj4b; only meaningful as long as different proxy"
82 + " instances are used for different UNO interfaces of one UNO"
86 success
&= test("UnoRuntime.areSame(null, null)",
87 UnoRuntime
.areSame(null, null));
88 success
&= test("!UnoRuntime.areSame(null, obj1a)",
89 !UnoRuntime
.areSame(null, obj1a
));
90 success
&= test("!UnoRuntime.areSame(null, obj1b)",
91 !UnoRuntime
.areSame(null, obj1b
));
92 success
&= test("!UnoRuntime.areSame(null, obj2a)",
93 !UnoRuntime
.areSame(null, obj2a
));
94 success
&= test("!UnoRuntime.areSame(null, obj2b)",
95 !UnoRuntime
.areSame(null, obj2b
));
96 success
&= test("!UnoRuntime.areSame(null, obj3a)",
97 !UnoRuntime
.areSame(null, obj3a
));
98 success
&= test("!UnoRuntime.areSame(null, obj3b)",
99 !UnoRuntime
.areSame(null, obj3b
));
100 success
&= test("!UnoRuntime.areSame(null, obj4a)",
101 !UnoRuntime
.areSame(null, obj4a
));
102 success
&= test("!UnoRuntime.areSame(null, obj4b)",
103 !UnoRuntime
.areSame(null, obj4b
));
105 success
&= test("!obj1a.equals(null)", !obj1a
.equals(null));
106 success
&= test("!UnoRuntime.areSame(obj1a, null)",
107 !UnoRuntime
.areSame(obj1a
, null));
108 success
&= test("obj1a.equals(obj1a)", obj1a
.equals(obj1a
));
109 success
&= test("UnoRuntime.areSame(obj1a, obj1a)",
110 UnoRuntime
.areSame(obj1a
, obj1a
));
111 success
&= test("obj1a.equals(obj1b)", obj1a
.equals(obj1b
));
112 success
&= test("UnoRuntime.areSame(obj1a, obj1b)",
113 UnoRuntime
.areSame(obj1a
, obj1b
));
114 success
&= test("!obj1a.equals(obj2a)", !obj1a
.equals(obj2a
));
115 success
&= test("!UnoRuntime.areSame(obj1a, obj2a)",
116 !UnoRuntime
.areSame(obj1a
, obj2a
));
117 success
&= test("!obj1a.equals(obj2b)", !obj1a
.equals(obj2b
));
118 success
&= test("!UnoRuntime.areSame(obj1a, obj2b)",
119 !UnoRuntime
.areSame(obj1a
, obj2b
));
120 success
&= test("!obj1a.equals(obj3a)", !obj1a
.equals(obj3a
));
121 success
&= test("!UnoRuntime.areSame(obj1a, obj3a)",
122 !UnoRuntime
.areSame(obj1a
, obj3a
));
123 success
&= test("!obj1a.equals(obj3b)", !obj1a
.equals(obj3b
));
124 success
&= test("!UnoRuntime.areSame(obj1a, obj3b)",
125 !UnoRuntime
.areSame(obj1a
, obj3b
));
126 success
&= test("!obj1a.equals(obj4a)", !obj1a
.equals(obj4a
));
127 success
&= test("!UnoRuntime.areSame(obj1a, obj4a)",
128 !UnoRuntime
.areSame(obj1a
, obj4a
));
129 success
&= test("!obj1a.equals(obj4b)", !obj1a
.equals(obj4b
));
130 success
&= test("!UnoRuntime.areSame(obj1a, obj4b)",
131 !UnoRuntime
.areSame(obj1a
, obj4b
));
133 success
&= test("!obj1b.equals(null)", !obj1b
.equals(null));
134 success
&= test("!UnoRuntime.areSame(obj1b, null)",
135 !UnoRuntime
.areSame(obj1b
, null));
136 success
&= test("obj1b.equals(obj1a)", obj1b
.equals(obj1a
));
137 success
&= test("UnoRuntime.areSame(obj1b, obj1a)",
138 UnoRuntime
.areSame(obj1b
, obj1a
));
139 success
&= test("obj1b.equals(obj1b)", obj1b
.equals(obj1b
));
140 success
&= test("UnoRuntime.areSame(obj1b, obj1b)",
141 UnoRuntime
.areSame(obj1b
, obj1b
));
142 success
&= test("!obj1b.equals(obj2a)", !obj1b
.equals(obj2a
));
143 success
&= test("!UnoRuntime.areSame(obj1b, obj2a)",
144 !UnoRuntime
.areSame(obj1b
, obj2a
));
145 success
&= test("!obj1b.equals(obj2b)", !obj1b
.equals(obj2b
));
146 success
&= test("!UnoRuntime.areSame(obj1b, obj2b)",
147 !UnoRuntime
.areSame(obj1b
, obj2b
));
148 success
&= test("!obj1b.equals(obj3a)", !obj1b
.equals(obj3a
));
149 success
&= test("!UnoRuntime.areSame(obj1b, obj3a)",
150 !UnoRuntime
.areSame(obj1b
, obj3a
));
151 success
&= test("!obj1b.equals(obj3b)", !obj1b
.equals(obj3b
));
152 success
&= test("!UnoRuntime.areSame(obj1b, obj3b)",
153 !UnoRuntime
.areSame(obj1b
, obj3b
));
154 success
&= test("!obj1b.equals(obj4a)", !obj1b
.equals(obj4a
));
155 success
&= test("!UnoRuntime.areSame(obj1b, obj4a)",
156 !UnoRuntime
.areSame(obj1b
, obj4a
));
157 success
&= test("!obj1b.equals(obj4b)", !obj1b
.equals(obj4b
));
158 success
&= test("!UnoRuntime.areSame(obj1b, obj4b)",
159 !UnoRuntime
.areSame(obj1b
, obj4b
));
161 success
&= test("!obj2a.equals(null)", !obj2a
.equals(null));
162 success
&= test("!UnoRuntime.areSame(obj2a, null)",
163 !UnoRuntime
.areSame(obj2a
, null));
164 success
&= test("!obj2a.equals(obj1a)", !obj2a
.equals(obj1a
));
165 success
&= test("!UnoRuntime.areSame(obj2a, obj1a)",
166 !UnoRuntime
.areSame(obj2a
, obj1a
));
167 success
&= test("!obj2a.equals(obj1b)", !obj2a
.equals(obj1b
));
168 success
&= test("!UnoRuntime.areSame(obj2a, obj1b)",
169 !UnoRuntime
.areSame(obj2a
, obj1b
));
170 success
&= test("obj2a.equals(obj2a)", obj2a
.equals(obj2a
));
171 success
&= test("UnoRuntime.areSame(obj2a, obj2a)",
172 UnoRuntime
.areSame(obj2a
, obj2a
));
173 success
&= test("obj2a.equals(obj2b)", obj2a
.equals(obj2b
));
174 success
&= test("UnoRuntime.areSame(obj2a, obj2b)",
175 UnoRuntime
.areSame(obj2a
, obj2b
));
176 success
&= test("!obj2a.equals(obj3a)", !obj2a
.equals(obj3a
));
177 success
&= test("!UnoRuntime.areSame(obj2a, obj3a)",
178 !UnoRuntime
.areSame(obj2a
, obj3a
));
179 success
&= test("!obj2a.equals(obj3b)", !obj2a
.equals(obj3b
));
180 success
&= test("!UnoRuntime.areSame(obj2a, obj3b)",
181 !UnoRuntime
.areSame(obj2a
, obj3b
));
182 success
&= test("!obj2a.equals(obj4a)", !obj2a
.equals(obj4a
));
183 success
&= test("!UnoRuntime.areSame(obj2a, obj4a)",
184 !UnoRuntime
.areSame(obj2a
, obj4a
));
185 success
&= test("!obj2a.equals(obj4b)", !obj2a
.equals(obj4b
));
186 success
&= test("!UnoRuntime.areSame(obj2a, obj4b)",
187 !UnoRuntime
.areSame(obj2a
, obj4b
));
189 success
&= test("!obj2b.equals(null)", !obj2b
.equals(null));
190 success
&= test("!UnoRuntime.areSame(obj2b, null)",
191 !UnoRuntime
.areSame(obj2b
, null));
192 success
&= test("!obj2b.equals(obj1a)", !obj2b
.equals(obj1a
));
193 success
&= test("!UnoRuntime.areSame(obj2b, obj1a)",
194 !UnoRuntime
.areSame(obj2b
, obj1a
));
195 success
&= test("!obj2b.equals(obj1b)", !obj2b
.equals(obj1b
));
196 success
&= test("!UnoRuntime.areSame(obj2b, obj1b)",
197 !UnoRuntime
.areSame(obj2b
, obj1b
));
198 success
&= test("obj2b.equals(obj2a)", obj2b
.equals(obj2a
));
199 success
&= test("UnoRuntime.areSame(obj2b, obj2a)",
200 UnoRuntime
.areSame(obj2b
, obj2a
));
201 success
&= test("obj2b.equals(obj2b)", obj2b
.equals(obj2b
));
202 success
&= test("UnoRuntime.areSame(obj2b, obj2b)",
203 UnoRuntime
.areSame(obj2b
, obj2b
));
204 success
&= test("!obj2b.equals(obj3a)", !obj2b
.equals(obj3a
));
205 success
&= test("!UnoRuntime.areSame(obj2b, obj3a)",
206 !UnoRuntime
.areSame(obj2b
, obj3a
));
207 success
&= test("!obj2b.equals(obj3b)", !obj2b
.equals(obj3b
));
208 success
&= test("!UnoRuntime.areSame(obj2b, obj3b)",
209 !UnoRuntime
.areSame(obj2b
, obj3b
));
210 success
&= test("!obj2b.equals(obj4a)", !obj2b
.equals(obj4a
));
211 success
&= test("!UnoRuntime.areSame(obj2b, obj4a)",
212 !UnoRuntime
.areSame(obj2b
, obj4a
));
213 success
&= test("!obj2b.equals(obj4b)", !obj2b
.equals(obj4b
));
214 success
&= test("!UnoRuntime.areSame(obj2b, obj4b)",
215 !UnoRuntime
.areSame(obj2b
, obj4b
));
217 success
&= test("!obj3a.equals(null)", !obj3a
.equals(null));
218 success
&= test("!UnoRuntime.areSame(obj3a, null)",
219 !UnoRuntime
.areSame(obj3a
, null));
220 success
&= test("!obj3a.equals(obj1a)", !obj3a
.equals(obj1a
));
221 success
&= test("!UnoRuntime.areSame(obj3a, obj1a)",
222 !UnoRuntime
.areSame(obj3a
, obj1a
));
223 success
&= test("!obj3a.equals(obj1b)", !obj3a
.equals(obj1b
));
224 success
&= test("!UnoRuntime.areSame(obj3a, obj1b)",
225 !UnoRuntime
.areSame(obj3a
, obj1b
));
226 success
&= test("!obj3a.equals(obj2a)", !obj3a
.equals(obj2a
));
227 success
&= test("!UnoRuntime.areSame(obj3a, obj2a)",
228 !UnoRuntime
.areSame(obj3a
, obj2a
));
229 success
&= test("!obj3a.equals(obj2b)", !obj3a
.equals(obj2b
));
230 success
&= test("!UnoRuntime.areSame(obj3a, obj2b)",
231 !UnoRuntime
.areSame(obj3a
, obj2b
));
232 success
&= test("obj3a.equals(obj3a)", obj3a
.equals(obj3a
));
233 success
&= test("UnoRuntime.areSame(obj3a, obj3a)",
234 UnoRuntime
.areSame(obj3a
, obj3a
));
235 success
&= test("obj3a.equals(obj3b)", obj3a
.equals(obj3b
));
236 success
&= test("UnoRuntime.areSame(obj3a, obj3b)",
237 UnoRuntime
.areSame(obj3a
, obj3b
));
238 success
&= test("!obj3a.equals(obj4a)", !obj3a
.equals(obj4a
));
239 success
&= test("!UnoRuntime.areSame(obj3a, obj4a)",
240 !UnoRuntime
.areSame(obj3a
, obj4a
));
241 success
&= test("!obj3a.equals(obj4b)", !obj3a
.equals(obj4b
));
242 success
&= test("!UnoRuntime.areSame(obj3a, obj4b)",
243 !UnoRuntime
.areSame(obj3a
, obj4b
));
245 success
&= test("!obj3b.equals(null)", !obj3b
.equals(null));
246 success
&= test("!UnoRuntime.areSame(obj3b, null)",
247 !UnoRuntime
.areSame(obj3b
, null));
248 success
&= test("!obj3b.equals(obj1a)", !obj3b
.equals(obj1a
));
249 success
&= test("!UnoRuntime.areSame(obj3b, obj1a)",
250 !UnoRuntime
.areSame(obj3b
, obj1a
));
251 success
&= test("!obj3b.equals(obj1b)", !obj3b
.equals(obj1b
));
252 success
&= test("!UnoRuntime.areSame(obj3b, obj1b)",
253 !UnoRuntime
.areSame(obj3b
, obj1b
));
254 success
&= test("!obj3b.equals(obj2a)", !obj3b
.equals(obj2a
));
255 success
&= test("!UnoRuntime.areSame(obj3b, obj2a)",
256 !UnoRuntime
.areSame(obj3b
, obj2a
));
257 success
&= test("!obj3b.equals(obj2b)", !obj3b
.equals(obj2b
));
258 success
&= test("!UnoRuntime.areSame(obj3b, obj2b)",
259 !UnoRuntime
.areSame(obj3b
, obj2b
));
260 success
&= test("obj3b.equals(obj3a)", obj3b
.equals(obj3a
));
261 success
&= test("UnoRuntime.areSame(obj3b, obj3a)",
262 UnoRuntime
.areSame(obj3b
, obj3a
));
263 success
&= test("obj3b.equals(obj3b)", obj3b
.equals(obj3b
));
264 success
&= test("UnoRuntime.areSame(obj3b, obj3b)",
265 UnoRuntime
.areSame(obj3b
, obj3b
));
266 success
&= test("!obj3b.equals(obj4a)", !obj3b
.equals(obj4a
));
267 success
&= test("!UnoRuntime.areSame(obj3b, obj4a)",
268 !UnoRuntime
.areSame(obj3b
, obj4a
));
269 success
&= test("!obj3b.equals(obj4b)", !obj3b
.equals(obj4b
));
270 success
&= test("!UnoRuntime.areSame(obj3b, obj4b)",
271 !UnoRuntime
.areSame(obj3b
, obj4b
));
273 success
&= test("!obj4a.equals(null)", !obj4a
.equals(null));
274 success
&= test("!UnoRuntime.areSame(obj4a, null)",
275 !UnoRuntime
.areSame(obj4a
, null));
276 success
&= test("!obj4a.equals(obj1a)", !obj4a
.equals(obj1a
));
277 success
&= test("!UnoRuntime.areSame(obj4a, obj1a)",
278 !UnoRuntime
.areSame(obj4a
, obj1a
));
279 success
&= test("!obj4a.equals(obj1b)", !obj4a
.equals(obj1b
));
280 success
&= test("!UnoRuntime.areSame(obj4a, obj1b)",
281 !UnoRuntime
.areSame(obj4a
, obj1b
));
282 success
&= test("!obj4a.equals(obj2a)", !obj4a
.equals(obj2a
));
283 success
&= test("!UnoRuntime.areSame(obj4a, obj2a)",
284 !UnoRuntime
.areSame(obj4a
, obj2a
));
285 success
&= test("!obj4a.equals(obj2b)", !obj4a
.equals(obj2b
));
286 success
&= test("!UnoRuntime.areSame(obj4a, obj2b)",
287 !UnoRuntime
.areSame(obj4a
, obj2b
));
288 success
&= test("!obj4a.equals(obj3a)", !obj4a
.equals(obj3a
));
289 success
&= test("!UnoRuntime.areSame(obj4a, obj3a)",
290 !UnoRuntime
.areSame(obj4a
, obj3a
));
291 success
&= test("!obj4a.equals(obj3b)", !obj4a
.equals(obj3b
));
292 success
&= test("!UnoRuntime.areSame(obj4a, obj3b)",
293 !UnoRuntime
.areSame(obj4a
, obj3b
));
294 success
&= test("obj4a.equals(obj4a)", obj4a
.equals(obj4a
));
295 success
&= test("UnoRuntime.areSame(obj4a, obj4a)",
296 UnoRuntime
.areSame(obj4a
, obj4a
));
297 success
&= test("obj4a.equals(obj4b)", obj4a
.equals(obj4b
));
298 success
&= test("UnoRuntime.areSame(obj4a, obj4b)",
299 UnoRuntime
.areSame(obj4a
, obj4b
));
301 success
&= test("!obj4b.equals(null)", !obj4b
.equals(null));
302 success
&= test("!UnoRuntime.areSame(obj4b, null)",
303 !UnoRuntime
.areSame(obj4b
, null));
304 success
&= test("!obj4b.equals(obj1a)", !obj4b
.equals(obj1a
));
305 success
&= test("!UnoRuntime.areSame(obj4b, obj1a)",
306 !UnoRuntime
.areSame(obj4b
, obj1a
));
307 success
&= test("!obj4b.equals(obj1b)", !obj4b
.equals(obj1b
));
308 success
&= test("!UnoRuntime.areSame(obj4b, obj1b)",
309 !UnoRuntime
.areSame(obj4b
, obj1b
));
310 success
&= test("!obj4b.equals(obj2a)", !obj4b
.equals(obj2a
));
311 success
&= test("!UnoRuntime.areSame(obj4b, obj2a)",
312 !UnoRuntime
.areSame(obj4b
, obj2a
));
313 success
&= test("!obj4b.equals(obj2b)", !obj4b
.equals(obj2b
));
314 success
&= test("!UnoRuntime.areSame(obj4b, obj2b)",
315 !UnoRuntime
.areSame(obj4b
, obj2b
));
316 success
&= test("!obj4b.equals(obj3a)", !obj4b
.equals(obj3a
));
317 success
&= test("!UnoRuntime.areSame(obj4b, obj3a)",
318 !UnoRuntime
.areSame(obj4b
, obj3a
));
319 success
&= test("!obj4b.equals(obj3b)", !obj4b
.equals(obj3b
));
320 success
&= test("!UnoRuntime.areSame(obj4b, obj3b)",
321 !UnoRuntime
.areSame(obj4b
, obj3b
));
322 success
&= test("obj4b.equals(obj4a)", obj4b
.equals(obj4a
));
323 success
&= test("UnoRuntime.areSame(obj4b, obj4a)",
324 UnoRuntime
.areSame(obj4b
, obj4a
));
325 success
&= test("obj4b.equals(obj4b)", obj4b
.equals(obj4b
));
326 success
&= test("UnoRuntime.areSame(obj4b, obj4b)",
327 UnoRuntime
.areSame(obj4b
, obj4b
));
329 success
&= test("obj1a.hashCode() == obj1b.hashCode()",
330 obj1a
.hashCode() == obj1b
.hashCode());
331 success
&= test("obj2a.hashCode() == obj2b.hashCode()",
332 obj2a
.hashCode() == obj2b
.hashCode());
333 success
&= test("obj3a.hashCode() == obj3b.hashCode()",
334 obj3a
.hashCode() == obj3b
.hashCode());
335 success
&= test("obj4a.hashCode() == obj4b.hashCode()",
336 obj4a
.hashCode() == obj4b
.hashCode());
341 private static boolean test(String message
, boolean condition
) {
343 System
.err
.println("Failed: " + message
);
349 private static final class Provider
implements XInstanceProvider
{
350 public Provider(TestBed testBed
) {
351 this.testBed
= testBed
;
354 public Object
getInstance(String instanceName
) {
355 return new XTransport() {
356 public Object
getType1() {
357 return new XType1() {};
360 public Object
getType2() {
361 return new XType2() {};
366 private final TestBed testBed
;
369 public interface XTransport
extends XInterface
{
374 TypeInfo
[] UNOTYPEINFO
= { new MethodTypeInfo("getType1", 0, 0),
375 new MethodTypeInfo("getType2", 1, 0) };
378 public interface XType1
extends XInterface
{
379 TypeInfo
[] UNOTYPEINFO
= null;
382 public interface XType2
extends XInterface
{
383 TypeInfo
[] UNOTYPEINFO
= null;