XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
XText xParentText = xText.getText();
assure("getText(): no parent", xParentText != null);
XTextRange xStart = xText.getStart();
assure("getStart(): no start", xStart != null);
XTextRange xEnd = xText.getEnd();
assure("getEnd(): no end", xEnd != null);
/*
String string = xText.getString();
assure("getString(): invalid string returned",
string != null && "AB".equals(string) );
*/
xText.setString("45");
{
String string = xText.getString();
assure("getString(): invalid string returned: " + string,
string != null && "45".equals(string) );
}
XTextCursor xTextCursor = xText.createTextCursor();
assure("createTextCursor(): failed", xTextCursor != null);
try {
xText.createTextCursorByRange(null);
assure("createTextCursorByRange(): null allowed?", false);
} catch (RuntimeException e) { /* expected */ }
XTextCursor xTextCursorStart = xText.createTextCursorByRange(xStart);
assure("createTextCursorByRange(): failed for start",
xTextCursorStart != null);
XTextCursor xTextCursorEnd = xText.createTextCursorByRange(xEnd);
assure("createTextCursorByRange(): failed for end",
xTextCursorEnd != null);
// move outside meta
xDocTextCursor.gotoStart(false);
try {
xText.insertString(null, "foo", false);
assure("insertString(): null allowed?", false);
} catch (RuntimeException e) { /* expected */ }
try {
xText.insertString(xDocTextCursor, "foo", false);
assure("insertString(): cursor outside allowed?", false);
} catch (RuntimeException e) { /* expected */ }
xStart = xText.getStart();
xText.insertString(xStart, "A", false);
{
String string = xText.getString();
assure("getString(): invalid string returned: " + string,
string != null && "A45".equals(string) );
}
xText.insertString(xEnd, "B", false);
{
String string = xText.getString();
assure("getString(): invalid string returned: " + string,
string != null && "A45B".equals(string) );
}
try {
xText.insertControlCharacter(null, HARD_HYPHEN, false);
assure("insertControlCharacter(): null allowed?", false);
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
xStart = xText.getStart();
try {
xText.insertControlCharacter(xDocTextCursor, HARD_HYPHEN, false);
assure("insertControlCharacter(): cursor outside allowed?", false);
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
xText.insertControlCharacter(xStart, HARD_HYPHEN, false);
{
String string = xText.getString();
assure("getString(): invalid string returned: " + string,
string != null && ('\u2011' + "A45B").equals(string) );
}
xText.insertControlCharacter(xEnd, HARD_HYPHEN, false);
{
String string = xText.getString();
assure("getString(): invalid string returned: " + string,
string != null &&
('\u2011' + "A45B" + '\u2011').equals(string) );
}
xText.setString("45");
try {
xText.insertTextContent(null, xMeta, false);
assure("insertTextContent(): null range allowed?", false);
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
try {
xText.insertTextContent(xStart, null, false);
assure("insertTextContent(): null content allowed?", false);
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
try {
xText.insertTextContent(xDocTextCursor, xMeta, false);
assure("insertTextContent(): cursor outside allowed?", false);
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
TextFieldNode field1 = new TextFieldNode( "f1" );
TextFieldNode field2 = new TextFieldNode( "f2" );
XTextContent xField1 = inserter.makeTextField(field1.getContent());
XTextContent xField2 = inserter.makeTextField(field2.getContent());
xStart = xText.getStart();
xText.insertTextContent(xStart, xField1, false);
TreeNode root = new TreeNode()
.appendChild( new TextNode("12") )
.appendChild( meta.dup()
.appendChild( field1.dup() )
.appendChild( new TextNode("45") ) )
.appendChild( new TextNode("6789") );
doTest(root, false);
xText.insertTextContent(xEnd, xField2, false);
root = new TreeNode()
.appendChild( new TextNode("12") )
.appendChild( meta.dup()
.appendChild( field1.dup() )
.appendChild( new TextNode("45") )
.appendChild( field2.dup() ) )
.appendChild( new TextNode("6789") );
doTest(root, false);
try {
xText.removeTextContent(null);
assure("removeTextContent(): null content allowed?", false);
} catch (RuntimeException e) { /* expected */ }
xText.removeTextContent(xField1);
XTextRange xAnchor = xMeta.getAnchor();
assure("getAnchor(): null", xAnchor != null);
// evil test case: insert ruby around meta
RubyNode ruby = new RubyNode( mkName("ruby") );
inserter.insertRange( new Range(2, 6, ruby) );
/* prevent caching...
root = new TreeNode()
.appendChild( new TextNode("12") )
.appendChild( ruby.dup()
.appendChild( meta.dup()
.appendChild( new TextNode("45") )
.appendChild( field2.dup() ) ) )
.appendChild( new TextNode("6789") );
doTest(root, false);
*/
XEnumerationAccess xEA = (XEnumerationAccess)
UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta);
XEnumeration xEnum = xEA.createEnumeration();
assure("createEnumeration(): returns null", xEnum != null);
{
assure("hasNext(): first missing", xEnum.hasMoreElements());
Object xElement = xEnum.nextElement();
XTextRange xPortion = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xElement);
XPropertySet xPropSet = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xPortion);
String type = (String) xPropSet.getPropertyValue("TextPortionType");
assure("first: not text", type.equals("Text"));
String txt = xPortion.getString();
assure("first: text differs: " + txt, "45".equals(txt));
}
{
assure("hasNext(): second missing", xEnum.hasMoreElements());
Object xElement = xEnum.nextElement();
XTextRange xPortion = (XTextRange)
UnoRuntime.queryInterface(XTextRange.class, xElement);
XPropertySet xPropSet = (XPropertySet)
UnoRuntime.queryInterface(XPropertySet.class, xPortion);
String type = (String) xPropSet.getPropertyValue("TextPortionType");
assure("second: not text", type.equals("TextField"));