• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
18  * Simple string test.
19  */
20 public class Main {
main(String args[])21     public static void main(String args[]) {
22         String baseStr = "*** This is a very nice string!!!";
23         String testStr;
24         int i;
25 
26         testStr = baseStr.substring(4, baseStr.length() - 3);
27         System.out.println("testStr is '" + testStr + "'");
28 
29         /* sloppy for loop */
30         for (i = 0; i < testStr.length(); i++)
31             System.out.print(testStr.charAt(i));
32         System.out.print("\n");
33 
34         String testStr2 = "This is a very nice strinG";
35         if (testStr.length() != testStr2.length())
36             System.out.println("WARNING: stringTest length mismatch");
37 
38         System.out.println("Compare result is " + testStr.compareTo(testStr2));
39 
40         // expected: -65302
41         String s1 = "\u0c6d\u0cb6\u0d00\u0000\u0080\u0080\u0080\u0000\u0002\u0002\u0002\u0000\u00e9\u00e9\u00e9";
42         String s2 = "\u0c6d\u0cb6\u0d00\u0000\u0080\u0080\u0080\u0000\u0002\u0002\u0002\u0000\uffff\uffff\uffff\u00e9\u00e9\u00e9";
43         System.out.println("Compare unicode: " + s1.compareTo(s2));
44 
45         try {
46             testStr.charAt(500);
47             System.out.println("GLITCH: expected exception");
48         } catch (StringIndexOutOfBoundsException sioobe) {
49             System.out.println("Got expected exception");
50         }
51     }
52 }
53