diff options
author | sb <sb@openoffice.org> | 2010-05-07 11:03:36 +0200 |
---|---|---|
committer | sb <sb@openoffice.org> | 2010-05-07 11:03:36 +0200 |
commit | 1f9abbd13e98b50a03813b643477d7aed96b5a3e (patch) | |
tree | 6202a44decab24ce6330d4e66ae2f7e7adac2d45 /sw/qa/complex/writer | |
parent | 8eacb235792032735ac6ee805d0919812599f1b3 (diff) |
sb123: #i111449# adapted sw/qa/complex to new framework
Diffstat (limited to 'sw/qa/complex/writer')
-rw-r--r-- | sw/qa/complex/writer/CheckBookmarks.java | 125 | ||||
-rw-r--r-- | sw/qa/complex/writer/CheckCrossReferences.java | 332 | ||||
-rw-r--r-- | sw/qa/complex/writer/CheckFlies.java | 218 | ||||
-rwxr-xr-x | sw/qa/complex/writer/CheckIndexedPropertyValues.java | 182 | ||||
-rwxr-xr-x | sw/qa/complex/writer/CheckNamedPropertyValues.java | 198 | ||||
-rw-r--r-- | sw/qa/complex/writer/TestDocument.java | 41 | ||||
-rwxr-xr-x | sw/qa/complex/writer/TextPortionEnumerationTest.java | 547 | ||||
-rwxr-xr-x | sw/qa/complex/writer/makefile.mk | 100 |
8 files changed, 695 insertions, 1048 deletions
diff --git a/sw/qa/complex/writer/CheckBookmarks.java b/sw/qa/complex/writer/CheckBookmarks.java index 0915db42e6ac..f1167b09a18e 100644 --- a/sw/qa/complex/writer/CheckBookmarks.java +++ b/sw/qa/complex/writer/CheckBookmarks.java @@ -43,9 +43,15 @@ import com.sun.star.text.XTextRange; import com.sun.star.uno.UnoRuntime; import complexlib.ComplexTestCase; import java.math.BigInteger; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; class BookmarkHashes { - public String m_sName; public BigInteger m_nSetupHash; public BigInteger m_nInsertRandomHash; public BigInteger m_nDeleteRandomHash; @@ -53,40 +59,13 @@ class BookmarkHashes { 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(); + public void assertExpectation(BookmarkHashes aExpectation) { + assertEquals(aExpectation.m_nSetupHash, m_nSetupHash); + assertEquals(aExpectation.m_nInsertRandomHash, m_nInsertRandomHash); + assertEquals(aExpectation.m_nDeleteRandomHash, m_nDeleteRandomHash); + assertEquals(aExpectation.m_nLinebreakHash, m_nLinebreakHash); + assertEquals(aExpectation.m_nOdfReloadHash, m_nOdfReloadHash); + assertEquals(aExpectation.m_nMsWordReloadHash, m_nMsWordReloadHash); } static public java.math.BigInteger getBookmarksHash(XTextDocument xDoc) @@ -114,18 +93,15 @@ class BookmarkHashes { } } -public class CheckBookmarks extends ComplexTestCase { +public class CheckBookmarks { 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 final BookmarkHashes actualHashes = new BookmarkHashes(); private BookmarkHashes getDEV300m41Expectations() { - BookmarkHashes result = new BookmarkHashes("DEV300m41"); + BookmarkHashes result = new BookmarkHashes(); result.m_nSetupHash = new BigInteger("-4b0706744e8452fe1ae9d5e1c28cf70fb6194795",16); result.m_nInsertRandomHash = new BigInteger("25aa0fad3f4881832dcdfe658ec2efa8a1a02bc5",16); result.m_nDeleteRandomHash = new BigInteger("-3ec87e810b46d734677c351ad893bbbf9ea10f55",16); @@ -135,42 +111,49 @@ public class CheckBookmarks extends ComplexTestCase { return result; } - public void checkBookmarks() + @Test 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); - } + actualHashes.assertExpectation(getDEV300m41Expectations()); } + @Before public void setUpDocuments() throws Exception { + m_xMsf = connection.getFactory(); + m_xDoc = util.WriterTools.createTextDoc(m_xMsf); + 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); + } + + @After public void tearDownDocuments() { + util.DesktopTools.closeDoc(m_xDoc); + util.DesktopTools.closeDoc(m_xOdfReloadedDoc); + util.DesktopTools.closeDoc(m_xMsWordReloadedDoc); + } + + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); + private void setupBookmarks() throws com.sun.star.uno.Exception { diff --git a/sw/qa/complex/writer/CheckCrossReferences.java b/sw/qa/complex/writer/CheckCrossReferences.java index 7b469c0a4afc..720b3a4b7600 100644 --- a/sw/qa/complex/writer/CheckCrossReferences.java +++ b/sw/qa/complex/writer/CheckCrossReferences.java @@ -1,123 +1,96 @@ -/* - * 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. - */ +/************************************************************************* +* +* 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.text.XTextDocument; import com.sun.star.uno.UnoRuntime; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; /** * * @author od138299 */ -public class CheckCrossReferences extends ComplexTestCase { +public class CheckCrossReferences { - 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; + public com.sun.star.text.XTextField getNextField() + throws com.sun.star.uno.Exception + { 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; - } + 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") ) { + com.sun.star.text.XTextField xField = (com.sun.star.text.XTextField)UnoRuntime.queryInterface( + com.sun.star.text.XTextField.class, + xPortionProps.getPropertyValue( "TextField" ) ); + assertNotNull("Cannot retrieve next field.", xField); + 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; - } + 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") ) { + com.sun.star.text.XTextField xField = (com.sun.star.text.XTextField)UnoRuntime.queryInterface( + com.sun.star.text.XTextField.class, + xPortionProps.getPropertyValue( "TextField" ) ); + assertNotNull("Cannot retrieve next field.", xField); + 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; + fail("Cannot retrieve next field."); + return null; // unreachable } public com.sun.star.beans.XPropertySet getFieldProps( @@ -126,11 +99,7 @@ public class CheckCrossReferences extends ComplexTestCase { (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; - } + assertNotNull("Cannot retrieve field properties.", xProps); return xProps; } @@ -138,56 +107,26 @@ public class CheckCrossReferences extends ComplexTestCase { public void checkField( com.sun.star.text.XTextField xField, com.sun.star.beans.XPropertySet xProps, short nFormat, - String aExpectedFldResult ) { + String aExpectedFldResult ) + throws com.sun.star.uno.Exception + { // 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; - } + xProps.setPropertyValue("ReferenceFieldPart", new Short(nFormat)); + // 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 ); + assertEquals( "set reference field format doesn't result in correct field result", + aExpectedFldResult, aFldResult); } - 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; - } - + @Test public void checkCrossReferences() throws com.sun.star.uno.Exception { // setup paragraph enumeration { com.sun.star.container.XEnumerationAccess xParaEnumAccess = (com.sun.star.container.XEnumerationAccess)UnoRuntime.queryInterface( - com.sun.star.container.XEnumerationAccess.class, xDoc.getText()); + com.sun.star.container.XEnumerationAccess.class, document.getText()); xParaEnum = xParaEnumAccess.createEnumeration(); } @@ -195,7 +134,7 @@ public class CheckCrossReferences extends ComplexTestCase { { com.sun.star.text.XTextFieldsSupplier xFieldSupp = (com.sun.star.text.XTextFieldsSupplier)UnoRuntime.queryInterface( - com.sun.star.text.XTextFieldsSupplier.class, xDoc); + com.sun.star.text.XTextFieldsSupplier.class, document); xFldsRefresh = (com.sun.star.util.XRefreshable)UnoRuntime.queryInterface( com.sun.star.util.XRefreshable.class, xFieldSupp.getTextFields()); } @@ -214,7 +153,6 @@ public class CheckCrossReferences extends ComplexTestCase { 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 ); @@ -254,63 +192,36 @@ public class CheckCrossReferences extends ComplexTestCase { // 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()); + com.sun.star.container.XEnumerationAccess.class, document.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; + 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; } } - if ( xParaTextRange == null ) { - System.out.println("Cannot find paragraph to insert cross-reference bookmark."); - failed("Cannot find paragraph to insert cross-reference bookmark."); - return; - } + assertNotNull( + "Cannot find paragraph to insert cross-reference bookmark.", + xParaTextRange); // insert bookmark XMultiServiceFactory xFac = (XMultiServiceFactory)UnoRuntime.queryInterface( - XMultiServiceFactory.class, xDoc); + XMultiServiceFactory.class, document); 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; - } + com.sun.star.text.XTextContent xBookmark = + (com.sun.star.text.XTextContent)UnoRuntime.queryInterface( + com.sun.star.text.XTextContent.class, + xFac.createInstance( "com.sun.star.text.Bookmark" ) ); if ( xBookmark != null ) { com.sun.star.container.XNamed xName = (com.sun.star.container.XNamed)UnoRuntime.queryInterface( @@ -320,22 +231,10 @@ public class CheckCrossReferences extends ComplexTestCase { } // 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; - } + com.sun.star.text.XTextContent xNewField = + (com.sun.star.text.XTextContent)UnoRuntime.queryInterface( + com.sun.star.text.XTextContent.class, + xFac.createInstance( "com.sun.star.text.TextField.GetReference" ) ); if ( xNewField != null ) { com.sun.star.beans.XPropertySet xFieldProps = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( @@ -354,16 +253,37 @@ public class CheckCrossReferences extends ComplexTestCase { 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 ); + assertEquals( "inserted reference field doesn't has correct field result", + "J", xField.getPresentation( false ) ); 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 ); + assertEquals( "inserted reference field doesn't has correct field result", + "Hallo new bookmark: J", xField.getPresentation( false ) ); } + } + + @Before public void setUpDocument() throws com.sun.star.uno.Exception { + document = util.WriterTools.loadTextDoc( + connection.getFactory(), + TestDocument.getUrl("CheckCrossReferences.odt")); + } - // closing test document - util.DesktopTools.closeDoc( xDoc ); + @After public void tearDownDocument() { + util.DesktopTools.closeDoc(document); } + + private XTextDocument document = null; + + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/sw/qa/complex/writer/CheckFlies.java b/sw/qa/complex/writer/CheckFlies.java index 50e94290c5b2..7b4cdd8098d3 100644 --- a/sw/qa/complex/writer/CheckFlies.java +++ b/sw/qa/complex/writer/CheckFlies.java @@ -31,50 +31,40 @@ 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; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; -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 +public class CheckFlies { + @Test public void checkFlies() + throws com.sun.star.uno.Exception { - 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); - } + com.sun.star.text.XTextFramesSupplier xTFS = (com.sun.star.text.XTextFramesSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextFramesSupplier.class, + document); + checkTextFrames(xTFS); + com.sun.star.text.XTextGraphicObjectsSupplier xTGOS = (com.sun.star.text.XTextGraphicObjectsSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextGraphicObjectsSupplier.class, + document); + checkGraphicFrames(xTGOS); + com.sun.star.text.XTextEmbeddedObjectsSupplier xTEOS = (com.sun.star.text.XTextEmbeddedObjectsSupplier)UnoRuntime.queryInterface( + com.sun.star.text.XTextEmbeddedObjectsSupplier.class, + document); + checkEmbeddedFrames(xTEOS); } private void checkEmbeddedFrames(com.sun.star.text.XTextEmbeddedObjectsSupplier xTGOS) - throws com.sun.star.lang.WrappedTargetException + throws com.sun.star.uno.Exception { Collection<String> vExpectedEmbeddedFrames = new ArrayList<String>(); vExpectedEmbeddedFrames.add("Object1"); @@ -82,51 +72,42 @@ public class CheckFlies extends ComplexTestCase { 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."); + assertTrue( + "Unexpected frame name", + vExpectedEmbeddedFrames.remove(sFrameName)); + xEmbeddedFrames.getByName(sFrameName); + assertTrue( + "Could not find embedded frame by name.", + xEmbeddedFrames.hasByName(sFrameName)); } - if(!vExpectedEmbeddedFrames.isEmpty()) - failed("Missing expected embedded frames."); + assertTrue( + "Missing expected embedded frames.", + vExpectedEmbeddedFrames.isEmpty()); try { xEmbeddedFrames.getByName("Nonexisting embedded frame"); - failed("Got nonexisting embedded frame"); + fail("Got nonexisting embedded frame"); } catch(com.sun.star.container.NoSuchElementException e) {} - if(xEmbeddedFrames.hasByName("Nonexisting embedded frame")) - failed("Has nonexisting embedded frame"); + assertFalse( + "Has nonexisting embedded frame", + xEmbeddedFrames.hasByName("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."); + assertEquals( + "Unexpected number of embedded frames reported.", nEmbeddedFrames, + xEmbeddedFramesIdx.getCount()); 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."); - } + xEmbeddedFramesIdx.getByIndex(nCurrentFrameIdx); } } private void checkGraphicFrames(com.sun.star.text.XTextGraphicObjectsSupplier xTGOS) - throws com.sun.star.lang.WrappedTargetException + throws com.sun.star.uno.Exception { Collection<String> vExpectedGraphicFrames = new ArrayList<String>(); vExpectedGraphicFrames.add("graphics1"); @@ -134,51 +115,42 @@ public class CheckFlies extends ComplexTestCase { 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."); + assertTrue( + "Unexpected frame name", + vExpectedGraphicFrames.remove(sFrameName)); + xGraphicFrames.getByName(sFrameName); + assertTrue( + "Could not find graphics frame by name.", + xGraphicFrames.hasByName(sFrameName)); } - if(!vExpectedGraphicFrames.isEmpty()) - failed("Missing expected graphics frames."); + assertTrue( + "Missing expected graphics frames.", + vExpectedGraphicFrames.isEmpty()); try { xGraphicFrames.getByName("Nonexisting graphics frame"); - failed("Got nonexisting graphics frame"); + fail("Got nonexisting graphics frame"); } catch(com.sun.star.container.NoSuchElementException e) {} - if(xGraphicFrames.hasByName("Nonexisting graphics frame")) - failed("Has nonexisting graphics frame"); + assertFalse( + "Has nonexisting graphics frame", + xGraphicFrames.hasByName("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."); + assertEquals( + "Unexpected number of graphics frames reported.", nGraphicFrames, + xGraphicFramesIdx.getCount()); 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."); - } + xGraphicFramesIdx.getByIndex(nCurrentFrameIdx); } } private void checkTextFrames(com.sun.star.text.XTextFramesSupplier xTFS) - throws com.sun.star.lang.WrappedTargetException + throws com.sun.star.uno.Exception { Collection<String> vExpectedTextFrames = new ArrayList<String>(); vExpectedTextFrames.add("Frame1"); @@ -188,46 +160,60 @@ public class CheckFlies extends ComplexTestCase { 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."); + assertTrue( + "Unexpected frame name", + vExpectedTextFrames.remove(sFrameName)); + xTextFrames.getByName(sFrameName); + assertTrue( + "Could not find text frame by name.", + xTextFrames.hasByName(sFrameName)); } - if(!vExpectedTextFrames.isEmpty()) - failed("Missing expected text frames."); + assertTrue( + "Missing expected text frames.", vExpectedTextFrames.isEmpty()); try { xTextFrames.getByName("Nonexisting Textframe"); - failed("Got nonexisting text frame."); + fail("Got nonexisting text frame."); } catch(com.sun.star.container.NoSuchElementException e) {} - if(xTextFrames.hasByName("Nonexisting text frame")) - failed("Has nonexisting text frame."); + assertFalse( + "Has nonexisting text frame.", + xTextFrames.hasByName("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."); + assertEquals( + "Unexpected number of text frames reported.", nTextFrames, + xTextFramesIdx.getCount()); 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."); - } + xTextFramesIdx.getByIndex(nCurrentFrameIdx); } } + + @Before public void setUpDocument() throws com.sun.star.uno.Exception { + document = util.WriterTools.loadTextDoc( + connection.getFactory(), + TestDocument.getUrl("CheckFlies.odt")); + } + + @After public void tearDownDocument() { + util.DesktopTools.closeDoc(document); + } + + private XTextDocument document = null; + + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/sw/qa/complex/writer/CheckIndexedPropertyValues.java b/sw/qa/complex/writer/CheckIndexedPropertyValues.java index aca4f68c7ec2..bd086afc3e65 100755 --- a/sw/qa/complex/writer/CheckIndexedPropertyValues.java +++ b/sw/qa/complex/writer/CheckIndexedPropertyValues.java @@ -27,53 +27,29 @@ 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; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; /** * Test the com.sun.star.document.IndexedPropertyValues service */ -public class CheckIndexedPropertyValues extends ComplexTestCase { +public class CheckIndexedPropertyValues { + @Test public void checkIndexedPropertyValues() + throws com.sun.star.uno.Exception + { + XIndexContainer xCont = UnoRuntime.queryInterface( + XIndexContainer.class, + connection.getFactory().createInstance( + "com.sun.star.document.IndexedPropertyValues")); - 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)); + assertNotNull("XIndexContainer was queried but returned null.", xCont); PropertyValue[] prop1 = new PropertyValue[1]; prop1[0] = new PropertyValue(); prop1[0].Name = "Jupp"; @@ -84,99 +60,55 @@ public class CheckIndexedPropertyValues extends ComplexTestCase { 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(); - } + Type t = xCont.getElementType(); + assertEquals("Initial container is not empty", 0, xCont.getCount()); + xCont.insertByIndex(0, prop1); + PropertyValue[]ret = (PropertyValue[])xCont.getByIndex(0); + assertEquals(prop1[0].Name, ret[0].Name); + assertEquals(prop1[0].Value, ret[0].Value); + xCont.replaceByIndex(0, prop2); + ret = (PropertyValue[])xCont.getByIndex(0); + assertEquals(prop2[0].Name, ret[0].Name); + assertEquals(prop2[0].Value, ret[0].Value); + xCont.removeByIndex(0); + assertTrue("Could not remove PropertyValue.", + !xCont.hasElements() && xCont.getCount()==0); + xCont.insertByIndex(0, prop1); + xCont.insertByIndex(1, prop2); + assertTrue("Did not insert PropertyValue.", + xCont.hasElements() && xCont.getCount()==2); + try { + xCont.insertByIndex(25, prop2); + fail("IllegalArgumentException was not thrown."); } - catch(com.sun.star.lang.IllegalArgumentException e) { - failed(e.getMessage()); - e.printStackTrace(); + catch(com.sun.star.lang.IndexOutOfBoundsException e) { + } + + try { + xCont.removeByIndex(25); + fail("IndexOutOfBoundsException was not thrown."); } catch(com.sun.star.lang.IndexOutOfBoundsException e) { - failed(e.getMessage()); - e.printStackTrace(); } - catch(com.sun.star.lang.WrappedTargetException e) { - failed(e.getMessage()); - e.printStackTrace(); + + try { + xCont.insertByIndex(2, "Example String"); + fail("IllegalArgumentException was not thrown."); + } + catch(com.sun.star.lang.IllegalArgumentException e) { } } + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/sw/qa/complex/writer/CheckNamedPropertyValues.java b/sw/qa/complex/writer/CheckNamedPropertyValues.java index 851381cf3c24..bad8bbda3303 100755 --- a/sw/qa/complex/writer/CheckNamedPropertyValues.java +++ b/sw/qa/complex/writer/CheckNamedPropertyValues.java @@ -27,53 +27,29 @@ 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; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; /** * */ -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)); +public class CheckNamedPropertyValues { + @Test public void checkNamedPropertyValues() + throws com.sun.star.uno.Exception + { + XNameContainer xCont = UnoRuntime.queryInterface( + XNameContainer.class, + connection.getFactory().createInstance( + "com.sun.star.document.NamedPropertyValues")); + + assertNotNull("XNameContainer was queried but returned null.", xCont); PropertyValue[] prop1 = new PropertyValue[1]; prop1[0] = new PropertyValue(); prop1[0].Name = "Jupp"; @@ -84,113 +60,61 @@ public class CheckNamedPropertyValues extends ComplexTestCase { 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(); - } + Type t = xCont.getElementType(); + assertFalse("Initial container is not empty.", xCont.hasElements()); + + xCont.insertByName("prop1", prop1); + PropertyValue[]ret = (PropertyValue[])xCont.getByName("prop1"); + assertEquals(prop1[0].Name, ret[0].Name); + assertEquals(prop1[0].Value, ret[0].Value); + xCont.replaceByName("prop1", prop2); + ret = (PropertyValue[])xCont.getByName("prop1"); + assertEquals(prop2[0].Name, ret[0].Name); + assertEquals(prop2[0].Value, ret[0].Value); + xCont.removeByName("prop1"); + assertFalse("Could not remove PropertyValue.", xCont.hasElements()); + xCont.insertByName("prop1", prop1); + xCont.insertByName("prop2", prop2); + assertTrue("Did not insert PropertyValue.", xCont.hasElements()); + String[] names = xCont.getElementNames(); + assertEquals("Not all element names were returned.", 2, names.length); + for (int i=0; i<names.length; i++) { + assertTrue( + "Got a wrong element name", + names[i].equals("prop1") || names[i].equals("prop2")); + } - 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(); - } + try { + xCont.insertByName("prop2", prop1); + fail("ElementExistException was not thrown."); + } + catch(com.sun.star.container.ElementExistException e) { + } + try { + xCont.insertByName("prop3", "Example String"); + fail("IllegalArgumentException was not thrown."); } catch(com.sun.star.lang.IllegalArgumentException e) { - failed(e.getMessage()); - e.printStackTrace(); } - catch(com.sun.star.container.ElementExistException e) { - failed(e.getMessage()); - e.printStackTrace(); + + try { + xCont.removeByName("prop3"); + fail("NoSuchElementException was not thrown."); } catch(com.sun.star.container.NoSuchElementException e) { - failed(e.getMessage()); - e.printStackTrace(); - } - catch(com.sun.star.lang.WrappedTargetException e) { - failed(e.getMessage()); - e.printStackTrace(); } } + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/sw/qa/complex/writer/TestDocument.java b/sw/qa/complex/writer/TestDocument.java new file mode 100644 index 000000000000..8f120385bb79 --- /dev/null +++ b/sw/qa/complex/writer/TestDocument.java @@ -0,0 +1,41 @@ +/************************************************************************* +* +* 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 java.io.File; + +final class TestDocument { + public static String getUrl(String name) { + return new File("testdocuments", name). + getAbsoluteFile().toURI().toString().replaceFirst( + "\\A[Ff][Ii][Ll][Ee]:/(?=[^/]|\\z)", "file:///"); + // file:/path -> file:///path + } + + private TestDocument() {} +} diff --git a/sw/qa/complex/writer/TextPortionEnumerationTest.java b/sw/qa/complex/writer/TextPortionEnumerationTest.java index 72e9664aaab4..8c84cae3ce16 100755 --- a/sw/qa/complex/writer/TextPortionEnumerationTest.java +++ b/sw/qa/complex/writer/TextPortionEnumerationTest.java @@ -27,7 +27,6 @@ package complex.writer; -import complexlib.ComplexTestCase; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.AnyConverter; import com.sun.star.uno.XComponentContext; @@ -60,6 +59,13 @@ 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 org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openoffice.test.OfficeConnection; +import static org.junit.Assert.*; import java.util.Map; import java.util.HashMap; @@ -422,10 +428,8 @@ class FuzzyTester 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; + FuzzyTester() { m_BufferExpected = new ArrayList<TreeNode>(); m_BufferActual = new ArrayList<TreeNode>(); m_StackExpected = new Stack<Pair<TreeNode, TreeNodeEnum>>(); @@ -434,12 +438,10 @@ class FuzzyTester /** idea: traverse both trees, enumerate nodes, stopping at content nodes. then compare buffers. */ - boolean doTest(TreeNode expected, TreeNode actual) + void 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"); + assertEquals("__ROOT__", expected.getType()); + assertEquals("__ROOT__", actual.getType()); m_StackExpected.push(new Pair(expected, expected.createEnumeration())); m_StackActual.push(new Pair(actual, actual.createEnumeration())); do { @@ -449,18 +451,19 @@ class FuzzyTester testBuffer(); } while (!m_StackExpected.empty() || !m_StackActual.empty()); if (m_DiffSequence != 0) { - m_Log.println("warning: " + m_DiffSequence + System.out.println("warning: " + m_DiffSequence + " differences in sequence"); } if (m_DiffSpuriousEmptyText != 0) { - m_Log.println("warning: " + m_DiffSpuriousEmptyText + System.out.println("warning: " + m_DiffSpuriousEmptyText + " spurious empty text nodes"); } if (m_DiffNesting != 0) { - m_Log.println("WARNING: " + m_DiffNesting + System.out.println("WARNING: " + m_DiffNesting + " differences in nesting"); } - return (m_DiffContent == 0) && (m_DiffMissing == 0); + assertEquals(0, m_DiffContent); + assertEquals(0, m_DiffMissing); } private void traverse(Stack<Pair<TreeNode, TreeNodeEnum>> stack, @@ -553,7 +556,7 @@ class FuzzyTester } m_BufferActual.set(j, null); } else { -//m_Log.println("testBuffer:"); +//System.out.println("testBuffer:"); printMissing(node); m_DiffMissing++; } @@ -563,7 +566,7 @@ class FuzzyTester TreeNode node = m_BufferActual.get(j); if (node != null) { -//m_Log.println("testBuffer:"); +//System.out.println("testBuffer:"); printUnexpected(node); if ((node instanceof TextNode) && ((TextNode) node).getContent().length() == 0) { @@ -580,25 +583,25 @@ class FuzzyTester void printDiff(String prefix, String expected, String actual) { - m_Log.println(prefix + + System.out.println(prefix + ":\texpected: " + expected + "\tactual: " + actual); } void printNesting(TreeNode node, TreeNode nesting) { - m_Log.println("node: " + node.toString() + System.out.println("node: " + node.toString() + " possibly moved across nesting " + nesting.toString()); } void printMissing(TreeNode node) { - m_Log.println(" missing node: " + node.toString()); + System.out.println(" missing node: " + node.toString()); } void printUnexpected(TreeNode node) { - m_Log.println("unexpected node: " + node.toString()); + System.out.println("unexpected node: " + node.toString()); } } @@ -609,10 +612,9 @@ class FuzzyTester class EnumConverter { private Stack<TreeNode> m_Stack; - TextPortionEnumerationTest m_T; - EnumConverter(TextPortionEnumerationTest err) { - m_Stack = new Stack<TreeNode>(); m_T = err; + EnumConverter() { + m_Stack = new Stack<TreeNode>(); } TreeNode convert(XEnumeration xEnum) throws Exception @@ -620,7 +622,7 @@ class EnumConverter TreeNode root = new TreeNode(); m_Stack.push(root); TreeNode ret = convertChildren(xEnum); - m_T.assure("EnumConverter.convert: stack", m_Stack.empty()); + assertTrue("EnumConverter.convert: stack", m_Stack.empty()); return ret; } @@ -660,7 +662,7 @@ class EnumConverter xMeta); XEnumeration xEnumChildren = xEA.createEnumeration(); TreeNode node2 = convertChildren(xEnumChildren); - m_T.assure("stack error: meta-field", node == node2); + assertSame("stack error: meta-field", node2, node); } else { XPropertySet xFieldPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xField); @@ -668,7 +670,7 @@ class EnumConverter xFieldPropSet.getPropertyValue("Content"); boolean isFixed = (Boolean) xFieldPropSet.getPropertyValue("IsFixed"); - m_T.assure("field not fixed?", isFixed); + assertTrue("field not fixed?", isFixed); node = new TextFieldNode(content); } } else if (type.equals("Footnote")) { @@ -771,10 +773,8 @@ class EnumConverter 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())); + assertTrue("stack error: Ruby expected; is: " + + node.toString(), node instanceof RubyNode); } } else if (type.equals("InContentMetadata")) { Object xMeta = xPropSet.getPropertyValue("InContentMetadata"); @@ -787,9 +787,7 @@ class EnumConverter 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"); + assertSame("stack error: meta", node2, node); } else { throw new RuntimeException("unexpected type: " + type); } @@ -1226,7 +1224,7 @@ class RangeInserter extends Inserter //---------------------------------------------------------------------- -public class TextPortionEnumerationTest extends ComplexTestCase +public class TextPortionEnumerationTest { private XMultiServiceFactory m_xMSF = null; private XComponentContext m_xContext = null; @@ -1235,113 +1233,26 @@ public class TextPortionEnumerationTest extends ComplexTestCase 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", - "testMetaXText", - "testMetaXTextCursor", - "testMetaXTextAttachToxMark", - "testMetaXTextAttachRefMark", - "testMetaXTextAttachTextField", - "testMetaXTextAttachFootnote", - "testMetaXTextAttachMeta", - "testMetaFieldXTextField", - "testMetaFieldXPropertySet", - "testLoadStore", - }; - } - - public void before() throws Exception - { - m_xMSF = (XMultiServiceFactory) param.getMSF(); + @Before public void before() throws Exception + { + m_xMSF = connection.getFactory(); 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); + assertNotNull("could not get component context.", m_xContext); m_xDoc = util.WriterTools.createTextDoc(m_xMSF); m_TmpDir = util.utils.getOfficeTemp/*Dir*/(m_xMSF); - log.println("tempdir: " + m_TmpDir); + System.out.println("tempdir: " + m_TmpDir); } - public void after() + @After public void after() { - if (m_xDoc != null) { - util.DesktopTools.closeDoc(m_xDoc); - m_xDoc = null; - } + util.DesktopTools.closeDoc(m_xDoc); } - public void testText() throws Exception + @Test public void testText() throws Exception { TreeNode root = new TreeNode(); TreeNode text = new TextNode("abc"); @@ -1349,7 +1260,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testTextField() throws Exception + @Test public void testTextField() throws Exception { String name = mkName("ruby"); TreeNode root = new TreeNode(); @@ -1358,7 +1269,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testControlChar() throws Exception + /*@Test*/ public void testControlChar() throws Exception { //FIXME this is converted to a text portion: ControlCharacter is obsolete TreeNode root = new TreeNode(); @@ -1367,7 +1278,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testSoftPageBreak() throws Exception + /*@Test*/ public void testSoftPageBreak() throws Exception { //FIXME: insert a soft page break: not done TreeNode root = new TreeNode(); @@ -1378,7 +1289,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFootnote() throws Exception + @Test public void testFootnote() throws Exception { String name = mkName("ftn"); TreeNode root = new TreeNode(); @@ -1387,7 +1298,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrameAs() throws Exception + @Test public void testFrameAs() throws Exception { String name = mkName("frame"); TreeNode root = new TreeNode(); @@ -1396,7 +1307,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrameAt() throws Exception + @Test public void testFrameAt() throws Exception { String name = mkName("frame"); TreeNode root = new TreeNode(); @@ -1407,7 +1318,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testBookmarkPoint() throws Exception + @Test public void testBookmarkPoint() throws Exception { String name = mkName("mark"); TreeNode root = new TreeNode(); @@ -1418,7 +1329,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testBookmark() throws Exception + @Test public void testBookmark() throws Exception { String name = mkName("mark"); TreeNode root = new TreeNode(); @@ -1431,7 +1342,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testBookmarkPointXmlId() throws Exception + @Test public void testBookmarkPointXmlId() throws Exception { String name = mkName("mark"); StringPair id = mkId("id"); @@ -1443,7 +1354,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testBookmarkXmlId() throws Exception + @Test public void testBookmarkXmlId() throws Exception { String name = mkName("mark"); StringPair id = mkId("id"); @@ -1457,7 +1368,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRefmarkPoint() throws Exception + @Test public void testRefmarkPoint() throws Exception { String name = mkName("refmark"); TreeNode root = new TreeNode(); @@ -1468,7 +1379,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRefmark() throws Exception + @Test public void testRefmark() throws Exception { String name = mkName("refmark"); TreeNode root = new TreeNode(); @@ -1481,7 +1392,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testToxmarkPoint() throws Exception + @Test public void testToxmarkPoint() throws Exception { String name = mkName("toxmark"); TreeNode root = new TreeNode(); @@ -1492,7 +1403,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testToxmark() throws Exception + @Test public void testToxmark() throws Exception { String name = mkName("toxmark"); TreeNode root = new TreeNode(); @@ -1505,7 +1416,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testHyperlink() throws Exception + @Test public void testHyperlink() throws Exception { String name = mkName("url"); TreeNode root = new TreeNode(); @@ -1516,7 +1427,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testHyperlinkEmpty() throws Exception + @Test public void testHyperlinkEmpty() throws Exception { String name = mkName("url"); TreeNode root = new TreeNode(); @@ -1527,7 +1438,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRuby() throws Exception + @Test public void testRuby() throws Exception { String name = mkName("ruby"); TreeNode root = new TreeNode(); @@ -1538,7 +1449,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRubyEmpty() throws Exception + @Test public void testRubyEmpty() throws Exception { // BUG: #i91534# String name = mkName("ruby"); @@ -1548,7 +1459,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMeta() throws Exception + @Test public void testMeta() throws Exception { StringPair id = new StringPair("content.xml", mkName("id")); TreeNode root = new TreeNode(); @@ -1560,7 +1471,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMetaEmpty() throws Exception + @Test public void testMetaEmpty() throws Exception { StringPair id = new StringPair("content.xml", mkName("id")); TreeNode root = new TreeNode(); @@ -1571,7 +1482,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMetaField() throws Exception + @Test public void testMetaField() throws Exception { StringPair id = new StringPair("content.xml", mkName("id")); TreeNode root = new TreeNode(); @@ -1583,7 +1494,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMetaFieldEmpty() throws Exception + @Test public void testMetaFieldEmpty() throws Exception { StringPair id = new StringPair("content.xml", mkName("id")); TreeNode root = new TreeNode(); @@ -1594,7 +1505,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testBookmark1() throws Exception + @Test public void testBookmark1() throws Exception { String name1 = mkName("mark"); String name2 = mkName("mark"); @@ -1610,7 +1521,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testBookmark2() throws Exception + @Test public void testBookmark2() throws Exception { String name1 = mkName("mark"); String name2 = mkName("mark"); @@ -1626,7 +1537,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRefMark2() throws Exception + @Test public void testRefMark2() throws Exception { String name1 = mkName("refmark"); TreeNode root = new TreeNode(); @@ -1638,7 +1549,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRefMark3() throws Exception + @Test public void testRefMark3() throws Exception { String name1 = mkName("refmark"); String name2 = mkName("refmark"); @@ -1652,7 +1563,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testToxMark2() throws Exception + @Test public void testToxMark2() throws Exception { String name1 = mkName("toxmark"); TreeNode root = new TreeNode(); @@ -1663,7 +1574,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testToxMark3() throws Exception + @Test public void testToxMark3() throws Exception { String name1 = mkName("toxmark"); String name2 = mkName("toxmark"); @@ -1677,7 +1588,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMarks1() throws Exception + @Test public void testMarks1() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("toxmark"); @@ -1696,7 +1607,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMarks2() throws Exception + @Test public void testMarks2() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("refmark"); @@ -1719,7 +1630,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testMarks3() throws Exception + @Test public void testMarks3() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("refmark"); @@ -1741,7 +1652,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrameMark1() throws Exception + @Test public void testFrameMark1() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("frame"); @@ -1753,7 +1664,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrameMark2() throws Exception + @Test public void testFrameMark2() throws Exception { // BUG: #i98530# String name1 = mkName("bookmark"); @@ -1766,7 +1677,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrameMark3() throws Exception + @Test public void testFrameMark3() throws Exception { String name1 = mkName("frame"); String name2 = mkName("bookmark"); @@ -1778,7 +1689,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrameMark4() throws Exception + @Test public void testFrameMark4() throws Exception { String name1 = mkName("frame"); String name2 = mkName("bookmark"); @@ -1790,7 +1701,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrames1() throws Exception + @Test public void testFrames1() throws Exception { String name1 = mkName("frame"); String name2 = mkName("frame"); @@ -1802,7 +1713,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrames2() throws Exception + @Test public void testFrames2() throws Exception { String name1 = mkName("frame"); String name2 = mkName("frame"); @@ -1814,7 +1725,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrames3() throws Exception + @Test public void testFrames3() throws Exception { String name1 = mkName("frame"); String name2 = mkName("frame"); @@ -1826,7 +1737,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrames4() throws Exception + @Test public void testFrames4() throws Exception { String name1 = mkName("frame"); String name2 = mkName("frame"); @@ -1838,7 +1749,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testFrames5() throws Exception + @Test public void testFrames5() throws Exception { String name1 = mkName("frame"); String name2 = mkName("frame"); @@ -1850,7 +1761,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRubyHyperlink1() throws Exception + @Test public void testRubyHyperlink1() throws Exception { String name1 = mkName("ruby"); String name2 = mkName("url"); @@ -1863,7 +1774,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testRubyHyperlink2() throws Exception + @Test public void testRubyHyperlink2() throws Exception { String name1 = mkName("url"); String name2 = mkName("ruby"); @@ -1876,7 +1787,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEnd1() throws Exception + @Test public void testEnd1() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("toxmark"); @@ -1889,7 +1800,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEnd2() throws Exception + @Test public void testEnd2() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("frame"); @@ -1906,7 +1817,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEnd3() throws Exception + @Test public void testEnd3() throws Exception { String name1 = mkName("ftn"); String name2 = mkName("toxmark"); @@ -1917,7 +1828,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEnd4() throws Exception + @Test public void testEnd4() throws Exception { String name1 = mkName("bookmark"); String name2 = mkName("frame"); @@ -1929,7 +1840,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEnd5() throws Exception + @Test public void testEnd5() throws Exception { String name1 = mkName("refmark"); String name2 = mkName("ruby"); @@ -1943,7 +1854,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEmpty1() throws Exception + @Test public void testEmpty1() throws Exception { String name1 = mkName("refmark"); String name2 = mkName("toxmark"); @@ -1965,7 +1876,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEmpty2() throws Exception + @Test public void testEmpty2() throws Exception { String name3 = mkName("bookmark"); String name4 = mkName("frame"); @@ -1979,7 +1890,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void testEmpty3() throws Exception + @Test public void testEmpty3() throws Exception { String name1 = mkName("refmark"); String name2 = mkName("toxmark"); @@ -2010,7 +1921,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root); } - public void test1() throws Exception + @Test public void test1() throws Exception { String name1 = mkName("frame"); String name2 = mkName("bookmark"); @@ -2037,7 +1948,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase attributes; if these ever become entities, they should not be split! */ - public void testRange1() throws Exception + @Test public void testRange1() throws Exception { String name1 = mkName("url"); RangeInserter inserter = new RangeInserter(m_xDoc); @@ -2052,7 +1963,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeHyperlinkHyperlink() throws Exception + @Test public void testRangeHyperlinkHyperlink() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2111,7 +2022,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeHyperlinkRuby() throws Exception + @Test public void testRangeHyperlinkRuby() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2177,7 +2088,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeRubyHyperlink() throws Exception + @Test public void testRangeRubyHyperlink() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2234,7 +2145,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeRubyRuby() throws Exception + @Test public void testRangeRubyRuby() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2280,7 +2191,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeHyperlinkMeta() throws Exception + @Test public void testRangeHyperlinkMeta() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2346,7 +2257,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeRubyMeta() throws Exception + @Test public void testRangeRubyMeta() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2413,7 +2324,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeMetaHyperlink() throws Exception + @Test public void testRangeMetaHyperlink() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2470,7 +2381,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeMetaRuby() throws Exception + @Test public void testRangeMetaRuby() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2559,7 +2470,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRangeMetaMeta() throws Exception + @Test public void testRangeMetaMeta() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2570,7 +2481,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase TreeNode met2 = new MetaNode( mkId("id") ); try { inserter.insertRange( new Range(0, 4, met2) ); - assure("testRangeMetaMeta: overlap left allowed", false); + fail("testRangeMetaMeta: overlap left allowed"); } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } TreeNode root = new TreeNode() .appendChild( new TextNode("123") ) @@ -2581,7 +2492,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase TreeNode met3 = new MetaNode( mkId("id") ); try { inserter.insertRange( new Range(5/*-1*/, 8/*-1*/, met3) ); - assure("testRangeMetaMeta: overlap right allowed", false); + fail("testRangeMetaMeta: overlap right allowed"); } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } root = new TreeNode() .appendChild( new TextNode("123") ) @@ -2611,7 +2522,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRange2() throws Exception + @Test public void testRange2() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2681,7 +2592,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRange3() throws Exception + @Test public void testRange3() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2715,7 +2626,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRange4() throws Exception + @Test public void testRange4() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2769,7 +2680,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRange5() throws Exception + @Test public void testRange5() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2818,7 +2729,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRange6() throws Exception + @Test public void testRange6() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2858,7 +2769,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase doTest(root, false); } - public void testRange7() throws Exception + @Test public void testRange7() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123456789"); @@ -2899,7 +2810,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase /* TODO: test partial selection, test UNDO/REDO */ /** test SwXMeta XText interface */ - public void testMetaXText() throws Exception + @Test public void testMetaXText() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("12AB6789"); @@ -2921,113 +2832,106 @@ public class TextPortionEnumerationTest extends ComplexTestCase XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta); XText xParentText = xText.getText(); - assure("getText(): no parent", xParentText != null); + assertNotNull("getText(): no parent", xParentText); XTextRange xStart = xText.getStart(); - assure("getStart(): no start", xStart != null); + assertNotNull("getStart(): no start", xStart); XTextRange xEnd = xText.getEnd(); - assure("getEnd(): no end", xEnd != null); - - /* - String string = xText.getString(); - assure("getString(): invalid string returned", - string != null && "AB".equals(string) ); - */ + assertNotNull("getEnd(): no end", xEnd); xText.setString("45"); { String string = xText.getString(); - assure("getString(): invalid string returned: " + string, - string != null && "45".equals(string) ); + assertEquals("getString(): invalid string returned", + "45", string); } XTextCursor xTextCursor = xText.createTextCursor(); - assure("createTextCursor(): failed", xTextCursor != null); + assertNotNull("createTextCursor(): failed", xTextCursor); try { xText.createTextCursorByRange(null); - assure("createTextCursorByRange(): null allowed?", false); + fail("createTextCursorByRange(): null allowed?"); } catch (RuntimeException e) { /* expected */ } XTextCursor xTextCursorStart = xText.createTextCursorByRange(xStart); - assure("createTextCursorByRange(): failed for start", - xTextCursorStart != null); + assertNotNull("createTextCursorByRange(): failed for start", + xTextCursorStart); XTextCursor xTextCursorEnd = xText.createTextCursorByRange(xEnd); - assure("createTextCursorByRange(): failed for end", - xTextCursorEnd != null); + assertNotNull("createTextCursorByRange(): failed for end", + xTextCursorEnd); // move outside meta xDocTextCursor.gotoStart(false); try { xText.insertString(null, "foo", false); - assure("insertString(): null allowed?", false); + fail("insertString(): null allowed?"); } catch (RuntimeException e) { /* expected */ } try { xText.insertString(xDocTextCursor, "foo", false); - assure("insertString(): cursor outside allowed?", false); + fail("insertString(): cursor outside allowed?"); } 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) ); + assertEquals("getString(): invalid string returned", + "A45", string); } xText.insertString(xEnd, "B", false); { String string = xText.getString(); - assure("getString(): invalid string returned: " + string, - string != null && "A45B".equals(string) ); + assertEquals("getString(): invalid string returned", + "A45B", string); } try { xText.insertControlCharacter(null, HARD_HYPHEN, false); - assure("insertControlCharacter(): null allowed?", false); + fail("insertControlCharacter(): null allowed?"); } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } xStart = xText.getStart(); try { xText.insertControlCharacter(xDocTextCursor, HARD_HYPHEN, false); - assure("insertControlCharacter(): cursor outside allowed?", false); + fail("insertControlCharacter(): cursor outside allowed?"); } 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) ); + assertEquals("getString(): invalid string returned", + '\u2011' + "A45B", string); } xText.insertControlCharacter(xEnd, HARD_HYPHEN, false); { String string = xText.getString(); - assure("getString(): invalid string returned: " + string, - string != null && - ('\u2011' + "A45B" + '\u2011').equals(string) ); + assertEquals("getString(): invalid string returned", + '\u2011' + "A45B" + '\u2011', string); } xText.setString("45"); try { xText.insertTextContent(null, xMeta, false); - assure("insertTextContent(): null range allowed?", false); + fail("insertTextContent(): null range allowed?"); } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } try { xText.insertTextContent(xStart, null, false); - assure("insertTextContent(): null content allowed?", false); + fail("insertTextContent(): null content allowed?"); } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } try { xText.insertTextContent(xDocTextCursor, xMeta, false); - assure("insertTextContent(): cursor outside allowed?", false); + fail("insertTextContent(): cursor outside allowed?"); } catch (com.sun.star.lang.IllegalArgumentException e) { /* ignore */ } TextFieldNode field1 = new TextFieldNode( "f1" ); @@ -3059,13 +2963,13 @@ public class TextPortionEnumerationTest extends ComplexTestCase try { xText.removeTextContent(null); - assure("removeTextContent(): null content allowed?", false); + fail("removeTextContent(): null content allowed?"); } catch (RuntimeException e) { /* expected */ } xText.removeTextContent(xField1); XTextRange xAnchor = xMeta.getAnchor(); - assure("getAnchor(): null", xAnchor != null); + assertNotNull("getAnchor(): null", xAnchor); // evil test case: insert ruby around meta RubyNode ruby = new RubyNode( mkName("ruby") ); @@ -3085,31 +2989,31 @@ public class TextPortionEnumerationTest extends ComplexTestCase XEnumerationAccess xEA = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xMeta); XEnumeration xEnum = xEA.createEnumeration(); - assure("createEnumeration(): returns null", xEnum != null); + assertNotNull("createEnumeration(): returns null", xEnum); { - assure("hasNext(): first missing", xEnum.hasMoreElements()); + assertTrue("hasNext(): first missing", xEnum.hasMoreElements()); Object xElement = xEnum.nextElement(); XTextRange xPortion = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, xElement); XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPortion); String type = (String) xPropSet.getPropertyValue("TextPortionType"); - assure("first: not text: " + type, type.equals("Text")); + assertEquals("first: not text", "Text", type); String txt = xPortion.getString(); - assure("first: text differs: " + txt, "45".equals(txt)); + assertEquals("first: text differs", "45", txt); } { - assure("hasNext(): second missing", xEnum.hasMoreElements()); + assertTrue("hasNext(): second missing", xEnum.hasMoreElements()); Object xElement = xEnum.nextElement(); XTextRange xPortion = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, xElement); XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPortion); String type = (String) xPropSet.getPropertyValue("TextPortionType"); - assure("second: not text", type.equals("TextField")); + assertEquals("second: not text", "TextField", type); } // no ruby end here!!! - assure("hasNext(): more elements?", !xEnum.hasMoreElements()); + assertFalse("hasNext(): more elements?", xEnum.hasMoreElements()); XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMeta); @@ -3117,14 +3021,14 @@ public class TextPortionEnumerationTest extends ComplexTestCase try { XTextCursor xCursor = xText.createTextCursor(); - assure("createTextCursor(): succeeds on disposed object?", - xCursor == null); + assertNull("createTextCursor(): succeeds on disposed object?", + xCursor); } catch (RuntimeException e) { /* expected */ } } /** check that cursor move methods move to positions in the meta, but do not move to positions outside the meta. */ - public void testMetaXTextCursor() throws Exception + @Test public void testMetaXTextCursor() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("Text. 12 More text here."); @@ -3145,30 +3049,30 @@ public class TextPortionEnumerationTest extends ComplexTestCase XText xText = (XText) UnoRuntime.queryInterface(XText.class, xMeta); XTextRange xStart = xText.getStart(); - assure("getStart(): no start", xStart != null); + assertNotNull("getStart(): no start", xStart); XTextRange xEnd = xText.getEnd(); - assure("getEnd(): no end", xEnd != null); + assertNotNull("getEnd(): no end", xEnd); XTextCursor xTextCursor = xText.createTextCursor(); - assure("createTextCursor(): no cursor", xTextCursor != null); + assertNotNull("createTextCursor(): no cursor", xTextCursor); // XTextCursor boolean bSuccess = false; xTextCursor.gotoStart(false); xTextCursor.gotoEnd(false); bSuccess = xTextCursor.goLeft((short)1, false); - assure("goLeft(): failed", bSuccess); + assertTrue("goLeft(): failed", bSuccess); bSuccess = xTextCursor.goLeft((short)1000, false); - assure("goLeft(): succeeded", !bSuccess); + assertFalse("goLeft(): succeeded", bSuccess); bSuccess = xTextCursor.goRight((short)1, false); - assure("goRight(): failed", bSuccess); + assertTrue("goRight(): failed", bSuccess); bSuccess = xTextCursor.goRight((short)1000, false); - assure("goRight(): succeeded", !bSuccess); + assertFalse("goRight(): succeeded", bSuccess); xTextCursor.gotoRange(xStart, false); xTextCursor.gotoRange(xEnd, false); try { xTextCursor.gotoRange(xDocTextCursor, false); - assure("gotoRange(): succeeded", false); + fail("gotoRange(): succeeded"); } catch (RuntimeException e) { /* expected */ } // XWordCursor @@ -3178,44 +3082,44 @@ public class TextPortionEnumerationTest extends ComplexTestCase UnoRuntime.queryInterface(XWordCursor.class, xTextCursor); bSuccess = xWordCursor.gotoNextWord(true); - assure("gotoNextWord(): failed", bSuccess); + assertTrue("gotoNextWord(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoNextWord(): wrong string: " + string, - "Two ".equals(string)); + assertEquals("gotoNextWord(): wrong string", + "Two ", string); } bSuccess = xWordCursor.gotoNextWord(false); - assure("gotoNextWord(): succeeded", !bSuccess); + assertFalse("gotoNextWord(): succeeded", bSuccess); xTextCursor.collapseToEnd(); bSuccess = xWordCursor.gotoPreviousWord(true); - assure("gotoPreviousWord(): failed", bSuccess); + assertTrue("gotoPreviousWord(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoPreviousWord(): wrong string: " + string, - "words".equals(string)); + assertEquals("gotoPreviousWord(): wrong string", + "words", string); } bSuccess = xWordCursor.gotoPreviousWord(false); - assure("gotoPreviousWord(): succeeded", !bSuccess); + assertFalse("gotoPreviousWord(): succeeded", bSuccess); bSuccess = xWordCursor.gotoEndOfWord(true); - assure("gotoEndOfWord(): failed", bSuccess); + assertTrue("gotoEndOfWord(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoEndOfWord(): wrong string: " + string, - "Two".equals(string)); + assertEquals("gotoEndOfWord(): wrong string", + "Two", string); } xTextCursor.gotoEnd(false); bSuccess = xWordCursor.gotoStartOfWord(true); - assure("gotoStartOfWord(): failed", bSuccess); + assertTrue("gotoStartOfWord(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoStartOfWord(): wrong string: " + string, - "words".equals(string)); + assertEquals("gotoStartOfWord(): wrong string", + "words", string); } xText.setString(""); bSuccess = xWordCursor.gotoEndOfWord(false); - assure("gotoEndOfWord(): succeeded", !bSuccess); + assertFalse("gotoEndOfWord(): succeeded", bSuccess); bSuccess = xWordCursor.gotoStartOfWord(false); - assure("gotoStartOfWord(): succeeded", !bSuccess); + assertFalse("gotoStartOfWord(): succeeded", bSuccess); // XSentenceCursor xText.setString("This is a sentence. Another sentence."); @@ -3224,60 +3128,60 @@ public class TextPortionEnumerationTest extends ComplexTestCase UnoRuntime.queryInterface(XSentenceCursor.class, xTextCursor); bSuccess = xSentenceCursor.gotoNextSentence(true); - assure("gotoNextSentence(): failed", bSuccess); + assertTrue("gotoNextSentence(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoNextSentence(): wrong string: " + string, - "This is a sentence. ".equals(string)); + assertEquals("gotoNextSentence(): wrong string", + "This is a sentence. ", string); } bSuccess = xSentenceCursor.gotoNextSentence(false); - assure("gotoNextSentence(): succeeded", !bSuccess); + assertFalse("gotoNextSentence(): succeeded", bSuccess); // FIXME: // the sentence cursor seems to work differently than the word cursor xText.setString("This is a sentence. Another sentence. Sentence 3."); xTextCursor.gotoEnd(false); bSuccess = xSentenceCursor.gotoPreviousSentence(true); - assure("gotoPreviousSentence(): failed", bSuccess); + assertTrue("gotoPreviousSentence(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoPreviousSentence(): wrong string: " + string, - "Another sentence. Sentence 3.".equals(string)); + assertEquals("gotoPreviousSentence(): wrong string", + "Another sentence. Sentence 3.", string); } bSuccess = xSentenceCursor.gotoPreviousSentence(false); - assure("gotoPreviousSentence(): succeeded", !bSuccess); + assertFalse("gotoPreviousSentence(): succeeded", bSuccess); bSuccess = xSentenceCursor.gotoEndOfSentence(true); - assure("gotoEndOfSentence(): failed", bSuccess); + assertTrue("gotoEndOfSentence(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoEndOfSentence(): wrong string: " + string, - "This is a sentence.".equals(string)); + assertEquals("gotoEndOfSentence(): wrong string", + "This is a sentence.", string); } xTextCursor.gotoEnd(false); bSuccess = xSentenceCursor.gotoStartOfSentence(true); - assure("gotoStartOfSentence(): failed", bSuccess); + assertTrue("gotoStartOfSentence(): failed", bSuccess); { String string = xTextCursor.getString(); - assure("gotoStartOfSentence(): wrong string: " + string, - "Sentence 3.".equals(string)); + assertEquals("gotoStartOfSentence(): wrong string", + "Sentence 3.", string); } xText.setString(""); bSuccess = xSentenceCursor.gotoEndOfSentence(false); - assure("gotoEndOfSentence(): succeeded", !bSuccess); + assertFalse("gotoEndOfSentence(): succeeded", bSuccess); bSuccess = xSentenceCursor.gotoStartOfSentence(false); - assure("gotoStartOfSentence(): succeeded", !bSuccess); + assertFalse("gotoStartOfSentence(): succeeded", bSuccess); XParagraphCursor xParagraphCursor = (XParagraphCursor) UnoRuntime.queryInterface(XParagraphCursor.class, xTextCursor); // XParagraphCursor (does not make sense) bSuccess = xParagraphCursor.gotoNextParagraph(false); - assure("gotoNextParagraph(): succeeded", !bSuccess); + assertFalse("gotoNextParagraph(): succeeded", bSuccess); bSuccess = xParagraphCursor.gotoPreviousParagraph(false); - assure("gotoPreviousParagraph(): succeeded", !bSuccess); + assertFalse("gotoPreviousParagraph(): succeeded", bSuccess); bSuccess = xParagraphCursor.gotoStartOfParagraph(false); - assure("gotoStartOfParagraph(): succeeded", !bSuccess); + assertFalse("gotoStartOfParagraph(): succeeded", bSuccess); bSuccess = xParagraphCursor.gotoEndOfParagraph(false); - assure("gotoEndOfParagraph(): succeeded", !bSuccess); + assertFalse("gotoEndOfParagraph(): succeeded", bSuccess); } @@ -3291,7 +3195,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase throws Exception { } } - public void testMetaXTextAttachToxMark() throws Exception + @Test public void testMetaXTextAttachToxMark() throws Exception { doMetaXTextAttach( new AttachHelper() { @@ -3307,7 +3211,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase }); } - public void testMetaXTextAttachRefMark() throws Exception + @Test public void testMetaXTextAttachRefMark() throws Exception { doMetaXTextAttach( new AttachHelper() { @@ -3323,7 +3227,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase }); } - public void testMetaXTextAttachTextField() throws Exception + @Test public void testMetaXTextAttachTextField() throws Exception { doMetaXTextAttach( new AttachHelper() { @@ -3339,7 +3243,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase }); } - public void testMetaXTextAttachFootnote() throws Exception + @Test public void testMetaXTextAttachFootnote() throws Exception { doMetaXTextAttach( new AttachHelper() { @@ -3355,7 +3259,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase }); } - public void testMetaXTextAttachMeta() throws Exception + @Test public void testMetaXTextAttachMeta() throws Exception { doMetaXTextAttach( new AttachHelper() { @@ -3605,7 +3509,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase } } - public void testMetaFieldXTextField() throws Exception + @Test public void testMetaFieldXTextField() throws Exception { com.sun.star.rdf.XRepositorySupplier xModel = (com.sun.star.rdf.XRepositorySupplier) UnoRuntime.queryInterface( @@ -3643,12 +3547,12 @@ public class TextPortionEnumerationTest extends ComplexTestCase xGraph.addStatement(xMetadatable, xOdfPrefix, xPrefix); xGraph.addStatement(xMetadatable, xOdfSuffix, xSuffix); - assure("getPresentation(): wrong", - "fooabcbar".equals(xMetaField.getPresentation(false))); + assertEquals("getPresentation(): wrong", + "fooabcbar", xMetaField.getPresentation(false)); inserter.insertRange( new Range(0, 0, text) ); } - public void testMetaFieldXPropertySet() throws Exception + @Test public void testMetaFieldXPropertySet() throws Exception { RangeInserter inserter = new RangeInserter(m_xDoc); TreeNode text = new TextNode("123"); @@ -3664,32 +3568,32 @@ public class TextPortionEnumerationTest extends ComplexTestCase XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xMetaField); - assure("PropertySet: not supported?", xPropertySet != null); + assertNotNull("PropertySet: not supported?", xPropertySet); XPropertySetInfo xPropertySetInfo = xPropertySet.getPropertySetInfo(); - assure("hasPropertyByName(\"NumberFormat\"):", - xPropertySetInfo.hasPropertyByName("NumberFormat")); - assure("hasPropertyByName(\"IsFixedLanguage\"):", - xPropertySetInfo.hasPropertyByName("IsFixedLanguage")); + assertTrue("hasPropertyByName(\"NumberFormat\"):", + xPropertySetInfo.hasPropertyByName("NumberFormat")); + assertTrue("hasPropertyByName(\"IsFixedLanguage\"):", + xPropertySetInfo.hasPropertyByName("IsFixedLanguage")); int def = (Integer) xPropertySet.getPropertyValue("NumberFormat"); - log.println("NumberFormat: default is " + def); + System.out.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); + assertEquals("NumberFormat: failed", INT, format); boolean isFixed = (Boolean) xPropertySet.getPropertyValue("IsFixedLanguage"); - assure("IsFixedLanguage: failed", isFixed); + assertTrue("IsFixedLanguage: failed", isFixed); } - public void testLoadStore() throws Exception + @Test public void testLoadStore() throws Exception { XComponent xComp = null; String filename = "TESTMETA.odt"; String file; try { - file = util.utils.getFullTestURL(filename); + file = TestDocument.getUrl(filename); xComp = doLoad(file); if (xComp != null) { @@ -3705,21 +3609,21 @@ public class TextPortionEnumerationTest extends ComplexTestCase private void doStore(XComponent xComp, String file) throws Exception { - log.println("Storing test document..."); + System.out.println("Storing test document..."); XStorable xStor = (XStorable) UnoRuntime.queryInterface( XStorable.class, xComp); xStor.storeToURL(file, new PropertyValue[0]); - log.println("...done"); + System.out.println("...done"); } public XComponent doLoad(String file) throws Exception { XComponent xComp = null; - log.println("Loading test document..."); + System.out.println("Loading test document..."); PropertyValue[] loadProps = new PropertyValue[1]; loadProps[0] = new PropertyValue(); @@ -3735,9 +3639,9 @@ public class TextPortionEnumerationTest extends ComplexTestCase XText xText = xTextDoc.getText(); - log.println("...done"); + System.out.println("...done"); - log.println("Checking meta(-field)s in loaded test document..."); + System.out.println("Checking meta(-field)s in loaded test document..."); TreeNode root = new TreeNode() .appendChild( new RubyNode("ruby1") @@ -3782,7 +3686,7 @@ public class TextPortionEnumerationTest extends ComplexTestCase .appendChild( new TextNode(" X X ") ); doTest(xTextDoc, root, false); - log.println("...done"); + System.out.println("...done"); return xComp; } @@ -3828,19 +3732,18 @@ public class TextPortionEnumerationTest extends ComplexTestCase XEnumerationAccess xEA = (XEnumerationAccess) UnoRuntime.queryInterface(XEnumerationAccess.class, xElement); XEnumeration xEnum = xEA.createEnumeration(); - TreeNode outtree = new EnumConverter(this).convert(xEnum); + TreeNode outtree = new EnumConverter().convert(xEnum); dumpTree(outtree, "O: "); - boolean success = new FuzzyTester(log).doTest(intree, outtree); - assure("test failed", success); + new FuzzyTester().doTest(intree, outtree); } private void dumpTree(TreeNode tree) { dumpTree(tree, "> "); } private void dumpTree(TreeNode tree, String prefix) { - log.println(prefix + tree.toString()); + System.out.println(prefix + tree.toString()); TreeNodeEnum children = tree.createEnumeration(); while (children.hasNext()) { TreeNode node = children.next(); @@ -3863,6 +3766,16 @@ public class TextPortionEnumerationTest extends ComplexTestCase return new StringPair("content.xml", id); } - public void assure(String str, boolean cond) { super.assure(str, cond); } + @BeforeClass public static void setUpConnection() throws Exception { + connection.setUp(); + } + + @AfterClass public static void tearDownConnection() + throws InterruptedException, com.sun.star.uno.Exception + { + connection.tearDown(); + } + + private static final OfficeConnection connection = new OfficeConnection(); } diff --git a/sw/qa/complex/writer/makefile.mk b/sw/qa/complex/writer/makefile.mk index ae2a15f821dd..550e9d64fd82 100755 --- a/sw/qa/complex/writer/makefile.mk +++ b/sw/qa/complex/writer/makefile.mk @@ -25,84 +25,32 @@ # #************************************************************************* -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 = +.IF "$(OOO_SUBSEQUENT_TESTS)" == "" +nothing .PHONY: .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 ------------------------------------------------------ +PRJ = ../../.. +PRJNAME = sw +TARGET = qa_complex_writer + +.IF "$(OOO_JUNIT_JAR)" != "" +PACKAGE = complex/writer +JAVATESTFILES = \ + CheckBookmarks.java \ + CheckCrossReferences.java \ + CheckFlies.java \ + CheckIndexedPropertyValues.java \ + CheckNamedPropertyValues.java \ + TextPortionEnumerationTest.java +JAVAFILES = $(JAVATESTFILES) TestDocument.java +JARFILES = OOoRunner.jar ridl.jar test.jar unoil.jar +EXTRAJARFILES = $(OOO_JUNIT_JAR) +.END -.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 +.INCLUDE: settings.mk +.INCLUDE: target.mk +.INCLUDE: installationtest.mk -TextPortionEnumerationTest: - +java -cp $(CLASSPATH) $(CT_APP) $(CT_APPEXECCOMMAND) $(CT_TESTBASE) -tdoc $(PWD)$/testdocuments $(CT_PACKAGE).TextPortionEnumerationTest +ALLTAR : javatest +.END |