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 color,
49  * test page footer/header's back color.
50  *
51  */
52 @RunWith(Parameterized.class)
53 public class CheckBackColor {
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 backColorProperty = "";
62 
63 	private int backColor = 0;
64 
65 
CheckBackColor(String onProperty, String backColorProperty, int backColor)66 	public CheckBackColor(String onProperty, String backColorProperty, 	int backColor){
67 		this.onProperty = onProperty;
68 		this.backColorProperty = backColorProperty;
69 
70 		this.backColor = backColor;
71 	}
72 
73 	@Parameters
data()74     public static Collection<Object[]> data(){
75     	Object[][] params = new Object[][]{
76     			{"FooterIsOn", "BackColor", 255},
77     			{"FooterIsOn", "BackColor", 65535},
78     			{"FooterIsOn", "FooterBackColor", 255},
79     			{"FooterIsOn", "FooterBackColor", 0},
80     			{"HeaderIsOn", "HeaderBackColor", 65536},
81     			{"HeaderIsOn", "HeaderBackColor", 65535}
82     			};
83     	return Arrays.asList(params);
84     }
85 
86     /**
87      * test header/footer's back color and back graphic.
88      * @throws Exception
89      */
90     @Ignore("#120949 - header/footer's background lost when export to doc format ")
91 	@Test
testFooterHeaderBackground()92 	public void testFooterHeaderBackground() throws Exception
93 	{
94 		XComponent xComponent = unoApp.newDocument("swriter");
95 		//turn on header/footer
96 		SWUtil.setDefaultPageStyleProperty(xComponent, onProperty, new Boolean(true));
97 		SWUtil.setDefaultPageStyleProperty(xComponent, backColorProperty, Integer.valueOf(backColor));
98 
99 		//save as ODT and reopen, get back color
100 		unoApp.saveDocument(xComponent, tempFilePathODT);
101         unoApp.closeDocument(xComponent);
102         xComponent = unoApp.loadDocument(tempFilePathODT);
103 
104 		int color = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, backColorProperty)).intValue();
105 
106 
107 		this.compare("ODT", color);
108 
109 		//save as DOC and reopen, only get back color
110 	    SWUtil.saveAsDoc(xComponent, FileUtil.getUrl(tempFilePathDOC));
111 	    unoApp.closeDocument(xComponent);
112 	    xComponent = unoApp.loadDocument(tempFilePathDOC);
113 	    color = ((Integer)SWUtil.getDefaultPageStyleProperty(xComponent, backColorProperty)).intValue();
114 
115 		this.compare("DOC", color);
116 
117 		unoApp.closeDocument(xComponent);
118 	}
119 
compare(String preDescription, int color)120 	private void compare(String preDescription, int color){
121 		Assert.assertEquals(preDescription + ":" + backColorProperty,(double)backColor, color, 2);
122 	}
123 
124 	/**
125 	 * @throws java.lang.Exception
126 	 */
127 	@Before
setUp()128 	public void setUp() throws Exception {
129 		unoApp.start();
130 
131 		FileUtil.deleteFile(getPath("temp"));
132 		temp = new File(getPath("temp"));
133 		temp.mkdirs();
134 
135 		tempFilePathODT = temp + "/tempFilePathODT.odt";
136 		tempFilePathDOC = temp + "/tempFilePathDOC.doc";
137 	}
138 
139 	@After
tearDown()140 	public void tearDown() throws Exception {
141 		unoApp.close();
142 	}
143 
144 
145 }
146