XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta);
XText xParentText = xText.getText();
assertNotNull("getText(): no parent", xParentText);
XTextRange xStart = xText.getStart();
assertNotNull("getStart(): no start", xStart);
XTextRange xEnd = xText.getEnd();
assertNotNull("getEnd(): no end", xEnd);
xText.setString("45");
{
String string = xText.getString();
assertEquals("getString(): invalid string returned",
"45", string);
}
XTextCursor xTextCursor = xText.createTextCursor();
assertNotNull("createTextCursor(): failed", xTextCursor);
try {
xText.createTextCursorByRange(null);
fail("createTextCursorByRange(): null allowed?");
} catch (RuntimeException e) { /* expected */ }
XTextCursor xTextCursorStart = xText.createTextCursorByRange(xStart);
assertNotNull("createTextCursorByRange(): failed for start",
xTextCursorStart);
XTextCursor xTextCursorEnd = xText.createTextCursorByRange(xEnd);
assertNotNull("createTextCursorByRange(): failed for end",
xTextCursorEnd);
// move outside meta
xDocTextCursor.gotoStart(false);
try {
xText.insertString(null, "foo", false);
fail("insertString(): null allowed?");
} catch (RuntimeException e) { /* expected */ }
try {
xText.insertString(xDocTextCursor, "foo", false);
fail("insertString(): cursor outside allowed?");
} catch (RuntimeException e) { /* expected */ }
xStart = xText.getStart();
xText.insertString(xStart, "A", false);
{
String string = xText.getString();
assertEquals("getString(): invalid string returned",
"A45", string);
}
xText.insertString(xEnd, "B", false);
{
String string = xText.getString();
assertEquals("getString(): invalid string returned",
"A45B", string);
}
try {
xText.insertControlCharacter(null, HARD_HYPHEN, false);
fail("insertControlCharacter(): null allowed?");
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
xStart = xText.getStart();
try {
xText.insertControlCharacter(xDocTextCursor, HARD_HYPHEN, false);
fail("insertControlCharacter(): cursor outside allowed?");
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
xText.insertControlCharacter(xStart, HARD_HYPHEN, false);
{
String string = xText.getString();
assertEquals("getString(): invalid string returned",
'\u2011' + "A45B", string);
}
xText.insertControlCharacter(xEnd, HARD_HYPHEN, false);
{
String string = xText.getString();
assertEquals("getString(): invalid string returned",
'\u2011' + "A45B" + '\u2011', string);
}
xText.setString("45");
try {
xText.insertTextContent(null, xMeta, false);
fail("insertTextContent(): null range allowed?");
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
try {
xText.insertTextContent(xStart, null, false);
fail("insertTextContent(): null content allowed?");
} catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ }
try {
xText.insertTextContent(xDocTextCursor, xMeta, false);
fail("insertTextContent(): cursor outside allowed?");
} 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);
fail("removeTextContent(): null content allowed?");
} catch (RuntimeException e) { /* expected */ }
xText.removeTextContent(xField1);
XTextRange xAnchor = xMeta.getAnchor();
assertNotNull("getAnchor(): null", xAnchor);
// 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();
assertNotNull("createEnumeration(): returns null", xEnum);
{
assertTrue("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");
assertEquals("first: not text", "Text", type);
String txt = xPortion.getString();
assertEquals("first: text differs", "45", txt);
}
{
assertTrue("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");
assertEquals("second: not text", "TextField", type);