1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package mod._sw;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import lib.TestCase;
import lib.TestEnvironment;
import lib.TestParameters;
import util.SOfficeFactory;
import com.sun.star.beans.Property;
import com.sun.star.beans.PropertyAttribute;
import com.sun.star.beans.XPropertySet;
import com.sun.star.text.ControlCharacter;
import com.sun.star.text.XParagraphCursor;
import com.sun.star.text.XSimpleText;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
/**
* Test for object which is represented by service
* <code>com.sun.star.text.TextCursor</code>. <p>
* Object implements the following interfaces :
* <ul>
* <li> <code>com::sun::star::text::XTextCursor</code></li>
* <li> <code>com::sun::star::text::XWordCursor</code></li>
* <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
* <li> <code>com::sun::star::text::XTextRange</code></li>
* <li> <code>com::sun::star::beans::XPropertySet</code></li>
* <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
* <li> <code>com::sun::star::beans::XPropertyState</code></li>
* <li> <code>com::sun::star::style::CharacterProperties</code></li>
* <li> <code>com::sun::star::text::XSentenceCursor</code></li>
* <li> <code>com::sun::star::style::ParagraphProperties</code></li>
* <li> <code>com::sun::star::text::XParagraphCursor</code></li>
* <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
* <li> <code>com::sun::star::util::XSortable</code></li>
* <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
* </ul> <p>
* This object test <b> is NOT </b> designed to be run in several
* threads concurrently.
* @see com.sun.star.text.XTextCursor
* @see com.sun.star.text.XWordCursor
* @see com.sun.star.style.CharacterPropertiesComplex
* @see com.sun.star.text.XTextRange
* @see com.sun.star.beans.XPropertySet
* @see com.sun.star.container.XContentEnumerationAccess
* @see com.sun.star.beans.XPropertyState
* @see com.sun.star.style.CharacterProperties
* @see com.sun.star.text.XSentenceCursor
* @see com.sun.star.style.ParagraphProperties
* @see com.sun.star.text.XParagraphCursor
* @see com.sun.star.document.XDocumentInsertable
* @see com.sun.star.util.XSortable
* @see com.sun.star.style.CharacterPropertiesAsian
* @see ifc.text._XTextCursor
* @see ifc.text._XWordCursor
* @see ifc.style._CharacterPropertiesComplex
* @see ifc.text._XTextRange
* @see ifc.beans._XPropertySet
* @see ifc.container._XContentEnumerationAccess
* @see ifc.beans._XPropertyState
* @see ifc.style._CharacterProperties
* @see ifc.text._XSentenceCursor
* @see ifc.style._ParagraphProperties
* @see ifc.text._XParagraphCursor
* @see ifc.document._XDocumentInsertable
* @see ifc.util._XSortable
* @see ifc.style._CharacterPropertiesAsian
*/
public class SwXTextCursor extends TestCase {
XTextDocument xTextDoc;
/**
* Creates text document.
*/
@Override
protected void initialize(TestParameters tParam, PrintWriter log) throws Exception {
SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
log.println("creating a textdocument");
xTextDoc = SOF.createTextDoc(null);
}
/**
* Disposes text document.
*/
@Override
protected void cleanup(TestParameters tParam, PrintWriter log) {
log.println(" disposing xTextDoc ");
util.DesktopTools.closeDoc(xTextDoc);
}
/**
* Creating a TestEnvironment for the interfaces to be tested. After major
* text of text document is obtained, text cursor is created and several
* paragraphs within the text are inserted to a text document. Finally,
* text cursor is returned as a test component.
* Object relations created :
* <ul>
* <li> <code>'XTEXT'</code> for
* {@link ifc.text._XTextRange} : major text of text document</li>
* </ul>
*/
@Override
protected TestEnvironment createTestEnvironment(TestParameters Param,
PrintWriter log) {
XInterface oObj = null;
log.println("creating a test environment");
// get the bodytext of textdocument here
log.println("getting the TextCursor");
final XSimpleText aText = xTextDoc.getText();
final XTextCursor textCursor = aText.createTextCursor();
oObj = textCursor;
log.println("inserting some text");
try {
for (int i = 0; i < 3; i++) {
aText.insertString(textCursor, "" + (3 - i), false);
for (int j = 0; j < 5; j++) {
aText.insertString(textCursor, "XTextCursor,XTextCursor",
false);
aText.insertString(textCursor, "The quick brown fox ",
false);
aText.insertString(textCursor, "jumps over the lazy dog ",
false);
}
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertControlCharacter(textCursor,
ControlCharacter.LINE_BREAK,
false);
}
} catch (com.sun.star.lang.IllegalArgumentException e) {
log.println("Error, insert text to text document.");
e.printStackTrace(log);
}
log.println("creating a new environment for SwXTextCursor object");
TestEnvironment tEnv = new TestEnvironment(oObj);
tEnv.addObjRelation("XTEXT", xTextDoc.getText());
XPropertySet xCursorProp = UnoRuntime.queryInterface(
XPropertySet.class, oObj);
String[] skipNames = { "ParaBackGraphicURL" };
String[] propertyNames = getPropertyNames(xCursorProp, skipNames);
tEnv.addObjRelation("PropertyNames", propertyNames);
tEnv.addObjRelation("SkipProperties", propertyNames);
//Adding relation for util.XSortable
final XParagraphCursor paragrCursor = UnoRuntime.queryInterface(
XParagraphCursor.class,
oObj);
final PrintWriter finalLog = log;
tEnv.addObjRelation("SORTCHECKER",
new ifc.util._XSortable.XSortChecker() {
PrintWriter out = finalLog;
public void setPrintWriter(PrintWriter log) {
out = log;
}
public void prepareToSort() {
textCursor.gotoEnd(false);
try {
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertString(textCursor, "4", false);
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertString(textCursor, "b", false);
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertString(textCursor, "3", false);
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertString(textCursor, "a", false);
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertString(textCursor, "23", false);
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
aText.insertString(textCursor, "ab", false);
aText.insertControlCharacter(textCursor,
ControlCharacter.PARAGRAPH_BREAK,
false);
} catch (com.sun.star.lang.IllegalArgumentException e) {
out.println("Unexpected exception:" + e);
}
out.println(
"Preparing cursor to sorting. Text before sorting:");
paragrCursor.gotoEnd(true);
for (int i = 0; i < 6; i++) {
paragrCursor.gotoPreviousParagraph(true);
}
out.println(textCursor.getString());
}
public boolean checkSort(boolean isSortNumbering,
boolean isSortAscending) {
out.println("Sort checking...");
String ls = System.getProperty("line.separator");
String text = paragrCursor.getString();
out.println("Text after sorting:\n" + text);
boolean res = false;
if (isSortNumbering) {
if (isSortAscending) {
res = text.endsWith(ls+"3"+ls+"4"+ls+"23");
if (!res) {
out.println("Text must ends by:\n" + "\r\n3\r\n4\r\n23\r\n");
}
} else {
res = text.startsWith("23"+ls+"4"+ls+"3"+ls);
if (!res) {
out.println("Text must starts with:\n" + "23\r\n4\r\n3\r\n");
}
}
} else {
if (isSortAscending) {
res = text.equals(ls+"23"+ls+"3"+ls+"4"+ls+"a"+ls+"ab"+ls+"b");
if (!res) {
out.println("Text must be equal to:\n" + "\r\n23\r\n3\r\n4\r\na\r\nab\r\nb\r\n");
}
} else {
res = text.endsWith("b"+ls+"ab"+ls+"a"+ls+"4"+ls+"3"+ls+"23"+ls);
if (!res) {
out.println("Text must be equal to:\n" + "b\r\nab\r\na\r\n4\r\n3\r\n23\r\n");
}
}
}
if (res) {
out.println("Sorted correctly");
}
return res;
}
});
return tEnv;
} // finish method getTestEnvironment
public String[] getPropertyNames(XPropertySet props, String[] skipList) {
Property[] the_props = props.getPropertySetInfo().getProperties();
ArrayList<String> names = new ArrayList<String>();
for (int i = 0; i < the_props.length; i++) {
boolean isWritable = ((the_props[i].Attributes & PropertyAttribute.READONLY) == 0);
if (isWritable && !Arrays.asList(skipList).contains(the_props[i].Name)) {
names.add(the_props[i].Name);
}
}
return names.toArray(new String[names.size()]);
}
} // finish class SwXTextCursor
|