< prev index next >

test/java/util/regex/RegExTest.java

Print this page
rev 12323 : [mq]: 6854417-RegExTest-java-fails-intermittently
   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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  * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
  27  * @author Mike McCloskey
  28  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  29  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  35  * 8027645 8035076 8039124 8035975 8074678
  36  * @library /lib/testlibrary
  37  * @build jdk.testlibrary.*
  38  * @run main RegExTest
  39  * @key intermittent randomness
  40  */
  41 
  42 import java.util.function.Function;
  43 import java.util.regex.*;
  44 import java.util.Random;
  45 import java.io.*;
  46 import java.util.*;
  47 import java.nio.CharBuffer;
  48 import java.util.function.Predicate;
  49 import jdk.testlibrary.RandomFactory;
  50 
  51 /**
  52  * This is a test class created to check the operation of
  53  * the Pattern and Matcher classes.
  54  */
  55 public class RegExTest {
  56 
  57     private static Random generator = RandomFactory.getRandom();
  58     private static boolean failure = false;
  59     private static int failCount = 0;


3537 
3538     /**
3539      * Tests the Boyer-Moore pattern matching of a character sequence
3540      * on randomly generated patterns.
3541      */
3542     private static void bm() throws Exception {
3543         doBnM('a');
3544         report("Boyer Moore (ASCII)");
3545 
3546         doBnM(Character.MIN_SUPPLEMENTARY_CODE_POINT - 10);
3547         report("Boyer Moore (Supplementary)");
3548     }
3549 
3550     private static void doBnM(int baseCharacter) throws Exception {
3551         int achar=0;
3552 
3553         for (int i=0; i<100; i++) {
3554             // Create a short pattern to search for
3555             int patternLength = generator.nextInt(7) + 4;
3556             StringBuffer patternBuffer = new StringBuffer(patternLength);


3557             for (int x=0; x<patternLength; x++) {
3558                 int ch = baseCharacter + generator.nextInt(26);
3559                 if (Character.isSupplementaryCodePoint(ch)) {
3560                     patternBuffer.append(Character.toChars(ch));
3561                 } else {
3562                     patternBuffer.append((char)ch);
3563                 }
3564             }
3565             String pattern =  patternBuffer.toString();









3566             Pattern p = Pattern.compile(pattern);
3567 
3568             // Create a buffer with random ASCII chars that does
3569             // not match the sample
3570             String toSearch = null;
3571             StringBuffer s = null;
3572             Matcher m = p.matcher("");
3573             do {
3574                 s = new StringBuffer(100);
3575                 for (int x=0; x<100; x++) {
3576                     int ch = baseCharacter + generator.nextInt(26);
3577                     if (Character.isSupplementaryCodePoint(ch)) {
3578                         s.append(Character.toChars(ch));
3579                     } else {
3580                         s.append((char)ch);
3581                     }
3582                 }
3583                 toSearch = s.toString();
3584                 m.reset(toSearch);
3585             } while (m.find());


   1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   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  * @summary tests RegExp framework (use -Dseed=X to set PRNG seed)
  27  * @author Mike McCloskey
  28  * @bug 4481568 4482696 4495089 4504687 4527731 4599621 4631553 4619345
  29  * 4630911 4672616 4711773 4727935 4750573 4792284 4803197 4757029 4808962
  30  * 4872664 4803179 4892980 4900747 4945394 4938995 4979006 4994840 4997476
  31  * 5013885 5003322 4988891 5098443 5110268 6173522 4829857 5027748 6376940
  32  * 6358731 6178785 6284152 6231989 6497148 6486934 6233084 6504326 6635133
  33  * 6350801 6676425 6878475 6919132 6931676 6948903 6990617 7014645 7039066
  34  * 7067045 7014640 7189363 8007395 8013252 8013254 8012646 8023647 6559590
  35  * 8027645 8035076 8039124 8035975 8074678 6854417
  36  * @library /lib/testlibrary
  37  * @build jdk.testlibrary.*
  38  * @run main RegExTest
  39  * @key randomness
  40  */
  41 
  42 import java.util.function.Function;
  43 import java.util.regex.*;
  44 import java.util.Random;
  45 import java.io.*;
  46 import java.util.*;
  47 import java.nio.CharBuffer;
  48 import java.util.function.Predicate;
  49 import jdk.testlibrary.RandomFactory;
  50 
  51 /**
  52  * This is a test class created to check the operation of
  53  * the Pattern and Matcher classes.
  54  */
  55 public class RegExTest {
  56 
  57     private static Random generator = RandomFactory.getRandom();
  58     private static boolean failure = false;
  59     private static int failCount = 0;


3537 
3538     /**
3539      * Tests the Boyer-Moore pattern matching of a character sequence
3540      * on randomly generated patterns.
3541      */
3542     private static void bm() throws Exception {
3543         doBnM('a');
3544         report("Boyer Moore (ASCII)");
3545 
3546         doBnM(Character.MIN_SUPPLEMENTARY_CODE_POINT - 10);
3547         report("Boyer Moore (Supplementary)");
3548     }
3549 
3550     private static void doBnM(int baseCharacter) throws Exception {
3551         int achar=0;
3552 
3553         for (int i=0; i<100; i++) {
3554             // Create a short pattern to search for
3555             int patternLength = generator.nextInt(7) + 4;
3556             StringBuffer patternBuffer = new StringBuffer(patternLength);
3557             String pattern;
3558             retry: for (;;) {
3559                 for (int x=0; x<patternLength; x++) {
3560                     int ch = baseCharacter + generator.nextInt(26);
3561                     if (Character.isSupplementaryCodePoint(ch)) {
3562                         patternBuffer.append(Character.toChars(ch));
3563                     } else {
3564                         patternBuffer.append((char)ch);
3565                     }
3566                 }
3567                 pattern = patternBuffer.toString();
3568 
3569                 // Avoid patterns that start and end with the same substring
3570                 // See JDK-6854417
3571                 for (int x=1; x <patternLength; x++) {
3572                     if (pattern.startsWith(pattern.substring(x)))
3573                         continue retry;
3574                 }
3575                 break;
3576             }
3577             Pattern p = Pattern.compile(pattern);
3578 
3579             // Create a buffer with random ASCII chars that does
3580             // not match the sample
3581             String toSearch = null;
3582             StringBuffer s = null;
3583             Matcher m = p.matcher("");
3584             do {
3585                 s = new StringBuffer(100);
3586                 for (int x=0; x<100; x++) {
3587                     int ch = baseCharacter + generator.nextInt(26);
3588                     if (Character.isSupplementaryCodePoint(ch)) {
3589                         s.append(Character.toChars(ch));
3590                     } else {
3591                         s.append((char)ch);
3592                     }
3593                 }
3594                 toSearch = s.toString();
3595                 m.reset(toSearch);
3596             } while (m.find());


< prev index next >