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 package fvt.uno.sw.page;
22 
23 import static org.openoffice.test.common.Testspace.*;
24 
25 import java.io.File;
26 import java.util.Arrays;
27 import java.util.Collection;
28 
29 import org.junit.After;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.Ignore;
33 import org.junit.Assert;
34 import org.junit.runner.RunWith;
35 import org.junit.runners.Parameterized;
36 import org.junit.runners.Parameterized.Parameters;
37 
38 import org.openoffice.test.common.FileUtil;
39 import org.openoffice.test.uno.UnoApp;
40 
41 import testlib.uno.SWUtil;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.table.BorderLine;
46 
47 /**
48  * test page's back graphic,
49  * test page footer/header's back graphic.
50  *
51  */
52 @RunWith(Parameterized.class)
53 public class CheckBackGraphic {
54 	UnoApp unoApp = new UnoApp();
55 	XTextDocument textDocument = null;
56 	File temp = null;
57 	String tempFilePathODT = "";
58 	String tempFilePathDOC = "";
59 
60 	private String onProperty = "";
61 	private String backGraphicURLProperty = "";
62 
63 	private String backGraphicPath = "";
64 	private String backGraphicURL = "";
65 
66 
CheckBackGraphic(String onProperty, String backGraphicURLProperty, String backGraphicPath)67 	public CheckBackGraphic(String onProperty, String backGraphicURLProperty, String backGraphicPath){
68 		this.onProperty = onProperty;
69 		this.backGraphicURLProperty = backGraphicURLProperty;
70 
71 		this.backGraphicPath = backGraphicPath;
72 	}
73 
74 	@Parameters
data()75     public static Collection<Object[]> data(){
76     	Object[][] params = new Object[][]{
77     			{"FooterIsOn", "BackGraphicURL", "uno/sw/page/BackGraphic1.jpg"},
78     			{"FooterIsOn", "BackGraphicURL", "uno/sw/page/BackGraphic2.jpg"},
79     			{"FooterIsOn", "FooterBackGraphicURL", "uno/sw/page/BackGraphic1.jpg"},
80     			{"FooterIsOn", "FooterBackGraphicURL", "uno/sw/page/BackGraphic2.jpg"},
81     			{"HeaderIsOn", "HeaderBackGraphicURL", "uno/sw/page/BackGraphic1.jpg"},
82     			{"HeaderIsOn", "HeaderBackGraphicURL", "uno/sw/page/BackGraphic2.jpg"}
83     			};
84     	return Arrays.asList(params);
85     }
86 
87     /**
88      * test header/footer's back color and back graphic.
89      * @throws Exception
90      */
91 	@Test
testFooterHeaderBackground()92 	public void testFooterHeaderBackground() throws Exception
93 	{
94 		String graphicUrl = FileUtil.getUrl(prepareData(backGraphicPath));
95 		backGraphicURL = graphicUrl;
96 		XComponent xComponent = unoApp.newDocument("swriter");
97 		//turn on header/footer
98 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
99 		SWUtil.setDefaultPageStyleProperty(xComponent, backGraphicURLProperty, backGraphicURL);
100 
101 		//save as ODT and reopen, get back color and back graphic
102 		unoApp.saveDocument(xComponent, tempFilePathODT);
103         unoApp.closeDocument(xComponent);
104         xComponent = unoApp.loadDocument(tempFilePathODT);
105 
106 		String graphic = (String)SWUtil.getDefaultPageStyleProperty(xComponent, backGraphicURLProperty);
107 
108 
109 		Assert.assertEquals("ODT:" + backGraphicURLProperty, backGraphicURL, graphic);
110 
111 		unoApp.closeDocument(xComponent);
112 	}
113 
114 
115 
116 	/**
117 	 * @throws java.lang.Exception
118 	 */
119 	@Before
setUp()120 	public void setUp() throws Exception {
121 		unoApp.start();
122 
123 		FileUtil.deleteFile(getPath("temp"));
124 		temp = new File(getPath("temp"));
125 		temp.mkdirs();
126 
127 		tempFilePathODT = temp + "/tempFilePathODT.odt";
128 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
129 	}
130 
131 	@After
tearDown()132 	public void tearDown() throws Exception {
133 		unoApp.close();
134 	}
135 
136 
137 }
138