Conversion.java (ef94b85d) Conversion.java (75ed6c31)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 21 unchanged lines hidden (view full) ---

30import org.junit.Before;
31import org.junit.BeforeClass;
32import org.junit.Rule;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35import org.openoffice.test.OpenOffice;
36import org.openoffice.test.common.DataSheet;
37import org.openoffice.test.common.FileProvider;
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 21 unchanged lines hidden (view full) ---

30import org.junit.Before;
31import org.junit.BeforeClass;
32import org.junit.Rule;
33import org.junit.Test;
34import org.junit.runner.RunWith;
35import org.openoffice.test.OpenOffice;
36import org.openoffice.test.common.DataSheet;
37import org.openoffice.test.common.FileProvider;
38import org.openoffice.test.common.SystemUtil;
39import org.openoffice.test.common.Testspace;
40import org.openoffice.test.common.FileProvider.FileFilter;
41import org.openoffice.test.common.FileProvider.FileRepeat;
42import org.openoffice.test.common.FileProvider.FileRepos;
43import org.openoffice.test.common.FileUtil;
44import org.openoffice.test.common.Logger;
38import org.openoffice.test.common.FileProvider.FileFilter;
39import org.openoffice.test.common.FileProvider.FileRepeat;
40import org.openoffice.test.common.FileProvider.FileRepos;
41import org.openoffice.test.common.FileUtil;
42import org.openoffice.test.common.Logger;
43import org.openoffice.test.common.Testspace;
45import org.openoffice.test.uno.UnoApp;
44import org.openoffice.test.uno.UnoApp;
45
46import com.sun.star.beans.PropertyValue;
47import com.sun.star.document.MacroExecMode;
48import com.sun.star.lang.XComponent;
49import com.sun.star.uno.UnoRuntime;
50import com.sun.star.util.XCloseable;
51
52
53@RunWith(FileProvider.class)
54public class Conversion {
55
56 @Rule
57 public Logger log = Logger.getLogger(this);
58
59 @FileRepos
46import com.sun.star.beans.PropertyValue;
47import com.sun.star.document.MacroExecMode;
48import com.sun.star.lang.XComponent;
49import com.sun.star.uno.UnoRuntime;
50import com.sun.star.util.XCloseable;
51
52
53@RunWith(FileProvider.class)
54public class Conversion {
55
56 @Rule
57 public Logger log = Logger.getLogger(this);
58
59 @FileRepos
60 public static String repos = System.getProperty("conversion.repos", getDataPath("conversion_pvt"));
60 public static String repos = System.getProperty("conversion.repos", getDataPath("uno"));
61 @FileFilter
62 public static String filter = System.getProperty("conversion.filter",
63 "-f .*(doc|dot|odt|ott)$ writer_pdf_Export pdf "
64 + "-f .*(xls|xlt|ods|ots)$ calc_pdf_Export pdf "
65 + "-f .*(ppt|ppt|odp|otp)$ impress_pdf_Export pdf "
66 + "-f .*(doc|dot|docx|docm|dotx|dotm)$ writer8 odt "
67 + "-f .*(xls|xlt|xlsx|xltx|xlsm|xltm)$ calc8 ods "
68 + "-f .*(ppt|pot|pptx|pptm|potm|potx)$ impress8 odp "
69 + "-f .*(odt|ott)$ 'MS Word 97' doc "
70 + "-f .*(ods|ots)$ 'MS Excel 97' xls "
71 + "-f .*(odp|otp)$ 'MS PowerPoint 97' ppt");
72
73 @FileRepeat
74 public static int repeat = Integer.parseInt(System.getProperty("conversion.repeat", "8"));
75
76 public static String clean = System.getProperty("conversion.clean", "file");
77
78 public static int nLevelInfo = Integer.parseInt(System.getProperty("conversion.limitationcheck", "0")); // Level info: starts from 1, 0 means no need for limitation check
79
61 @FileFilter
62 public static String filter = System.getProperty("conversion.filter",
63 "-f .*(doc|dot|odt|ott)$ writer_pdf_Export pdf "
64 + "-f .*(xls|xlt|ods|ots)$ calc_pdf_Export pdf "
65 + "-f .*(ppt|ppt|odp|otp)$ impress_pdf_Export pdf "
66 + "-f .*(doc|dot|docx|docm|dotx|dotm)$ writer8 odt "
67 + "-f .*(xls|xlt|xlsx|xltx|xlsm|xltm)$ calc8 ods "
68 + "-f .*(ppt|pot|pptx|pptm|potm|potx)$ impress8 odp "
69 + "-f .*(odt|ott)$ 'MS Word 97' doc "
70 + "-f .*(ods|ots)$ 'MS Excel 97' xls "
71 + "-f .*(odp|otp)$ 'MS PowerPoint 97' ppt");
72
73 @FileRepeat
74 public static int repeat = Integer.parseInt(System.getProperty("conversion.repeat", "8"));
75
76 public static String clean = System.getProperty("conversion.clean", "file");
77
78 public static int nLevelInfo = Integer.parseInt(System.getProperty("conversion.limitationcheck", "0")); // Level info: starts from 1, 0 means no need for limitation check
79
80 public static int nSleep = Integer.parseInt(System.getProperty("conversion.sleep", "3")); // Sleep before loadComponentFromURL and storeToURL
80 public static long nSleep = Long.parseLong(System.getProperty("conversion.sleep", "0")); // Sleep before loadComponentFromURL and storeToURL
81
82 private static OpenOffice aoo = new OpenOffice();
83
84 private static UnoApp app = null;
85
86 private static DataSheet result;
87
88 private static int counter = 0;
89
90 @BeforeClass
91 public static void beforeClass() throws Exception {
92 aoo.setUnoUrl(OpenOffice.DEFAULT_UNO_URL);
93 aoo.addArgs("-invisible", "-conversionmode", "-hidemenu", "-nofirststartwizard");
94 app = new UnoApp(aoo);
95 Testspace.prepareDataFile("limit_cfg.ini", aoo.getHome().toString()+"/program"); // Move limitation check file to installation dir
96 result = new DataSheet(getFile("output/" + Conversion.class.getName()+ ".xml"));
81
82 private static OpenOffice aoo = new OpenOffice();
83
84 private static UnoApp app = null;
85
86 private static DataSheet result;
87
88 private static int counter = 0;
89
90 @BeforeClass
91 public static void beforeClass() throws Exception {
92 aoo.setUnoUrl(OpenOffice.DEFAULT_UNO_URL);
93 aoo.addArgs("-invisible", "-conversionmode", "-hidemenu", "-nofirststartwizard");
94 app = new UnoApp(aoo);
95 Testspace.prepareDataFile("limit_cfg.ini", aoo.getHome().toString()+"/program"); // Move limitation check file to installation dir
96 result = new DataSheet(getFile("output/" + Conversion.class.getName()+ ".xml"));
97 result.addRow("data", "File","Scenario","File Size","No","Time Consumed After Closing","Time Consumed After Saving","Time Consumed After Loading");
97 result.addRow("data", "File","Scenario", "No", "Time Consumed After Closing","Time Consumed After Saving","Time Consumed After Loading", "File Size", "Exported File Size");
98 }
99
100 @AfterClass
101 public static void afterClass() throws Exception {
102 app.close();
103 }
104
105 private String sourcePath = null;

--- 31 unchanged lines hidden (view full) ---

137 String pathRepos = new File(repos).getCanonicalPath().replace("\\", "/") + "/";
138 sourceFileId = pathSource.replace(pathRepos, "");
139 log.info("Start [File: " + sourceFileId + "] [Size: " + (sourceFile.length() / 1024) + "KB] [Scenario: " + scenario + "]");
140 app.start();
141 }
142
143 @After
144 public void after() throws Exception{
98 }
99
100 @AfterClass
101 public static void afterClass() throws Exception {
102 app.close();
103 }
104
105 private String sourcePath = null;

--- 31 unchanged lines hidden (view full) ---

137 String pathRepos = new File(repos).getCanonicalPath().replace("\\", "/") + "/";
138 sourceFileId = pathSource.replace(pathRepos, "");
139 log.info("Start [File: " + sourceFileId + "] [Size: " + (sourceFile.length() / 1024) + "KB] [Scenario: " + scenario + "]");
140 app.start();
141 }
142
143 @After
144 public void after() throws Exception{
145 result.addRow("data", sourceFileId, scenario, sourceFile.length(), counter % repeat , closeTime, saveTime, loadTime);
145 result.addRow("data", sourceFileId, scenario, counter % repeat , closeTime, saveTime, loadTime, sourceFile.length(), targetFile.length());
146 log.info("Result [After Closing: " + closeTime + "] [After Saving: " + saveTime + "] [After Loading: " + loadTime + "]");
147 if (closeTime < 0) {
148 app.close();
149 } else if ("file".equalsIgnoreCase(clean) && counter % repeat == 0) {
150 app.close();
151 }
152 }
153
154 private PropertyValue propertyValue(String name, Object value) {
155 PropertyValue p = new PropertyValue();
156 p.Name = name;
157 p.Value= value;
158 return p;
159 }
146 log.info("Result [After Closing: " + closeTime + "] [After Saving: " + saveTime + "] [After Loading: " + loadTime + "]");
147 if (closeTime < 0) {
148 app.close();
149 } else if ("file".equalsIgnoreCase(clean) && counter % repeat == 0) {
150 app.close();
151 }
152 }
153
154 private PropertyValue propertyValue(String name, Object value) {
155 PropertyValue p = new PropertyValue();
156 p.Name = name;
157 p.Value= value;
158 return p;
159 }
160
160
161 @Test(timeout=10 * 60000)
162 public void testConversion() throws Exception {
163 try {
161
162 @Test(timeout=10 * 60000)
163 public void testConversion() throws Exception {
164 try {
164 // convert
165 SystemUtil.sleep(nSleep); // Sleep before loadComponentFromURL
165 if (nSleep > 0)
166 Thread.sleep(nSleep);
166 long start = System.currentTimeMillis();
167 XComponent doc = app.loadDocumentFromURL(sourceFileUrl,
168 propertyValue("Hidden", true),
169 propertyValue("ReadOnly", true),
170 propertyValue("AsyncMode", false),
171 propertyValue("MacroExecutionMode", MacroExecMode.NEVER_EXECUTE),
172 propertyValue("LimitationCheckLevel", nLevelInfo));
173
174 loadTime = System.currentTimeMillis() - start;
175
167 long start = System.currentTimeMillis();
168 XComponent doc = app.loadDocumentFromURL(sourceFileUrl,
169 propertyValue("Hidden", true),
170 propertyValue("ReadOnly", true),
171 propertyValue("AsyncMode", false),
172 propertyValue("MacroExecutionMode", MacroExecMode.NEVER_EXECUTE),
173 propertyValue("LimitationCheckLevel", nLevelInfo));
174
175 loadTime = System.currentTimeMillis() - start;
176
176 SystemUtil.sleep(nSleep); // Sleep before storeToURL
177 if (nSleep > 0)
178 Thread.sleep(nSleep);
177 app.saveDocumentToURL(doc, targetFileUrl,
178 propertyValue( "FilterName", targetFilterName),
179 propertyValue( "Overwrite", true));
180 saveTime = System.currentTimeMillis() - start - nSleep;
181 XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, doc);
182 xCloseable.close(true);
183 closeTime = System.currentTimeMillis() - start - nSleep;
184 } catch (com.sun.star.task.ErrorCodeIOException e){
185 int errCode = e.ErrCode;
186 if( 296 == errCode ) {
187 loadTime = -2;
188 saveTime = -2;
189 closeTime = -2;
190 }
191
192 throw e;
193 }
194 }
195}
179 app.saveDocumentToURL(doc, targetFileUrl,
180 propertyValue( "FilterName", targetFilterName),
181 propertyValue( "Overwrite", true));
182 saveTime = System.currentTimeMillis() - start - nSleep;
183 XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, doc);
184 xCloseable.close(true);
185 closeTime = System.currentTimeMillis() - start - nSleep;
186 } catch (com.sun.star.task.ErrorCodeIOException e){
187 int errCode = e.ErrCode;
188 if( 296 == errCode ) {
189 loadTime = -2;
190 saveTime = -2;
191 closeTime = -2;
192 }
193
194 throw e;
195 }
196 }
197}