poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject cvs commit: jakarta-poi/src/testcases/org/apache/poi/hpsf/basic TestWrite.java
Date Wed, 03 Dec 2003 20:00:14 GMT
klute       2003/12/03 12:00:14

  Modified:    src/contrib/src/org/apache/poi/contrib/poibrowser Codec.java
               src/java/org/apache/poi/hpsf SummaryInformation.java
                        VariantSupport.java
               src/testcases/org/apache/poi/hpsf/basic TestWrite.java
  Log:
  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!
  
  Revision  Changes    Path
  1.6       +1 -5      jakarta-poi/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java
  
  Index: Codec.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/contrib/src/org/apache/poi/contrib/poibrowser/Codec.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Codec.java	13 Sep 2003 12:15:38 -0000	1.5
  +++ Codec.java	3 Dec 2003 20:00:14 -0000	1.6
  @@ -90,10 +90,6 @@
   
       /**
        * <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)
       {
  
  
  
  1.14      +6 -6      jakarta-poi/src/java/org/apache/poi/hpsf/SummaryInformation.java
  
  Index: SummaryInformation.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hpsf/SummaryInformation.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- SummaryInformation.java	13 Sep 2003 12:31:28 -0000	1.13
  +++ SummaryInformation.java	3 Dec 2003 20:00:14 -0000	1.14
  @@ -310,12 +310,12 @@
        * 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>
        */
  
  
  
  1.7       +1 -9      jakarta-poi/src/java/org/apache/poi/hpsf/VariantSupport.java
  
  Index: VariantSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hpsf/VariantSupport.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- VariantSupport.java	2 Dec 2003 17:46:01 -0000	1.6
  +++ VariantSupport.java	3 Dec 2003 20:00:14 -0000	1.7
  @@ -230,7 +230,6 @@
                   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 @@
               }
           }
   
  -        /* Add 0x00 characters to write a multiple of four bytes: */
  -        // FIXME (1) Try this!
  -//        while (length % 4 != 0)
  -//        {
  -//            out.write(0);
  -//            length++;
  -//        }
           return length;
       }
   
  
  
  
  1.9       +72 -15    jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
  
  Index: TestWrite.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestWrite.java	2 Dec 2003 17:46:01 -0000	1.8
  +++ TestWrite.java	3 Dec 2003 20:00:14 -0000	1.9
  @@ -65,6 +65,7 @@
   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 @@
       {
           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 @@
               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 @@
               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 (Exception ex)
  +            {
  +                t = ex;
               }
  -            catch (IOException ex2)
  +            catch (Error ex)
               {
  -                t.printStackTrace();
  +                t = ex;
               }
  -            fail(sw.toString());
  +            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 @@
           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 " +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org


Mime
View raw message