Lines 30-35
Link Here
|
30 |
import org.junit.Before; |
30 |
import org.junit.Before; |
31 |
import org.junit.BeforeClass; |
31 |
import org.junit.BeforeClass; |
32 |
import org.junit.Test; |
32 |
import org.junit.Test; |
|
|
33 |
import org.openoffice.test.common.FileUtil; |
33 |
import org.openoffice.test.common.Testspace; |
34 |
import org.openoffice.test.common.Testspace; |
34 |
import org.openoffice.test.uno.UnoApp; |
35 |
import org.openoffice.test.uno.UnoApp; |
35 |
|
36 |
|
Lines 66-72
Link Here
|
66 |
@After |
67 |
@After |
67 |
public void tearDownDocument() { |
68 |
public void tearDownDocument() { |
68 |
app.closeDocument(document); |
69 |
app.closeDocument(document); |
69 |
// FileUtil.deleteFile(Testspace.getFile(tempPath)); |
70 |
FileUtil.deleteFile(Testspace.getFile(tempPath)); |
70 |
} |
71 |
} |
71 |
|
72 |
|
72 |
|
73 |
|
Lines 89-98
Link Here
|
89 |
* 2.Verify the Time is created by check the date hour in the new document |
90 |
* 2.Verify the Time is created by check the date hour in the new document |
90 |
* 3.Save and close the new document to doc format |
91 |
* 3.Save and close the new document to doc format |
91 |
* 4.Reload the new save doc file, check the time field |
92 |
* 4.Reload the new save doc file, check the time field |
|
|
93 |
* @throws Exception |
92 |
*/ |
94 |
*/ |
93 |
|
95 |
|
94 |
@Test |
96 |
@Test |
95 |
public void testCreateTimeFieldSaveDoc() { |
97 |
public void testCreateTimeFieldSaveDoc() throws Exception { |
96 |
|
98 |
|
97 |
String url = Testspace.getUrl(tempPath + tempFileName + ".doc"); |
99 |
String url = Testspace.getUrl(tempPath + tempFileName + ".doc"); |
98 |
PropertyValue[] propsValue = new PropertyValue[1]; |
100 |
PropertyValue[] propsValue = new PropertyValue[1]; |
Lines 108-116
Link Here
|
108 |
* 2.Verify the Time Field is created by check the date hour in the new document |
110 |
* 2.Verify the Time Field is created by check the date hour in the new document |
109 |
* 3.Save and close the new document to doc format |
111 |
* 3.Save and close the new document to doc format |
110 |
* 4.Reload the new save odt file, check the Time Field |
112 |
* 4.Reload the new save odt file, check the Time Field |
|
|
113 |
* @throws Exception |
111 |
*/ |
114 |
*/ |
112 |
@Test |
115 |
@Test |
113 |
public void testCreateTimeFieldSaveODT() { |
116 |
public void testCreateTimeFieldSaveODT() throws Exception { |
114 |
|
117 |
|
115 |
String url = Testspace.getUrl(tempPath + tempFileName + ".odt"); |
118 |
String url = Testspace.getUrl(tempPath + tempFileName + ".odt"); |
116 |
PropertyValue[] propsValue = new PropertyValue[0]; |
119 |
PropertyValue[] propsValue = new PropertyValue[0]; |
Lines 118-168
Link Here
|
118 |
|
121 |
|
119 |
} |
122 |
} |
120 |
|
123 |
|
121 |
private void createTimeFiled(XTextDocument document, String url, PropertyValue[] propsValue) { |
124 |
private void createTimeFiled(XTextDocument document, String url, PropertyValue[] propsValue) throws Exception { |
122 |
XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document); |
125 |
XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document); |
123 |
try { |
126 |
XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime")); |
124 |
XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime")); |
|
|
125 |
|
126 |
|
127 |
|
127 |
XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); |
|
|
128 |
props.setPropertyValue("IsDate", false); |
129 |
|
130 |
document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); |
131 |
DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); |
132 |
|
128 |
|
133 |
String dateString = document.getText().getString(); |
129 |
XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); |
134 |
assertTrue("Verify time field is creatd, by verify it's hour", dateString.indexOf(String.valueOf(dateField.Hours).trim()) != -1); |
130 |
props.setPropertyValue("IsDate", false); |
135 |
assertTrue("Verify time field is creatd, by verify it's minutes", dateString.indexOf(String.valueOf(dateField.Minutes).trim()) != -1); |
131 |
|
136 |
int expectHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); |
132 |
document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); |
137 |
assertEquals("Verify time field is creatd, value is right, by compare Hour", expectHour, dateField.Hours); |
133 |
DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); |
138 |
XStorable store = UnoRuntime.queryInterface(XStorable.class, document); |
134 |
|
139 |
store.storeAsURL(url, propsValue); |
135 |
String dateString = document.getText().getString(); |
140 |
app.closeDocument(document); |
136 |
assertTrue("Verify time field is creatd, by verify it's hour", dateString.indexOf(String.valueOf(dateField.Hours).trim()) != -1); |
141 |
|
137 |
assertTrue("Verify time field is creatd, by verify it's minutes", dateString.indexOf(String.valueOf(dateField.Minutes).trim()) != -1); |
142 |
try { |
138 |
int expectHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); |
143 |
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); |
139 |
assertEquals("Verify time field is creatd, value is right, by compare Hour", expectHour, dateField.Hours); |
144 |
XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); |
140 |
XStorable store = UnoRuntime.queryInterface(XStorable.class, document); |
145 |
XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); |
141 |
store.storeAsURL(url, propsValue); |
146 |
XEnumeration enumeration = xEnumeratedFields.createEnumeration(); |
142 |
app.closeDocument(document); |
147 |
while (enumeration.hasMoreElements()) { |
143 |
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); |
148 |
Object field = enumeration.nextElement(); |
144 |
XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); |
149 |
XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); |
145 |
XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); |
150 |
DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); |
146 |
XEnumeration enumeration = xEnumeratedFields.createEnumeration(); |
151 |
assertEquals("Verify time field is creatd correct by save and reload.", expectHour, dateField2.Hours); |
147 |
while (enumeration.hasMoreElements()) { |
152 |
} |
148 |
Object field = enumeration.nextElement(); |
153 |
|
149 |
XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); |
154 |
|
150 |
DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); |
155 |
} catch (Exception e) { |
151 |
assertEquals("Verify time field is creatd correct by save and reload.", expectHour, dateField2.Hours); |
156 |
e.printStackTrace(); |
|
|
157 |
} |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
} catch (com.sun.star.uno.Exception e) { |
163 |
e.printStackTrace(); |
164 |
} |
152 |
} |
165 |
|
153 |
|
|
|
154 |
|
166 |
} |
155 |
} |
167 |
/** |
156 |
/** |
168 |
* Test Date Field can be created correctly. |
157 |
* Test Date Field can be created correctly. |
Lines 170-179
Link Here
|
170 |
* 2.Verify the Date is created by check the date hour in the new document |
159 |
* 2.Verify the Date is created by check the date hour in the new document |
171 |
* 3.Save and close the new document to doc format |
160 |
* 3.Save and close the new document to doc format |
172 |
* 4.Reload the new save doc file, check the Date field |
161 |
* 4.Reload the new save doc file, check the Date field |
|
|
162 |
* @throws Exception |
173 |
*/ |
163 |
*/ |
174 |
|
164 |
|
175 |
@Test |
165 |
@Test |
176 |
public void testCreateDateFieldSaveDoc() { |
166 |
public void testCreateDateFieldSaveDoc() throws Exception { |
177 |
|
167 |
|
178 |
String url = Testspace.getUrl(tempPath + tempFileName + ".doc"); |
168 |
String url = Testspace.getUrl(tempPath + tempFileName + ".doc"); |
179 |
PropertyValue[] propsValue = new PropertyValue[1]; |
169 |
PropertyValue[] propsValue = new PropertyValue[1]; |
Lines 189-244
Link Here
|
189 |
* 2.Verify the dateField is created by check the date hour in the new document |
179 |
* 2.Verify the dateField is created by check the date hour in the new document |
190 |
* 3.Save and close the new document to doc format |
180 |
* 3.Save and close the new document to doc format |
191 |
* 4.Reload the new save odt file, check the date field |
181 |
* 4.Reload the new save odt file, check the date field |
|
|
182 |
* @throws Exception |
192 |
*/ |
183 |
*/ |
193 |
@Test |
184 |
@Test |
194 |
public void testCreateDateFieldSaveODT() { |
185 |
public void testCreateDateFieldSaveODT() throws Exception { |
195 |
|
186 |
|
196 |
String url = Testspace.getUrl(tempPath + tempFileName + ".odt"); |
187 |
String url = Testspace.getUrl(tempPath + tempFileName + ".odt"); |
197 |
PropertyValue[] propsValue = new PropertyValue[0]; |
188 |
PropertyValue[] propsValue = new PropertyValue[0]; |
198 |
createDateFiled(document, url, propsValue); |
189 |
createDateFiled(document, url, propsValue); |
199 |
|
190 |
|
200 |
} |
191 |
} |
201 |
private void createDateFiled(XTextDocument document, String url, PropertyValue[] propsValue) { |
192 |
private void createDateFiled(XTextDocument document, String url, PropertyValue[] propsValue) throws Exception { |
202 |
XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document); |
193 |
XMultiServiceFactory sevriceFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, document); |
203 |
try { |
194 |
XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime")); |
204 |
XTextField dateFiled = (XTextField)UnoRuntime.queryInterface(XTextField.class, sevriceFactory.createInstance("com.sun.star.text.textfield.DateTime")); |
|
|
205 |
|
206 |
|
195 |
|
207 |
XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); |
|
|
208 |
props.setPropertyValue("IsDate", true); |
209 |
|
210 |
document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); |
211 |
DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); |
212 |
|
196 |
|
213 |
String dateString = document.getText().getString(); |
197 |
XPropertySet props = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, dateFiled); |
214 |
assertTrue("Verify date field is creatd, by verify it's Month", dateString.indexOf(String.valueOf(dateField.Month).trim()) != -1); |
198 |
props.setPropertyValue("IsDate", true); |
215 |
assertTrue("Verify date field is creatd, by verify it's Day", dateString.indexOf(String.valueOf(dateField.Day).trim()) != -1); |
199 |
|
216 |
int expectDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
200 |
document.getText().insertTextContent(document.getText().getEnd(), dateFiled, false); |
217 |
assertEquals("Verify date field is creatd, value is right, by compare Day", expectDay, dateField.Day); |
201 |
DateTime dateField = (DateTime) props.getPropertyValue("DateTimeValue"); |
218 |
XStorable store = UnoRuntime.queryInterface(XStorable.class, document); |
202 |
|
219 |
store.storeAsURL(url, propsValue); |
203 |
String dateString = document.getText().getString(); |
220 |
app.closeDocument(document); |
204 |
assertTrue("Verify date field is creatd, by verify it's Month", dateString.indexOf(String.valueOf(dateField.Month).trim()) != -1); |
221 |
|
205 |
assertTrue("Verify date field is creatd, by verify it's Day", dateString.indexOf(String.valueOf(dateField.Day).trim()) != -1); |
222 |
try { |
206 |
int expectDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); |
223 |
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); |
207 |
assertEquals("Verify date field is creatd, value is right, by compare Day", expectDay, dateField.Day); |
224 |
XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); |
208 |
XStorable store = UnoRuntime.queryInterface(XStorable.class, document); |
225 |
XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); |
209 |
store.storeAsURL(url, propsValue); |
226 |
XEnumeration enumeration = xEnumeratedFields.createEnumeration(); |
210 |
app.closeDocument(document); |
227 |
while (enumeration.hasMoreElements()) { |
211 |
document = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, app.loadDocumentFromURL(url)); |
228 |
Object field = enumeration.nextElement(); |
212 |
XTextFieldsSupplier fieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, document); |
229 |
XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); |
213 |
XEnumerationAccess xEnumeratedFields = fieldsSupplier.getTextFields(); |
230 |
DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); |
214 |
XEnumeration enumeration = xEnumeratedFields.createEnumeration(); |
231 |
assertEquals("Verify date field is creatd correct by save and reload.", expectDay, dateField2.Day); |
215 |
while (enumeration.hasMoreElements()) { |
232 |
} |
216 |
Object field = enumeration.nextElement(); |
233 |
|
217 |
XPropertySet props2 = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, field); |
234 |
|
218 |
DateTime dateField2 = (DateTime) props2.getPropertyValue("DateTimeValue"); |
235 |
} catch (Exception e) { |
219 |
assertEquals("Verify date field is creatd correct by save and reload.", expectDay, dateField2.Day); |
236 |
e.printStackTrace(); |
|
|
237 |
} |
238 |
|
239 |
|
240 |
} catch (com.sun.star.uno.Exception e) { |
241 |
e.printStackTrace(); |
242 |
} |
220 |
} |
243 |
|
221 |
|
244 |
} |
222 |
} |