1deb45f49SLiu Zhe /**************************************************************
2deb45f49SLiu Zhe  *
3deb45f49SLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4deb45f49SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5deb45f49SLiu Zhe  * distributed with this work for additional information
6deb45f49SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7deb45f49SLiu Zhe  * to you under the Apache License, Version 2.0 (the
8deb45f49SLiu Zhe  * "License"); you may not use this file except in compliance
9deb45f49SLiu Zhe  * with the License.  You may obtain a copy of the License at
10deb45f49SLiu Zhe  *
11deb45f49SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12deb45f49SLiu Zhe  *
13deb45f49SLiu Zhe  * Unless required by applicable law or agreed to in writing,
14deb45f49SLiu Zhe  * software distributed under the License is distributed on an
15deb45f49SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16deb45f49SLiu Zhe  * KIND, either express or implied.  See the License for the
17deb45f49SLiu Zhe  * specific language governing permissions and limitations
18deb45f49SLiu Zhe  * under the License.
19deb45f49SLiu Zhe  *
20deb45f49SLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe package fvt.uno.sw.page;
22deb45f49SLiu Zhe 
23deb45f49SLiu Zhe import static org.openoffice.test.common.Testspace.*;
24deb45f49SLiu Zhe 
25deb45f49SLiu Zhe import java.io.File;
26deb45f49SLiu Zhe import java.util.Arrays;
27deb45f49SLiu Zhe import java.util.Collection;
28deb45f49SLiu Zhe 
29deb45f49SLiu Zhe import org.junit.After;
30deb45f49SLiu Zhe import org.junit.Before;
31deb45f49SLiu Zhe import org.junit.Test;
32deb45f49SLiu Zhe import org.junit.Ignore;
33deb45f49SLiu Zhe import org.junit.Assert;
34deb45f49SLiu Zhe import org.junit.runner.RunWith;
35deb45f49SLiu Zhe import org.junit.runners.Parameterized;
36deb45f49SLiu Zhe import org.junit.runners.Parameterized.Parameters;
37deb45f49SLiu Zhe 
38deb45f49SLiu Zhe import org.openoffice.test.common.FileUtil;
39deb45f49SLiu Zhe import org.openoffice.test.uno.UnoApp;
40deb45f49SLiu Zhe 
41deb45f49SLiu Zhe import testlib.uno.SWUtil;
42deb45f49SLiu Zhe import com.sun.star.text.XTextDocument;
43deb45f49SLiu Zhe import com.sun.star.uno.UnoRuntime;
44deb45f49SLiu Zhe import com.sun.star.lang.XComponent;
45deb45f49SLiu Zhe import com.sun.star.table.BorderLine;
46deb45f49SLiu Zhe 
47deb45f49SLiu Zhe /**
48deb45f49SLiu Zhe  * test page's back graphic,
49deb45f49SLiu Zhe  * test page footer/header's back graphic.
50deb45f49SLiu Zhe  *
51deb45f49SLiu Zhe  */
52deb45f49SLiu Zhe @RunWith(Parameterized.class)
53deb45f49SLiu Zhe public class CheckBackGraphic {
54deb45f49SLiu Zhe 	UnoApp unoApp = new UnoApp();
55deb45f49SLiu Zhe 	XTextDocument textDocument = null;
56deb45f49SLiu Zhe 	File temp = null;
57deb45f49SLiu Zhe 	String tempFilePathODT = "";
58deb45f49SLiu Zhe 	String tempFilePathDOC = "";
59deb45f49SLiu Zhe 
60deb45f49SLiu Zhe 	private String onProperty = "";
61deb45f49SLiu Zhe 	private String backGraphicURLProperty = "";
62deb45f49SLiu Zhe 
63deb45f49SLiu Zhe 	private String backGraphicPath = "";
64deb45f49SLiu Zhe 	private String backGraphicURL = "";
65deb45f49SLiu Zhe 
66deb45f49SLiu Zhe 
CheckBackGraphic(String onProperty, String backGraphicURLProperty, String backGraphicPath)67deb45f49SLiu Zhe 	public CheckBackGraphic(String onProperty, String backGraphicURLProperty, String backGraphicPath){
68deb45f49SLiu Zhe 		this.onProperty = onProperty;
69deb45f49SLiu Zhe 		this.backGraphicURLProperty = backGraphicURLProperty;
70deb45f49SLiu Zhe 
71deb45f49SLiu Zhe 		this.backGraphicPath = backGraphicPath;
72deb45f49SLiu Zhe 	}
73deb45f49SLiu Zhe 
74deb45f49SLiu Zhe 	@Parameters
data()75deb45f49SLiu Zhe     public static Collection<Object[]> data(){
76deb45f49SLiu Zhe     	Object[][] params = new Object[][]{
77deb45f49SLiu Zhe     			{"FooterIsOn", "BackGraphicURL", "uno/sw/page/BackGraphic1.jpg"},
78deb45f49SLiu Zhe     			{"FooterIsOn", "BackGraphicURL", "uno/sw/page/BackGraphic2.jpg"},
79deb45f49SLiu Zhe     			{"FooterIsOn", "FooterBackGraphicURL", "uno/sw/page/BackGraphic1.jpg"},
80deb45f49SLiu Zhe     			{"FooterIsOn", "FooterBackGraphicURL", "uno/sw/page/BackGraphic2.jpg"},
81deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderBackGraphicURL", "uno/sw/page/BackGraphic1.jpg"},
82deb45f49SLiu Zhe     			{"HeaderIsOn", "HeaderBackGraphicURL", "uno/sw/page/BackGraphic2.jpg"}
83deb45f49SLiu Zhe     			};
84deb45f49SLiu Zhe     	return Arrays.asList(params);
85deb45f49SLiu Zhe     }
86deb45f49SLiu Zhe 
87deb45f49SLiu Zhe     /**
88deb45f49SLiu Zhe      * test header/footer's back color and back graphic.
89deb45f49SLiu Zhe      * @throws Exception
90deb45f49SLiu Zhe      */
91deb45f49SLiu Zhe 	@Test
testFooterHeaderBackground()92deb45f49SLiu Zhe 	public void testFooterHeaderBackground() throws Exception
93deb45f49SLiu Zhe 	{
94deb45f49SLiu Zhe 		String graphicUrl = FileUtil.getUrl(prepareData(backGraphicPath));
95deb45f49SLiu Zhe 		backGraphicURL = graphicUrl;
96deb45f49SLiu Zhe 		XComponent xComponent = unoApp.newDocument("swriter");
97deb45f49SLiu Zhe 		//turn on header/footer
98deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
99deb45f49SLiu Zhe 		SWUtil.setDefaultPageStyleProperty(xComponent, backGraphicURLProperty, backGraphicURL);
100deb45f49SLiu Zhe 
101deb45f49SLiu Zhe 		//save as ODT and reopen, get back color and back graphic
102deb45f49SLiu Zhe 		unoApp.saveDocument(xComponent, tempFilePathODT);
103deb45f49SLiu Zhe         unoApp.closeDocument(xComponent);
104deb45f49SLiu Zhe         xComponent = unoApp.loadDocument(tempFilePathODT);
105deb45f49SLiu Zhe 
106deb45f49SLiu Zhe 		String graphic = (String)SWUtil.getDefaultPageStyleProperty(xComponent, backGraphicURLProperty);
107deb45f49SLiu Zhe 
108deb45f49SLiu Zhe 
109deb45f49SLiu Zhe 		Assert.assertEquals("ODT:" + backGraphicURLProperty, backGraphicURL, graphic);
110deb45f49SLiu Zhe 
111deb45f49SLiu Zhe 		unoApp.closeDocument(xComponent);
112deb45f49SLiu Zhe 	}
113deb45f49SLiu Zhe 
114deb45f49SLiu Zhe 
115deb45f49SLiu Zhe 
116deb45f49SLiu Zhe 	/**
117deb45f49SLiu Zhe 	 * @throws java.lang.Exception
118deb45f49SLiu Zhe 	 */
119deb45f49SLiu Zhe 	@Before
setUp()120deb45f49SLiu Zhe 	public void setUp() throws Exception {
121deb45f49SLiu Zhe 		unoApp.start();
122deb45f49SLiu Zhe 
123deb45f49SLiu Zhe 		FileUtil.deleteFile(getPath("temp"));
124deb45f49SLiu Zhe 		temp = new File(getPath("temp"));
125deb45f49SLiu Zhe 		temp.mkdirs();
126deb45f49SLiu Zhe 
127deb45f49SLiu Zhe 		tempFilePathODT = temp + "/tempFilePathODT.odt";
128deb45f49SLiu Zhe 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
129deb45f49SLiu Zhe 	}
130deb45f49SLiu Zhe 
131deb45f49SLiu Zhe 	@After
tearDown()132deb45f49SLiu Zhe 	public void tearDown() throws Exception {
133deb45f49SLiu Zhe 		unoApp.close();
134deb45f49SLiu Zhe 	}
135deb45f49SLiu Zhe 
136deb45f49SLiu Zhe 
137deb45f49SLiu Zhe }
138