01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexey A. Ivanov
19: * @version $Revision$
20: */package javax.swing.text;
21:
22: import java.lang.ref.WeakReference;
23: import javax.swing.SerializableTestCase;
24:
25: public class GapContent_SerializeTest extends SerializableTestCase {
26: private GapContent content;
27:
28: @Override
29: protected void setUp() throws Exception {
30: toSave = content = new GapContent();
31: content.insertString(0, "01234");
32: content.insertString(5, "abcde");
33: content.insertString(5, "!");
34: super .setUp();
35: }
36:
37: @Override
38: public void testSerializable() throws Exception {
39: GapContent restored = (GapContent) toLoad;
40: assertEquals(content.length(), restored.length());
41: assertEquals(content.getArrayLength(), restored
42: .getArrayLength());
43: assertEquals(content.getGapStart(), restored.getGapStart());
44: assertEquals(content.getGapEnd(), restored.getGapEnd());
45: assertEquals(content.getString(0, content.length()), restored
46: .getString(0, restored.length()));
47: // Test that position handling works the way it is supposed
48: Position pos = restored.createPosition(5);
49: WeakReference<Position> wr = new WeakReference<Position>(pos);
50: assertEquals(5, pos.getOffset());
51: restored.insertString(0, "aStr");
52: assertEquals(9, pos.getOffset());
53: }
54: }
|