1 package fvt.uno.sw.frame;
2 
3 import static org.junit.Assert.*;
4 
5 import java.util.Arrays;
6 import java.util.Collection;
7 
8 import org.junit.After;
9 import org.junit.AfterClass;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.junit.runners.Parameterized;
14 import org.junit.runners.Parameterized.Parameters;
15 import org.openoffice.test.common.Testspace;
16 import org.openoffice.test.uno.UnoApp;
17 
18 import testlib.uno.SWUtil;
19 
20 import com.sun.star.beans.XPropertySet;
21 import com.sun.star.container.XNameAccess;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.table.ShadowFormat;
24 import com.sun.star.table.ShadowLocation;
25 import com.sun.star.text.XText;
26 import com.sun.star.text.XTextCursor;
27 import com.sun.star.text.XTextDocument;
28 import com.sun.star.text.XTextFrame;
29 import com.sun.star.text.XTextFramesSupplier;
30 import com.sun.star.uno.UnoRuntime;
31 @RunWith(value = Parameterized.class)
32 public class FrameShadow {
33 	private static final UnoApp app = new UnoApp();
34 	private XTextDocument xTextDocument=null;
35 	private XMultiServiceFactory xWriterFactory=null;
36 	private XText xText=null;
37 	private int shadowColor;
38 	private short shadowWidth;
39 	private ShadowLocation shadowLocation;
40 	public FrameShadow(ShadowLocation shadowLocation,short shadowWidth,int shadowColor){
41 		this.shadowLocation=shadowLocation;
42 		this.shadowWidth=shadowWidth;
43 		this.shadowColor=shadowColor;
44 	}
45 	@Parameters
46     public static Collection<Object[]> data(){
47     	Object[][] params = new Object[][]{
48     			{ShadowLocation.NONE,(short)0,0},
49     			{ShadowLocation.TOP_LEFT,(short)101,0x00FF00FF},
50     			{ShadowLocation.TOP_RIGHT,(short)101,0x00FF00FF},
51     			{ShadowLocation.BOTTOM_LEFT,(short)101,0x00FF00FF},
52     			{ShadowLocation.BOTTOM_RIGHT,(short)101,0x00FF00FF},
53     			};
54     	return Arrays.asList(params);
55     }
56 	@Before
57 	public void setUp() throws Exception {
58 		app.start();
59 	}
60 
61 	@After
62 	public void tearDown() throws Exception {
63 		app.close();
64 	}
65 
66 	@Test
67 	public void testFrameShadow() throws Exception {
68 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
69 		xText=xTextDocument.getText();
70 		XTextCursor xTextCursor = xText.createTextCursor();
71 		// get internal service factory of the document
72 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
73 		// Create a new table from the document's factory
74 		XTextFrame xTextFrame1 = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
75 		xText.insertTextContent(xTextCursor,xTextFrame1,false);
76 		XPropertySet xTextFrameProps1 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame1);
77 		ShadowFormat shadowFormat=new ShadowFormat();
78 		shadowFormat.Color=shadowColor;
79 		shadowFormat.Location=shadowLocation;
80 		shadowFormat.ShadowWidth=shadowWidth;
81 		xTextFrameProps1.setPropertyValue("ShadowFormat",shadowFormat);
82 		//reopen the document
83 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, SWUtil.saveTo_Override_reload(xTextDocument,"writer8", Testspace.getPath("output/test.odt"),app));
84 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
85 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
86 		XTextFrame xTextFrame_Assert1=(XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xTextFrames_odt.getByName("Frame1"));
87 		XPropertySet xTextFrameProps_assert1 = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextFrame_Assert1);
88 		ShadowFormat shadowFormat_Assert1=(ShadowFormat) UnoRuntime.queryInterface(ShadowFormat.class, xTextFrameProps_assert1.getPropertyValue("ShadowFormat"));
89 		assertEquals("assert shadow color",shadowColor,shadowFormat_Assert1.Color);
90 		assertEquals("assert shadow location",shadowLocation,shadowFormat_Assert1.Location);
91 		assertEquals("assert shadow width",shadowWidth,shadowFormat_Assert1.ShadowWidth);
92 	}
93 }
94