tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / javaunohelper / test / com / sun / star / lib / uno / helper / WeakBase_Test.java
bloba649f1682ffc9fc36f3b303ee085d4e46cbfe64c
1 /*
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 com.sun.star.lib.uno.helper;
21 import com.sun.star.bridge.XBridgeSupplier2;
22 import com.sun.star.lang.XTypeProvider;
23 import com.sun.star.uno.XAdapter;
24 import com.sun.star.uno.Type;
25 import com.sun.star.uno.XReference;
26 import com.sun.star.uno.XWeak;
28 import java.util.logging.Level;
29 import java.util.logging.Logger;
31 import static org.junit.Assert.assertArrayEquals;
32 import static org.junit.Assert.assertEquals;
33 import static org.junit.Assert.assertNull;
34 import static org.junit.Assert.assertSame;
35 import static org.junit.Assert.assertTrue;
36 import org.junit.Test;
37 import util.WaitUnreachable;
39 public class WeakBase_Test
42 private static final Logger logger = Logger.getLogger(WeakBase_Test.class.getName());
44 @Test public void getTypes() throws Exception
46 logger.log(Level.INFO, "Testing WeakBase.getTypes");
47 SomeClass comp= new SomeClass();
49 Type[] types= comp.getTypes(); //XWeak,XTypeProvider,XReference,XBridgeSupplier2
50 assertEquals(types.length, 4);
51 for (int c= 0; c < types.length; c++)
53 boolean result= false;
54 if (types[c].equals( new Type( XWeak.class)))
55 result= true;
56 else if (types[c].equals(new Type(XTypeProvider.class)))
57 result= true;
58 else if (types[c].equals(new Type(XReference.class)))
59 result= true;
60 else if (types[c].equals(new Type(XBridgeSupplier2.class)))
61 result= true;
62 assertTrue(result);
65 Foo1 f1= new Foo1();
66 Foo1 f2= new Foo1();
67 Type[] t1= f1.getTypes();
68 Type[] t2= f2.getTypes();
69 assertArrayEquals(t1, t2);
70 new Foo2();
73 @Test public void queryAdapter() throws Exception
75 logger.log(Level.INFO, "Testing WeakBase.queryAdapter, XAdapter tests");
76 SomeClass comp= new SomeClass();
78 XAdapter adapter= comp.queryAdapter();
79 MyRef aRef1= new MyRef();
80 MyRef aRef2= new MyRef();
81 adapter.addReference(aRef1);
82 adapter.addReference(aRef2);
84 assertSame(adapter.queryAdapted(), comp);
85 WaitUnreachable u = new WaitUnreachable(comp);
86 comp= null;
87 u.waitUnreachable();
88 assertEquals(aRef1.nDisposeCalled, 1);
89 assertEquals(aRef2.nDisposeCalled, 1);
90 assertNull(adapter.queryAdapted());
91 adapter.removeReference(aRef1); // should not do any harm
92 adapter.removeReference(aRef2);
94 comp= new SomeClass();
95 adapter= comp.queryAdapter();
96 aRef1.nDisposeCalled= 0;
97 aRef2.nDisposeCalled= 0;
99 adapter.addReference(aRef1);
100 adapter.addReference(aRef2);
102 adapter.removeReference(aRef1);
103 u = new WaitUnreachable(comp);
104 comp= null;
105 u.waitUnreachable();
106 assertEquals(aRef1.nDisposeCalled, 0);
107 assertEquals(aRef2.nDisposeCalled, 1);
111 class OtherClass extends WeakBase implements XBridgeSupplier2
114 public Object createBridge(Object obj, byte[] values, short param, short param3) throws com.sun.star.lang.IllegalArgumentException
116 return null;
120 class SomeClass extends OtherClass implements XReference
123 public void dispose()
129 class MyRef implements XReference
131 int nDisposeCalled;
133 public void dispose()
135 nDisposeCalled++;
139 class Foo1 extends WeakBase
143 class Foo2 extends WeakBase
147 class Foo3 extends Foo1