incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1381966 - in /incubator/ooo/trunk/test/testuno: ./ source/org/openoffice/test/uno/UnoApp.java source/testcase/uno/pvt/ source/testcase/uno/pvt/Conversion.java
Date Fri, 07 Sep 2012 09:47:36 GMT
Author: liuzhe
Date: Fri Sep  7 09:47:36 2012
New Revision: 1381966

URL: http://svn.apache.org/viewvc?rev=1381966&view=rev
Log:
"One test class for performance test"

Added:
    incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/
    incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java
Modified:
    incubator/ooo/trunk/test/testuno/   (props changed)
    incubator/ooo/trunk/test/testuno/source/org/openoffice/test/uno/UnoApp.java

Propchange: incubator/ooo/trunk/test/testuno/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Sep  7 09:47:36 2012
@@ -1 +1,2 @@
 .classpath
+bin

Modified: incubator/ooo/trunk/test/testuno/source/org/openoffice/test/uno/UnoApp.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/org/openoffice/test/uno/UnoApp.java?rev=1381966&r1=1381965&r2=1381966&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/org/openoffice/test/uno/UnoApp.java (original)
+++ incubator/ooo/trunk/test/testuno/source/org/openoffice/test/uno/UnoApp.java Fri Sep  7
09:47:36 2012
@@ -78,6 +78,15 @@ public class UnoApp {
 	 * Start OpenOffice and connect to it
 	 */
 	public void start() {
+		if (componentContext != null) {
+			try {
+				componentContext.getServiceManager();
+				return;
+			} catch (Exception e) {
+				
+			}
+		}
+		
 		if (openOffice != null) {
 			openOffice.start();
 			unoUrl = openOffice.getUnoUrl();
@@ -154,15 +163,24 @@ public class UnoApp {
 		return desktop;
 	}
 
-	public XComponent loadDocument(String file) throws Exception {
+//	public XComponent loadDocument(String file) throws Exception {
+//		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
desktop);
+//		return componentLoader.loadComponentFromURL(FileUtil.getUrl(file), "_blank", 0, new PropertyValue[0]);
+//	}
+	
+	public XComponent loadDocument(String file, PropertyValue... propertyValue) throws Exception
{
 		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
desktop);
-		return componentLoader.loadComponentFromURL(FileUtil.getUrl(file), "_blank", 0, new PropertyValue[0]);
+		return componentLoader.loadComponentFromURL(FileUtil.getUrl(file), "_blank", 0, propertyValue);
 	}
 	
+//	public XComponent loadDocumentFromURL(String url) throws Exception {
+//		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
desktop);
+//		return componentLoader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
+//	}
 	
-	public XComponent loadDocumentFromURL(String url) throws Exception {
+	public XComponent loadDocumentFromURL(String url, PropertyValue... propertyValue) throws
Exception {
 		XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class,
desktop);
-		return componentLoader.loadComponentFromURL(url, "_blank", 0, new PropertyValue[0]);
+		return componentLoader.loadComponentFromURL(url, "_blank", 0, propertyValue);
 	}
 	
 	public XComponent newDocument(String type) throws Exception {
@@ -170,10 +188,21 @@ public class UnoApp {
 		return componentLoader.loadComponentFromURL("private:factory/" + type, "_blank", 0, new
PropertyValue[0]);
 	}
 	
-	public void saveDocument(XComponent doc, String toPath) throws Exception {
+//	public void saveDocument(XComponent doc, String toPath) throws Exception {
+//		XStorable m_xstorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, doc);	
+//		String fileUrl = FileUtil.getUrl(new File(toPath));	
+//		m_xstorable.storeAsURL(fileUrl, new PropertyValue[0]);
+//	}
+	
+	public void saveDocument(XComponent doc, String toPath, PropertyValue... propertyValue)
throws Exception {
 		XStorable m_xstorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, doc);	
 		String fileUrl = FileUtil.getUrl(new File(toPath));	
-		m_xstorable.storeAsURL(fileUrl, new PropertyValue[0]);
+		m_xstorable.storeToURL(fileUrl, propertyValue);
+	}
+	
+	public void saveDocumentToURL(XComponent doc, String toURL, PropertyValue... propertyValue)
throws Exception {
+		XStorable m_xstorable = (XStorable)UnoRuntime.queryInterface(XStorable.class, doc);	
+		m_xstorable.storeToURL(toURL, propertyValue);
 	}
 	
 	public void closeDocument(XComponent doc) {

Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java?rev=1381966&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java Fri Sep  7 09:47:36
2012
@@ -0,0 +1,184 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+package testcase.uno.pvt;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.OpenOffice;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Logger;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.document.MacroExecMode;
+import com.sun.star.lang.XComponent;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.XCloseable;
+
+
+@RunWith(Parameterized.class)
+public class Conversion {
+	@Rule
+	public Logger log = Logger.getLogger(this);
+	
+	public static String repos = System.getProperty("user.home") + "/pvt_conversion_data";
+
+	public static String[] params = {
+		".*\\.((doc)|(dot)|(odt)|(ott))$", "writer_pdf_Export", "pdf", 
+		".*\\.((xls)|(xlt)|(ods)|(ots))$", "calc_pdf_Export", "pdf", 
+		".*\\.((ppt)|(ppt)|(odp)|(otp))$", "impress_pdf_Export", "pdf", 
+		".*\\.((doc)|(dot))$", "writer8", "odt", 
+		".*\\.((xls)|(xlt))$", "calc8", "ods", 
+		".*\\.((ppt)|(ppt))$", "impress8", "odp", 
+		".*\\.((odt)|(ott))$", "MS Word 97", "doc", 
+		".*\\.((ods)|(ots))$", "MS Excel 97", "xls", 
+		".*\\.((odp)|(otp))$", "MS PowerPoint 97", "ppt", 
+		};
+
+	private static UnoApp app = new UnoApp();
+	private static PrintStream result;
+	@Parameters
+	public static Collection<Object[]> data() {
+		File dir = new File(repos);
+		ArrayList<Object[]> list = new ArrayList<Object[]>();
+		collect(dir, list);
+		return list;
+	}
+
+	/**
+	 * @param dir
+	 * @param list
+	 */
+	public static void collect(File dir, ArrayList<Object[]> list) {
+		File[] files = dir.listFiles();
+		if (files == null)
+			return;
+
+		for (File file : files) {
+			if (file.isDirectory()) {
+				collect(file, list);
+			} else {
+				String fileName = file.getName().toLowerCase();
+				for (int i = 0; i < params.length;) {
+					String pattern = params[i++];
+					String targetFilterName = params[i++];
+					String targetExtName = params[i++];
+					if (pattern != null && fileName.matches(pattern)) {
+						Object[] data = {file, Testspace.getFile("classtemp/" + file.getName()+ "." + targetExtName),
targetFilterName};
+						list.add(data);
+					}
+				}
+			}
+		}
+	}
+	
+	@BeforeClass
+	public static void beforeClass() throws Exception {
+		//Disable automation
+		OpenOffice.getDefault().setAutomationPort(-1);
+		OpenOffice.getDefault().addArgs("-invisible", "-conversionmode", "-headless", "-hidemenu");
+
+		File resultFile = Testspace.getFile("output/conversion.csv");
+		resultFile.getParentFile().mkdirs();
+		result = new PrintStream(new FileOutputStream(resultFile));
+		result.println("File,Scenario,After Close,After Save,After Load");
+	}
+	
+	@AfterClass
+	public static void afterClass() throws Exception {
+		result.close();
+	}
+	
+	@Before
+	public void before() throws Exception {
+		app.start();
+	}
+	
+	@After
+	public void after() throws Exception{
+		String scenario = FileUtil.getFileExtName(sourceFile.getName()).toLowerCase() + " to "
+ FileUtil.getFileExtName(targetFile.getName()).toLowerCase();
+		result.println(sourceFile.getName() + "," + scenario + "," + closeTime + "," + saveTime
+ "," + loadTime);
+		if (closeTime < 0) {
+			log.warning("Exception occurs during " + sourceFile.getName() + "->" + targetFile.getName());
+			app.close();
+		}
+	}
+	
+	private File sourceFile = null;
+	private File targetFile = null;
+	private String sourceFileUrl = null;
+	private String targetFileUrl = null;
+	private String targetFilterName = null;
+	private long loadTime = -1;
+	private long saveTime = -1;
+	private long closeTime = -1;
+	
+	public Conversion(File sourceFile, File targetFile, String targetFilterName) {
+		super();
+		this.sourceFile = sourceFile;
+		this.targetFile = targetFile;
+		this.targetFilterName = targetFilterName;
+		sourceFileUrl = FileUtil.getUrl(this.sourceFile);
+		targetFileUrl = FileUtil.getUrl(this.targetFile);
+	}
+	
+	private PropertyValue propertyValue(String name, Object value) {
+		PropertyValue p = new PropertyValue();
+		p.Name = name;
+		p.Value= value;
+		return p;
+	}
+	
+	@Test
+	public void testConversion() throws Exception {
+		// convert
+		long start = System.currentTimeMillis();
+		XComponent doc = app.loadDocumentFromURL(sourceFileUrl, 
+				propertyValue("Hidden", true),
+				propertyValue("ReadOnly", true),
+				propertyValue("AsyncMode", false),
+				propertyValue("MacroExecutionMode", MacroExecMode.NEVER_EXECUTE));
+
+		loadTime = System.currentTimeMillis() - start;
+		app.saveDocumentToURL(doc, targetFileUrl, 
+				propertyValue( "FilterName", targetFilterName),
+				propertyValue( "Overwrite", true));
+		saveTime = System.currentTimeMillis() - start;
+		XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, doc);
+		xCloseable.close(true);
+		closeTime = System.currentTimeMillis() - start;
+	}
+}



Mime
View raw message