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 package complex.checkColor; 23 24 import com.sun.star.awt.Size; 25 import com.sun.star.beans.XPropertySet; 26 import com.sun.star.container.XNameAccess; 27 import com.sun.star.container.XNameContainer; 28 import com.sun.star.lang.XMultiServiceFactory; 29 import com.sun.star.style.XStyleFamiliesSupplier; 30 import com.sun.star.text.XTextDocument; 31 import com.sun.star.uno.Any; 32 import com.sun.star.uno.Type; 33 import com.sun.star.uno.UnoRuntime; 34 import org.junit.After; 35 import org.junit.AfterClass; 36 import org.junit.Before; 37 import org.junit.BeforeClass; 38 import org.junit.Test; 39 import org.openoffice.test.OfficeConnection; 40 import util.DesktopTools; 41 import util.SOfficeFactory; 42 import static org.junit.Assert.*; 43 44 /** 45 * Created because of complaint on dev@openoffice.org: check the changing of 46 * BackColor and IsLandscape properties on the PageStyle service. 47 */ 48 public class CheckChangeColor { 49 /** 50 * Check BackColor and IsLandscape properties, wait for an exception: test 51 * is ok if no exception happened. 52 */ checkChangeColor()53 @Test public void checkChangeColor() throws Exception { 54 // create a supplier to get the Style family collection 55 XStyleFamiliesSupplier xSupplier = ( XStyleFamiliesSupplier ) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, document); 56 57 // get the NameAccess interface from the Style family collection 58 XNameAccess xNameAccess = xSupplier.getStyleFamilies(); 59 60 XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName( "PageStyles" )); 61 62 // create a PropertySet to set the properties for the new Pagestyle 63 XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPageStyleCollection.getByName("Standard") ); 64 65 assertEquals( 66 "IsLandscape", new Any(Type.BOOLEAN, false), 67 Any.complete(xPropertySet.getPropertyValue("IsLandscape"))); 68 assertEquals( 69 "Size", new Type(Size.class), 70 Any.complete(xPropertySet.getPropertyValue("Size")).getType()); 71 72 xPropertySet.setPropertyValue("BackColor", 0xFF000000); 73 xPropertySet.setPropertyValue("IsLandscape", true); 74 assertEquals( 75 "BackColor", new Any(Type.LONG, 0xFF000000), 76 Any.complete(xPropertySet.getPropertyValue("BackColor"))); 77 assertEquals( 78 "IsLandscape", new Any(Type.BOOLEAN, true), 79 Any.complete(xPropertySet.getPropertyValue("IsLandscape"))); 80 } 81 setUpDocument()82 @Before public void setUpDocument() throws com.sun.star.uno.Exception { 83 document = SOfficeFactory.getFactory( 84 UnoRuntime.queryInterface( 85 XMultiServiceFactory.class, 86 connection.getComponentContext().getServiceManager())). 87 createTextDoc(null); 88 } 89 tearDownDocument()90 @After public void tearDownDocument() { 91 DesktopTools.closeDoc(document); 92 } 93 94 private XTextDocument document = null; 95 setUpConnection()96 @BeforeClass public static void setUpConnection() throws Exception { 97 connection.setUp(); 98 } 99 tearDownConnection()100 @AfterClass public static void tearDownConnection() 101 throws InterruptedException, com.sun.star.uno.Exception 102 { 103 connection.tearDown(); 104 } 105 106 private static final OfficeConnection connection = new OfficeConnection(); 107 } 108