15c44d1b3SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 35c44d1b3SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 45c44d1b3SAndrew Rist * or more contributor license agreements. See the NOTICE file 55c44d1b3SAndrew Rist * distributed with this work for additional information 65c44d1b3SAndrew Rist * regarding copyright ownership. The ASF licenses this file 75c44d1b3SAndrew Rist * to you under the Apache License, Version 2.0 (the 85c44d1b3SAndrew Rist * "License"); you may not use this file except in compliance 95c44d1b3SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 115c44d1b3SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 135c44d1b3SAndrew Rist * Unless required by applicable law or agreed to in writing, 145c44d1b3SAndrew Rist * software distributed under the License is distributed on an 155c44d1b3SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165c44d1b3SAndrew Rist * KIND, either express or implied. See the License for the 175c44d1b3SAndrew Rist * specific language governing permissions and limitations 185c44d1b3SAndrew Rist * under the License. 19cdf0e10cSrcweir * 205c44d1b3SAndrew Rist *************************************************************/ 215c44d1b3SAndrew Rist 225c44d1b3SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package testtools.servicetests; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import util.WaitUnreachable; 28cdf0e10cSrcweir 29*6e57475aSDamjan Jovanovic import static org.junit.Assert.*; 30cdf0e10cSrcweir 31*6e57475aSDamjan Jovanovic public abstract class TestBase { runTest()32*6e57475aSDamjan Jovanovic public final void runTest() throws Exception { 33cdf0e10cSrcweir TestServiceFactory factory = getTestServiceFactory(); 34cdf0e10cSrcweir TestService2 t = UnoRuntime.queryInterface( 35cdf0e10cSrcweir TestService2.class, factory.get()); 36*6e57475aSDamjan Jovanovic assertTrue(t != null); 37*6e57475aSDamjan Jovanovic assertTrue(UnoRuntime.queryInterface(TestService1.class, t) == t); 38*6e57475aSDamjan Jovanovic assertTrue(UnoRuntime.queryInterface(XTestService1.class, t) == t); 39*6e57475aSDamjan Jovanovic assertTrue(UnoRuntime.queryInterface(XTestService2.class, t) == t); 40*6e57475aSDamjan Jovanovic assertTrue(t.fn1() == 1); 41*6e57475aSDamjan Jovanovic assertTrue(t.getProp1() == 1); 42cdf0e10cSrcweir t.setProp1(0); 43*6e57475aSDamjan Jovanovic assertTrue(t.getProp1() == 0); 44*6e57475aSDamjan Jovanovic assertTrue(t.getProp2() == 2); 45cdf0e10cSrcweir /*try { 46cdf0e10cSrcweir t.getProp3Void(); 47*6e57475aSDamjan Jovanovic fail(); 48cdf0e10cSrcweir } catch (VoidPropertyException e) { 49cdf0e10cSrcweir }*/ 50*6e57475aSDamjan Jovanovic assertTrue(t.getProp3Long() == 3); 51cdf0e10cSrcweir /*try { 52cdf0e10cSrcweir t.getProp4None(); 53*6e57475aSDamjan Jovanovic fail(); 54cdf0e10cSrcweir } catch (OptionalPropertyException e) { 55cdf0e10cSrcweir }*/ 56*6e57475aSDamjan Jovanovic assertTrue(t.getProp4Long() == 4); 57cdf0e10cSrcweir /*try { 58cdf0e10cSrcweir t.getProp5None(); 59*6e57475aSDamjan Jovanovic fail(); 60cdf0e10cSrcweir } catch (OptionalPropertyException e) { 61cdf0e10cSrcweir } 62cdf0e10cSrcweir try { 63cdf0e10cSrcweir t.getProp5Void(); 64*6e57475aSDamjan Jovanovic fail(); 65cdf0e10cSrcweir } catch (VoidPropertyException e) { 66cdf0e10cSrcweir }*/ 67*6e57475aSDamjan Jovanovic assertTrue(t.getProp5Long() == 5); 68*6e57475aSDamjan Jovanovic assertTrue(t.getProp6() == 6); 69cdf0e10cSrcweir /*t.clearProp6(); 70cdf0e10cSrcweir try { 71cdf0e10cSrcweir t.getProp6(); 72*6e57475aSDamjan Jovanovic fail(); 73cdf0e10cSrcweir } catch (VoidPropertyException e) { 74cdf0e10cSrcweir }*/ 75cdf0e10cSrcweir t.setProp6(0); 76*6e57475aSDamjan Jovanovic assertTrue(t.getProp6() == 0); 77cdf0e10cSrcweir /*try { 78cdf0e10cSrcweir t.getProp7None(); 79*6e57475aSDamjan Jovanovic fail(); 80cdf0e10cSrcweir } catch (OptionalPropertyException e) { 81cdf0e10cSrcweir } 82cdf0e10cSrcweir try { 83cdf0e10cSrcweir t.setProp7None(0); 84*6e57475aSDamjan Jovanovic fail(); 85cdf0e10cSrcweir } catch (OptionalPropertyException e) { 86cdf0e10cSrcweir } 87cdf0e10cSrcweir try { 88cdf0e10cSrcweir t.clearProp7None(); 89*6e57475aSDamjan Jovanovic fail(); 90cdf0e10cSrcweir } catch (OptionalPropertyException e) { 91cdf0e10cSrcweir }*/ 92*6e57475aSDamjan Jovanovic assertTrue(t.getProp7() == 7); 93cdf0e10cSrcweir /*t.clearProp7(); 94cdf0e10cSrcweir try { 95cdf0e10cSrcweir t.getProp7(); 96*6e57475aSDamjan Jovanovic fail(); 97cdf0e10cSrcweir } catch (VoidPropertyException e) { 98cdf0e10cSrcweir }*/ 99cdf0e10cSrcweir t.setProp7(0); 100*6e57475aSDamjan Jovanovic assertTrue(t.getProp7() == 0); 101cdf0e10cSrcweir /*try { 102cdf0e10cSrcweir t.getProp8None(); 103*6e57475aSDamjan Jovanovic fail(); 104cdf0e10cSrcweir } catch (OptionalPropertyException e) { 105cdf0e10cSrcweir } 106cdf0e10cSrcweir try { 107cdf0e10cSrcweir t.setProp8None(0); 108*6e57475aSDamjan Jovanovic fail(); 109cdf0e10cSrcweir } catch (OptionalPropertyException e) { 110cdf0e10cSrcweir }*/ 111*6e57475aSDamjan Jovanovic assertTrue(t.getProp8Long() == 8); 112cdf0e10cSrcweir t.setProp8Long(0); 113*6e57475aSDamjan Jovanovic assertTrue(t.getProp8Long() == 0); 114*6e57475aSDamjan Jovanovic assertTrue(t.fn2() == 2); 115cdf0e10cSrcweir XTestService3 t3 = UnoRuntime.queryInterface(XTestService3.class, t); 116*6e57475aSDamjan Jovanovic assertTrue(t3 != null); 117*6e57475aSDamjan Jovanovic assertTrue(t3.fn3() == 3); 118cdf0e10cSrcweir XTestService4 t4 = UnoRuntime.queryInterface(XTestService4.class, t); 119*6e57475aSDamjan Jovanovic assertTrue(t4 == null); 120cdf0e10cSrcweir WaitUnreachable u = new WaitUnreachable(t); 121cdf0e10cSrcweir t = null; 122cdf0e10cSrcweir WaitUnreachable.ensureFinalization(t3); 123cdf0e10cSrcweir t3 = null; 124cdf0e10cSrcweir WaitUnreachable.ensureFinalization(t4); 125cdf0e10cSrcweir t4 = null; 126cdf0e10cSrcweir u.waitUnreachable(); 127cdf0e10cSrcweir factory.dispose(); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir getTestServiceFactory()130cdf0e10cSrcweir protected abstract TestServiceFactory getTestServiceFactory() 131cdf0e10cSrcweir throws Exception; 132cdf0e10cSrcweir 133cdf0e10cSrcweir protected interface TestServiceFactory { get()134cdf0e10cSrcweir Object get() throws Exception; 135cdf0e10cSrcweir dispose()136cdf0e10cSrcweir void dispose() throws Exception; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139