diff options
author | Rainer Klute <klute@apache.org> | 2003-12-03 20:00:14 +0000 |
---|---|---|
committer | Rainer Klute <klute@apache.org> | 2003-12-03 20:00:14 +0000 |
commit | 5ec57813ec28b75f654c7a0af82e6c0e522de9d9 (patch) | |
tree | 94ae3cd423a4210ae18bd0ff7de7a2485dc73f99 /src/testcases/org/apache/poi/hpsf | |
parent | 319c1c1fe8c3ee2a9fc1f08ce8b8a515450215f6 (diff) | |
download | poi-5ec57813ec28b75f654c7a0af82e6c0e522de9d9.tar.gz poi-5ec57813ec28b75f654c7a0af82e6c0e522de9d9.zip |
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
Diffstat (limited to 'src/testcases/org/apache/poi/hpsf')
-rw-r--r-- | src/testcases/org/apache/poi/hpsf/basic/TestWrite.java | 85 |
1 files changed, 71 insertions, 14 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java index 95b78ea66b..609f0358af 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java @@ -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 + { + 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 (Exception ex) + { + t = ex; + } + 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 { - 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); + fail("UnsupportedEncodingException for codepage " + codepage + + " expected."); } - catch (IOException ex2) + catch (UnsupportedEncodingException ex) { - t.printStackTrace(); + /* This is the expected behaviour. */ } - fail(sw.toString()); + 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 " + |