< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/StringIndexOfTestBase.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 package org.graalvm.compiler.replacements.test;
  26 


  27 import org.graalvm.compiler.core.test.GraalCompilerTest;
  28 import org.junit.Test;
  29 import org.junit.runner.RunWith;
  30 import org.junit.runners.Parameterized;
  31 
  32 import java.util.ArrayList;
  33 import java.util.Collection;

  34 
  35 @RunWith(value = Parameterized.class)
  36 public abstract class StringIndexOfTestBase extends GraalCompilerTest {
  37     @Parameterized.Parameter(value = 0) public String sourceString;
  38     @Parameterized.Parameter(value = 1) public String constantString;
  39 
  40     @Parameterized.Parameters(name = "{0},{1}")
  41     public static Collection<Object[]> data() {
  42         ArrayList<Object[]> tests = new ArrayList<>();
  43         String[] targets = new String[]{"foobar", "foo", "bar"};
  44         String[] utf16targets = new String[]{"grga " + ((char) 0x10D) + "varak", "grga", ((char) 0x10D) + "varak"};
  45         addTargets(tests, targets);
  46         addTargets(tests, utf16targets);



















  47         return tests;
  48     }
  49 
  50     private static void addTargets(ArrayList<Object[]> tests, String[] targets) {
  51         for (String source : targets) {
  52             for (String target : targets) {
  53                 tests.add(new Object[]{source, target});
  54             }
  55             tests.add(new Object[]{source, ""});
  56             tests.add(new Object[]{"", source});
  57             tests.add(new Object[]{"", ""});
  58         }
  59         for (String source : targets) {
  60             String s = "";
  61             for (int i = 0; i < 10; i++) {
  62                 s = s + source.substring(0, source.length() - 1);
  63             }
  64             for (String target : targets) {
  65                 tests.add(new Object[]{s, target});
  66                 tests.add(new Object[]{s + target, target});


  82     }
  83 
  84     public int testStringBuilderIndexOfOffset(StringBuilder a, String b, int fromIndex) {
  85         return a.indexOf(b, fromIndex);
  86     }
  87 
  88     @Test
  89     public void testStringIndexOfConstant() {
  90         test("testStringIndexOf", new Object[]{this.sourceString, this.constantString});
  91     }
  92 
  93     @Test
  94     public void testStringIndexOfConstantOffset() {
  95         test("testStringIndexOfOffset", new Object[]{this.sourceString, this.constantString, -1});
  96         test("testStringIndexOfOffset", new Object[]{this.sourceString, this.constantString, 0});
  97         test("testStringIndexOfOffset", new Object[]{this.sourceString, this.constantString, Math.max(0, sourceString.length() - constantString.length())});
  98     }
  99 
 100     @Test
 101     public void testStringBuilderIndexOfConstant() {

 102         /*
 103          * Put a copy of the target string in the space after the current string to detect cases
 104          * where we search too far.
 105          */
 106         StringBuilder sb = new StringBuilder(this.sourceString);
 107         sb.append(constantString);
 108         sb.setLength(sourceString.length());
 109         test("testStringBuilderIndexOf", new Object[]{sb, this.constantString});
 110     }
 111 
 112     @Test
 113     public void testStringBuilderIndexOfConstantOffset() {

 114         /*
 115          * Put a copy of the target string in the space after the current string to detect cases
 116          * where we search too far.
 117          */
 118         StringBuilder sb = new StringBuilder(this.sourceString);
 119         sb.append(constantString);
 120         sb.setLength(sourceString.length());
 121         test("testStringBuilderIndexOfOffset", new Object[]{sb, this.constantString, -1});
 122         test("testStringBuilderIndexOfOffset", new Object[]{sb, this.constantString, 0});
 123         test("testStringBuilderIndexOfOffset", new Object[]{sb, this.constantString, Math.max(0, sourceString.length() - constantString.length())});
 124     }
 125 }


   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 package org.graalvm.compiler.replacements.test;
  26 
  27 import static org.junit.Assume.assumeFalse;
  28 
  29 import org.graalvm.compiler.core.test.GraalCompilerTest;
  30 import org.junit.Test;
  31 import org.junit.runner.RunWith;
  32 import org.junit.runners.Parameterized;
  33 
  34 import java.util.ArrayList;
  35 import java.util.Collection;
  36 import jdk.vm.ci.aarch64.AArch64;
  37 
  38 @RunWith(value = Parameterized.class)
  39 public abstract class StringIndexOfTestBase extends GraalCompilerTest {
  40     @Parameterized.Parameter(value = 0) public String sourceString;
  41     @Parameterized.Parameter(value = 1) public String constantString;
  42 
  43     @Parameterized.Parameters(name = "{0},{1}")
  44     public static Collection<Object[]> data() {
  45         ArrayList<Object[]> tests = new ArrayList<>();
  46         String[] targets = new String[]{"foobar", "foo", "bar"};
  47         String[] utf16targets = new String[]{"grga " + ((char) 0x10D) + "varak", "grga", ((char) 0x10D) + "varak"};
  48         addTargets(tests, targets);
  49         addTargets(tests, utf16targets);
  50 
  51         // Check long targets
  52         // Checkstyle: stop
  53         String lipsum = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata ";
  54         // Checkstyle: resume
  55         String lipsumUTF16 = lipsum + ((char) 0x10D);
  56         int[] subStringLengths = {7, 8, 15, 16, 31, 32, 63, 64};
  57         for (int len : subStringLengths) {
  58             String target = lipsum.substring(50, 50 + len);
  59             tests.add(new Object[]{lipsum, target});
  60             tests.add(new Object[]{lipsum, target + "X"});
  61             tests.add(new Object[]{lipsumUTF16, target});
  62             tests.add(new Object[]{lipsumUTF16, target + "X"});
  63             tests.add(new Object[]{lipsumUTF16, target + ((char) 0x10D)});
  64         }
  65         tests.add(new Object[]{
  66                         "\u0100\u0101\u0102\u0103\u0104\u0105\u0106\u0107\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff\u0108\u0109\u010a\u010b\u010c",
  67                         "\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u00ff"});
  68 
  69         return tests;
  70     }
  71 
  72     private static void addTargets(ArrayList<Object[]> tests, String[] targets) {
  73         for (String source : targets) {
  74             for (String target : targets) {
  75                 tests.add(new Object[]{source, target});
  76             }
  77             tests.add(new Object[]{source, ""});
  78             tests.add(new Object[]{"", source});
  79             tests.add(new Object[]{"", ""});
  80         }
  81         for (String source : targets) {
  82             String s = "";
  83             for (int i = 0; i < 10; i++) {
  84                 s = s + source.substring(0, source.length() - 1);
  85             }
  86             for (String target : targets) {
  87                 tests.add(new Object[]{s, target});
  88                 tests.add(new Object[]{s + target, target});


 104     }
 105 
 106     public int testStringBuilderIndexOfOffset(StringBuilder a, String b, int fromIndex) {
 107         return a.indexOf(b, fromIndex);
 108     }
 109 
 110     @Test
 111     public void testStringIndexOfConstant() {
 112         test("testStringIndexOf", new Object[]{this.sourceString, this.constantString});
 113     }
 114 
 115     @Test
 116     public void testStringIndexOfConstantOffset() {
 117         test("testStringIndexOfOffset", new Object[]{this.sourceString, this.constantString, -1});
 118         test("testStringIndexOfOffset", new Object[]{this.sourceString, this.constantString, 0});
 119         test("testStringIndexOfOffset", new Object[]{this.sourceString, this.constantString, Math.max(0, sourceString.length() - constantString.length())});
 120     }
 121 
 122     @Test
 123     public void testStringBuilderIndexOfConstant() {
 124         assumeFalse("Disabled on AArch64 due to issues on AArch64; see GR-13100 or JDK-8215792", getTarget().arch instanceof AArch64);
 125         /*
 126          * Put a copy of the target string in the space after the current string to detect cases
 127          * where we search too far.
 128          */
 129         StringBuilder sb = new StringBuilder(this.sourceString);
 130         sb.append(constantString);
 131         sb.setLength(sourceString.length());
 132         test("testStringBuilderIndexOf", new Object[]{sb, this.constantString});
 133     }
 134 
 135     @Test
 136     public void testStringBuilderIndexOfConstantOffset() {
 137         assumeFalse("Disabled on AArch64 due to issues on AArch64; see GR-13100 or JDK-8215792", getTarget().arch instanceof AArch64);
 138         /*
 139          * Put a copy of the target string in the space after the current string to detect cases
 140          * where we search too far.
 141          */
 142         StringBuilder sb = new StringBuilder(this.sourceString);
 143         sb.append(constantString);
 144         sb.setLength(sourceString.length());
 145         test("testStringBuilderIndexOfOffset", new Object[]{sb, this.constantString, -1});
 146         test("testStringBuilderIndexOfOffset", new Object[]{sb, this.constantString, 0});
 147         test("testStringBuilderIndexOfOffset", new Object[]{sb, this.constantString, Math.max(0, sourceString.length() - constantString.length())});
 148     }
 149 }
< prev index next >