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: package org.apache.poi.hssf.usermodel;
19:
20: import junit.framework.TestCase;
21:
22: public class TestHSSFRichTextString extends TestCase {
23: public void testApplyFont() throws Exception {
24:
25: HSSFRichTextString r = new HSSFRichTextString("testing");
26: assertEquals(0, r.numFormattingRuns());
27: r.applyFont(2, 4, new HSSFFont((short) 1, null));
28: assertEquals(2, r.numFormattingRuns());
29: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0));
30: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1));
31: assertEquals(1, r.getFontAtIndex(2));
32: assertEquals(1, r.getFontAtIndex(3));
33: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4));
34: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5));
35: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(6));
36:
37: r.applyFont(6, 7, new HSSFFont((short) 2, null));
38: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0));
39: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1));
40: assertEquals(1, r.getFontAtIndex(2));
41: assertEquals(1, r.getFontAtIndex(3));
42: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4));
43: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5));
44: assertEquals(2, r.getFontAtIndex(6));
45:
46: r.applyFont(HSSFRichTextString.NO_FONT);
47: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(0));
48: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(1));
49: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(2));
50: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(3));
51: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(4));
52: assertEquals(HSSFRichTextString.NO_FONT, r.getFontAtIndex(5));
53:
54: r.applyFont(new HSSFFont((short) 1, null));
55: assertEquals(1, r.getFontAtIndex(0));
56: assertEquals(1, r.getFontAtIndex(1));
57: assertEquals(1, r.getFontAtIndex(2));
58: assertEquals(1, r.getFontAtIndex(3));
59: assertEquals(1, r.getFontAtIndex(4));
60: assertEquals(1, r.getFontAtIndex(5));
61: assertEquals(1, r.getFontAtIndex(6));
62:
63: }
64:
65: public void testClearFormatting() throws Exception {
66:
67: HSSFRichTextString r = new HSSFRichTextString("testing");
68: assertEquals(0, r.numFormattingRuns());
69: r.applyFont(2, 4, new HSSFFont((short) 1, null));
70: assertEquals(2, r.numFormattingRuns());
71: r.clearFormatting();
72: assertEquals(0, r.numFormattingRuns());
73: }
74: }
|