summaryrefslogtreecommitdiff
path: root/sw/qa/complex
diff options
context:
space:
mode:
authorjmzambon <jeanmarczambon@gmail.com>2017-08-26 17:33:17 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-08-29 10:46:23 +0200
commit5a6ac13b7ccd121ede008238ee16a8c688910144 (patch)
treea6b6e1eac910bbb7c408dc8905bf044f5891877c /sw/qa/complex
parente6ec0794858df1444f43659b568119bf126a90e6 (diff)
tdf#97362: TextPortionEnumerationTest partially migrated to python (part 7)
Convert tests: - test_range2 - test_range3 - test_range4 - test_range5 - test_range6 - test_range7 - test_meta_xchild - test_meta_xtext - test_meta_xtextcursor - test_xtextcursor Change-Id: Iabfa51869611ee027565102f6658b045a182d66e Reviewed-on: https://gerrit.libreoffice.org/41589 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw/qa/complex')
-rw-r--r--sw/qa/complex/writer/TextPortionEnumerationTest.java788
1 files changed, 0 insertions, 788 deletions
diff --git a/sw/qa/complex/writer/TextPortionEnumerationTest.java b/sw/qa/complex/writer/TextPortionEnumerationTest.java
index 0866ec897d51..255d39d619aa 100644
--- a/sw/qa/complex/writer/TextPortionEnumerationTest.java
+++ b/sw/qa/complex/writer/TextPortionEnumerationTest.java
@@ -1258,794 +1258,6 @@ public class TextPortionEnumerationTest
util.DesktopTools.closeDoc(m_xDoc);
}
- @Test public void testRange2() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- TreeNode met1 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(1, 8, met1) );
- TreeNode met2 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(3/*-1*/, 8/*-1*/, met2) );
- TreeNode met3 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(5/*-2*/, 8/*-2*/, met3) );
- TreeNode root = new TreeNode()
- .appendChild( new TextNode("1") )
- .appendChild( met1.dup()
- .appendChild( new TextNode("2") )
- .appendChild( met2.dup()
- .appendChild( new TextNode("3") )
- .appendChild( met3.dup()
- .appendChild( new TextNode("456") ) )
- .appendChild( new TextNode("7") ) )
- .appendChild( new TextNode("8") ) )
- .appendChild( new TextNode("9") );
- doTest(root, false);
- // split ruby at every meta start!
- TreeNode rby4 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(0, 7/*-3*/, rby4) );
- root = new TreeNode()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("1") ) )
- .appendChild( met1.dup()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("2") ) )
- .appendChild( met2.dup()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("3") ) )
- .appendChild( met3.dup()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("4") ) )
- .appendChild( new TextNode("56") ) )
- .appendChild( new TextNode("7") ) )
- .appendChild( new TextNode("8") ) )
- .appendChild( new TextNode("9") );
- doTest(root, false);
- // split ruby at every meta end!
- TreeNode rby5 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(8/*-3*/, 12/*-3*/, rby5) );
- root = new TreeNode()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("1") ) )
- .appendChild( met1.dup()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("2") ) )
- .appendChild( met2.dup()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("3") ) )
- .appendChild( met3.dup()
- .appendChild( rby4.dup()
- .appendChild( new TextNode("4") ) )
- .appendChild( new TextNode("5") )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("6") ) ) )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("7") ) ) )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("8") ) ) )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("9") ) );
- doTest(root, false);
- }
-
- @Test public void testRange3() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- TreeNode rby1 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(0, 9, rby1) );
- TreeNode met2 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(2, 7, met2) );
- TreeNode root = new TreeNode()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("12") )
- .appendChild( met2.dup()
- .appendChild( new TextNode("34567") ) )
- .appendChild( new TextNode("89") ) );
- doTest(root, false);
- // overwrite outer ruby, split remains at inner meta!
- TreeNode rby3 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(5/*-1*/, 6/*-1*/, rby3) );
- root = new TreeNode()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("12") ) )
- .appendChild( met2.dup()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("34") ) )
- .appendChild( rby3.dup()
- .appendChild( new TextNode("5") ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("67") ) ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("89") ) );
- doTest(root, false);
- }
-
- @Test public void testRange4() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- TreeNode rby1 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(0, 9, rby1) );
- TreeNode met2 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(1, 8, met2) );
- TreeNode met3 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(3/*-1*/, 8/*-1*/, met3) );
- TreeNode met4 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(5/*-2*/, 8/*-2*/, met4) );
- TreeNode root = new TreeNode()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("1") )
- .appendChild( met2.dup()
- .appendChild( new TextNode("2") )
- .appendChild( met3.dup()
- .appendChild( new TextNode("3") )
- .appendChild( met4.dup()
- .appendChild( new TextNode("456") ) )
- .appendChild( new TextNode("7") ) )
- .appendChild( new TextNode("8") ) )
- .appendChild( new TextNode("9") ) );
- doTest(root, false);
- // overwrite outer ruby, split remains at every inner meta!
- TreeNode rby5 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(7/*-3*/, 8/*-3*/, rby5) );
- root = new TreeNode()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("1") ) )
- .appendChild( met2.dup()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("2") ) )
- .appendChild( met3.dup()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("3") ) )
- .appendChild( met4.dup()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("4") ) )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("5") ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("6") ) ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("7") ) ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("8") ) ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("9") ) );
- doTest(root, false);
- }
-
- @Test public void testRange5() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- TreeNode rby1 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(0, 9, rby1) );
- TreeNode met2 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(1, 3, met2) );
- TreeNode met3 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(5/*-1*/, 6/*-1*/, met3) );
- TreeNode met4 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(8/*-2*/, 10/*-2*/, met4) );
- TreeNode root = new TreeNode()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("1") )
- .appendChild( met2.dup().appendChild( new TextNode("23") ) )
- .appendChild( new TextNode("4") )
- .appendChild( met3.dup().appendChild( new TextNode("5") ) )
- .appendChild( new TextNode("6") )
- .appendChild( met4.dup().appendChild( new TextNode("78") ) )
- .appendChild( new TextNode("9") ) );
- doTest(root, false);
- // overwrite outer ruby, but split at inner metas!
- TreeNode rby5 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(3/*-1*/, 10/*-3*/, rby5) );
- root = new TreeNode()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("1") ) )
- .appendChild( met2.dup()
- .appendChild( rby1.dup()
- .appendChild( new TextNode("2") ) )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("3") ) ) )
- .appendChild( rby5.dup()
- .appendChild( new TextNode("4") )
- .appendChild( met3.dup()
- .appendChild( new TextNode("5") ) )
- .appendChild( new TextNode("6") ) )
- .appendChild( met4.dup()
- .appendChild( rby5.dup()
- .appendChild( new TextNode("7") ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("8") ) ) )
- .appendChild( rby1.dup()
- .appendChild( new TextNode("9") ) );
- doTest(root, false);
- }
-
- @Test public void testRange6() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- TreeNode met1 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(1, 5, met1) );
- TreeNode met2 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(3/*-1*/, 6/*-1*/, met2) );
- TreeNode met3 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(5/*-2*/, 7/*-2*/, met3) );
- TreeNode root = new TreeNode()
- .appendChild( new TextNode("1") )
- .appendChild( met1.dup()
- .appendChild( new TextNode("2") )
- .appendChild( met2.dup()
- .appendChild( new TextNode("3") )
- .appendChild( met3.dup()
- .appendChild( new TextNode("45") ) ) ) )
- .appendChild( new TextNode("6789") );
- doTest(root, false);
- // split at 3 metas, all at same position
- TreeNode rby4 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(7/*-3*/, 10/*-3*/, rby4) );
- root = new TreeNode()
- .appendChild( new TextNode("1") )
- .appendChild( met1.dup()
- .appendChild( new TextNode("2") )
- .appendChild( met2.dup()
- .appendChild( new TextNode("3") )
- .appendChild( met3.dup()
- .appendChild( new TextNode("4") )
- .appendChild( rby4.dup()
- .appendChild( new TextNode("5") ) ) ) ) )
- .appendChild( rby4.dup()
- .appendChild( new TextNode("67") ) )
- .appendChild( new TextNode("89") );
- doTest(root, false);
- }
-
- @Test public void testRange7() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- TreeNode url1 = new HyperlinkNode( mkName("url") );
- inserter.insertRange( new Range(1, 5, url1) );
- TreeNode met2 = new MetaNode( mkId("id") );
- inserter.insertRange( new Range(3, 5, met2) );
- TreeNode root = new TreeNode()
- .appendChild( new TextNode("1") )
- .appendChild( url1.dup()
- .appendChild( new TextNode("23") ) )
- .appendChild( met2.dup()
- .appendChild( url1.dup()
- .appendChild( new TextNode("45") ) ) )
- .appendChild( new TextNode("6789") );
- doTest(root, false);
- // this should result in not splitting the hyperlink, but due to API
- // we can't tell :(
- TreeNode rby3 = new RubyNode( mkName("ruby") );
- inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, rby3) );
- root = new TreeNode()
- .appendChild( new TextNode("1") )
- .appendChild( url1.dup()
- .appendChild( new TextNode("23") ) )
- .appendChild( met2.dup()
- .appendChild( url1.dup()
- .appendChild( new TextNode("4") ) )
- .appendChild( rby3.dup()
- .appendChild( url1.dup()
- .appendChild( new TextNode("5") ) ) ) )
- .appendChild( rby3.dup()
- .appendChild( new TextNode("67") ) )
- .appendChild( new TextNode("89") );
- doTest(root, false);
- }
-
- /* TODO: test partial selection, test UNDO/REDO */
-
- // #i109601# NestedTextContent and XChild
- @Test public void testMetaXChild() throws Exception
- {
- StringPair id1 = new StringPair("content.xml", mkName("id"));
- StringPair id2 = new StringPair("content.xml", mkName("id"));
- StringPair id3 = new StringPair("content.xml", mkName("id"));
- StringPair id4 = new StringPair("content.xml", mkName("id"));
- StringPair id5 = new StringPair("content.xml", mkName("id"));
- StringPair id6 = new StringPair("content.xml", mkName("id"));
- TreeNode meta1 = new MetaNode(id1);
- TreeNode meta2 = new MetaNode(id2);
- TreeNode meta3 = new MetaFieldNode(id3);
- TreeNode meta4 = new MetaNode(id4);
- TreeNode meta5 = new MetaNode(id5);
- TreeNode meta6 = new MetaFieldNode(id6);
- TreeNode root = new TreeNode()
- .appendChild( meta1.dup()
- .appendChild( new TextNode("1") ) )
- .appendChild( new TextNode("2") )
- .appendChild( meta2.dup()
- .appendChild( meta3.dup()
- .appendChild( new TextNode("34") )
- .appendChild( meta4.dup()
- .appendChild( new TextNode("56") ) )
- .appendChild( meta5.dup() )
- .appendChild( new TextNode("7") ) ) )
- .appendChild( new TextNode("8") )
- .appendChild( meta6.dup()
- .appendChild( new TextNode("9") ) );
-
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("123456789");
- inserter.insertRange( new Range(0, 0, text) );
- XTextContent xMeta1 = inserter.insertRange( new Range(0, 1, meta1) );
- XTextContent xMeta2 = inserter.insertRange( new Range(3, 8, meta2) );
- XTextContent xMeta3 = inserter.insertRange( new Range(4, 9, meta3) );
- XTextContent xMeta4 = inserter.insertRange( new Range(7, 9, meta4) );
- XTextContent xMeta5 = inserter.insertRange( new Range(10, 10, meta5) );
- XTextContent xMeta6 = inserter.insertRange( new Range(13, 14, meta6) );
-
- doTest(root, false);
-
- XText xDocText = m_xDoc.getText();
- XTextCursor xDocTextCursor = xDocText.createTextCursor();
- XParagraphCursor xParagraphCursor = UnoRuntime.queryInterface(XParagraphCursor.class, xDocTextCursor);
- xParagraphCursor.gotoNextParagraph(false); // second paragraph
- // X12XX34X56X78X9
- // 1 23 4 5 6
- // 1 452 6
- // 3
- StringPair [] nestedTextContent = new StringPair[] {
- null,
- id1,
- id1,
- null,
- id2,
- id3,
- id3,
- id3,
- id4,
- id4,
- id4,
- id5,
- id3,
- null,
- id6,
- id6,
- };
- XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xDocTextCursor);
- for (int i = 0; i < nestedTextContent.length; ++i) {
- Object oNTC = xPropertySet.getPropertyValue("NestedTextContent");
- XTextContent xNTC = UnoRuntime.queryInterface(XTextContent.class, oNTC);
- if (null == nestedTextContent[i]) {
- assertNull("unexpected NestedTextContent at: " + i, xNTC);
- } else {
- XMetadatable xMetadatable = UnoRuntime.queryInterface(XMetadatable.class, xNTC);
- StringPair xmlid = xMetadatable.getMetadataReference();
- assertTrue("wrong NestedTextContent at: " + i,
- MetaNode.eq(nestedTextContent[i], xmlid));
- }
- xDocTextCursor.goRight((short)1, false);
- }
-
- XChild xChild1 = UnoRuntime.queryInterface(XChild.class, xMeta1);
- XChild xChild2 = UnoRuntime.queryInterface(XChild.class, xMeta2);
- XChild xChild3 = UnoRuntime.queryInterface(XChild.class, xMeta3);
- XChild xChild4 = UnoRuntime.queryInterface(XChild.class, xMeta4);
- XChild xChild5 = UnoRuntime.queryInterface(XChild.class, xMeta5);
- XChild xChild6 = UnoRuntime.queryInterface(XChild.class, xMeta6);
- try {
- xChild1.setParent(xChild4);
- fail("setParent(): allowed?");
- } catch (NoSupportException e) { /* expected */ }
- assertNull("getParent(): not null", xChild1.getParent());
- assertNull("getParent(): not null", xChild2.getParent());
- assertNull("getParent(): not null", xChild6.getParent());
- {
- Object xParent3 = xChild3.getParent();
- assertNotNull("getParent(): null", xParent3);
- XMetadatable xMetadatable = UnoRuntime.queryInterface(XMetadatable.class, xParent3);
- StringPair xmlid = xMetadatable.getMetadataReference();
- assertTrue("getParent(): wrong", MetaNode.eq(xmlid, id2));
- }{
- Object xParent4 = xChild4.getParent();
- assertNotNull("getParent(): null", xParent4);
- XMetadatable xMetadatable = UnoRuntime.queryInterface(XMetadatable.class, xParent4);
- StringPair xmlid = xMetadatable.getMetadataReference();
- assertTrue("getParent(): wrong", MetaNode.eq(xmlid, id3));
- }{
- Object xParent5 = xChild5.getParent();
- assertNotNull("getParent(): null", xParent5);
- XMetadatable xMetadatable = UnoRuntime.queryInterface(XMetadatable.class, xParent5);
- StringPair xmlid = xMetadatable.getMetadataReference();
- assertTrue("getParent(): wrong", MetaNode.eq(xmlid, id3));
- }
- }
-
- /** test SwXMeta XText interface */
- @Test public void testMetaXText() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("12AB6789");
- inserter.insertRange( new Range(0, 0, text) );
- MetaNode meta = new MetaNode( mkId("id") );
- XTextContent xMeta = inserter.makeMeta();
-
- XText xDocText = m_xDoc.getText();
- XTextCursor xDocTextCursor = xDocText.createTextCursor();
- xDocTextCursor.goRight((short)3, false);
- xDocTextCursor.goRight((short)2, true);
- xDocText.insertTextContent(xDocTextCursor, xMeta, true);
-
- XMetadatable xMetadatable = UnoRuntime.queryInterface(XMetadatable.class, xMeta);
- xMetadatable.setMetadataReference(meta.getXmlId());
- 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 = 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 = UnoRuntime.queryInterface(XTextRange.class, xElement);
- XPropertySet xPropSet = 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 = UnoRuntime.queryInterface(XTextRange.class, xElement);
- XPropertySet xPropSet = UnoRuntime.queryInterface(XPropertySet.class, xPortion);
- String type = (String) xPropSet.getPropertyValue("TextPortionType");
- assertEquals("second: not text", "TextField", type);
- }
- // no ruby end here!!!
- assertFalse("hasNext(): more elements?", xEnum.hasMoreElements());
-
- XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, xMeta);
- xComponent.dispose();
-
- try {
- XTextCursor xCursor = xText.createTextCursor();
- assertNull("createTextCursor(): succeeds on disposed object?",
- xCursor);
- } catch (RuntimeException e) { /* expected */ }
- }
-
- /** check that cursor move methods move to positions in the meta,
- but do not move to positions outside the meta. */
- @Test public void testMetaXTextCursor() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- TreeNode text = new TextNode("Text. 12 More text here.");
- inserter.insertRange( new Range(0, 0, text) );
- MetaNode met1 = new MetaNode( mkId("id") );
- XTextContent xMeta = inserter.makeMeta();
-
- XText xDocText = m_xDoc.getText();
- XTextCursor xDocTextCursor = xDocText.createTextCursor();
- xDocTextCursor.goRight((short)7, false);
- xDocTextCursor.goRight((short)2, true);
- xDocText.insertTextContent(xDocTextCursor, xMeta, true);
- xDocTextCursor.gotoStart(true);
-
- XMetadatable xMetadatable = UnoRuntime.queryInterface(XMetadatable.class, xMeta);
- xMetadatable.setMetadataReference(met1.getXmlId());
- XText xText = UnoRuntime.queryInterface(XText.class, xMeta);
-
- XTextRange xStart = xText.getStart();
- assertNotNull("getStart(): no start", xStart);
- XTextRange xEnd = xText.getEnd();
- assertNotNull("getEnd(): no end", xEnd);
-
- XTextCursor xTextCursor = xText.createTextCursor();
- assertNotNull("createTextCursor(): no cursor", xTextCursor);
-
- // XTextCursor
- boolean bSuccess = false;
- xTextCursor.gotoStart(false);
- xTextCursor.gotoEnd(false);
- bSuccess = xTextCursor.goLeft((short)1, false);
- assertTrue("goLeft(): failed", bSuccess);
- bSuccess = xTextCursor.goLeft((short)1000, false);
- assertFalse("goLeft(): succeeded", bSuccess);
- bSuccess = xTextCursor.goRight((short)1, false);
- assertTrue("goRight(): failed", bSuccess);
- bSuccess = xTextCursor.goRight((short)1000, false);
- assertFalse("goRight(): succeeded", bSuccess);
- xTextCursor.gotoRange(xStart, false);
- xTextCursor.gotoRange(xEnd, false);
- try {
- xTextCursor.gotoRange(xDocTextCursor, false);
- fail("gotoRange(): succeeded");
- } catch (RuntimeException e) { /* expected */ }
-
- // XWordCursor
- xText.setString("Two words");
- xTextCursor.gotoStart(false);
- XWordCursor xWordCursor = UnoRuntime.queryInterface(XWordCursor.class, xTextCursor);
-
- bSuccess = xWordCursor.gotoNextWord(true); //at start of "words"
- assertTrue("gotoNextWord(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoNextWord(): wrong string",
- "Two ", string);
- }
- bSuccess = xWordCursor.gotoNextWord(false); //at end of "words", cannot leave metafield
- assertFalse("gotoNextWord(): succeeded", bSuccess);
- xTextCursor.collapseToEnd();
- bSuccess = xWordCursor.gotoPreviousWord(true); //at start of "words"
- assertTrue("gotoPreviousWord(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoPreviousWord(): wrong string",
- "words", string);
- }
- bSuccess = xWordCursor.gotoPreviousWord(false); //at start of "Two"
- assertTrue("gotoPreviousWord(): failed", bSuccess);
-
- bSuccess = xWordCursor.gotoPreviousWord(false); //cannot leave metafield
- assertFalse("gotoPreviousWord(): succeeded", bSuccess);
-
- bSuccess = xWordCursor.gotoEndOfWord(true); //at end of "Two"
- assertTrue("gotoEndOfWord(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoEndOfWord(): wrong string",
- "Two", string);
- }
- xTextCursor.gotoEnd(false);
- bSuccess = xWordCursor.gotoStartOfWord(true);
- assertTrue("gotoStartOfWord(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoStartOfWord(): wrong string",
- "words", string);
- }
- xText.setString("");
- bSuccess = xWordCursor.gotoEndOfWord(false);
- assertFalse("gotoEndOfWord(): succeeded", bSuccess);
- bSuccess = xWordCursor.gotoStartOfWord(false);
- assertFalse("gotoStartOfWord(): succeeded", bSuccess);
-
- // XSentenceCursor
- xText.setString("This is a sentence. Another sentence.");
- xTextCursor.gotoStart(false);
- XSentenceCursor xSentenceCursor = UnoRuntime.queryInterface(XSentenceCursor.class, xTextCursor);
-
- bSuccess = xSentenceCursor.gotoNextSentence(true);
- assertTrue("gotoNextSentence(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoNextSentence(): wrong string",
- "This is a sentence. ", string);
- }
- bSuccess = xSentenceCursor.gotoNextSentence(false);
- assertFalse("gotoNextSentence(): succeeded", bSuccess);
- // FIXME:
- // the sentence cursor seems to work differently than the word cursor
- xText.setString("This is a sentence. Another sentence. Sentence 3.");
- xTextCursor.gotoEnd(false);
- bSuccess = xSentenceCursor.gotoPreviousSentence(true);
- assertTrue("gotoPreviousSentence(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoPreviousSentence(): wrong string",
- "Another sentence. Sentence 3.", string);
- }
- bSuccess = xSentenceCursor.gotoPreviousSentence(false);
- assertFalse("gotoPreviousSentence(): succeeded", bSuccess);
- bSuccess = xSentenceCursor.gotoEndOfSentence(true);
- assertTrue("gotoEndOfSentence(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoEndOfSentence(): wrong string",
- "This is a sentence.", string);
- }
- xTextCursor.gotoEnd(false);
- bSuccess = xSentenceCursor.gotoStartOfSentence(true);
- assertTrue("gotoStartOfSentence(): failed", bSuccess);
- {
- String string = xTextCursor.getString();
- assertEquals("gotoStartOfSentence(): wrong string",
- "Sentence 3.", string);
- }
- xText.setString("");
- bSuccess = xSentenceCursor.gotoEndOfSentence(false);
- assertFalse("gotoEndOfSentence(): succeeded", bSuccess);
- bSuccess = xSentenceCursor.gotoStartOfSentence(false);
- assertFalse("gotoStartOfSentence(): succeeded", bSuccess);
-
- XParagraphCursor xParagraphCursor = UnoRuntime.queryInterface(XParagraphCursor.class, xTextCursor);
-
- // XParagraphCursor (does not make sense)
- bSuccess = xParagraphCursor.gotoNextParagraph(false);
- assertFalse("gotoNextParagraph(): succeeded", bSuccess);
- bSuccess = xParagraphCursor.gotoPreviousParagraph(false);
- assertFalse("gotoPreviousParagraph(): succeeded", bSuccess);
- bSuccess = xParagraphCursor.gotoStartOfParagraph(false);
- assertFalse("gotoStartOfParagraph(): succeeded", bSuccess);
- bSuccess = xParagraphCursor.gotoEndOfParagraph(false);
- assertFalse("gotoEndOfParagraph(): succeeded", bSuccess);
- }
-
- /** See https://bugs.libreoffice.org/show_bug.cgi?id=49629
- ensure that gotoEndOfWord does not fail when footnote is at word end*/
- @Test public void testXTextCursor() throws Exception
- {
- RangeInserter inserter = new RangeInserter(m_xDoc);
- XText xDocText = m_xDoc.getText();
- XTextCursor xDocTextCursor = xDocText.createTextCursor();
- inserter.insertText(xDocTextCursor, "Text");
- XWordCursor xWordCursor = UnoRuntime.queryInterface(XWordCursor.class, xDocTextCursor);
- xWordCursor.gotoEndOfWord(false);
- inserter.insertFootnote(xDocTextCursor, "footnote");
- xDocTextCursor.gotoStart(false);
- boolean bSuccess = xWordCursor.gotoEndOfWord(true);
- assertTrue("gotoEndOfWord(): failed", bSuccess);
- String string = xWordCursor.getString();
- assertEquals("gotoEndOfWord(): wrong string", "Text", string);
- }
-
private abstract class AttachHelper
{
abstract boolean isAttribute();