Kaydet (Commit) 9c297922 authored tarafından Liu Zhe's avatar Liu Zhe

#120703 - [testuno] - insert, delete of page break and line break

Patch by: Xiao Xiao Ting <tingxiaox@gmail.com>
Review by: Liu Zhe <aliuzhe@gmail.com>
üst 0c8ea0f2
......@@ -18,7 +18,10 @@ import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.*;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.util.XCloseable;
import com.sun.star.lang.XComponent;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.container.XEnumeration;
public class DocumentTest {
......@@ -66,6 +69,23 @@ public class DocumentTest {
}
/**
* test close document
* @throws Exception
*/
@Test
public void testCloseDocument() throws Exception
{
XComponent component = unoApp.newDocument("swriter");
unoApp.closeDocument(component);
XModel xModel = unoApp.getDesktop().getCurrentFrame().getController().getModel();
Assert.assertTrue("Document has been closed.",xModel==null);
}
/**
* test new document
* @throws Exception
*/
@Test
public void testNewDocument() throws Exception
{
......@@ -78,7 +98,10 @@ public class DocumentTest {
unoApp.closeDocument(textDocument);
}
/**
* test new document from template
* @throws Exception
*/
@Test
public void testNewDocumentFromTemplate() throws Exception
{
......@@ -99,6 +122,10 @@ public class DocumentTest {
unoApp.closeDocument(textDocument);
}
/**
* test save document as odt
* @throws Exception
*/
@Test
public void testSaveDocument() throws Exception
{
......@@ -126,6 +153,10 @@ public class DocumentTest {
unoApp.closeDocument(textDocument);
}
/**
* test save document as doc
* @throws Exception
*/
@Test
public void testSaveAsDocument() throws Exception
{
......@@ -155,6 +186,10 @@ public class DocumentTest {
unoApp.closeDocument(textDocument);
}
/**
* test export document as pdf
* @throws Exception
*/
@Test
public void testExportAsPDF() throws Exception
{
......@@ -184,6 +219,10 @@ public class DocumentTest {
unoApp.closeDocument(textDocument);
}
/**
* test save document as template
* @throws Exception
*/
@Test
public void testSaveAsTemplate() throws Exception
{
......
......@@ -25,16 +25,22 @@ import org.openoffice.test.uno.UnoApp;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XEnumeration;
import com.sun.star.container.XEnumerationAccess;
import com.sun.star.container.XNamed;
import com.sun.star.document.XDocumentInfo;
import com.sun.star.document.XDocumentInfoSupplier;
import com.sun.star.frame.XStorable;
import com.sun.star.io.IOException;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.style.BreakType;
import com.sun.star.text.ControlCharacter;
import com.sun.star.text.XText;
import com.sun.star.text.XTextContent;
import com.sun.star.text.XTextCursor;
import com.sun.star.text.XTextDocument;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XController;
import com.sun.star.uno.UnoRuntime;
public class SWUtil {
......@@ -133,4 +139,50 @@ public class SWUtil {
xBookmarkAsNamed.setName(bookmarkName);
document.getText().insertTextContent(textCursor, xBookmarkAsTextContent, true);
}
/**
* insert column break in current cursor
* @param xText
* @param currentCursor
* @throws Exception
*/
public static void insertColumnBreak(XText xText, XTextCursor currentCursor) throws Exception
{
XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, currentCursor);
xCursorProps.setPropertyValue("BreakType", BreakType.COLUMN_AFTER);
xText.insertControlCharacter(currentCursor,ControlCharacter.PARAGRAPH_BREAK,false);
}
/**
* insert page break in current cursor
* @param xText
* @param currentCursor
* @throws Exception
*/
public static void insertPageBreak(XText xText, XTextCursor currentCursor) throws Exception
{
XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface(
XPropertySet.class, currentCursor);
xCursorProps.setPropertyValue("BreakType", BreakType.PAGE_AFTER);
xText.insertControlCharacter(currentCursor,ControlCharacter.PARAGRAPH_BREAK,false);
}
/**
* get page count
* @param document
* @return
* @throws Exception
*/
public static int getPageCount(XTextDocument document) throws Exception
{
XModel xmodel = (XModel)UnoRuntime.queryInterface(XModel.class, document);
XController xcont = xmodel.getCurrentController();
XPropertySet xps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xcont);
Integer pageCount = (Integer) xps.getPropertyValue("PageCount");
return pageCount.intValue();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment