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.frame;
22 
23 import static org.junit.Assert.*;
24 
25 import java.util.Arrays;
26 import java.util.Collection;
27 
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.junit.runners.Parameterized;
33 import org.junit.runners.Parameterized.Parameters;
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.XPropertySet;
39 import com.sun.star.container.XNameAccess;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.style.GraphicLocation;
42 import com.sun.star.text.XText;
43 import com.sun.star.text.XTextCursor;
44 import com.sun.star.text.XTextDocument;
45 import com.sun.star.text.XTextFrame;
46 import com.sun.star.text.XTextFramesSupplier;
47 import com.sun.star.uno.UnoRuntime;
48 import testlib.uno.SWUtil;
49 @RunWith(value = Parameterized.class)
50 public class FrameBackGraphic {
51 	private static final UnoApp app = new UnoApp();
52 	private XTextDocument xTextDocument=null;
53 	private XMultiServiceFactory xWriterFactory=null;
54 	private XText xText=null;
55 	private int backGraphicLocation;
56 	private String graphicURL=null;
57 	private String graphicName=null;
58 	public FrameBackGraphic(String graphicURL,String graphicName,int backGraphicLocation){
59 		this.graphicURL=graphicURL;
60 		this.graphicName=graphicName;
61 		this.backGraphicLocation = backGraphicLocation;
62 	}
63 	@Parameters
64     public static Collection<Object[]> data(){
65     	Object[][] params = new Object[][]{
66     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",1},
67     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",2},
68     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",3},
69     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",4},
70     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",5},
71     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",6},
72     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",7},
73     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",8},
74     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",9},
75     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",10},
76     			{FileUtil.getUrl(Testspace.prepareData("uno/Desert.jpg")),"draw_jpg_Export",11}
77     			};
78     	return Arrays.asList(params);
79     }
80 
81 	@Before
82 	public void setUp() throws Exception {
83 		app.start();
84 	}
85 
86 	@After
87 	public void tearDown() throws Exception {
88 		app.close();
89 	}
90 	@Test
91 	public void testFrameBackGraphic() throws Exception {
92 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
93 		xText=xTextDocument.getText();
94 		XTextCursor xTextCursor = xText.createTextCursor();
95 		// get internal service factory of the document
96 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
97 		// Create a new Frame from the document's factory
98 		XTextFrame xTextFrame1 = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
99 		xText.insertTextContent(xTextCursor,xTextFrame1,false);
100 		XPropertySet xFrameProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame1);
101 		xFrameProps1.setPropertyValue("BackGraphicURL",graphicURL);
102 		xFrameProps1.setPropertyValue("BackGraphicFilter",graphicName);
103 		xFrameProps1.setPropertyValue("BackGraphicLocation",backGraphicLocation);
104 		XTextDocument xTextDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class,SWUtil.saveTo_Override_reload(xTextDocument, "writer8",Testspace.getPath("output/test.odt"), app));
105 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class,xTextDocument_odt);
106 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
107 		Object xFrame_obj1=xTextFrames_odt.getByName("Frame1");
108 		XTextFrame xFrame_Assert1=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xFrame_obj1);
109 		XPropertySet xFrameProps1_assert = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFrame_Assert1);
110 		GraphicLocation graphiclocation=(GraphicLocation)xFrameProps1_assert.getPropertyValue("BackGraphicLocation");
111 		assertEquals("verify Frame backgraphic location",backGraphicLocation,graphiclocation.getValue());
112 		assertEquals("verify Frame backgraphic fileter",graphicName,xFrameProps1_assert.getPropertyValue("BackGraphicFilter"));
113 		assertEquals("verify Frame backgraphic URL",graphicURL,xFrameProps1_assert.getPropertyValue("BackGraphicURL"));
114 	}
115 }
116