1 /*
   2  * Copyright (c) 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 import org.testng.annotations.DataProvider;
  25 import org.testng.annotations.Test;
  26 
  27 import static org.testng.Assert.assertEquals;
  28 
  29 /*
  30  * @test
  31  * @bug 8077559
  32  * @summary Tests Compact String. This one is for String.compareToIgnoreCase.
  33  * @run testng/othervm -XX:+CompactStrings CompareToIgnoreCase
  34  * @run testng/othervm -XX:-CompactStrings CompareToIgnoreCase
  35  */
  36 
  37 public class CompareToIgnoreCase extends CompactString {
  38 
  39     @DataProvider
  40     public Object[][] provider() {
  41         return new Object[][] {
  42 
  43                 new Object[] { STRING_EMPTY, "A", -1 },
  44                 new Object[] { STRING_L1, "a", 0 },
  45                 new Object[] { STRING_L1, "A", 0 },
  46                 new Object[] { STRING_L1, "\uFF21", -65248 },
  47                 new Object[] { STRING_L1, "B", -1 },
  48                 new Object[] { STRING_L2, "AB", 0 },
  49                 new Object[] { STRING_L2, "aB", 0 },
  50                 new Object[] { STRING_L2, "\uFF21", -65248 },
  51                 new Object[] { STRING_L2, "A\uFF21", -65247 },
  52                 new Object[] { STRING_L4, "ABCD", 0 },
  53                 new Object[] { STRING_L4, "abcd", 0 },
  54                 new Object[] { STRING_L4, "ABc\uFF21", -65245 },
  55                 new Object[] { STRING_LLONG, "ABCDEFGH", 0 },
  56                 new Object[] { STRING_LLONG, "abcdefgh", 0 },
  57                 new Object[] { STRING_LLONG, "ABCDEFG\uFF21", -65241 },
  58                 new Object[] { STRING_LLONG, "abcdefg\uFF21", -65241 },
  59                 new Object[] { STRING_U1, "\uFF41", 0 },
  60                 new Object[] { STRING_U1,
  61                         "\uFF41\uFF42\uFF43\uFF44\uFF45\uFF46\uFF47\uFF48", -7 },
  62                 new Object[] { STRING_U1, "A", 65248 },
  63                 new Object[] { STRING_U2, "\uFF41", 1 },
  64                 new Object[] { STRING_U2, "\uFF41\uFF42", 0 },
  65                 new Object[] { STRING_U2,
  66                         "\uFF41\uFF42\uFF43\uFF44\uFF45\uFF46\uFF47\uFF48", -6 },
  67                 new Object[] { STRING_M12, "\uFF41a", 0 },
  68                 new Object[] { STRING_M12, "\uFF41\uFF42", -65249 },
  69                 new Object[] { STRING_M11, "a\uFF41", 0 },
  70                 new Object[] { STRING_M11, "a\uFF42", -1 }, };
  71     }
  72 
  73     @Test(dataProvider = "provider")
  74     public void testCompareToIgnoreCase(String str, String anotherString,
  75             int expected) {
  76         map.get(str)
  77                 .forEach(
  78                         (source, data) -> {
  79                             assertEquals(
  80                                     data.compareToIgnoreCase(anotherString),
  81                                     expected,
  82                                     String.format(
  83                                             "testing String(%s).compareToIgnoreCase(%s), source : %s, ",
  84                                             escapeNonASCIIs(data),
  85                                             escapeNonASCIIs(anotherString),
  86                                             source));
  87                         });
  88     }
  89 }