Author: liuzhe Date: Tue Sep 11 07:57:50 2012 New Revision: 1383278 URL: http://svn.apache.org/viewvc?rev=1383278&view=rev Log: Use FileProvider runner instead of Parameterized
Modified: incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java Modified: 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=1383278&r1=1383277&r2=1383278&view=diff ============================================================================== --- incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java (original) +++ incubator/ooo/trunk/test/testuno/source/testcase/uno/pvt/Conversion.java Tue Sep 11 07:57:50 2012 @@ -21,12 +21,11 @@ package testcase.uno.pvt; +import static org.openoffice.test.common.Testspace.*; + import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import org.junit.After; import org.junit.AfterClass; @@ -34,12 +33,11 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.rules.Timeout; 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.FileProvider; +import org.openoffice.test.common.FileProvider.FileFilter; +import org.openoffice.test.common.FileProvider.FileRepos; import org.openoffice.test.common.FileUtil; import org.openoffice.test.common.Logger; import org.openoffice.test.common.Testspace; @@ -52,63 +50,29 @@ import com.sun.star.uno.UnoRuntime; import com.sun.star.util.XCloseable; -@RunWith(Parameterized.class) +@RunWith(FileProvider.class) public class Conversion { - @Rule - public TestRule timeout = new Timeout(10 * 60000); - + @Rule public Logger log = Logger.getLogger(this); - public static File repos = Testspace.getFile("pvt_conversion_data"); + @FileRepos + public static String repos = getDataFile("pvt_conversion").getAbsolutePath(); - 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)|(docx)|(docm)|(dotx)|(dotm))$", "writer8", "odt", - ".*\\.((xls)|(xlt)|(xlsx)|(xltx)|(xlsm)|(xltm))$", "calc8", "ods", - ".*\\.((ppt)|(pot)|(pptx)|(pptm)|(potm)|(potx))$", "impress8", "odp", - ".*\\.((odt)|(ott))$", "MS Word 97", "doc", - ".*\\.((ods)|(ots))$", "MS Excel 97", "xls", - ".*\\.((odp)|(otp))$", "MS PowerPoint 97", "ppt", - }; + @FileFilter + public static String filter = "-f .*\\.((doc)|(dot)|(odt)|(ott))$ writer_pdf_Export pdf " + + "-f .*\\.((xls)|(xlt)|(ods)|(ots))$ calc_pdf_Export pdf " + + "-f .*\\.((ppt)|(ppt)|(odp)|(otp))$ impress_pdf_Export pdf " + + "-f .*\\.((doc)|(dot)|(docx)|(docm)|(dotx)|(dotm))$ writer8 odt " + + "-f .*\\.((xls)|(xlt)|(xlsx)|(xltx)|(xlsm)|(xltm))$ calc8 ods " + + "-f .*\\.((ppt)|(pot)|(pptx)|(pptm)|(potm)|(potx))$ impress8 odp " + + "-f .*\\.((odt)|(ott))$ 'MS Word 97' doc " + + "-f .*\\.((ods)|(ots))$ 'MS Excel 97' xls " + + "-f .*\\.((odp)|(otp))$ 'MS PowerPoint 97' ppt"; private static UnoApp app = new UnoApp(); + private static PrintStream result; - @Parameters - public static Collection<Object[]> data() { - ArrayList<Object[]> list = new ArrayList<Object[]>(); - collect(repos, list); - return list; - } - - /** - * @param dir - * @param list - */ - public static void collect(File dir, ArrayList<Object[]> list) { - File[] files = dir.listFiles(); - if (files == null) - return; - Arrays.sort(files); - 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 { @@ -128,30 +92,38 @@ public class Conversion { app.close(); } + private String sourcePath = null; + private String targetFilterName = null; + private String targetExtName = null; + private File sourceFile = null; private File targetFile = null; private String sourceFileUrl = null; private String targetFileUrl = null; - private String targetFilterName = null; + private String scenario = null; private String sourceFileId = null; private long loadTime = -1; private long saveTime = -1; private long closeTime = -1; - public Conversion(File sourceFile, File targetFile, String targetFilterName) { + public Conversion(String sourcePath, String targetFilterName, String targetExtName) { super(); - this.sourceFile = sourceFile; - this.targetFile = targetFile; + this.sourcePath = sourcePath; this.targetFilterName = targetFilterName; - sourceFileUrl = FileUtil.getUrl(this.sourceFile); - targetFileUrl = FileUtil.getUrl(this.targetFile); - scenario = FileUtil.getFileExtName(sourceFile.getName()).toLowerCase() + " to " + FileUtil.getFileExtName(targetFile.getName()).toLowerCase(); - sourceFileId = sourceFile.getAbsolutePath().replace(repos.getAbsolutePath(), "").replace("\\", "/"); + this.targetExtName = targetExtName; } @Before public void before() throws Exception { + sourceFile = prepareDataFile(sourcePath); + sourceFileUrl = FileUtil.getUrl(this.sourceFile); + targetFile = getFile("classtemp/" + sourceFile.getName()+ "." + targetExtName); + targetFileUrl = FileUtil.getUrl(this.targetFile); + + scenario = FileUtil.getFileExtName(sourceFile.getName()).toLowerCase() + " to " + FileUtil.getFileExtName(targetFile.getName()).toLowerCase(); + sourceFileId = sourceFile.getAbsolutePath().replace(new File(repos).getAbsolutePath(), "").replace("\\", "/"); + log.info("Start [File: " + sourceFileId + "] [Size: " + (sourceFile.length() / 1024) + "KB] [Scenario: " + scenario + "]"); app.start(); } @@ -172,7 +144,7 @@ public class Conversion { return p; } - @Test + @Test(timeout=10 * 60000) public void testConversion() throws Exception { // convert long start = System.currentTimeMillis();