incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1374156 - in /incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw: DocumentTest.java DocumentTest.odt DocumentTest.ott
Date Fri, 17 Aug 2012 06:27:59 GMT
Author: liuzhe
Date: Fri Aug 17 06:27:58 2012
New Revision: 1374156

URL: http://svn.apache.org/viewvc?rev=1374156&view=rev
Log:
#120561# - [testuno] - save document, export as pdf
Patch by: Xiao Xiao Ting <tingxiaox@gmail.com>
Review by: Liu Zhe <aliuzhe@gmail.com>

Added:
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.java
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.odt   (with
props)
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.ott   (with
props)

Added: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.java?rev=1374156&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.java (added)
+++ incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.java Fri Aug
17 06:27:58 2012
@@ -0,0 +1,232 @@
+package testcase.uno.sw;
+
+import static org.openoffice.test.common.Testspace.*;
+
+import java.io.File;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.Assert;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.uno.UnoApp;
+
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XText;
+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.lang.XComponent;
+
+
+public class DocumentTest {
+	UnoApp unoApp = new UnoApp();
+	XTextDocument textDocument = null;
+	File temp = null;
+	String workingFilePath = "";
+	String workingTemplatePath = "";
+	
+	/**
+	 * @throws java.lang.Exception
+	 */
+	@Before
+	public void setUp() throws Exception {
+		unoApp.start();
+		
+		FileUtil.deleteFile(getPath("temp"));
+		temp = new File(getPath("temp"));
+		temp.mkdirs();
+		
+		//copy sample file to temp folder
+		String originalFilePath = prepareData("testcase/uno/sw/DocumentTest.odt");	
+		String originalTemplatePath = prepareData("testcase/uno/sw/DocumentTest.ott");	
+		workingFilePath = temp + "/DocumentTest.odt";
+		workingTemplatePath = temp + "/DocumentTest.ott";
+		FileUtil.copyFile(new File(originalFilePath), new File(workingFilePath));	
+		FileUtil.copyFile(new File(originalTemplatePath), new File(workingTemplatePath));
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.close();
+	}	
+	
+	private XComponent newDocumentFromTemplate(String templatePath) throws Exception
+	{
+		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
unoApp.getDesktop());
+		PropertyValue[] pros = new PropertyValue[1];
+		pros[0] = new PropertyValue();
+		pros[0].Name = "AsTemplate";
+		pros[0].Value = new Boolean(true);		
+		
+		XComponent component = componentLoader.loadComponentFromURL(FileUtil.getUrl(workingTemplatePath),
"_blank", 0,pros);
+		return component;
+	}
+
+
+	@Test
+	public void testNewDocument() throws Exception
+	{
+		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
unoApp.getDesktop());		
+		XComponent component = componentLoader.loadComponentFromURL("private:factory/" + "swriter",
"_blank", 0, new PropertyValue[0]);
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument);
+		String title = xTitle.getTitle();
+		Assert.assertEquals("New Document title start with \"Untitled\"",true, title.startsWith("Untitled"));
+		unoApp.closeDocument(textDocument);
+	}
+	
+	
+	@Test
+	public void testNewDocumentFromTemplate() throws Exception
+	{		
+		XComponent component = this.newDocumentFromTemplate(workingTemplatePath);
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		XText xText = textDocument.getText();
+		XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument);
+		xText = textDocument.getText();
+		XTextCursor xTextCursor = xText.createTextCursor();	
+		xTextCursor.gotoEnd(true);		
+		XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,
xTextCursor);
+		String paraStyle = (String)xPropertySet.getPropertyValue("ParaStyleName");
+		
+        Assert.assertEquals("new document from template, heading style in template is remained.
", "Heading 1", paraStyle); 		
+        
+        Assert.assertEquals("new document from template, title start with \"Untitled\".",
true, xTitle.getTitle().startsWith("Untitled"));
+        
+        unoApp.closeDocument(textDocument);
+	}
+	
+	@Test
+	public void testSaveDocument() throws Exception
+	{			
+		XComponent component = unoApp.loadDocument(workingFilePath);
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		XText xText = textDocument.getText();
+		XTextCursor xTextCursor = xText.createTextCursor();	
+		xTextCursor.gotoEnd(true);		
+		XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,
xTextCursor);
+		
+		xPropertySet.setPropertyValue("ParaStyleName", "Heading 1");		
+		
+		XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, component);
+        xStorable.store();         
+        unoApp.closeDocument(textDocument);        
+       
+        component = unoApp.loadDocument(workingFilePath);
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		xText = textDocument.getText();
+		xTextCursor = xText.createTextCursor();	
+		xTextCursor.gotoEnd(true);		
+		xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
	
+		
+        Assert.assertEquals("Modify plain text to heading 1 style. ", "Heading 1", (String)xPropertySet.getPropertyValue("ParaStyleName"));
       
+        unoApp.closeDocument(textDocument);
+	}
+	
+	@Test
+	public void testSaveAsDocument() throws Exception
+	{		
+		File saveAsFile = new File(workingFilePath + ".doc");			
+		XComponent component = unoApp.loadDocument(workingFilePath);		
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		XText xText = textDocument.getText();
+		XTextCursor xTextCursor = xText.createTextCursor();		
+		XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,
xTextCursor);
+		
+		xPropertySet.setPropertyValue("ParaStyleName", "Heading 1");
+		xText.insertString(xTextCursor, "test Save odt as doc.", false);
+		
+		XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, component);
+        PropertyValue[] storeProps = new PropertyValue[2];
+        
+        storeProps[0] = new PropertyValue();
+        storeProps[0].Name = "Overwrite";
+        storeProps[0].Value = new Boolean(true);   
+        
+        storeProps[1] = new PropertyValue();
+        storeProps[1].Name = "FilterName";
+        storeProps[1].Value = "MS Word 97";
+        
+        xStorable.storeAsURL(FileUtil.getUrl(saveAsFile), storeProps);        
+        Assert.assertTrue("Save odt document as doc the file exist: " + saveAsFile.getAbsolutePath(),
saveAsFile.exists()); 
+        unoApp.closeDocument(textDocument);
+	}
+	
+	@Test
+	public void testExportAsPDF() throws Exception
+	{		
+		File saveAsFile = new File(workingFilePath + ".pdf");		
+		XComponent component = unoApp.loadDocument(workingFilePath);
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+				
+		XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, component);
+        PropertyValue[] storeProps = new PropertyValue[3];        
+        
+        storeProps[0] = new PropertyValue();
+        storeProps[0].Name = "Overwrite";
+        storeProps[0].Value = new Boolean(true);
+        
+        storeProps[1] = new PropertyValue();
+        storeProps[1].Name = "FilterName";
+        storeProps[1].Value = "writer_pdf_Export";  
+        
+        storeProps[2] = new PropertyValue();
+        storeProps[2].Name = "CompressionMode";
+        storeProps[2].Value = "1";         
+        
+        xStorable.storeToURL(FileUtil.getUrl(saveAsFile), storeProps); 
+       
+        Assert.assertTrue("Export document as PDF.", saveAsFile.exists()); 
+        
+        unoApp.closeDocument(textDocument);
+	}
+	
+	@Test
+	public void testSaveAsTemplate() throws Exception
+	{
+		File saveAsFile = new File(workingFilePath + ".ott");			
+		XComponent component = unoApp.loadDocument(workingFilePath);		
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		XText xText = textDocument.getText();
+		XTextCursor xTextCursor = xText.createTextCursor();	
+		xTextCursor.gotoEnd(true);		
+		XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,
xTextCursor);
+		
+		xPropertySet.setPropertyValue("ParaStyleName", "Heading 1");		
+		
+		XStorable xStorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, component);
+        xStorable.store();    
+        
+		PropertyValue[] storeProps = new PropertyValue[3];
+		storeProps[0] = new PropertyValue();
+		storeProps[0].Name="TemplateName";
+		storeProps[0].Value="MyNewCreatedTemplate";
+		
+		storeProps[1] = new PropertyValue();
+		storeProps[1].Name="TemplateRegionName";
+		storeProps[1].Value="My Templates";
+		
+		storeProps[2] = new PropertyValue();
+		storeProps[2].Name="AsTemplate";
+		storeProps[2].Value=new Boolean(true);
+		
+		xStorable.storeToURL(FileUtil.getUrl(saveAsFile), storeProps);
+		unoApp.closeDocument(textDocument);
+		
+		component = this.newDocumentFromTemplate(saveAsFile.getAbsolutePath());
+		textDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, component);
+		XTitle xTitle = (XTitle)UnoRuntime.queryInterface(XTitle.class, textDocument);		
+		xText = textDocument.getText();
+		xTextCursor = xText.createTextCursor();	
+		xTextCursor.gotoEnd(true);		
+		xPropertySet = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xTextCursor);
+		String paraStyle = (String)xPropertySet.getPropertyValue("ParaStyleName");
+		Assert.assertEquals("Save document as template, heading style is remained. ", "Heading
1", paraStyle); 		
+        Assert.assertEquals("Save document as template, title start with \"Untitled\".",
true, xTitle.getTitle().startsWith("Untitled"));        
+        unoApp.closeDocument(textDocument);
+	}
+
+}

Added: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.odt
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.odt?rev=1374156&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.odt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.ott
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.ott?rev=1374156&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sw/DocumentTest.ott
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message