1 package testcase.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@Ignore //bug 120673_character rotation degree change to 90 from 270 when save to doc
136 	public void testCharacterRotationDefineSetting() throws Exception {
137 		XTextDocument xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.newDocument("swriter"));// new a text document
138 		xText = xTextDocument.getText();
139 		xText.setString("we are Chinese,they are American.We are all living in one earth!"
140 				+ "and we all love our home very much!!!");
141 		// create text cursor for selecting and formatting text
142 		XTextCursor xTextCursor = xText.createTextCursor();
143 		XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
144 		xTextCursor.gotoStart(false);
145 		xTextCursor.goRight((short) 102, true);
146 		xCursorProps.setPropertyValue("CharRotation", (short)2700);
147 		xCursorProps.setPropertyValue("CharScaleWidth", (short)300);
148 		//save to odt
149 		XStorable xStorable_odt = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
150 		PropertyValue[] aStoreProperties_odt = new PropertyValue[2];
151 		aStoreProperties_odt[0] = new PropertyValue();
152 		aStoreProperties_odt[1] = new PropertyValue();
153 		aStoreProperties_odt[0].Name = "Override";
154 		aStoreProperties_odt[0].Value = true;
155 		aStoreProperties_odt[1].Name = "FilterName";
156 		aStoreProperties_odt[1].Value = "StarOffice XML (Writer)";
157 		xStorable_odt.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.odt")), aStoreProperties_odt);
158 		//save to doc
159 		XStorable xStorable_doc = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
160 		PropertyValue[] aStoreProperties_doc = new PropertyValue[2];
161 		aStoreProperties_doc[0] = new PropertyValue();
162 		aStoreProperties_doc[1] = new PropertyValue();
163 		aStoreProperties_doc[0].Name = "Override";
164 		aStoreProperties_doc[0].Value = true;
165 		aStoreProperties_doc[1].Name = "FilterName";
166 		aStoreProperties_doc[1].Value = "MS Word 97";
167 		xStorable_doc.storeToURL(FileUtil.getUrl(Testspace.getPath("output/test.doc")), aStoreProperties_doc);
168 		app.closeDocument(xTextDocument);
169 
170 		//reopen the document and assert character rotation and scale width
171 		XTextDocument assertDocument_odt=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.odt")));
172 		XPropertySet xCursorProps_assert_odt = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_odt.getText().createTextCursor());
173 		//verify set property
174 		assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_odt.getPropertyValue("CharRotation"));
175 		assertEquals("assert character rotation ",(short)300,xCursorProps_assert_odt.getPropertyValue("CharScaleWidth"));
176 
177 		//reopen the document and assert row height setting
178 		XTextDocument assertDocument_doc=(XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, app.loadDocument(Testspace.getPath("output/test.doc")));
179 		XPropertySet xCursorProps_assert_doc = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, assertDocument_doc.getText().createTextCursor());
180 		//verify set property
181 		assertEquals("assert character rotation ",(short)2700,xCursorProps_assert_doc.getPropertyValue("CharRotation"));
182 		assertEquals("assert character rotation ",(short)300,xCursorProps_assert_doc.getPropertyValue("CharScaleWidth"));
183 	}
184 }
185