5 String source
= "abcdefg";
6 char[] dest
= new char [3];
10 source
.getChars (0, 5, // Source
12 Fail ("getChars", "Should not have succeeded");
16 ExpectArrayIndex ("getChars", e
);
20 /* How do I stop a compiler warning causing a test to fail?
21 static void getBytes()
23 String source = "abcdefg";
24 byte[] dest = new byte[3];
28 source.getBytes (0, 5, dest, (1<<31) - 1);
29 Fail ("getBytes", "Should not have succeeded");
33 ExpectArrayIndex ("getBytes", e);
38 static void regionMatches()
40 if ("abcdefg".regionMatches (4, "abcdefg", 4, -1))
42 Fail ("regionMatches", "Should not return true");
47 if ("abcdefg".regionMatches (4, "abcdefg", 4, (1<<31)-1))
49 Fail ("regionMatches (2nd)", "Should not return true");
54 Fail ("regionMatches (2nd)", e
);
58 static void regionMatchesCase()
60 if ("abcdefg".regionMatches (true, 4, "abcdefg", 4, -1))
62 Fail ("regionMatchesCase", "Should not return true");
67 if ("abcdefg".regionMatches (true, 4, "abcdefg", 4, (1<<31)-1))
69 Fail ("regionMatchesCase (2nd)", "Should not return true");
74 Fail ("regionMatchesCase (2nd)", e
);
78 static void startsWith()
80 // We make the arg pretty big to try and cause a segfault.
81 String s
= new String ("abcdef");
82 StringBuffer b
= new StringBuffer (1000000);
83 b
.setLength (1000000);
84 String arg
= new String (b
);
88 s
.startsWith (arg
, (1<<31) - 1000000);
92 Fail ("startsWith", e
);
98 char[] array
= new char[] {'a', 'b', 'c', 'd', 'e'};
101 String
.valueOf (array
, 4, (1<<31)-1);
102 Fail ("valueOf", "should not succeed");
106 ExpectArrayIndex ("valueOf", e
);
110 public static void main (String
[] args
) throws Throwable
119 if (tests_failed
== 0)
120 System
.out
.println ("ok");
123 static void ExpectArrayIndex (String test
, Throwable e
)
125 if (e
instanceof ArrayIndexOutOfBoundsException
)
131 static void Fail (String test
, Object problem
)
134 System
.err
.print (test
);
135 System
.err
.print ('\t');
136 System
.err
.println (problem
);
139 static int tests_failed
;