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