Fix unit tests broken by newly added test-file, ignore TestFontRendering as it is inherently unstable currently
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568744 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7e63803aa9
commit
dcad3624dc
@ -41,6 +41,7 @@ import javax.imageio.ImageIO;
|
|||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hslf.model.Slide;
|
import org.apache.poi.hslf.model.Slide;
|
||||||
import org.apache.poi.hslf.model.TextPainter;
|
import org.apache.poi.hslf.model.TextPainter;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,6 +50,7 @@ import org.junit.Test;
|
|||||||
public class TestFontRendering {
|
public class TestFontRendering {
|
||||||
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
|
||||||
|
|
||||||
|
@Ignore("This fails on some systems because fonts are rendered slightly different")
|
||||||
@Test
|
@Test
|
||||||
public void bug55902mixedFontWithChineseCharacters() throws Exception {
|
public void bug55902mixedFontWithChineseCharacters() throws Exception {
|
||||||
// font files need to be downloaded first via
|
// font files need to be downloaded first via
|
||||||
|
@ -58,13 +58,7 @@ public class TestReadAllFiles extends TestCase {
|
|||||||
public boolean accept(final File f)
|
public boolean accept(final File f)
|
||||||
{
|
{
|
||||||
// exclude files that we know will fail
|
// exclude files that we know will fail
|
||||||
for(String exclude : excludes) {
|
return f.isFile() && checkExclude(f);
|
||||||
if(f.getAbsolutePath().endsWith(exclude)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return f.isFile();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -86,4 +80,20 @@ public class TestReadAllFiles extends TestCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the file should be checked, false if it should be excluded.
|
||||||
|
*
|
||||||
|
* @param f
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean checkExclude(File f) {
|
||||||
|
for(String exclude : excludes) {
|
||||||
|
if(f.getAbsolutePath().endsWith(exclude)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,43 +17,16 @@
|
|||||||
|
|
||||||
package org.apache.poi.hpsf.basic;
|
package org.apache.poi.hpsf.basic;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hpsf.ClassID;
|
import org.apache.poi.hpsf.*;
|
||||||
import org.apache.poi.hpsf.HPSFRuntimeException;
|
|
||||||
import org.apache.poi.hpsf.IllegalPropertySetDataException;
|
|
||||||
import org.apache.poi.hpsf.MutableProperty;
|
|
||||||
import org.apache.poi.hpsf.MutablePropertySet;
|
|
||||||
import org.apache.poi.hpsf.MutableSection;
|
|
||||||
import org.apache.poi.hpsf.NoFormatIDException;
|
|
||||||
import org.apache.poi.hpsf.NoPropertySetStreamException;
|
|
||||||
import org.apache.poi.hpsf.PropertySet;
|
|
||||||
import org.apache.poi.hpsf.PropertySetFactory;
|
|
||||||
import org.apache.poi.hpsf.ReadingNotSupportedException;
|
|
||||||
import org.apache.poi.hpsf.Section;
|
|
||||||
import org.apache.poi.hpsf.SummaryInformation;
|
|
||||||
import org.apache.poi.hpsf.UnsupportedVariantTypeException;
|
|
||||||
import org.apache.poi.hpsf.Variant;
|
|
||||||
import org.apache.poi.hpsf.VariantSupport;
|
|
||||||
import org.apache.poi.hpsf.WritingNotSupportedException;
|
|
||||||
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
|
import org.apache.poi.hpsf.wellknown.PropertyIDMap;
|
||||||
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
||||||
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
|
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
|
||||||
@ -63,6 +36,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
|||||||
import org.apache.poi.util.CodePageUtil;
|
import org.apache.poi.util.CodePageUtil;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
import org.apache.poi.util.TempFile;
|
import org.apache.poi.util.TempFile;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Tests HPSF's writing functionality.</p>
|
* <p>Tests HPSF's writing functionality.</p>
|
||||||
@ -665,19 +639,26 @@ public class TestWrite extends TestCase
|
|||||||
* the origin file and check whether they are equal.</p></li>
|
* the origin file and check whether they are equal.</p></li>
|
||||||
*
|
*
|
||||||
* </ul>
|
* </ul>
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testRecreate()
|
public void testRecreate() throws IOException
|
||||||
{
|
{
|
||||||
final File dataDir = _samples.getFile("");
|
final File dataDir = _samples.getFile("");
|
||||||
final File[] fileList = dataDir.listFiles(new FileFilter()
|
final File[] fileList = dataDir.listFiles(new FileFilter()
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
public boolean accept(final File f)
|
public boolean accept(final File f)
|
||||||
{
|
{
|
||||||
return f.getName().startsWith("Test");
|
return f.getName().startsWith("Test") && TestReadAllFiles.checkExclude(f);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for (int i = 0; i < fileList.length; i++)
|
for (int i = 0; i < fileList.length; i++) {
|
||||||
|
try {
|
||||||
testRecreate(fileList[i]);
|
testRecreate(fileList[i]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException("While handling file " + fileList[i], e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -687,10 +668,10 @@ public class TestWrite extends TestCase
|
|||||||
* POI filesystem.</p>
|
* POI filesystem.</p>
|
||||||
*
|
*
|
||||||
* @param f the POI filesystem to check
|
* @param f the POI filesystem to check
|
||||||
|
* @throws IOException
|
||||||
|
* @throws HPSFException
|
||||||
*/
|
*/
|
||||||
private void testRecreate(final File f)
|
private void testRecreate(final File f) throws IOException, HPSFException
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
/* Read the POI filesystem's property set streams: */
|
/* Read the POI filesystem's property set streams: */
|
||||||
final POIFile[] psf1 = Util.readPropertySets(f);
|
final POIFile[] psf1 = Util.readPropertySets(f);
|
||||||
@ -736,20 +717,15 @@ public class TestWrite extends TestCase
|
|||||||
assertEquals("Equality for file " + f.getName(), ps1, ps2);
|
assertEquals("Equality for file " + f.getName(), ps1, ps2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
handle(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Tests writing and reading back a proper dictionary.</p>
|
* <p>Tests writing and reading back a proper dictionary.</p>
|
||||||
|
* @throws IOException
|
||||||
|
* @throws HPSFException
|
||||||
*/
|
*/
|
||||||
public void testDictionary()
|
public void testDictionary() throws IOException, HPSFException
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
|
final File copy = TempFile.createTempFile("Test-HPSF", "ole2");
|
||||||
copy.deleteOnExit();
|
copy.deleteOnExit();
|
||||||
@ -787,19 +763,16 @@ public class TestWrite extends TestCase
|
|||||||
* from the origin file and check whether they are equal. */
|
* from the origin file and check whether they are equal. */
|
||||||
assertEquals(ps1, ps2);
|
assertEquals(ps1, ps2);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
handle(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Tests writing and reading back a proper dictionary with an invalid
|
* <p>Tests writing and reading back a proper dictionary with an invalid
|
||||||
* codepage. (HPSF writes Unicode dictionaries only.)</p>
|
* codepage. (HPSF writes Unicode dictionaries only.)</p>
|
||||||
|
* @throws IOException
|
||||||
|
* @throws HPSFException
|
||||||
*/
|
*/
|
||||||
public void testDictionaryWithInvalidCodepage()
|
public void testDictionaryWithInvalidCodepage() throws IOException, HPSFException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -829,44 +802,6 @@ public class TestWrite extends TestCase
|
|||||||
{
|
{
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
handle(ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Handles unexpected exceptions in testcases.</p>
|
|
||||||
*
|
|
||||||
* @param ex The exception that has been thrown.
|
|
||||||
*/
|
|
||||||
private void handle(final Exception ex)
|
|
||||||
{
|
|
||||||
final StringWriter sw = new StringWriter();
|
|
||||||
final PrintWriter pw = new PrintWriter(sw);
|
|
||||||
Throwable t = ex;
|
|
||||||
while (t != null)
|
|
||||||
{
|
|
||||||
t.printStackTrace(pw);
|
|
||||||
if (t instanceof HPSFRuntimeException)
|
|
||||||
t = ((HPSFRuntimeException) t).getReason();
|
|
||||||
else
|
|
||||||
t = null;
|
|
||||||
if (t != null)
|
|
||||||
pw.println("Caused by:");
|
|
||||||
}
|
|
||||||
pw.close();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
sw.close();
|
|
||||||
}
|
|
||||||
catch (IOException ex2)
|
|
||||||
{
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
fail(sw.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,26 +32,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hpsf.CustomProperties;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hpsf.CustomProperty;
|
import org.apache.poi.hpsf.*;
|
||||||
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
|
||||||
import org.apache.poi.hpsf.MarkUnsupportedException;
|
|
||||||
import org.apache.poi.hpsf.MutableProperty;
|
|
||||||
import org.apache.poi.hpsf.MutableSection;
|
|
||||||
import org.apache.poi.hpsf.NoPropertySetStreamException;
|
|
||||||
import org.apache.poi.hpsf.PropertySet;
|
|
||||||
import org.apache.poi.hpsf.PropertySetFactory;
|
|
||||||
import org.apache.poi.hpsf.SummaryInformation;
|
|
||||||
import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
|
|
||||||
import org.apache.poi.hpsf.Variant;
|
|
||||||
import org.apache.poi.hpsf.VariantSupport;
|
|
||||||
import org.apache.poi.hpsf.WritingNotSupportedException;
|
|
||||||
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
import org.apache.poi.hpsf.wellknown.SectionIDMap;
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
||||||
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
import org.apache.poi.poifs.filesystem.DocumentEntry;
|
||||||
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
import org.apache.poi.poifs.filesystem.DocumentInputStream;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.POIDataSamples;
|
|
||||||
import org.apache.poi.util.TempFile;
|
import org.apache.poi.util.TempFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +56,7 @@ public class TestWriteWellKnown extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* @see TestCase#setUp()
|
* @see TestCase#setUp()
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void setUp()
|
public void setUp()
|
||||||
{
|
{
|
||||||
VariantSupport.setLogUnsupportedTypes(false);
|
VariantSupport.setLogUnsupportedTypes(false);
|
||||||
@ -92,12 +80,16 @@ public class TestWriteWellKnown extends TestCase {
|
|||||||
final File dataDir = _samples.getFile("");
|
final File dataDir = _samples.getFile("");
|
||||||
final File[] docs = dataDir.listFiles(new FileFilter()
|
final File[] docs = dataDir.listFiles(new FileFilter()
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
public boolean accept(final File file)
|
public boolean accept(final File file)
|
||||||
{
|
{
|
||||||
return file.isFile() && file.getName().startsWith("Test");
|
return file.isFile() && file.getName().startsWith("Test") && TestReadAllFiles.checkExclude(file);
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
for (int i = 0; i < docs.length; i++)
|
for (int i = 0; i < docs.length; i++)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
final File doc = docs[i];
|
final File doc = docs[i];
|
||||||
|
|
||||||
/* Read a test document <em>doc</em> into a POI filesystem. */
|
/* Read a test document <em>doc</em> into a POI filesystem. */
|
||||||
@ -145,6 +137,9 @@ public class TestWriteWellKnown extends TestCase {
|
|||||||
dsi.getScale();
|
dsi.getScale();
|
||||||
dsi.getSlideCount();
|
dsi.getSlideCount();
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException("While handling file " + docs[i], e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,6 +582,7 @@ public class TestWriteWellKnown extends TestCase {
|
|||||||
{
|
{
|
||||||
final AllDataFilesTester.TestTask task = new AllDataFilesTester.TestTask()
|
final AllDataFilesTester.TestTask task = new AllDataFilesTester.TestTask()
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
public void runTest(final File file) throws FileNotFoundException,
|
public void runTest(final File file) throws FileNotFoundException,
|
||||||
IOException, NoPropertySetStreamException,
|
IOException, NoPropertySetStreamException,
|
||||||
MarkUnsupportedException,
|
MarkUnsupportedException,
|
||||||
@ -638,15 +634,20 @@ public class TestWriteWellKnown extends TestCase {
|
|||||||
final File dataDir = _samples.getFile("");
|
final File dataDir = _samples.getFile("");
|
||||||
final File[] docs = dataDir.listFiles(new FileFilter()
|
final File[] docs = dataDir.listFiles(new FileFilter()
|
||||||
{
|
{
|
||||||
|
@Override
|
||||||
public boolean accept(final File file)
|
public boolean accept(final File file)
|
||||||
{
|
{
|
||||||
return file.isFile() && file.getName().startsWith("Test");
|
return file.isFile() && file.getName().startsWith("Test") && TestReadAllFiles.checkExclude(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i = 0; i < docs.length; i++)
|
for (int i = 0; i < docs.length; i++)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
task.runTest(docs[i]);
|
task.runTest(docs[i]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IOException("While handling file " + docs[i], e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user