HPSF: new testcase to check the new codepage support - plus a fix to correct a bug detected by the testcase. Hey, that's what testcases are good for!

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353461 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Rainer Klute 2003-12-03 20:00:14 +00:00
parent 131bb9d0bd
commit a914cfc17c
4 changed files with 76 additions and 31 deletions

View File

@ -90,10 +90,6 @@ public class Codec
/**
* <p>Converts a string into its hexadecimal notation.</p>
*
* <p><strong>FIXME:</strong> If this method is called frequently,
* it should directly implement the algorithm in the called method
* in order to avoid creating a string instance.</p>
*/
public static String hexEncode(final String s)
{

View File

@ -310,12 +310,12 @@ public class SummaryInformation extends SpecialPropertySet
* WMF or Clipboard (BMP?) format. He also provided two links that
* might be helpful: <a
* href="http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch"
* target="_blank">http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch
* </a> and <a
* target="_blank">http://www.csn.ul.ie/~caolan/publink/file/OLE2SummaryAgainst_file-3.27.patch</a>
* and <a
* href="http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp"
* target="_blank">http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp
* </a>. However, we won't do any conversion into any image type
* but instead just return a byte array.</p>
* target="_blank">http://msdn.microsoft.com/library/en-us/dno97ta/html/msdn_docprop.asp</a>.
* However, we won't do any conversion into any image type but instead just
* return a byte array.</p>
*
* @return The thumbnail or <code>null</code>
*/

View File

@ -230,7 +230,6 @@ public class VariantSupport extends Variant
final int first = o1 + LittleEndian.INT_SIZE;
long last = first + LittleEndian.getUInt(src, o1) - 1;
o1 += LittleEndian.INT_SIZE;
final int rawLength = (int) (last - first + 1);
while (src[(int) last] == 0 && first <= last)
last--;
final int l = (int) (last - first + 1);
@ -454,13 +453,6 @@ public class VariantSupport extends Variant
}
}
/* Add 0x00 characters to write a multiple of four bytes: */
// FIXME (1) Try this!
// while (length % 4 != 0)
// {
// out.write(0);
// length++;
// }
return length;
}

View File

@ -65,6 +65,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -402,7 +403,6 @@ public class TestWrite extends TestCase
{
Throwable t = null;
final int codepage = -1;
/* FIXME (2): Add tests for various codepages! */
try
{
check(Variant.VT_EMPTY, null, codepage);
@ -414,8 +414,8 @@ public class TestWrite extends TestCase
check(Variant.VT_CF, new byte[]{0, 1, 2, 3}, codepage);
check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4}, codepage);
check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage);
check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
codepage);
check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage);
check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage);
check(Variant.VT_I2, new Integer(27), codepage);
check(Variant.VT_I4, new Long(28), codepage);
check(Variant.VT_FILETIME, new Date(), codepage);
@ -445,21 +445,80 @@ public class TestWrite extends TestCase
t = ex;
}
if (t != null)
fail(org.apache.poi.hpsf.Util.toString(t));
}
/**
* <p>Writes and reads back strings using several different codepages and
* checks whether the stuff that has been read back equals the stuff that
* was written.</p>
*/
public void testCodepages()
{
Throwable t = null;
final int[] validCodepages = new int[] {-1, 1252, 1200, 65001};
for (int i = 0; i < validCodepages.length; i++)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
int codepage = validCodepages[i];
try
{
sw.close();
check(Variant.VT_LPSTR, "", codepage);
check(Variant.VT_LPSTR, "ä", codepage);
check(Variant.VT_LPSTR, "äö", codepage);
check(Variant.VT_LPSTR, "äöü", codepage);
check(Variant.VT_LPSTR, "äöüÄ", codepage);
check(Variant.VT_LPSTR, "äöüÄÖ", codepage);
check(Variant.VT_LPSTR, "äöüÄÖÜ", codepage);
check(Variant.VT_LPSTR, "äöüÄÖÜß", codepage);
check(Variant.VT_LPSTR, "\u79D1\u5B78", codepage);
}
catch (IOException ex2)
catch (Exception ex)
{
t.printStackTrace();
t = ex;
}
fail(sw.toString());
catch (Error ex)
{
t = ex;
}
if (t != null)
fail(org.apache.poi.hpsf.Util.toString(t));
}
final int[] invalidCodepages = new int[] {0, 1, 2, 4711, 815};
for (int i = 0; i < invalidCodepages.length; i++)
{
int codepage = invalidCodepages[i];
try
{
check(Variant.VT_LPSTR, "", codepage);
check(Variant.VT_LPSTR, "ä", codepage);
check(Variant.VT_LPSTR, "äö", codepage);
check(Variant.VT_LPSTR, "äöü", codepage);
check(Variant.VT_LPSTR, "äöüÄ", codepage);
check(Variant.VT_LPSTR, "äöüÄÖ", codepage);
check(Variant.VT_LPSTR, "äöüÄÖÜ", codepage);
check(Variant.VT_LPSTR, "äöüÄÖÜß", codepage);
fail("UnsupportedEncodingException for codepage " + codepage +
" expected.");
}
catch (UnsupportedEncodingException ex)
{
/* This is the expected behaviour. */
}
catch (Exception ex)
{
t = ex;
}
catch (Error ex)
{
t = ex;
}
if (t != null)
fail(org.apache.poi.hpsf.Util.toString(t));
}
}
@ -482,11 +541,9 @@ public class TestWrite extends TestCase
final byte[] b = out.toByteArray();
final Object objRead =
VariantSupport.read(b, 0, b.length + LittleEndian.INT_SIZE,
variantType, -1);
variantType, codepage);
if (objRead instanceof byte[])
{
// final int diff = diff(org.apache.poi.hpsf.Util.pad4
// ((byte[]) value), (byte[]) objRead);
final int diff = diff((byte[]) value, (byte[]) objRead);
if (diff >= 0)
fail("Byte arrays are different. First different byte is at " +