< 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
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2016, 2018, 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 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});


  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});
  89                 tests.add(new Object[]{s.substring(0, s.length() - 1) + s, s});
  90             }
  91         }








  92     }
  93 
  94     public int testStringIndexOf(String a, String b) {
  95         return a.indexOf(b);
  96     }
  97 
  98     public int testStringIndexOfOffset(String a, String b, int fromIndex) {
  99         return a.indexOf(b, fromIndex);
 100     }
 101 
 102     public int testStringBuilderIndexOf(StringBuilder a, String b) {
 103         return a.indexOf(b);
 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() {


   1 /*
   2  * Copyright (c) 2016, 2019, 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 package org.graalvm.compiler.replacements.test;
  26 
  27 import static org.junit.Assume.assumeFalse;
  28 
  29 import java.util.ArrayList;
  30 import java.util.Collection;
  31 
  32 import org.graalvm.compiler.core.test.GraalCompilerTest;
  33 import org.junit.Test;
  34 import org.junit.runner.RunWith;
  35 import org.junit.runners.Parameterized;
  36 


  37 import jdk.vm.ci.aarch64.AArch64;
  38 
  39 @RunWith(value = Parameterized.class)
  40 public abstract class StringIndexOfTestBase extends GraalCompilerTest {


  41 
  42     @Parameterized.Parameters(name = "{0},{1}")
  43     public static Collection<Object[]> data() {
  44         ArrayList<Object[]> tests = new ArrayList<>();
  45         String[] targets = new String[]{"foobar", "foo", "bar"};
  46         String[] utf16targets = new String[]{"grga " + ((char) 0x10D) + "varak", "grga", ((char) 0x10D) + "varak"};
  47         addTargets(tests, targets);
  48         addTargets(tests, utf16targets);
  49 
  50         // Check long targets
  51         // Checkstyle: stop
  52         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 ";
  53         // Checkstyle: resume
  54         String lipsumUTF16 = lipsum + ((char) 0x10D);
  55         int[] subStringLengths = {7, 8, 15, 16, 31, 32, 63, 64};
  56         for (int len : subStringLengths) {
  57             String target = lipsum.substring(50, 50 + len);
  58             tests.add(new Object[]{lipsum, target});
  59             tests.add(new Object[]{lipsum, target + "X"});
  60             tests.add(new Object[]{lipsumUTF16, target});


  71     private static void addTargets(ArrayList<Object[]> tests, String[] targets) {
  72         for (String source : targets) {
  73             for (String target : targets) {
  74                 tests.add(new Object[]{source, target});
  75             }
  76             tests.add(new Object[]{source, ""});
  77             tests.add(new Object[]{"", source});
  78             tests.add(new Object[]{"", ""});
  79         }
  80         for (String source : targets) {
  81             String s = "";
  82             for (int i = 0; i < 10; i++) {
  83                 s = s + source.substring(0, source.length() - 1);
  84             }
  85             for (String target : targets) {
  86                 tests.add(new Object[]{s, target});
  87                 tests.add(new Object[]{s + target, target});
  88                 tests.add(new Object[]{s.substring(0, s.length() - 1) + s, s});
  89             }
  90         }
  91     }
  92 
  93     protected final String sourceString;
  94     protected final String constantString;
  95 
  96     public StringIndexOfTestBase(String sourceString, String constantString) {
  97         this.sourceString = sourceString;
  98         this.constantString = constantString;
  99     }
 100 
 101     public int testStringIndexOf(String a, String b) {
 102         return a.indexOf(b);
 103     }
 104 
 105     public int testStringIndexOfOffset(String a, String b, int fromIndex) {
 106         return a.indexOf(b, fromIndex);
 107     }
 108 
 109     public int testStringBuilderIndexOf(StringBuilder a, String b) {
 110         return a.indexOf(b);
 111     }
 112 
 113     public int testStringBuilderIndexOfOffset(StringBuilder a, String b, int fromIndex) {
 114         return a.indexOf(b, fromIndex);
 115     }
 116 
 117     @Test
 118     public void testStringIndexOfConstant() {


< prev index next >