| jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | import junit.framework.Assert; |
| Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 18 | import java.lang.reflect.Method; |
| Vladimir Marko | 85bef97 | 2017-02-17 10:18:57 +0000 | [diff] [blame] | 19 | import java.util.Locale; |
| jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * more string tests |
| 23 | */ |
| 24 | public class Main { |
| Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 25 | public static void main(String args[]) throws Exception { |
| jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 26 | String test = "0123456789"; |
| 27 | String test1 = new String("0123456789"); // different object |
| 28 | String test2 = new String("0123456780"); // different value |
| 29 | String offset = new String("xxx0123456789yyy"); |
| 30 | String sub = offset.substring(3, 13); |
| 31 | Object blah = new Object(); |
| 32 | |
| 33 | Assert.assertTrue(test.equals(test)); |
| 34 | Assert.assertTrue(test.equals(test1)); |
| 35 | Assert.assertFalse(test.equals(test2)); |
| 36 | |
| 37 | Assert.assertEquals(test.compareTo(test1), 0); |
| 38 | Assert.assertTrue(test1.compareTo(test2) > 0); |
| 39 | Assert.assertTrue(test2.compareTo(test1) < 0); |
| 40 | |
| Alexei Zavjalov | 4554bfd | 2014-02-26 17:28:35 +0700 | [diff] [blame] | 41 | Assert.assertEquals("".compareTo(""), 0); |
| 42 | Assert.assertTrue(test.compareTo("") > 0); |
| 43 | Assert.assertTrue("".compareTo(test) < 0); |
| 44 | |
| jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 45 | /* compare string with a nonzero offset, in left/right side */ |
| 46 | Assert.assertEquals(test.compareTo(sub), 0); |
| 47 | Assert.assertEquals(sub.compareTo(test), 0); |
| 48 | Assert.assertTrue(test.equals(sub)); |
| 49 | Assert.assertTrue(sub.equals(test)); |
| 50 | /* same base, one is a substring */ |
| 51 | Assert.assertFalse(offset.equals(sub)); |
| 52 | Assert.assertFalse(sub.equals(offset)); |
| 53 | /* wrong class */ |
| 54 | Assert.assertFalse(test.equals(blah)); |
| 55 | |
| 56 | /* null ptr - throw */ |
| 57 | try { |
| 58 | test.compareTo(null); |
| 59 | Assert.fail("didn't get expected npe"); |
| 60 | } catch (NullPointerException npe) { |
| 61 | System.out.println("Got expected npe"); |
| 62 | } |
| 63 | /* null ptr - ok */ |
| 64 | Assert.assertFalse(test.equals(null)); |
| 65 | |
| 66 | test = test.substring(1); |
| 67 | Assert.assertTrue(test.equals("123456789")); |
| 68 | Assert.assertFalse(test.equals(test1)); |
| 69 | |
| 70 | test = test.substring(1); |
| 71 | Assert.assertTrue(test.equals("23456789")); |
| 72 | |
| 73 | test = test.substring(1); |
| 74 | Assert.assertTrue(test.equals("3456789")); |
| 75 | |
| 76 | test = test.substring(1); |
| 77 | Assert.assertTrue(test.equals("456789")); |
| 78 | |
| 79 | test = test.substring(3,5); |
| 80 | Assert.assertTrue(test.equals("78")); |
| 81 | |
| 82 | test = "this/is/a/path"; |
| 83 | String[] strings = test.split("/"); |
| 84 | Assert.assertEquals(4, strings.length); |
| 85 | |
| 86 | Assert.assertEquals("this is a path", test.replaceAll("/", " ")); |
| 87 | Assert.assertEquals("this is a path", test.replace("/", " ")); |
| Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 88 | |
| Andreas Gampe | 166aaee | 2016-07-18 08:27:23 -0700 | [diff] [blame] | 89 | Class<?> Strings = Class.forName("com.android.org.bouncycastle.util.Strings"); |
| Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 90 | Method fromUTF8ByteArray = Strings.getDeclaredMethod("fromUTF8ByteArray", byte[].class); |
| 91 | String result = (String) fromUTF8ByteArray.invoke(null, new byte[] {'O', 'K'}); |
| 92 | System.out.println(result); |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 93 | |
| 94 | testCompareToAndEquals(); |
| 95 | testIndexOf(); |
| Vladimir Marko | 16850ae | 2016-12-09 14:01:02 +0000 | [diff] [blame] | 96 | |
| 97 | String s0_0 = "\u0000"; |
| 98 | String s0_1 = new String(s0_0); |
| 99 | String s0_2 = new String(new char[] { '\u0000' }); |
| 100 | String s0_3 = s0_0 + ""; |
| 101 | System.out.println( |
| 102 | " " + $noinline$equals(s0_0, s0_0) + |
| 103 | " " + $noinline$equals(s0_0, s0_1) + |
| 104 | " " + $noinline$equals(s0_0, s0_2) + |
| 105 | " " + $noinline$equals(s0_0, s0_3)); |
| 106 | System.out.println( |
| 107 | " " + $noinline$equals(s0_1, s0_0) + |
| 108 | " " + $noinline$equals(s0_1, s0_1) + |
| 109 | " " + $noinline$equals(s0_1, s0_2) + |
| 110 | " " + $noinline$equals(s0_1, s0_3)); |
| 111 | System.out.println( |
| 112 | " " + $noinline$equals(s0_2, s0_0) + |
| 113 | " " + $noinline$equals(s0_2, s0_1) + |
| 114 | " " + $noinline$equals(s0_2, s0_2) + |
| 115 | " " + $noinline$equals(s0_2, s0_3)); |
| 116 | System.out.println( |
| 117 | " " + $noinline$equals(s0_3, s0_0) + |
| 118 | " " + $noinline$equals(s0_3, s0_1) + |
| 119 | " " + $noinline$equals(s0_3, s0_2) + |
| 120 | " " + $noinline$equals(s0_3, s0_3)); |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 121 | |
| 122 | testEqualsConstString(); |
| 123 | testConstStringEquals(); |
| Vladimir Marko | 85bef97 | 2017-02-17 10:18:57 +0000 | [diff] [blame] | 124 | |
| 125 | // Regression tests for String.setCharAt() breaking string compression invariants. |
| 126 | Locale en_US = new Locale("en", "US"); |
| 127 | Assert.assertEquals("I", /* Small latin dotless i */ "\u0131".toUpperCase()); |
| 128 | Assert.assertEquals("abc", "a\u0131c".replace('\u0131', 'b')); |
| 129 | Assert.assertEquals("a\u0131c", "abc".replace('b', '\u0131')); |
| Vladimir Marko | 26ec3ca | 2017-03-14 13:37:14 +0000 | [diff] [blame] | 130 | |
| 131 | // Regression test for scratch register exhaustion in String.equals() intrinsic on arm64. |
| 132 | Assert.assertFalse(result.equals("Very long constant string, so that the known constant count field cannot be embedded in a CMP immediate instruction on arm64. Since it can hold 12-bit values, optionally shifted left by 12, let's go somewhere over 2^12, i.e. 4096. That should trigger the bug with or without string compression. 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/")); |
| jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 133 | } |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 134 | |
| 135 | public static void testCompareToAndEquals() { |
| 136 | String[] strings = { |
| 137 | // Special: empty string. |
| 138 | "", |
| 139 | // Category 0, ASCII strings: |
| 140 | // "0123456789abcdef".substring(0, index + 1) |
| 141 | "0", |
| 142 | "01", |
| 143 | "012", |
| 144 | "0123", |
| 145 | "01234", |
| 146 | "012345", |
| 147 | "0123456", |
| 148 | "01234567", |
| 149 | "012345678", |
| 150 | "0123456789", |
| 151 | "0123456789a", |
| 152 | "0123456789ab", |
| 153 | "0123456789abc", |
| 154 | "0123456789abcd", |
| 155 | "0123456789abcde", |
| 156 | "0123456789abcdef", |
| 157 | // Category 1, ASCII strings: |
| 158 | // "0123456789abcdef".substring(0, index) + "x" |
| 159 | "x", |
| 160 | "0x", |
| 161 | "01x", |
| 162 | "012x", |
| 163 | "0123x", |
| 164 | "01234x", |
| 165 | "012345x", |
| 166 | "0123456x", |
| 167 | "01234567x", |
| 168 | "012345678x", |
| 169 | "0123456789x", |
| 170 | "0123456789ax", |
| 171 | "0123456789abx", |
| 172 | "0123456789abcx", |
| 173 | "0123456789abcdx", |
| 174 | "0123456789abcdex", |
| 175 | // Category 2, ASCII strings, |
| 176 | // "0123456789abcdef".substring(0, index) + "x" + |
| 177 | // "0123456789abcdef".substring(index + 1) |
| 178 | "x123456789abcdef", |
| 179 | "0x23456789abcdef", |
| 180 | "01x3456789abcdef", |
| 181 | "012x456789abcdef", |
| 182 | "0123x56789abcdef", |
| 183 | "01234x6789abcdef", |
| 184 | "012345x789abcdef", |
| 185 | "0123456x89abcdef", |
| 186 | "01234567x9abcdef", |
| 187 | "012345678xabcdef", |
| 188 | "0123456789xbcdef", |
| 189 | "0123456789axcdef", |
| 190 | "0123456789abxdef", |
| 191 | "0123456789abcxef", |
| 192 | "0123456789abcdxf", |
| 193 | "0123456789abcdex", |
| 194 | // Category 3, ASCII strings: |
| 195 | // "z" + "0123456789abcdef".substring(1, index + 1) |
| 196 | "z", |
| 197 | "z1", |
| 198 | "z12", |
| 199 | "z123", |
| 200 | "z1234", |
| 201 | "z12345", |
| 202 | "z123456", |
| 203 | "z1234567", |
| 204 | "z12345678", |
| 205 | "z123456789", |
| 206 | "z123456789a", |
| 207 | "z123456789ab", |
| 208 | "z123456789abc", |
| 209 | "z123456789abcd", |
| 210 | "z123456789abcde", |
| 211 | "z123456789abcdef", |
| 212 | // Category 4, non-ASCII strings: |
| 213 | // "0123456789abcdef".substring(0, index) + "\u0440" |
| 214 | "\u0440", |
| 215 | "0\u0440", |
| 216 | "01\u0440", |
| 217 | "012\u0440", |
| 218 | "0123\u0440", |
| 219 | "01234\u0440", |
| 220 | "012345\u0440", |
| 221 | "0123456\u0440", |
| 222 | "01234567\u0440", |
| 223 | "012345678\u0440", |
| 224 | "0123456789\u0440", |
| 225 | "0123456789a\u0440", |
| 226 | "0123456789ab\u0440", |
| 227 | "0123456789abc\u0440", |
| 228 | "0123456789abcd\u0440", |
| 229 | "0123456789abcde\u0440", |
| 230 | // Category 5, non-ASCII strings: |
| 231 | // "0123456789abcdef".substring(0, index) + "\u0440" + |
| 232 | // "0123456789abcdef".substring(index + 1) |
| 233 | "\u0440123456789abcdef", |
| 234 | "0\u044023456789abcdef", |
| 235 | "01\u04403456789abcdef", |
| 236 | "012\u0440456789abcdef", |
| 237 | "0123\u044056789abcdef", |
| 238 | "01234\u04406789abcdef", |
| 239 | "012345\u0440789abcdef", |
| 240 | "0123456\u044089abcdef", |
| 241 | "01234567\u04409abcdef", |
| 242 | "012345678\u0440abcdef", |
| 243 | "0123456789\u0440bcdef", |
| 244 | "0123456789a\u0440cdef", |
| 245 | "0123456789ab\u0440def", |
| 246 | "0123456789abc\u0440ef", |
| 247 | "0123456789abcd\u0440f", |
| 248 | "0123456789abcde\u0440", |
| 249 | // Category 6, ASCII strings: |
| 250 | // "\u0443" + "0123456789abcdef".substring(1, index + 1) |
| 251 | "\u0443", |
| 252 | "\u04431", |
| 253 | "\u044312", |
| 254 | "\u0443123", |
| 255 | "\u04431234", |
| 256 | "\u044312345", |
| 257 | "\u0443123456", |
| 258 | "\u04431234567", |
| 259 | "\u044312345678", |
| 260 | "\u0443123456789", |
| 261 | "\u0443123456789a", |
| 262 | "\u0443123456789ab", |
| 263 | "\u0443123456789abc", |
| 264 | "\u0443123456789abcd", |
| 265 | "\u0443123456789abcde", |
| 266 | "\u0443123456789abcdef", |
| 267 | // Category 7, non-ASCII strings: |
| 268 | // "0123456789abcdef".substring(0, index) + "\u0482" |
| 269 | "\u0482", |
| 270 | "0\u0482", |
| 271 | "01\u0482", |
| 272 | "012\u0482", |
| 273 | "0123\u0482", |
| 274 | "01234\u0482", |
| 275 | "012345\u0482", |
| 276 | "0123456\u0482", |
| 277 | "01234567\u0482", |
| 278 | "012345678\u0482", |
| 279 | "0123456789\u0482", |
| 280 | "0123456789a\u0482", |
| 281 | "0123456789ab\u0482", |
| 282 | "0123456789abc\u0482", |
| 283 | "0123456789abcd\u0482", |
| 284 | "0123456789abcde\u0482", |
| 285 | // Category 8, non-ASCII strings: |
| 286 | // "0123456789abcdef".substring(0, index) + "\u0482" + |
| 287 | // "0123456789abcdef".substring(index + 1) |
| 288 | "\u0482123456789abcdef", |
| 289 | "0\u048223456789abcdef", |
| 290 | "01\u04823456789abcdef", |
| 291 | "012\u0482456789abcdef", |
| 292 | "0123\u048256789abcdef", |
| 293 | "01234\u04826789abcdef", |
| 294 | "012345\u0482789abcdef", |
| 295 | "0123456\u048289abcdef", |
| 296 | "01234567\u04829abcdef", |
| 297 | "012345678\u0482abcdef", |
| 298 | "0123456789\u0482bcdef", |
| 299 | "0123456789a\u0482cdef", |
| 300 | "0123456789ab\u0482def", |
| 301 | "0123456789abc\u0482ef", |
| 302 | "0123456789abcd\u0482f", |
| 303 | "0123456789abcde\u0482", |
| 304 | // Category 9, ASCII strings: |
| 305 | // "\u0489" + "0123456789abcdef".substring(1, index + 1) |
| 306 | "\u0489", |
| 307 | "\u04891", |
| 308 | "\u048912", |
| 309 | "\u0489123", |
| 310 | "\u04891234", |
| 311 | "\u048912345", |
| 312 | "\u0489123456", |
| 313 | "\u04891234567", |
| 314 | "\u048912345678", |
| 315 | "\u0489123456789", |
| 316 | "\u0489123456789a", |
| 317 | "\u0489123456789ab", |
| 318 | "\u0489123456789abc", |
| 319 | "\u0489123456789abcd", |
| 320 | "\u0489123456789abcde", |
| 321 | "\u0489123456789abcdef", |
| 322 | }; |
| 323 | int length = strings.length; |
| 324 | Assert.assertEquals(1 + 16 * 10, length); |
| 325 | for (int i = 0; i != length; ++i) { |
| 326 | String lhs = strings[i]; |
| 327 | for (int j = 0; j != length; ++j) { |
| 328 | String rhs = strings[j]; |
| 329 | int result = $noinline$compareTo(lhs, rhs); |
| 330 | final int expected; |
| 331 | if (i == 0 || j == 0 || i == j) { |
| 332 | // One of the strings is empty or the strings are the same. |
| 333 | expected = lhs.length() - rhs.length(); |
| 334 | } else { |
| 335 | int i_category = (i - 1) / 16; |
| 336 | int i_index = (i - 1) % 16; |
| 337 | int j_category = (j - 1) / 16; |
| 338 | int j_index = (j - 1) % 16; |
| 339 | int min_ij_index = (i_index < j_index) ? i_index : j_index; |
| 340 | if (i_category == j_category) { |
| 341 | switch (i_category) { |
| 342 | case 0: case 3: case 6: case 9: |
| 343 | // Differs in length. |
| 344 | expected = lhs.length() - rhs.length(); |
| 345 | break; |
| 346 | case 1: case 2: case 4: case 5: case 7: case 8: |
| 347 | // Differs in charAt(min_ij_index). |
| 348 | expected = lhs.charAt(min_ij_index) - rhs.charAt(min_ij_index); |
| 349 | break; |
| 350 | default: throw new Error("Unexpected category."); |
| 351 | } |
| 352 | } else if (i_category == 3 || i_category == 6 || i_category == 9 || |
| 353 | j_category == 3 || j_category == 6 || j_category == 9) { |
| 354 | // In these categories, charAt(0) differs from other categories' strings. |
| 355 | expected = lhs.charAt(0) - rhs.charAt(0); |
| 356 | } else if (// Category 0 string is a prefix to any longer string in |
| 357 | // remaining categories. |
| 358 | (i_category == 0 && i_index < j_index) || |
| 359 | (j_category == 0 && j_index < i_index) || |
| 360 | // Category 2 string is a prefix to category 3 string at the same |
| 361 | // index. Similar for categories 4 and 5 and also 7 and 8. |
| 362 | // This includes matching last strings of these pairs of categories. |
| 363 | (i_index == j_index && |
| 364 | ((i_category == 1 && j_category == 2) || |
| 365 | (i_category == 2 && j_category == 1) || |
| 366 | (i_category == 4 && j_category == 5) || |
| 367 | (i_category == 5 && j_category == 4) || |
| 368 | (i_category == 7 && j_category == 8) || |
| 369 | (i_category == 8 && j_category == 7)))) { |
| 370 | // Differs in length. |
| 371 | expected = lhs.length() - rhs.length(); |
| 372 | } else { |
| 373 | // The remaining cases differ in charAt(min_ij_index), the characters |
| 374 | // before that are "0123456789abcdef".substring(0, min_ij_index). |
| 375 | for (int k = 0; k < min_ij_index; ++k) { |
| 376 | Assert.assertEquals("0123456789abcdef".charAt(k), lhs.charAt(k)); |
| 377 | Assert.assertEquals("0123456789abcdef".charAt(k), rhs.charAt(k)); |
| 378 | } |
| 379 | expected = lhs.charAt(min_ij_index) - rhs.charAt(min_ij_index); |
| 380 | Assert.assertFalse(expected == 0); |
| 381 | } |
| 382 | } |
| 383 | if (expected != result) { |
| 384 | throw new Error( |
| 385 | "Mismatch at i=" + i + ", j=" + j + ", expected=" + expected + |
| 386 | ", result=" + result); |
| 387 | } |
| 388 | boolean equalsExpected = |
| 389 | (i == j) || |
| 390 | // Last string in categories 1 and 2. |
| 391 | (i == 32 && j == 48) || (i == 48 && j == 32) || |
| 392 | // Last string in categories 4 and 5. |
| 393 | (i == 80 && j == 96) || (i == 96 && j == 80) || |
| 394 | // Last string in categories 7 and 8. |
| 395 | (i == 128 && j == 144) || (i == 144 && j == 128); |
| 396 | Assert.assertEquals(equalsExpected, $noinline$equals(lhs, rhs)); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | try { |
| 401 | $noinline$compareTo("", null); |
| 402 | Assert.fail(); |
| 403 | } catch (NullPointerException expected) { |
| 404 | } |
| 405 | try { |
| 406 | $noinline$compareTo(null, ""); |
| 407 | Assert.fail(); |
| 408 | } catch (NullPointerException expected) { |
| 409 | } |
| 410 | |
| 411 | Assert.assertFalse($noinline$equals("", null)); |
| 412 | try { |
| 413 | $noinline$equals(null, ""); |
| 414 | Assert.fail(); |
| 415 | } catch (NullPointerException expected) { |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | public static void testIndexOf() { |
| 420 | String[] prefixes = { |
| 421 | "", |
| 422 | "0", |
| 423 | "01", |
| 424 | "012", |
| 425 | "0123", |
| 426 | "01234", |
| 427 | "012345", |
| 428 | "0123456", |
| 429 | "01234567", |
| 430 | "012345678", |
| 431 | "0123456789", |
| 432 | "0123456789a", |
| 433 | "0123456789ab", |
| 434 | "0123456789abc", |
| 435 | "0123456789abcd", |
| 436 | "0123456789abcdef", |
| 437 | }; |
| 438 | String[] cores = { |
| 439 | "", |
| 440 | "x", |
| 441 | "xx", |
| 442 | "xxx", |
| 443 | "xxxx", |
| 444 | "xxxxx", |
| 445 | "xxxxxx", |
| 446 | "xxxxxxx", |
| 447 | "xxxxxxxx", |
| 448 | "xzx", |
| 449 | "xxzx", |
| 450 | "xxxzx", |
| 451 | "xxxxzx", |
| 452 | "xxxxxzx", |
| 453 | "xxxxxxzx", |
| 454 | "xxxxxxxzx", |
| 455 | "xxxxxxxxzx", |
| 456 | "\u0440", |
| 457 | "\u0440\u0440", |
| 458 | "\u0440\u0440\u0440", |
| 459 | "\u0440\u0440\u0440\u0440", |
| 460 | "\u0440\u0440\u0440\u0440\u0440", |
| 461 | "\u0440\u0440\u0440\u0440\u0440\u0440", |
| 462 | "\u0440\u0440\u0440\u0440\u0440\u0440\u0440", |
| 463 | "\u0440\u0440\u0440\u0440\u0440\u0440\u0440\u0440", |
| 464 | "\u0440z\u0440", |
| 465 | "\u0440\u0440z\u0440", |
| 466 | "\u0440\u0440\u0440z\u0440", |
| 467 | "\u0440\u0440\u0440\u0440z\u0440", |
| 468 | "\u0440\u0440\u0440\u0440\u0440z\u0440", |
| 469 | "\u0440\u0440\u0440\u0440\u0440\u0440z\u0440", |
| 470 | "\u0440\u0440\u0440\u0440\u0440\u0440\u0440z\u0440", |
| 471 | "\u0440\u0440\u0440\u0440\u0440\u0440\u0440\u0440z\u0440", |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 472 | "\u0000", |
| 473 | "\u0000\u0000", |
| 474 | "\u0000\u0000\u0000", |
| 475 | "\u0000\u0000\u0000\u0000", |
| 476 | "\u0000\u0000\u0000\u0000\u0000", |
| 477 | "\u0000\u0000\u0000\u0000\u0000\u0000", |
| 478 | "\u0000\u0000\u0000\u0000\u0000\u0000\u0000", |
| 479 | "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", |
| 480 | "\u0000z\u0000", |
| 481 | "\u0000\u0000z\u0000", |
| 482 | "\u0000\u0000\u0000z\u0000", |
| 483 | "\u0000\u0000\u0000\u0000z\u0000", |
| 484 | "\u0000\u0000\u0000\u0000\u0000z\u0000", |
| 485 | "\u0000\u0000\u0000\u0000\u0000\u0000z\u0000", |
| 486 | "\u0000\u0000\u0000\u0000\u0000\u0000\u0000z\u0000", |
| 487 | "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000z\u0000", |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 488 | }; |
| 489 | String[] suffixes = { |
| 490 | "", |
| 491 | "y", |
| 492 | "yy", |
| 493 | "yyy", |
| 494 | "yyyy", |
| 495 | "yyyyy", |
| 496 | "yyyyyy", |
| 497 | "yyyyyyy", |
| 498 | "yyyyyyyy", |
| 499 | "\u0441", |
| 500 | "y\u0441", |
| 501 | "yy\u0441", |
| 502 | "yyy\u0441", |
| 503 | "yyyy\u0441", |
| 504 | "yyyyy\u0441", |
| 505 | "yyyyyy\u0441", |
| 506 | "yyyyyyy\u0441", |
| 507 | "yyyyyyyy\u0441", |
| 508 | }; |
| 509 | for (String p : prefixes) { |
| 510 | for (String c : cores) { |
| 511 | for (String s : suffixes) { |
| 512 | String full = p + c + s; |
| 513 | int expX = (c.isEmpty() || c.charAt(0) != 'x') ? -1 : p.length(); |
| 514 | int exp0440 = (c.isEmpty() || c.charAt(0) != '\u0440') ? -1 : p.length(); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 515 | int exp0000 = (c.isEmpty() || c.charAt(0) != '\u0000') ? -1 : p.length(); |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 516 | Assert.assertEquals(expX, $noinline$indexOf(full, 'x')); |
| 517 | Assert.assertEquals(exp0440, $noinline$indexOf(full, '\u0440')); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 518 | Assert.assertEquals(exp0000, $noinline$indexOf(full, '\u0000')); |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 519 | Assert.assertEquals(expX, $noinline$indexOf(full, 'x', -1)); |
| 520 | Assert.assertEquals(exp0440, $noinline$indexOf(full, '\u0440', -1)); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 521 | Assert.assertEquals(exp0000, $noinline$indexOf(full, '\u0000', -1)); |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 522 | Assert.assertEquals(-1, $noinline$indexOf(full, 'x', full.length() + 1)); |
| 523 | Assert.assertEquals(-1, $noinline$indexOf(full, '\u0440', full.length() + 1)); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 524 | Assert.assertEquals(-1, $noinline$indexOf(full, '\u0000', full.length() + 1)); |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 525 | for (int from = 0; from != full.length(); ++from) { |
| 526 | final int eX; |
| 527 | final int e0440; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 528 | final int e0000; |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 529 | if (from <= p.length()) { |
| 530 | eX = expX; |
| 531 | e0440 = exp0440; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 532 | e0000 = exp0000; |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 533 | } else if (from >= p.length() + c.length()) { |
| 534 | eX = -1; |
| 535 | e0440 = -1; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 536 | e0000 = -1; |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 537 | } else if (full.charAt(from) == 'z') { |
| 538 | eX = (full.charAt(from + 1) != 'x') ? -1 : from + 1; |
| 539 | e0440 = (full.charAt(from + 1) != '\u0440') ? -1 : from + 1; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 540 | e0000 = (full.charAt(from + 1) != '\u0000') ? -1 : from + 1; |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 541 | } else { |
| 542 | eX = (full.charAt(from) != 'x') ? -1 : from; |
| 543 | e0440 = (full.charAt(from) != '\u0440') ? -1 : from; |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 544 | e0000 = (full.charAt(from) != '\u0000') ? -1 : from; |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 545 | } |
| 546 | Assert.assertEquals(eX, $noinline$indexOf(full, 'x', from)); |
| 547 | Assert.assertEquals(e0440, $noinline$indexOf(full, '\u0440', from)); |
| Vladimir Marko | fdaf0f4 | 2016-10-13 19:29:53 +0100 | [diff] [blame] | 548 | Assert.assertEquals(e0000, $noinline$indexOf(full, '\u0000', from)); |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 555 | public static void testEqualsConstString() { |
| 556 | Assert.assertTrue($noinline$equalsConstString0("")); |
| 557 | Assert.assertFalse($noinline$equalsConstString0("1")); |
| 558 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 559 | Assert.assertTrue($noinline$equalsConstString3("012")); |
| 560 | Assert.assertFalse($noinline$equalsConstString3("01")); |
| 561 | Assert.assertFalse($noinline$equalsConstString3("0123")); |
| 562 | Assert.assertFalse($noinline$equalsConstString3("01x")); |
| 563 | Assert.assertFalse($noinline$equalsConstString3("01\u0440")); |
| 564 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 565 | Assert.assertTrue($noinline$equalsConstString7("0123456")); |
| 566 | Assert.assertFalse($noinline$equalsConstString7("012345")); |
| 567 | Assert.assertFalse($noinline$equalsConstString7("01234567")); |
| 568 | Assert.assertFalse($noinline$equalsConstString7("012345x")); |
| 569 | Assert.assertFalse($noinline$equalsConstString7("012345\u0440")); |
| 570 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 571 | Assert.assertTrue($noinline$equalsConstString12("012345678901")); |
| 572 | Assert.assertFalse($noinline$equalsConstString12("01234567890")); |
| 573 | Assert.assertFalse($noinline$equalsConstString12("0123456789012")); |
| 574 | Assert.assertFalse($noinline$equalsConstString12("01234567890x")); |
| 575 | Assert.assertFalse($noinline$equalsConstString12("01234567890\u0440")); |
| 576 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 577 | Assert.assertTrue($noinline$equalsConstString14("01234567890123")); |
| 578 | Assert.assertFalse($noinline$equalsConstString14("0123456789012")); |
| 579 | Assert.assertFalse($noinline$equalsConstString14("012345678901234")); |
| 580 | Assert.assertFalse($noinline$equalsConstString14("0123456789012x")); |
| 581 | Assert.assertFalse($noinline$equalsConstString14("0123456789012\u0440")); |
| 582 | |
| 583 | Assert.assertTrue($noinline$equalsConstString24("012345678901234567890123")); |
| 584 | Assert.assertFalse($noinline$equalsConstString24("01234567890123456789012")); |
| 585 | Assert.assertFalse($noinline$equalsConstString24("0123456789012345678901234")); |
| 586 | Assert.assertFalse($noinline$equalsConstString24("01234567890123456789012x")); |
| 587 | Assert.assertFalse($noinline$equalsConstString24("01234567890123456789012\u0440")); |
| 588 | |
| 589 | Assert.assertTrue($noinline$equalsConstString29("01234567890123456789012345678")); |
| 590 | Assert.assertFalse($noinline$equalsConstString29("0123456789012345678901234567")); |
| 591 | Assert.assertFalse($noinline$equalsConstString29("012345678901234567890123456789")); |
| 592 | Assert.assertFalse($noinline$equalsConstString29("0123456789012345678901234567x")); |
| 593 | Assert.assertFalse($noinline$equalsConstString29("0123456789012345678901234567\u0440")); |
| 594 | |
| 595 | Assert.assertTrue($noinline$equalsConstString35("01234567890123456789012345678901234")); |
| 596 | Assert.assertFalse($noinline$equalsConstString35("0123456789012345678901234567890123")); |
| 597 | Assert.assertFalse($noinline$equalsConstString35("012345678901234567890123456789012345")); |
| 598 | Assert.assertFalse($noinline$equalsConstString35("0123456789012345678901234567890123x")); |
| 599 | Assert.assertFalse( |
| 600 | $noinline$equalsConstString35("0123456789012345678901234567890123\u0440")); |
| 601 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 602 | Assert.assertTrue($noinline$equalsConstNonAsciiString3("\u044012")); |
| 603 | Assert.assertFalse($noinline$equalsConstNonAsciiString3("\u04401")); |
| 604 | Assert.assertFalse($noinline$equalsConstNonAsciiString3("\u0440123")); |
| 605 | Assert.assertFalse($noinline$equalsConstNonAsciiString3("\u04401x")); |
| 606 | Assert.assertFalse($noinline$equalsConstNonAsciiString3("012")); |
| 607 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 608 | Assert.assertTrue($noinline$equalsConstNonAsciiString7("\u0440123456")); |
| 609 | Assert.assertFalse($noinline$equalsConstNonAsciiString7("\u044012345")); |
| 610 | Assert.assertFalse($noinline$equalsConstNonAsciiString7("\u04401234567")); |
| 611 | Assert.assertFalse($noinline$equalsConstNonAsciiString7("\u044012345x")); |
| 612 | Assert.assertFalse($noinline$equalsConstNonAsciiString7("0123456")); |
| 613 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 614 | Assert.assertTrue($noinline$equalsConstNonAsciiString12("\u044012345678901")); |
| 615 | Assert.assertFalse($noinline$equalsConstNonAsciiString12("\u04401234567890")); |
| 616 | Assert.assertFalse($noinline$equalsConstNonAsciiString12("\u0440123456789012")); |
| 617 | Assert.assertFalse($noinline$equalsConstNonAsciiString12("\u04401234567890x")); |
| 618 | Assert.assertFalse($noinline$equalsConstNonAsciiString12("012345678901")); |
| 619 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 620 | Assert.assertTrue($noinline$equalsConstNonAsciiString14("\u04401234567890123")); |
| 621 | Assert.assertFalse($noinline$equalsConstNonAsciiString14("\u0440123456789012")); |
| 622 | Assert.assertFalse($noinline$equalsConstNonAsciiString14("\u044012345678901234")); |
| 623 | Assert.assertFalse($noinline$equalsConstNonAsciiString14("\u0440123456789012x")); |
| 624 | Assert.assertFalse($noinline$equalsConstNonAsciiString14("01234567890123")); |
| 625 | |
| 626 | Assert.assertTrue($noinline$equalsConstNonAsciiString24("\u044012345678901234567890123")); |
| 627 | Assert.assertFalse($noinline$equalsConstNonAsciiString24("\u04401234567890123456789012")); |
| 628 | Assert.assertFalse($noinline$equalsConstNonAsciiString24("\u0440123456789012345678901234")); |
| 629 | Assert.assertFalse($noinline$equalsConstNonAsciiString24("\u04401234567890123456789012x")); |
| 630 | Assert.assertFalse($noinline$equalsConstNonAsciiString24("\012345678901234567890123")); |
| 631 | |
| 632 | Assert.assertTrue( |
| 633 | $noinline$equalsConstNonAsciiString29("\u04401234567890123456789012345678")); |
| 634 | Assert.assertFalse( |
| 635 | $noinline$equalsConstNonAsciiString29("\u0440123456789012345678901234567")); |
| 636 | Assert.assertFalse( |
| 637 | $noinline$equalsConstNonAsciiString29("\u044012345678901234567890123456789")); |
| 638 | Assert.assertFalse( |
| 639 | $noinline$equalsConstNonAsciiString29("\u0440123456789012345678901234567x")); |
| 640 | Assert.assertFalse($noinline$equalsConstNonAsciiString29("01234567890123456789012345678")); |
| 641 | |
| 642 | Assert.assertTrue( |
| 643 | $noinline$equalsConstNonAsciiString35("\u04401234567890123456789012345678901234")); |
| 644 | Assert.assertFalse( |
| 645 | $noinline$equalsConstNonAsciiString35("\u0440123456789012345678901234567890123")); |
| 646 | Assert.assertFalse( |
| 647 | $noinline$equalsConstNonAsciiString35("\u044012345678901234567890123456789012345")); |
| 648 | Assert.assertFalse( |
| 649 | $noinline$equalsConstNonAsciiString35("\u0440123456789012345678901234567890123x")); |
| 650 | Assert.assertFalse( |
| 651 | $noinline$equalsConstNonAsciiString35("01234567890123456789012345678901234")); |
| 652 | } |
| 653 | |
| 654 | public static void testConstStringEquals() { |
| 655 | Assert.assertTrue($noinline$constString0Equals("")); |
| 656 | Assert.assertFalse($noinline$constString0Equals("1")); |
| 657 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 658 | Assert.assertTrue($noinline$constString3Equals("012")); |
| 659 | Assert.assertFalse($noinline$constString3Equals("01")); |
| 660 | Assert.assertFalse($noinline$constString3Equals("0123")); |
| 661 | Assert.assertFalse($noinline$constString3Equals("01x")); |
| 662 | Assert.assertFalse($noinline$constString3Equals("01\u0440")); |
| 663 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 664 | Assert.assertTrue($noinline$constString7Equals("0123456")); |
| 665 | Assert.assertFalse($noinline$constString7Equals("012345")); |
| 666 | Assert.assertFalse($noinline$constString7Equals("01234567")); |
| 667 | Assert.assertFalse($noinline$constString7Equals("012345x")); |
| 668 | Assert.assertFalse($noinline$constString7Equals("012345\u0440")); |
| 669 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 670 | Assert.assertTrue($noinline$constString12Equals("012345678901")); |
| 671 | Assert.assertFalse($noinline$constString12Equals("01234567890")); |
| 672 | Assert.assertFalse($noinline$constString12Equals("0123456789012")); |
| 673 | Assert.assertFalse($noinline$constString12Equals("01234567890x")); |
| 674 | Assert.assertFalse($noinline$constString12Equals("01234567890\u0440")); |
| 675 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 676 | Assert.assertTrue($noinline$constString14Equals("01234567890123")); |
| 677 | Assert.assertFalse($noinline$constString14Equals("0123456789012")); |
| 678 | Assert.assertFalse($noinline$constString14Equals("012345678901234")); |
| 679 | Assert.assertFalse($noinline$constString14Equals("0123456789012x")); |
| 680 | Assert.assertFalse($noinline$constString14Equals("0123456789012\u0440")); |
| 681 | |
| 682 | Assert.assertTrue($noinline$constString24Equals("012345678901234567890123")); |
| 683 | Assert.assertFalse($noinline$constString24Equals("01234567890123456789012")); |
| 684 | Assert.assertFalse($noinline$constString24Equals("0123456789012345678901234")); |
| 685 | Assert.assertFalse($noinline$constString24Equals("01234567890123456789012x")); |
| 686 | Assert.assertFalse($noinline$constString24Equals("01234567890123456789012\u0440")); |
| 687 | |
| 688 | Assert.assertTrue($noinline$constString29Equals("01234567890123456789012345678")); |
| 689 | Assert.assertFalse($noinline$constString29Equals("0123456789012345678901234567")); |
| 690 | Assert.assertFalse($noinline$constString29Equals("012345678901234567890123456789")); |
| 691 | Assert.assertFalse($noinline$constString29Equals("0123456789012345678901234567x")); |
| 692 | Assert.assertFalse($noinline$constString29Equals("0123456789012345678901234567\u0440")); |
| 693 | |
| 694 | Assert.assertTrue($noinline$constString35Equals("01234567890123456789012345678901234")); |
| 695 | Assert.assertFalse($noinline$constString35Equals("0123456789012345678901234567890123")); |
| 696 | Assert.assertFalse($noinline$constString35Equals("012345678901234567890123456789012345")); |
| 697 | Assert.assertFalse($noinline$constString35Equals("0123456789012345678901234567890123x")); |
| 698 | Assert.assertFalse( |
| 699 | $noinline$constString35Equals("0123456789012345678901234567890123\u0040")); |
| 700 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 701 | Assert.assertTrue($noinline$constNonAsciiString3Equals("\u044012")); |
| 702 | Assert.assertFalse($noinline$constNonAsciiString3Equals("\u04401")); |
| 703 | Assert.assertFalse($noinline$constNonAsciiString3Equals("\u0440123")); |
| 704 | Assert.assertFalse($noinline$constNonAsciiString3Equals("\u04401x")); |
| 705 | Assert.assertFalse($noinline$constNonAsciiString3Equals("0123456")); |
| 706 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 707 | Assert.assertTrue($noinline$constNonAsciiString7Equals("\u0440123456")); |
| 708 | Assert.assertFalse($noinline$constNonAsciiString7Equals("\u044012345")); |
| 709 | Assert.assertFalse($noinline$constNonAsciiString7Equals("\u04401234567")); |
| 710 | Assert.assertFalse($noinline$constNonAsciiString7Equals("\u044012345x")); |
| 711 | Assert.assertFalse($noinline$constNonAsciiString7Equals("0123456")); |
| 712 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 713 | Assert.assertTrue($noinline$constNonAsciiString12Equals("\u044012345678901")); |
| 714 | Assert.assertFalse($noinline$constNonAsciiString12Equals("\u04401234567890")); |
| 715 | Assert.assertFalse($noinline$constNonAsciiString12Equals("\u0440123456789012")); |
| 716 | Assert.assertFalse($noinline$constNonAsciiString12Equals("\u04401234567890x")); |
| 717 | Assert.assertFalse($noinline$constNonAsciiString12Equals("012345678901")); |
| 718 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 719 | Assert.assertTrue($noinline$constNonAsciiString14Equals("\u04401234567890123")); |
| 720 | Assert.assertFalse($noinline$constNonAsciiString14Equals("\u0440123456789012")); |
| 721 | Assert.assertFalse($noinline$constNonAsciiString14Equals("\u044012345678901234")); |
| 722 | Assert.assertFalse($noinline$constNonAsciiString14Equals("\u0440123456789012x")); |
| 723 | Assert.assertFalse($noinline$constNonAsciiString14Equals("01234567890123")); |
| 724 | |
| 725 | Assert.assertTrue($noinline$constNonAsciiString24Equals("\u044012345678901234567890123")); |
| 726 | Assert.assertFalse($noinline$constNonAsciiString24Equals("\u04401234567890123456789012")); |
| 727 | Assert.assertFalse($noinline$constNonAsciiString24Equals("\u0440123456789012345678901234")); |
| 728 | Assert.assertFalse($noinline$constNonAsciiString24Equals("\u04401234567890123456789012x")); |
| 729 | Assert.assertFalse($noinline$constNonAsciiString24Equals("\012345678901234567890123")); |
| 730 | |
| 731 | Assert.assertTrue( |
| 732 | $noinline$constNonAsciiString29Equals("\u04401234567890123456789012345678")); |
| 733 | Assert.assertFalse( |
| 734 | $noinline$constNonAsciiString29Equals("\u0440123456789012345678901234567")); |
| 735 | Assert.assertFalse( |
| 736 | $noinline$constNonAsciiString29Equals("\u044012345678901234567890123456789")); |
| 737 | Assert.assertFalse( |
| 738 | $noinline$constNonAsciiString29Equals("\u0440123456789012345678901234567x")); |
| 739 | Assert.assertFalse($noinline$constNonAsciiString29Equals("01234567890123456789012345678")); |
| 740 | |
| 741 | Assert.assertTrue( |
| 742 | $noinline$constNonAsciiString35Equals("\u04401234567890123456789012345678901234")); |
| 743 | Assert.assertFalse( |
| 744 | $noinline$constNonAsciiString35Equals("\u0440123456789012345678901234567890123")); |
| 745 | Assert.assertFalse( |
| 746 | $noinline$constNonAsciiString35Equals("\u044012345678901234567890123456789012345")); |
| 747 | Assert.assertFalse( |
| 748 | $noinline$constNonAsciiString35Equals("\u0440123456789012345678901234567890123x")); |
| 749 | Assert.assertFalse( |
| 750 | $noinline$constNonAsciiString35Equals("01234567890123456789012345678901234")); |
| Vladimir Marko | a44c445 | 2017-07-13 18:49:35 +0100 | [diff] [blame] | 751 | |
| 752 | // Regression test for incorrectly creating an uncompressed string when the |
| 753 | // string should be compressed. Only the low 8 bits are relevant but the whole |
| 754 | // `hibyte` was erroneously tested. Bug: 63661357 |
| 755 | Assert.assertTrue("A".equals(new String(new byte[] { (byte)'A' }, /* hibyte */ 0x100))); |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | public static boolean $noinline$equalsConstString0(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 759 | return s.equals(""); |
| 760 | } |
| 761 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 762 | public static boolean $noinline$equalsConstString3(String s) { |
| 763 | return s.equals("012"); |
| 764 | } |
| 765 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 766 | public static boolean $noinline$equalsConstString7(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 767 | return s.equals("0123456"); |
| 768 | } |
| 769 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 770 | public static boolean $noinline$equalsConstString12(String s) { |
| 771 | return s.equals("012345678901"); |
| 772 | } |
| 773 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 774 | public static boolean $noinline$equalsConstString14(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 775 | return s.equals("01234567890123"); |
| 776 | } |
| 777 | |
| 778 | public static boolean $noinline$equalsConstString24(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 779 | return s.equals("012345678901234567890123"); |
| 780 | } |
| 781 | |
| 782 | public static boolean $noinline$equalsConstString29(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 783 | return s.equals("01234567890123456789012345678"); |
| 784 | } |
| 785 | |
| 786 | public static boolean $noinline$equalsConstString35(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 787 | return s.equals("01234567890123456789012345678901234"); |
| 788 | } |
| 789 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 790 | public static boolean $noinline$equalsConstNonAsciiString3(String s) { |
| 791 | return s.equals("\u044012"); |
| 792 | } |
| 793 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 794 | public static boolean $noinline$equalsConstNonAsciiString7(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 795 | return s.equals("\u0440123456"); |
| 796 | } |
| 797 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 798 | public static boolean $noinline$equalsConstNonAsciiString12(String s) { |
| 799 | return s.equals("\u044012345678901"); |
| 800 | } |
| 801 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 802 | public static boolean $noinline$equalsConstNonAsciiString14(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 803 | return s.equals("\u04401234567890123"); |
| 804 | } |
| 805 | |
| 806 | public static boolean $noinline$equalsConstNonAsciiString24(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 807 | return s.equals("\u044012345678901234567890123"); |
| 808 | } |
| 809 | |
| 810 | public static boolean $noinline$equalsConstNonAsciiString29(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 811 | return s.equals("\u04401234567890123456789012345678"); |
| 812 | } |
| 813 | |
| 814 | public static boolean $noinline$equalsConstNonAsciiString35(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 815 | return s.equals("\u04401234567890123456789012345678901234"); |
| 816 | } |
| 817 | |
| 818 | public static boolean $noinline$constString0Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 819 | return s.equals(""); |
| 820 | } |
| 821 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 822 | public static boolean $noinline$constString3Equals(String s) { |
| 823 | return "012".equals(s); |
| 824 | } |
| 825 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 826 | public static boolean $noinline$constString7Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 827 | return "0123456".equals(s); |
| 828 | } |
| 829 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 830 | public static boolean $noinline$constString12Equals(String s) { |
| 831 | return "012345678901".equals(s); |
| 832 | } |
| 833 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 834 | public static boolean $noinline$constString14Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 835 | return "01234567890123".equals(s); |
| 836 | } |
| 837 | |
| 838 | public static boolean $noinline$constString24Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 839 | return "012345678901234567890123".equals(s); |
| 840 | } |
| 841 | |
| 842 | public static boolean $noinline$constString29Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 843 | return "01234567890123456789012345678".equals(s); |
| 844 | } |
| 845 | |
| 846 | public static boolean $noinline$constString35Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 847 | return "01234567890123456789012345678901234".equals(s); |
| 848 | } |
| 849 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 850 | public static boolean $noinline$constNonAsciiString3Equals(String s) { |
| 851 | return "\u044012".equals(s); |
| 852 | } |
| 853 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 854 | public static boolean $noinline$constNonAsciiString7Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 855 | return "\u0440123456".equals(s); |
| 856 | } |
| 857 | |
| Vladimir Marko | 984519c | 2017-08-23 10:45:29 +0100 | [diff] [blame] | 858 | public static boolean $noinline$constNonAsciiString12Equals(String s) { |
| 859 | return "\u044012345678901".equals(s); |
| 860 | } |
| 861 | |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 862 | public static boolean $noinline$constNonAsciiString14Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 863 | return "\u04401234567890123".equals(s); |
| 864 | } |
| 865 | |
| 866 | public static boolean $noinline$constNonAsciiString24Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 867 | return "\u044012345678901234567890123".equals(s); |
| 868 | } |
| 869 | |
| 870 | public static boolean $noinline$constNonAsciiString29Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 871 | return "\u04401234567890123456789012345678".equals(s); |
| 872 | } |
| 873 | |
| 874 | public static boolean $noinline$constNonAsciiString35Equals(String s) { |
| Vladimir Marko | e39f14f | 2017-02-10 15:44:25 +0000 | [diff] [blame] | 875 | return "\u04401234567890123456789012345678901234".equals(s); |
| 876 | } |
| 877 | |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 878 | public static int $noinline$compareTo(String lhs, String rhs) { |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 879 | return lhs.compareTo(rhs); |
| 880 | } |
| 881 | |
| 882 | public static boolean $noinline$equals(String lhs, String rhs) { |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 883 | return lhs.equals(rhs); |
| 884 | } |
| 885 | |
| 886 | public static int $noinline$indexOf(String lhs, int ch) { |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 887 | return lhs.indexOf(ch); |
| 888 | } |
| 889 | |
| 890 | public static int $noinline$indexOf(String lhs, int ch, int fromIndex) { |
| Vladimir Marko | 9c9883b | 2016-10-17 14:45:29 +0100 | [diff] [blame] | 891 | return lhs.indexOf(ch, fromIndex); |
| 892 | } |
| jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 893 | } |