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.compareTo. 33 * @run testng/othervm -XX:+CompactStrings CompareTo 34 * @run testng/othervm -XX:-CompactStrings CompareTo 35 */ 36 37 public class CompareTo 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_EMPTY, "\uFF21", -1 }, 45 new Object[] { STRING_L1, "AB", -1 }, 46 new Object[] { STRING_L1, "A", 0 }, 47 new Object[] { STRING_L1, "a", -32 }, 48 new Object[] { STRING_L1, "\uFF21", -65248 }, 49 new Object[] { STRING_L2, "AB", 0 }, 50 new Object[] { STRING_L2, "Ab", -32 }, 51 new Object[] { STRING_L2, "AA", 1 }, 52 new Object[] { STRING_L2, "\uFF21", -65248 }, 69 new Object[] { STRING_U2, "\uFF21\uFF21", 1 }, 70 new Object[] { STRING_U2, "A", 65248 }, 71 new Object[] { STRING_M12, "\uFF21A", 0 }, 72 new Object[] { STRING_M12, "A\uFF21", 65248 }, 73 new Object[] { STRING_M12, "\uFF21\uFF21", -65248 }, 74 new Object[] { STRING_M11, "A\uFF21", 0 }, 75 new Object[] { STRING_M11, "\uFF21A", -65248 }, 76 new Object[] { STRING_M11, "AA", 65248 }, }; 77 } 78 79 @Test(dataProvider = "provider") 80 public void testCompareTo(String str, String anotherString, int expected) { 81 map.get(str) 82 .forEach( 83 (source, data) -> { 84 assertEquals( 85 data.compareTo(anotherString), 86 expected, 87 String.format( 88 "testing String(%s).compareTo(%s), source : %s, ", 89 escapeNonASCIIs(data), 90 escapeNonASCIIs(anotherString), 91 source)); 92 }); 93 } 94 } | 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 8137326 32 * @summary Tests Compact String. Verifies the compareTo method for String, 33 * StringBuilder and StringBuffer. 34 * @run testng/othervm -XX:+CompactStrings CompareTo 35 * @run testng/othervm -XX:-CompactStrings CompareTo 36 */ 37 38 public class CompareTo extends CompactString { 39 40 @DataProvider 41 public Object[][] provider() { 42 return new Object[][] { 43 44 new Object[] { STRING_EMPTY, "A", -1 }, 45 new Object[] { STRING_EMPTY, "\uFF21", -1 }, 46 new Object[] { STRING_L1, "AB", -1 }, 47 new Object[] { STRING_L1, "A", 0 }, 48 new Object[] { STRING_L1, "a", -32 }, 49 new Object[] { STRING_L1, "\uFF21", -65248 }, 50 new Object[] { STRING_L2, "AB", 0 }, 51 new Object[] { STRING_L2, "Ab", -32 }, 52 new Object[] { STRING_L2, "AA", 1 }, 53 new Object[] { STRING_L2, "\uFF21", -65248 }, 70 new Object[] { STRING_U2, "\uFF21\uFF21", 1 }, 71 new Object[] { STRING_U2, "A", 65248 }, 72 new Object[] { STRING_M12, "\uFF21A", 0 }, 73 new Object[] { STRING_M12, "A\uFF21", 65248 }, 74 new Object[] { STRING_M12, "\uFF21\uFF21", -65248 }, 75 new Object[] { STRING_M11, "A\uFF21", 0 }, 76 new Object[] { STRING_M11, "\uFF21A", -65248 }, 77 new Object[] { STRING_M11, "AA", 65248 }, }; 78 } 79 80 @Test(dataProvider = "provider") 81 public void testCompareTo(String str, String anotherString, int expected) { 82 map.get(str) 83 .forEach( 84 (source, data) -> { 85 assertEquals( 86 data.compareTo(anotherString), 87 expected, 88 String.format( 89 "testing String(%s).compareTo(%s), source : %s, ", 90 escapeNonASCIIs(data), 91 escapeNonASCIIs(anotherString), 92 source)); 93 }); 94 } 95 96 /* 97 * Runs the same test with StringBuilder 98 */ 99 @Test(dataProvider = "provider") 100 public void testStringBuilder(String str, String anotherString, int expected) { 101 StringBuilder another = new StringBuilder(anotherString); 102 map.get(str) 103 .forEach( 104 (source, data) -> { 105 StringBuilder sb = new StringBuilder(data); 106 assertEquals( 107 sb.compareTo(another), 108 expected, 109 String.format( 110 "testing StringBuilder(%s).compareTo(%s), source : %s, ", 111 escapeNonASCIIs(data), 112 escapeNonASCIIs(anotherString), 113 source)); 114 }); 115 } 116 117 /* 118 * Runs the same test with StringBuffer 119 */ 120 @Test(dataProvider = "provider") 121 public void testStringBuffer(String str, String anotherString, int expected) { 122 StringBuffer another = new StringBuffer(anotherString); 123 map.get(str) 124 .forEach( 125 (source, data) -> { 126 StringBuffer sb = new StringBuffer(data); 127 assertEquals( 128 sb.compareTo(another), 129 expected, 130 String.format( 131 "testing StringBuffer(%s).compareTo(%s), source : %s, ", 132 escapeNonASCIIs(data), 133 escapeNonASCIIs(anotherString), 134 source)); 135 }); 136 } 137 } |