1 package fvt.uno.sw.puretext;
2 
3 import static org.junit.Assert.*;
4 
5 import org.junit.After;
6 import org.junit.Before;
7 import org.junit.Ignore;
8 import org.junit.Test;
9 import org.openoffice.test.common.FileUtil;
10 import org.openoffice.test.common.Testspace;
11 import org.openoffice.test.uno.UnoApp;
12 //import org.openoffice.test.vcl.Tester.*;
13 import com.sun.star.text.*;
14 import com.sun.star.beans.*;
15 import com.sun.star.frame.XStorable;
16 import com.sun.star.uno.UnoRuntime;
17 
18 public class CharacterRotationAndScaleWidth {
19 	private static final UnoApp app = new UnoApp();
20 	XText xText = null;
21 
22 	@Before
23 	public void setUp() throws Exception {
24 		app.start();
25 
26 	}
27 
28 	@After
29 	public void tearDown() throws Exception {
30 		app.close();
31 	}
32 
33 	@Test
34 	public void testCharacterRotationZeroSetting() throws Exception {
35 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
36 		xText = xTextDocument.getText();
37 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
38 				+ "and we all love our home very much!!!");
39 		// create text cursor for selecting and formatting text
40 		XTextCursor xTextCursor = xText.createTextCursor();
41 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
42 		xTextCursor.gotoStart(false);
43 		xTextCursor.goRight((short) 102, true);
44 		xCursorProps.setPropertyValue("CharRotation", (short)0);
45 		xCursorProps.setPropertyValue("CharScaleWidth", (short)150);
46 		//save to odt
47 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
48 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
49 		aStoreProperties_odt[0] = new PropertyValue();
50 		aStoreProperties_odt[1] = new PropertyValue();
51 		aStoreProperties_odt[0].Name = "Override";
52 		aStoreProperties_odt[0].Value = true;
53 		aStoreProperties_odt[1].Name = "FilterName";
54 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
55 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
56 		//save to doc
57 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
58 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
59 		aStoreProperties_doc[0] = new PropertyValue();
60 		aStoreProperties_doc[1] = new PropertyValue();
61 		aStoreProperties_doc[0].Name = "Override";
62 		aStoreProperties_doc[0].Value = true;
63 		aStoreProperties_doc[1].Name = "FilterName";
64 		aStoreProperties_doc[1].Value = "MS Word 97";
65 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
66 		app.closeDocument(xTextDocument);
67 
68 		//reopen the document and assert character rotation and scale width
69 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
70 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
71 		//verify set property
72 		assertEquals("assert character rotation ",(short)0,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
73 		assertEquals("assert character rotation ",(short)150,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
74 
75 		//reopen the document and assert row height setting
76 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
77 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
78 		//verify set property
79 		assertEquals("assert character rotation ",(short)0,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
80 		assertEquals("assert character rotation ",(short)150,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
81 	}
82 	@Test
83 	public void testCharacterRotationNinetySetting() throws Exception {
84 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
85 		xText = xTextDocument.getText();
86 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
87 				+ "and we all love our home very much!!!");
88 		// create text cursor for selecting and formatting text
89 		XTextCursor xTextCursor = xText.createTextCursor();
90 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
91 		xTextCursor.gotoStart(false);
92 		xTextCursor.goRight((short) 102, true);
93 		xCursorProps.setPropertyValue("CharRotation", (short)900);
94 		xCursorProps.setPropertyValue("CharScaleWidth", (short)200);
95 		xCursorProps.setPropertyValue("CharRotationIsFitToLine", true);
96 		//save to odt
97 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
98 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
99 		aStoreProperties_odt[0] = new PropertyValue();
100 		aStoreProperties_odt[1] = new PropertyValue();
101 		aStoreProperties_odt[0].Name = "Override";
102 		aStoreProperties_odt[0].Value = true;
103 		aStoreProperties_odt[1].Name = "FilterName";
104 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
105 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
106 		//save to doc
107 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
108 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
109 		aStoreProperties_doc[0] = new PropertyValue();
110 		aStoreProperties_doc[1] = new PropertyValue();
111 		aStoreProperties_doc[0].Name = "Override";
112 		aStoreProperties_doc[0].Value = true;
113 		aStoreProperties_doc[1].Name = "FilterName";
114 		aStoreProperties_doc[1].Value = "MS Word 97";
115 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
116 		app.closeDocument(xTextDocument);
117 
118 		//reopen the document and assert character rotation and scale width
119 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
120 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
121 		//verify set property
122 		assertEquals("assert character rotation ",(short)900,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
123 		assertEquals("assert character rotation ",(short)200,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
124 		assertEquals("assert character rotation ",true,xCursorProps_assert_odt.getPropertyValue("CharRotationIsFitToLine"));
125 
126 		//reopen the document and assert row height setting
127 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
128 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
129 		//verify set property
130 		assertEquals("assert character rotation ",(short)900,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
131 		assertEquals("assert character rotation ",(short)200,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
132 		assertEquals("assert character rotation ",true,xCursorProps_assert_odt.getPropertyValue("CharRotationIsFitToLine"));
133 	}
134 	//test character rotation 270 degree
135 	@Test
136 	@Ignore("Bug #120673 - character rotation changes to 90 from 270 degrees when saving to doc")
137 	public void testCharacterRotationDefineSetting() throws Exception {
138 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
139 		xText = xTextDocument.getText();
140 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
141 				+ "and we all love our home very much!!!");
142 		// create text cursor for selecting and formatting text
143 		XTextCursor xTextCursor = xText.createTextCursor();
144 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
145 		xTextCursor.gotoStart(false);
146 		xTextCursor.goRight((short) 102, true);
147 		xCursorProps.setPropertyValue("CharRotation", (short)2700);
148 		xCursorProps.setPropertyValue("CharScaleWidth", (short)300);
149 		//save to odt
150 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
151 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
152 		aStoreProperties_odt[0] = new PropertyValue();
153 		aStoreProperties_odt[1] = new PropertyValue();
154 		aStoreProperties_odt[0].Name = "Override";
155 		aStoreProperties_odt[0].Value = true;
156 		aStoreProperties_odt[1].Name = "FilterName";
157 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
158 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
159 		//save to doc
160 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
161 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
162 		aStoreProperties_doc[0] = new PropertyValue();
163 		aStoreProperties_doc[1] = new PropertyValue();
164 		aStoreProperties_doc[0].Name = "Override";
165 		aStoreProperties_doc[0].Value = true;
166 		aStoreProperties_doc[1].Name = "FilterName";
167 		aStoreProperties_doc[1].Value = "MS Word 97";
168 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
169 		app.closeDocument(xTextDocument);
170 
171 		//reopen the document and assert character rotation and scale width
172 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
173 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
174 		//verify set property
175 		assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
176 		assertEquals("assert character rotation ",(short)300,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
177 
178 		//reopen the document and assert row height setting
179 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
180 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
181 		//verify set property
182 		assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
183 		assertEquals("assert character rotation ",(short)300,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
184 	}
185 }
186