diff options
Diffstat (limited to 'sw/qa')
34 files changed, 7936 insertions, 0 deletions
diff --git a/sw/qa/complex/accessibility/AccessibleRelationSet.java b/sw/qa/complex/accessibility/AccessibleRelationSet.java new file mode 100644 index 000000000000..b7f45d25db2b --- /dev/null +++ b/sw/qa/complex/accessibility/AccessibleRelationSet.java @@ -0,0 +1,252 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.accessibility; + +import com.sun.star.accessibility.AccessibleRelation; +import com.sun.star.accessibility.AccessibleRole; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleText; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleRelationSet; +import com.sun.star.awt.XWindow; +import com.sun.star.frame.XModel; +import com.sun.star.lang.IndexOutOfBoundsException; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.text.ControlCharacter; +import com.sun.star.text.XText; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextDocument; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import complexlib.ComplexTestCase; +import java.io.PrintWriter; +import lib.StatusException; +import util.AccessibilityTools; +import util.WriterTools; +import util.utils; + +public class AccessibleRelationSet extends ComplexTestCase { + + private static XAccessible para1 = null; + private static XAccessible para2 = null; + private static XAccessible para3 = null; + private static XTextDocument xTextDoc = null; + private final static String[] types = {"INVALID","CONTENT_FLOWS_FROM","CONTENT_FLOWS_TO","CONTROLLED_BY","CONTROLLER_FOR","LABEL_FOR","LABELED_BY","MEMBER_OF","SUB_WINDOW_OF"}; + + public String[] getTestMethodNames() { + return new String[]{"contents_flows_to","contents_flows_from"}; + } + + public void contents_flows_to() { + XAccessibleRelationSet set = getAccessibleRelation(para1); + + boolean res = true; + short firstrelation=-1; + XAccessibleText atarget=null; + if (set != null) { + log.println("Count of relations "+set.getRelationCount()); + assure("didn't gain correct count of relations", + set.getRelationCount() == 1); + try { + firstrelation = set.getRelation(0).RelationType; + Object oTmp = set.getRelation(0).TargetSet[0]; + atarget = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp); + } catch (IndexOutOfBoundsException e) { + log.println("Exception when getting relations "+e); + res = false; + } + } + + log.println("Expected for paragraph 0 "+types[2]); + log.println("gained for paragraph 0 "+types[firstrelation]); + res = types[2].equals(types[firstrelation]); + assure("didn't gain correct relation type",res); + + log.println("Text of target paragraph "+atarget.getText()); + XAccessibleText paraTxt2 = + (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, para2); + assure("didn't gain correct target paragraph", + atarget.getText().equals(paraTxt2.getText()) ); + } + + public void contents_flows_from() { + XAccessibleRelationSet set = getAccessibleRelation(para2); + + boolean res = true; + short[] relationtypes = new short[2]; + XAccessibleText[] atargets = new XAccessibleText[2]; + if (set != null) { + log.println("Count of relations "+set.getRelationCount()); + assure("didn't gain correct count of relations", + set.getRelationCount() == 2); + try { + short tmprelation = set.getRelation(0).RelationType; + if ( tmprelation == 1 ) + { + Object oTmp = set.getRelation(0).TargetSet[0]; + atargets[0] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp); + relationtypes[0] = tmprelation; + } + else if ( tmprelation == 2 ) + { + Object oTmp = set.getRelation(0).TargetSet[0]; + atargets[1] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp); + relationtypes[1] = tmprelation; + } + else + { + assure("didn't gain correct relation type", false); + } + tmprelation = set.getRelation(1).RelationType; + if ( tmprelation == 1 ) + { + Object oTmp = set.getRelation(1).TargetSet[0]; + atargets[0] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp); + relationtypes[0] = tmprelation; + } + else if ( tmprelation == 2 ) + { + Object oTmp = set.getRelation(1).TargetSet[0]; + atargets[1] = (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, oTmp); + relationtypes[1] = tmprelation; + } + else + { + assure("didn't gain correct relation type", false); + } + } catch (IndexOutOfBoundsException e) { + log.println("Exception when getting relations "+e); + res = false; + } + } + + log.println("### Checking "+types[1]+" for paragraph 1"); + log.println("Expected for paragraph 1 "+types[1]); + log.println("gained for paragraph 1 "+types[relationtypes[0]]); + res = types[1].equals(types[relationtypes[0]]); + assure("didn't gain correct relation type",res); + + log.println("Text of target paragraph "+atargets[0].getText()); + XAccessibleText paraTxt1 = + (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, para1); + assure("didn't gain correct target paragraph", + atargets[0].getText().equals(paraTxt1.getText()) ); + + log.println("### Checking "+types[2]+" for paragraph 1"); + log.println("Expected for paragraph 1 "+types[2]); + log.println("gained for paragraph 1 "+types[relationtypes[1]]); + res = types[2].equals(types[relationtypes[1]]); + assure("didn't gain correct relation type",res); + + log.println("Text of target paragraph "+atargets[1].getText()); + XAccessibleText paraTxt3 = + (XAccessibleText) UnoRuntime.queryInterface(XAccessibleText.class, para3); + assure("didn't gain correct target paragraph", + atargets[1].getText().equals(paraTxt3.getText()) ); + } + + private boolean getResult(XAccessible aPara, short index, int nr) { + XAccessibleRelationSet set = getAccessibleRelation(aPara); + + boolean res = true; + short firstrelation=-1; + if (set != null) { + log.println("Count of relations "+set.getRelationCount()); + try { + firstrelation = set.getRelation(0).RelationType; + } catch (IndexOutOfBoundsException e) { + log.println("Exception when getting relations "+e); + res = false; + } + } + + + log.println("Expected for paragraph "+nr+" "+types[index]); + log.println("gained for paragraph "+nr+" "+types[firstrelation]); + res = types[index].equals(types[firstrelation]); + return res; + } + + + public void before() { + log.println( "creating a text document" ); + xTextDoc = WriterTools.createTextDoc( (XMultiServiceFactory) param.getMSF()); + + XText oText = xTextDoc.getText(); + XTextCursor oCursor = oText.createTextCursor(); + + log.println( "inserting some lines" ); + try { + for (int i=0; i<5; i++){ + oText.insertString( oCursor,"Paragraph Number: " + i, false); + oText.insertControlCharacter( + oCursor, ControlCharacter.PARAGRAPH_BREAK, false ); + } + } catch ( com.sun.star.lang.IllegalArgumentException e ){ + e.printStackTrace((PrintWriter)log); + throw new StatusException( "Couldn't insert lines", e ); + } + + XModel aModel = (XModel) + UnoRuntime.queryInterface(XModel.class, xTextDoc); + + AccessibilityTools at = new AccessibilityTools(); + + XWindow xWindow = at.getCurrentWindow( (XMultiServiceFactory) param.getMSF(), aModel); + XAccessible xRoot = at.getAccessibleObject(xWindow); + + at.getAccessibleObjectForRole(xRoot, AccessibleRole.DOCUMENT); + + try { + para1 = at.SearchedContext.getAccessibleChild(0); + para2 = at.SearchedContext.getAccessibleChild(1); + para3 = at.SearchedContext.getAccessibleChild(2); + } catch(IndexOutOfBoundsException e) { + e.printStackTrace((PrintWriter)log); + throw new StatusException( "Couldn't insert lines", e ); + } + + log.println("ImplementationName (para1)" + utils.getImplName(para1)); + log.println("ImplementationName (para2)" + utils.getImplName(para2)); + } + + public void after() { + log.println("close text document"); + util.DesktopTools.closeDoc(xTextDoc); + } + + public XAccessibleRelationSet getAccessibleRelation(XAccessible xAcc) { + XAccessibleContext oObj = (XAccessibleContext) + UnoRuntime.queryInterface(XAccessibleContext.class, xAcc); + + XAccessibleRelationSet set = oObj.getAccessibleRelationSet(); + return set; + } + + +} diff --git a/sw/qa/complex/accessibility/makefile.mk b/sw/qa/complex/accessibility/makefile.mk new file mode 100644 index 000000000000..e4096829bb22 --- /dev/null +++ b/sw/qa/complex/accessibility/makefile.mk @@ -0,0 +1,57 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = AccessibleRelationSet +PRJNAME = sw +PACKAGE = complex$/accessibility + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar +JAVAFILES = AccessibleRelationSet.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + + +run: + +java -cp $(CLASSPATH) org.openoffice.Runner -TimeOut 0 -tb java_complex -o $(PACKAGE:s#$/#.#).$(JAVAFILES:b) diff --git a/sw/qa/complex/checkColor/CheckChangeColor.java b/sw/qa/complex/checkColor/CheckChangeColor.java new file mode 100755 index 000000000000..8a8c563c7eea --- /dev/null +++ b/sw/qa/complex/checkColor/CheckChangeColor.java @@ -0,0 +1,90 @@ +package complex.checkColor; + +import com.sun.star.awt.Rectangle; +import com.sun.star.awt.Size; +import com.sun.star.awt.WindowDescriptor; +import com.sun.star.awt.XControlModel; +import com.sun.star.awt.XToolkit; +import com.sun.star.awt.XWindow; +import com.sun.star.awt.XWindowPeer; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +import com.sun.star.drawing.XControlShape; +import com.sun.star.drawing.XShape; +import com.sun.star.frame.XComponentLoader; +import com.sun.star.frame.XController; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.style.XStyleFamiliesSupplier; +import com.sun.star.text.XTextDocument; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.view.XControlAccess; +import complexlib.ComplexTestCase; +import java.io.PrintWriter; +import util.FormTools; +import util.SOfficeFactory; +import util.WriterTools; + +/** + * Created because of complaint on dev@openoffice.org: check the changing of + * BackColor and IsLandscape properties on the PageStyle service. + */ +public class CheckChangeColor extends ComplexTestCase { + + private XToolkit xToolkit = null; + private XWindowPeer xWinPeer = null; + + /** + * Get all test method names. + * @return The test methods. + */ + public String[] getTestMethodNames() { + return new String[] {"checkChangeColor"}; + } + + + /** + * Check BackColor and IsLandscape properties, wait for an exception: test + * is ok if no exception happened. + */ + public void checkChangeColor() { + try { + XMultiServiceFactory m_xMSF_ = (XMultiServiceFactory)param.getMSF(); + XComponentLoader aLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class,m_xMSF_.createInstance( "com.sun.star.frame.Desktop" )); + XComponent xDocument = (XComponent)UnoRuntime.queryInterface(XComponent.class, aLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, new PropertyValue[ 0 ] ) ); + // xDocument.addEventListener( this ); + + XTextDocument oDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xDocument); + XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc ); + + // XInterface xInterface = (XInterface) oDocMSF.createInstance( "com.sun.star.style.PageStyle" ); + + // create a supplier to get the Style family collection + XStyleFamiliesSupplier xSupplier = ( XStyleFamiliesSupplier ) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, oDoc ); + + // get the NameAccess interface from the Style family collection + XNameAccess xNameAccess = xSupplier.getStyleFamilies(); + + XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName( "PageStyles" )); + + // create a PropertySet to set the properties for the new Pagestyle + XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPageStyleCollection.getByName("Standard") ); + + log.println("BackColor @ "+xPropertySet.getPropertyValue("BackColor").toString()); + log.println("IsLandscape @ "+xPropertySet.getPropertyValue("IsLandscape").toString()); + log.println("Size @ H:"+((Size)xPropertySet.getPropertyValue("Size")).Height+" W:"+((Size)xPropertySet.getPropertyValue("Size")).Width); + + log.println("Set Landscape"); + xPropertySet.setPropertyValue("IsLandscape",new Boolean(true) ); + log.println("Set BackColor"); + xPropertySet.setPropertyValue("BackColor",new Integer((int)255000000) ); + } + catch(Exception e) { + e.printStackTrace(); + failed("Exception."); + } + } +} diff --git a/sw/qa/complex/checkColor/makefile.mk b/sw/qa/complex/checkColor/makefile.mk new file mode 100755 index 000000000000..3048fb8fff95 --- /dev/null +++ b/sw/qa/complex/checkColor/makefile.mk @@ -0,0 +1,75 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = CheckChangeColor +PRJNAME = $(TARGET) +PACKAGE = complex$/checkColor + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = mysql.jar ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar mysql.jar +JAVAFILES = CheckChangeColor.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL : ALLTAR +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE : target.mk + +RUN: run + +run: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_NOOFFICE) $(CT_TEST) diff --git a/sw/qa/complex/indeterminateState/CheckIndeterminateState.java b/sw/qa/complex/indeterminateState/CheckIndeterminateState.java new file mode 100755 index 000000000000..7c3bf14f2e01 --- /dev/null +++ b/sw/qa/complex/indeterminateState/CheckIndeterminateState.java @@ -0,0 +1,136 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.indeterminateState; + +import complexlib.ComplexTestCase; +import helper.OfficeProvider; +import util.SOfficeFactory; +import util.AccessibilityTools; +import com.sun.star.awt.XWindow; +import com.sun.star.awt.XExtendedToolkit; +import com.sun.star.frame.XDispatch; +import com.sun.star.frame.XController; +import com.sun.star.frame.XDesktop; +import com.sun.star.frame.XModel; +import com.sun.star.text.XTextDocument; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XInterface; +import com.sun.star.accessibility.AccessibleRole; +import com.sun.star.accessibility.XAccessible; +import com.sun.star.accessibility.XAccessibleValue; +import com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.accessibility.XAccessibleStateSet; +import com.sun.star.accessibility.AccessibleStateType; +import com.sun.star.accessibility.XAccessibleAction; +import com.sun.star.awt.XTopWindow; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.frame.XDispatchProvider; +import com.sun.star.util.URL; +import com.sun.star.util.XURLTransformer; + +import java.io.PrintWriter; + +/** + */ +public class CheckIndeterminateState extends ComplexTestCase { + + /** + * Return all test methods. + * @return The test methods. + */ + public String[] getTestMethodNames() { + return new String[]{"checkToolBoxItem"}; + } + + /* + * Test the indeterminate state of AccessibleToolBarItem + * The used tools are in project qadevOOo/runner + */ + public void checkToolBoxItem() { + log.println( "creating a test environment" ); + XTextDocument xTextDoc = null; + // get a soffice factory object + SOfficeFactory SOF = SOfficeFactory.getFactory((XMultiServiceFactory) param.getMSF()); + + try { + log.println( "creating a text document" ); + xTextDoc = SOF.createTextDoc(null); + } catch ( com.sun.star.uno.Exception e ) { + // Some exception occures.FAILED + e.printStackTrace( (java.io.PrintWriter)log ); + failed (e.getMessage()); + } + + XModel aModel = (XModel) + UnoRuntime.queryInterface(XModel.class, xTextDoc); + + XController xController = aModel.getCurrentController(); + + XInterface oObj = null; + + System.out.println("Press any key after making 'Bold' indeterminate."); + try{ + byte[]b = new byte[16]; + System.in.read(b); + } catch (Exception e) { + e.printStackTrace(); + } + + AccessibilityTools at = new AccessibilityTools(); + XWindow xWindow = at.getCurrentContainerWindow((XMultiServiceFactory)param.getMSF(), aModel); + XAccessible xRoot = at.getAccessibleObject(xWindow); + + // uncomment to print the whole accessible tree. +// at.printAccessibleTree((java.io.PrintWriter)log,xRoot); + + oObj = at.getAccessibleObjectForRole(xRoot, + AccessibleRole.PUSH_BUTTON, "Bold"); + System.out.println("Found a PUSH_BUTTON: " + (oObj != null)); + + oObj = at.getAccessibleObjectForRole(xRoot, + AccessibleRole.TOGGLE_BUTTON, "Bold"); + System.out.println("Found a TOGGLE_BUTTON: " + (oObj != null)); + + log.println("ImplementationName: "+ util.utils.getImplName(oObj)); + + XAccessibleContext oContext = (XAccessibleContext) + UnoRuntime.queryInterface(XAccessibleContext.class, oObj); + + XAccessibleStateSet oSet = oContext.getAccessibleStateSet(); + + short[]states = oSet.getStates(); + for(int i=0; i<states.length; i++) + System.out.println("State "+i+": "+states[i]); + + assure("The 'INDETERMINATE' state is not set.",oSet.contains(AccessibleStateType.INDETERMINATE)); + } + +} + + diff --git a/sw/qa/complex/indeterminateState/makefile.mk b/sw/qa/complex/indeterminateState/makefile.mk new file mode 100755 index 000000000000..8850da116f5b --- /dev/null +++ b/sw/qa/complex/indeterminateState/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = CheckIndexedPropertyValue +PRJNAME = $(TARGET) +PACKAGE = complex$/indeterminateState + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = mysql.jar ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar +JAVAFILES = CheckIndeterminateState.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# start an office if the parameter is set for the makefile +.IF "$(OFFICE)" == "" +CT_APPEXECCOMMAND = +.ELSE +CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" +.ENDIF + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL: ALLTAR +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE : target.mk + +RUN: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) $(CT_TEST) + +run: RUN diff --git a/sw/qa/complex/writer/CheckBookmarks.java b/sw/qa/complex/writer/CheckBookmarks.java new file mode 100644 index 000000000000..0915db42e6ac --- /dev/null +++ b/sw/qa/complex/writer/CheckBookmarks.java @@ -0,0 +1,277 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.writer; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.container.XNamed; +import com.sun.star.container.XNameAccess; +import com.sun.star.frame.XStorable; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.text.XBookmarksSupplier; +import com.sun.star.text.XSimpleText; +import com.sun.star.text.XText; +import com.sun.star.text.XTextContent; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextDocument; +import com.sun.star.text.XTextRange; +import com.sun.star.uno.UnoRuntime; +import complexlib.ComplexTestCase; +import java.math.BigInteger; + +class BookmarkHashes { + public String m_sName; + public BigInteger m_nSetupHash; + public BigInteger m_nInsertRandomHash; + public BigInteger m_nDeleteRandomHash; + public BigInteger m_nLinebreakHash; + public BigInteger m_nOdfReloadHash; + public BigInteger m_nMsWordReloadHash; + + public BookmarkHashes(String sName) { + m_sName = sName; + } + + public String checkExpectationString(BookmarkHashes aExpectation) { + StringBuffer buffer = new StringBuffer(); + buffer.append("Comparing " + m_sName + " to expectations from " + aExpectation.m_sName + "\n"); + buffer.append(compareHashString("after setup", m_nSetupHash, aExpectation.m_nSetupHash)); + buffer.append(compareHashString("after insert random", m_nInsertRandomHash, aExpectation.m_nInsertRandomHash)); + buffer.append(compareHashString("after delete random", m_nDeleteRandomHash, aExpectation.m_nDeleteRandomHash)); + buffer.append(compareHashString("after line breaks", m_nLinebreakHash, aExpectation.m_nLinebreakHash)); + buffer.append(compareHashString("after ODF roundtrip", m_nOdfReloadHash, aExpectation.m_nOdfReloadHash)); + buffer.append(compareHashString("after MsWord roundtrip", m_nMsWordReloadHash, aExpectation.m_nMsWordReloadHash)); + return buffer.toString(); + }; + + public boolean meetsExpectation(BookmarkHashes aExpectation) { + return m_nSetupHash.equals(aExpectation.m_nSetupHash) + && m_nInsertRandomHash.equals(aExpectation.m_nInsertRandomHash) + && m_nDeleteRandomHash.equals(aExpectation.m_nDeleteRandomHash) + && m_nLinebreakHash.equals(aExpectation.m_nLinebreakHash) + && m_nOdfReloadHash.equals(aExpectation.m_nOdfReloadHash) + && m_nMsWordReloadHash.equals(aExpectation.m_nMsWordReloadHash); + } + + private String compareHashString(String sCheckName, BigInteger nActual, BigInteger nExpectation) { + StringBuffer buffer = new StringBuffer(sCheckName); + buffer.append(": "); + if(nActual.equals(nExpectation)) + buffer.append("good (" + nActual.toString(16) + ")"); + else + buffer.append("bad (actual:" + nActual.toString(16) + ", expected: " + nExpectation.toString(16) + ")"); + buffer.append("\n"); + return buffer.toString(); + } + + static public java.math.BigInteger getBookmarksHash(XTextDocument xDoc) + throws com.sun.star.uno.Exception, java.security.NoSuchAlgorithmException + { + StringBuffer buffer = new StringBuffer(""); + XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)UnoRuntime.queryInterface( + XBookmarksSupplier.class, + xDoc); + XNameAccess xBookmarks = xBookmarksSupplier.getBookmarks(); + for(String sBookmarkname : xBookmarks.getElementNames()) { + Object xBookmark = xBookmarks.getByName(sBookmarkname); + XTextContent xBookmarkAsContent = (XTextContent)UnoRuntime.queryInterface( + XTextContent.class, + xBookmark); + buffer.append(sBookmarkname); + buffer.append(":"); + buffer.append(xBookmarkAsContent.getAnchor().getString()); + buffer.append(";"); + } + java.security.MessageDigest sha1 = java.security.MessageDigest.getInstance("SHA-1"); + sha1.reset(); + sha1.update(buffer.toString().getBytes()); + return new java.math.BigInteger(sha1.digest()); + } +} + +public class CheckBookmarks extends ComplexTestCase { + private XMultiServiceFactory m_xMsf = null; + private XTextDocument m_xDoc = null; + private XTextDocument m_xOdfReloadedDoc = null; + private XTextDocument m_xMsWordReloadedDoc = null; + + public String[] getTestMethodNames() { + return new String[]{"checkBookmarks"}; + } + + private BookmarkHashes getDEV300m41Expectations() { + BookmarkHashes result = new BookmarkHashes("DEV300m41"); + result.m_nSetupHash = new BigInteger("-4b0706744e8452fe1ae9d5e1c28cf70fb6194795",16); + result.m_nInsertRandomHash = new BigInteger("25aa0fad3f4881832dcdfe658ec2efa8a1a02bc5",16); + result.m_nDeleteRandomHash = new BigInteger("-3ec87e810b46d734677c351ad893bbbf9ea10f55",16); + result.m_nLinebreakHash = new BigInteger("3ae08c284ea0d6e738cb43c0a8105e718a633550",16); + result.m_nOdfReloadHash = new BigInteger("3ae08c284ea0d6e738cb43c0a8105e718a633550",16); + result.m_nMsWordReloadHash = new BigInteger("3ae08c284ea0d6e738cb43c0a8105e718a633550",16); + return result; + } + + public void checkBookmarks() + throws com.sun.star.uno.Exception, + com.sun.star.io.IOException, + java.security.NoSuchAlgorithmException + { + try { + m_xMsf = (XMultiServiceFactory)param.getMSF(); + m_xDoc = util.WriterTools.createTextDoc(m_xMsf); + BookmarkHashes actualHashes = new BookmarkHashes("actual"); + BookmarkHashes expectedHashes = getDEV300m41Expectations(); + setupBookmarks(); + actualHashes.m_nSetupHash = BookmarkHashes.getBookmarksHash(m_xDoc); + insertRandomParts(200177); + actualHashes.m_nInsertRandomHash = BookmarkHashes.getBookmarksHash(m_xDoc); + deleteRandomParts(4711); + actualHashes.m_nDeleteRandomHash = BookmarkHashes.getBookmarksHash(m_xDoc); + insertLinebreaks(007); + actualHashes.m_nLinebreakHash = BookmarkHashes.getBookmarksHash(m_xDoc); + m_xOdfReloadedDoc = reloadFrom("StarOffice XML (Writer)", "odf"); + actualHashes.m_nOdfReloadHash = BookmarkHashes.getBookmarksHash(m_xOdfReloadedDoc); + m_xMsWordReloadedDoc = reloadFrom("MS Word 97", "doc"); + actualHashes.m_nMsWordReloadHash = BookmarkHashes.getBookmarksHash(m_xMsWordReloadedDoc); + log.println(actualHashes.checkExpectationString(expectedHashes)); + if(!actualHashes.meetsExpectation(expectedHashes)) + failed("CheckBookmark did not meet expectations (" + expectedHashes.m_sName + ")."); + } finally { + // closing test document + if(m_xDoc != null) + util.DesktopTools.closeDoc(m_xDoc); + if(m_xOdfReloadedDoc!= null) + util.DesktopTools.closeDoc(m_xOdfReloadedDoc); + if(m_xMsWordReloadedDoc!= null) + util.DesktopTools.closeDoc(m_xMsWordReloadedDoc); + } + } + + private void setupBookmarks() + throws com.sun.star.uno.Exception + { + XText xText = m_xDoc.getText(); + XSimpleText xSimpleText = (XSimpleText)UnoRuntime.queryInterface( + XSimpleText.class, + xText); + for(int nPara=0; nPara<10; ++nPara) { + for(int nBookmark=0; nBookmark<100; ++nBookmark){ + insertBookmark( + xText.createTextCursor(), + "P" + nPara + "word" + nBookmark, + "P" + nPara + "word" + nBookmark); + XTextCursor xWordCrsr = xText.createTextCursor(); + xWordCrsr.setString(" "); + } + XTextCursor xParaCrsr = xText.createTextCursor(); + XTextRange xParaCrsrAsRange = (XTextRange)UnoRuntime.queryInterface( + XTextRange.class, + xParaCrsr); + xText.insertControlCharacter(xParaCrsrAsRange, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false); + } + } + + private void insertRandomParts(long seed) + throws com.sun.star.uno.Exception + { + java.util.Random rnd = new java.util.Random(seed); + XTextCursor xCrsr = m_xDoc.getText().createTextCursor(); + for(int i=0; i<600; i++) { + xCrsr.goRight((short)rnd.nextInt(100), false); + xCrsr.setString(Long.toString(rnd.nextLong())); + } + } + + private void deleteRandomParts(long seed) + throws com.sun.star.uno.Exception + { + java.util.Random rnd = new java.util.Random(seed); + XTextCursor xCrsr = m_xDoc.getText().createTextCursor(); + for(int i=0; i<600; i++) { + xCrsr.goRight((short)rnd.nextInt(100), false); + xCrsr.goRight((short)rnd.nextInt(20), true); + xCrsr.setString(""); + } + } + + private void insertLinebreaks(long seed) + throws com.sun.star.uno.Exception + { + XText xText = m_xDoc.getText(); + java.util.Random rnd = new java.util.Random(seed); + XTextCursor xCrsr = m_xDoc.getText().createTextCursor(); + for(int i=0; i<30; i++) { + xCrsr.goRight((short)rnd.nextInt(300), false); + XTextRange xCrsrAsRange = (XTextRange)UnoRuntime.queryInterface( + XTextRange.class, + xCrsr); + xText.insertControlCharacter(xCrsrAsRange, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, false); + } + } + + private void insertBookmark(XTextCursor crsr, String name, String content) + throws com.sun.star.uno.Exception + { + XMultiServiceFactory xDocFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory.class, + m_xDoc); + + Object xBookmark = xDocFactory.createInstance("com.sun.star.text.Bookmark"); + XTextContent xBookmarkAsTextContent = (XTextContent)UnoRuntime.queryInterface( + XTextContent.class, + xBookmark); + crsr.setString(content); + XNamed xBookmarkAsNamed = (XNamed)UnoRuntime.queryInterface( + XNamed.class, + xBookmark); + xBookmarkAsNamed.setName(name); + m_xDoc.getText().insertTextContent(crsr, xBookmarkAsTextContent, true); + } + + private XTextDocument reloadFrom(String sFilter, String sExtension) + throws com.sun.star.io.IOException + { + String sFileUrl = util.utils.getOfficeTemp(m_xMsf) + "/Bookmarktest." + sExtension; + try { + PropertyValue[] aStoreProperties = new PropertyValue[2]; + aStoreProperties[0] = new PropertyValue(); + aStoreProperties[1] = new PropertyValue(); + aStoreProperties[0].Name = "Override"; + aStoreProperties[0].Value = true; + aStoreProperties[1].Name = "FilterName"; + aStoreProperties[1].Value = sFilter; + XStorable xStorable = (XStorable)UnoRuntime.queryInterface( + XStorable.class, + m_xDoc); + xStorable.storeToURL(sFileUrl, aStoreProperties); + return util.WriterTools.loadTextDoc(m_xMsf, sFileUrl); + } finally { + if(util.utils.fileExists(m_xMsf, sFileUrl)) + util.utils.deleteFile(m_xMsf, sFileUrl); + } + } +} diff --git a/sw/qa/complex/writer/CheckCrossReferences.java b/sw/qa/complex/writer/CheckCrossReferences.java new file mode 100644 index 000000000000..7b469c0a4afc --- /dev/null +++ b/sw/qa/complex/writer/CheckCrossReferences.java @@ -0,0 +1,369 @@ +/* + * CheckCrossReferences.java + * + * Created on November 1, 2007, 1:49 PM + * + * To change this template, choose Tools | Template Manager + * and open the template in the editor. + */ + +package complex.writer; + +import complexlib.ComplexTestCase; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.UnoRuntime; + +/** + * + * @author od138299 + */ +public class CheckCrossReferences extends ComplexTestCase { + + private com.sun.star.text.XTextDocument xDoc; + private com.sun.star.container.XEnumeration xParaEnum; + private com.sun.star.container.XEnumeration xPortionEnum; + private com.sun.star.util.XRefreshable xFldsRefresh; + + public String[] getTestMethodNames() { + return new String[]{"checkCrossReferences"}; + } + + public com.sun.star.text.XTextField getNextField() { + + com.sun.star.text.XTextField xField = null; + if ( xPortionEnum != null ) { + try { + while ( xPortionEnum.hasMoreElements() ) { + com.sun.star.beans.XPropertySet xPortionProps = + (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class , xPortionEnum.nextElement()); + final String sPortionType = + xPortionProps.getPropertyValue( "TextPortionType" ).toString(); + if ( sPortionType.equals( "TextField") ) { + xField = (com.sun.star.text.XTextField)UnoRuntime.queryInterface( + com.sun.star.text.XTextField.class, + xPortionProps.getPropertyValue( "TextField" ) ); + if ( xField == null ) { + System.out.println("Cannot retrieve next field."); + failed("Cannot retrieve next field."); + return null; + } + return xField; + } + } + } catch (com.sun.star.container.NoSuchElementException e) { + System.out.println("Cannot retrieve next field."); + e.printStackTrace(); + failed(e.getMessage()); + return null; + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Cannot retrieve next field."); + e.printStackTrace(); + failed(e.getMessage()); + return null; + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Cannot retrieve next field."); + e.printStackTrace(); + failed(e.getMessage()); + return null; + } + } + + while ( xParaEnum.hasMoreElements() ) { + try { + com.sun.star.container.XEnumerationAccess aPara = + (com.sun.star.container.XEnumerationAccess)UnoRuntime.queryInterface( + com.sun.star.container.XEnumerationAccess.class, xParaEnum.nextElement()); + xPortionEnum = aPara.createEnumeration(); + while ( xPortionEnum.hasMoreElements() ) { + com.sun.star.beans.XPropertySet xPortionProps = + (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class , xPortionEnum.nextElement()); + final String sPortionType = + xPortionProps.getPropertyValue( "TextPortionType" ).toString(); + if ( sPortionType.equals( "TextField") ) { + xField = (com.sun.star.text.XTextField)UnoRuntime.queryInterface( + com.sun.star.text.XTextField.class, + xPortionProps.getPropertyValue( "TextField" ) ); + if ( xField == null ) { + System.out.println("Cannot retrieve next field."); + failed("Cannot retrieve next field."); + return null; + } + return xField; + } + } + } catch (com.sun.star.container.NoSuchElementException e) { + System.out.println("Cannot retrieve next field."); + e.printStackTrace(); + failed(e.getMessage()); + return null; + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Cannot retrieve next field."); + e.printStackTrace(); + failed(e.getMessage()); + return null; + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Cannot retrieve next field."); + e.printStackTrace(); + failed(e.getMessage()); + return null; + } + } + + if ( xField == null ) { + System.out.println("Cannot retrieve next field."); + failed("Cannot retrieve next field."); + return null; + } + + return xField; + } + + public com.sun.star.beans.XPropertySet getFieldProps( + com.sun.star.text.XTextField xField ) { + com.sun.star.beans.XPropertySet xProps = + (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xField ); + + if ( xProps == null ) { + System.out.println("Cannot retrieve field properties."); + failed("Cannot retrieve field properties."); + return null; + } + + return xProps; + } + + public void checkField( com.sun.star.text.XTextField xField, + com.sun.star.beans.XPropertySet xProps, + short nFormat, + String aExpectedFldResult ) { + // set requested format + try { + xProps.setPropertyValue("ReferenceFieldPart", new Short(nFormat)); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Cannot set ReferenceFieldPart property at field."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } catch (com.sun.star.beans.PropertyVetoException e) { + System.out.println("Cannot set ReferenceFieldPart property at field."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Cannot set ReferenceFieldPart property at field."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } catch (com.sun.star.beans.UnknownPropertyException e) { + System.out.println("Cannot set ReferenceFieldPart property at field."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } + // refresh fields in order to get new format applied + xFldsRefresh.refresh(); + + String aFldResult = xField.getPresentation( false ); + assure( "set reference field format doesn't result in correct field result", + aFldResult.equals(aExpectedFldResult), true ); + } + + public void checkCrossReferences() throws com.sun.star.uno.Exception { + // load test document + try { + XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); + xDoc = util.WriterTools.loadTextDoc( xMSF, util.utils.getFullTestURL("CheckCrossReferences.odt")); + } catch(com.sun.star.uno.RuntimeException e) { + System.out.println("Cannot load test document."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } + + // setup paragraph enumeration + { + com.sun.star.container.XEnumerationAccess xParaEnumAccess = + (com.sun.star.container.XEnumerationAccess)UnoRuntime.queryInterface( + com.sun.star.container.XEnumerationAccess.class, xDoc.getText()); + xParaEnum = xParaEnumAccess.createEnumeration(); + } + + // get field refresher + { + com.sun.star.text.XTextFieldsSupplier xFieldSupp = + (com.sun.star.text.XTextFieldsSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextFieldsSupplier.class, xDoc); + xFldsRefresh = (com.sun.star.util.XRefreshable)UnoRuntime.queryInterface( + com.sun.star.util.XRefreshable.class, xFieldSupp.getTextFields()); + } + + // check first reference field + { + // strings for checking + final String FldResult1 = "*i*"; + final String FldResult2 = "+b+*i*"; + final String FldResult3 = "-1-+b+*i*"; + final String FldResult4 = "1."; + final String FldResult5 = " 1."; + final String FldResult6 = "A. 1."; + + // variables for current field + com.sun.star.text.XTextField xField = null; + com.sun.star.beans.XPropertySet xProps = null; + + log.println( "Checking field reference formats NUMBER, NUMBER_NO_CONTEXT and NUMBER_FULL_CONTEXT for existing fields" ); + xField = getNextField(); + xProps = getFieldProps( xField ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult2 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3 ); + + xField = getNextField(); + xProps = getFieldProps( xField ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult1 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3 ); + + xField = getNextField(); + xProps = getFieldProps( xField ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult3 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult1 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult3 ); + + xField = getNextField(); + xProps = getFieldProps( xField ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult5 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6 ); + + xField = getNextField(); + xProps = getFieldProps( xField ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult4 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6 ); + + xField = getNextField(); + xProps = getFieldProps( xField ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER, FldResult6 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_NO_CONTEXT, FldResult4 ); + checkField( xField, xProps, com.sun.star.text.ReferenceFieldPart.NUMBER_FULL_CONTEXT, FldResult6 ); + } + + // insert a certain cross-reference bookmark and a reference field to this bookmark + { + log.println("Checking insert of cross-reference bookmark and corresponding reference field"); + // restart paragraph enumeration + com.sun.star.container.XEnumerationAccess xParaEnumAccess = + (com.sun.star.container.XEnumerationAccess)UnoRuntime.queryInterface( + com.sun.star.container.XEnumerationAccess.class, xDoc.getText()); + xParaEnum = xParaEnumAccess.createEnumeration(); + + // iterate on the paragraphs to find certain paragraph to insert the bookmark + com.sun.star.text.XTextRange xParaTextRange = null; + while ( xParaEnum.hasMoreElements() ) { + try { + xParaTextRange = (com.sun.star.text.XTextRange)UnoRuntime.queryInterface( + com.sun.star.text.XTextRange.class, xParaEnum.nextElement()); + if ( xParaTextRange.getString().equals( "J" ) ) { + break; + } + else { + xParaTextRange = null; + } + } catch (com.sun.star.container.NoSuchElementException e) { + System.out.println("Cannot find paragraph to insert cross-reference bookmark."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } catch (com.sun.star.lang.WrappedTargetException e) { + System.out.println("Cannot find paragraph to insert cross-reference bookmark."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } + } + if ( xParaTextRange == null ) { + System.out.println("Cannot find paragraph to insert cross-reference bookmark."); + failed("Cannot find paragraph to insert cross-reference bookmark."); + return; + } + + // insert bookmark + XMultiServiceFactory xFac = (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory.class, xDoc); + final String cBookmarkName = "__RefNumPara__47114711"; + com.sun.star.text.XTextContent xBookmark = null; + try { + xBookmark = (com.sun.star.text.XTextContent)UnoRuntime.queryInterface( + com.sun.star.text.XTextContent.class, + xFac.createInstance( "com.sun.star.text.Bookmark" ) ); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Cannot create bookmark."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } catch (com.sun.star.uno.Exception e) { + System.out.println("Cannot create bookmark."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } + if ( xBookmark != null ) { + com.sun.star.container.XNamed xName = + (com.sun.star.container.XNamed)UnoRuntime.queryInterface( + com.sun.star.container.XNamed.class, xBookmark ); + xName.setName( cBookmarkName ); + xBookmark.attach(xParaTextRange.getStart()); + } + + // insert reference field, which references the inserted bookmark + com.sun.star.text.XTextContent xNewField = null; + try { + xNewField = (com.sun.star.text.XTextContent)UnoRuntime.queryInterface( + com.sun.star.text.XTextContent.class, + xFac.createInstance( "com.sun.star.text.TextField.GetReference" ) ); + } catch (com.sun.star.lang.IllegalArgumentException e) { + System.out.println("Cannot create new field."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } catch (com.sun.star.uno.Exception e) { + System.out.println("Cannot create new field."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } + if ( xNewField != null ) { + com.sun.star.beans.XPropertySet xFieldProps = + (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xNewField ); + xFieldProps.setPropertyValue( "ReferenceFieldPart", new Short(com.sun.star.text.ReferenceFieldPart.TEXT) ); + xFieldProps.setPropertyValue( "ReferenceFieldSource", new Short(com.sun.star.text.ReferenceFieldSource.BOOKMARK) ); + xFieldProps.setPropertyValue( "SourceName", cBookmarkName ); + com.sun.star.text.XTextRange xFieldTextRange = + (com.sun.star.text.XTextRange)UnoRuntime.queryInterface( + com.sun.star.text.XTextRange.class, xParaEnum.nextElement()); + xNewField.attach(xFieldTextRange.getEnd()); + xFldsRefresh.refresh(); + } + + // check inserted reference field + com.sun.star.text.XTextField xField = + (com.sun.star.text.XTextField)UnoRuntime.queryInterface( + com.sun.star.text.XTextField.class, xNewField ); + assure( "inserted reference field doesn't has correct field result", + xField.getPresentation( false ).equals("J"), true ); + + xParaTextRange.getStart().setString( "Hallo new bookmark: " ); + xFldsRefresh.refresh(); + assure( "inserted reference field doesn't has correct field result. Instead it's: "+xField.getPresentation( false ), + xField.getPresentation( false ).equals("Hallo new bookmark: J"), true ); + } + + // closing test document + util.DesktopTools.closeDoc( xDoc ); + } +} diff --git a/sw/qa/complex/writer/CheckFlies.java b/sw/qa/complex/writer/CheckFlies.java new file mode 100644 index 000000000000..50e94290c5b2 --- /dev/null +++ b/sw/qa/complex/writer/CheckFlies.java @@ -0,0 +1,233 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.writer; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.container.XNamed; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XIndexAccess; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.text.XTextDocument; +import com.sun.star.uno.UnoRuntime; +import complexlib.ComplexTestCase; +import java.math.BigInteger; +import java.util.Collection; +import java.util.ArrayList; + +public class CheckFlies extends ComplexTestCase { + private XMultiServiceFactory m_xMsf = null; + private XTextDocument m_xDoc = null; + + public String[] getTestMethodNames() { + return new String[]{"checkFlies"}; + } + + public void checkFlies() + throws com.sun.star.uno.Exception, + com.sun.star.io.IOException + { + try { + m_xMsf = (XMultiServiceFactory)param.getMSF(); + m_xDoc = util.WriterTools.loadTextDoc(m_xMsf, util.utils.getFullTestURL("CheckFlies.odt")); + com.sun.star.text.XTextFramesSupplier xTFS = (com.sun.star.text.XTextFramesSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextFramesSupplier.class, + m_xDoc); + checkTextFrames(xTFS); + com.sun.star.text.XTextGraphicObjectsSupplier xTGOS = (com.sun.star.text.XTextGraphicObjectsSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextGraphicObjectsSupplier.class, + m_xDoc); + checkGraphicFrames(xTGOS); + com.sun.star.text.XTextEmbeddedObjectsSupplier xTEOS = (com.sun.star.text.XTextEmbeddedObjectsSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextEmbeddedObjectsSupplier.class, + m_xDoc); + checkEmbeddedFrames(xTEOS); + } finally { + // closing test document + if(m_xDoc != null) + util.DesktopTools.closeDoc(m_xDoc); + } + } + + private void checkEmbeddedFrames(com.sun.star.text.XTextEmbeddedObjectsSupplier xTGOS) + throws com.sun.star.lang.WrappedTargetException + { + Collection<String> vExpectedEmbeddedFrames = new ArrayList<String>(); + vExpectedEmbeddedFrames.add("Object1"); + int nEmbeddedFrames = vExpectedEmbeddedFrames.size(); + com.sun.star.container.XNameAccess xEmbeddedFrames = xTGOS.getEmbeddedObjects(); + for(String sFrameName : xEmbeddedFrames.getElementNames()) + { + if(!vExpectedEmbeddedFrames.remove(sFrameName)) + failed("Unexpected frame name"); + try + { + xEmbeddedFrames.getByName(sFrameName); + } + catch(com.sun.star.container.NoSuchElementException e) + { + failed("Could not get embedded frame by name."); + } + if(!xEmbeddedFrames.hasByName(sFrameName)) + failed("Could not find embedded frame by name."); + } + if(!vExpectedEmbeddedFrames.isEmpty()) + failed("Missing expected embedded frames."); + try + { + xEmbeddedFrames.getByName("Nonexisting embedded frame"); + failed("Got nonexisting embedded frame"); + } + catch(com.sun.star.container.NoSuchElementException e) + {} + if(xEmbeddedFrames.hasByName("Nonexisting embedded frame")) + failed("Has nonexisting embedded frame"); + + com.sun.star.container.XIndexAccess xEmbeddedFramesIdx = (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface( + com.sun.star.container.XIndexAccess.class, + xEmbeddedFrames); + if(xEmbeddedFramesIdx.getCount() != nEmbeddedFrames) + failed("Unexpected number of embedded frames reported."); + for(int nCurrentFrameIdx = 0; nCurrentFrameIdx < xEmbeddedFramesIdx.getCount(); nCurrentFrameIdx++) + { + try + { + xEmbeddedFramesIdx.getByIndex(nCurrentFrameIdx); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) + { + failed("Could not get embedded frame by index."); + } + } + } + + private void checkGraphicFrames(com.sun.star.text.XTextGraphicObjectsSupplier xTGOS) + throws com.sun.star.lang.WrappedTargetException + { + Collection<String> vExpectedGraphicFrames = new ArrayList<String>(); + vExpectedGraphicFrames.add("graphics1"); + int nGraphicFrames = vExpectedGraphicFrames.size(); + com.sun.star.container.XNameAccess xGraphicFrames = xTGOS.getGraphicObjects(); + for(String sFrameName : xGraphicFrames.getElementNames()) + { + if(!vExpectedGraphicFrames.remove(sFrameName)) + failed("Unexpected frame name"); + try + { + xGraphicFrames.getByName(sFrameName); + } + catch(com.sun.star.container.NoSuchElementException e) + { + failed("Could not get graphics frame by name."); + } + if(!xGraphicFrames.hasByName(sFrameName)) + failed("Could not find graphics frame by name."); + } + if(!vExpectedGraphicFrames.isEmpty()) + failed("Missing expected graphics frames."); + try + { + xGraphicFrames.getByName("Nonexisting graphics frame"); + failed("Got nonexisting graphics frame"); + } + catch(com.sun.star.container.NoSuchElementException e) + {} + if(xGraphicFrames.hasByName("Nonexisting graphics frame")) + failed("Has nonexisting graphics frame"); + + com.sun.star.container.XIndexAccess xGraphicFramesIdx = (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface( + com.sun.star.container.XIndexAccess.class, + xGraphicFrames); + if(xGraphicFramesIdx.getCount() != nGraphicFrames) + failed("Unexpected number of graphics frames reported."); + for(int nCurrentFrameIdx = 0; nCurrentFrameIdx < xGraphicFramesIdx.getCount(); nCurrentFrameIdx++) + { + try + { + xGraphicFramesIdx.getByIndex(nCurrentFrameIdx); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) + { + failed("Could not get graphics frame by index."); + } + } + } + + private void checkTextFrames(com.sun.star.text.XTextFramesSupplier xTFS) + throws com.sun.star.lang.WrappedTargetException + { + Collection<String> vExpectedTextFrames = new ArrayList<String>(); + vExpectedTextFrames.add("Frame1"); + vExpectedTextFrames.add("Frame2"); + + int nTextFrames = vExpectedTextFrames.size(); + com.sun.star.container.XNameAccess xTextFrames = xTFS.getTextFrames(); + for(String sFrameName : xTextFrames.getElementNames()) + { + if(!vExpectedTextFrames.remove(sFrameName)) + failed("Unexpected frame name"); + try + { + xTextFrames.getByName(sFrameName); + } + catch(com.sun.star.container.NoSuchElementException e) + { + failed("Could not get text frame by name."); + } + if(!xTextFrames.hasByName(sFrameName)) + failed("Could not find text frame by name."); + } + if(!vExpectedTextFrames.isEmpty()) + failed("Missing expected text frames."); + try + { + xTextFrames.getByName("Nonexisting Textframe"); + failed("Got nonexisting text frame."); + } + catch(com.sun.star.container.NoSuchElementException e) + {} + if(xTextFrames.hasByName("Nonexisting text frame")) + failed("Has nonexisting text frame."); + + com.sun.star.container.XIndexAccess xTextFramesIdx = (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface( + com.sun.star.container.XIndexAccess.class, + xTextFrames); + if(xTextFramesIdx.getCount() != nTextFrames) + failed("Unexpected number of text frames reported."); + for(int nCurrentFrameIdx = 0; nCurrentFrameIdx < xTextFramesIdx.getCount(); nCurrentFrameIdx++) + { + try + { + xTextFramesIdx.getByIndex(nCurrentFrameIdx); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) + { + failed("Could not get text frame by index."); + } + } + } +} diff --git a/sw/qa/complex/writer/CheckIndexedPropertyValues.java b/sw/qa/complex/writer/CheckIndexedPropertyValues.java new file mode 100755 index 000000000000..aca4f68c7ec2 --- /dev/null +++ b/sw/qa/complex/writer/CheckIndexedPropertyValues.java @@ -0,0 +1,182 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.writer; + +import complexlib.ComplexTestCase; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.beans.PropertyValue; +import com.sun.star.container.XIndexContainer; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.Type; + +/** + * Test the com.sun.star.document.IndexedPropertyValues service + */ +public class CheckIndexedPropertyValues extends ComplexTestCase { + + private final String testedServiceName = + "com.sun.star.document.IndexedPropertyValues"; + public String[] getTestMethodNames() { + return new String[]{"checkIndexedPropertyValues"}; + } + +/* public String getTestObjectName() { + return testedServiceName; + } +*/ + public void checkIndexedPropertyValues() { + Object oObj = null; + try { + // print information about the service + XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); + oObj = xMSF.createInstance(testedServiceName); + System.out.println("****************"); + System.out.println("Service Name:"); + util.dbg.getSuppServices(oObj); + System.out.println("****************"); + System.out.println("Interfaces:"); + util.dbg.printInterfaces((XInterface)oObj, true); + } + catch(com.sun.star.uno.Exception e) { + System.out.println("Cannot create object."); + e.printStackTrace(); + failed(e.getMessage()); + return; + } + XIndexContainer xCont = (XIndexContainer)UnoRuntime.queryInterface( + XIndexContainer.class, oObj); + + assure("XIndexContainer was queried but returned null.", + (xCont != null)); + PropertyValue[] prop1 = new PropertyValue[1]; + prop1[0] = new PropertyValue(); + prop1[0].Name = "Jupp"; + prop1[0].Value = "GoodGuy"; + + PropertyValue[] prop2 = new PropertyValue[1]; + prop2[0] = new PropertyValue(); + prop2[0].Name = "Horst"; + prop2[0].Value = "BadGuy"; + + try { + Type t = xCont.getElementType(); + log.println("Insertable Type: " + t.getTypeName()); + assure("Initial container is not empty: " + xCont.getCount(), xCont.getCount()==0); + log.println("Inserting a PropertyValue."); + xCont.insertByIndex(0, prop1); + PropertyValue[]ret = (PropertyValue[])xCont.getByIndex(0); + assure("Got the wrong PropertyValue: " + + ret[0].Name + " " +(String)ret[0].Value, + ret[0].Name.equals(prop1[0].Name) && + ret[0].Value.equals(prop1[0].Value)); + log.println("Replace the PropertyValue."); + xCont.replaceByIndex(0, prop2); + ret = (PropertyValue[])xCont.getByIndex(0); + assure("Got the wrong PropertyValue: " + + ret[0].Name + " " +(String)ret[0].Value, + ret[0].Name.equals(prop2[0].Name) && + ret[0].Value.equals(prop2[0].Value)); + log.println("Remove the PropertyValue."); + xCont.removeByIndex(0); + assure("Could not remove PropertyValue.", + !xCont.hasElements() && xCont.getCount()==0); + log.println("Insert again."); + xCont.insertByIndex(0, prop1); + xCont.insertByIndex(1, prop2); + assure("Did not insert PropertyValue.", + xCont.hasElements() && xCont.getCount()==2); + + try { + log.println("Insert with wrong index."); + xCont.insertByIndex(25, prop2); + failed("IllegalArgumentException was not thrown."); + } + catch(com.sun.star.lang.IllegalArgumentException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Expected exception thrown: "+e); + } + catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + + try { + log.println("Remove non-existing index."); + xCont.removeByIndex(25); + failed("IndexOutOfBoundsException was not thrown."); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Expected exception thrown: "+e); + } + catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + + try { + log.println("Insert wrong argument."); + xCont.insertByIndex(2, "Example String"); + failed("IllegalArgumentException was not thrown."); + } + catch(com.sun.star.lang.IllegalArgumentException e) { + log.println("Expected exception thrown: " + e); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + + } + catch(com.sun.star.lang.IllegalArgumentException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.lang.IndexOutOfBoundsException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + } + +} diff --git a/sw/qa/complex/writer/CheckNamedPropertyValues.java b/sw/qa/complex/writer/CheckNamedPropertyValues.java new file mode 100755 index 000000000000..851381cf3c24 --- /dev/null +++ b/sw/qa/complex/writer/CheckNamedPropertyValues.java @@ -0,0 +1,196 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.writer; + + +import complexlib.ComplexTestCase; +import com.sun.star.beans.PropertyValue; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.uno.XInterface; +import com.sun.star.container.XNameContainer; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.Type; + +/** + * + */ +public class CheckNamedPropertyValues extends ComplexTestCase { + + private final String testedServiceName = + "com.sun.star.document.NamedPropertyValues"; + + public String[] getTestMethodNames() { + return new String[]{"checkNamedPropertyValues"}; + } + +/* public String getTestObjectName() { + return "complex.writer.CheckNamedPropertyValues"; + } */ + + public void checkNamedPropertyValues() { + Object oObj = null; + try { + XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); + oObj = xMSF.createInstance(testedServiceName); + System.out.println("****************"); + System.out.println("Service Name:"); + util.dbg.getSuppServices(oObj); + System.out.println("****************"); + System.out.println("Interfaces:"); + util.dbg.printInterfaces((XInterface)oObj, true); + } + catch(com.sun.star.uno.Exception e) { + e.printStackTrace(); + failed(e.getMessage()); + return; + } + XNameContainer xCont = (XNameContainer)UnoRuntime.queryInterface( + XNameContainer.class, oObj); + + assure("XNameContainer was queried but returned null.", + (xCont != null)); + PropertyValue[] prop1 = new PropertyValue[1]; + prop1[0] = new PropertyValue(); + prop1[0].Name = "Jupp"; + prop1[0].Value = "GoodGuy"; + + PropertyValue[] prop2 = new PropertyValue[1]; + prop2[0] = new PropertyValue(); + prop2[0].Name = "Horst"; + prop2[0].Value = "BadGuy"; + + try { + Type t = xCont.getElementType(); + log.println("Insertable Type: " + t.getTypeName()); + assure("Initial container is not empty.", !xCont.hasElements()); + + log.println("Insert a PropertyValue."); + xCont.insertByName("prop1", prop1); + PropertyValue[]ret = (PropertyValue[])xCont.getByName("prop1"); + assure("Got the wrong PropertyValue: " + + ret[0].Name + " " +(String)ret[0].Value, + ret[0].Name.equals(prop1[0].Name) && + ret[0].Value.equals(prop1[0].Value)); + log.println("Replace the PropertyValue."); + xCont.replaceByName("prop1", prop2); + ret = (PropertyValue[])xCont.getByName("prop1"); + assure("Got the wrong PropertyValue: " + + ret[0].Name + " " +(String)ret[0].Value, + ret[0].Name.equals(prop2[0].Name) && + ret[0].Value.equals(prop2[0].Value)); + log.println("Remove the PropertyValue."); + xCont.removeByName("prop1"); + assure("Could not remove PropertyValue.", !xCont.hasElements()); + log.println("Insert again."); + xCont.insertByName("prop1", prop1); + xCont.insertByName("prop2", prop2); + assure("Did not insert PropertyValue.", xCont.hasElements()); + String[] names = xCont.getElementNames(); + int count = 0; + for (int i=0; i<names.length; i++) { + if (names[i].equals("prop1") || names[i].equals("prop2")) + count++; + else + failed("Got a wrong element name: "+names[i]); + } + if (count != 2) + failed("Not all element names were returned."); + + try { + log.println("Insert PropertyValue with an existing name."); + xCont.insertByName("prop2", prop1); + failed("ElementExistException was not thrown."); + } + catch(com.sun.star.lang.IllegalArgumentException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.container.ElementExistException e) { + log.println("Expected exception thrown: "+e); + } + catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + + try { + log.println("Inserting a wrong argument."); + xCont.insertByName("prop3", "Example String"); + failed("IllegalArgumentException was not thrown."); + } + catch(com.sun.star.lang.IllegalArgumentException e) { + log.println("Expected exception thrown: "+e); + } + catch(com.sun.star.container.ElementExistException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + + try { + log.println("Remove a non-existing element."); + xCont.removeByName("prop3"); + failed("NoSuchElementException was not thrown."); + } + catch(com.sun.star.container.NoSuchElementException e) { + log.println("Expected exception thrown: "+e); + } + catch(com.sun.star.lang.WrappedTargetException e) { + log.println("Wrong exception thrown."); + failed(e.getMessage()); + e.printStackTrace(); + } + + } + catch(com.sun.star.lang.IllegalArgumentException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.container.ElementExistException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.container.NoSuchElementException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + catch(com.sun.star.lang.WrappedTargetException e) { + failed(e.getMessage()); + e.printStackTrace(); + } + } + + +} diff --git a/sw/qa/complex/writer/TextPortionEnumerationTest.java b/sw/qa/complex/writer/TextPortionEnumerationTest.java new file mode 100755 index 000000000000..2eda02bfa518 --- /dev/null +++ b/sw/qa/complex/writer/TextPortionEnumerationTest.java @@ -0,0 +1,4251 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.writer; + +import complexlib.ComplexTestCase; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XServiceInfo; +import com.sun.star.lang.NoSupportException; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.Pair; +import com.sun.star.beans.StringPair; +import com.sun.star.container.XNamed; +import com.sun.star.container.XChild; +import com.sun.star.container.XIndexAccess; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XContentEnumerationAccess; +import com.sun.star.container.XEnumerationAccess; +import com.sun.star.container.XEnumeration; +import com.sun.star.container.NoSuchElementException; +import com.sun.star.frame.XStorable; +import com.sun.star.util.XCloseable; +import com.sun.star.text.XText; +import com.sun.star.text.XTextContent; +import com.sun.star.text.XTextDocument; +import com.sun.star.text.XTextRange; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XWordCursor; +import com.sun.star.text.XSentenceCursor; +import com.sun.star.text.XParagraphCursor; +import com.sun.star.text.XFootnote; +import com.sun.star.text.XTextField; +import com.sun.star.text.XBookmarksSupplier; +import com.sun.star.text.XTextSectionsSupplier; +import com.sun.star.text.XDocumentIndexesSupplier; +import com.sun.star.text.TextContentAnchorType; +import static com.sun.star.text.TextContentAnchorType.*; +import static com.sun.star.text.ControlCharacter.*; +import com.sun.star.rdf.XMetadatable; +import com.sun.star.rdf.Statement; +import com.sun.star.rdf.XDocumentRepository; +import com.sun.star.rdf.XRepositorySupplier; + +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; +import java.util.Stack; + + +class TreeNodeEnum +{ + private Object[] m_Elements; + private int m_Pos; + TreeNodeEnum(Object[] Elements) { m_Elements = Elements; m_Pos = 0; } + boolean hasNext() { return m_Pos < m_Elements.length; } + TreeNode next() { return (TreeNode) m_Elements[m_Pos++]; } +} + +/** base class for tree nodes. only instance: root of tree. */ +class TreeNode +{ + private List<TreeNode> m_Children; + String getType() { return "__ROOT__"; } + boolean hasContent() { return false; } + boolean isNesting() { return false; } + TreeNode dup() { throw new RuntimeException("TreeNode.dup"); } + TreeNodeEnum createEnumeration() { + return new TreeNodeEnum(m_Children.toArray()); + } + TreeNode() { m_Children = new ArrayList<TreeNode>(); } + TreeNode appendChild(TreeNode child) + { m_Children.add(child); return this; } + public String toString() { + return "<" + getType() + ">"; + } +} + +abstract class MarkNode extends TreeNode +{ + boolean m_isPoint; + boolean m_isStart = false; + String m_Name; + boolean isPoint() { return m_isPoint; } + boolean isStart() { return m_isStart; } + String getName() { return m_Name; } + MarkNode(String name) { m_Name = name; m_isPoint = true; } + boolean equals(MarkNode other) { + return (other.m_Name.equals(m_Name)) && (other.m_isPoint == m_isPoint) + && (other.m_isStart == m_isStart); + } + public String toString() { + return super.toString() + "\tname: " + m_Name + + "\tisPoint: " + m_isPoint + "\tisStart: " + m_isStart; + } +} + +class BookmarkNode extends MarkNode +{ + private StringPair m_XmlId; + StringPair getXmlId() { return m_XmlId; } + BookmarkNode dup() { return new BookmarkNode(getName(), getXmlId()); } + BookmarkNode(String name) { this(name, new StringPair()); } + BookmarkNode(String name, StringPair xmlid) { + super(name); m_XmlId = xmlid; + } + String getType() { return "Bookmark"; } + public boolean equals(Object other) { + return (other instanceof BookmarkNode) + && super.equals((MarkNode) other) + && MetaNode.eq(((BookmarkNode) other).m_XmlId, m_XmlId); + } + public String toString() { + return super.toString() + + "\txmlid: " + m_XmlId.First + "#" + m_XmlId.Second; + } +} + +class BookmarkStartNode extends BookmarkNode +{ + BookmarkStartNode dup() { return new BookmarkStartNode(getName()); } + BookmarkStartNode(String name) { this(name, new StringPair()); } + BookmarkStartNode(String name, StringPair xmlid) { + super(name, xmlid); m_isPoint = false; m_isStart = true; + } +} + +class BookmarkEndNode extends BookmarkNode +{ + BookmarkEndNode dup() { return new BookmarkEndNode(getName()); } + BookmarkEndNode(String name) { this(name, new StringPair()); } + BookmarkEndNode(String name, StringPair xmlid) { + super(name, xmlid); m_isPoint = false; m_isStart = false; + } +} + +class ReferenceMarkNode extends MarkNode +{ + ReferenceMarkNode dup() { return new ReferenceMarkNode(getName()); } + ReferenceMarkNode(String name) { super(name); } + String getType() { return "ReferenceMark"; } + public boolean equals(Object other) { + return (other instanceof ReferenceMarkNode) + && super.equals((MarkNode) other); + } +} + +class ReferenceMarkStartNode extends ReferenceMarkNode +{ + ReferenceMarkStartNode dup() + { return new ReferenceMarkStartNode(getName()); } + ReferenceMarkStartNode(String name) { + super(name); m_isPoint = false; m_isStart = true; + } +} + +class ReferenceMarkEndNode extends ReferenceMarkNode +{ + ReferenceMarkEndNode dup() + { return new ReferenceMarkEndNode(getName()); } + ReferenceMarkEndNode(String name) { + super(name); m_isPoint = false; m_isStart = false; + } +} + +class DocumentIndexMarkNode extends MarkNode +{ + DocumentIndexMarkNode dup() + { return new DocumentIndexMarkNode(getName()); } + DocumentIndexMarkNode(String name) { super(name); } + String getType() { return "DocumentIndexMark"; } + public boolean equals(Object other) { + return (other instanceof DocumentIndexMarkNode) + && super.equals((MarkNode) other); + } +} + +class DocumentIndexMarkStartNode extends DocumentIndexMarkNode +{ + DocumentIndexMarkStartNode dup() + { return new DocumentIndexMarkStartNode(getName()); } + DocumentIndexMarkStartNode(String name) { + super(name); m_isPoint = false; m_isStart = true; + } +} + +class DocumentIndexMarkEndNode extends DocumentIndexMarkNode +{ + DocumentIndexMarkEndNode dup() + { return new DocumentIndexMarkEndNode(getName()); } + DocumentIndexMarkEndNode(String name) { + super(name); m_isPoint = false; m_isStart = false; + } +} + +abstract class ContentNode extends TreeNode +{ + private String m_Content; + String getContent() { return m_Content; } + boolean hasContent() { return true; } + ContentNode(String content) { + m_Content = content; + } + TreeNode appendChild(TreeNode t) { + throw new RuntimeException("ContentNode.appendChild"); + } + public String toString() { + return super.toString() + "\tcontent: " + m_Content; + } + boolean equals(ContentNode other) { + return (other.m_Content.equals(m_Content)); + } +} + +class TextNode extends ContentNode +{ + TextNode dup() { return new TextNode(getContent()); } + TextNode(String content) { super(content); } + String getType() { return "Text"; } + public boolean equals(Object other) { + return (other instanceof TextNode) && super.equals((ContentNode) other); + } +} + +class TextFieldNode extends ContentNode +{ + TextFieldNode dup() { return new TextFieldNode(getContent()); } + TextFieldNode(String content) { super(content); } + String getType() { return "TextField"; } + public boolean equals(Object other) { + return (other instanceof TextFieldNode) + && super.equals((ContentNode) other); + } +} + +class FrameNode extends TreeNode +{ + private String m_Name; + private TextContentAnchorType m_Anchor; + String getName() { return m_Name; } + TextContentAnchorType getAnchor() { return m_Anchor; } + FrameNode dup() { return new FrameNode(getName(), getAnchor()); } + FrameNode(String name, TextContentAnchorType anchor) { + m_Name = name; m_Anchor = anchor; + } + String getType() { return "Frame"; } + public boolean equals(Object other) { + return (other instanceof FrameNode) + && (((FrameNode) other).m_Name.equals(m_Name)) + && (((FrameNode) other).m_Anchor == m_Anchor); + } + public String toString() { + return super.toString() + + "\tname: " + m_Name + "\tanchor: " + toString(m_Anchor); + } + static String toString(TextContentAnchorType anchor) { + switch (anchor.getValue()) { + case AS_CHARACTER_value: return "AS_CHARACTER"; + case AT_CHARACTER_value: return "AT_CHARACTER"; + case AT_PARAGRAPH_value: return "AT_PARAGRAPH"; + case AT_PAGE_value: return "AT_PAGE"; + case AT_FRAME_value: return "AT_FRAME"; + default: throw new RuntimeException("unknown anchor"); + } + } +} + +class FootnoteNode extends TreeNode +{ + private String m_Label; + String getLabel() { return m_Label; } + FootnoteNode dup() { return new FootnoteNode(getLabel()); } + FootnoteNode(String label) { m_Label = label; } + String getType() { return "Footnote"; } + public boolean equals(Object other) { + return (other instanceof FootnoteNode) + && (((FootnoteNode) other).m_Label.equals(m_Label)); + } + public String toString() { + return super.toString() + "\tlabel: " + m_Label; + } +} + +class ControlCharacterNode extends TreeNode +{ + private short m_Char; + short getChar() { return m_Char; } + ControlCharacterNode dup() { return new ControlCharacterNode(getChar()); } + ControlCharacterNode(short c) { m_Char = c; } + String getType() { return "ControlCharacter"; } + public boolean equals(Object other) { + return (other instanceof ControlCharacterNode) + && (((ControlCharacterNode) other).m_Char == m_Char); + } + public String toString() { + return super.toString() + "\tchar: " + m_Char; + } +} + +class SoftPageBreakNode extends TreeNode +{ + String getType() { return "SoftPageBreak"; } + public boolean equals(Object other) { + return (other instanceof SoftPageBreakNode); + } +} + +class HyperlinkNode extends TreeNode +{ + private String m_URL; + String getURL() { return m_URL; } + HyperlinkNode dup() { return new HyperlinkNode(getURL()); } + HyperlinkNode(String url) { + if (url.length() == 0) throw new RuntimeException("HyperlinkNode"); + m_URL = url; + } + String getType() { return "Hyperlink"; } + boolean isNesting() { return true; } + public boolean equals(Object other) { + return (other instanceof HyperlinkNode) + && (((HyperlinkNode) other).m_URL.equals(m_URL)); + } + public String toString() { + return super.toString() + "\turl: " + m_URL; + } +} + +class RubyNode extends TreeNode +{ + private String m_Ruby; + String getRubyText() { return m_Ruby; } + RubyNode dup() { return new RubyNode(getRubyText()); } + RubyNode(String ruby) { + if (ruby.length() == 0) throw new RuntimeException("RubyNode"); + m_Ruby = ruby; + } + String getType() { return "Ruby"; } + boolean isNesting() { return true; } + public boolean equals(Object other) { + return (other instanceof RubyNode) + && (((RubyNode) other).m_Ruby.equals(m_Ruby)); + } + public String toString() { + return super.toString() + "\trubytext: " + m_Ruby; + } +} + +class MetaNode extends TreeNode +{ + private StringPair m_XmlId; + StringPair getXmlId() { return m_XmlId; } + MetaNode dup() { return new MetaNode(getXmlId()); } + MetaNode (StringPair xmlid) { m_XmlId = xmlid; } + String getType() { return "InContentMetadata"; } + boolean isNesting() { return true; } + public boolean equals(Object other) { + return (other instanceof MetaNode) + && eq(((MetaNode) other).m_XmlId, m_XmlId); + } + static boolean eq(StringPair left, StringPair right) + { + return left.First.equals(right.First) + && left.Second.equals(right.Second); + } + public String toString() { + return super.toString() + + "\txmlid: " + m_XmlId.First + "#" + m_XmlId.Second; + } +} + +class MetaFieldNode extends MetaNode +{ + MetaFieldNode dup() { return new MetaFieldNode(getXmlId()); } + MetaFieldNode (StringPair xmlid) { super(xmlid); } + String getType() { return "MetadataField"; } +} + +class Range +{ + private short m_Start; + private short m_End; + private TreeNode m_Node; + short getStart() { return m_Start; } + short getEnd() { return m_End ; } + short getExtent() { return (short) (m_End - m_Start); } + TreeNode getNode() { return m_Node; } + Range(int start, int end, TreeNode node) + { m_Start = (short) start; m_End = (short) end; m_Node = node; } +} + +//---------------------------------------------------------------------- + +/* this is where we nail the pudding to the wall */ +class FuzzyTester +{ + private long m_DiffContent = 0; + private long m_DiffMissing = 0; + private long m_DiffNesting = 0; + private long m_DiffSpuriousEmptyText = 0; + private long m_DiffSequence = 0; // ignored? + private Stack<Pair<TreeNode, TreeNodeEnum>> m_StackExpected; + private Stack<Pair<TreeNode, TreeNodeEnum>> m_StackActual; + private List<TreeNode> m_BufferExpected; + private List<TreeNode> m_BufferActual; + private share.LogWriter m_Log; + + FuzzyTester(share.LogWriter log) { + m_Log = log; + m_BufferExpected = new ArrayList<TreeNode>(); + m_BufferActual = new ArrayList<TreeNode>(); + m_StackExpected = new Stack<Pair<TreeNode, TreeNodeEnum>>(); + m_StackActual = new Stack<Pair<TreeNode, TreeNodeEnum>>(); + } + + /** idea: traverse both trees, enumerate nodes, stopping at content nodes. + then compare buffers. */ + boolean doTest(TreeNode expected, TreeNode actual) + { + if (!expected.getType().equals("__ROOT__")) + throw new RuntimeException("doTest: expected: root"); + if (!actual.getType().equals("__ROOT__")) + throw new RuntimeException("doTest: actual: root"); + m_StackExpected.push(new Pair(expected, expected.createEnumeration())); + m_StackActual.push(new Pair(actual, actual.createEnumeration())); + do { + traverse(m_StackExpected, m_BufferExpected); + traverse(m_StackActual, m_BufferActual); + //??? root? + testBuffer(); + } while (!m_StackExpected.empty() || !m_StackActual.empty()); + if (m_DiffSequence != 0) { + m_Log.println("warning: " + m_DiffSequence + + " differences in sequence"); + } + if (m_DiffSpuriousEmptyText != 0) { + m_Log.println("warning: " + m_DiffSpuriousEmptyText + + " spurious empty text nodes"); + } + if (m_DiffNesting != 0) { + m_Log.println("WARNING: " + m_DiffNesting + + " differences in nesting"); + } + return (m_DiffContent == 0) && (m_DiffMissing == 0); + } + + private void traverse(Stack<Pair<TreeNode, TreeNodeEnum>> stack, + List<TreeNode> buffer) + { + while (!stack.empty()) { + TreeNodeEnum topEnum = stack.peek().Second; + if (topEnum.hasNext()) { + TreeNode node = topEnum.next(); + buffer.add(node); + TreeNodeEnum nodeEnum = node.createEnumeration(); + if (nodeEnum.hasNext()) { + stack.push(new Pair(node, nodeEnum)); + } + if (node.hasContent()) { + if (!((node instanceof TextNode) // spurious empty text? + && ((TextNode) node).getContent().length() == 0)) { + return; // break here + } + } + } else { + buffer.add(stack.peek().First); + stack.pop(); + } + } + } + + private void testTerminatingNode() + { + int lenExpected = m_BufferExpected.size(); + int lenActual = m_BufferActual.size(); + if (lenExpected == 0 || lenActual == 0) + return; + TreeNode expected = m_BufferExpected.get(lenExpected - 1); + TreeNode actual = m_BufferActual.get(lenActual - 1); + + boolean eRoot = expected.getType().equals("__ROOT__"); + boolean aRoot = actual.getType().equals("__ROOT__"); + if (eRoot || aRoot) { + if (!(eRoot && aRoot)) { + if (aRoot) printMissing(expected); + else printUnexpected(actual); + m_DiffMissing++; + } + return; + } + + testContentNode((ContentNode) expected, (ContentNode) actual); + + m_BufferExpected.set(lenExpected - 1, null); + m_BufferActual.set(lenActual - 1, null); + } + + private void testContentNode(ContentNode expected, ContentNode actual) + { + String contentExpected = expected.getContent(); + String contentActual = actual.getContent(); + if (!expected.equals(actual)) { + printDiff("text content differs", contentExpected, contentActual); + m_DiffContent++; + } + } + + private void testBuffer() + { + int lenExpected = m_BufferExpected.size(); + int lenActual = m_BufferActual.size(); + for (int i = 0; i < lenExpected - 1; i++ ) + { + TreeNode node = m_BufferExpected.get(i); + int j = m_BufferActual.indexOf(node); + if (j >= 0) { + TreeNode other = m_BufferActual.get(j); + if (j != i) + { + //FIXME how bad is this? + printDiff("position differs", + String.valueOf(i), String.valueOf(j)); + // a hacky hack + int min = Math.min(i,j); + int max = Math.max(Math.min(lenActual - 1, i),j); + for (int k = min; k != max; k ++) { + TreeNode tmp = m_BufferActual.get(k); + if (tmp != null && tmp.isNesting()) { + printNesting(node, tmp); + m_DiffNesting++; + } + } + m_DiffSequence++; + } + m_BufferActual.set(j, null); + } else { +//m_Log.println("testBuffer:"); + printMissing(node); + m_DiffMissing++; + } + } + for (int j = 0; j < lenActual - 1; j++) + { + TreeNode node = m_BufferActual.get(j); + if (node != null) + { +//m_Log.println("testBuffer:"); + printUnexpected(node); + if ((node instanceof TextNode) && + ((TextNode) node).getContent().length() == 0) { + m_DiffSpuriousEmptyText++; + } else { + m_DiffMissing++; + } + } + } + testTerminatingNode(); + m_BufferExpected.clear(); + m_BufferActual.clear(); + } + + void printDiff(String prefix, String expected, String actual) + { + m_Log.println(prefix + + ":\texpected: " + expected + "\tactual: " + actual); + } + + void printNesting(TreeNode node, TreeNode nesting) + { + m_Log.println("node: " + node.toString() + + " possibly moved across nesting " + nesting.toString()); + } + + void printMissing(TreeNode node) + { + m_Log.println(" missing node: " + node.toString()); + + } + + void printUnexpected(TreeNode node) + { + m_Log.println("unexpected node: " + node.toString()); + + } +} + + +//---------------------------------------------------------------------- + +class EnumConverter +{ + private Stack<TreeNode> m_Stack; + TextPortionEnumerationTest m_T; + + EnumConverter(TextPortionEnumerationTest err) { + m_Stack = new Stack<TreeNode>(); m_T = err; + } + + TreeNode convert(XEnumeration xEnum) throws Exception + { + TreeNode root = new TreeNode(); + m_Stack.push(root); + TreeNode ret = convertChildren(xEnum); + m_T.assure("EnumConverter.convert: stack", m_Stack.empty()); + return ret; + } + + TreeNode convertChildren(XEnumeration xEnum) throws Exception + { + while (xEnum.hasMoreElements()) { + TreeNode node; + 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"); + if (type.equals("Text")) { + String text = xPortion.getString(); + node = new TextNode(text); + String url = (String) xPropSet.getPropertyValue("HyperLinkURL"); + if (url.length() > 0) { + TreeNode temp = node; + node = new HyperlinkNode(url); + node.appendChild(temp); + } + } else if (type.equals("TextField")) { + Object xField = xPropSet.getPropertyValue("TextField"); + XServiceInfo xService = (XServiceInfo) + UnoRuntime.queryInterface(XServiceInfo.class, xField); + if (xService.supportsService( + "com.sun.star.text.textfield.MetadataField")) + { + XMetadatable xMeta = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xField); + StringPair xmlid = xMeta.getMetadataReference(); + node = new MetaFieldNode(xmlid); + m_Stack.push(node); + XEnumerationAccess xEA = (XEnumerationAccess) + UnoRuntime.queryInterface(XEnumerationAccess.class, + xMeta); + XEnumeration xEnumChildren = xEA.createEnumeration(); + TreeNode node2 = convertChildren(xEnumChildren); + m_T.assure("stack error: meta-field", node == node2); + } else { + XPropertySet xFieldPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xField); + String content = (String) + xFieldPropSet.getPropertyValue("Content"); + boolean isFixed = (Boolean) + xFieldPropSet.getPropertyValue("IsFixed"); + m_T.assure("field not fixed?", isFixed); + node = new TextFieldNode(content); + } + } else if (type.equals("Footnote")) { + Object xNote = xPropSet.getPropertyValue("Footnote"); + XFootnote xFootnote = (XFootnote) + UnoRuntime.queryInterface(XFootnote.class, xNote); + String label = xFootnote.getLabel(); + node = new FootnoteNode(label); + } else if (type.equals("Frame")) { + XContentEnumerationAccess xCEA = (XContentEnumerationAccess) + UnoRuntime.queryInterface(XContentEnumerationAccess.class, + xPortion); + XEnumeration xContentEnum = xCEA.createContentEnumeration(""); + while (xContentEnum.hasMoreElements()) { + Object xFrame = xContentEnum.nextElement(); + XPropertySet xFramePropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xFrame); + TextContentAnchorType anchor = (TextContentAnchorType) + xFramePropSet.getPropertyValue("AnchorType"); + XNamed xNamed = (XNamed) + UnoRuntime.queryInterface(XNamed.class, xFrame); + String name = xNamed.getName(); + node = new FrameNode(name, anchor); + m_Stack.peek().appendChild(node); + } + continue; + } else if (type.equals("ControlCharacter")) { + short c = (Short) + xPropSet.getPropertyValue("ControlCharacter"); + node = new ControlCharacterNode(c); + } else if (type.equals("Bookmark")) { + Object xMark = xPropSet.getPropertyValue("Bookmark"); + XNamed xNamed = (XNamed) + UnoRuntime.queryInterface(XNamed.class, xMark); + String name = xNamed.getName(); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xMark); + StringPair xmlid = xMetadatable.getMetadataReference(); + boolean isCollapsed = (Boolean) + xPropSet.getPropertyValue("IsCollapsed"); + if (isCollapsed) { + node = new BookmarkNode(name, xmlid); + } else { + boolean isStart = (Boolean) + xPropSet.getPropertyValue("IsStart"); + if (isStart) { + node = new BookmarkStartNode(name, xmlid); + } else { + node = new BookmarkEndNode(name, xmlid); + } + } + } else if (type.equals("ReferenceMark")) { + Object xMark = xPropSet.getPropertyValue("ReferenceMark"); + XNamed xNamed = (XNamed) + UnoRuntime.queryInterface(XNamed.class, xMark); + String name = xNamed.getName(); + boolean isCollapsed = (Boolean) + xPropSet.getPropertyValue("IsCollapsed"); + if (isCollapsed) { + node = new ReferenceMarkNode(name); + } else { + boolean isStart = (Boolean) + xPropSet.getPropertyValue("IsStart"); + if (isStart) { + node = new ReferenceMarkStartNode(name); + } else { + node = new ReferenceMarkEndNode(name); + } + } + } else if (type.equals("DocumentIndexMark")) { + Object xMark = xPropSet.getPropertyValue("DocumentIndexMark"); + XPropertySet xMarkSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xMark); + String name = (String) xMarkSet.getPropertyValue("PrimaryKey"); + boolean isCollapsed = (Boolean) + xPropSet.getPropertyValue("IsCollapsed"); + if (isCollapsed) { + node = new DocumentIndexMarkNode(name); + } else { + boolean isStart = (Boolean) + xPropSet.getPropertyValue("IsStart"); + if (isStart) { + node = new DocumentIndexMarkStartNode(name); + } else { + node = new DocumentIndexMarkEndNode(name); + } + } + } else if (type.equals("SoftPageBreak")) { + node = new SoftPageBreakNode(); + } else if (type.equals("Ruby")) { + boolean isStart = (Boolean) + xPropSet.getPropertyValue("IsStart"); + if (isStart) { + // ARRGH!!! stupid api... + // the text is ONLY at the start! + String ruby = (String) + xPropSet.getPropertyValue("RubyText"); + node = new RubyNode(ruby); + m_Stack.push(node); + continue; + } else { + node = m_Stack.pop(); + m_T.assure("stack error: Ruby expected; is: " + + node.toString(), node instanceof RubyNode); +// m_T.assure("stack error: ruby", +// ruby.equals(((RubyNode)node).getRubyText())); + } + } else if (type.equals("InContentMetadata")) { + Object xMeta = xPropSet.getPropertyValue("InContentMetadata"); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xMeta); + StringPair xmlid = xMetadatable.getMetadataReference(); + node = new MetaNode(xmlid); + m_Stack.push(node); + XEnumerationAccess xEA = (XEnumerationAccess) + UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta); + XEnumeration xEnumChildren = xEA.createEnumeration(); + TreeNode node2 = convertChildren(xEnumChildren); + m_T.assure("stack error: meta", node == node2); +// } else if (type.equals("MetadataField")) { +// Object xMeta = xPropSet.getPropertyValue("MetadataField"); + } else { + throw new RuntimeException("unexpected type: " + type); + } + m_Stack.peek().appendChild(node); + } + TreeNode ret = m_Stack.pop(); + return ret; + } +} + + +//---------------------------------------------------------------------- + +abstract class Inserter +{ + private XMultiServiceFactory m_xDocFactory; + XText m_xText; + XParagraphCursor m_xCursor; + + Inserter(XTextDocument xDoc) + { + m_xDocFactory = (XMultiServiceFactory) + UnoRuntime.queryInterface(XMultiServiceFactory.class, xDoc); + m_xText = xDoc.getText(); + XTextCursor xCursor = m_xText.createTextCursor(); + m_xCursor = (XParagraphCursor) + UnoRuntime.queryInterface(XParagraphCursor.class, xCursor); + } + + void initParagraph() throws Exception + { + m_xCursor.gotoStartOfParagraph(false); + m_xText.insertControlCharacter(m_xCursor, PARAGRAPH_BREAK, false); + // we split the first (empty) paragraph, and then insert into the + // second (empty) paragraph; this ensures first is always empty! + } + + void insertControlCharacter(XTextCursor xCursor, short cchar) + throws Exception + { + m_xText.insertControlCharacter(xCursor, cchar, false); + } + + void insertText(XTextCursor xCursor, String text) + { + xCursor.setString(text); + } + + void insertTextField(XTextCursor xCursor, String content) throws Exception + { + XTextContent xContent = makeTextField(content); + xContent.attach(xCursor); + } + + XTextContent makeTextField(String content) + throws Exception + { + Object xField = + m_xDocFactory.createInstance("com.sun.star.text.textfield.Author"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xField); + XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xField); + xPropSet.setPropertyValue("IsFixed", true); + xPropSet.setPropertyValue("FullName", false); + xPropSet.setPropertyValue("Content", content); + return xContent; + } + + void insertFrame(XTextRange xCursor, String name, + TextContentAnchorType anchor) throws Exception + { + XTextContent xContent = makeFrame(name, anchor); + xContent.attach(xCursor); + } + + XTextContent makeFrame(String name, TextContentAnchorType anchor) + throws Exception + { + Object xFrame = + m_xDocFactory.createInstance("com.sun.star.text.TextFrame"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xFrame); + XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xFrame); + xPropSet.setPropertyValue("AnchorType", anchor); + XNamed xNamed = (XNamed) + UnoRuntime.queryInterface(XNamed.class, xContent); + xNamed.setName(name); + return xContent; + } + + void insertFootnote(XTextCursor xCursor, String label) throws Exception + { + XTextContent xContent = makeFootnote(label); + xContent.attach(xCursor); + } + + XTextContent makeFootnote(String label) throws Exception + { + Object xNote = + m_xDocFactory.createInstance("com.sun.star.text.Footnote"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xNote); + XFootnote xFootnote = (XFootnote) + UnoRuntime.queryInterface(XFootnote.class, xNote); + xFootnote.setLabel(label); + return xContent; + } + + void insertBookmark(XTextCursor xCursor, String name, StringPair xmlid) + throws Exception + { + XTextContent xContent = makeBookmark(name); + xContent.attach(xCursor); + if (!xmlid.First.equals("")) + { + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xContent); + xMetadatable.setMetadataReference(xmlid); + } + } + + XTextContent makeBookmark(String name) throws Exception + { + Object xBookmark = + m_xDocFactory.createInstance("com.sun.star.text.Bookmark"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xBookmark); + XNamed xNamed = (XNamed) + UnoRuntime.queryInterface(XNamed.class, xContent); + xNamed.setName(name); + return xContent; + } + + void insertReferenceMark(XTextCursor xCursor, String name) throws Exception + { + XTextContent xContent = makeReferenceMark(name); + xContent.attach(xCursor); + } + + XTextContent makeReferenceMark(String name) throws Exception + { + Object xMark = + m_xDocFactory.createInstance("com.sun.star.text.ReferenceMark"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xMark); + XNamed xNamed = (XNamed) + UnoRuntime.queryInterface(XNamed.class, xContent); + xNamed.setName(name); + return xContent; + } + + void insertDocumentIndexMark(XTextCursor xCursor, String key) + throws Exception + { + XTextContent xContent = makeDocumentIndexMark(key); + xContent.attach(xCursor); + } + + XTextContent makeDocumentIndexMark(String key) throws Exception + { + Object xMark = + m_xDocFactory.createInstance("com.sun.star.text.DocumentIndexMark"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xMark); + XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xMark); + xPropSet.setPropertyValue("PrimaryKey", key); + return xContent; + } + + void insertHyperlink(XTextCursor xCursor, String url) throws Exception + { + XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xCursor); + xPropSet.setPropertyValue("HyperLinkURL", url); + } + + void insertRuby(XTextCursor xCursor, String rubytext) throws Exception + { + XPropertySet xPropSet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xCursor); + xPropSet.setPropertyValue("RubyText", rubytext); + } + + XTextContent insertMeta(XTextCursor xCursor, StringPair xmlid) + throws Exception + { + XTextContent xContent = makeMeta(); + xContent.attach(xCursor); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xContent); + xMetadatable.setMetadataReference(xmlid); + return xContent; + } + + XTextContent makeMeta() throws Exception + { + Object xMeta = m_xDocFactory.createInstance( + "com.sun.star.text.InContentMetadata"); + XTextContent xContent = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, xMeta); + return xContent; + } + + XTextField insertMetaField(XTextCursor xCursor, StringPair xmlid) + throws Exception + { + XTextField xContent = makeMetaField(); + xContent.attach(xCursor); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xContent); + xMetadatable.setMetadataReference(xmlid); + return xContent; + } + + XTextField makeMetaField() throws Exception + { + Object xMeta = m_xDocFactory.createInstance( + "com.sun.star.text.textfield.MetadataField"); + XTextField xContent = (XTextField) + UnoRuntime.queryInterface(XTextField.class, xMeta); + return xContent; + } + +} + +class TreeInserter extends Inserter +{ + private Map<String, XTextRange> m_BookmarkStarts; + private Map<String, XTextRange> m_ReferenceMarkStarts; + private Map<String, XTextRange> m_DocumentIndexMarkStarts; + private List<Pair<XTextRange, FrameNode>> m_FrameHints; + + TreeInserter(XTextDocument xDoc) + { + super(xDoc); + m_BookmarkStarts = new HashMap<String, XTextRange>(); + m_ReferenceMarkStarts = new HashMap<String, XTextRange>(); + m_DocumentIndexMarkStarts = new HashMap<String, XTextRange>(); + m_FrameHints = new ArrayList<Pair<XTextRange, FrameNode>>(); + } + + void insertTree(TreeNode tree) throws Exception + { + if (!tree.getType().equals("__ROOT__")) + throw new RuntimeException("insertTree: test error: no root"); + initParagraph(); + insertChildren(tree.createEnumeration()); + for (int i = 0; i < m_FrameHints.size(); ++i) { + Pair<XTextRange, FrameNode> p = m_FrameHints.get(i); + insertFrame(p.First, p.Second.getName(), p.Second.getAnchor()); + } + } + + void insertChildren(TreeNodeEnum children) throws Exception + { + while (children.hasNext()) { + m_xCursor.gotoEndOfParagraph(false); + TreeNode node = children.next(); + String type = node.getType(); + if (type.equals("Bookmark")) { + BookmarkNode bkmk = (BookmarkNode) node; + String name = bkmk.getName(); + StringPair id = bkmk.getXmlId(); + if (bkmk.isPoint()) { + insertBookmark(m_xCursor, name, id); + } else if (bkmk.isStart()) { + m_BookmarkStarts.put(name, m_xCursor.getStart()); + } else { + XTextRange xRange = m_BookmarkStarts.get(name); + XParagraphCursor xCursor = mkCursor(xRange); + insertBookmark(xCursor, name, id); + } + } else if (type.equals("ReferenceMark")) { + ReferenceMarkNode mark = (ReferenceMarkNode) node; + String name = mark.getName(); + if (mark.isPoint()) { + insertReferenceMark(m_xCursor, name); + } else if (mark.isStart()) { + m_ReferenceMarkStarts.put(name, m_xCursor.getStart()); + } else { + XTextRange xRange = m_ReferenceMarkStarts.get(name); + XParagraphCursor xCursor = mkCursor(xRange); + insertReferenceMark(xCursor, name); + } + } else if (type.equals("DocumentIndexMark")) { + DocumentIndexMarkNode mark = (DocumentIndexMarkNode) node; + String name = mark.getName(); + if (mark.isPoint()) { + insertDocumentIndexMark(m_xCursor, name); + } else if (mark.isStart()) { + m_DocumentIndexMarkStarts.put(name, m_xCursor.getStart()); + } else { + XTextRange xRange = m_DocumentIndexMarkStarts.get(name); + XParagraphCursor xCursor = mkCursor(xRange); + insertDocumentIndexMark(xCursor, name); + } + } else if (type.equals("Hyperlink")) { + HyperlinkNode href = (HyperlinkNode) node; + XTextRange xRange = m_xCursor.getStart(); + insertChildren(href.createEnumeration()); + XParagraphCursor xCursor = mkCursor(xRange); + insertHyperlink(xCursor, href.getURL()); + } else if (type.equals("Ruby")) { + RubyNode ruby = (RubyNode) node; + XTextRange xRange = m_xCursor.getStart(); + insertChildren(ruby.createEnumeration()); + XParagraphCursor xCursor = mkCursor(xRange); + insertRuby(xCursor, ruby.getRubyText()); + } else if (type.equals("InContentMetadata")) { + MetaNode meta = (MetaNode) node; + XTextRange xRange = m_xCursor.getStart(); + insertChildren(meta.createEnumeration()); + XParagraphCursor xCursor = mkCursor(xRange); + insertMeta(xCursor, meta.getXmlId()); + } else if (type.equals("MetadataField")) { + MetaFieldNode meta = (MetaFieldNode) node; + XTextRange xRange = m_xCursor.getStart(); + insertChildren(meta.createEnumeration()); + XParagraphCursor xCursor = mkCursor(xRange); + insertMetaField(xCursor, meta.getXmlId()); + } else if (type.equals("Text")) { + TextNode text = (TextNode) node; + insertText(m_xCursor, text.getContent()); + } else if (type.equals("TextField")) { + TextFieldNode field = (TextFieldNode) node; + insertTextField(m_xCursor, field.getContent()); + } else if (type.equals("Footnote")) { + FootnoteNode note = (FootnoteNode) node; + insertFootnote(m_xCursor, note.getLabel()); + } else if (type.equals("Frame")) { + FrameNode frame = (FrameNode) node; + if (frame.getAnchor() == AT_CHARACTER) { + m_FrameHints.add( new Pair(m_xCursor.getStart(), frame) ); + } else { + insertFrame(m_xCursor, frame.getName(), frame.getAnchor()); + } + } else if (type.equals("ControlCharacter")) { + ControlCharacterNode cchar = (ControlCharacterNode) node; + insertControlCharacter(m_xCursor, cchar.getChar()); + } else if (type.equals("SoftPageBreak")) { + SoftPageBreakNode spbk = (SoftPageBreakNode) node; + throw new RuntimeException("sorry, cannot test SoftPageBreak"); + } else { + throw new RuntimeException("unexpected type: " + type); + } + } + } + + XParagraphCursor mkCursor(XTextRange xRange) + { + XTextCursor xCursor = m_xText.createTextCursorByRange(xRange); + XParagraphCursor xParaCursor = (XParagraphCursor) + UnoRuntime.queryInterface(XParagraphCursor.class, xCursor); + xParaCursor.gotoEndOfParagraph(true); + return xParaCursor; + } +} + + +// FIXME: this does not account for inserted dummy characters! +class RangeInserter extends Inserter +{ + RangeInserter(XTextDocument xDoc) throws Exception + { super(xDoc); initParagraph(); } + + /* + void insertText(int pos, String text) + { + m_xCursor.gotoStartOfParagraph(false); + m_xCursor.goRight((short) pos, false); + insertText(m_xCursor, text); + } + */ + + XTextContent insertRange(Range range) throws Exception + { + m_xCursor.gotoStartOfParagraph(false); + m_xCursor.goRight(range.getStart(), false); + m_xCursor.goRight(range.getExtent(), true); + return insertNode(m_xCursor, range.getNode()); + } + + XTextContent insertNode(XParagraphCursor xCursor, TreeNode node) + throws Exception + { + String type = node.getType(); + if (type.equals("Bookmark")) { + BookmarkNode bkmk = (BookmarkNode) node; + if (bkmk.isPoint()) throw new RuntimeException("range only"); + insertBookmark(xCursor, bkmk.getName(), bkmk.getXmlId()); + } else if (type.equals("ReferenceMark")) { + ReferenceMarkNode mark = (ReferenceMarkNode) node; + if (mark.isPoint()) throw new RuntimeException("range only"); + insertReferenceMark(xCursor, mark.getName()); + } else if (type.equals("DocumentIndexMark")) { + DocumentIndexMarkNode mark = (DocumentIndexMarkNode) node; + if (mark.isPoint()) throw new RuntimeException("range only"); + insertDocumentIndexMark(xCursor, mark.getName()); + } else if (type.equals("Hyperlink")) { + HyperlinkNode href = (HyperlinkNode) node; + insertHyperlink(xCursor, href.getURL()); + } else if (type.equals("Ruby")) { + RubyNode ruby = (RubyNode) node; + insertRuby(xCursor, ruby.getRubyText()); + } else if (type.equals("InContentMetadata")) { + MetaNode meta = (MetaNode) node; + return insertMeta(xCursor, meta.getXmlId()); + } else if (type.equals("MetadataField")) { + MetaFieldNode meta = (MetaFieldNode) node; + return insertMetaField(xCursor, meta.getXmlId()); + } else if (type.equals("Text")) { + TextNode text = (TextNode) node; + insertText(xCursor, text.getContent()); + } else if (type.equals("TextField")) { + TextFieldNode field = (TextFieldNode) node; + insertTextField(m_xCursor, field.getContent()); + } else if (type.equals("Footnote")) { + FootnoteNode note = (FootnoteNode) node; + insertFootnote(m_xCursor, note.getLabel()); + } else if (type.equals("Frame")) { + FrameNode frame = (FrameNode) node; + insertFrame(xCursor, frame.getName(), frame.getAnchor()); + } else if (type.equals("ControlCharacter")) { + ControlCharacterNode cchar = (ControlCharacterNode) node; + insertControlCharacter(m_xCursor, cchar.getChar()); + } else if (type.equals("SoftPageBreak")) { + throw new RuntimeException("sorry, cannot test SoftPageBreak"); + } else { + throw new RuntimeException("unexpected type: " + type); + } + return null; + } +} + + +//---------------------------------------------------------------------- + +public class TextPortionEnumerationTest extends ComplexTestCase +{ + private XMultiServiceFactory m_xMSF = null; + private XComponentContext m_xContext = null; + private XTextDocument m_xDoc = null; + private String m_TmpDir = null; + + private int m_Count = 1; + +// public String[] getTestMethodNames() { return new String[] { "testLoadStore" }; } + public String[] getTestMethodNames() { + return new String[] { + "testText", + "testTextField", +// "testControlChar", +// "testSoftPageBreak", + "testFootnote", + "testFrameAs", + "testFrameAt", + "testBookmarkPoint", + "testBookmark", + "testBookmarkPointXmlId", + "testBookmarkXmlId", + "testRefmarkPoint", + "testRefmark", + "testToxmarkPoint", + "testToxmark", + "testHyperlink", + "testHyperlinkEmpty", + "testRuby", + "testRubyEmpty", + "testMeta", + "testMetaEmpty", + "testMetaField", + "testMetaFieldEmpty", + "testBookmark1", + "testBookmark2", + "testRefMark2", + "testRefMark3", + "testToxMark2", + "testToxMark3", + "testMarks1", + "testMarks2", + "testMarks3", + "testFrameMark1", + "testFrameMark2", + "testFrameMark3", + "testFrameMark4", + "testFrames1", + "testFrames2", + "testFrames3", + "testFrames4", + "testFrames5", + "testRubyHyperlink1", + "testRubyHyperlink2", + "testEnd1", + "testEnd2", + "testEnd3", + "testEnd4", + "testEnd5", + "testEmpty1", + "testEmpty2", + "testEmpty3", + "test1", + "testRange1", + "testRangeHyperlinkHyperlink", + "testRangeHyperlinkRuby", + "testRangeRubyHyperlink", + "testRangeRubyRuby", + "testRangeHyperlinkMeta", + "testRangeRubyMeta", + "testRangeMetaHyperlink", + "testRangeMetaRuby", + "testRangeMetaMeta", + "testRange2", + "testRange3", + "testRange4", + "testRange5", + "testRange6", + "testRange7", + "testMetaXChild", + "testMetaXText", + "testMetaXTextCursor", + "testMetaXTextAttachToxMark", + "testMetaXTextAttachRefMark", + "testMetaXTextAttachTextField", + "testMetaXTextAttachFootnote", + "testMetaXTextAttachMeta", + "testMetaFieldXTextField", + "testMetaFieldXPropertySet", + "testLoadStore", + "testLoadStoreXmlid", + }; + } + + public void before() throws Exception + { + m_xMSF = (XMultiServiceFactory) param.getMSF(); + XPropertySet xPropertySet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, m_xMSF); + Object defaultCtx = xPropertySet.getPropertyValue("DefaultContext"); + m_xContext = (XComponentContext) + UnoRuntime.queryInterface(XComponentContext.class, defaultCtx); + assure("could not get component context.", m_xContext != null); + m_xDoc = util.WriterTools.createTextDoc(m_xMSF); + m_TmpDir = util.utils.getOfficeTemp/*Dir*/(m_xMSF); + log.println("tempdir: " + m_TmpDir); + } + + public void after() + { + if (m_xDoc != null) { + util.DesktopTools.closeDoc(m_xDoc); + m_xDoc = null; + } + } + + public void testText() throws Exception + { + TreeNode root = new TreeNode(); + TreeNode text = new TextNode("abc"); + root.appendChild(text); + doTest(root); + } + + public void testTextField() throws Exception + { + String name = mkName("ruby"); + TreeNode root = new TreeNode(); + TreeNode txtf = new TextFieldNode("abc"); + root.appendChild(txtf); + doTest(root); + } + + public void testControlChar() throws Exception + { +//FIXME this is converted to a text portion: ControlCharacter is obsolete + TreeNode root = new TreeNode(); + TreeNode cchr = new ControlCharacterNode(HARD_HYPHEN); + root.appendChild(cchr); + doTest(root); + } + + public void testSoftPageBreak() throws Exception + { +//FIXME: insert a soft page break: not done + TreeNode root = new TreeNode(); + TreeNode spbk = new SoftPageBreakNode(); + TreeNode text = new TextNode("abc"); + root.appendChild(spbk); + root.appendChild(text); + doTest(root); + } + + public void testFootnote() throws Exception + { + String name = mkName("ftn"); + TreeNode root = new TreeNode(); + TreeNode ftnd = new FootnoteNode(name); + root.appendChild(ftnd); + doTest(root); + } + + public void testFrameAs() throws Exception + { + String name = mkName("frame"); + TreeNode root = new TreeNode(); + TreeNode fram = new FrameNode(name, AS_CHARACTER); + root.appendChild(fram); + doTest(root); + } + + public void testFrameAt() throws Exception + { + String name = mkName("frame"); + TreeNode root = new TreeNode(); +// TreeNode text = new TextNode(""); // necessary? + TreeNode fram = new FrameNode(name, AT_CHARACTER); +// root.appendChild(text); + root.appendChild(fram); + doTest(root); + } + + public void testBookmarkPoint() throws Exception + { + String name = mkName("mark"); + TreeNode root = new TreeNode(); + TreeNode bkmk = new BookmarkNode(name); + TreeNode text = new TextNode("abc"); + root.appendChild(bkmk); + root.appendChild(text); + doTest(root); + } + + public void testBookmark() throws Exception + { + String name = mkName("mark"); + TreeNode root = new TreeNode(); + TreeNode bkm1 = new BookmarkStartNode(name); + TreeNode text = new TextNode("abc"); + TreeNode bkm2 = new BookmarkEndNode(name); + root.appendChild(bkm1); + root.appendChild(text); + root.appendChild(bkm2); + doTest(root); + } + + public void testBookmarkPointXmlId() throws Exception + { + String name = mkName("mark"); + StringPair id = mkId("id"); + TreeNode root = new TreeNode(); + TreeNode bkmk = new BookmarkNode(name, id); + TreeNode text = new TextNode("abc"); + root.appendChild(bkmk); + root.appendChild(text); + doTest(root); + } + + public void testBookmarkXmlId() throws Exception + { + String name = mkName("mark"); + StringPair id = mkId("id"); + TreeNode root = new TreeNode(); + TreeNode bkm1 = new BookmarkStartNode(name, id); + TreeNode text = new TextNode("abc"); + TreeNode bkm2 = new BookmarkEndNode(name, id); + root.appendChild(bkm1); + root.appendChild(text); + root.appendChild(bkm2); + doTest(root); + } + + public void testRefmarkPoint() throws Exception + { + String name = mkName("refmark"); + TreeNode root = new TreeNode(); + TreeNode rfmk = new ReferenceMarkNode(name); + TreeNode text = new TextNode("abc"); + root.appendChild(rfmk); + root.appendChild(text); + doTest(root); + } + + public void testRefmark() throws Exception + { + String name = mkName("refmark"); + TreeNode root = new TreeNode(); + TreeNode rfm1 = new ReferenceMarkStartNode(name); + TreeNode text = new TextNode("abc"); + TreeNode rfm2 = new ReferenceMarkEndNode(name); + root.appendChild(rfm1); + root.appendChild(text); + root.appendChild(rfm2); + doTest(root); + } + + public void testToxmarkPoint() throws Exception + { + String name = mkName("toxmark"); + TreeNode root = new TreeNode(); + TreeNode txmk = new DocumentIndexMarkNode(name); + TreeNode text = new TextNode("abc"); + root.appendChild(txmk); + root.appendChild(text); + doTest(root); + } + + public void testToxmark() throws Exception + { + String name = mkName("toxmark"); + TreeNode root = new TreeNode(); + TreeNode txm1 = new DocumentIndexMarkStartNode(name); + TreeNode text = new TextNode("abc"); + TreeNode txm2 = new DocumentIndexMarkEndNode(name); + root.appendChild(txm1); + root.appendChild(text); + root.appendChild(txm2); + doTest(root); + } + + public void testHyperlink() throws Exception + { + String name = mkName("url"); + TreeNode root = new TreeNode(); + TreeNode href = new HyperlinkNode(name); + TreeNode text = new TextNode("abc"); + href.appendChild(text); + root.appendChild(href); + doTest(root); + } + + public void testHyperlinkEmpty() throws Exception + { + String name = mkName("url"); + TreeNode root = new TreeNode(); + TreeNode href = new HyperlinkNode(name); + TreeNode text = new TextNode(""); + href.appendChild(text); + root.appendChild(href); + doTest(root); + } + + public void testRuby() throws Exception + { + String name = mkName("ruby"); + TreeNode root = new TreeNode(); + TreeNode ruby = new RubyNode(name); + TreeNode text = new TextNode("abc"); + ruby.appendChild(text); + root.appendChild(ruby); + doTest(root); + } + + public void testRubyEmpty() throws Exception + { + // BUG: #i91534# + String name = mkName("ruby"); + TreeNode root = new TreeNode(); + TreeNode ruby = new RubyNode(name); + root.appendChild(ruby); + doTest(root); + } + + public void testMeta() throws Exception + { + StringPair id = new StringPair("content.xml", mkName("id")); + TreeNode root = new TreeNode(); + TreeNode meta = new MetaNode(id); + TreeNode text = new TextNode("abc"); + root.appendChild(new TextNode("123")); + meta.appendChild(text); + root.appendChild(meta); + doTest(root); + } + + public void testMetaEmpty() throws Exception + { + StringPair id = new StringPair("content.xml", mkName("id")); + TreeNode root = new TreeNode(); + TreeNode meta = new MetaNode(id); +// TreeNode text = new TextNode(""); +// meta.appendChild(text); + root.appendChild(meta); + doTest(root); + } + + public void testMetaField() throws Exception + { + StringPair id = new StringPair("content.xml", mkName("id")); + TreeNode root = new TreeNode(); + TreeNode meta = new MetaFieldNode(id); + TreeNode text = new TextNode("abc"); + root.appendChild(new TextNode("123")); + meta.appendChild(text); + root.appendChild(meta); + doTest(root); + } + + public void testMetaFieldEmpty() throws Exception + { + StringPair id = new StringPair("content.xml", mkName("id")); + TreeNode root = new TreeNode(); + TreeNode meta = new MetaFieldNode(id); +// TreeNode text = new TextNode(""); +// meta.appendChild(text); + root.appendChild(meta); + doTest(root); + } + + public void testBookmark1() throws Exception + { + String name1 = mkName("mark"); + String name2 = mkName("mark"); + String name3 = mkName("mark"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkStartNode(name1) ); + root.appendChild( new BookmarkNode(name2) ); + root.appendChild( new BookmarkStartNode(name3) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkEndNode(name1) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new BookmarkEndNode(name3) ); + doTest(root); + } + + public void testBookmark2() throws Exception + { + String name1 = mkName("mark"); + String name2 = mkName("mark"); + String name3 = mkName("mark"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkStartNode(name1) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkNode(name2) ); + root.appendChild( new BookmarkStartNode(name3) ); + root.appendChild( new BookmarkEndNode(name1) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new BookmarkEndNode(name3) ); + doTest(root); + } + + public void testRefMark2() throws Exception + { + String name1 = mkName("refmark"); + TreeNode root = new TreeNode(); + root.appendChild( new ReferenceMarkStartNode(name1) ); + root.appendChild( new TextNode("abc") ); + // BUG: #i102541# (this is actually not unoportenum's fault) + root.appendChild( new ReferenceMarkEndNode(name1) ); + root.appendChild( new TextNode("de") ); + doTest(root); + } + + public void testRefMark3() throws Exception + { + // BUG: #i107672# (non-deterministic; depends on pointer ordering) + String name1 = mkName("refmark"); + String name2 = mkName("refmark"); + String name3 = mkName("refmark"); + String name4 = mkName("refmark"); + String name5 = mkName("refmark"); + String name6 = mkName("refmark"); + String name7 = mkName("refmark"); + TreeNode root = new TreeNode(); + root.appendChild( new ReferenceMarkStartNode(name1) ); + root.appendChild( new ReferenceMarkStartNode(name2) ); + root.appendChild( new ReferenceMarkStartNode(name3) ); + root.appendChild( new ReferenceMarkStartNode(name4) ); + root.appendChild( new ReferenceMarkStartNode(name5) ); + root.appendChild( new ReferenceMarkStartNode(name6) ); + root.appendChild( new ReferenceMarkStartNode(name7) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new ReferenceMarkEndNode(name7) ); + root.appendChild( new ReferenceMarkEndNode(name6) ); + root.appendChild( new ReferenceMarkEndNode(name5) ); + root.appendChild( new ReferenceMarkEndNode(name4) ); + root.appendChild( new ReferenceMarkEndNode(name3) ); + root.appendChild( new ReferenceMarkEndNode(name2) ); + root.appendChild( new ReferenceMarkEndNode(name1) ); + root.appendChild( new TextNode("de") ); + doTest(root); + } + + public void testToxMark2() throws Exception + { + String name1 = mkName("toxmark"); + TreeNode root = new TreeNode(); + root.appendChild( new DocumentIndexMarkStartNode(name1) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new DocumentIndexMarkEndNode(name1) ); + root.appendChild( new TextNode("de") ); + doTest(root); + } + + public void testToxMark3() throws Exception + { + // BUG: #i107672# (non-deterministic; depends on pointer ordering) + String name1 = mkName("toxmark"); + String name2 = mkName("toxmark"); + String name3 = mkName("toxmark"); + String name4 = mkName("toxmark"); + String name5 = mkName("toxmark"); + String name6 = mkName("toxmark"); + String name7 = mkName("toxmark"); + TreeNode root = new TreeNode(); + root.appendChild( new DocumentIndexMarkStartNode(name1) ); + root.appendChild( new DocumentIndexMarkStartNode(name2) ); + root.appendChild( new DocumentIndexMarkStartNode(name3) ); + root.appendChild( new DocumentIndexMarkStartNode(name4) ); + root.appendChild( new DocumentIndexMarkStartNode(name5) ); + root.appendChild( new DocumentIndexMarkStartNode(name6) ); + root.appendChild( new DocumentIndexMarkStartNode(name7) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new DocumentIndexMarkEndNode(name7) ); + root.appendChild( new DocumentIndexMarkEndNode(name6) ); + root.appendChild( new DocumentIndexMarkEndNode(name5) ); + root.appendChild( new DocumentIndexMarkEndNode(name4) ); + root.appendChild( new DocumentIndexMarkEndNode(name3) ); + root.appendChild( new DocumentIndexMarkEndNode(name2) ); + root.appendChild( new DocumentIndexMarkEndNode(name1) ); + root.appendChild( new TextNode("de") ); + doTest(root); + } + + public void testMarks1() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("toxmark"); + String name3 = mkName("refmark"); + String name4 = mkName("toxmark"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkStartNode(name1) ); + root.appendChild( new DocumentIndexMarkNode(name2) ); + root.appendChild( new ReferenceMarkStartNode(name3) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkEndNode(name1) ); + root.appendChild( new DocumentIndexMarkStartNode(name4) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new DocumentIndexMarkEndNode(name4) ); + root.appendChild( new ReferenceMarkEndNode(name3) ); + doTest(root); + } + + public void testMarks2() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("refmark"); + String name3 = mkName("refmark"); + String name4 = mkName("toxmark"); + String name5 = mkName("refmark"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkStartNode(name1) ); + root.appendChild( new ReferenceMarkNode(name2) ); + root.appendChild( new ReferenceMarkStartNode(name3) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new DocumentIndexMarkStartNode(name4) ); + root.appendChild( new ReferenceMarkStartNode(name5) ); + // BUG: #i102541# (this is actually not unoportenum's fault) + root.appendChild( new ReferenceMarkEndNode(name3) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new DocumentIndexMarkEndNode(name4) ); + root.appendChild( new BookmarkEndNode(name1) ); + root.appendChild( new ReferenceMarkEndNode(name5) ); + doTest(root); + } + + public void testMarks3() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("refmark"); + String name3 = mkName("refmark"); + String name4 = mkName("toxmark"); + String name5 = mkName("refmark"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkStartNode(name1) ); + root.appendChild( new DocumentIndexMarkNode(name2) ); + root.appendChild( new DocumentIndexMarkStartNode(name3) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new ReferenceMarkStartNode(name4) ); + root.appendChild( new DocumentIndexMarkStartNode(name5) ); + root.appendChild( new DocumentIndexMarkEndNode(name3) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new ReferenceMarkEndNode(name4) ); + root.appendChild( new BookmarkEndNode(name1) ); + root.appendChild( new DocumentIndexMarkEndNode(name5) ); + doTest(root); + } + + public void testFrameMark1() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkNode(name1) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new FrameNode(name2, AS_CHARACTER) ); + doTest(root); + } + + public void testFrameMark2() throws Exception + { + // BUG: #i98530# + String name1 = mkName("bookmark"); + String name2 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkNode(name1) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new FrameNode(name2, AT_CHARACTER) ); + doTest(root); + } + + public void testFrameMark3() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("bookmark"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new FrameNode(name1, AS_CHARACTER) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new BookmarkNode(name2) ); + doTest(root); + } + + public void testFrameMark4() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("bookmark"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new FrameNode(name1, AT_CHARACTER) ); + root.appendChild( new TextNode("de") ); + root.appendChild( new BookmarkNode(name2) ); + doTest(root); + } + + public void testFrames1() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("frame"); + String name3 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new FrameNode(name1, AT_CHARACTER) ); + root.appendChild( new FrameNode(name2, AT_CHARACTER) ); + root.appendChild( new FrameNode(name3, AT_CHARACTER) ); + doTest(root); + } + + public void testFrames2() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("frame"); + String name3 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new FrameNode(name1, AS_CHARACTER) ); + root.appendChild( new FrameNode(name2, AS_CHARACTER) ); + root.appendChild( new FrameNode(name3, AS_CHARACTER) ); + doTest(root); + } + + public void testFrames3() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("frame"); + String name3 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new FrameNode(name1, AT_CHARACTER) ); + root.appendChild( new FrameNode(name2, AS_CHARACTER) ); + root.appendChild( new FrameNode(name3, AT_CHARACTER) ); + doTest(root); + } + + public void testFrames4() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("frame"); + String name3 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new FrameNode(name1, AT_CHARACTER) ); + root.appendChild( new FrameNode(name2, AT_CHARACTER) ); + root.appendChild( new FrameNode(name3, AS_CHARACTER) ); + doTest(root); + } + + public void testFrames5() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("frame"); + String name3 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new FrameNode(name1, AS_CHARACTER) ); + root.appendChild( new FrameNode(name2, AT_CHARACTER) ); + root.appendChild( new FrameNode(name3, AT_CHARACTER) ); + doTest(root); + } + + public void testRubyHyperlink1() throws Exception + { + String name1 = mkName("ruby"); + String name2 = mkName("url"); + TreeNode root = new TreeNode(); + TreeNode ruby = new RubyNode(name1); + TreeNode href = new HyperlinkNode(name2); + href.appendChild( new TextNode("abc") ); + ruby.appendChild(href); + root.appendChild(ruby); + doTest(root); + } + + public void testRubyHyperlink2() throws Exception + { + String name1 = mkName("url"); + String name2 = mkName("ruby"); + TreeNode root = new TreeNode(); + TreeNode href = new HyperlinkNode(name1); + TreeNode ruby = new RubyNode(name2); + ruby.appendChild( new TextNode("abc") ); + href.appendChild(ruby); + root.appendChild(href); + doTest(root); + } + + public void testEnd1() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("toxmark"); + String name3 = mkName("refmark"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkNode(name1) ); + root.appendChild( new DocumentIndexMarkNode(name2) ); + root.appendChild( new ReferenceMarkNode(name3) ); + doTest(root); + } + + public void testEnd2() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("frame"); + String name3 = mkName("refmark"); + String name4 = mkName("frame"); + String name5 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new BookmarkNode(name1) ); + root.appendChild( new FrameNode(name2, AT_CHARACTER) ); + root.appendChild( new ReferenceMarkNode(name3) ); + root.appendChild( new FrameNode(name4, AT_CHARACTER) ); + root.appendChild( new FrameNode(name5, AT_CHARACTER) ); + doTest(root); + } + + public void testEnd3() throws Exception + { + String name1 = mkName("ftn"); + String name2 = mkName("toxmark"); + TreeNode root = new TreeNode(); + root.appendChild( new TextNode("abc") ); + root.appendChild( new FootnoteNode(name1) ); + root.appendChild( new DocumentIndexMarkNode(name2) ); + doTest(root); + } + + public void testEnd4() throws Exception + { + String name1 = mkName("bookmark"); + String name2 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkStartNode(name1) ); + root.appendChild( new TextNode("abc") ); + root.appendChild( new FrameNode(name2, AS_CHARACTER) ); + root.appendChild( new BookmarkEndNode(name1) ); + doTest(root); + } + + public void testEnd5() throws Exception + { + String name1 = mkName("refmark"); + String name2 = mkName("ruby"); + TreeNode root = new TreeNode(); + root.appendChild( new ReferenceMarkStartNode(name1) ); + root.appendChild( new TextNode("abc") ); + TreeNode ruby = new RubyNode(name2); + ruby.appendChild( new TextFieldNode("de") ); + root.appendChild(ruby); + root.appendChild( new ReferenceMarkEndNode(name1) ); + doTest(root); + } + + public void testEmpty1() throws Exception + { + String name1 = mkName("refmark"); + String name2 = mkName("toxmark"); + String name3 = mkName("bookmark"); + String name4 = mkName("frame"); + String name7 = mkName("refmark"); + String name8 = mkName("toxmark"); + String name9 = mkName("bookmark"); + String nameA = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new ReferenceMarkNode(name1) ); + root.appendChild( new DocumentIndexMarkNode(name2) ); + root.appendChild( new BookmarkNode(name3) ); + root.appendChild( new FrameNode(name4, AT_CHARACTER) ); + root.appendChild( new ReferenceMarkNode(name7) ); + root.appendChild( new DocumentIndexMarkNode(name8) ); + root.appendChild( new BookmarkNode(name9) ); + root.appendChild( new FrameNode(nameA, AT_CHARACTER) ); + doTest(root); + } + + public void testEmpty2() throws Exception + { + String name3 = mkName("bookmark"); + String name4 = mkName("frame"); + String name9 = mkName("bookmark"); + String nameA = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new BookmarkNode(name3) ); + root.appendChild( new FrameNode(name4, AT_CHARACTER) ); + root.appendChild( new BookmarkNode(name9) ); + root.appendChild( new FrameNode(nameA, AT_CHARACTER) ); + doTest(root); + } + + public void testEmpty3() throws Exception + { + String name1 = mkName("refmark"); + String name2 = mkName("toxmark"); + String name3 = mkName("bookmark"); + String name4 = mkName("frame"); + String name5 = mkName("url"); + String name6 = mkName("ruby"); + String name7 = mkName("refmark"); + String name8 = mkName("toxmark"); + String name9 = mkName("bookmark"); + String nameA = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new ReferenceMarkNode(name1) ); + root.appendChild( new DocumentIndexMarkNode(name2) ); + root.appendChild( new BookmarkNode(name3) ); + root.appendChild( new FrameNode(name4, AT_CHARACTER) ); + /* currently empty hyperlinks may get eaten... + TreeNode href = new HyperlinkNode(name5); + href.appendChild( new TextNode("") ); + root.appendChild(href); + */ + TreeNode ruby = new RubyNode(name6); + root.appendChild(ruby); + root.appendChild( new ReferenceMarkNode(name7) ); + root.appendChild( new DocumentIndexMarkNode(name8) ); + root.appendChild( new BookmarkNode(name9) ); + root.appendChild( new FrameNode(nameA, AT_CHARACTER) ); + doTest(root); + } + + public void test1() throws Exception + { + String name1 = mkName("frame"); + String name2 = mkName("bookmark"); + String name3 = mkName("ruby"); + String name4 = mkName("ftn"); + String name5 = mkName("frame"); + TreeNode root = new TreeNode(); + root.appendChild( new FrameNode(name1, AT_CHARACTER) ); + root.appendChild( new BookmarkStartNode(name2) ); + root.appendChild( new TextNode("abc") ); + TreeNode ruby = new RubyNode(name3); + ruby.appendChild( new TextNode("de") ); + ruby.appendChild( new FootnoteNode(name4) ); + ruby.appendChild( new BookmarkEndNode(name2) ); + root.appendChild(ruby); + root.appendChild( new TextNode("fg") ); + root.appendChild( new FrameNode(name5, AT_CHARACTER) ); + root.appendChild( new TextFieldNode("h") ); + doTest(root); + } + + /* some range tests for the insertion: these are for the current + API which treats hyperlinks and rubys not as entities, but as formatting + attributes; if these ever become entities, they should not be split! + */ + + public void testRange1() throws Exception + { + String name1 = mkName("url"); + RangeInserter inserter = new RangeInserter(m_xDoc); + TreeNode text = new TextNode("12345"); + inserter.insertRange(new Range(0, 0, text)); + TreeNode url1 = new HyperlinkNode(name1); + Range range1 = new Range(0, 5, url1); + inserter.insertRange(range1); + TreeNode root = new TreeNode(); + root.appendChild( url1 ); + url1.appendChild( text ); + doTest(root, false); + } + + public void testRangeHyperlinkHyperlink() 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, 4, url1) ); + // overlap left + TreeNode url2 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(0, 2, url2) ); + TreeNode root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("12") ) ) + .appendChild( url1.dup().appendChild( new TextNode("34") ) ) + .appendChild( new TextNode("56789") ); + doTest(root, false); + // overlap right + TreeNode url3 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(3, 7, url3) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("12") ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( url3.dup().appendChild( new TextNode("4567") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // around + TreeNode url4 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(3, 7, url4) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("12") ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( url4.dup().appendChild( new TextNode("4567") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // inside + TreeNode url5 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(4, 6, url5) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("12") ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( url4.dup().appendChild( new TextNode("4") ) ) + .appendChild( url5.dup().appendChild( new TextNode("56") ) ) + .appendChild( url4.dup().appendChild( new TextNode("7") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // empty + TreeNode url6 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(7, 7, url6) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("12") ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( url4.dup().appendChild( new TextNode("4") ) ) + .appendChild( url5.dup().appendChild( new TextNode("56") ) ) + .appendChild( url4.dup().appendChild( new TextNode("7") ) ) +// this one gets eaten, but we still need to test inserting it (#i106930#) +// .appendChild( url6.dup().appendChild( new TextNode("") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + } + + public void testRangeHyperlinkRuby() 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, 4, url1) ); + // overlap left + TreeNode rby2 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(0, 2, rby2) ); + TreeNode root = new TreeNode() + .appendChild( rby2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( url1.dup().appendChild( new TextNode("34") ) ) + .appendChild( new TextNode("56789") ); + doTest(root, false); + // overlap right + TreeNode rby3 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(3, 5, rby3) ); + root = new TreeNode() + .appendChild( rby2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( rby3.dup() + .appendChild( url1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // around + TreeNode rby4 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(2, 3, rby4) ); + root = new TreeNode() + .appendChild( rby2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( rby4.dup() + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) ) + .appendChild( rby3.dup() + .appendChild( url1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // inside + TreeNode url5 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(6, 9, url5) ); + TreeNode rby6 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(7, 8, rby6) ); + root = new TreeNode() + .appendChild( rby2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( rby4.dup() + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) ) + .appendChild( rby3.dup() + .appendChild( url1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6") ) + .appendChild( url5.dup().appendChild( new TextNode("7") ) ) + .appendChild( rby6.dup() + .appendChild( url5.dup().appendChild( new TextNode("8") ) ) ) + .appendChild( url5.dup().appendChild( new TextNode("9") ) ); + doTest(root, false); + } + + public void testRangeRubyHyperlink() 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(1, 6, rby1) ); + // overlap left + TreeNode url2 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(0, 3, url2) ); + TreeNode root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby1.dup() + .appendChild( url2.dup().appendChild( new TextNode("23") ) ) + .appendChild( new TextNode("456") ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // overlap right + TreeNode url3 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(5, 7, url3) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby1.dup() + .appendChild( url2.dup().appendChild( new TextNode("23") ) ) + .appendChild( new TextNode("45") ) + .appendChild( url3.dup().appendChild( new TextNode("6") ) ) ) + .appendChild( url3.dup().appendChild( new TextNode("7") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // around (not quite, due to API) + TreeNode url4 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(1, 8, url4) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby1.dup() + .appendChild( url4.dup() + .appendChild( new TextNode("23456") ) ) ) + .appendChild( url4.dup().appendChild( new TextNode("78") ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + // inside + TreeNode url5 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(3, 5, url5) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby1.dup() + .appendChild( url4.dup() + .appendChild( new TextNode("23") ) ) + .appendChild( url5.dup() + .appendChild( new TextNode("45") ) ) + .appendChild( url4.dup() + .appendChild( new TextNode("6") ) ) ) + .appendChild( url4.dup().appendChild( new TextNode("78") ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + } + + public void testRangeRubyRuby() 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(1, 4, rby1) ); + // overlap left + TreeNode rby2 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(0, 2, rby2) ); + TreeNode root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("12") ) ) + .appendChild( rby1.dup().appendChild( new TextNode("34") ) ) + .appendChild( new TextNode("56789") ); + doTest(root, false); + // overlap right + TreeNode rby3 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(3, 7, rby3) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("12") ) ) + .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) + .appendChild( rby3.dup().appendChild( new TextNode("4567") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // around + TreeNode rby4 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(3, 7, rby4) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("12") ) ) + .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) + .appendChild( rby4.dup().appendChild( new TextNode("4567") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // inside + TreeNode rby5 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(4, 6, rby5) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("12") ) ) + .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) + .appendChild( rby4.dup().appendChild( new TextNode("4") ) ) + .appendChild( rby5.dup().appendChild( new TextNode("56") ) ) + .appendChild( rby4.dup().appendChild( new TextNode("7") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + } + + public void testRangeHyperlinkMeta() 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, 4, url1) ); + // overlap left + TreeNode met2 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(0, 2, met2) ); + TreeNode root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( url1.dup().appendChild( new TextNode("34") ) ) + .appendChild( new TextNode("56789") ); + doTest(root, false); + // overlap right + TreeNode met3 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, met3) ); + root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) + .appendChild( met3.dup() + .appendChild( url1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // around + TreeNode met4 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(3/*-1*/, 4/*-1*/, met4) ); + root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( met4.dup() + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) ) + .appendChild( met3.dup() + .appendChild( url1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // inside + TreeNode url5 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(9/*-3*/, 12/*-3*/, url5) ); + TreeNode met6 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(10/*-3*/, 11/*-3*/, met6) ); + root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( url1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( met4.dup() + .appendChild( url1.dup().appendChild( new TextNode("3") ) ) ) + .appendChild( met3.dup() + .appendChild( url1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6") ) + .appendChild( url5.dup().appendChild( new TextNode("7") ) ) + .appendChild( met6.dup() + .appendChild( url5.dup().appendChild( new TextNode("8") ) ) ) + .appendChild( url5.dup().appendChild( new TextNode("9") ) ); + doTest(root, false); + } + + public void testRangeRubyMeta() 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(1, 4, rby1) ); + // overlap left + TreeNode met2 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(0, 2, met2) ); + TreeNode root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( rby1.dup().appendChild( new TextNode("34") ) ) + .appendChild( new TextNode("56789") ); + doTest(root, false); + // overlap right + TreeNode met3 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, met3) ); + root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) + .appendChild( met3.dup() + .appendChild( rby1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // around + TreeNode met4 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(3/*-1*/, 4/*-1*/, met4) ); + root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( met4.dup() + .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) ) + .appendChild( met3.dup() + .appendChild( rby1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // inside + TreeNode rby5 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(9/*-3*/, 12/*-3*/, rby5) ); + TreeNode met6 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(10/*-3*/, 11/*-3*/, met6) ); + root = new TreeNode() + .appendChild( met2.dup() + .appendChild( new TextNode("1") ) + .appendChild( rby1.dup().appendChild( new TextNode("2") ) ) ) + .appendChild( met4.dup() + .appendChild( rby1.dup().appendChild( new TextNode("3") ) ) ) + .appendChild( met3.dup() + .appendChild( rby1.dup().appendChild( new TextNode("4") ) ) + .appendChild( new TextNode("5") ) ) + .appendChild( new TextNode("6") ) + .appendChild( rby5.dup() + .appendChild( new TextNode("7") ) + .appendChild( met6.dup() + .appendChild( new TextNode("8") ) ) + .appendChild( new TextNode("9") ) ); + doTest(root, false); + } + + public void testRangeMetaHyperlink() 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, 6, met1) ); + // overlap left + TreeNode url2 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(0, 4/*-1*/, url2) ); + TreeNode root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( met1.dup() + .appendChild( url2.dup().appendChild( new TextNode("23") ) ) + .appendChild( new TextNode("456") ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // overlap right + TreeNode url3 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(6/*-1*/, 8/*-1*/, url3) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( met1.dup() + .appendChild( url2.dup().appendChild( new TextNode("23") ) ) + .appendChild( new TextNode("45") ) + .appendChild( url3.dup().appendChild( new TextNode("6") ) ) ) + .appendChild( url3.dup().appendChild( new TextNode("7") ) ) + .appendChild( new TextNode("89") ); + doTest(root, false); + // around (not quite, due to API) + TreeNode url4 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(1, 9/*-1*/, url4) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( met1.dup() + .appendChild( url4.dup() + .appendChild( new TextNode("23456") ) ) ) + .appendChild( url4.dup().appendChild( new TextNode("78") ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + // inside + TreeNode url5 = new HyperlinkNode( mkName("url") ); + inserter.insertRange( new Range(4/*-1*/, 6/*-1*/, url5) ); + root = new TreeNode() + .appendChild( url2.dup().appendChild( new TextNode("1") ) ) + .appendChild( met1.dup() + .appendChild( url4.dup() + .appendChild( new TextNode("23") ) ) + .appendChild( url5.dup() + .appendChild( new TextNode("45") ) ) + .appendChild( url4.dup() + .appendChild( new TextNode("6") ) ) ) + .appendChild( url4.dup().appendChild( new TextNode("78") ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + } + + public void testRangeMetaRuby() 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) ); + // overlap left + TreeNode rby2 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(0, 3/*-1*/, rby2) ); + TreeNode root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("1") ) ) + .appendChild( met1.dup() + .appendChild( rby2.dup().appendChild( new TextNode("2") ) ) + .appendChild( new TextNode("345") ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + // overlap right + TreeNode rby3 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(5/*-1*/, 7/*-1*/, rby3) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("1") ) ) + .appendChild( met1.dup() + .appendChild( rby2.dup().appendChild( new TextNode("2") ) ) + .appendChild( new TextNode("34") ) + .appendChild( rby3.dup().appendChild( new TextNode("5") ) ) ) + .appendChild( rby3.dup().appendChild( new TextNode("6") ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // around + TreeNode rby4 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(1, 7/*-1*/, rby4) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby4.dup() + .appendChild( met1.dup() + .appendChild( new TextNode("2345") ) ) + .appendChild( new TextNode("6") ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // inside + TreeNode met5 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(7/*-1*/, 9/*-1*/, met5) ); + TreeNode rby6 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(9/*-2*/, 10/*-2*/, rby6) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby4.dup() + .appendChild( met1.dup() + .appendChild( new TextNode("2345") ) ) + .appendChild( new TextNode("6") ) ) + .appendChild( met5.dup() + .appendChild( new TextNode("7") ) + .appendChild( rby6.dup() + .appendChild( new TextNode("8") ) ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + // inside, with invalid range that includes the dummy char + TreeNode rby7 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(7/*-1*/, 9/*-2*/, rby7) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby4.dup() + .appendChild( met1.dup() + .appendChild( new TextNode("2345") ) ) + .appendChild( new TextNode("6") ) ) + .appendChild( met5.dup() + .appendChild( rby7.dup() + .appendChild( new TextNode("7") ) ) + .appendChild( rby6.dup() + .appendChild( new TextNode("8") ) ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + // around, at same position as meta + TreeNode rby8 = new RubyNode( mkName("ruby") ); + inserter.insertRange( new Range(7/*-1*/, 10/*-2*/, rby8) ); + root = new TreeNode() + .appendChild( rby2.dup().appendChild( new TextNode("1") ) ) + .appendChild( rby4.dup() + .appendChild( met1.dup() + .appendChild( new TextNode("2345") ) ) + .appendChild( new TextNode("6") ) ) + .appendChild( rby8.dup() + .appendChild( met5.dup() + .appendChild( new TextNode("78") ) ) ) + .appendChild( new TextNode("9") ); + doTest(root, false); + } + + public void testRangeMetaMeta() 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(3, 6, met1) ); + // overlap left + TreeNode met2 = new MetaNode( mkId("id") ); + try { + inserter.insertRange( new Range(0, 4, met2) ); + assure("testRangeMetaMeta: overlap left allowed", false); + } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } + TreeNode root = new TreeNode() + .appendChild( new TextNode("123") ) + .appendChild( met1.dup().appendChild( new TextNode("456") ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // overlap right + TreeNode met3 = new MetaNode( mkId("id") ); + try { + inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, met3) ); + assure("testRangeMetaMeta: overlap right allowed", false); + } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } + root = new TreeNode() + .appendChild( new TextNode("123") ) + .appendChild( met1.dup().appendChild( new TextNode("456") ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // around + TreeNode met4 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(3, 7/*-1*/, met4) ); + root = new TreeNode() + .appendChild( new TextNode("123") ) + .appendChild( met4.dup() + .appendChild( met1.dup().appendChild( new TextNode("456") ) ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + // inside + TreeNode met5 = new MetaNode( mkId("id") ); + inserter.insertRange( new Range(6/*-2*/, 8/*-2*/, met5) ); + root = new TreeNode() + .appendChild( new TextNode("123") ) + .appendChild( met4.dup() + .appendChild( met1.dup() + .appendChild( new TextNode("4") ) + .appendChild( met5.dup() + .appendChild( new TextNode("56") ) ) ) ) + .appendChild( new TextNode("789") ); + doTest(root, false); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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); + } + + 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 + 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 = (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 = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xDocTextCursor); + for (int i = 0; i < nestedTextContent.length; ++i) { + Object oNTC = xPropertySet.getPropertyValue("NestedTextContent"); + XTextContent xNTC = (XTextContent) + UnoRuntime.queryInterface(XTextContent.class, oNTC); + if (null == nestedTextContent[i]) { + assure("unexpected NestedTextContent at: " + i, null == xNTC); + } else { + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xNTC); + StringPair xmlid = xMetadatable.getMetadataReference(); + assure("wrong NestedTextContent at: " + i, + MetaNode.eq(nestedTextContent[i], xmlid)); + } + xDocTextCursor.goRight((short)1, false); + } + + XChild xChild1 = (XChild) + UnoRuntime.queryInterface(XChild.class, xMeta1); + XChild xChild2 = (XChild) + UnoRuntime.queryInterface(XChild.class, xMeta2); + XChild xChild3 = (XChild) + UnoRuntime.queryInterface(XChild.class, xMeta3); + XChild xChild4 = (XChild) + UnoRuntime.queryInterface(XChild.class, xMeta4); + XChild xChild5 = (XChild) + UnoRuntime.queryInterface(XChild.class, xMeta5); + XChild xChild6 = (XChild) + UnoRuntime.queryInterface(XChild.class, xMeta6); + try { + xChild1.setParent(xChild4); + assure("setParent(): allowed?", false); + } catch (NoSupportException e) { /* expected */ } + assure("getParent(): not null", xChild1.getParent() == null); + assure("getParent(): not null", xChild2.getParent() == null); + assure("getParent(): not null", xChild6.getParent() == null); + { + Object xParent3 = xChild3.getParent(); + assure("getParent(): null", null != xParent3); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xParent3); + StringPair xmlid = xMetadatable.getMetadataReference(); + assure("getParent(): wrong", MetaNode.eq(xmlid, id2)); + }{ + Object xParent4 = xChild4.getParent(); + assure("getParent(): null", null != xParent4); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xParent4); + StringPair xmlid = xMetadatable.getMetadataReference(); + assure("getParent(): wrong", MetaNode.eq(xmlid, id3)); + }{ + Object xParent5 = xChild5.getParent(); + assure("getParent(): null", null != xParent5); + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xParent5); + StringPair xmlid = xMetadatable.getMetadataReference(); + assure("getParent(): wrong", MetaNode.eq(xmlid, id3)); + } + } + + /** test SwXMeta XText interface */ + 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") ); +// inserter.insertRange( new Range(3, 5, met2) ); + 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); +// xMeta.attach(xDocTextCursor); + + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xMeta); + xMetadatable.setMetadataReference(meta.getXmlId()); + 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, 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")); + } + // no ruby end here!!! + assure("hasNext(): more elements?", !xEnum.hasMoreElements()); + + XComponent xComponent = (XComponent) + UnoRuntime.queryInterface(XComponent.class, xMeta); + xComponent.dispose(); + + try { + XTextCursor xCursor = xText.createTextCursor(); + assure("createTextCursor(): succeeds on disposed object?", + xCursor == null); + } catch (RuntimeException e) { /* expected */ } + } + + /** check that cursor move methods move to positions in the meta, + but do not move to positions outside the meta. */ + 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 = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xMeta); + xMetadatable.setMetadataReference(met1.getXmlId()); + XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta); + + XTextRange xStart = xText.getStart(); + assure("getStart(): no start", xStart != null); + XTextRange xEnd = xText.getEnd(); + assure("getEnd(): no end", xEnd != null); + + XTextCursor xTextCursor = xText.createTextCursor(); + assure("createTextCursor(): no cursor", xTextCursor != null); + + // XTextCursor + boolean bSuccess = false; + xTextCursor.gotoStart(false); + xTextCursor.gotoEnd(false); + bSuccess = xTextCursor.goLeft((short)1, false); + assure("goLeft(): failed", bSuccess); + bSuccess = xTextCursor.goLeft((short)1000, false); + assure("goLeft(): succeeded", !bSuccess); + bSuccess = xTextCursor.goRight((short)1, false); + assure("goRight(): failed", bSuccess); + bSuccess = xTextCursor.goRight((short)1000, false); + assure("goRight(): succeeded", !bSuccess); + xTextCursor.gotoRange(xStart, false); + xTextCursor.gotoRange(xEnd, false); + try { + xTextCursor.gotoRange(xDocTextCursor, false); + assure("gotoRange(): succeeded", false); + } catch (RuntimeException e) { /* expected */ } + + // XWordCursor + xText.setString("Two words"); + xTextCursor.gotoStart(false); + XWordCursor xWordCursor = (XWordCursor) + UnoRuntime.queryInterface(XWordCursor.class, xTextCursor); + + bSuccess = xWordCursor.gotoNextWord(true); + assure("gotoNextWord(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoNextWord(): wrong string: " + string, + "Two ".equals(string)); + } + bSuccess = xWordCursor.gotoNextWord(false); + assure("gotoNextWord(): succeeded", !bSuccess); + xTextCursor.collapseToEnd(); + bSuccess = xWordCursor.gotoPreviousWord(true); + assure("gotoPreviousWord(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoPreviousWord(): wrong string: " + string, + "words".equals(string)); + } + bSuccess = xWordCursor.gotoPreviousWord(false); + assure("gotoPreviousWord(): succeeded", !bSuccess); + bSuccess = xWordCursor.gotoEndOfWord(true); + assure("gotoEndOfWord(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoEndOfWord(): wrong string: " + string, + "Two".equals(string)); + } + xTextCursor.gotoEnd(false); + bSuccess = xWordCursor.gotoStartOfWord(true); + assure("gotoStartOfWord(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoStartOfWord(): wrong string: " + string, + "words".equals(string)); + } + xText.setString(""); + bSuccess = xWordCursor.gotoEndOfWord(false); + assure("gotoEndOfWord(): succeeded", !bSuccess); + bSuccess = xWordCursor.gotoStartOfWord(false); + assure("gotoStartOfWord(): succeeded", !bSuccess); + + // XSentenceCursor + xText.setString("This is a sentence. Another sentence."); + xTextCursor.gotoStart(false); + XSentenceCursor xSentenceCursor = (XSentenceCursor) + UnoRuntime.queryInterface(XSentenceCursor.class, xTextCursor); + + bSuccess = xSentenceCursor.gotoNextSentence(true); + assure("gotoNextSentence(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoNextSentence(): wrong string: " + string, + "This is a sentence. ".equals(string)); + } + bSuccess = xSentenceCursor.gotoNextSentence(false); + assure("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); + assure("gotoPreviousSentence(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoPreviousSentence(): wrong string: " + string, + "Another sentence. Sentence 3.".equals(string)); + } + bSuccess = xSentenceCursor.gotoPreviousSentence(false); + assure("gotoPreviousSentence(): succeeded", !bSuccess); + bSuccess = xSentenceCursor.gotoEndOfSentence(true); + assure("gotoEndOfSentence(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoEndOfSentence(): wrong string: " + string, + "This is a sentence.".equals(string)); + } + xTextCursor.gotoEnd(false); + bSuccess = xSentenceCursor.gotoStartOfSentence(true); + assure("gotoStartOfSentence(): failed", bSuccess); + { + String string = xTextCursor.getString(); + assure("gotoStartOfSentence(): wrong string: " + string, + "Sentence 3.".equals(string)); + } + xText.setString(""); + bSuccess = xSentenceCursor.gotoEndOfSentence(false); + assure("gotoEndOfSentence(): succeeded", !bSuccess); + bSuccess = xSentenceCursor.gotoStartOfSentence(false); + assure("gotoStartOfSentence(): succeeded", !bSuccess); + + XParagraphCursor xParagraphCursor = (XParagraphCursor) + UnoRuntime.queryInterface(XParagraphCursor.class, xTextCursor); + + // XParagraphCursor (does not make sense) + bSuccess = xParagraphCursor.gotoNextParagraph(false); + assure("gotoNextParagraph(): succeeded", !bSuccess); + bSuccess = xParagraphCursor.gotoPreviousParagraph(false); + assure("gotoPreviousParagraph(): succeeded", !bSuccess); + bSuccess = xParagraphCursor.gotoStartOfParagraph(false); + assure("gotoStartOfParagraph(): succeeded", !bSuccess); + bSuccess = xParagraphCursor.gotoEndOfParagraph(false); + assure("gotoEndOfParagraph(): succeeded", !bSuccess); + } + + + abstract class AttachHelper + { + abstract boolean isAttribute(); + abstract TreeNode mkTreeNode(); + abstract XTextContent mkTextContent(Inserter inserter, TreeNode node) + throws Exception; + void postInserted(TreeNode node, XTextContent xContent) + throws Exception { } + } + + public void testMetaXTextAttachToxMark() throws Exception + { + doMetaXTextAttach( new AttachHelper() + { + boolean isAttribute() { return true; } + TreeNode mkTreeNode() { + return new DocumentIndexMarkNode( mkName("toxmark") ); + } + XTextContent mkTextContent(Inserter inserter, TreeNode node) + throws Exception { + return inserter.makeDocumentIndexMark( + ((DocumentIndexMarkNode)node).getName()); + } + }); + } + + public void testMetaXTextAttachRefMark() throws Exception + { + doMetaXTextAttach( new AttachHelper() + { + boolean isAttribute() { return true; } + TreeNode mkTreeNode() { + return new ReferenceMarkNode( mkName("refmark") ); + } + XTextContent mkTextContent(Inserter inserter, TreeNode node) + throws Exception { + return inserter.makeReferenceMark( + ((ReferenceMarkNode)node).getName()); + } + }); + } + + public void testMetaXTextAttachTextField() throws Exception + { + doMetaXTextAttach( new AttachHelper() + { + boolean isAttribute() { return false; } + TreeNode mkTreeNode() { + return new TextFieldNode( mkName("field") ); + } + XTextContent mkTextContent(Inserter inserter, TreeNode node) + throws Exception { + return inserter.makeTextField( + ((TextFieldNode)node).getContent()); + } + }); + } + + public void testMetaXTextAttachFootnote() throws Exception + { + doMetaXTextAttach( new AttachHelper() + { + boolean isAttribute() { return false; } + TreeNode mkTreeNode() { + return new FootnoteNode( mkName("ftn") ); + } + XTextContent mkTextContent(Inserter inserter, TreeNode node) + throws Exception { + return inserter.makeFootnote( + ((FootnoteNode)node).getLabel()); + } + }); + } + + public void testMetaXTextAttachMeta() throws Exception + { + doMetaXTextAttach( new AttachHelper() + { + boolean isAttribute() { return true; } + TreeNode mkTreeNode() { + return new MetaNode( mkId("id") ); + } + XTextContent mkTextContent(Inserter inserter, TreeNode node) + throws Exception { + return inserter.makeMeta(); + } + void postInserted(TreeNode node, XTextContent xContent) + throws Exception { + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xContent); + xMetadatable.setMetadataReference( + ((MetaNode)node).getXmlId()); + } + }); + } + + void doMetaXTextAttach(AttachHelper helper) throws Exception + { + RangeInserter inserter = new RangeInserter(m_xDoc); + TreeNode text = new TextNode("12AB6789"); + 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)3, false); + xDocTextCursor.goRight((short)2, true); + xDocText.insertTextContent(xDocTextCursor, xMeta, true); + + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xMeta); + xMetadatable.setMetadataReference(met1.getXmlId()); + XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta); + XTextRange xStart = null; + XTextRange xEnd = null; + + { + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + // insertTextContent with meta getStart()/getEnd() + xText.insertTextContent(xStart, xContent1, false); + xText.insertTextContent(xEnd , xContent2, false); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + { + xText.setString("AB"); + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + XTextCursor xTextCursor = xText.createTextCursor(); + xTextCursor.gotoStart(false); + + // insertTextContent with meta cursor + xText.insertTextContent(xTextCursor, xContent1, false); + xTextCursor.gotoEnd(false); + xText.insertTextContent(xTextCursor, xContent2, false); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + if (!helper.isAttribute()) + { +// xText.setString("AB"); + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + XTextCursor xTextCursor = xText.createTextCursor(); + xTextCursor.gotoStart(false); + xTextCursor.goRight((short)1, true); + + // insertTextContent with meta cursor and absorb + xText.insertTextContent(xTextCursor, xContent1, true); + xTextCursor.gotoEnd(false); + xTextCursor.goLeft((short)1, true); + xText.insertTextContent(xTextCursor, xContent2, true); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + { + xText.setString("AB"); + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + xDocTextCursor.gotoRange(xStart, false); + + // insertTextContent with document cursor + xText.insertTextContent(xDocTextCursor, xContent1, false); + xDocTextCursor.gotoRange(xEnd, false); + xText.insertTextContent(xDocTextCursor, xContent2, false); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + if (!helper.isAttribute()) + { +// xText.setString("AB"); + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + xDocTextCursor.gotoRange(xStart, false); + xDocTextCursor.goRight((short)1, true); + + // insertTextContent with document cursor and absorb + xText.insertTextContent(xDocTextCursor, xContent1, true); + xDocTextCursor.gotoRange(xEnd, false); + xDocTextCursor.goLeft((short)1, true); + xText.insertTextContent(xDocTextCursor, xContent2, true); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + { + xText.setString("AB"); + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + // attach to range from meta getStart()/getEnd() + xContent1.attach(xStart); + xContent2.attach(xEnd); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + { + xText.setString("AB"); + xStart = xText.getStart(); + xEnd = xText.getEnd(); + + TreeNode nod1 = helper.mkTreeNode(); + TreeNode nod2 = helper.mkTreeNode(); + XTextContent xContent1 = helper.mkTextContent(inserter, nod1); + XTextContent xContent2 = helper.mkTextContent(inserter, nod2); + + XTextCursor xTextCursor = xText.createTextCursor(); + xTextCursor.gotoStart(false); + + // attach to cursor from meta XText + xContent1.attach(xTextCursor); + xTextCursor.gotoEnd(false); + xContent2.attach(xTextCursor); + + helper.postInserted(nod1, xContent1); + helper.postInserted(nod2, xContent2); + + TreeNode root = new TreeNode() + .appendChild( new TextNode("12") ) + .appendChild( met1.dup() + .appendChild( nod1.dup() ) + .appendChild( new TextNode("AB") ) + .appendChild( nod2.dup() ) ) + .appendChild( new TextNode("6789") ); + doTest(root, false); + } + } + + public void testMetaFieldXTextField() throws Exception + { + com.sun.star.rdf.XRepositorySupplier xModel = + (com.sun.star.rdf.XRepositorySupplier) UnoRuntime.queryInterface( + com.sun.star.rdf.XRepositorySupplier.class, m_xDoc); + com.sun.star.rdf.XRepository xRepo = xModel.getRDFRepository(); + // for testing just add it to the first graph + com.sun.star.rdf.XURI[] Graphs = xRepo.getGraphNames(); + com.sun.star.rdf.XNamedGraph xGraph = xRepo.getGraph(Graphs[0]); + com.sun.star.rdf.XURI xOdfPrefix = + com.sun.star.rdf.URI.createKnown(m_xContext, + com.sun.star.rdf.URIs.ODF_PREFIX); + com.sun.star.rdf.XURI xOdfSuffix = + com.sun.star.rdf.URI.createKnown(m_xContext, + com.sun.star.rdf.URIs.ODF_SUFFIX); + com.sun.star.rdf.XNode xPrefix = + com.sun.star.rdf.Literal.create(m_xContext, "foo"); + com.sun.star.rdf.XNode xSuffix = + com.sun.star.rdf.Literal.create(m_xContext, "bar"); + + RangeInserter inserter = new RangeInserter(m_xDoc); + TreeNode text = new TextNode("abc"); + inserter.insertRange( new Range(0, 0, text) ); + XText xDocText = m_xDoc.getText(); + XTextCursor xDocTextCursor = xDocText.createTextCursor(); + xDocTextCursor.goRight((short)1, false); + xDocTextCursor.goRight((short)3, true); + + XTextField xMetaField = inserter.makeMetaField(); + + xDocText.insertTextContent(xDocTextCursor, xMetaField, true); + + XMetadatable xMetadatable = (XMetadatable) + UnoRuntime.queryInterface(XMetadatable.class, xMetaField); + xMetadatable.ensureMetadataReference(); + + xGraph.addStatement(xMetadatable, xOdfPrefix, xPrefix); + xGraph.addStatement(xMetadatable, xOdfSuffix, xSuffix); + assure("getPresentation(): wrong", + "fooabcbar".equals(xMetaField.getPresentation(false))); + inserter.insertRange( new Range(0, 0, text) ); + } + + public void testMetaFieldXPropertySet() throws Exception + { + RangeInserter inserter = new RangeInserter(m_xDoc); + TreeNode text = new TextNode("123"); + inserter.insertRange( new Range(0, 0, text) ); + XText xDocText = m_xDoc.getText(); + XTextCursor xDocTextCursor = xDocText.createTextCursor(); + xDocTextCursor.goRight((short)1, false); + xDocTextCursor.goRight((short)3, true); + + XTextField xMetaField = inserter.makeMetaField(); + + xDocText.insertTextContent(xDocTextCursor, xMetaField, true); + + XPropertySet xPropertySet = (XPropertySet) + UnoRuntime.queryInterface(XPropertySet.class, xMetaField); + assure("PropertySet: not supported?", xPropertySet != null); + XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo(); + assure("hasPropertyByName(\"NumberFormat\"):", + xPropertySetInfo.hasPropertyByName("NumberFormat")); + assure("hasPropertyByName(\"IsFixedLanguage\"):", + xPropertySetInfo.hasPropertyByName("IsFixedLanguage")); + + int def = (Integer) xPropertySet.getPropertyValue("NumberFormat"); + log.println("NumberFormat: default is " + def); + short INT = com.sun.star.i18n.NumberFormatIndex.NUMBER_INT; + xPropertySet.setPropertyValue("NumberFormat", INT); + xPropertySet.setPropertyValue("IsFixedLanguage", true); + int format = (Integer) xPropertySet.getPropertyValue("NumberFormat"); + assure("NumberFormat: failed", format == INT); + boolean isFixed = (Boolean) + xPropertySet.getPropertyValue("IsFixedLanguage"); + assure("IsFixedLanguage: failed", isFixed); + } + + public void testLoadStore() throws Exception + { + XTextDocument xComp = null; + String filename = "TESTMETA.odt"; + String file; + try { + file = util.utils.getFullTestURL(filename); + xComp = doLoad(file); + if (xComp != null) + { + checkLoadMeta(xComp); + file = m_TmpDir + filename; + doStore(xComp, file); + close(xComp); + xComp = doLoad(file); + checkLoadMeta(xComp); + } + } finally { + close(xComp); + } + } + + private void doStore(XComponent xComp, String file) throws Exception + { + log.println("Storing test document..."); + + XStorable xStor = (XStorable) UnoRuntime.queryInterface( + XStorable.class, xComp); + + xStor.storeToURL(file, new PropertyValue[0]); + + log.println("...done"); + } + + public XTextDocument doLoad(String file) throws Exception + { + XComponent xComp = null; + + log.println("Loading test document..."); + + PropertyValue[] loadProps = new PropertyValue[1]; + loadProps[0] = new PropertyValue(); + loadProps[0].Name = "Hidden"; + loadProps[0].Value = new Boolean(true); + + xComp = util.DesktopTools.loadDoc(m_xMSF, file, loadProps); +// xComp = util.DesktopTools.getCLoader(m_xMSF).loadComponentFromURL(file, "_blank", 0, loadProps); + + XTextDocument xTextDoc = (XTextDocument) + UnoRuntime.queryInterface(XTextDocument.class, xComp); + + assure("cannot load: " + file, xTextDoc != null); + + log.println("...done"); + + return xTextDoc; + } + + public void checkLoadMeta(XTextDocument xTextDoc) throws Exception + { + XText xText = xTextDoc.getText(); + + log.println("Checking meta(-field)s in loaded test document..."); + + TreeNode root = new TreeNode() + .appendChild( new RubyNode("ruby1") + .appendChild( new TextNode("1") ) ) + .appendChild( new MetaNode(mkId_("id1")) + .appendChild( new TextNode("2") ) ) + .appendChild( new MetaFieldNode(mkId_("id2")) + .appendChild( new TextNode("3") ) ) + .appendChild( new RubyNode("ruby2") + .appendChild( new MetaNode(mkId_("id3")) + .appendChild( new TextNode("4") ) ) ) + .appendChild( new RubyNode("ruby3") + .appendChild( new MetaFieldNode(mkId_("id4")) + .appendChild( new TextNode("5") ) ) ) + .appendChild( new MetaNode(mkId_("id5")) + .appendChild( new RubyNode("ruby4") + .appendChild( new TextNode("6") ) ) ) + .appendChild( new MetaFieldNode(mkId_("id6")) + .appendChild( new RubyNode("ruby5") + .appendChild( new TextNode("7") ) ) ) + .appendChild( new MetaNode(mkId_("id7")) + .appendChild( new MetaNode(mkId_("id8")) + .appendChild( new TextNode("8") ) ) ) + .appendChild( new MetaNode(mkId_("id9")) + .appendChild( new MetaFieldNode(mkId_("id10")) + .appendChild( new TextNode("9") ) ) ) + .appendChild( new MetaFieldNode(mkId_("id11")) + .appendChild( new MetaNode(mkId_("id12")) + .appendChild( new TextNode("10") ) ) ) + .appendChild( new MetaFieldNode(mkId_("id13")) + .appendChild( new MetaFieldNode(mkId_("id14")) + .appendChild( new TextNode("11") ) ) ) + .appendChild( new MetaNode(mkId_("id15")) + .appendChild( new RubyNode("ruby6") + .appendChild( new MetaFieldNode(mkId_("id16")) + .appendChild( new TextNode("12") ) ) ) ) + .appendChild( new MetaNode(mkId_("")) { + public boolean equals(Object other) { + return (other instanceof MetaNode); + } } + .appendChild( new TextNode("13") ) ) + .appendChild( new TextNode(" X X ") ); + doTest(xTextDoc, root, false); + + log.println("...done"); + } + + public void testLoadStoreXmlid() throws Exception + { + XTextDocument xComp = null; + String filename = "TESTXMLID.odt"; + String file; + try { + file = util.utils.getFullTestURL(filename); + xComp = doLoad(file); + if (xComp != null) + { + checkLoadXmlId(xComp); + file = m_TmpDir + filename; + doStore(xComp, file); + close(xComp); + xComp = doLoad(file); + checkLoadXmlId(xComp); + } + } finally { + close(xComp); + } + } + + public void checkLoadXmlId(XTextDocument xTextDoc) throws Exception + { + XText xText = xTextDoc.getText(); + + log.println("Checking bookmarks in loaded test document..."); + + XRepositorySupplier xRS = (XRepositorySupplier) + UnoRuntime.queryInterface(XRepositorySupplier.class, xTextDoc); + XDocumentRepository xRepo = (XDocumentRepository) + UnoRuntime.queryInterface(XDocumentRepository.class, + xRS.getRDFRepository()); + XBookmarksSupplier xBMS = (XBookmarksSupplier) + UnoRuntime.queryInterface(XBookmarksSupplier.class, xTextDoc); + XNameAccess xBookmarks = xBMS.getBookmarks(); + XMetadatable xMark1 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xBookmarks.getByName("mk1")); + assure("mark1", + eq(xMark1.getMetadataReference(), + new StringPair("content.xml", "id90"))); + + XMetadatable xMark2 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xBookmarks.getByName("mk2")); + Pair<Statement[], Boolean> result = xRepo.getStatementRDFa(xMark2); + assure("mark2", (result.First.length == 1) + && result.First[0].Subject.getStringValue().equals("uri:foo") + && result.First[0].Predicate.getStringValue().equals("uri:bar") + && result.First[0].Object.getStringValue().contains("a fooish bar") + ); + + XMetadatable xMark3 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xBookmarks.getByName("mk3")); + assure("mark3", + eq(xMark3.getMetadataReference(), + new StringPair("content.xml", "id91"))); + + log.println("...done"); + + log.println("Checking sections in loaded test document..."); + + XTextSectionsSupplier xTSS = (XTextSectionsSupplier) + UnoRuntime.queryInterface(XTextSectionsSupplier.class, xTextDoc); + + XNameAccess xSections = xTSS.getTextSections(); + + XMetadatable xSection1 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Section 1")); + assure("idsection1", eq(xSection1.getMetadataReference(), + new StringPair("content.xml", "idSection1"))); + + XMetadatable xSection2 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Section 2")); + assure("idSection2", eq(xSection2.getMetadataReference(), + new StringPair("content.xml", "idSection2"))); + + XMetadatable xSection3 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, + xSections.getByName("Table of Contents1_Head")); + assure("idTOCTitle", eq(xSection3.getMetadataReference(), + new StringPair("content.xml", "idTOCTitle"))); + + XMetadatable xSection4 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, + xSections.getByName("Alphabetical Index1_Head")); + assure("idAITitle", eq(xSection4.getMetadataReference(), + new StringPair("content.xml", "idAITitle"))); + + XMetadatable xSection5 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, + xSections.getByName("Illustration Index1_Head")); + assure("idIITitle", eq(xSection5.getMetadataReference(), + new StringPair("content.xml", "idIITitle"))); + + XMetadatable xSection6 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, + xSections.getByName("Index of Tables1_Head")); + assure("idIOTTitle", eq(xSection6.getMetadataReference(), + new StringPair("content.xml", "idIOTTitle"))); + + XMetadatable xSection7 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, + xSections.getByName("User-Defined1_Head")); + assure("idUDTitle", eq(xSection7.getMetadataReference(), + new StringPair("content.xml", "idUDTitle"))); + + XMetadatable xSection8 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, + xSections.getByName("Table of Objects1_Head")); + assure("idTOOTitle", eq(xSection8.getMetadataReference(), + new StringPair("content.xml", "idTOOTitle"))); + + XMetadatable xSection9 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Bibliography1_Head")); + assure("idBibTitle", eq(xSection9.getMetadataReference(), + new StringPair("content.xml", "idBibTitle"))); + + log.println("...done"); + + log.println("Checking indexes in loaded test document..."); + + XDocumentIndexesSupplier xDIS = (XDocumentIndexesSupplier) + UnoRuntime.queryInterface(XDocumentIndexesSupplier.class, xTextDoc); + XIndexAccess xIndexesIA = xDIS.getDocumentIndexes(); + XNameAccess xIndexes = + UnoRuntime.queryInterface(XNameAccess.class, xIndexesIA); + + XMetadatable xIndex1 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("Table of Contents1")); + assure("idTOC", eq(xIndex1.getMetadataReference(), + new StringPair("content.xml", "idTOC"))); + XMetadatable xIndex1s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Table of Contents1")); + assure("idTOC", eq(xIndex1s.getMetadataReference(), + new StringPair("content.xml", "idTOC"))); + + XMetadatable xIndex2 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("Alphabetical Index1")); + assure("idAI", eq(xIndex2.getMetadataReference(), + new StringPair("content.xml", "idAI"))); + XMetadatable xIndex2s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Alphabetical Index1")); + assure("idAI", eq(xIndex2s.getMetadataReference(), + new StringPair("content.xml", "idAI"))); + + XMetadatable xIndex3 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("Illustration Index1")); + assure("idII", eq(xIndex3.getMetadataReference(), + new StringPair("content.xml", "idII"))); + XMetadatable xIndex3s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Illustration Index1")); + assure("idII", eq(xIndex3s.getMetadataReference(), + new StringPair("content.xml", "idII"))); + + XMetadatable xIndex4 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("Index of Tables1")); + assure("idIOT", eq(xIndex4.getMetadataReference(), + new StringPair("content.xml", "idIOT"))); + XMetadatable xIndex4s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Index of Tables1")); + assure("idIOT", eq(xIndex4s.getMetadataReference(), + new StringPair("content.xml", "idIOT"))); + + XMetadatable xIndex5 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("User-Defined1")); + assure("idUD", eq(xIndex5.getMetadataReference(), + new StringPair("content.xml", "idUD"))); + XMetadatable xIndex5s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("User-Defined1")); + assure("idUD", eq(xIndex5s.getMetadataReference(), + new StringPair("content.xml", "idUD"))); + + XMetadatable xIndex6 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("Table of Objects1")); + assure("idTOO", eq(xIndex6.getMetadataReference(), + new StringPair("content.xml", "idTOO"))); + XMetadatable xIndex6s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Table of Objects1")); + assure("idTOO", eq(xIndex6s.getMetadataReference(), + new StringPair("content.xml", "idTOO"))); + + XMetadatable xIndex7 = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xIndexes.getByName("Bibliography1")); + assure("idBib", eq(xIndex7.getMetadataReference(), + new StringPair("content.xml", "idBib"))); + XMetadatable xIndex7s = (XMetadatable) UnoRuntime.queryInterface( + XMetadatable.class, xSections.getByName("Bibliography1")); + assure("idBib", eq(xIndex7s.getMetadataReference(), + new StringPair("content.xml", "idBib"))); + + log.println("...done"); + } + + static void close(XComponent i_comp) + { + try { + XCloseable xClos = (XCloseable) UnoRuntime.queryInterface( + XCloseable.class, i_comp); + if (xClos != null) xClos.close(true); + } catch (Exception e) { + } + } + + private void doTest(TreeNode intree) throws Exception + { + doTest(m_xDoc, intree, true); + } + + private void doTest(TreeNode intree, boolean insert) throws Exception + { + doTest(m_xDoc, intree, insert); + } + + private void doTest(XTextDocument xDoc, TreeNode intree, + boolean insert) throws Exception + { + dumpTree(intree, "I: "); + + if (insert) { + new TreeInserter(xDoc).insertTree(intree); + } + +//Thread.sleep(10000); + + XText xText = xDoc.getText(); + XEnumerationAccess xTextEA = (XEnumerationAccess) + UnoRuntime.queryInterface(XEnumerationAccess.class, xText); + XEnumeration xTextEnum = xTextEA.createEnumeration(); + // skip to right paragraph + xTextEnum.nextElement(); // skip first -- always empty! + Object xElement = xTextEnum.nextElement(); // second contains test case + XEnumerationAccess xEA = (XEnumerationAccess) + UnoRuntime.queryInterface(XEnumerationAccess.class, xElement); + XEnumeration xEnum = xEA.createEnumeration(); + TreeNode outtree = new EnumConverter(this).convert(xEnum); + + dumpTree(outtree, "O: "); + + boolean success = new FuzzyTester(log).doTest(intree, outtree); + assure("test failed", success); + } + + private void dumpTree(TreeNode tree) { dumpTree(tree, "> "); } + + private void dumpTree(TreeNode tree, String prefix) + { + log.println(prefix + tree.toString()); + TreeNodeEnum children = tree.createEnumeration(); + while (children.hasNext()) { + TreeNode node = children.next(); + dumpTree(node, prefix + " "); + } + } + + private String mkName(String prefix) + { + return prefix + String.valueOf(m_Count++); + } + + private StringPair mkId(String prefix) + { + return new StringPair("content.xml", mkName(prefix)); + } + + private StringPair mkId_(String id) + { + return new StringPair("content.xml", id); + } + + static boolean eq(StringPair i_Left, StringPair i_Right) + { + return ((i_Left.First).equals(i_Right.First)) && + ((i_Left.Second).equals(i_Right.Second)); + } + + public void assure(String str, boolean cond) { super.assure(str, cond); } +} + diff --git a/sw/qa/complex/writer/makefile.mk b/sw/qa/complex/writer/makefile.mk new file mode 100755 index 000000000000..ae2a15f821dd --- /dev/null +++ b/sw/qa/complex/writer/makefile.mk @@ -0,0 +1,108 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = PropertyValues +PRJNAME = $(TARGET) +PACKAGE = complex$/writer + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = mysql.jar ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar +JAVAFILES = CheckIndexedPropertyValues.java CheckNamedPropertyValues.java CheckCrossReferences.java CheckBookmarks.java CheckFlies.java TextPortionEnumerationTest.java +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# start an office if the parameter is set for the makefile +.IF "$(OFFICE)" == "" +CT_APPEXECCOMMAND = +.ELSE +CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" +.ENDIF + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# build package name with "." instead of $/ +CT_PACKAGE = -o $(PACKAGE:s\$/\.\) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.IF "$(depend)" == "" +ALL: ALLTAR +.ELSE +ALL: ALLDEP +.ENDIF + +.INCLUDE : target.mk + +run: \ + CheckBookmarks \ + CheckCrossReferences \ + CheckIndexedPropertyValues \ + CheckNamedPropertyValues \ + CheckFlies \ + TextPortionEnumerationTest \ + + +RUN: run + +CheckIndexedPropertyValues: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) $(CT_PACKAGE).CheckIndexedPropertyValues + + +CheckNamedPropertyValues: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) $(CT_PACKAGE).CheckNamedPropertyValues + +CheckCrossReferences: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) -tdoc $(PWD)$/testdocuments $(CT_PACKAGE).CheckCrossReferences + +CheckBookmarks: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) -tdoc $(PWD)$/testdocuments $(CT_PACKAGE).CheckBookmarks + +CheckFlies: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) -tdoc $(PWD)$/testdocuments $(CT_PACKAGE).CheckFlies + +TextPortionEnumerationTest: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) -tdoc $(PWD)$/testdocuments $(CT_PACKAGE).TextPortionEnumerationTest + diff --git a/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt b/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt Binary files differnew file mode 100644 index 000000000000..d8102f0356f8 --- /dev/null +++ b/sw/qa/complex/writer/testdocuments/CheckCrossReferences.odt diff --git a/sw/qa/complex/writer/testdocuments/CheckFlies.odt b/sw/qa/complex/writer/testdocuments/CheckFlies.odt Binary files differnew file mode 100644 index 000000000000..8f42989b3a0d --- /dev/null +++ b/sw/qa/complex/writer/testdocuments/CheckFlies.odt diff --git a/sw/qa/complex/writer/testdocuments/TESTMETA.odt b/sw/qa/complex/writer/testdocuments/TESTMETA.odt Binary files differnew file mode 100755 index 000000000000..004af82e5ddf --- /dev/null +++ b/sw/qa/complex/writer/testdocuments/TESTMETA.odt diff --git a/sw/qa/complex/writer/testdocuments/TESTXMLID.odt b/sw/qa/complex/writer/testdocuments/TESTXMLID.odt Binary files differnew file mode 100644 index 000000000000..063d392a489f --- /dev/null +++ b/sw/qa/complex/writer/testdocuments/TESTXMLID.odt diff --git a/sw/qa/core/Test-BigPtrArray.cxx b/sw/qa/core/Test-BigPtrArray.cxx new file mode 100644 index 000000000000..4b5394a77d3c --- /dev/null +++ b/sw/qa/core/Test-BigPtrArray.cxx @@ -0,0 +1,877 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sw.hxx" +#define TIMELOG + +#include <testshl/simpleheader.hxx> +#include <bparr.hxx> +#include <string> +#include <stdlib.h> +#include <rtl/logfile.hxx> + +#undef ENABLE_DEBUG_OUTPUT + +using namespace std; + + +namespace /* private */ +{ + const int NUM_ENTRIES = 100000; + + class BigPtrEntryMock : public BigPtrEntry + { + public: + BigPtrEntryMock(int count) : count_(count) + { + } + + ~BigPtrEntryMock() + { + #ifdef ENABLE_DEBUG_OUTPUT + printf("Destructor called (%i)\n", count_); + #endif + } + + int getCount() const + { + return count_; + } + + void setCount(int newCount) + { + count_ = newCount; + } + + ULONG Position() const + { + return GetPos(); + } + + private: + int count_; + }; + + BOOL AddToCount(const ElementPtr& rElem, void* pArgs) + { + BigPtrEntryMock* const pbem = static_cast<BigPtrEntryMock* const>(rElem); + pbem->setCount(pbem->getCount() + *((int*)pArgs)); + return true; + } + + void dumpBigPtrArray(const BigPtrArray& bparr) + { + #ifdef ENABLE_DEBUG_OUTPUT + for (int i = 0; i < bparr.Count(); i++) + printf("bparr[%i,%i]: %i\n", i, static_cast<BigPtrEntryMock*>(bparr[i])->Position(), static_cast<BigPtrEntryMock*>(bparr[i])->getCount()); + + printf("\n"); + #endif + } + + void fillBigPtrArray(BigPtrArray& bparr, ULONG numEntries) + { + for (int i = 0; i < numEntries; i++) + bparr.Insert(new BigPtrEntryMock(i), bparr.Count()); + } + + void printMethodName(const char* name) + { + #ifdef ENABLE_DEBUG_OUTPUT + printf(name); + #endif + } + + bool checkElementPositions(const BigPtrArray& bparr) + { + for (int i = 0; i < bparr.Count(); i++) + { + if (static_cast<BigPtrEntryMock*>(bparr[i])->Position() != i) + return false; + } + return true; + } + + void releaseBigPtrArrayContent(BigPtrArray& bparr) + { + for (int i = 0; i < bparr.Count(); i++) + delete bparr[i]; + } + + RTL_LOGFILE_CONTEXT(logFile, "BigPtrArray performance measures" ); +} + +class BigPtrArrayUnittest : public CppUnit::TestFixture +{ +public: + + BigPtrArrayUnittest() + { + } + + /** Test constructor/destructor + The size of the BigPtrArray + aka the 'Count' should be 0 + initially. + */ + void test_ctor() + { + printMethodName("test_ctor\n"); + + BigPtrArray bparr; + + CPPUNIT_ASSERT_MESSAGE + ( + "BigPtrArray ctor failed", + bparr.Count() == 0 + ); + } + + void test_insert_entries_at_front() + { + printMethodName("test_insert_entries_at_front\n"); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_at_front"); + + BigPtrArray bparr; + + for (int i = 0; i < NUM_ENTRIES; i++) + { + ULONG oldCount = bparr.Count(); + bparr.Insert(new BigPtrEntryMock(i), 0); + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_entries_at_front failed", + (bparr.Count() == oldCount + 1) + ) + } + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_at_front"); + + for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_entries_at_front failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_entries_at_front failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_insert_entries_in_the_middle() + { + printMethodName("test_insert_entries_in_the_middle\n"); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_entries_in_the_middle"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + ULONG oldCount = bparr.Count(); + + bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count() / 2); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_entries_in_the_middle"); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_entries_in_the_middle failed", + (oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount() == NUM_ENTRIES) + ) + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_entries_in_the_middle failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_insert_at_already_used_index() + { + printMethodName("test_insert_at_already_used_index\n"); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_insert_at_already_used_index"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + int oldCount = bparr.Count(); + + for (int i = 0, j = -5; i < 5; i++, j++) + bparr.Insert(new BigPtrEntryMock(j), i); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_insert_at_already_used_index"); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_at_already_used_index failed", + (oldCount + 5 == bparr.Count()) + ) + + for (int i = 0, j = -5; i < bparr.Count(); i++, j++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_at_already_used_index failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == j + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_at_already_used_index failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_insert_at_end() + { + printMethodName("test_insert_at_end\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + ULONG oldCount = bparr.Count(); + bparr.Insert(new BigPtrEntryMock(NUM_ENTRIES), bparr.Count()); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_at_end failed", + (oldCount + 1 == bparr.Count() && static_cast<BigPtrEntryMock*>(bparr[bparr.Count()-1])->getCount() == NUM_ENTRIES) + ) + + CPPUNIT_ASSERT_MESSAGE + ( + "test_insert_at_end failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_remove_at_front() + { + printMethodName("test_remove_at_front\n"); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_at_front"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + for (int i = 0; i < NUM_ENTRIES; i++) + { + ULONG oldCount = bparr.Count(); + + delete bparr[0]; // release content + bparr.Remove(0); // remove item from container + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_at_front failed (wrong count)", + (oldCount - 1 == bparr.Count()) + ) + + for (int j = 0, k = i + 1; j < bparr.Count(); j++, k++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_at_front failed", + static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == k + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_at_front failed", + checkElementPositions(bparr) + ) + + dumpBigPtrArray(bparr); + } + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_at_front"); + } + + void test_remove_at_back() + { + printMethodName("test_remove_at_back\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + for (int i = NUM_ENTRIES - 1; i >= 0; i--) + { + ULONG oldCount = bparr.Count(); + delete bparr[i]; + bparr.Remove(i); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_at_back failed (wrong count)", + (oldCount - 1 == bparr.Count()) + ) + + for (int j = 0; j < bparr.Count(); j++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_at_back failed", + static_cast<BigPtrEntryMock*>(bparr[j])->getCount() == j + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_at_back failed", + checkElementPositions(bparr) + ) + + dumpBigPtrArray(bparr); + } + } + + void test_remove_in_the_middle() + { + printMethodName("test_remove_in_the_middle\n"); + + RTL_LOGFILE_CONTEXT_TRACE(logFile, "START: test_remove_in_the_middle"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + while (bparr.Count()) + { + ULONG oldCount = bparr.Count(); + int oldElement = static_cast<BigPtrEntryMock*>(bparr[bparr.Count() / 2])->getCount(); + + delete bparr[bparr.Count() / 2]; + bparr.Remove(bparr.Count() / 2); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_in_the_middle failed (wrong count)", + (oldCount - 1 == bparr.Count()) + ) + + for (int i = 0; i < bparr.Count(); i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_in_the_middle failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() != oldElement + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_in_the_middle failed", + checkElementPositions(bparr) + ) + + dumpBigPtrArray(bparr); + } + RTL_LOGFILE_CONTEXT_TRACE(logFile, "END: test_remove_in_the_middle"); + } + + void test_remove_multiple_elements_at_once() + { + printMethodName("test_remove_multiple_elements_at_once\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + while(bparr.Count()) + { + ULONG nRemove = (bparr.Count() > 3) ? 3 : bparr.Count(); + ULONG oldCount = bparr.Count(); + + for (int i = 0; i < nRemove; i++) + delete bparr[i]; + + bparr.Remove(0, nRemove); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_multiple_elements_at_once failed", + (oldCount - nRemove == bparr.Count()) + ) + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_multiple_elements_at_once failed", + checkElementPositions(bparr) + ) + + dumpBigPtrArray(bparr); + } + } + + void test_remove_all_elements_at_once() + { + printMethodName("test_remove_all_elements_at_once\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + releaseBigPtrArrayContent(bparr); + bparr.Remove(0, bparr.Count()); + + CPPUNIT_ASSERT_MESSAGE + ( + "test_remove_all_elements_at_once failed", + bparr.Count() == 0 + ) + + dumpBigPtrArray(bparr); + } + + void test_move_elements_from_lower_to_higher_pos() + { + printMethodName("test_move_elements_from_lower_to_higher_pos\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + for (int i = 0; i < NUM_ENTRIES - 1; i++) + { + bparr.Move(i, i + 2); + dumpBigPtrArray(bparr); + } + + for (int i = 0; i < (NUM_ENTRIES - 1); i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_elements_from_lower_to_higher_pos failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i + 1) + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_elements_from_lower_to_higher_pos failed", + static_cast<BigPtrEntryMock*>(bparr[NUM_ENTRIES -1])->getCount() == 0 + ) + + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_elements_from_lower_to_higher_pos failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + } + + void test_move_elements_from_higher_to_lower_pos() + { + printMethodName("test_move_elements_from_higher_to_lower_pos\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + for (int i = NUM_ENTRIES - 1; i >= 1; i--) + { + bparr.Move(i, i - 1); + dumpBigPtrArray(bparr); + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_elements_from_higher_to_lower_pos failed", + static_cast<BigPtrEntryMock*>(bparr[0])->getCount() == (NUM_ENTRIES - 1) + ) + + for (int i = 1; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_elements_from_higher_to_lower_pos failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i - 1) + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_elements_from_higher_to_lower_pos failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + } + + void test_move_to_same_position() + { + printMethodName("test_move_to_same_position\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + for (int i = 0; i < NUM_ENTRIES; i++) + { + bparr.Move(i, i); + } + + dumpBigPtrArray(bparr); + + for (int i = 0; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_to_same_position failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_move_to_same_position failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_replace_elements() + { + printMethodName("test_replace_elements\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + for (int i = 0, j = NUM_ENTRIES - 1; i < NUM_ENTRIES; i++, j--) + { + delete bparr[i]; + bparr.Replace(i, new BigPtrEntryMock(j)); + dumpBigPtrArray(bparr); + } + + for (int i = 0; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_replace_elements failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (NUM_ENTRIES - i - 1) + ) + } + + CPPUNIT_ASSERT_MESSAGE + ( + "test_replace_elements failed", + checkElementPositions(bparr) + ) + + releaseBigPtrArrayContent(bparr); + } + + void test_for_each() + { + printMethodName("test_for_each\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + int addCount = 1; + bparr.ForEach(AddToCount, &addCount); + + for (int i = 0; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_for_each failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1) + ) + } + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_for_some1() + { + printMethodName("test_for_some1\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + int addCount = 1; + bparr.ForEach(0, NUM_ENTRIES / 2, AddToCount, &addCount); + + int i = 0; + for (/* */; i < NUM_ENTRIES / 2; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_for_some1 failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1) + ) + } + + for (/* */; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_for_some1 failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i) + ) + } + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_for_some2() + { + printMethodName("test_for_some2\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + int addCount = 1; + bparr.ForEach(NUM_ENTRIES / 2, NUM_ENTRIES, AddToCount, &addCount); + + int i = 0; + for (/* */; i < NUM_ENTRIES / 2; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_for_some2 failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i) + ) + } + + for (/* */; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_for_some2 failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == (i+1) + ) + } + + releaseBigPtrArrayContent(bparr); + dumpBigPtrArray(bparr); + } + + void test_for_some3() + { + printMethodName("test_for_some3\n"); + + BigPtrArray bparr; + + fillBigPtrArray(bparr, NUM_ENTRIES); + dumpBigPtrArray(bparr); + + int addCount = 1; + bparr.ForEach(0, 0, AddToCount, &addCount); + + for (int i = 0; i < NUM_ENTRIES; i++) + { + CPPUNIT_ASSERT_MESSAGE + ( + "test_for_some3 failed", + static_cast<BigPtrEntryMock*>(bparr[i])->getCount() == i + ) + } + releaseBigPtrArrayContent(bparr); + } + + CPPUNIT_TEST_SUITE(BigPtrArrayUnittest); + CPPUNIT_TEST(test_ctor); + CPPUNIT_TEST(test_insert_entries_at_front); + CPPUNIT_TEST(test_insert_entries_in_the_middle); + CPPUNIT_TEST(test_insert_at_already_used_index); + CPPUNIT_TEST(test_insert_at_end); + CPPUNIT_TEST(test_remove_at_front); + CPPUNIT_TEST(test_remove_at_back); + CPPUNIT_TEST(test_remove_in_the_middle); + CPPUNIT_TEST(test_remove_multiple_elements_at_once); + CPPUNIT_TEST(test_remove_all_elements_at_once); + CPPUNIT_TEST(test_move_elements_from_lower_to_higher_pos); + CPPUNIT_TEST(test_move_elements_from_higher_to_lower_pos); + CPPUNIT_TEST(test_replace_elements); + CPPUNIT_TEST(test_for_each); + CPPUNIT_TEST(test_for_some1); + CPPUNIT_TEST(test_for_some2); + CPPUNIT_TEST(test_for_some3); + CPPUNIT_TEST_SUITE_END(); +}; + +const char* START = "START: "; +const char* END = "END: "; + +class PerformanceTracer +{ +public: + +public: + PerformanceTracer(const string& methodName) : + startString_(START), + endString_(END) + { + startString_ += methodName; + endString_ += methodName; + RTL_LOGFILE_CONTEXT_TRACE(logFile, startString_.c_str()); + } + + ~PerformanceTracer() + { + RTL_LOGFILE_CONTEXT_TRACE(logFile, endString_.c_str()); + } + +private: + string startString_; + string endString_; +}; + +class BigPtrArrayPerformanceTest : public CppUnit::TestFixture +{ +public: + BigPtrArrayPerformanceTest() + { + } + + void test_insert_at_end_1000() + { test_insert_at_end("1000"); } + + void test_insert_at_end_10000() + { test_insert_at_end("10000"); } + + void test_insert_at_end_100000() + { test_insert_at_end("100000"); } + + void test_insert_at_end_1000000() + { test_insert_at_end("1000000"); } + + void test_insert_at_front_1000() + { test_insert_at_front("1000"); } + + void test_insert_at_front_10000() + { test_insert_at_front("10000"); } + + void test_insert_at_front_100000() + { test_insert_at_front("100000"); } + + void test_insert_at_front_1000000() + { test_insert_at_front("1000000"); } + + CPPUNIT_TEST_SUITE(BigPtrArrayPerformanceTest); + CPPUNIT_TEST(test_insert_at_end_1000); + CPPUNIT_TEST(test_insert_at_end_10000); + CPPUNIT_TEST(test_insert_at_end_100000); + CPPUNIT_TEST(test_insert_at_end_1000000); + CPPUNIT_TEST(test_insert_at_front_1000); + CPPUNIT_TEST(test_insert_at_front_10000); + CPPUNIT_TEST(test_insert_at_front_100000); + CPPUNIT_TEST(test_insert_at_front_1000000); + CPPUNIT_TEST_SUITE_END(); + +private: + void test_insert_at_end(const char* numElements) + { + char buff[100] = { 0 }; + strcat(buff, "test_insert_at_end "); + strcat(buff, numElements); + int n = atoi(numElements); + PerformanceTracer tracer(buff); + BigPtrArray bparr; + for (int i = 0; i < n; i++) + bparr.Insert(new BigPtrEntryMock(i), bparr.Count()); + + releaseBigPtrArrayContent(bparr); + } + + void test_insert_at_front(const char* numElements) + { + char buff[100] = { 0 }; + strcat(buff, "test_insert_at_front "); + strcat(buff, numElements); + int n = atoi(numElements); + PerformanceTracer tracer(buff); + BigPtrArray bparr; + for (int i = 0; i < n; i++) + bparr.Insert(new BigPtrEntryMock(i), 0); + + releaseBigPtrArrayContent(bparr); + } +}; + + +//##################################### +// register test suites +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BigPtrArrayUnittest, "BigPtrArrayUnittest"); +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BigPtrArrayPerformanceTest, "BigPtrArrayPerformanceTest"); + +NOADDITIONAL; + diff --git a/sw/qa/core/bigpointerarray-new.cxx b/sw/qa/core/bigpointerarray-new.cxx new file mode 100644 index 000000000000..28501f4c3f4a --- /dev/null +++ b/sw/qa/core/bigpointerarray-new.cxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_sw.hxx" + +#include "bparr.hxx" +#include <algorithm> + +BigPtrArray::BigPtrArray() +{ + //container_.reserve(1000); +} + +ULONG BigPtrArray::Count() const +{ + return container_.size(); +} + +void BigPtrArray::Move(ULONG fromPos, ULONG toPos) +{ + DBG_ASSERT(fromPos < container_.size() && toPos < container_.size(), "BigPtrArray.Move precondition violation"); + Insert(container_[fromPos], toPos); + Remove(toPos < fromPos ? fromPos + 1 : fromPos, 1); +} + +void BigPtrArray::ForEach(ULONG fromPos, ULONG toPos, FnForEach fn, void* pArgs) +{ + DBG_ASSERT(fromPos < toPos && fromPos < container_.size() && toPos < container_.size(), "BigPtrArray::ForEach precondition violation"); + Container_t::const_iterator iter = container_.begin() + fromPos; + Container_t::const_iterator iter_end = container_.begin() + toPos; + for (/*no init*/; iter != iter_end; ++iter) + fn(*iter, pArgs); +} + +void BigPtrArray::ForEach(FnForEach fn, void* pArgs) +{ + Container_t::const_iterator iter = container_.begin(); + Container_t::const_iterator iter_end = container_.end(); + for ( /*no init*/; iter != iter_end; ++iter) + fn(*iter, pArgs); +} + +ElementPtr BigPtrArray::operator[](ULONG pos) const +{ + DBG_ASSERT(pos < container_.size(), "BigPtrArray::operator[] precondition violation"); + return container_[pos]; +} + +void BigPtrArray::Insert(const ElementPtr& rElem, ULONG pos) +{ + DBG_ASSERT(pos <= container_.size(), "BigPtrArray::Insert precondition violation"); + + rElem->pBigPtrArray_ = this; + rElem->pos_ = pos; + + if (pos == container_.size()) + container_.push_back(rElem); + else + { + container_.insert(container_.begin() + pos, rElem); + FixElementIndizes(container_.begin(), container_.end()); + } +} + +void BigPtrArray::Remove( ULONG pos, ULONG n ) +{ + DBG_ASSERT((pos < container_.size()) && ((container_.begin() + pos + n) < container_.end()), "BigPtrArray.Remove precondition violation") + container_.erase(container_.begin() + pos, container_.begin() + pos + n); + FixElementIndizes(container_.begin(), container_.end()); +} + +void BigPtrArray::Replace(ULONG pos, const ElementPtr& rElem) +{ + DBG_ASSERT(pos < container_.size(), "BigPtrArray::Replace precondition violation"); + rElem->pBigPtrArray_ = this; + rElem->pos_ = pos; + container_[pos] = rElem; +} + +void BigPtrArray::FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const +{ + Container_t::const_iterator iter = begin; + for (int i = 0; iter != end; ++iter, i++) + (*iter)->pos_ = i; +} diff --git a/sw/qa/core/bigpointerarray-new.hxx b/sw/qa/core/bigpointerarray-new.hxx new file mode 100644 index 000000000000..9e639ad96f16 --- /dev/null +++ b/sw/qa/core/bigpointerarray-new.hxx @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef _BPARR_HXX +#define _BPARR_HXX + +#include <tools/solar.h> +#include <tools/debug.hxx> + +#include <deque> + +class BigPtrArray; + +/** Base class for container entries +*/ +class BigPtrEntry +{ + friend class BigPtrArray; + BigPtrArray* pBigPtrArray_; + ULONG pos_; + +protected: + BigPtrEntry() : pBigPtrArray_(0), pos_(0) + {} + + virtual ~BigPtrEntry() + {} + + ULONG GetPos() const + { + return pos_; + } + + BigPtrArray& GetArray() const + { + return *pBigPtrArray_; + } +}; + +typedef BigPtrEntry* ElementPtr; +typedef BOOL (*FnForEach)(const ElementPtr&, void* pArgs); + +/** A container abstraction +*/ +class BigPtrArray +{ +public: + typedef std::deque<ElementPtr> Container_t; + +public: + /** + */ + BigPtrArray(); + + /** Return the number of entries inserted + into the array + */ + ULONG Count() const; + + /** Insert an Element into the array at a certain + position + + @param rElem + [in] the element + + @param pos + [in] the position where to insert the element. + + @pre (pos >= 0 && pos <= BigPtrArray.Count()) + @post (((oldCount + 1) == BigPtrArray.Count()) && BigPtrArray[pos] == rElem) + */ + void Insert(const ElementPtr& rElem, ULONG pos); + + /** Remove a specified number of elements starting at a certain position. + + @param pos + [in] the position where to start removing elements + + @param n + [in] the number of elements to remove + + @pre (pos < BigPtrArray.Count() && n <= BigPtrArray.Count()) + @post ((oldCount - n) == BigPtrArray.Count()) + */ + void Remove(ULONG pos, ULONG n = 1); + + /** Move an entry from a certain position to another on. + + @param from + [in] + + @param to + [in] + */ + void Move(ULONG fromPos, ULONG toPos); + + /** Replace an entry at a certain position + + @param pos + [in] the position of the entry + + @param rElem + [in] the new entry + + @pre pos < BigPtrArray.Count() + @post (oldCount == BigPtrArray.Count() && BigPtrArray[pos] == rElem) + */ + void Replace(ULONG pos, const ElementPtr& rElem); + + /** Get the entry at a certain index + + @param pos + [in] the position of the entry + + @pre pos < BigPtrArray.Count() + */ + ElementPtr operator[](ULONG pos) const; + + /** + */ + void ForEach(FnForEach fn, void* pArgs = NULL); + + /** + */ + void ForEach(ULONG fromPos, ULONG toPos, FnForEach fn, void* pArgs = NULL); + +private: + + void FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const; + +private: + Container_t container_; +}; + +#endif diff --git a/sw/qa/core/export.exp b/sw/qa/core/export.exp new file mode 100644 index 000000000000..a13529da5876 --- /dev/null +++ b/sw/qa/core/export.exp @@ -0,0 +1 @@ +registerAllTestFunction diff --git a/sw/qa/core/export.map b/sw/qa/core/export.map new file mode 100644 index 000000000000..7321bbca16ad --- /dev/null +++ b/sw/qa/core/export.map @@ -0,0 +1,34 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3_0_0 { + global: + registerAllTestFunction; + + local: + *; +}; diff --git a/sw/qa/core/makefile.mk b/sw/qa/core/makefile.mk new file mode 100644 index 000000000000..00ebfda8844a --- /dev/null +++ b/sw/qa/core/makefile.mk @@ -0,0 +1,69 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* +PRJ=..$/.. + +PRJNAME=sw +TARGET=test-bigptrarray +# this is removed at the moment because we need some enhancements +# TESTDIR=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +CFLAGSCXX += $(CPPUNIT_CFLAGS) + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:testjob by codegen.pl + +.IF "$(GUI)" == "WNT" + CFLAGS+=/Ob1 +.ENDIF + +SHL1OBJS=$(SLO)$/Test-BigPtrArray.obj \ + $(SLO)$/bparr.obj + +SHL1TARGET=$(TARGET) +SHL1STDLIBS=$(SALLIB) $(TOOLSLIB) $(CPPUNITLIB) $(TESTSHL2LIB) + +SHL1IMPLIB= i$(SHL1TARGET) + +# SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +DEF1NAME =$(SHL1TARGET) + +# DEF1EXPORTFILE= export.exp +SHL1VERSIONMAP = export.map + +# END ------------------------------------------------------------------ + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk diff --git a/sw/qa/core/performance-jobfile b/sw/qa/core/performance-jobfile new file mode 100644 index 000000000000..9e33d3c858ba --- /dev/null +++ b/sw/qa/core/performance-jobfile @@ -0,0 +1,9 @@ +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_end_1000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_end_10000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_end_100000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_end_1000000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_front_1000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_front_10000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_front_100000 +BigPtrArrayPerformanceTest.BigPtrArrayPerformanceTest.test_insert_at_front_1000000 + diff --git a/sw/qa/unoapi/Test.java b/sw/qa/unoapi/Test.java new file mode 100644 index 000000000000..e0311cc069bb --- /dev/null +++ b/sw/qa/unoapi/Test.java @@ -0,0 +1,51 @@ +/************************************************************************* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +************************************************************************/ + +package org.openoffice.sw.qa.unoapi; + +import org.openoffice.Runner; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; + +public final class Test { + @org.junit.Before public void setUp() throws Exception { + connection.setUp(); + } + + @org.junit.After public void tearDown() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + @org.junit.Test public void test() { + assertTrue( + Runner.run( + "-sce", "sw.sce", "-xcl", "knownissues.xcl", "-tdoc", + "testdocuments", "-cs", connection.getDescription())); + } + + private final OfficeConnection connection = new OfficeConnection(); +} diff --git a/sw/qa/unoapi/knownissues.xcl b/sw/qa/unoapi/knownissues.xcl new file mode 100644 index 000000000000..08e441211cf7 --- /dev/null +++ b/sw/qa/unoapi/knownissues.xcl @@ -0,0 +1,175 @@ +### i85576 ### +sw.SwXCellRange::com::sun::star::text::CellRange + +### i21166 ### +sw.SwXCell::com::sun::star::text::CellProperties +sw.SwXCell::com::sun::star::beans::XPropertySet + +### i59143 ### +sw.SwXTableColumns::com::sun::star::table::XTableColumns + +### i85580 ### +sw.SwXTextView::com::sun::star::view::XSelectionSupplier +#-> disabled in sw.scw + +### i23394 ### +sw.XMLContentImporter::com::sun::star::xml::sax::XDocumentHandler +sw.XMLMetaImporter::com::sun::star::xml::sax::XDocumentHandler +sw.XMLStylesImporter::com::sun::star::xml::sax::XDocumentHandler +# -> disables in sw.sce + +### i23422 ### +sw.SwXTextViewCursor::com::sun::star::beans::XMultiPropertyStates + +### i112111 ### +sw.SwXViewSettings::com::sun::star::beans::XPropertySet + +### i23623 ### +sw.SwXStyleFamily::com::sun::star::container::XNameReplace + +### i85583 ### +sw.PageStyle::com::sun::star::style::PageProperties + +### i25408 ### +sw.PageStyle::com::sun::star::style::XStyle + +### i85584 ### +sw.CharacterStyle::com::sun::star::style::CharacterPropertiesAsian + +### i25473 ### +sw.ConditionalParagraphStyle::com::sun::star::beans::XMultiPropertyStates +sw.ParagraphStyle::com::sun::star::beans::XMultiPropertyStates + +### i34456 ### +sw.SwXTextDocument::com::sun::star::view::XPrintJobBroadcaster + +### i37272 ### +sw.SwXDrawPage::com::sun::star::drawing::XShapeGrouper + +### i38584 ### +sw.SwXParagraph::com::sun::star::beans::XPropertySet +sw.SwXTextPortion::com::sun::star::beans::XPropertySet +sw.SwXTextRange::com::sun::star::beans::XPropertySet +sw.SwXTextViewCursor::com::sun::star::beans::XPropertySet +sw.SwXTextCursor::com::sun::star::beans::XPropertySet + +### i85585 ### +sw.SwXTextSection::com::sun::star::text::TextSection + +### i85586 ### +sw.SwAccessibleDocumentView::com::sun::star::accessibility::XAccessibleEventBroadcaster + +### i58374 ### +sw.DocumentSettings::com::sun::star::document::Settings + +### i85586 ### +sw.SwXAutoTextGroup::com::sun::star::container::XElementAccess + +### i72029 ### +sw.SwXChapterNumbering::com::sun::star::text::NumberingRules + +### i38586 ### +sw.SwXParagraph::com::sun::star::style::ParagraphProperties +sw.SwXTextCursor::com::sun::star::style::ParagraphProperties +sw.SwXTextPortion::com::sun::star::style::ParagraphProperties +sw.SwXTextRange::com::sun::star::style::ParagraphProperties +sw.SwXTextViewCursor::com::sun::star::style::ParagraphProperties +sw.ConditionalParagraphStyle::com::sun::star::style::ParagraphProperties +sw.ParagraphStyle::com::sun::star::style::ParagraphProperties +sw.SwXCellRange::com::sun::star::style::ParagraphProperties +sw.SwXTextDefaults::com::sun::star::style::ParagraphProperties +sw.SwXTextTableCursor::com::sun::star::style::ParagraphProperties + +### i85575 ### +sw.SwXParagraph::com::sun::star::style::CharacterProperties +sw.SwXTextCursor::com::sun::star::style::CharacterProperties + +### i77882 ### +sw.SwXTextCursor::com::sun::star::document::XDocumentInsertable + +### i85595 ### +sw.ParagraphStyle::com::sun::star::beans::XMultiPropertySet +sw.ParagraphStyle::com::sun::star::beans::XPropertySet + +### i85596 ### +sw.SwXFieldMaster::com::sun::star::text::TextFieldMaster + +### i85634 ### +sw.SwAccessibleTableView +# -> disabled in sw.sce + +### i85635 ### +sw.DocumentSettings::com::sun::star::text::PrintPreviewSettings + +### i85638 ### +sw.SwXTextDocument::com::sun::star::frame::XStorable + +### i85640 ### +sw.SwXMailMerge +#-> disabled in sw.sce + +### i86656 ### +sw.SwAccessibleDocumentView::com::sun::star::accessibility::XAccessibleComponent + +### i86751 ### +sw.SwAccessibleDocumentPageView::com::sun::star::accessibility::XAccessibleEventBroadcaster +#-> disabled in sw.sce + +### i87978 ### +sw.DocumentSettings::com::sun::star::beans::XPropertySet +sw.ConditionalParagraphStyle::com::sun::star::beans::XPropertySet + +### i88242 ### +sw.SwXTextDocument::com::sun::star::view::XPrintable +sw.SwXTextDocument::com::sun::star::text::XPagePrintable + +### i88257 ### +sw.SwAccessibleTextGraphicObject::com::sun::star::accessibility::XAccessibleImage + +### i88262 ### +sw.SwXTextFrame::com::sun::star::text::BaseFrameProperties + +### i88374 ### +sw.SwXTextTable::com::sun::star::table::XAutoFormattable + +### i88310 ### +sw.SwAccessibleTextGraphicObject::com::sun::star::accessibility::XAccessibleComponent + +### i88606 ### +sw.SwAccessibleTextGraphicObject::com::sun::star::accessibility::XAccessibleContext + +### i89021 ### +sw.SwXTextDefaults +#-> disabled in sw.sce + +### i89022 ### +sw.SwAccessiblePageView +#-> disabled in sw.sce + +### i89419 ### +sw.SwXTextEmbeddedObject::com::sun::star::text::BaseFrameProperties + +### i91530 ### +sw.SwXTextPortion::com::sun::star::style::CharacterProperties + +### i94977 ### +sw.SwXTextGraphicObject::com::sun::star::text::BaseFrameProperties + +### i109917 ### +sw.SwXTextDocument::com::sun::star::document::XEventBroadcaster + +### i111186 ### +sw.PageStyle::com::sun::star::beans::XPropertySet + +### i111218 ### +sw.SwAccessibleParagraphView::com::sun::star::accessibility::XAccessibleEventBroadcaster + +### i111220 ### +sw.XMLContentExporter::com::sun::star::document::XFilter +sw.XMLSettingsExporter::com::sun::star::document::XFilter + +### i111273 ### +sw.SwXTextEmbeddedObject::com::sun::star::document::XEmbeddedObjectSupplier + +### i111332 ### +sw.XMLStylesExporter::com::sun::star::document::XFilter diff --git a/sw/qa/unoapi/lastCheck.txt b/sw/qa/unoapi/lastCheck.txt new file mode 100644 index 000000000000..b222cd4719d7 --- /dev/null +++ b/sw/qa/unoapi/lastCheck.txt @@ -0,0 +1 @@ +sw: checked with cws_tleamisc that is based on src680_m47 diff --git a/sw/qa/unoapi/makefile.mk b/sw/qa/unoapi/makefile.mk new file mode 100644 index 000000000000..f5102c2c9c84 --- /dev/null +++ b/sw/qa/unoapi/makefile.mk @@ -0,0 +1,48 @@ +#************************************************************************* +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +#***********************************************************************/ + +.IF "$(OOO_SUBSEQUENT_TESTS)" == "" +nothing .PHONY: +.ELSE + +PRJ = ../.. +PRJNAME = sw +TARGET = qa_unoapi + +.IF "$(OOO_JUNIT_JAR)" != "" +PACKAGE = org/openoffice/sw/qa/unoapi +JAVATESTFILES = Test.java +JAVAFILES = $(JAVATESTFILES) +JARFILES = OOoRunner.jar ridl.jar test.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) +.END + +.INCLUDE: settings.mk +.INCLUDE: target.mk +.INCLUDE: installationtest.mk + +ALLTAR : javatest + +.END diff --git a/sw/qa/unoapi/sw.sce b/sw/qa/unoapi/sw.sce new file mode 100644 index 000000000000..0f1092af8a51 --- /dev/null +++ b/sw/qa/unoapi/sw.sce @@ -0,0 +1,94 @@ +-o sw.CharacterStyle +-o sw.ConditionalParagraphStyle +-o sw.PageStyle +-o sw.ParagraphStyle +#i111197 -o sw.SwAccessibleDocumentPageView +#i86751 -o sw.SwAccessibleDocumentView +-o sw.SwAccessibleEndnoteView +-o sw.SwAccessibleFooterView +-o sw.SwAccessibleFootnoteView +-o sw.SwAccessibleHeaderView +#i89022 -o sw.SwAccessiblePageView +-o sw.SwAccessibleParagraphView +-o sw.SwAccessibleTableCellView +#i85634 -o sw.SwAccessibleTableView +#i111178 -o sw.SwAccessibleTextEmbeddedObject +#i111178 -o sw.SwAccessibleTextFrameView +-o sw.SwAccessibleTextGraphicObject +-o sw.SwXAutoTextContainer +-o sw.SwXAutoTextEntry +-o sw.SwXAutoTextGroup +-o sw.SwXBodyText +-o sw.SwXBookmark +-o sw.SwXBookmarks +-o sw.SwXCell +-o sw.SwXCellRange +-o sw.SwXChapterNumbering +-o sw.SwXDocumentIndex +-o sw.SwXDocumentIndexMark +-o sw.SwXDocumentIndexes +-o sw.SwXDrawPage +-o sw.SwXEndnoteProperties +-o sw.SwXFieldEnumeration +-o sw.SwXFieldMaster +-o sw.SwXFootnote +-o sw.SwXFootnoteProperties +-o sw.SwXFootnoteText +-o sw.SwXFootnotes +-o sw.SwXFrames +-o sw.SwXHeadFootText +-o sw.SwXLineNumberingProperties +#i85640 -o sw.SwXMailMerge +-o sw.SwXModule +-o sw.SwXNumberingRules +#i103696 -o sw.SwXParagraph +-o sw.SwXParagraphEnumeration +-o sw.SwXPrintSettings +-o sw.SwXPropertySet +-o sw.SwXPropertySetInfo +-o sw.SwXReferenceMark +-o sw.SwXReferenceMarks +#i111190 -o sw.SwXShape +-o sw.SwXStyleFamilies +-o sw.SwXStyleFamily +-o sw.SwXTableCellText +-o sw.SwXTableColumns +-o sw.SwXTableRows +-o sw.SwXTextColumns +-o sw.SwXTextCursor +#i89021 -o sw.SwXTextDefaults +-o sw.SwXTextDocument +-o sw.SwXTextEmbeddedObject +-o sw.SwXTextEmbeddedObjects +-o sw.SwXTextField +-o sw.SwXTextFieldMasters +-o sw.SwXTextFieldTypes +-o sw.SwXTextFrame +-o sw.SwXTextFrameText +-o sw.SwXTextGraphicObject +-o sw.SwXTextGraphicObjects +#i103696 -o sw.SwXTextPortion +-o sw.SwXTextPortionEnumeration +-o sw.SwXTextRange +-o sw.SwXTextRanges +-o sw.SwXTextSearch +-o sw.SwXTextSection +-o sw.SwXTextSections +-o sw.SwXTextTable +-o sw.SwXTextTableCursor +-o sw.SwXTextTableRow +-o sw.SwXTextTables +#i85580 -o sw.SwXTextView +-o sw.SwXTextViewCursor +-o sw.SwXViewSettings +-o sw.XMLContentExporter +#i23394 -o sw.XMLContentImporter +#i111194-o sw.XMLExporter +-o sw.XMLImporter +#i23394 -o sw.XMLMetaExporter +-o sw.XMLMetaImporter +-o sw.XMLSettingsExporter +-o sw.XMLSettingsImporter +-o sw.XMLStylesExporter +#i23394 -o sw.XMLStylesImporter +-o sw.DocumentSettings diff --git a/sw/qa/unoapi/testdocuments/MailMerge.sxw b/sw/qa/unoapi/testdocuments/MailMerge.sxw Binary files differnew file mode 100644 index 000000000000..108840535093 --- /dev/null +++ b/sw/qa/unoapi/testdocuments/MailMerge.sxw diff --git a/sw/qa/unoapi/testdocuments/SwXTextEmbeddedObject.sdw b/sw/qa/unoapi/testdocuments/SwXTextEmbeddedObject.sdw Binary files differnew file mode 100644 index 000000000000..4f5c2e39c030 --- /dev/null +++ b/sw/qa/unoapi/testdocuments/SwXTextEmbeddedObject.sdw diff --git a/sw/qa/unoapi/testdocuments/SwXTextEmbeddedObject.sxw b/sw/qa/unoapi/testdocuments/SwXTextEmbeddedObject.sxw Binary files differnew file mode 100644 index 000000000000..75c6242f5070 --- /dev/null +++ b/sw/qa/unoapi/testdocuments/SwXTextEmbeddedObject.sxw diff --git a/sw/qa/unoapi/testdocuments/XDocumentInsertable.sxw b/sw/qa/unoapi/testdocuments/XDocumentInsertable.sxw Binary files differnew file mode 100644 index 000000000000..b1398769d7ac --- /dev/null +++ b/sw/qa/unoapi/testdocuments/XDocumentInsertable.sxw diff --git a/sw/qa/unoapi/testdocuments/sForm.sxw b/sw/qa/unoapi/testdocuments/sForm.sxw Binary files differnew file mode 100644 index 000000000000..a4958930c348 --- /dev/null +++ b/sw/qa/unoapi/testdocuments/sForm.sxw |