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 javax.swing.BasicSwingTestCase;
23: import javax.swing.SerializableTestCase;
24: import javax.swing.text.AbstractDocumentTest.DisAbstractedDocument;
25: import org.apache.harmony.x.swing.StringConstants;
26:
27: public class AbstractDocument_SerializationTest extends
28: SerializableTestCase {
29: private AbstractDocument doc;
30:
31: private final String key = "key";
32:
33: private final String value = "value";
34:
35: private final String text = "text\n"
36: + AbstractDocument_UpdateTest.RTL;
37:
38: @Override
39: protected void setUp() throws Exception {
40: toSave = doc = new DisAbstractedDocument(new GapContent());
41: doc.insertString(0, text, null);
42: doc.putProperty(key, value);
43: doc.setDocumentFilter(new AbstractDocument_FilterTest.Filter());
44: super .setUp();
45: }
46:
47: @Override
48: public void testSerializable() throws BadLocationException {
49: AbstractDocument restored = (AbstractDocument) toLoad;
50: assertEquals(text, restored.getText(0, restored.getLength()));
51: assertEquals(value, restored.getProperty(key));
52: assertEquals(
53: Boolean.TRUE,
54: restored
55: .getProperty(BasicSwingTestCase.isHarmony() ? StringConstants.BIDI_PROPERTY
56: : "i18n"));
57: if (BasicSwingTestCase.isHarmony()) {
58: AbstractDocument_ListenerTest listener = new AbstractDocument_ListenerTest();
59: restored.addDocumentListener(listener);
60: restored.addUndoableEditListener(listener);
61: restored.insertString(0, "234", null);
62: // 12345 must be inserted instead of only 234 'cause of filter
63: assertEquals("12345" + text, restored.getText(0, restored
64: .getLength()));
65: // Event handlers should be called
66: assertNotNull(listener.insert);
67: assertNotNull(listener.undo);
68: assertEquals(0, restored.getStartPosition().getOffset());
69: assertEquals(restored.getLength() + 1, restored
70: .getEndPosition().getOffset());
71: // Test readers are not null
72: restored.readLock();
73: restored.readUnlock();
74: }
75: }
76: }
|