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 testtools.servicetests; 25 26 import com.sun.star.uno.UnoRuntime; 27 import util.WaitUnreachable; 28 29 import static org.junit.Assert.*; 30 31 public abstract class TestBase { runTest()32 public final void runTest() throws Exception { 33 TestServiceFactory factory = getTestServiceFactory(); 34 TestService2 t = UnoRuntime.queryInterface( 35 TestService2.class, factory.get()); 36 assertTrue(t != null); 37 assertTrue(UnoRuntime.queryInterface(TestService1.class, t) == t); 38 assertTrue(UnoRuntime.queryInterface(XTestService1.class, t) == t); 39 assertTrue(UnoRuntime.queryInterface(XTestService2.class, t) == t); 40 assertTrue(t.fn1() == 1); 41 assertTrue(t.getProp1() == 1); 42 t.setProp1(0); 43 assertTrue(t.getProp1() == 0); 44 assertTrue(t.getProp2() == 2); 45 /*try { 46 t.getProp3Void(); 47 fail(); 48 } catch (VoidPropertyException e) { 49 }*/ 50 assertTrue(t.getProp3Long() == 3); 51 /*try { 52 t.getProp4None(); 53 fail(); 54 } catch (OptionalPropertyException e) { 55 }*/ 56 assertTrue(t.getProp4Long() == 4); 57 /*try { 58 t.getProp5None(); 59 fail(); 60 } catch (OptionalPropertyException e) { 61 } 62 try { 63 t.getProp5Void(); 64 fail(); 65 } catch (VoidPropertyException e) { 66 }*/ 67 assertTrue(t.getProp5Long() == 5); 68 assertTrue(t.getProp6() == 6); 69 /*t.clearProp6(); 70 try { 71 t.getProp6(); 72 fail(); 73 } catch (VoidPropertyException e) { 74 }*/ 75 t.setProp6(0); 76 assertTrue(t.getProp6() == 0); 77 /*try { 78 t.getProp7None(); 79 fail(); 80 } catch (OptionalPropertyException e) { 81 } 82 try { 83 t.setProp7None(0); 84 fail(); 85 } catch (OptionalPropertyException e) { 86 } 87 try { 88 t.clearProp7None(); 89 fail(); 90 } catch (OptionalPropertyException e) { 91 }*/ 92 assertTrue(t.getProp7() == 7); 93 /*t.clearProp7(); 94 try { 95 t.getProp7(); 96 fail(); 97 } catch (VoidPropertyException e) { 98 }*/ 99 t.setProp7(0); 100 assertTrue(t.getProp7() == 0); 101 /*try { 102 t.getProp8None(); 103 fail(); 104 } catch (OptionalPropertyException e) { 105 } 106 try { 107 t.setProp8None(0); 108 fail(); 109 } catch (OptionalPropertyException e) { 110 }*/ 111 assertTrue(t.getProp8Long() == 8); 112 t.setProp8Long(0); 113 assertTrue(t.getProp8Long() == 0); 114 assertTrue(t.fn2() == 2); 115 XTestService3 t3 = UnoRuntime.queryInterface(XTestService3.class, t); 116 assertTrue(t3 != null); 117 assertTrue(t3.fn3() == 3); 118 XTestService4 t4 = UnoRuntime.queryInterface(XTestService4.class, t); 119 assertTrue(t4 == null); 120 WaitUnreachable u = new WaitUnreachable(t); 121 t = null; 122 WaitUnreachable.ensureFinalization(t3); 123 t3 = null; 124 WaitUnreachable.ensureFinalization(t4); 125 t4 = null; 126 u.waitUnreachable(); 127 factory.dispose(); 128 } 129 getTestServiceFactory()130 protected abstract TestServiceFactory getTestServiceFactory() 131 throws Exception; 132 133 protected interface TestServiceFactory { get()134 Object get() throws Exception; 135 dispose()136 void dispose() throws Exception; 137 } 138 } 139