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             "BackColor", new Any(Type.LONG, 0xFFFFFFFF),
67             Any.complete(xPropertySet.getPropertyValue("BackColor")));
68         assertEquals(
69             "IsLandscape", new Any(Type.BOOLEAN, false),
70             Any.complete(xPropertySet.getPropertyValue("IsLandscape")));
71         assertEquals(
72             "Size", new Type(Size.class),
73             Any.complete(xPropertySet.getPropertyValue("Size")).getType());
74 
75         xPropertySet.setPropertyValue("BackColor", 0xFF000000);
76         xPropertySet.setPropertyValue("IsLandscape", true);
77         assertEquals(
78             "BackColor", new Any(Type.LONG, 0xFF000000),
79             Any.complete(xPropertySet.getPropertyValue("BackColor")));
80         assertEquals(
81             "IsLandscape", new Any(Type.BOOLEAN, true),
82             Any.complete(xPropertySet.getPropertyValue("IsLandscape")));
83     }
84 
setUpDocument()85     @Before public void setUpDocument() throws com.sun.star.uno.Exception {
86         document = SOfficeFactory.getFactory(
87             UnoRuntime.queryInterface(
88                 XMultiServiceFactory.class,
89                 connection.getComponentContext().getServiceManager())).
90             createTextDoc(null);
91     }
92 
tearDownDocument()93     @After public void tearDownDocument() {
94         DesktopTools.closeDoc(document);
95     }
96 
97     private XTextDocument document = null;
98 
setUpConnection()99     @BeforeClass public static void setUpConnection() throws Exception {
100         connection.setUp();
101     }
102 
tearDownConnection()103     @AfterClass public static void tearDownConnection()
104         throws InterruptedException, com.sun.star.uno.Exception
105     {
106         connection.tearDown();
107     }
108 
109     private static final OfficeConnection connection = new OfficeConnection();
110 }
111