< prev index next >

test/sun/nio/cs/FindDecoderBugs.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6380723
  27  * @summary Decode many byte sequences in many ways


  28  * @run main/timeout=1800 FindDecoderBugs
  29  * @author Martin Buchholz
  30  * @key randomness
  31  */
  32 
  33 import java.util.*;
  34 import java.util.regex.*;
  35 import java.nio.*;
  36 import java.nio.charset.*;

  37 
  38 public class FindDecoderBugs {
  39 
  40     static boolean isBroken(String csn) {
  41         if (csn.equals("x-COMPOUND_TEXT")) return true;
  42         return false;
  43     }
  44 
  45     static <T extends Comparable<? super T>> List<T> sort(Collection<T> c) {
  46         List<T> list = new ArrayList<T>(c);
  47         Collections.sort(list);
  48         return list;
  49     }
  50 
  51     static class TooManyFailures extends RuntimeException {
  52         private static final long serialVersionUID = 0L;
  53     }
  54 
  55     static String string(byte[] a) {
  56         final StringBuilder sb = new StringBuilder();


 305                 test(ia);
 306             }
 307         }
 308 
 309         void testPrefix(byte[] prefix) {
 310             if (prefix.length > 0)
 311                 System.out.printf("Testing prefix %s%n", string(prefix));
 312 
 313             test(prefix);
 314 
 315             testExhaustively(prefix, 1);
 316             testExhaustively(prefix, 2);
 317             // Can you spare a week of CPU time?
 318             // testExhaustively(cs, tester, prefix, 3);
 319 
 320             testRandomly(prefix, 3);
 321             testRandomly(prefix, 4);
 322         }
 323     }
 324 
 325     private final static Random rnd = new Random();
 326     private static byte randomByte() {
 327         return (byte) rnd.nextInt(0x100);
 328     }
 329     private static byte[] randomBytes(int len) {
 330         byte[] a = new byte[len];
 331         for (int i = 0; i < len; i++)
 332             a[i] = randomByte();
 333         return a;
 334     }
 335 
 336     private static final byte SS2 = (byte) 0x8e;
 337     private static final byte SS3 = (byte) 0x8f;
 338     private static final byte ESC = (byte) 0x1b;
 339     private static final byte SO  = (byte) 0x0e;
 340     private static final byte SI  = (byte) 0x0f;
 341 
 342     private final static byte[][] stateChangers = {
 343         {SS2}, {SS3}, {SO}, {SI}
 344     };
 345 




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 6380723
  27  * @summary Decode many byte sequences in many ways (use -Dseed=X to set PRNG seed)
  28  * @library /lib/testlibrary
  29  * @build jdk.testlibrary.*
  30  * @run main/timeout=1800 FindDecoderBugs
  31  * @author Martin Buchholz
  32  * @key intermittent randomness
  33  */
  34 
  35 import java.util.*;
  36 import java.util.regex.*;
  37 import java.nio.*;
  38 import java.nio.charset.*;
  39 import jdk.testlibrary.RandomFactory;
  40 
  41 public class FindDecoderBugs {
  42 
  43     static boolean isBroken(String csn) {
  44         if (csn.equals("x-COMPOUND_TEXT")) return true;
  45         return false;
  46     }
  47 
  48     static <T extends Comparable<? super T>> List<T> sort(Collection<T> c) {
  49         List<T> list = new ArrayList<T>(c);
  50         Collections.sort(list);
  51         return list;
  52     }
  53 
  54     static class TooManyFailures extends RuntimeException {
  55         private static final long serialVersionUID = 0L;
  56     }
  57 
  58     static String string(byte[] a) {
  59         final StringBuilder sb = new StringBuilder();


 308                 test(ia);
 309             }
 310         }
 311 
 312         void testPrefix(byte[] prefix) {
 313             if (prefix.length > 0)
 314                 System.out.printf("Testing prefix %s%n", string(prefix));
 315 
 316             test(prefix);
 317 
 318             testExhaustively(prefix, 1);
 319             testExhaustively(prefix, 2);
 320             // Can you spare a week of CPU time?
 321             // testExhaustively(cs, tester, prefix, 3);
 322 
 323             testRandomly(prefix, 3);
 324             testRandomly(prefix, 4);
 325         }
 326     }
 327 
 328     private final static Random rnd = RandomFactory.getRandom();
 329     private static byte randomByte() {
 330         return (byte) rnd.nextInt(0x100);
 331     }
 332     private static byte[] randomBytes(int len) {
 333         byte[] a = new byte[len];
 334         for (int i = 0; i < len; i++)
 335             a[i] = randomByte();
 336         return a;
 337     }
 338 
 339     private static final byte SS2 = (byte) 0x8e;
 340     private static final byte SS3 = (byte) 0x8f;
 341     private static final byte ESC = (byte) 0x1b;
 342     private static final byte SO  = (byte) 0x0e;
 343     private static final byte SI  = (byte) 0x0f;
 344 
 345     private final static byte[][] stateChangers = {
 346         {SS2}, {SS3}, {SO}, {SI}
 347     };
 348 


< prev index next >