1/*
2 * Copyright (C) 2008 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
17package android.widget;
18
19import android.test.AndroidTestCase;
20import android.test.suitebuilder.annotation.SmallTest;
21import android.text.GetChars;
22
23/**
24 * TextViewTest tests {@link TextView}.
25 */
26public class TextViewTest extends AndroidTestCase {
27
28    @SmallTest
29    public void testArray() throws Exception {
30        TextView tv = new TextView(mContext);
31
32        char[] c = new char[] { 'H', 'e', 'l', 'l', 'o', ' ',
33                                'W', 'o', 'r', 'l', 'd', '!' };
34
35        tv.setText(c, 1, 4);
36        CharSequence oldText = tv.getText();
37
38        tv.setText(c, 4, 5);
39        CharSequence newText = tv.getText();
40
41        assertTrue(newText == oldText);
42
43        assertEquals(5, newText.length());
44        assertEquals('o', newText.charAt(0));
45        assertEquals("o Wor", newText.toString());
46
47        assertEquals(" Wo", newText.subSequence(1, 4));
48
49        char[] c2 = new char[7];
50        ((GetChars) newText).getChars(1, 4, c2, 2);
51        assertEquals('\0', c2[1]);
52        assertEquals(' ', c2[2]);
53        assertEquals('W', c2[3]);
54        assertEquals('o', c2[4]);
55        assertEquals('\0', c2[5]);
56    }
57}
58