1 package fvt.uno.sw.frame;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Test;
8 import org.openoffice.test.common.Testspace;
9 import org.openoffice.test.uno.UnoApp;
10 
11 import testlib.uno.SWUtil;
12 
13 import com.sun.star.beans.XPropertySet;
14 import com.sun.star.container.XNameAccess;
15 import com.sun.star.lang.XMultiServiceFactory;
16 import com.sun.star.table.BorderLine;
17 import com.sun.star.text.XText;
18 import com.sun.star.text.XTextCursor;
19 import com.sun.star.text.XTextDocument;
20 import com.sun.star.text.XTextFrame;
21 import com.sun.star.text.XTextFramesSupplier;
22 import com.sun.star.uno.UnoRuntime;
23 
24 public class FrameBorder {
25 	private static final UnoApp app = new UnoApp();
26 	private XTextDocument xTextDocument=null;
27 	private XMultiServiceFactory xWriterFactory=null;
28 	private XText xText=null;
29 	@Before
30 	public void setUp() throws Exception {
31 		app.start();
32 	}
33 
34 	@After
35 	public void tearDown() throws Exception {
36 		app.close();
37 	}
38 
39 	@Test
40 	public void testInsertFrame() throws Exception {
41 		xTextDocument =(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));
42 		xText=xTextDocument.getText();
43 		XTextCursor xTextCursor = xText.createTextCursor();
44 		// get internal service factory of the document
45 		xWriterFactory =(XMultiServiceFactory)UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
46 		// Create a new table from the document's factory
47 		XTextFrame xTextFrame = (XTextFrame)UnoRuntime.queryInterface(XTextFrame.class, xWriterFactory.createInstance("com.sun.star.text.TextFrame"));
48 		xText.insertTextContent(xTextCursor,xTextFrame,false);
49 		XPropertySet xTextFramerops = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrame);
50 		//set frame border
51 		BorderLine[]borderLine=new BorderLine[] {new BorderLine(),new BorderLine(),new BorderLine(),new BorderLine()};
52 		borderLine[0].Color=0x00FF0000;
53 		borderLine[0].InnerLineWidth=101;
54 		borderLine[0].OuterLineWidth=19;
55 		borderLine[0].LineDistance=100;
56 		borderLine[1].Color =0x00FFFF00;
57 		borderLine[1].InnerLineWidth=101;
58 		borderLine[1].OuterLineWidth=19;
59 		borderLine[1].LineDistance=101;
60 		borderLine[2].Color =0x0000FF00;
61 		borderLine[2].InnerLineWidth=150;
62 		borderLine[2].OuterLineWidth=19;
63 		borderLine[2].LineDistance=101;
64 		borderLine[3].Color =0x0000FF00;
65 		borderLine[3].InnerLineWidth=150;
66 		borderLine[3].OuterLineWidth=19;
67 		borderLine[3].LineDistance=101;
68 		xTextFramerops.setPropertyValue("LeftBorder", borderLine[0]);
69 		xTextFramerops.setPropertyValue("RightBorder", borderLine[1]);
70 		xTextFramerops.setPropertyValue("TopBorder", borderLine[2]);
71 		xTextFramerops.setPropertyValue("BottomBorder", borderLine[3]);
72 		//reopen the document
73 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, SWUtil.saveTo_Override_reload(xTextDocument,"writer8", Testspace.getPath("output/test.odt"),app));
74 		XTextFramesSupplier xTFS_odt = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, assertDocument_odt);
75 		XNameAccess xTextFrames_odt = xTFS_odt.getTextFrames();
76 		XPropertySet xFrameProps_Assert_odt = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextFrames_odt.getByName("Frame1"));
77 		BorderLine LeftBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("LeftBorder"));
78 		assertEquals("assert topline color as setting",0x00FF0000,LeftBorder_Assert_odt.Color);
79 		assertEquals("assert topline innerline width as setting",101,LeftBorder_Assert_odt.InnerLineWidth);
80 		assertEquals("assert topline outerlinewidth as setting",19,LeftBorder_Assert_odt.OuterLineWidth);
81 		assertEquals("assert topline linedistance as setting",101,LeftBorder_Assert_odt.LineDistance);
82 		BorderLine RightBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("RightBorder"));
83 		assertEquals("assert bottomline color as setting",0x00FFFF00,RightBorder_Assert_odt.Color);
84 		assertEquals("assert bottomline innerline width as setting",101,RightBorder_Assert_odt.InnerLineWidth);
85 		assertEquals("assert bottomline outerlinewidth as setting",19,RightBorder_Assert_odt.OuterLineWidth);
86 		assertEquals("assert bottomline linedistance as setting",101,RightBorder_Assert_odt.LineDistance);
87 		BorderLine TopBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("TopBorder"));
88 		assertEquals("assert leftline color as setting",0x0000FF00,TopBorder_Assert_odt.Color);
89 		assertEquals("assert leftline innerline width as setting",150,TopBorder_Assert_odt.InnerLineWidth);
90 		assertEquals("assert leftline outerlinewidth as setting",19,TopBorder_Assert_odt.OuterLineWidth);
91 		assertEquals("assert leftline linedistance as setting",101,TopBorder_Assert_odt.LineDistance);
92 		BorderLine BottomBorder_Assert_odt=(BorderLine) UnoRuntime.queryInterface(BorderLine.class, xFrameProps_Assert_odt.getPropertyValue("BottomBorder"));
93 		assertEquals("assert rightline color as setting",0x0000FF00,BottomBorder_Assert_odt.Color);
94 		assertEquals("assert rightline linedistance as setting",101,BottomBorder_Assert_odt.LineDistance);
95 		assertEquals("assert rightline innerline width as setting",150,BottomBorder_Assert_odt.InnerLineWidth);
96 		assertEquals("assert rightline outerlinewidth as setting",19,BottomBorder_Assert_odt.OuterLineWidth);
97 	}
98 }
99