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 fvt.uno.sd.bullet;
25 import static org.junit.Assert.*;
26 import static testlib.uno.PageUtil.getDrawPageByIndex;
27 import static testlib.uno.ShapeUtil.*;
28 
29 import org.junit.After;
30 import org.junit.AfterClass;
31 import org.junit.Before;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.openoffice.test.common.FileUtil;
35 import org.openoffice.test.common.Testspace;
36 import org.openoffice.test.uno.UnoApp;
37 
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.beans.XPropertySet;
40 import com.sun.star.container.XIndexReplace;
41 import com.sun.star.drawing.XShape;
42 
43 import com.sun.star.lang.XComponent;
44 
45 import com.sun.star.style.NumberingType;
46 import com.sun.star.uno.UnoRuntime;
47 import testlib.uno.SDUtil;
48 
49 /**
50  * 1. New a SD
51 2. Insert some text
52 3. Set bullet on
53 4. Change the bullet color and bullet size
54 5. save/close/reopen and then check the bullet color and size
55  *
56  */
57 public class CheckBulletStyle {
58 
59 	private static final UnoApp app = new UnoApp();
60 
61 	private XComponent m_xSDComponent = null;
62 	private String m_filePath = null;
63 //	private XShape m_xsecondTextBox = null;
64 	Object m_numberingRules = null;
65 	XPropertySet m_textProperty = null;
66 	XIndexReplace m_xReplace = null;
67 
68 	@Before
setUpDocument()69 	public void setUpDocument() throws Exception {
70 		m_filePath = Testspace.getPath("temp/CheckBulletStyle.odp");
71 		if(FileUtil.fileExists(m_filePath))
72 		{	//load
73 			m_xReplace = load();
74 		}
75 		else{
76 			//create a sd
77 			m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, app.newDocument("simpress"));
78 			Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
79 			Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1);
80 			XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox);
81 			m_textProperty = addPortion(xsecondTextBox, "Test Bullet Style", false);
82 
83 			//get numberingRules
84 			m_numberingRules = m_textProperty.getPropertyValue("NumberingRules");
85 
86 			m_xReplace = (XIndexReplace) UnoRuntime.queryInterface(
87 		             XIndexReplace.class, m_numberingRules);
88 
89 			PropertyValue[] props = new PropertyValue[1];
90 		    props[0] = new PropertyValue();
91 		    props[0].Name = "NumberingType";
92 		    props[0].Value = new Short(NumberingType.CHAR_SPECIAL );
93 
94 		    //set numberingType
95 		    m_xReplace.replaceByIndex(0, props);
96 		    m_textProperty.setPropertyValue("NumberingRules", m_numberingRules);
97 		    //set numbering level to 0
98 		    m_textProperty.setPropertyValue("NumberingLevel", new Short((short)0));
99 		}
100 	}
load()101 	private XIndexReplace load() throws Exception{
102 		m_xSDComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class,
103 				app.loadDocument(m_filePath));
104 		Object firstPage = getDrawPageByIndex(m_xSDComponent, 0);
105 		Object secondTextBox = SDUtil.getShapeOfPageByIndex(firstPage, 1);
106 		XShape xsecondTextBox = (XShape)UnoRuntime.queryInterface(XShape.class, secondTextBox);
107 		m_textProperty = getPortion(xsecondTextBox, 0);
108 
109 		m_numberingRules = m_textProperty.getPropertyValue("NumberingRules");
110 
111 		XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface(
112 	             XIndexReplace.class, m_numberingRules);
113 		return xReplace;
114 	}
115 
116 	@After
tearDownDocument()117 	public void tearDownDocument() {
118 		app.closeDocument(m_xSDComponent);
119 
120 		//remove the temp file
121 		FileUtil.deleteFile(Testspace.getPath("temp"));
122 	}
123 
124 	@BeforeClass
setUpConnection()125 	public static void setUpConnection() throws Exception {
126 		app.start();
127 	}
128 
129 	@AfterClass
tearDownConnection()130 	public static void tearDownConnection() throws InterruptedException,
131 			Exception {
132 		app.close();
133 
134 	}
135 
136 	@Test
testBulletColor()137 	public void testBulletColor() throws Exception {
138 		//BulletColor, Integer
139 		PropertyValue[] props = new PropertyValue[1];
140 	    props[0] = new PropertyValue();
141 	    props[0].Name = "BulletColor";
142 	    props[0].Value = new Integer(255);
143 
144 	    m_xReplace.replaceByIndex(0, props);
145 	    m_textProperty.setPropertyValue("NumberingRules", m_numberingRules);
146 
147 	    app.saveDocument(m_xSDComponent, m_filePath);
148 		app.closeDocument(m_xSDComponent);
149 
150 		XIndexReplace xReplace = load();
151 		PropertyValue[] proValues = (PropertyValue[])xReplace.getByIndex(0);
152 		assertEquals("name should be BulletColor", "BulletColor", proValues[11].Name);
153 		assertEquals("BulletColor should be 255(Blue)", new Integer(255), proValues[11].Value);
154 	}
155 
156 	@Test
testBulletSize()157 	public void testBulletSize() throws Exception {
158 		//BulletRelSize, default 45
159 		PropertyValue[] props = new PropertyValue[1];
160 	    props[0] = new PropertyValue();
161 	    props[0].Name = "BulletRelSize";
162 	    props[0].Value = new Short((short)200);
163 
164 	    m_xReplace.replaceByIndex(0, props);
165 	    m_textProperty.setPropertyValue("NumberingRules", m_numberingRules);
166 
167 	    app.saveDocument(m_xSDComponent, m_filePath);
168 		app.closeDocument(m_xSDComponent);
169 
170 		XIndexReplace xReplace = load();
171 		PropertyValue[] proValues = (PropertyValue[])xReplace.getByIndex(0);
172 		assertEquals("name should be BulletRelSize", "BulletRelSize", proValues[12].Name);
173 		assertEquals("BulletRelSize should be 200%", new Short((short)200), proValues[12].Value);
174 	}
175 }
176